Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Frame/ExceptionOnSetExtendedStateTest/ExceptionOnSetExtendedStateTest.java
38828 views
/*1* Copyright (c) 2014, 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/* @test24@bug 803207825@summary Frame.setExtendedState throws RuntimeException, if26windowState=ICONIFIED|MAXIMIZED_BOTH, on OS X27@author Anton Litvinov28*/2930import java.awt.*;3132public class ExceptionOnSetExtendedStateTest {33private static final int[] frameStates = { Frame.NORMAL, Frame.ICONIFIED, Frame.MAXIMIZED_BOTH };3435private static boolean validatePlatform() {36String osName = System.getProperty("os.name");37if (osName == null) {38throw new RuntimeException("Name of the current OS could not be retrieved.");39}40return osName.startsWith("Mac");41}4243private static void testStateChange(int oldState, int newState, boolean decoratedFrame) {44System.out.println(String.format(45"testStateChange: oldState='%d', newState='%d', decoratedFrame='%b'",46oldState, newState, decoratedFrame));4748Frame frame = new Frame("ExceptionOnSetExtendedStateTest");49frame.setSize(200, 200);50frame.setUndecorated(!decoratedFrame);51frame.setVisible(true);52try {53Robot robot = new Robot();54robot.waitForIdle();55}catch(Exception ex) {56ex.printStackTrace();57throw new RuntimeException("Unexpected failure");58}5960frame.setExtendedState(oldState);61sleep(1000);62frame.setExtendedState(newState);6364boolean stateWasNotChanged = true;65int currentState = 0;66for (int i = 0; (i < 3) && stateWasNotChanged; i++) {67sleep(1000);68currentState = frame.getExtendedState();69if ((currentState == newState) ||70(((newState & Frame.ICONIFIED) != 0) && ((currentState & Frame.ICONIFIED) != 0))) {71stateWasNotChanged = false;72}73}74frame.dispose();7576if (stateWasNotChanged) {77throw new RuntimeException(String.format(78"Frame state was not changed. currentState='%d'", currentState));79}80}8182private static void sleep(int millis) {83try {84Thread.sleep(millis);85} catch (Exception e) {86e.printStackTrace();87}88}8990public static void main(String[] args) {91if (!validatePlatform()) {92System.out.println("This test is only for OS X.");93return;94}9596// Verify that changing states of decorated/undecorated frame to/from supported states97// and the state bit mask ICONIFIED | MAXIMIZED_BOTH does not raise RuntimeException.98for (int i = 0; i < frameStates.length; i++) {99testStateChange(frameStates[i], Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, true);100testStateChange(frameStates[i], Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, false);101testStateChange(Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, frameStates[i], true);102testStateChange(Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, frameStates[i], false);103}104}105}106107108