8142534: [TEST_BUG] Test javax/swing/JMenu/8072900/WrongSelectionOnMouseOver.java fails for Ubuntu 15.10
authorssadetsky
Wed, 12 Apr 2017 09:00:32 -0700
changeset 44762 00573e129ce6
parent 44663 5b91a944277e
child 44763 56f74283845e
8142534: [TEST_BUG] Test javax/swing/JMenu/8072900/WrongSelectionOnMouseOver.java fails for Ubuntu 15.10 Reviewed-by: yan, serb
jdk/test/javax/swing/JMenu/8072900/WrongSelectionOnMouseOver.java
--- a/jdk/test/javax/swing/JMenu/8072900/WrongSelectionOnMouseOver.java	Tue Apr 11 00:05:00 2017 +0300
+++ b/jdk/test/javax/swing/JMenu/8072900/WrongSelectionOnMouseOver.java	Wed Apr 12 09:00:32 2017 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017 Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -52,6 +52,8 @@
     private UIManager.LookAndFeelInfo laf;
     JFrame frame1;
     JFrame frame2;
+    private Point menu1location;
+    private Point menu2location;
 
     public WrongSelectionOnMouseOver(UIManager.LookAndFeelInfo laf) throws Exception {
         this.laf = laf;
@@ -136,7 +138,7 @@
             m2.add(i2);
 
             frame2.setLayout(new FlowLayout());
-            frame2.setBounds(400, 200, 200, 200);
+            frame2.setBounds(450, 200, 200, 200);
 
             frame2.setVisible(true);
         }
@@ -166,8 +168,13 @@
 
         robot.waitForIdle();
 
-        robot.mouseMove((int) m1.getLocationOnScreen().getX() + 5,
-                (int) m1.getLocationOnScreen().getY() + 5);
+        SwingUtilities.invokeAndWait(() -> {
+            menu1location = m1.getLocationOnScreen();
+            menu2location = m2.getLocationOnScreen();
+        });
+
+        robot.mouseMove((int) menu1location.getX() + 5,
+                (int) menu1location.getY() + 5);
         robot.mousePress(MouseEvent.BUTTON1_MASK);
         robot.mouseRelease(MouseEvent.BUTTON1_MASK);
 
@@ -175,8 +182,8 @@
             throw new RuntimeException("Menu has not been selected.");
         };
 
-        robot.mouseMove((int) m2.getLocationOnScreen().getX() + 5,
-                (int) m2.getLocationOnScreen().getY() + 5);
+        robot.mouseMove((int) menu2location.getX() + 5,
+                (int) menu2location.getY() + 5);
 
         if (!secondMenuMouseEntered.await(5, TimeUnit.SECONDS)) {
             throw new RuntimeException("MouseEntered event missed for the second menu");