Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Focus/NonFocusableWindowTest/NonfocusableOwnerTest.java
47964 views
/*1* Copyright (c) 2008, 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 618235926@summary Tests that Window having non-focusable owner can't be a focus owner.27@author Anton.Tarasov: area=awt.focus28@library ../../regtesthelpers29@build Util30@run main NonfocusableOwnerTest31*/3233import java.awt.*;34import java.awt.event.*;35import java.applet.Applet;36import java.lang.reflect.*;37import java.io.*;38import test.java.awt.regtesthelpers.Util;3940public class NonfocusableOwnerTest extends Applet {41Robot robot = Util.createRobot();42Frame frame;43Dialog dialog;44Window window1;45Window window2;46Button button = new Button("button");4748public static void main(String[] args) {49NonfocusableOwnerTest test = new NonfocusableOwnerTest();50test.start();51}5253public void start() {54Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {55public void eventDispatched(AWTEvent e) {56System.out.println(e.toString());57}58}, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK | WindowEvent.WINDOW_EVENT_MASK);5960frame = new Frame("Frame");61frame.setName("Frame-owner");62frame.setBounds(100, 0, 100, 100);63dialog = new Dialog(frame, "Dialog");64dialog.setName("Dialog-owner");65dialog.setBounds(100, 0, 100, 100);6667window1 = new Window(frame);68window1.setName("1st child");69window1.setBounds(100, 300, 100, 100);70window2 = new Window(window1);71window2.setName("2nd child");72window2.setBounds(100, 500, 100, 100);7374test1(frame, window1);75test2(frame, window1, window2);76test3(frame, window1, window2);7778window1 = new Window(dialog);79window1.setBounds(100, 300, 100, 100);80window1.setName("1st child");81window2 = new Window(window1);82window2.setName("2nd child");83window2.setBounds(100, 500, 100, 100);8485test1(dialog, window1);86test2(dialog, window1, window2);87test3(dialog, window1, window2);8889System.out.println("Test passed.");90}9192void test1(Window owner, Window child) {93System.out.println("* * * STAGE 1 * * *\nWindow owner: " + owner);9495owner.setFocusableWindowState(false);96owner.setVisible(true);9798child.add(button);99child.setVisible(true);100101Util.waitTillShown(child);102103Util.clickOnComp(button, robot);104if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {105throw new RuntimeException("Test Failed.");106}107child.dispose();108owner.dispose();109}110111void test2(Window owner, Window child1, Window child2) {112System.out.println("* * * STAGE 2 * * *\nWindow nowner: " + owner);113114owner.setFocusableWindowState(false);115owner.setVisible(true);116117child1.setFocusableWindowState(true);118child1.setVisible(true);119120child2.add(button);121child2.setVisible(true);122123Util.waitTillShown(child2);124125Util.clickOnComp(button, robot);126if (button == KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {127throw new RuntimeException("Test failed.");128}129child2.dispose();130child1.dispose();131owner.dispose();132}133134void test3(Window owner, Window child1, Window child2) {135System.out.println("* * * STAGE 3 * * *\nWidow owner: " + owner);136137owner.setFocusableWindowState(true);138owner.setVisible(true);139140child1.setFocusableWindowState(false);141child1.setVisible(true);142143child2.setFocusableWindowState(true);144child2.add(button);145child2.setVisible(true);146147Util.waitTillShown(child2);148149Util.clickOnComp(button, robot);150System.err.println("focus owner: " + KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner());151if (button != KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()) {152throw new RuntimeException("Test failed.");153}154child1.dispose();155child2.dispose();156owner.dispose();157}158}159160161