Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java
48795 views
/*1* Copyright (c) 2007, 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 656643426@library ../../regtesthelpers27@build Util Sysout AbstractTest28@summary Choice in unfocusable window responds to keyboard29@author Andrei Dmitriev: area=awt-choice30@run main UnfocusableToplevel31*/3233/**34* UnfocusableToplevel.java35*36* summary:37*/3839import java.awt.*;40import java.awt.event.*;41import test.java.awt.regtesthelpers.AbstractTest;42import test.java.awt.regtesthelpers.Sysout;43import test.java.awt.regtesthelpers.Util;4445public class UnfocusableToplevel {4647final static Robot robot = Util.createRobot();48final static int REASONABLE_PATH_TIME = 5000;4950public static void main(String []s)51{52Frame f = new Frame();53Window w = new Window(f);54final Choice ch = new Choice();5556ch.add("item 1");57ch.add("item 2");58ch.add("item 3");59ch.add("item 4");60ch.add("item 5");61w.add(ch);62w.setLayout(new FlowLayout());63w.setSize(200, 200);6465ch.addKeyListener(new KeyAdapter(){66public void keyTyped(KeyEvent e){67traceEvent("keytyped", e);68}69public void keyPressed(KeyEvent e){70traceEvent("keypress", e);71}72public void keyReleased(KeyEvent e){73traceEvent("keyrelease", e);74}75});7677ch.addItemListener(new ItemListener(){78public void itemStateChanged(ItemEvent ie){79traceEvent("stateChanged", ie);80}81});8283w.setVisible(true);8485Util.waitForIdle(robot);8687Util.clickOnComp(ch, robot);88Util.waitForIdle(robot);8990// will not test if the dropdown become opened as there is no reliable91// technique to accomplish that rather then checking color of dropdown92// Will suppose that the dropdown appears9394testKeys();95Util.waitForIdle(robot);96}9798private static void testKeys(){99typeKey(KeyEvent.VK_UP);100typeKey(KeyEvent.VK_DOWN);101typeKey(KeyEvent.VK_K);102typeKey(KeyEvent.VK_PAGE_UP);103typeKey(KeyEvent.VK_PAGE_DOWN);104}105106private static void typeKey(int keyChar){107try {108robot.keyPress(keyChar);109robot.delay(5);110} finally {111robot.keyRelease(keyChar);112}113robot.delay(100);114}115116private static void traceEvent(String message, AWTEvent e){117AbstractTest.fail(message + " " + e.toString());118}119}120121122