Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Frame/NormalToIconified/NormalToIconifiedTest.java
38828 views
/*1* Copyright (c) 2016, 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 817194926* @summary Tests that bitwise mask is set and state listener is notified during state transition.27* @author Dmitry Markov28* @library ../../regtesthelpers29* @build Util30* @run main NormalToIconifiedTest31*/3233import java.awt.Frame;34import java.awt.Robot;35import java.awt.event.WindowEvent;36import java.awt.event.WindowStateListener;37import java.util.concurrent.atomic.AtomicBoolean;3839import test.java.awt.regtesthelpers.Util;4041public class NormalToIconifiedTest {42private static final AtomicBoolean listenerNotified = new AtomicBoolean(false);4344public static void main(String[] args) {45Robot robot = Util.createRobot();4647Frame testFrame = new Frame("Test Frame");48testFrame.setSize(200, 200);49testFrame.addWindowStateListener(new WindowStateListener() {50@Override51public void windowStateChanged(WindowEvent e) {52listenerNotified.set(true);53synchronized (listenerNotified) {54listenerNotified.notifyAll();55}56}57});58testFrame.setVisible(true);5960Frame mainFrame = new Frame("Main Frame");61mainFrame.setSize(200, 200);62mainFrame.setLocationRelativeTo(null);63mainFrame.setVisible(true);6465Util.waitForIdle(robot);6667try {68Util.clickOnComp(mainFrame, robot);69Util.waitForIdle(robot);7071// NORMAL -> ICONIFIED72listenerNotified.set(false);73testFrame.setExtendedState(Frame.ICONIFIED);74Util.waitForIdle(robot);7576Util.waitForCondition(listenerNotified, 2000);77if (!listenerNotified.get()) {78throw new RuntimeException("Test FAILED! Window state listener was not notified during NORMAL to" +79"ICONIFIED transition");80}81if (testFrame.getExtendedState() != Frame.ICONIFIED) {82throw new RuntimeException("Test FAILED! Frame is not in ICONIFIED state");83}8485// ICONIFIED -> NORMAL86listenerNotified.set(false);87testFrame.setExtendedState(Frame.NORMAL);88Util.waitForIdle(robot);8990Util.waitForCondition(listenerNotified, 2000);91if (!listenerNotified.get()) {92throw new RuntimeException("Test FAILED! Window state listener was not notified during ICONIFIED to" +93"NORMAL transition");94}95if (testFrame.getExtendedState() != Frame.NORMAL) {96throw new RuntimeException("Test FAILED! Frame is not in NORMAL state");97}98} finally {99testFrame.dispose();100mainFrame.dispose();101}102}103}104105106107