Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 1 | /* |
Goetz Lindenmaier | 34afece | 2017-07-28 14:06:28 +0200 | [diff] [blame] | 2 | * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | * accompanied this code). |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License version |
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | * |
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | * or visit www.oracle.com if you need additional information or have any |
| 21 | * questions. |
| 22 | */ |
| 23 | |
Goetz Lindenmaier | 34afece | 2017-07-28 14:06:28 +0200 | [diff] [blame] | 24 | /** |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 25 | * @test |
Goetz Lindenmaier | 34afece | 2017-07-28 14:06:28 +0200 | [diff] [blame] | 26 | * @key headful |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 27 | * @bug 8007006 |
| 28 | * @summary [macosx] Closing subwindow loses main window menus. |
| 29 | * @author Leonid Romanov |
Yuri Nesterenko | c08a28b | 2014-12-05 14:55:08 +0300 | [diff] [blame] | 30 | * @library ../../../../lib/testlibrary |
| 31 | * @build ExtendedRobot jdk.testlibrary.OSInfo |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 32 | * @run main bug8007006 |
| 33 | */ |
| 34 | |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 35 | import java.awt.*; |
| 36 | import java.awt.event.*; |
| 37 | |
Yuri Nesterenko | c08a28b | 2014-12-05 14:55:08 +0300 | [diff] [blame] | 38 | import jdk.testlibrary.OSInfo; |
| 39 | |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 40 | public class bug8007006 { |
| 41 | private static Frame frame1; |
| 42 | private static Frame frame2; |
| 43 | |
| 44 | public static void main(String[] args) throws Exception { |
Yuri Nesterenko | c08a28b | 2014-12-05 14:55:08 +0300 | [diff] [blame] | 45 | if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) { |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 46 | System.out.println("This test is for MacOS only. Automatically passed on other platforms."); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | System.setProperty("apple.laf.useScreenMenuBar", "true"); |
| 51 | |
Yuri Nesterenko | c08a28b | 2014-12-05 14:55:08 +0300 | [diff] [blame] | 52 | ExtendedRobot robot = new ExtendedRobot(); |
| 53 | robot.setAutoDelay(50); |
| 54 | |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 55 | createAndShowGUI(); |
Yuri Nesterenko | c08a28b | 2014-12-05 14:55:08 +0300 | [diff] [blame] | 56 | robot.waitForIdle(1500); |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 57 | |
| 58 | frame2.dispose(); |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 59 | |
Yuri Nesterenko | c08a28b | 2014-12-05 14:55:08 +0300 | [diff] [blame] | 60 | robot.waitForIdle(1500); |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 61 | |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 62 | |
| 63 | // open "Apple" menu (the leftmost one) |
| 64 | robot.keyPress(KeyEvent.VK_META); |
| 65 | robot.keyPress(KeyEvent.VK_SHIFT); |
| 66 | robot.keyPress(KeyEvent.VK_SLASH); |
| 67 | robot.keyRelease(KeyEvent.VK_SLASH); |
| 68 | robot.keyRelease(KeyEvent.VK_SHIFT); |
| 69 | robot.keyRelease(KeyEvent.VK_META); |
| 70 | |
| 71 | // Select our menu |
| 72 | robot.keyPress(KeyEvent.VK_LEFT); |
| 73 | robot.keyRelease(KeyEvent.VK_LEFT); |
| 74 | |
| 75 | // Select menu item |
| 76 | robot.keyPress(KeyEvent.VK_DOWN); |
| 77 | robot.keyRelease(KeyEvent.VK_DOWN); |
| 78 | robot.keyPress(KeyEvent.VK_ENTER); |
| 79 | robot.keyRelease(KeyEvent.VK_ENTER); |
| 80 | |
Yuri Nesterenko | c08a28b | 2014-12-05 14:55:08 +0300 | [diff] [blame] | 81 | robot.waitForIdle(); |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 82 | |
| 83 | MenuBar mbar = frame1.getMenuBar(); |
| 84 | Menu menu = mbar.getMenu(0); |
| 85 | CheckboxMenuItem item = (CheckboxMenuItem)menu.getItem(0); |
| 86 | boolean isChecked = item.getState(); |
| 87 | |
| 88 | frame1.dispose(); |
| 89 | |
| 90 | if (isChecked) { |
| 91 | throw new Exception("Test failed: menu item remained checked"); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | private static void createAndShowGUI() { |
| 96 | frame1 = new Frame("Frame 1"); |
| 97 | frame1.setMenuBar(createMenuBar()); |
| 98 | frame1.setSize(200, 200); |
| 99 | |
| 100 | frame2 = new Frame("Frame 2"); |
| 101 | frame2.setMenuBar(createMenuBar()); |
| 102 | frame2.setSize(200, 200); |
| 103 | |
| 104 | frame1.setVisible(true); |
| 105 | frame2.setVisible(true); |
| 106 | } |
| 107 | |
| 108 | private static MenuBar createMenuBar() { |
| 109 | MenuBar mbar = new MenuBar(); |
| 110 | Menu menu = new Menu("Menu"); |
| 111 | MenuItem item = new CheckboxMenuItem("Checked", true); |
| 112 | |
| 113 | menu.add(item); |
| 114 | mbar.add(menu); |
| 115 | |
| 116 | return mbar; |
| 117 | } |
| 118 | |
Leonid Romanov | 0b24095 | 2013-11-12 20:02:12 +0400 | [diff] [blame] | 119 | } |