Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Focus/CloseDialogActivateOwnerTest/CloseDialogActivateOwnerTest.java
47497 views
/*1* Copyright (c) 2008, 2009, 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 678505826@summary Tests that an owner is activated on closing its owned dialog with the warning icon.27@author Anton Tarasov: area=awt.focus28@library ../../regtesthelpers29@build Util30@run main/othervm/policy=java.policy -Djava.security.manager CloseDialogActivateOwnerTest31*/3233import java.awt.*;34import java.awt.event.*;35import java.applet.Applet;36import java.util.concurrent.atomic.AtomicBoolean;37import java.lang.reflect.InvocationTargetException;38import test.java.awt.regtesthelpers.Util;3940public class CloseDialogActivateOwnerTest extends Applet {41Robot robot;4243public static void main(String[] args) {44CloseDialogActivateOwnerTest app = new CloseDialogActivateOwnerTest();45app.init();46app.start();47}4849public void init() {50robot = Util.createRobot();51}5253public void start() {54final Frame frame = new Frame("Owner Frame");55final Dialog dialog = new Dialog(frame, "Owned Dialog");5657frame.setSize(100, 100);58dialog.setSize(100, 100);5960// Show the owner. Check that it's focused.61if (!Util.trackWindowGainedFocus(frame, new Runnable() {62public void run() {63frame.setVisible(true);64}65}, 2000, false))66{67throw new TestErrorException("the owner frame hasn't been activated on show");68}6970// Show the owned dialog. Check that it's focused.71if (!Util.trackWindowGainedFocus(dialog, new Runnable() {72public void run() {73dialog.setVisible(true);74}75}, 2000, true))76{77throw new TestErrorException("the owned dialog hasn't been activated on show");78}7980robot.delay(2000); // wait for the warning icon is shown8182// Close the dialog. Check that the owner is activated.83if (!Util.trackWindowGainedFocus(frame, new Runnable() {84public void run() {85dialog.dispose();86}87}, 2000, false))88{89throw new TestFailedException("the owner hasn't been activated on closing the owned dialog");90}9192System.out.println("Test passed.");93}94}9596/**97* Thrown when the behavior being verified is found wrong.98*/99class TestFailedException extends RuntimeException {100TestFailedException(String msg) {101super("Test failed: " + msg);102}103}104105/**106* Thrown when an error not related to the behavior being verified is encountered.107*/108class TestErrorException extends Error {109TestErrorException(String msg) {110super("Unexpected error: " + msg);111}112}113114115116