< prev index next >

test/jdk/java/awt/MenuBar/8007006/bug8007006.java

Print this page

        

*** 26,36 **** * @key headful * @bug 8007006 * @summary [macosx] Closing subwindow loses main window menus. * @author Leonid Romanov * @library /test/lib ! * @build ExtendedRobot jdk.test.lib.Platform * @run main bug8007006 */ import java.awt.*; import java.awt.event.*; --- 26,36 ---- * @key headful * @bug 8007006 * @summary [macosx] Closing subwindow loses main window menus. * @author Leonid Romanov * @library /test/lib ! * @build jdk.test.lib.Platform * @run main bug8007006 */ import java.awt.*; import java.awt.event.*;
*** 38,96 **** import jdk.test.lib.Platform; public class bug8007006 { private static Frame frame1; private static Frame frame2; public static void main(String[] args) throws Exception { if (!Platform.isOSX()) { System.out.println("This test is for MacOS only. Automatically passed on other platforms."); return; } System.setProperty("apple.laf.useScreenMenuBar", "true"); ! ExtendedRobot robot = new ExtendedRobot(); ! robot.setAutoDelay(50); createAndShowGUI(); ! robot.waitForIdle(1500); ! 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(); frame1.dispose(); ! ! if (isChecked) { ! throw new Exception("Test failed: menu item remained checked"); } } private static void createAndShowGUI() { frame1 = new Frame("Frame 1"); --- 38,70 ---- import jdk.test.lib.Platform; 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()) { System.out.println("This test is for MacOS only. Automatically passed on other platforms."); return; } System.setProperty("apple.laf.useScreenMenuBar", "true"); ! Robot robot = new Robot(); ! robot.setAutoDelay(300); createAndShowGUI(); ! robot.waitForIdle(); frame2.dispose(); robot.waitForIdle(); ! performMenuItemTest(robot); frame1.dispose(); ! if (!isActionPerformed) { ! throw new Exception("Test failed: menu item action was not performed"); } } private static void createAndShowGUI() { frame1 = new Frame("Frame 1");
*** 104,119 **** frame1.setVisible(true); frame2.setVisible(true); } private static MenuBar createMenuBar() { ! MenuBar mbar = new MenuBar(); ! Menu menu = new Menu("Menu"); ! MenuItem item = new CheckboxMenuItem("Checked", true); ! menu.add(item); ! mbar.add(menu); ! return mbar; } } --- 78,130 ---- frame1.setVisible(true); frame2.setVisible(true); } private static MenuBar createMenuBar() { ! // 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); ! 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) { + } + } }
< prev index next >