3
# Date 1205521233 -10800
4
# Node ID 15ba7093f8e64e1facdfc48b8929edc6a4fbb0d3
5
# Parent 92e3f57c933b45c678abcbccaa47de059dfe926a
6
6578583: Regression: Modality is broken in windows vista home premium from jdk1.7 b02 onwards.
7
Summary: WS_DISABLED style should be used to fix some modality bugs
10
diff -r 92e3f57c933b -r 15ba7093f8e6 src/windows/native/sun/windows/awt_Component.cpp
11
--- openjdk.orig/jdk/src/windows/native/sun/windows/awt_Component.cpp Fri Mar 14 20:40:09 2008 +0300
12
+++ openjdk/jdk/src/windows/native/sun/windows/awt_Component.cpp Fri Mar 14 22:00:33 2008 +0300
13
@@ -5425,7 +5425,13 @@
14
void AwtComponent::Enable(BOOL bEnable)
16
sm_suppressFocusAndActivation = TRUE;
18
+ if (bEnable && IsTopLevel()) {
19
+ // we should not enable blocked toplevels
20
+ bEnable = !::IsWindow(AwtWindow::GetModalBlocker(GetHWnd()));
22
::EnableWindow(GetHWnd(), bEnable);
24
sm_suppressFocusAndActivation = FALSE;
25
CriticalSection::Lock l(GetLock());
27
diff -r 92e3f57c933b -r 15ba7093f8e6 src/windows/native/sun/windows/awt_Dialog.cpp
28
--- openjdk.orig/jdk/src/windows/native/sun/windows/awt_Dialog.cpp Fri Mar 14 20:40:09 2008 +0300
29
+++ openjdk/jdk/src/windows/native/sun/windows/awt_Dialog.cpp Fri Mar 14 22:00:33 2008 +0300
32
HWND blocker = AwtWindow::GetModalBlocker(AwtComponent::GetTopLevelParentForWindow(hWnd));
33
HWND topMostBlocker = blocker;
34
+ HWND prevForegroundWindow = ::GetForegroundWindow();
35
+ if (::IsWindow(blocker)) {
36
+ ::BringWindowToTop(hWnd);
38
while (::IsWindow(blocker)) {
39
topMostBlocker = blocker;
40
::BringWindowToTop(blocker);
42
// no beep/flash if the mouse was clicked in the taskbar menu
43
// or the dialog is currently inactive
44
if ((::WindowFromPoint(mhs->pt) == hWnd) &&
45
- (::GetForegroundWindow() == topMostBlocker))
46
+ (prevForegroundWindow == topMostBlocker))
49
// some heuristics: 3 times x 64 milliseconds
51
::BringWindowToTop(topMostBlocker);
52
::SetForegroundWindow(topMostBlocker);
58
diff -r 92e3f57c933b -r 15ba7093f8e6 src/windows/native/sun/windows/awt_Window.cpp
59
--- openjdk.orig/jdk/src/windows/native/sun/windows/awt_Window.cpp Fri Mar 14 20:40:09 2008 +0300
60
+++ openjdk/jdk/src/windows/native/sun/windows/awt_Window.cpp Fri Mar 14 22:00:33 2008 +0300
64
::RemoveProp(GetHWnd(), ModalBlockerProp);
65
- ::RemoveProp(GetHWnd(), ModalSaveWSEXProp);
67
if (m_grabbedWindow == this) {
69
@@ -1455,20 +1454,17 @@
70
if (!::IsWindow(window)) {
73
- DWORD exStyle = ::GetWindowLong(window, GWL_EXSTYLE);
75
if (::IsWindow(blocker)) {
76
- // save WS_EX_NOACTIVATE and WS_EX_APPWINDOW styles
77
- DWORD saveStyle = exStyle & (AWT_WS_EX_NOACTIVATE | WS_EX_APPWINDOW);
78
- ::SetProp(window, ModalSaveWSEXProp, reinterpret_cast<HANDLE>(saveStyle));
79
- ::SetWindowLong(window, GWL_EXSTYLE, (exStyle | AWT_WS_EX_NOACTIVATE) & ~WS_EX_APPWINDOW);
80
::SetProp(window, ModalBlockerProp, reinterpret_cast<HANDLE>(blocker));
81
+ ::EnableWindow(window, FALSE);
83
- // restore WS_EX_NOACTIVATE and WS_EX_APPWINDOW styles
84
- DWORD saveStyle = reinterpret_cast<DWORD>(::GetProp(window, ModalSaveWSEXProp));
85
- ::SetWindowLong(window, GWL_EXSTYLE,
86
- (exStyle & ~(AWT_WS_EX_NOACTIVATE | WS_EX_APPWINDOW)) | saveStyle);
87
- ::RemoveProp(window, ModalSaveWSEXProp);
88
::RemoveProp(window, ModalBlockerProp);
89
+ AwtComponent *comp = AwtComponent::GetComponent(window);
90
+ // we don't expect to be called with non-java HWNDs
91
+ DASSERT(comp && comp->IsTopLevel());
92
+ // we should not unblock disabled toplevels
93
+ ::EnableWindow(window, comp->isEnabled());
97
diff -r 92e3f57c933b -r 15ba7093f8e6 src/windows/native/sun/windows/awt_Window.h
98
--- openjdk.orig/jdk/src/windows/native/sun/windows/awt_Window.h Fri Mar 14 20:40:09 2008 +0300
99
+++ openjdk/jdk/src/windows/native/sun/windows/awt_Window.h Fri Mar 14 22:00:33 2008 +0300
102
// property name tagging windows disabled by modality
103
static LPCTSTR ModalBlockerProp = TEXT("SunAwtModalBlockerProp");
104
-static LPCTSTR ModalSaveWSEXProp = TEXT("SunAwtModalSaveWSEXProp");
105
static LPCTSTR ModalDialogPeerProp = TEXT("SunAwtModalDialogPeerProp");
108
diff -r 92e3f57c933b -r 15ba7093f8e6 test/java/awt/Modal/WsDisabledStyle/CloseBlocker/CloseBlocker.java
109
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
110
+++ openjdk/jdk/test/java/awt/Modal/WsDisabledStyle/CloseBlocker/CloseBlocker.java Fri Mar 14 22:00:33 2008 +0300
113
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
114
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
116
+ * This code is free software; you can redistribute it and/or modify it
117
+ * under the terms of the GNU General Public License version 2 only, as
118
+ * published by the Free Software Foundation.
120
+ * This code is distributed in the hope that it will be useful, but WITHOUT
121
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
122
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
123
+ * version 2 for more details (a copy is included in the LICENSE file that
124
+ * accompanied this code).
126
+ * You should have received a copy of the GNU General Public License version
127
+ * 2 along with this work; if not, write to the Free Software Foundation,
128
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
130
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
131
+ * CA 95054 USA or visit www.sun.com if you need additional information or
132
+ * have any questions.
138
+ @summary Modal Dialog block input to all frame windows not just its parent.
139
+ @author dmitry.cherepanov: area=awt.modal
140
+ @run main/manual CloseBlocker
144
+ * ManualMainTest.java
146
+ * summary: The test opens and closes blocker dialog, the test verifies
147
+ * that active window is correct when the dialog is closed.
151
+import java.awt.event.*;
153
+public class CloseBlocker
156
+ private static void init()
158
+ //*** Create instructions for the user here ***
160
+ String[] instructions =
162
+ " the test will be run 6 times, to start next test just close all ",
163
+ " windows of previous; the instructions are the same for all tests: ",
164
+ " 1) there are two frames (one the frames has 'show modal' button), ",
165
+ " 2) press the button to show a dialog, ",
166
+ " 3) close the dialog (an alternative scenario - activate another",
167
+ " native window before closing the dialog), ",
168
+ " 4) the frame with button should become next active window, ",
169
+ " if it's true, then the test passed, otherwise, it failed. ",
170
+ " Press 'pass' button only after all of the 6 tests are completed, ",
171
+ " the number of the currently executed test is displayed on the ",
174
+ Sysout.createDialog( );
175
+ Sysout.printInstructions( instructions );
177
+ test(true, true, false);
178
+ test(true, true, true);
179
+ test(false, true, false); // 3rd parameter has no affect for ownerless
181
+ test(true, false, false);
182
+ test(true, false, true);
183
+ test(false, false, false); // 3rd parameter has no affect for ownerless
187
+ private static final Object obj = new Object();
188
+ private static int counter = 0;
191
+ * The ownerless parameter indicates whether the blocker dialog
192
+ * has owner. The usual parameter indicates whether the blocker
193
+ * dialog is a Java dialog (non-native dialog like file dialog).
195
+ private static void test(final boolean ownerless, final boolean usual, final boolean initiallyOwnerIsActive) {
197
+ Sysout.print(" * test #" + (++counter) + " is running ... ");
199
+ final Frame active = new Frame();
200
+ final Frame nonactive = new Frame();
201
+ Button button = new Button("show modal");
202
+ button.addActionListener(new ActionListener() {
203
+ public void actionPerformed(ActionEvent ae) {
204
+ Dialog dialog = null;
205
+ Frame parent = ownerless ? null : (initiallyOwnerIsActive? active : nonactive);
207
+ dialog = new Dialog(parent, "Sample", true);
209
+ dialog = new FileDialog(parent, "Sample", FileDialog.LOAD);
211
+ dialog.addWindowListener(new WindowAdapter(){
212
+ public void windowClosing(WindowEvent e){
213
+ e.getWindow().dispose();
216
+ dialog.setBounds(200, 200, 200, 200);
217
+ dialog.setVisible(true);
221
+ active.add(button);
222
+ active.setBounds(200, 400, 200, 200);
223
+ WindowAdapter adapter = new WindowAdapter(){
224
+ public void windowClosing(WindowEvent e){
226
+ nonactive.dispose();
227
+ synchronized(obj) {
232
+ active.addWindowListener(adapter);
233
+ active.setVisible(true);
235
+ nonactive.setBounds(400, 400, 200, 200);
236
+ nonactive.addWindowListener(adapter);
237
+ nonactive.setVisible(true);
239
+ synchronized(obj) {
242
+ } catch(Exception e) {
243
+ throw new RuntimeException(e);
247
+ Sysout.println(" completed. ");
251
+ /*****************************************************
252
+ * Standard Test Machinery Section
253
+ * DO NOT modify anything in this section -- it's a
254
+ * standard chunk of code which has all of the
255
+ * synchronisation necessary for the test harness.
256
+ * By keeping it the same in all tests, it is easier
257
+ * to read and understand someone else's test, as
258
+ * well as insuring that all tests behave correctly
259
+ * with the test harness.
260
+ * There is a section following this for test-defined
262
+ ******************************************************/
263
+ private static boolean theTestPassed = false;
264
+ private static boolean testGeneratedInterrupt = false;
265
+ private static String failureMessage = "";
267
+ private static Thread mainThread = null;
269
+ private static int sleepTime = 300000;
271
+ public static void main( String args[] ) throws InterruptedException
273
+ mainThread = Thread.currentThread();
278
+ catch( TestPassedException e )
280
+ //The test passed, so just return from main and harness will
281
+ // interepret this return as a pass
284
+ //At this point, neither test passed nor test failed has been
285
+ // called -- either would have thrown an exception and ended the
286
+ // test, so we know we have multiple threads.
288
+ //Test involves other threads, so sleep and wait for them to
289
+ // called pass() or fail()
292
+ Thread.sleep( sleepTime );
293
+ //Timed out, so fail the test
294
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
296
+ catch (InterruptedException e)
298
+ if( ! testGeneratedInterrupt ) throw e;
300
+ //reset flag in case hit this code more than once for some reason (just safety)
301
+ testGeneratedInterrupt = false;
302
+ if ( theTestPassed == false )
304
+ throw new RuntimeException( failureMessage );
310
+ public static synchronized void setTimeoutTo( int seconds )
312
+ sleepTime = seconds * 1000;
315
+ public static synchronized void pass()
317
+ Sysout.println( "The test passed." );
318
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
319
+ //first check if this is executing in main thread
320
+ if ( mainThread == Thread.currentThread() )
322
+ //Still in the main thread, so set the flag just for kicks,
323
+ // and throw a test passed exception which will be caught
324
+ // and end the test.
325
+ theTestPassed = true;
326
+ throw new TestPassedException();
328
+ //pass was called from a different thread, so set the flag and interrupt
330
+ theTestPassed = true;
331
+ testGeneratedInterrupt = true;
332
+ mainThread.interrupt();
335
+ public static synchronized void fail()
337
+ //test writer didn't specify why test failed, so give generic
338
+ fail( "it just plain failed! :-)" );
341
+ public static synchronized void fail( String whyFailed )
343
+ Sysout.println( "The test failed: " + whyFailed );
344
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
345
+ //check if this called from main thread
346
+ if ( mainThread == Thread.currentThread() )
348
+ //If main thread, fail now 'cause not sleeping
349
+ throw new RuntimeException( whyFailed );
351
+ theTestPassed = false;
352
+ testGeneratedInterrupt = true;
353
+ failureMessage = whyFailed;
354
+ mainThread.interrupt();
357
+}// class ManualMainTest
359
+//This exception is used to exit from any level of call nesting
360
+// when it's determined that the test has passed, and immediately
362
+class TestPassedException extends RuntimeException
366
+//*********** End Standard Test Machinery Section **********
369
+//************ Begin classes defined for the test ****************
371
+// make listeners in a class defined here, and instantiate them in init()
373
+/* Example of a class which may be written as part of a test
374
+class NewClass implements anInterface
376
+ static int newVar = 0;
378
+ public void eventDispatched(AWTEvent e)
380
+ //Counting events to see if we get enough
383
+ if( eventCount == 20 )
385
+ //got enough events, so pass
387
+ ManualMainTest.pass();
389
+ else if( tries == 20 )
391
+ //tried too many times without getting enough events so fail
393
+ ManualMainTest.fail();
396
+ }// eventDispatched()
403
+//************** End classes defined for the test *******************
408
+/****************************************************
409
+ Standard Test Machinery
410
+ DO NOT modify anything below -- it's a standard
411
+ chunk of code whose purpose is to make user
412
+ interaction uniform, and thereby make it simpler
413
+ to read and understand someone else's test.
414
+ ****************************************************/
417
+ This is part of the standard test machinery.
418
+ It creates a dialog (with the instructions), and is the interface
419
+ for sending text messages to the user.
420
+ To print the instructions, send an array of strings to Sysout.createDialog
421
+ WithInstructions method. Put one line of instructions per array entry.
422
+ To display a message for the tester to see, simply call Sysout.println
423
+ with the string to be displayed.
424
+ This mimics System.out.println but works within the test harness as well
430
+ private static TestDialog dialog;
432
+ public static void createDialogWithInstructions( String[] instructions )
434
+ dialog = new TestDialog( new Frame(), "Instructions" );
435
+ dialog.printInstructions( instructions );
436
+ dialog.setVisible(true);
437
+ println( "Any messages for the tester will display here." );
440
+ public static void createDialog( )
442
+ dialog = new TestDialog( new Frame(), "Instructions" );
443
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
444
+ dialog.printInstructions( defInstr );
445
+ dialog.setVisible(true);
446
+ println( "Any messages for the tester will display here." );
450
+ public static void printInstructions( String[] instructions )
452
+ dialog.printInstructions( instructions );
456
+ public static void println( String messageIn )
458
+ dialog.displayMessage( messageIn, true );
461
+ public static void print( String messageIn )
463
+ dialog.displayMessage( messageIn, false );
469
+ This is part of the standard test machinery. It provides a place for the
470
+ test instructions to be displayed, and a place for interactive messages
471
+ to the user to be displayed.
472
+ To have the test instructions displayed, see Sysout.
473
+ To have a message to the user be displayed, see Sysout.
474
+ Do not call anything in this dialog directly.
476
+class TestDialog extends Dialog implements ActionListener
479
+ TextArea instructionsText;
480
+ TextArea messageText;
481
+ int maxStringLength = 80;
482
+ Panel buttonP = new Panel();
483
+ Button passB = new Button( "pass" );
484
+ Button failB = new Button( "fail" );
486
+ //DO NOT call this directly, go through Sysout
487
+ public TestDialog( Frame frame, String name )
489
+ super( frame, name );
490
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
491
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
492
+ add( "North", instructionsText );
494
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
495
+ add("Center", messageText);
497
+ passB = new Button( "pass" );
498
+ passB.setActionCommand( "pass" );
499
+ passB.addActionListener( this );
500
+ buttonP.add( "East", passB );
502
+ failB = new Button( "fail" );
503
+ failB.setActionCommand( "fail" );
504
+ failB.addActionListener( this );
505
+ buttonP.add( "West", failB );
507
+ add( "South", buttonP );
513
+ //DO NOT call this directly, go through Sysout
514
+ public void printInstructions( String[] instructions )
516
+ //Clear out any current instructions
517
+ instructionsText.setText( "" );
519
+ //Go down array of instruction strings
521
+ String printStr, remainingStr;
522
+ for( int i=0; i < instructions.length; i++ )
524
+ //chop up each into pieces maxSringLength long
525
+ remainingStr = instructions[ i ];
526
+ while( remainingStr.length() > 0 )
528
+ //if longer than max then chop off first max chars to print
529
+ if( remainingStr.length() >= maxStringLength )
531
+ //Try to chop on a word boundary
532
+ int posOfSpace = remainingStr.
533
+ lastIndexOf( ' ', maxStringLength - 1 );
535
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
537
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
538
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
543
+ printStr = remainingStr;
547
+ instructionsText.append( printStr + "\n" );
553
+ }//printInstructions()
555
+ //DO NOT call this directly, go through Sysout
556
+ public void displayMessage( String messageIn, boolean nextLine )
558
+ messageText.append( messageIn + (nextLine? "\n" : "") );
559
+ System.out.println(messageIn);
562
+ //catch presses of the passed and failed buttons.
563
+ //simply call the standard pass() or fail() static methods of
565
+ public void actionPerformed( ActionEvent e )
567
+ if( e.getActionCommand() == "pass" )
569
+ CloseBlocker.pass();
573
+ CloseBlocker.fail();
577
+}// TestDialog class
578
diff -r 92e3f57c933b -r 15ba7093f8e6 test/java/awt/Modal/WsDisabledStyle/OverBlocker/OverBlocker.java
579
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
580
+++ openjdk/jdk/test/java/awt/Modal/WsDisabledStyle/OverBlocker/OverBlocker.java Fri Mar 14 22:00:33 2008 +0300
583
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
584
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
586
+ * This code is free software; you can redistribute it and/or modify it
587
+ * under the terms of the GNU General Public License version 2 only, as
588
+ * published by the Free Software Foundation.
590
+ * This code is distributed in the hope that it will be useful, but WITHOUT
591
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
592
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
593
+ * version 2 for more details (a copy is included in the LICENSE file that
594
+ * accompanied this code).
596
+ * You should have received a copy of the GNU General Public License version
597
+ * 2 along with this work; if not, write to the Free Software Foundation,
598
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
600
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
601
+ * CA 95054 USA or visit www.sun.com if you need additional information or
602
+ * have any questions.
608
+ @summary Modal Dialog block input to all frame windows not just its parent.
609
+ @author dmitry.cherepanov: area=awt.modal
610
+ @run main/manual OverBlocker
616
+ * summary: The test verifies that if user tries to activate the blocked dialog
617
+ * then the blocker dialog appears over the other windows
621
+import java.awt.event.*;
623
+public class OverBlocker
626
+ private static void init()
628
+ //*** Create instructions for the user here ***
630
+ String[] instructions =
632
+ " the test will be run 4 times, to start next test just close all ",
633
+ " windows of previous; the instructions are the same for all tests: ",
634
+ " 1) there is a frame with 'show modal' button, ",
635
+ " 2) press the button to show a dialog, ",
636
+ " 3) activate any non-Java application, move the app over the dialog, ",
637
+ " 4) click on the frame by mouse, ",
638
+ " 5) make sure that the dialog comes up from the application and ",
639
+ " now the dialog overlaps the app as well as the frame, ",
640
+ " if it's true, then the test passed, otherwise, it failed. ",
641
+ " Press 'pass' button only after all of the 4 tests are completed, ",
642
+ " the number of the currently executed test is displayed on the ",
645
+ Sysout.createDialog( );
646
+ Sysout.printInstructions( instructions );
651
+ test(false, false);
655
+ private static final Object obj = new Object();
656
+ private static int counter = 0;
659
+ * The ownerless parameter indicates whether the blocker dialog
660
+ * has owner. The usual parameter indicates whether the blocker
661
+ * dialog is a Java dialog (non-native dialog like file dialog).
663
+ private static void test(final boolean ownerless, final boolean usual) {
665
+ Sysout.print(" * test #" + (++counter) + " is running ... ");
667
+ final Frame frame = new Frame();
668
+ Button button = new Button("show modal");
669
+ button.addActionListener(new ActionListener() {
670
+ public void actionPerformed(ActionEvent ae) {
671
+ Dialog dialog = null;
672
+ Frame parent = ownerless ? null : frame;
674
+ dialog = new Dialog(parent, "Sample", true);
676
+ dialog = new FileDialog(parent, "Sample", FileDialog.LOAD);
678
+ dialog.addWindowListener(new WindowAdapter(){
679
+ public void windowClosing(WindowEvent e){
680
+ e.getWindow().dispose();
683
+ dialog.setBounds(200, 200, 200, 200);
684
+ dialog.setVisible(true);
688
+ frame.setBounds(400, 400, 200, 200);
689
+ frame.addWindowListener(new WindowAdapter(){
690
+ public void windowClosing(WindowEvent e){
691
+ e.getWindow().dispose();
692
+ synchronized(obj) {
697
+ frame.setVisible(true);
699
+ synchronized(obj) {
702
+ } catch(Exception e) {
703
+ throw new RuntimeException(e);
707
+ Sysout.println(" completed. ");
711
+ /*****************************************************
712
+ * Standard Test Machinery Section
713
+ * DO NOT modify anything in this section -- it's a
714
+ * standard chunk of code which has all of the
715
+ * synchronisation necessary for the test harness.
716
+ * By keeping it the same in all tests, it is easier
717
+ * to read and understand someone else's test, as
718
+ * well as insuring that all tests behave correctly
719
+ * with the test harness.
720
+ * There is a section following this for test-defined
722
+ ******************************************************/
723
+ private static boolean theTestPassed = false;
724
+ private static boolean testGeneratedInterrupt = false;
725
+ private static String failureMessage = "";
727
+ private static Thread mainThread = null;
729
+ private static int sleepTime = 300000;
731
+ public static void main( String args[] ) throws InterruptedException
733
+ mainThread = Thread.currentThread();
738
+ catch( TestPassedException e )
740
+ //The test passed, so just return from main and harness will
741
+ // interepret this return as a pass
744
+ //At this point, neither test passed nor test failed has been
745
+ // called -- either would have thrown an exception and ended the
746
+ // test, so we know we have multiple threads.
748
+ //Test involves other threads, so sleep and wait for them to
749
+ // called pass() or fail()
752
+ Thread.sleep( sleepTime );
753
+ //Timed out, so fail the test
754
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
756
+ catch (InterruptedException e)
758
+ if( ! testGeneratedInterrupt ) throw e;
760
+ //reset flag in case hit this code more than once for some reason (just safety)
761
+ testGeneratedInterrupt = false;
762
+ if ( theTestPassed == false )
764
+ throw new RuntimeException( failureMessage );
770
+ public static synchronized void setTimeoutTo( int seconds )
772
+ sleepTime = seconds * 1000;
775
+ public static synchronized void pass()
777
+ Sysout.println( "The test passed." );
778
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
779
+ //first check if this is executing in main thread
780
+ if ( mainThread == Thread.currentThread() )
782
+ //Still in the main thread, so set the flag just for kicks,
783
+ // and throw a test passed exception which will be caught
784
+ // and end the test.
785
+ theTestPassed = true;
786
+ throw new TestPassedException();
788
+ //pass was called from a different thread, so set the flag and interrupt
790
+ theTestPassed = true;
791
+ testGeneratedInterrupt = true;
792
+ mainThread.interrupt();
795
+ public static synchronized void fail()
797
+ //test writer didn't specify why test failed, so give generic
798
+ fail( "it just plain failed! :-)" );
801
+ public static synchronized void fail( String whyFailed )
803
+ Sysout.println( "The test failed: " + whyFailed );
804
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
805
+ //check if this called from main thread
806
+ if ( mainThread == Thread.currentThread() )
808
+ //If main thread, fail now 'cause not sleeping
809
+ throw new RuntimeException( whyFailed );
811
+ theTestPassed = false;
812
+ testGeneratedInterrupt = true;
813
+ failureMessage = whyFailed;
814
+ mainThread.interrupt();
817
+}// class ManualMainTest
819
+//This exception is used to exit from any level of call nesting
820
+// when it's determined that the test has passed, and immediately
822
+class TestPassedException extends RuntimeException
826
+//*********** End Standard Test Machinery Section **********
829
+//************ Begin classes defined for the test ****************
831
+// make listeners in a class defined here, and instantiate them in init()
833
+/* Example of a class which may be written as part of a test
834
+class NewClass implements anInterface
836
+ static int newVar = 0;
838
+ public void eventDispatched(AWTEvent e)
840
+ //Counting events to see if we get enough
843
+ if( eventCount == 20 )
845
+ //got enough events, so pass
847
+ ManualMainTest.pass();
849
+ else if( tries == 20 )
851
+ //tried too many times without getting enough events so fail
853
+ ManualMainTest.fail();
856
+ }// eventDispatched()
863
+//************** End classes defined for the test *******************
868
+/****************************************************
869
+ Standard Test Machinery
870
+ DO NOT modify anything below -- it's a standard
871
+ chunk of code whose purpose is to make user
872
+ interaction uniform, and thereby make it simpler
873
+ to read and understand someone else's test.
874
+ ****************************************************/
877
+ This is part of the standard test machinery.
878
+ It creates a dialog (with the instructions), and is the interface
879
+ for sending text messages to the user.
880
+ To print the instructions, send an array of strings to Sysout.createDialog
881
+ WithInstructions method. Put one line of instructions per array entry.
882
+ To display a message for the tester to see, simply call Sysout.println
883
+ with the string to be displayed.
884
+ This mimics System.out.println but works within the test harness as well
890
+ private static TestDialog dialog;
892
+ public static void createDialogWithInstructions( String[] instructions )
894
+ dialog = new TestDialog( new Frame(), "Instructions" );
895
+ dialog.printInstructions( instructions );
896
+ dialog.setVisible(true);
897
+ println( "Any messages for the tester will display here." );
900
+ public static void createDialog( )
902
+ dialog = new TestDialog( new Frame(), "Instructions" );
903
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
904
+ dialog.printInstructions( defInstr );
905
+ dialog.setVisible(true);
906
+ println( "Any messages for the tester will display here." );
910
+ public static void printInstructions( String[] instructions )
912
+ dialog.printInstructions( instructions );
916
+ public static void println( String messageIn )
918
+ dialog.displayMessage( messageIn, true );
921
+ public static void print( String messageIn )
923
+ dialog.displayMessage( messageIn, false );
929
+ This is part of the standard test machinery. It provides a place for the
930
+ test instructions to be displayed, and a place for interactive messages
931
+ to the user to be displayed.
932
+ To have the test instructions displayed, see Sysout.
933
+ To have a message to the user be displayed, see Sysout.
934
+ Do not call anything in this dialog directly.
936
+class TestDialog extends Dialog implements ActionListener
939
+ TextArea instructionsText;
940
+ TextArea messageText;
941
+ int maxStringLength = 80;
942
+ Panel buttonP = new Panel();
943
+ Button passB = new Button( "pass" );
944
+ Button failB = new Button( "fail" );
946
+ //DO NOT call this directly, go through Sysout
947
+ public TestDialog( Frame frame, String name )
949
+ super( frame, name );
950
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
951
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
952
+ add( "North", instructionsText );
954
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
955
+ add("Center", messageText);
957
+ passB = new Button( "pass" );
958
+ passB.setActionCommand( "pass" );
959
+ passB.addActionListener( this );
960
+ buttonP.add( "East", passB );
962
+ failB = new Button( "fail" );
963
+ failB.setActionCommand( "fail" );
964
+ failB.addActionListener( this );
965
+ buttonP.add( "West", failB );
967
+ add( "South", buttonP );
973
+ //DO NOT call this directly, go through Sysout
974
+ public void printInstructions( String[] instructions )
976
+ //Clear out any current instructions
977
+ instructionsText.setText( "" );
979
+ //Go down array of instruction strings
981
+ String printStr, remainingStr;
982
+ for( int i=0; i < instructions.length; i++ )
984
+ //chop up each into pieces maxSringLength long
985
+ remainingStr = instructions[ i ];
986
+ while( remainingStr.length() > 0 )
988
+ //if longer than max then chop off first max chars to print
989
+ if( remainingStr.length() >= maxStringLength )
991
+ //Try to chop on a word boundary
992
+ int posOfSpace = remainingStr.
993
+ lastIndexOf( ' ', maxStringLength - 1 );
995
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
997
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
998
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
1003
+ printStr = remainingStr;
1004
+ remainingStr = "";
1007
+ instructionsText.append( printStr + "\n" );
1013
+ }//printInstructions()
1015
+ //DO NOT call this directly, go through Sysout
1016
+ public void displayMessage( String messageIn, boolean nextLine )
1018
+ messageText.append( messageIn + (nextLine? "\n" : "") );
1019
+ System.out.println(messageIn);
1022
+ //catch presses of the passed and failed buttons.
1023
+ //simply call the standard pass() or fail() static methods of
1025
+ public void actionPerformed( ActionEvent e )
1027
+ if( e.getActionCommand() == "pass" )
1029
+ OverBlocker.pass();
1033
+ OverBlocker.fail();
1037
+}// TestDialog class
1038
diff -r 92e3f57c933b -r 15ba7093f8e6 test/java/awt/Modal/WsDisabledStyle/Winkey/Winkey.java
1039
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
1040
+++ openjdk/jdk/test/java/awt/Modal/WsDisabledStyle/Winkey/Winkey.java Fri Mar 14 22:00:33 2008 +0300
1043
+ * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved.
1044
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1046
+ * This code is free software; you can redistribute it and/or modify it
1047
+ * under the terms of the GNU General Public License version 2 only, as
1048
+ * published by the Free Software Foundation.
1050
+ * This code is distributed in the hope that it will be useful, but WITHOUT
1051
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1052
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1053
+ * version 2 for more details (a copy is included in the LICENSE file that
1054
+ * accompanied this code).
1056
+ * You should have received a copy of the GNU General Public License version
1057
+ * 2 along with this work; if not, write to the Free Software Foundation,
1058
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1060
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
1061
+ * CA 95054 USA or visit www.sun.com if you need additional information or
1062
+ * have any questions.
1067
+ @bug 6572263 6571808
1068
+ @summary PIT:FileDialog minimized to taskbar(through 'Show Desktop')selecting the fileDialog using windowList
1069
+ @author dmitry.cherepanov: area=awt.modal
1070
+ @run main/manual Winkey
1076
+ * summary: the test verifies that pressing combination of Windows key
1077
+ * and M key to minimize all windows doesn't break AWT modality
1081
+import java.awt.event.*;
1083
+public class Winkey
1086
+ private static void init()
1088
+ //*** Create instructions for the user here ***
1090
+ String[] instructions =
1092
+ " 1. there is a frame with a 'show modal' button, ",
1093
+ " 2. press the button to show a modal dialog, ",
1094
+ " 3. the modal dialog will be shown over the frame, ",
1095
+ " 4. please verify that all (5.1, 5.2.1, 5.2.2) the following tests pass: ",
1097
+ " 5.1. press combination Windows Key and M key to minimize all windows, ",
1098
+ " 5.2. press combination Windows Key and D key to show desktop, ",
1099
+ " 5.2.1. restore the dialog by choosing this one in the ALT-TAB list, ",
1100
+ " 5.2.2. restore the dialog by mouse click on taskbar (on java or any other item)",
1102
+ " 6. make sure that the dialog and the frame are visible, ",
1103
+ " the bounds of the windows should be the same as before, ",
1104
+ " if it's true, then the test passed; otherwise, it failed. "
1106
+ Sysout.createDialog( );
1107
+ Sysout.printInstructions( instructions );
1109
+ final Frame frame = new Frame();
1110
+ Button button = new Button("show modal");
1111
+ button.addActionListener(new ActionListener() {
1112
+ public void actionPerformed(ActionEvent ae) {
1113
+ FileDialog dialog = new FileDialog((Frame)null, "Sample", FileDialog.LOAD);
1114
+ dialog.setVisible(true);
1117
+ frame.add(button);
1118
+ frame.setBounds(400, 400, 200, 200);
1119
+ frame.setVisible(true);
1123
+ /*****************************************************
1124
+ * Standard Test Machinery Section
1125
+ * DO NOT modify anything in this section -- it's a
1126
+ * standard chunk of code which has all of the
1127
+ * synchronisation necessary for the test harness.
1128
+ * By keeping it the same in all tests, it is easier
1129
+ * to read and understand someone else's test, as
1130
+ * well as insuring that all tests behave correctly
1131
+ * with the test harness.
1132
+ * There is a section following this for test-defined
1134
+ ******************************************************/
1135
+ private static boolean theTestPassed = false;
1136
+ private static boolean testGeneratedInterrupt = false;
1137
+ private static String failureMessage = "";
1139
+ private static Thread mainThread = null;
1141
+ private static int sleepTime = 300000;
1143
+ public static void main( String args[] ) throws InterruptedException
1145
+ mainThread = Thread.currentThread();
1150
+ catch( TestPassedException e )
1152
+ //The test passed, so just return from main and harness will
1153
+ // interepret this return as a pass
1156
+ //At this point, neither test passed nor test failed has been
1157
+ // called -- either would have thrown an exception and ended the
1158
+ // test, so we know we have multiple threads.
1160
+ //Test involves other threads, so sleep and wait for them to
1161
+ // called pass() or fail()
1164
+ Thread.sleep( sleepTime );
1165
+ //Timed out, so fail the test
1166
+ throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" );
1168
+ catch (InterruptedException e)
1170
+ if( ! testGeneratedInterrupt ) throw e;
1172
+ //reset flag in case hit this code more than once for some reason (just safety)
1173
+ testGeneratedInterrupt = false;
1174
+ if ( theTestPassed == false )
1176
+ throw new RuntimeException( failureMessage );
1182
+ public static synchronized void setTimeoutTo( int seconds )
1184
+ sleepTime = seconds * 1000;
1187
+ public static synchronized void pass()
1189
+ Sysout.println( "The test passed." );
1190
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
1191
+ //first check if this is executing in main thread
1192
+ if ( mainThread == Thread.currentThread() )
1194
+ //Still in the main thread, so set the flag just for kicks,
1195
+ // and throw a test passed exception which will be caught
1196
+ // and end the test.
1197
+ theTestPassed = true;
1198
+ throw new TestPassedException();
1200
+ //pass was called from a different thread, so set the flag and interrupt
1201
+ // the main thead.
1202
+ theTestPassed = true;
1203
+ testGeneratedInterrupt = true;
1204
+ mainThread.interrupt();
1207
+ public static synchronized void fail()
1209
+ //test writer didn't specify why test failed, so give generic
1210
+ fail( "it just plain failed! :-)" );
1213
+ public static synchronized void fail( String whyFailed )
1215
+ Sysout.println( "The test failed: " + whyFailed );
1216
+ Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
1217
+ //check if this called from main thread
1218
+ if ( mainThread == Thread.currentThread() )
1220
+ //If main thread, fail now 'cause not sleeping
1221
+ throw new RuntimeException( whyFailed );
1223
+ theTestPassed = false;
1224
+ testGeneratedInterrupt = true;
1225
+ failureMessage = whyFailed;
1226
+ mainThread.interrupt();
1229
+}// class ManualMainTest
1231
+//This exception is used to exit from any level of call nesting
1232
+// when it's determined that the test has passed, and immediately
1234
+class TestPassedException extends RuntimeException
1238
+//*********** End Standard Test Machinery Section **********
1241
+//************ Begin classes defined for the test ****************
1243
+// make listeners in a class defined here, and instantiate them in init()
1245
+/* Example of a class which may be written as part of a test
1246
+class NewClass implements anInterface
1248
+ static int newVar = 0;
1250
+ public void eventDispatched(AWTEvent e)
1252
+ //Counting events to see if we get enough
1255
+ if( eventCount == 20 )
1257
+ //got enough events, so pass
1259
+ ManualMainTest.pass();
1261
+ else if( tries == 20 )
1263
+ //tried too many times without getting enough events so fail
1265
+ ManualMainTest.fail();
1268
+ }// eventDispatched()
1270
+ }// NewClass class
1275
+//************** End classes defined for the test *******************
1280
+/****************************************************
1281
+ Standard Test Machinery
1282
+ DO NOT modify anything below -- it's a standard
1283
+ chunk of code whose purpose is to make user
1284
+ interaction uniform, and thereby make it simpler
1285
+ to read and understand someone else's test.
1286
+ ****************************************************/
1289
+ This is part of the standard test machinery.
1290
+ It creates a dialog (with the instructions), and is the interface
1291
+ for sending text messages to the user.
1292
+ To print the instructions, send an array of strings to Sysout.createDialog
1293
+ WithInstructions method. Put one line of instructions per array entry.
1294
+ To display a message for the tester to see, simply call Sysout.println
1295
+ with the string to be displayed.
1296
+ This mimics System.out.println but works within the test harness as well
1302
+ private static TestDialog dialog;
1304
+ public static void createDialogWithInstructions( String[] instructions )
1306
+ dialog = new TestDialog( new Frame(), "Instructions" );
1307
+ dialog.printInstructions( instructions );
1308
+ dialog.setVisible(true);
1309
+ println( "Any messages for the tester will display here." );
1312
+ public static void createDialog( )
1314
+ dialog = new TestDialog( new Frame(), "Instructions" );
1315
+ String[] defInstr = { "Instructions will appear here. ", "" } ;
1316
+ dialog.printInstructions( defInstr );
1317
+ dialog.setVisible(true);
1318
+ println( "Any messages for the tester will display here." );
1322
+ public static void printInstructions( String[] instructions )
1324
+ dialog.printInstructions( instructions );
1328
+ public static void println( String messageIn )
1330
+ dialog.displayMessage( messageIn );
1336
+ This is part of the standard test machinery. It provides a place for the
1337
+ test instructions to be displayed, and a place for interactive messages
1338
+ to the user to be displayed.
1339
+ To have the test instructions displayed, see Sysout.
1340
+ To have a message to the user be displayed, see Sysout.
1341
+ Do not call anything in this dialog directly.
1343
+class TestDialog extends Dialog implements ActionListener
1346
+ TextArea instructionsText;
1347
+ TextArea messageText;
1348
+ int maxStringLength = 80;
1349
+ Panel buttonP = new Panel();
1350
+ Button passB = new Button( "pass" );
1351
+ Button failB = new Button( "fail" );
1353
+ //DO NOT call this directly, go through Sysout
1354
+ public TestDialog( Frame frame, String name )
1356
+ super( frame, name );
1357
+ int scrollBoth = TextArea.SCROLLBARS_BOTH;
1358
+ instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
1359
+ add( "North", instructionsText );
1361
+ messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
1362
+ add("Center", messageText);
1364
+ passB = new Button( "pass" );
1365
+ passB.setActionCommand( "pass" );
1366
+ passB.addActionListener( this );
1367
+ buttonP.add( "East", passB );
1369
+ failB = new Button( "fail" );
1370
+ failB.setActionCommand( "fail" );
1371
+ failB.addActionListener( this );
1372
+ buttonP.add( "West", failB );
1374
+ add( "South", buttonP );
1380
+ //DO NOT call this directly, go through Sysout
1381
+ public void printInstructions( String[] instructions )
1383
+ //Clear out any current instructions
1384
+ instructionsText.setText( "" );
1386
+ //Go down array of instruction strings
1388
+ String printStr, remainingStr;
1389
+ for( int i=0; i < instructions.length; i++ )
1391
+ //chop up each into pieces maxSringLength long
1392
+ remainingStr = instructions[ i ];
1393
+ while( remainingStr.length() > 0 )
1395
+ //if longer than max then chop off first max chars to print
1396
+ if( remainingStr.length() >= maxStringLength )
1398
+ //Try to chop on a word boundary
1399
+ int posOfSpace = remainingStr.
1400
+ lastIndexOf( ' ', maxStringLength - 1 );
1402
+ if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
1404
+ printStr = remainingStr.substring( 0, posOfSpace + 1 );
1405
+ remainingStr = remainingStr.substring( posOfSpace + 1 );
1410
+ printStr = remainingStr;
1411
+ remainingStr = "";
1414
+ instructionsText.append( printStr + "\n" );
1420
+ }//printInstructions()
1422
+ //DO NOT call this directly, go through Sysout
1423
+ public void displayMessage( String messageIn )
1425
+ messageText.append( messageIn + "\n" );
1426
+ System.out.println(messageIn);
1429
+ //catch presses of the passed and failed buttons.
1430
+ //simply call the standard pass() or fail() static methods of
1432
+ public void actionPerformed( ActionEvent e )
1434
+ if( e.getActionCommand() == "pass" )
1444
+}// TestDialog class