changeset 53518:65407a437327

8198624: java/awt/KeyboardFocusmanager/TypeAhead/SubMenuShowTest/SubMenuShowTest.html fails on mac Reviewed-by: serb
author sveerabhadra
date Mon, 12 Nov 2018 10:55:49 +0530
parents 50de7d1f6b64
children 339963bcff24
files test/jdk/ProblemList.txt test/jdk/java/awt/KeyboardFocusmanager/TypeAhead/SubMenuShowTest/SubMenuShowTest.html test/jdk/java/awt/KeyboardFocusmanager/TypeAhead/SubMenuShowTest/SubMenuShowTest.java
diffstat 3 files changed, 62 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/ProblemList.txt	Sat Nov 10 18:48:35 2018 -0800
+++ b/test/jdk/ProblemList.txt	Mon Nov 12 10:55:49 2018 +0530
@@ -151,7 +151,6 @@
 java/awt/event/InputEvent/EventWhenTest/EventWhenTest.java 8168646 generic-all
 java/awt/KeyboardFocusmanager/TypeAhead/EnqueueWithDialogButtonTest/EnqueueWithDialogButtonTest.java 8198623 macosx-all
 java/awt/KeyboardFocusmanager/TypeAhead/FreezeTest/FreezeTest.java 8198623 macosx-all
-java/awt/KeyboardFocusmanager/TypeAhead/SubMenuShowTest/SubMenuShowTest.html 8198624 macosx-all
 java/awt/KeyboardFocusmanager/TypeAhead/TestDialogTypeAhead.html 8198626 macosx-all
 java/awt/Mixing/AWT_Mixing/HierarchyBoundsListenerMixingTest.java 8049405 macosx-all
 java/awt/Mixing/AWT_Mixing/OpaqueOverlappingChoice.java 8048171 generic-all
--- a/test/jdk/java/awt/KeyboardFocusmanager/TypeAhead/SubMenuShowTest/SubMenuShowTest.html	Sat Nov 10 18:48:35 2018 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,48 +0,0 @@
-<!--
- Copyright (c) 2006, 2018, 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
- under the terms of the GNU General Public License version 2 only, as
- published by the Free Software Foundation.
-
- This code is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- version 2 for more details (a copy is included in the LICENSE file that
- accompanied this code).
-
- You should have received a copy of the GNU General Public License version
- 2 along with this work; if not, write to the Free Software Foundation,
- Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-
- Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- or visit www.oracle.com if you need additional information or have any
- questions.
--->
-
-<html>
-<!--
-  @test
-  @key headful
-  @bug        6380743
-  @summary    Submenu should be shown by mnemonic key press.
-  @author     anton.tarasov@...: area=awt.focus
-  @library    ../../../regtesthelpers
-  @library    /test/lib
-  @build      Util
-  @build      jdk.test.lib.Platform
-  @run        applet SubMenuShowTest.html
-  -->
-<head>
-<title>SubMenuShowTest</title>
-</head>
-<body>
- 
-<h1>SubMenuShowTest<br>Bug ID: 6380743</h1>
- 
-<p>See the dialog box (usually in upper left corner) for instructions</p>
- 
-<APPLET CODE=SubMenuShowTest.class WIDTH=200 HEIGHT=200></APPLET>
-</body>
-</html>
--- a/test/jdk/java/awt/KeyboardFocusmanager/TypeAhead/SubMenuShowTest/SubMenuShowTest.java	Sat Nov 10 18:48:35 2018 -0800
+++ b/test/jdk/java/awt/KeyboardFocusmanager/TypeAhead/SubMenuShowTest/SubMenuShowTest.java	Mon Nov 12 10:55:49 2018 +0530
@@ -22,50 +22,78 @@
  */
 
 /*
-  test
-  @bug       6380743 8158380
-  @summary   Submenu should be shown by mnemonic key press.
-  @author    anton.tarasov@...: area=awt.focus
-  @run       applet SubMenuShowTest.html
+  @test
+  @key headful
+  @bug 6380743 8158380 8198624
+  @summary Submenu should be shown by mnemonic key press.
+  @author anton.tarasov@...: area=awt.focus
+  @library ../../../regtesthelpers
+  @library /test/lib
+  @build Util
+  @build jdk.test.lib.Platform
+  @run main SubMenuShowTest
 */
 
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-import java.applet.Applet;
+import java.awt.Robot;
+import java.awt.BorderLayout;
+import java.awt.event.KeyEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import javax.swing.SwingUtilities;
+import javax.swing.JFrame;
+import javax.swing.JMenuBar;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
 import java.util.concurrent.atomic.AtomicBoolean;
-import java.lang.reflect.InvocationTargetException;
-
 import jdk.test.lib.Platform;
 import test.java.awt.regtesthelpers.Util;
 
-public class SubMenuShowTest extends Applet {
-    Robot robot;
-    JFrame frame = new JFrame("Test Frame");
-    JMenuBar bar = new JMenuBar();
-    JMenu menu = new JMenu("Menu");
-    JMenu submenu = new JMenu("More");
-    JMenuItem item = new JMenuItem("item");
-    AtomicBoolean activated = new AtomicBoolean(false);
+public class SubMenuShowTest {
+    private static Robot robot;
+    private static JFrame frame;
+    private static JMenuBar bar;
+    private static JMenu menu;
+    private static JMenu submenu;
+    private static JMenuItem item;
+    private static AtomicBoolean activated = new AtomicBoolean(false);
 
-    public static void main(String[] args) {
-        SubMenuShowTest app = new SubMenuShowTest();
-        app.init();
-        app.start();
+    public static void main(String[] args) throws Exception {
+        SwingUtilities.invokeAndWait(SubMenuShowTest::createAndShowGUI);
+
+        try {
+            robot = new Robot();
+            robot.setAutoDelay(100);
+            robot.setAutoWaitForIdle(true);
+
+            doTest();
+        } catch (Exception ex) {
+            throw new RuntimeException("Test failed: Exception thrown:"+ex);
+        } finally {
+            dispose();
+        }
+
+        System.out.println("Test passed.");
     }
 
-    public void init() {
-        robot = Util.createRobot();
-        robot.setAutoDelay(200);
-        robot.setAutoWaitForIdle(true);
+    public static void dispose() throws Exception {
+        if(frame != null) {
+            SwingUtilities.invokeAndWait(() -> {
+                frame.dispose();
+            });
+        }
+    }
 
+    public static void createAndShowGUI() {
         // Create instructions for the user here, as well as set up
         // the environment -- set the layout manager, add buttons,
         // etc.
-        this.setLayout (new BorderLayout ());
-    }
+        frame = new JFrame("Test Frame");
+        bar = new JMenuBar();
+        menu = new JMenu("Menu");
+        submenu = new JMenu("More");
+        item = new JMenuItem("item");
 
-    public void start() {
+        frame.setLayout (new BorderLayout ());
         menu.setMnemonic('f');
         submenu.setMnemonic('m');
         menu.add(submenu);
@@ -85,7 +113,9 @@
             });
 
         frame.setVisible(true);
+    }
 
+    public static void doTest() {
         boolean isMacOSX = Platform.isOSX();
         if (isMacOSX) {
             robot.keyPress(KeyEvent.VK_CONTROL);
@@ -104,11 +134,9 @@
         robot.keyPress(KeyEvent.VK_SPACE);
         robot.keyRelease(KeyEvent.VK_SPACE);
 
-        if (!Util.waitForCondition(activated, 2000)) {
-            throw new TestFailedException("a submenu wasn't activated by mnemonic key press");
+        if (!Util.waitForCondition(activated, 1500)) {
+            throw new TestFailedException("A submenu wasn't activated by mnemonic key press");
         }
-
-        System.out.println("Test passed.");
     }
 }
 
@@ -117,4 +145,3 @@
         super("Test failed: " + msg);
     }
 }
-