Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Focus/8073453/AWTFocusTransitionTest.java
48429 views
/*1* Copyright (c) 2015, 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/* @test24* @bug 807345325* @summary Focus doesn't move when pressing Shift + Tab keys26* @author Dmitry Markov27* @compile AWTFocusTransitionTest.java28* @run main/othervm AWTFocusTransitionTest29*/30import sun.awt.SunToolkit;3132import java.awt.*;33import java.awt.event.KeyEvent;3435public class AWTFocusTransitionTest {36private static SunToolkit toolkit;37private static Robot robot;3839private static Frame frame;40private static TextField textField;41private static Button button;4243public static void main(String[] args) throws Exception {44toolkit = (SunToolkit)Toolkit.getDefaultToolkit();45robot = new Robot();46robot.setAutoDelay(50);4748try {49createAndShowGUI();5051toolkit.realSync();5253checkFocusOwner(textField);5455robot.keyPress(KeyEvent.VK_TAB);56robot.keyRelease(KeyEvent.VK_TAB);57toolkit.realSync();5859checkFocusOwner(button);6061robot.keyPress(KeyEvent.VK_SHIFT);62robot.keyPress(KeyEvent.VK_TAB);63robot.keyRelease(KeyEvent.VK_TAB);64robot.keyRelease(KeyEvent.VK_SHIFT);65toolkit.realSync();6667checkFocusOwner(textField);6869robot.keyPress(KeyEvent.VK_SHIFT);70robot.keyPress(KeyEvent.VK_TAB);71robot.keyRelease(KeyEvent.VK_TAB);72robot.keyRelease(KeyEvent.VK_SHIFT);73toolkit.realSync();7475checkFocusOwner(button);76} finally {77if (frame != null) {78frame.dispose();79}80}81System.out.println("Test Passed!");82}8384private static void createAndShowGUI() {85frame = new Frame("AWTFocusTransitionTest");86frame.setSize(300, 300);87frame.setFocusTraversalPolicyProvider(true);88frame.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());8990textField = new TextField();91button = new Button();9293Panel panel = new Panel();94panel.setFocusTraversalPolicyProvider(true);95panel.setFocusTraversalPolicy(new DefaultFocusTraversalPolicy());9697Panel p = new Panel();98p.setLayout(new GridLayout(3, 1));99p.add(textField);100p.add(button);101p.add(panel);102103frame.add(p);104frame.setVisible(true);105}106107private static void checkFocusOwner(Component component) {108if (component != frame.getFocusOwner()) {109throw new RuntimeException("Test Failed! Incorrect focus owner: " + frame.getFocusOwner() +110", but expected: " + component);111}112}113}114115116117