Path: blob/master/test/jdk/java/awt/Component/F10TopToplevel/F10TopToplevel.java
41155 views
/*1* Copyright (c) 2007, 2018, 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@key headful26@bug 653317527@summary Block F10 if closest toplevel to keystroke target is not a Frame.28@run main F10TopToplevel29*/3031import java.awt.*;32import java.awt.event.*;3334public class F10TopToplevel {3536static Frame frame;37static Dialog dialog;38static volatile boolean menuToggled = false;3940public static void main(final String[] args) {41MenuBar mb;42Menu menu;43MenuItem item;44frame = new Frame("am below");45frame.setMenuBar( (mb=new MenuBar()) );46menu = new Menu("nu");47menu.add((item = new MenuItem("item")));48item.addActionListener( new ActionListener() {49public void actionPerformed( ActionEvent ae ) {50menuToggled = true;51}52});53mb.add(menu);5455frame.setSize(200,200);56frame.setLocation( 400,100 );57frame.setVisible( true );5859dialog = new Dialog(frame);60dialog.setSize( 100,100 );61dialog.setVisible(true);6263Robot robot;64try {65robot = new Robot();66robot.setAutoDelay(5);67} catch(AWTException e){68throw new RuntimeException("cannot create robot.", e);69}70robot.waitForIdle();71robot.mouseMove(dialog.getLocationOnScreen().x + dialog.getWidth()/2,72dialog.getLocationOnScreen().y + dialog.getHeight()/2 );73robot.waitForIdle();74robot.mousePress(InputEvent.BUTTON1_MASK);75robot.mouseRelease(InputEvent.BUTTON1_MASK);76robot.waitForIdle();77robot.keyPress(KeyEvent.VK_F10);78robot.keyRelease(KeyEvent.VK_F10);7980robot.delay(10);81robot.keyPress(KeyEvent.VK_ENTER);82robot.waitForIdle();83robot.keyRelease(KeyEvent.VK_ENTER);8485robot.waitForIdle();8687if(menuToggled) {88throw new RuntimeException("Oops! Menu should not open.");89}9091}92}// class F10TopToplevel939495