Path: blob/master/test/jdk/java/awt/Frame/NormalToIconified/NormalToIconifiedTest.java
41153 views
/*1* Copyright (c) 2016, 2019, 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 8171949 821404627* @summary Tests that bitwise mask is set and state listener is notified during state transition.28* @author Dmitry Markov29* @library ../../regtesthelpers30* @build Util31* @run main NormalToIconifiedTest32*/3334import java.awt.Frame;35import java.awt.Robot;36import java.awt.event.WindowEvent;37import java.awt.event.WindowStateListener;38import java.util.concurrent.atomic.AtomicBoolean;3940import test.java.awt.regtesthelpers.Util;4142public class NormalToIconifiedTest {4344public static void main(String[] args) {45test(false);46test(true);47}4849private static void test(final boolean undecorated) {50AtomicBoolean listenerNotified = new AtomicBoolean(false);5152Robot robot = Util.createRobot();53Frame testFrame = new Frame("Test Frame");54testFrame.setUndecorated(undecorated);55testFrame.setSize(200, 200);56testFrame.addWindowStateListener(new WindowStateListener() {57@Override58public void windowStateChanged(WindowEvent e) {59listenerNotified.set(true);60synchronized (listenerNotified) {61listenerNotified.notifyAll();62}63}64});65testFrame.setVisible(true);66Frame mainFrame = new Frame("Main Frame");67mainFrame.setSize(200, 200);68mainFrame.setLocationRelativeTo(null);69mainFrame.setVisible(true);70Util.waitForIdle(robot);71try {72Util.clickOnComp(mainFrame, robot);73Util.waitForIdle(robot);7475// NORMAL -> ICONIFIED76listenerNotified.set(false);77testFrame.setExtendedState(Frame.ICONIFIED);78Util.waitForIdle(robot);7980Util.waitForCondition(listenerNotified, 2000);81if (!listenerNotified.get()) {82throw new RuntimeException("Test FAILED! Window state listener was not notified during NORMAL to" +83"ICONIFIED transition");84}85if (testFrame.getExtendedState() != Frame.ICONIFIED) {86throw new RuntimeException("Test FAILED! Frame is not in ICONIFIED state");87}8889// ICONIFIED -> NORMAL90listenerNotified.set(false);91testFrame.setExtendedState(Frame.NORMAL);92Util.waitForIdle(robot);9394Util.waitForCondition(listenerNotified, 2000);95if (!listenerNotified.get()) {96throw new RuntimeException("Test FAILED! Window state listener was not notified during ICONIFIED to" +97"NORMAL transition");98}99if (testFrame.getExtendedState() != Frame.NORMAL) {100throw new RuntimeException("Test FAILED! Frame is not in NORMAL state");101}102} finally {103testFrame.dispose();104mainFrame.dispose();105}106}107}108109110111