22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 @test |
25 @test |
26 @key headful |
26 @key headful |
27 @bug 4980161 |
27 @bug 4980161 7158623 |
28 @summary Setting focusable window state to false makes the maximized frame resizable |
28 @summary Setting focusable window state to false makes the maximized frame resizable |
29 @author anthony.petrov@...: area=awt.toplevel |
29 @compile UnfocusableMaximizedFrameResizablity.java |
30 @library ../../regtesthelpers |
|
31 @build Util |
|
32 @run main UnfocusableMaximizedFrameResizablity |
30 @run main UnfocusableMaximizedFrameResizablity |
33 */ |
31 */ |
34 |
32 |
35 /** |
33 import java.awt.Toolkit; |
36 * UnfocusableMaximizedFrameResizablity.java |
34 import java.awt.Frame; |
37 * |
35 import java.awt.Rectangle; |
38 * summary: Tests whether a maximized unfocusable frame connot be resized by the user |
36 import java.awt.AWTException; |
39 */ |
37 import java.awt.event.InputEvent; |
|
38 import java.awt.Robot; |
40 |
39 |
41 import java.awt.*; |
40 public class UnfocusableMaximizedFrameResizablity { |
42 import java.awt.event.*; |
|
43 import test.java.awt.regtesthelpers.Util; |
|
44 |
41 |
45 public class UnfocusableMaximizedFrameResizablity |
42 private static Frame frame; |
46 { |
43 private static Robot robot; |
|
44 private static boolean isProgInterruption = false; |
|
45 private static Thread mainThread = null; |
|
46 private static int sleepTime = 300000; |
47 |
47 |
48 //*** test-writer defined static variables go here *** |
48 private static void createAndShowFrame() { |
49 |
49 |
50 |
50 //The MAXIMIZED_BOTH state is not supported by the toolkit. Nothing to test. |
51 private static void init() |
|
52 { |
|
53 //*** Create instructions for the user here *** |
|
54 |
|
55 String[] instructions = |
|
56 { |
|
57 "This is an AUTOMATIC test, simply wait until it is done.", |
|
58 "The result (passed or failed) will be shown in the", |
|
59 "message window below." |
|
60 }; |
|
61 Sysout.createDialog( ); |
|
62 Sysout.printInstructions( instructions ); |
|
63 |
|
64 if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { |
51 if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { |
65 System.out.println("The MAXIMIZED_BOTH state is not supported by the toolkit. Nothing to test."); |
|
66 pass(); |
|
67 return; |
52 return; |
68 } |
53 } |
69 |
54 |
70 // Create the maximized unfocusable frame |
55 frame = new Frame("Unfocusable frame"); |
71 final Frame f = new Frame("Unfocusable frame"); |
56 frame.setMaximizedBounds(new Rectangle(0, 0, 300, 300)); |
72 f.setMaximizedBounds(new Rectangle(0, 0, 300, 300)); |
57 frame.setSize(200, 200); |
73 f.setSize(200, 200); |
58 frame.setVisible(true); |
74 f.setVisible(true); |
59 frame.setExtendedState(Frame.MAXIMIZED_BOTH); |
75 f.setExtendedState(Frame.MAXIMIZED_BOTH); |
60 frame.setFocusableWindowState(false); |
76 f.setFocusableWindowState(false); |
|
77 |
61 |
78 Robot robot = Util.createRobot(); |
62 try { |
79 robot.setAutoDelay(20); |
63 robot = new Robot(); |
80 |
64 } catch (AWTException e) { |
81 Util.waitForIdle(robot); |
65 throw new RuntimeException("Robot creation failed"); |
|
66 } |
|
67 robot.delay(2000); |
82 |
68 |
83 // The initial bounds of the frame |
69 // The initial bounds of the frame |
84 final Rectangle bounds = f.getBounds(); |
70 final Rectangle bounds = frame.getBounds(); |
85 System.out.println("Initial frame bounds: " + bounds); |
|
86 |
71 |
87 // Let's move the mouse pointer to the bottom-right coner of the frame (the "size-grip") |
72 // Let's move the mouse pointer to the bottom-right coner of the frame (the "size-grip") |
88 robot.mouseMove(bounds.x + bounds.width - 2, bounds.y + bounds.height - 2); |
73 robot.mouseMove(bounds.x + bounds.width - 2, bounds.y + bounds.height - 2); |
|
74 robot.waitForIdle(); |
89 |
75 |
90 // ... and start resizing |
76 // ... and start resizing |
91 robot.mousePress( InputEvent.BUTTON1_MASK ); |
77 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); |
92 Util.waitForIdle(robot); |
78 robot.waitForIdle(); |
93 robot.mouseMove(bounds.x + bounds.width + 20, bounds.y + bounds.height + 15); |
79 robot.mouseMove(bounds.x + bounds.width + 20, bounds.y + bounds.height + 15); |
94 Util.waitForIdle(robot); |
80 robot.waitForIdle(); |
95 robot.mouseRelease( InputEvent.BUTTON1_MASK ); |
81 |
96 Util.waitForIdle(robot); |
82 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); |
|
83 robot.waitForIdle(); |
97 |
84 |
98 // The bounds of the frame after the attempt of resizing is made |
85 // The bounds of the frame after the attempt of resizing is made |
99 final Rectangle finalBounds = f.getBounds(); |
86 final Rectangle finalBounds = frame.getBounds(); |
100 System.out.println("Final frame bounds: " + finalBounds); |
|
101 |
87 |
102 if (!finalBounds.equals(bounds)) { |
88 if (!finalBounds.equals(bounds)) { |
103 fail("The maximized unfocusable frame can be resized."); |
89 cleanup(); |
104 return; |
90 throw new RuntimeException("The maximized unfocusable frame can be resized."); |
105 } |
91 } |
|
92 cleanup(); |
|
93 } |
106 |
94 |
107 UnfocusableMaximizedFrameResizablity.pass(); |
95 private static void cleanup() { |
|
96 frame.dispose(); |
|
97 isProgInterruption = true; |
|
98 mainThread.interrupt(); |
|
99 } |
108 |
100 |
109 }//End init() |
101 public static void main(String args[]) throws InterruptedException { |
110 |
102 |
|
103 mainThread = Thread.currentThread(); |
111 |
104 |
112 |
105 try { |
113 /***************************************************** |
106 createAndShowFrame(); |
114 * Standard Test Machinery Section |
107 mainThread.sleep(sleepTime); |
115 * DO NOT modify anything in this section -- it's a |
108 } catch (InterruptedException e) { |
116 * standard chunk of code which has all of the |
109 if (!isProgInterruption) { |
117 * synchronisation necessary for the test harness. |
110 throw e; |
118 * By keeping it the same in all tests, it is easier |
|
119 * to read and understand someone else's test, as |
|
120 * well as insuring that all tests behave correctly |
|
121 * with the test harness. |
|
122 * There is a section following this for test- |
|
123 * classes |
|
124 ******************************************************/ |
|
125 private static boolean theTestPassed = false; |
|
126 private static boolean testGeneratedInterrupt = false; |
|
127 private static String failureMessage = ""; |
|
128 |
|
129 private static Thread mainThread = null; |
|
130 |
|
131 private static int sleepTime = 300000; |
|
132 |
|
133 // Not sure about what happens if multiple of this test are |
|
134 // instantiated in the same VM. Being static (and using |
|
135 // static vars), it aint gonna work. Not worrying about |
|
136 // it for now. |
|
137 public static void main( String args[] ) throws InterruptedException |
|
138 { |
|
139 mainThread = Thread.currentThread(); |
|
140 try |
|
141 { |
|
142 init(); |
|
143 } |
|
144 catch( TestPassedException e ) |
|
145 { |
|
146 //The test passed, so just return from main and harness will |
|
147 // interepret this return as a pass |
|
148 return; |
|
149 } |
|
150 //At this point, neither test pass nor test fail has been |
|
151 // called -- either would have thrown an exception and ended the |
|
152 // test, so we know we have multiple threads. |
|
153 |
|
154 //Test involves other threads, so sleep and wait for them to |
|
155 // called pass() or fail() |
|
156 try |
|
157 { |
|
158 Thread.sleep( sleepTime ); |
|
159 //Timed out, so fail the test |
|
160 throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" ); |
|
161 } |
|
162 catch (InterruptedException e) |
|
163 { |
|
164 //The test harness may have interrupted the test. If so, rethrow the exception |
|
165 // so that the harness gets it and deals with it. |
|
166 if( ! testGeneratedInterrupt ) throw e; |
|
167 |
|
168 //reset flag in case hit this code more than once for some reason (just safety) |
|
169 testGeneratedInterrupt = false; |
|
170 |
|
171 if ( theTestPassed == false ) |
|
172 { |
|
173 throw new RuntimeException( failureMessage ); |
|
174 } |
111 } |
175 } |
112 } |
176 |
113 |
177 }//main |
114 if (!isProgInterruption) { |
178 |
115 throw new RuntimeException("Timed out after " + sleepTime / 1000 |
179 public static synchronized void setTimeoutTo( int seconds ) |
116 + " seconds"); |
180 { |
117 } |
181 sleepTime = seconds * 1000; |
|
182 } |
118 } |
183 |
|
184 public static synchronized void pass() |
|
185 { |
|
186 Sysout.println( "The test passed." ); |
|
187 Sysout.println( "The test is over, hit Ctl-C to stop Java VM" ); |
|
188 //first check if this is executing in main thread |
|
189 if ( mainThread == Thread.currentThread() ) |
|
190 { |
|
191 //Still in the main thread, so set the flag just for kicks, |
|
192 // and throw a test passed exception which will be caught |
|
193 // and end the test. |
|
194 theTestPassed = true; |
|
195 throw new TestPassedException(); |
|
196 } |
|
197 theTestPassed = true; |
|
198 testGeneratedInterrupt = true; |
|
199 mainThread.interrupt(); |
|
200 }//pass() |
|
201 |
|
202 public static synchronized void fail() |
|
203 { |
|
204 //test writer didn't specify why test failed, so give generic |
|
205 fail( "it just plain failed! :-)" ); |
|
206 } |
|
207 |
|
208 public static synchronized void fail( String whyFailed ) |
|
209 { |
|
210 Sysout.println( "The test failed: " + whyFailed ); |
|
211 Sysout.println( "The test is over, hit Ctl-C to stop Java VM" ); |
|
212 //check if this called from main thread |
|
213 if ( mainThread == Thread.currentThread() ) |
|
214 { |
|
215 //If main thread, fail now 'cause not sleeping |
|
216 throw new RuntimeException( whyFailed ); |
|
217 } |
|
218 theTestPassed = false; |
|
219 testGeneratedInterrupt = true; |
|
220 failureMessage = whyFailed; |
|
221 mainThread.interrupt(); |
|
222 }//fail() |
|
223 |
|
224 }// class UnfocusableMaximizedFrameResizablity |
|
225 |
|
226 //This exception is used to exit from any level of call nesting |
|
227 // when it's determined that the test has passed, and immediately |
|
228 // end the test. |
|
229 class TestPassedException extends RuntimeException |
|
230 { |
|
231 } |
119 } |
232 |
120 |
233 //*********** End Standard Test Machinery Section ********** |
|
234 |
|
235 |
|
236 //************ Begin classes defined for the test **************** |
|
237 |
|
238 // if want to make listeners, here is the recommended place for them, then instantiate |
|
239 // them in init() |
|
240 |
|
241 /* Example of a class which may be written as part of a test |
|
242 class NewClass implements anInterface |
|
243 { |
|
244 static int newVar = 0; |
|
245 |
|
246 public void eventDispatched(AWTEvent e) |
|
247 { |
|
248 //Counting events to see if we get enough |
|
249 eventCount++; |
|
250 |
|
251 if( eventCount == 20 ) |
|
252 { |
|
253 //got enough events, so pass |
|
254 |
|
255 UnfocusableMaximizedFrameResizablity.pass(); |
|
256 } |
|
257 else if( tries == 20 ) |
|
258 { |
|
259 //tried too many times without getting enough events so fail |
|
260 |
|
261 UnfocusableMaximizedFrameResizablity.fail(); |
|
262 } |
|
263 |
|
264 }// eventDispatched() |
|
265 |
|
266 }// NewClass class |
|
267 |
|
268 */ |
|
269 |
|
270 |
|
271 //************** End classes defined for the test ******************* |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 /**************************************************** |
|
277 Standard Test Machinery |
|
278 DO NOT modify anything below -- it's a standard |
|
279 chunk of code whose purpose is to make user |
|
280 interaction uniform, and thereby make it simpler |
|
281 to read and understand someone else's test. |
|
282 ****************************************************/ |
|
283 |
|
284 /** |
|
285 This is part of the standard test machinery. |
|
286 It creates a dialog (with the instructions), and is the interface |
|
287 for sending text messages to the user. |
|
288 To print the instructions, send an array of strings to Sysout.createDialog |
|
289 WithInstructions method. Put one line of instructions per array entry. |
|
290 To display a message for the tester to see, simply call Sysout.println |
|
291 with the string to be displayed. |
|
292 This mimics System.out.println but works within the test harness as well |
|
293 as standalone. |
|
294 */ |
|
295 |
|
296 class Sysout |
|
297 { |
|
298 private static TestDialog dialog; |
|
299 |
|
300 public static void createDialogWithInstructions( String[] instructions ) |
|
301 { |
|
302 dialog = new TestDialog( new Frame(), "Instructions" ); |
|
303 dialog.printInstructions( instructions ); |
|
304 dialog.setVisible(true); |
|
305 println( "Any messages for the tester will display here." ); |
|
306 } |
|
307 |
|
308 public static void createDialog( ) |
|
309 { |
|
310 dialog = new TestDialog( new Frame(), "Instructions" ); |
|
311 String[] defInstr = { "Instructions will appear here. ", "" } ; |
|
312 dialog.printInstructions( defInstr ); |
|
313 dialog.setVisible(true); |
|
314 println( "Any messages for the tester will display here." ); |
|
315 } |
|
316 |
|
317 |
|
318 public static void printInstructions( String[] instructions ) |
|
319 { |
|
320 dialog.printInstructions( instructions ); |
|
321 } |
|
322 |
|
323 |
|
324 public static void println( String messageIn ) |
|
325 { |
|
326 dialog.displayMessage( messageIn ); |
|
327 System.out.println(messageIn); |
|
328 } |
|
329 |
|
330 }// Sysout class |
|
331 |
|
332 /** |
|
333 This is part of the standard test machinery. It provides a place for the |
|
334 test instructions to be displayed, and a place for interactive messages |
|
335 to the user to be displayed. |
|
336 To have the test instructions displayed, see Sysout. |
|
337 To have a message to the user be displayed, see Sysout. |
|
338 Do not call anything in this dialog directly. |
|
339 */ |
|
340 class TestDialog extends Dialog |
|
341 { |
|
342 |
|
343 TextArea instructionsText; |
|
344 TextArea messageText; |
|
345 int maxStringLength = 80; |
|
346 |
|
347 //DO NOT call this directly, go through Sysout |
|
348 public TestDialog( Frame frame, String name ) |
|
349 { |
|
350 super( frame, name ); |
|
351 int scrollBoth = TextArea.SCROLLBARS_BOTH; |
|
352 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); |
|
353 add( "North", instructionsText ); |
|
354 |
|
355 messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); |
|
356 add("Center", messageText); |
|
357 |
|
358 pack(); |
|
359 |
|
360 setVisible(true); |
|
361 }// TestDialog() |
|
362 |
|
363 //DO NOT call this directly, go through Sysout |
|
364 public void printInstructions( String[] instructions ) |
|
365 { |
|
366 //Clear out any current instructions |
|
367 instructionsText.setText( "" ); |
|
368 |
|
369 //Go down array of instruction strings |
|
370 |
|
371 String printStr, remainingStr; |
|
372 for( int i=0; i < instructions.length; i++ ) |
|
373 { |
|
374 //chop up each into pieces maxSringLength long |
|
375 remainingStr = instructions[ i ]; |
|
376 while( remainingStr.length() > 0 ) |
|
377 { |
|
378 //if longer than max then chop off first max chars to print |
|
379 if( remainingStr.length() >= maxStringLength ) |
|
380 { |
|
381 //Try to chop on a word boundary |
|
382 int posOfSpace = remainingStr. |
|
383 lastIndexOf( ' ', maxStringLength - 1 ); |
|
384 |
|
385 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; |
|
386 |
|
387 printStr = remainingStr.substring( 0, posOfSpace + 1 ); |
|
388 remainingStr = remainingStr.substring( posOfSpace + 1 ); |
|
389 } |
|
390 //else just print |
|
391 else |
|
392 { |
|
393 printStr = remainingStr; |
|
394 remainingStr = ""; |
|
395 } |
|
396 |
|
397 instructionsText.append( printStr + "\n" ); |
|
398 |
|
399 }// while |
|
400 |
|
401 }// for |
|
402 |
|
403 }//printInstructions() |
|
404 |
|
405 //DO NOT call this directly, go through Sysout |
|
406 public void displayMessage( String messageIn ) |
|
407 { |
|
408 messageText.append( messageIn + "\n" ); |
|
409 System.out.println(messageIn); |
|
410 } |
|
411 |
|
412 }// TestDialog class |
|