Path: blob/master/test/jdk/java/awt/Frame/ExceptionOnSetExtendedStateTest/ExceptionOnSetExtendedStateTest.java
41152 views
/*1* Copyright (c) 2014, 2017, 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 803207827* @summary Frame.setExtendedState throws RuntimeException, if28* windowState=ICONIFIED|MAXIMIZED_BOTH, on OS X29* @author Anton Litvinov30*/3132import java.awt.*;3334public class ExceptionOnSetExtendedStateTest {35private static final int[] frameStates = { Frame.NORMAL, Frame.ICONIFIED, Frame.MAXIMIZED_BOTH };3637private static boolean validatePlatform() {38String osName = System.getProperty("os.name");39if (osName == null) {40throw new RuntimeException("Name of the current OS could not be retrieved.");41}42return osName.startsWith("Mac");43}4445private static void testStateChange(int oldState, int newState, boolean decoratedFrame) {46System.out.println(String.format(47"testStateChange: oldState='%d', newState='%d', decoratedFrame='%b'",48oldState, newState, decoratedFrame));4950Frame frame = new Frame("ExceptionOnSetExtendedStateTest");51frame.setSize(200, 200);52frame.setUndecorated(!decoratedFrame);53frame.setVisible(true);54try {55Robot robot = new Robot();56robot.waitForIdle();57}catch(Exception ex) {58ex.printStackTrace();59throw new RuntimeException("Unexpected failure");60}6162frame.setExtendedState(oldState);63sleep(1000);64frame.setExtendedState(newState);6566boolean stateWasNotChanged = true;67int currentState = 0;68for (int i = 0; (i < 3) && stateWasNotChanged; i++) {69sleep(1000);70currentState = frame.getExtendedState();71if ((currentState == newState) ||72(((newState & Frame.ICONIFIED) != 0) && ((currentState & Frame.ICONIFIED) != 0))) {73stateWasNotChanged = false;74}75}76frame.dispose();7778if (stateWasNotChanged) {79throw new RuntimeException(String.format(80"Frame state was not changed. currentState='%d'", currentState));81}82}8384private static void sleep(int millis) {85try {86Thread.sleep(millis);87} catch (Exception e) {88e.printStackTrace();89}90}9192public static void main(String[] args) {93if (!validatePlatform()) {94System.out.println("This test is only for OS X.");95return;96}9798// Verify that changing states of decorated/undecorated frame to/from supported states99// and the state bit mask ICONIFIED | MAXIMIZED_BOTH does not raise RuntimeException.100for (int i = 0; i < frameStates.length; i++) {101testStateChange(frameStates[i], Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, true);102testStateChange(frameStates[i], Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, false);103testStateChange(Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, frameStates[i], true);104testStateChange(Frame.ICONIFIED | Frame.MAXIMIZED_BOTH, frameStates[i], false);105}106}107}108109110