Path: blob/master/test/jdk/java/awt/Focus/NonFocusableResizableTooSmall/NonFocusableResizableTooSmall.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 658192727@summary Non-focusable frame should honor the size of the frame buttons/decorations when resizing28@library ../../regtesthelpers29@build Util30@author anthony.petrov@...: area=awt.toplevel31@run main NonFocusableResizableTooSmall32*/3334/**35* NonFocusableResizableTooSmall.java36*37* summary: Non-focusable frame should honor the size of the frame buttons/decorations when resizing38*/3940import java.awt.*;41import java.awt.event.*;42import test.java.awt.regtesthelpers.Util;4344public class NonFocusableResizableTooSmall45{4647//*** test-writer defined static variables go here ***484950private static void init()51{52final Frame frame = new Frame();53frame.setFocusableWindowState(false);54frame.setSize(200, 100);55frame.setVisible(true);5657final Robot robot = Util.createRobot();58robot.setAutoDelay(20);5960// To be sure the window is shown and packed61Util.waitForIdle(robot);6263final Insets insets = frame.getInsets();64System.out.println("The insets of the frame: " + insets);65if (insets.right == 0 || insets.bottom == 0) {66System.out.println("The test environment must have non-zero right & bottom insets!");67pass();68return;69}7071// Let's move the mouse pointer to the bottom-right coner of the frame (the "size-grip")72final Rectangle bounds1 = frame.getBounds();73System.out.println("The bounds before resizing: " + bounds1);7475robot.mouseMove(bounds1.x + bounds1.width - 1, bounds1.y + bounds1.height - 1);7677// ... and start resizing to some very small78robot.mousePress( InputEvent.BUTTON1_MASK );7980// Now resize the frame so that the width is smaller81// than the widths of the left and the right borders.82// The sum of widths of the icon of the frame + the control-buttons83// (close, minimize, etc.) should be definitely larger!84robot.mouseMove(bounds1.x + insets.left + insets.right - 5, bounds1.y + bounds1.height - 1);85Util.waitForIdle(robot);8687robot.mouseRelease( InputEvent.BUTTON1_MASK );8889Util.waitForIdle(robot);9091// Check the current bounds of the frame92final Rectangle bounds2 = frame.getBounds();93System.out.println("The bounds after resizing: " + bounds2);9495if (bounds2.width <= (insets.left + insets.right)) {96fail("The frame has been resized to very small.");97}98pass();99}//End init()100101102103/*****************************************************104* Standard Test Machinery Section105* DO NOT modify anything in this section -- it's a106* standard chunk of code which has all of the107* synchronisation necessary for the test harness.108* By keeping it the same in all tests, it is easier109* to read and understand someone else's test, as110* well as insuring that all tests behave correctly111* with the test harness.112* There is a section following this for test-113* classes114******************************************************/115private static boolean theTestPassed = false;116private static boolean testGeneratedInterrupt = false;117private static String failureMessage = "";118119private static Thread mainThread = null;120121private static int sleepTime = 300000;122123// Not sure about what happens if multiple of this test are124// instantiated in the same VM. Being static (and using125// static vars), it aint gonna work. Not worrying about126// it for now.127public static void main( String args[] ) throws InterruptedException128{129mainThread = Thread.currentThread();130try131{132init();133}134catch( TestPassedException e )135{136//The test passed, so just return from main and harness will137// interepret this return as a pass138return;139}140//At this point, neither test pass nor test fail has been141// called -- either would have thrown an exception and ended the142// test, so we know we have multiple threads.143144//Test involves other threads, so sleep and wait for them to145// called pass() or fail()146try147{148Thread.sleep( sleepTime );149//Timed out, so fail the test150throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );151}152catch (InterruptedException e)153{154//The test harness may have interrupted the test. If so, rethrow the exception155// so that the harness gets it and deals with it.156if( ! testGeneratedInterrupt ) throw e;157158//reset flag in case hit this code more than once for some reason (just safety)159testGeneratedInterrupt = false;160161if ( theTestPassed == false )162{163throw new RuntimeException( failureMessage );164}165}166167}//main168169public static synchronized void setTimeoutTo( int seconds )170{171sleepTime = seconds * 1000;172}173174public static synchronized void pass()175{176System.out.println( "The test passed." );177System.out.println( "The test is over, hit Ctl-C to stop Java VM" );178//first check if this is executing in main thread179if ( mainThread == Thread.currentThread() )180{181//Still in the main thread, so set the flag just for kicks,182// and throw a test passed exception which will be caught183// and end the test.184theTestPassed = true;185throw new TestPassedException();186}187theTestPassed = true;188testGeneratedInterrupt = true;189mainThread.interrupt();190}//pass()191192public static synchronized void fail()193{194//test writer didn't specify why test failed, so give generic195fail( "it just plain failed! :-)" );196}197198public static synchronized void fail( String whyFailed )199{200System.out.println( "The test failed: " + whyFailed );201System.out.println( "The test is over, hit Ctl-C to stop Java VM" );202//check if this called from main thread203if ( mainThread == Thread.currentThread() )204{205//If main thread, fail now 'cause not sleeping206throw new RuntimeException( whyFailed );207}208theTestPassed = false;209testGeneratedInterrupt = true;210failureMessage = whyFailed;211mainThread.interrupt();212}//fail()213214}// class NonFocusableResizableTooSmall215216//This exception is used to exit from any level of call nesting217// when it's determined that the test has passed, and immediately218// end the test.219class TestPassedException extends RuntimeException220{221}222223224