8211822: Some tests fail after JDK-8210039
authorserb
Tue, 06 Nov 2018 17:57:17 -0800
changeset 52540 a00f1403dbe9
parent 52539 b0dcecb339c4
child 52541 7f67b8184ffc
8211822: Some tests fail after JDK-8210039 8202886: [macos] Test java/awt/MenuBar/8007006/bug8007006.java fails on MacOS Reviewed-by: prr, iignatyev, jdv, kaddepalli
test/jdk/ProblemList.txt
test/jdk/java/awt/MenuBar/8007006/bug8007006.java
test/jdk/javax/swing/JComboBox/4199622/bug4199622.java
test/jdk/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java
test/jdk/javax/swing/JPopupMenu/7154841/bug7154841.java
--- a/test/jdk/ProblemList.txt	Sat Nov 03 09:50:22 2018 +0530
+++ b/test/jdk/ProblemList.txt	Tue Nov 06 17:57:17 2018 -0800
@@ -474,7 +474,6 @@
 java/awt/datatransfer/ConstructFlavoredObjectTest/ConstructFlavoredObjectTest.java 8202860 linux-all
 java/awt/dnd/DisposeFrameOnDragCrash/DisposeFrameOnDragTest.java 8202790 macosx-all,linux-all
 java/awt/FileDialog/FilenameFilterTest/FilenameFilterTest.html 8202882 linux-all
-java/awt/MenuBar/8007006/bug8007006.java 8202886 macosx-all
 java/awt/Frame/FramesGC/FramesGC.java 8079069 macosx-all
 java/awt/dnd/MissingDragExitEventTest/MissingDragExitEventTest.java 8030121 macosx-all
 java/awt/Choice/ChoicePopupLocation/ChoicePopupLocation.java 8202931 macosx-all,linux-all
@@ -493,7 +492,6 @@
 java/awt/xembed/server/RunTestXEmbed.java 7034201 linux-all
 java/awt/Modal/ModalFocusTransferTests/FocusTransferDialogsDocModalTest.java 8164473 linux-all
 java/awt/im/memoryleak/InputContextMemoryLeakTest.java 8023814 linux-all,solaris-all
-java/awt/MenuBar/8007006/bug8007006.java 8213122 windows-all
 # below test fails only on Win 7
 java/awt/font/FontNames/LocaleFamilyNames.java 8213129 windows-all
 
@@ -821,9 +819,6 @@
 javax/swing/dnd/8139050/NativeErrorsInTableDnD.java 8202765  macosx-all,linux-all
 javax/swing/Popup/TaskbarPositionTest.java 8065097 macosx-all,linux-all
 javax/swing/JComboBox/WindowsComboBoxSize/WindowsComboBoxSizeTest.java 8213116 windows-all
-javax/swing/JComboBox/4199622/bug4199622.java 8213122 windows-all
-javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java 8213122 windows-all,macosx-all
-javax/swing/JPopupMenu/7154841/bug7154841.java 8213122 windows-all,macosx-all
 javax/swing/GraphicsConfigNotifier/StalePreferredSize.java 8213121 macosx-all
 javax/swing/JButton/4368790/bug4368790.java 8213123 macosx-all
 javax/swing/JEditorPane/6917744/bug6917744.java 8213124 macosx-all
--- a/test/jdk/java/awt/MenuBar/8007006/bug8007006.java	Sat Nov 03 09:50:22 2018 +0530
+++ b/test/jdk/java/awt/MenuBar/8007006/bug8007006.java	Tue Nov 06 17:57:17 2018 -0800
@@ -25,10 +25,10 @@
  * @test
  * @key headful
  * @bug 8007006
+ * @requires (os.family == "mac")
  * @summary [macosx] Closing subwindow loses main window menus.
- * @author Leonid Romanov
  * @library /test/lib
- * @build ExtendedRobot jdk.test.lib.Platform
+ * @build jdk.test.lib.Platform
  * @run main bug8007006
  */
 
@@ -40,6 +40,7 @@
 public class bug8007006 {
     private static Frame frame1;
     private static Frame frame2;
+    private static volatile boolean isActionPerformed;
 
     public static void main(String[] args) throws Exception {
         if (!Platform.isOSX()) {
@@ -49,46 +50,19 @@
 
         System.setProperty("apple.laf.useScreenMenuBar", "true");
 
-        ExtendedRobot robot = new ExtendedRobot();
-        robot.setAutoDelay(50);
+        Robot robot = new Robot();
+        robot.setAutoDelay(300);
 
         createAndShowGUI();
-        robot.waitForIdle(1500);
-
+        robot.waitForIdle();
         frame2.dispose();
-
-        robot.waitForIdle(1500);
-
-
-        // open "Apple" menu (the leftmost one)
-        robot.keyPress(KeyEvent.VK_META);
-        robot.keyPress(KeyEvent.VK_SHIFT);
-        robot.keyPress(KeyEvent.VK_SLASH);
-        robot.keyRelease(KeyEvent.VK_SLASH);
-        robot.keyRelease(KeyEvent.VK_SHIFT);
-        robot.keyRelease(KeyEvent.VK_META);
-
-        // Select our menu
-        robot.keyPress(KeyEvent.VK_LEFT);
-        robot.keyRelease(KeyEvent.VK_LEFT);
-
-        // Select menu item
-        robot.keyPress(KeyEvent.VK_DOWN);
-        robot.keyRelease(KeyEvent.VK_DOWN);
-        robot.keyPress(KeyEvent.VK_ENTER);
-        robot.keyRelease(KeyEvent.VK_ENTER);
-
         robot.waitForIdle();
 
-        MenuBar mbar = frame1.getMenuBar();
-        Menu menu = mbar.getMenu(0);
-        CheckboxMenuItem item = (CheckboxMenuItem)menu.getItem(0);
-        boolean isChecked = item.getState();
+        performMenuItemTest(robot);
 
         frame1.dispose();
-
-        if (isChecked) {
-            throw new Exception("Test failed: menu item remained checked");
+        if (!isActionPerformed) {
+            throw new Exception("Test failed: menu item action was not performed");
         }
     }
 
@@ -106,14 +80,51 @@
     }
 
     private static MenuBar createMenuBar() {
-        MenuBar mbar = new MenuBar();
-        Menu menu = new Menu("Menu");
-        MenuItem item = new CheckboxMenuItem("Checked", true);
-
+        // A very long name makes it more likely that the robot will hit the
+        // menu
+        Menu menu = new Menu("TestTestTestTestTestTestTestTestTestTest");
+        MenuItem item = new MenuItem("TestTestTestTestTestTestTestTestTestTest");
+        item.addActionListener(new ActionListener() {
+            @Override
+            public void actionPerformed(ActionEvent ev) {
+                isActionPerformed = true;
+            }
+        });
         menu.add(item);
-        mbar.add(menu);
-
-        return mbar;
+        MenuBar mb = new MenuBar();
+        mb.add(menu);
+        return mb;
     }
 
+    private static void performMenuItemTest(Robot robot) {
+        // Find the menu on the screen menu bar
+        // The location depends upon the application name which is the name
+        // of the first menu.
+        // Unfortunately, the application name can vary based on how the
+        // application is run.
+        // The work around is to make the menu and the menu item names very
+        // long.
+        int menuBarX = 250;
+        int menuBarY = 11;
+        int menuItemX = menuBarX;
+        int menuItemY = 34;
+        robot.mouseMove(menuBarX, menuBarY);
+        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
+        robot.mouseMove(menuItemX, menuItemY);
+        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
+        robot.waitForIdle();
+        waitForAction();
+    }
+
+    private static void waitForAction() {
+        try {
+            for (int i = 0; i < 10; i++) {
+                if (isActionPerformed) {
+                    return;
+                }
+                Thread.sleep(100);
+            }
+        } catch (InterruptedException ex) {
+        }
+    }
 }
--- a/test/jdk/javax/swing/JComboBox/4199622/bug4199622.java	Sat Nov 03 09:50:22 2018 +0530
+++ b/test/jdk/javax/swing/JComboBox/4199622/bug4199622.java	Tue Nov 06 17:57:17 2018 -0800
@@ -27,10 +27,9 @@
    @bug 4199622
    @requires (os.family == "windows")
    @summary RFE: JComboBox shouldn't send ActionEvents for keyboard navigation
-   @author Vladislav Karnaukhov
    @library /test/lib
    @modules java.desktop/com.sun.java.swing.plaf.windows
-   @build jdk.test.libr.Platform
+   @build jdk.test.lib.Platform
    @run main bug4199622
  */
 
--- a/test/jdk/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java	Sat Nov 03 09:50:22 2018 +0530
+++ b/test/jdk/javax/swing/JFrame/NSTexturedJFrame/NSTexturedJFrame.java	Tue Nov 06 17:57:17 2018 -0800
@@ -34,9 +34,10 @@
  * @test
  * @key headful
  * @bug 7124513
+ * @requires (os.family == "mac")
  * @summary We should support NSTexturedBackgroundWindowMask style on OSX.
- * @author Sergey Bylokhov
  * @library /test/lib
+ *          /test/jdk/lib/testlibrary/
  * @build ExtendedRobot jdk.test.lib.Platform
  * @run main NSTexturedJFrame
  */
--- a/test/jdk/javax/swing/JPopupMenu/7154841/bug7154841.java	Sat Nov 03 09:50:22 2018 +0530
+++ b/test/jdk/javax/swing/JPopupMenu/7154841/bug7154841.java	Tue Nov 06 17:57:17 2018 -0800
@@ -25,9 +25,10 @@
  * @test
  * @key headful
  * @bug 7154841
+ * @requires (os.family == "mac")
  * @summary JPopupMenu is overlapped by a Dock on Mac OS X
- * @author Petr Pchelko
  * @library /test/lib
+ *          /test/jdk/lib/testlibrary/
  * @build ExtendedRobot jdk.test.lib.Platform
  * @run main bug7154841
  */