Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/awt/Focus/NonFocusableResizableTooSmall/NonFocusableResizableTooSmall.java
41152 views
1
/*
2
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
@test
26
@key headful
27
@bug 6581927
28
@summary Non-focusable frame should honor the size of the frame buttons/decorations when resizing
29
@library ../../regtesthelpers
30
@build Util
31
@author anthony.petrov@...: area=awt.toplevel
32
@run main NonFocusableResizableTooSmall
33
*/
34
35
/**
36
* NonFocusableResizableTooSmall.java
37
*
38
* summary: Non-focusable frame should honor the size of the frame buttons/decorations when resizing
39
*/
40
41
import java.awt.*;
42
import java.awt.event.*;
43
import test.java.awt.regtesthelpers.Util;
44
45
public class NonFocusableResizableTooSmall
46
{
47
48
//*** test-writer defined static variables go here ***
49
50
51
private static void init()
52
{
53
final Frame frame = new Frame();
54
frame.setFocusableWindowState(false);
55
frame.setSize(200, 100);
56
frame.setVisible(true);
57
58
final Robot robot = Util.createRobot();
59
robot.setAutoDelay(20);
60
61
// To be sure the window is shown and packed
62
Util.waitForIdle(robot);
63
64
final Insets insets = frame.getInsets();
65
System.out.println("The insets of the frame: " + insets);
66
if (insets.right == 0 || insets.bottom == 0) {
67
System.out.println("The test environment must have non-zero right & bottom insets!");
68
pass();
69
return;
70
}
71
72
// Let's move the mouse pointer to the bottom-right coner of the frame (the "size-grip")
73
final Rectangle bounds1 = frame.getBounds();
74
System.out.println("The bounds before resizing: " + bounds1);
75
76
robot.mouseMove(bounds1.x + bounds1.width - 1, bounds1.y + bounds1.height - 1);
77
78
// ... and start resizing to some very small
79
robot.mousePress( InputEvent.BUTTON1_MASK );
80
81
// Now resize the frame so that the width is smaller
82
// than the widths of the left and the right borders.
83
// The sum of widths of the icon of the frame + the control-buttons
84
// (close, minimize, etc.) should be definitely larger!
85
robot.mouseMove(bounds1.x + insets.left + insets.right - 5, bounds1.y + bounds1.height - 1);
86
Util.waitForIdle(robot);
87
88
robot.mouseRelease( InputEvent.BUTTON1_MASK );
89
90
Util.waitForIdle(robot);
91
92
// Check the current bounds of the frame
93
final Rectangle bounds2 = frame.getBounds();
94
System.out.println("The bounds after resizing: " + bounds2);
95
96
if (bounds2.width <= (insets.left + insets.right)) {
97
fail("The frame has been resized to very small.");
98
}
99
pass();
100
}//End init()
101
102
103
104
/*****************************************************
105
* Standard Test Machinery Section
106
* DO NOT modify anything in this section -- it's a
107
* standard chunk of code which has all of the
108
* synchronisation necessary for the test harness.
109
* By keeping it the same in all tests, it is easier
110
* to read and understand someone else's test, as
111
* well as insuring that all tests behave correctly
112
* with the test harness.
113
* There is a section following this for test-
114
* classes
115
******************************************************/
116
private static boolean theTestPassed = false;
117
private static boolean testGeneratedInterrupt = false;
118
private static String failureMessage = "";
119
120
private static Thread mainThread = null;
121
122
private static int sleepTime = 300000;
123
124
// Not sure about what happens if multiple of this test are
125
// instantiated in the same VM. Being static (and using
126
// static vars), it aint gonna work. Not worrying about
127
// it for now.
128
public static void main( String args[] ) throws InterruptedException
129
{
130
mainThread = Thread.currentThread();
131
try
132
{
133
init();
134
}
135
catch( TestPassedException e )
136
{
137
//The test passed, so just return from main and harness will
138
// interepret this return as a pass
139
return;
140
}
141
//At this point, neither test pass nor test fail has been
142
// called -- either would have thrown an exception and ended the
143
// test, so we know we have multiple threads.
144
145
//Test involves other threads, so sleep and wait for them to
146
// called pass() or fail()
147
try
148
{
149
Thread.sleep( sleepTime );
150
//Timed out, so fail the test
151
throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
152
}
153
catch (InterruptedException e)
154
{
155
//The test harness may have interrupted the test. If so, rethrow the exception
156
// so that the harness gets it and deals with it.
157
if( ! testGeneratedInterrupt ) throw e;
158
159
//reset flag in case hit this code more than once for some reason (just safety)
160
testGeneratedInterrupt = false;
161
162
if ( theTestPassed == false )
163
{
164
throw new RuntimeException( failureMessage );
165
}
166
}
167
168
}//main
169
170
public static synchronized void setTimeoutTo( int seconds )
171
{
172
sleepTime = seconds * 1000;
173
}
174
175
public static synchronized void pass()
176
{
177
System.out.println( "The test passed." );
178
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
179
//first check if this is executing in main thread
180
if ( mainThread == Thread.currentThread() )
181
{
182
//Still in the main thread, so set the flag just for kicks,
183
// and throw a test passed exception which will be caught
184
// and end the test.
185
theTestPassed = true;
186
throw new TestPassedException();
187
}
188
theTestPassed = true;
189
testGeneratedInterrupt = true;
190
mainThread.interrupt();
191
}//pass()
192
193
public static synchronized void fail()
194
{
195
//test writer didn't specify why test failed, so give generic
196
fail( "it just plain failed! :-)" );
197
}
198
199
public static synchronized void fail( String whyFailed )
200
{
201
System.out.println( "The test failed: " + whyFailed );
202
System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
203
//check if this called from main thread
204
if ( mainThread == Thread.currentThread() )
205
{
206
//If main thread, fail now 'cause not sleeping
207
throw new RuntimeException( whyFailed );
208
}
209
theTestPassed = false;
210
testGeneratedInterrupt = true;
211
failureMessage = whyFailed;
212
mainThread.interrupt();
213
}//fail()
214
215
}// class NonFocusableResizableTooSmall
216
217
//This exception is used to exit from any level of call nesting
218
// when it's determined that the test has passed, and immediately
219
// end the test.
220
class TestPassedException extends RuntimeException
221
{
222
}
223
224