Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/MenuBar/8007006/bug8007006.java
38821 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 800700626* @summary [macosx] Closing subwindow loses main window menus.27* @author Leonid Romanov28* @library ../../../../lib/testlibrary29* @build ExtendedRobot jdk.testlibrary.OSInfo30* @run main bug800700631*/3233import java.awt.*;34import java.awt.event.*;3536import jdk.testlibrary.OSInfo;3738public class bug8007006 {39private static Frame frame1;40private static Frame frame2;4142public static void main(String[] args) throws Exception {43if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {44System.out.println("This test is for MacOS only. Automatically passed on other platforms.");45return;46}4748System.setProperty("apple.laf.useScreenMenuBar", "true");4950ExtendedRobot robot = new ExtendedRobot();51robot.setAutoDelay(50);5253createAndShowGUI();54robot.waitForIdle(1500);5556frame2.dispose();5758robot.waitForIdle(1500);596061// open "Apple" menu (the leftmost one)62robot.keyPress(KeyEvent.VK_META);63robot.keyPress(KeyEvent.VK_SHIFT);64robot.keyPress(KeyEvent.VK_SLASH);65robot.keyRelease(KeyEvent.VK_SLASH);66robot.keyRelease(KeyEvent.VK_SHIFT);67robot.keyRelease(KeyEvent.VK_META);6869// Select our menu70robot.keyPress(KeyEvent.VK_LEFT);71robot.keyRelease(KeyEvent.VK_LEFT);7273// Select menu item74robot.keyPress(KeyEvent.VK_DOWN);75robot.keyRelease(KeyEvent.VK_DOWN);76robot.keyPress(KeyEvent.VK_ENTER);77robot.keyRelease(KeyEvent.VK_ENTER);7879robot.waitForIdle();8081MenuBar mbar = frame1.getMenuBar();82Menu menu = mbar.getMenu(0);83CheckboxMenuItem item = (CheckboxMenuItem)menu.getItem(0);84boolean isChecked = item.getState();8586frame1.dispose();8788if (isChecked) {89throw new Exception("Test failed: menu item remained checked");90}91}9293private static void createAndShowGUI() {94frame1 = new Frame("Frame 1");95frame1.setMenuBar(createMenuBar());96frame1.setSize(200, 200);9798frame2 = new Frame("Frame 2");99frame2.setMenuBar(createMenuBar());100frame2.setSize(200, 200);101102frame1.setVisible(true);103frame2.setVisible(true);104}105106private static MenuBar createMenuBar() {107MenuBar mbar = new MenuBar();108Menu menu = new Menu("Menu");109MenuItem item = new CheckboxMenuItem("Checked", true);110111menu.add(item);112mbar.add(menu);113114return mbar;115}116117}118119120