Path: blob/master/test/jdk/java/awt/Focus/CloseDialogActivateOwnerTest/CloseDialogActivateOwnerTest.java
41152 views
/*1* Copyright (c) 2008, 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 678505827@summary Tests that an owner is activated on closing its owned dialog with the warning icon.28@library ../../regtesthelpers29@build Util30@run main/othervm/policy=java.policy -Djava.security.manager CloseDialogActivateOwnerTest31*/3233import java.awt.*;34import test.java.awt.regtesthelpers.Util;3536public class CloseDialogActivateOwnerTest {37Robot robot;3839public static void main(String[] args) {40CloseDialogActivateOwnerTest app = new CloseDialogActivateOwnerTest();41app.init();42app.start();43}4445public void init() {46robot = Util.createRobot();47}4849public void start() {50final Frame frame = new Frame("Owner Frame");51final Dialog dialog = new Dialog(frame, "Owned Dialog");5253frame.setSize(100, 100);54dialog.setSize(100, 100);5556// Show the owner. Check that it's focused.57if (!Util.trackWindowGainedFocus(frame, new Runnable() {58public void run() {59frame.setVisible(true);60}61}, 2000, false))62{63throw new TestErrorException("the owner frame hasn't been activated on show");64}6566// Show the owned dialog. Check that it's focused.67if (!Util.trackWindowGainedFocus(dialog, new Runnable() {68public void run() {69dialog.setVisible(true);70}71}, 2000, true))72{73throw new TestErrorException("the owned dialog hasn't been activated on show");74}7576robot.delay(2000); // wait for the warning icon is shown7778// Close the dialog. Check that the owner is activated.79if (!Util.trackWindowGainedFocus(frame, new Runnable() {80public void run() {81dialog.dispose();82}83}, 2000, false))84{85throw new TestFailedException("the owner hasn't been activated on closing the owned dialog");86}8788System.out.println("Test passed.");89}90}9192/**93* Thrown when the behavior being verified is found wrong.94*/95class TestFailedException extends RuntimeException {96TestFailedException(String msg) {97super("Test failed: " + msg);98}99}100101/**102* Thrown when an error not related to the behavior being verified is encountered.103*/104class TestErrorException extends Error {105TestErrorException(String msg) {106super("Unexpected error: " + msg);107}108}109110111112