Skip to content

Commit 01e754f

Browse files
author
Satyen Subramaniam
committed
8340015: Open source several AWT focus tests - series 7
Reviewed-by: shade Backport-of: 147e30070d8adbe65453a3a9316b9324890ea25f
1 parent 4771398 commit 01e754f

File tree

4 files changed

+266
-1
lines changed

4 files changed

+266
-1
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,6 @@ java/awt/Checkbox/CheckboxBoxSizeTest.java 8340870 windows-all
848848
java/awt/Checkbox/CheckboxIndicatorSizeTest.java 8340870 windows-all
849849
java/awt/Checkbox/CheckboxNullLabelTest.java 8340870 windows-all
850850
java/awt/dnd/WinMoveFileToShellTest.java 8341665 windows-all
851-
851+
java/awt/Focus/MinimizeNonfocusableWindowTest.java 8024487 windows-all
852852

853853
############################################################################
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2011, 2024, 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+
* @bug 6399659
27+
* @summary When minimizing non-focusable window focus shouldn't jump out of the focused window.
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual MinimizeNonfocusableWindowTest
31+
*/
32+
33+
import java.awt.Frame;
34+
import java.awt.Window;
35+
import java.util.List;
36+
37+
public class MinimizeNonfocusableWindowTest {
38+
39+
private static final String INSTRUCTIONS = """
40+
41+
You should see three frames: Frame-1, Frame-2 and Unfocusable.
42+
43+
1. Click Frame-1 to make it focused window, then click Frame-2.
44+
Minimize Unfocusable frame with the mouse. If Frame-2 is still
45+
the focused window continue testing, otherwise press FAIL.
46+
47+
2. Restore Unfocusable frame to normal state. Try to resize by dragging
48+
its edge with left mouse button. It should be resizable. If not press
49+
FAIL. Try the same with right mouse button. It shouldn't resize.
50+
If it does, press FAIL, otherwise press PASS.""";
51+
52+
public static void main(String[] args) throws Exception {
53+
PassFailJFrame.builder()
54+
.title("MinimizeNonfocusableWindowTest Instructions")
55+
.instructions(INSTRUCTIONS)
56+
.rows((int) INSTRUCTIONS.lines().count() + 1)
57+
.columns(40)
58+
.testUI(MinimizeNonfocusableWindowTest::createTestUI)
59+
.build()
60+
.awaitAndCheck();
61+
}
62+
63+
private static List<Window> createTestUI() {
64+
Frame frame1 = new Frame("Frame-1");
65+
Frame frame2 = new Frame("Frame-2");
66+
Frame frame3 = new Frame("Unfocusable");
67+
frame1.setBounds(100, 0, 200, 100);
68+
frame2.setBounds(100, 150, 200, 100);
69+
frame3.setBounds(100, 300, 200, 100);
70+
71+
frame3.setFocusableWindowState(false);
72+
73+
return List.of(frame1, frame2, frame3);
74+
}
75+
}
76+
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (c) 1999, 2024, 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+
* @bug 4257071 4228379
27+
* @summary Ensures that focus lost is delivered to a lightweight component
28+
in a disposed window
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual WindowDisposeFocusTest
32+
*/
33+
34+
import java.awt.Window;
35+
import java.awt.event.WindowAdapter;
36+
import java.awt.event.WindowEvent;
37+
import javax.swing.JButton;
38+
import javax.swing.JDialog;
39+
import javax.swing.JFrame;
40+
import javax.swing.JPanel;
41+
42+
public class WindowDisposeFocusTest {
43+
44+
private static final String INSTRUCTIONS = """
45+
Click on "Second"
46+
Click on close box
47+
When dialog pops up, "Second" should no longer have focus.""";
48+
49+
public static void main(String[] args) throws Exception {
50+
PassFailJFrame.builder()
51+
.title("WindowDisposeFocusTest Instructions")
52+
.instructions(INSTRUCTIONS)
53+
.rows((int) INSTRUCTIONS.lines().count() + 2)
54+
.columns(35)
55+
.testUI(WindowDisposeFocusTest::createTestUI)
56+
.build()
57+
.awaitAndCheck();
58+
}
59+
60+
private static Window createTestUI() {
61+
return JFCFocusBug2.test(new String[]{});
62+
}
63+
}
64+
65+
class JFCFocusBug2 extends JPanel {
66+
67+
static public Window test(String[] args) {
68+
final JFrame frame = new JFrame("WindowDisposeFrame");
69+
frame.setSize(100, 100);
70+
frame.setVisible(true);
71+
72+
final JFCFocusBug2 bug = new JFCFocusBug2();
73+
final JDialog dialog = new JDialog(frame, false);
74+
dialog.addWindowListener(new WindowAdapter() {
75+
public void windowClosing(WindowEvent e) {
76+
dialog.dispose();
77+
JDialog dialog2 = new JDialog(frame, false);
78+
dialog2.setContentPane(bug);
79+
dialog2.pack();
80+
dialog2.setVisible(true);
81+
}
82+
});
83+
dialog.setContentPane(bug);
84+
dialog.pack();
85+
dialog.setVisible(true);
86+
return frame;
87+
}
88+
89+
public JFCFocusBug2() {
90+
_first = new JButton("First");
91+
_second = new JButton("Second");
92+
add(_first);
93+
add(_second);
94+
}
95+
96+
private JButton _first;
97+
private JButton _second;
98+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (c) 2006, 2024, 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+
* @bug 6435715
27+
* @summary JButton stops receiving the focusGained event and eventually focus is lost altogether
28+
* @modules java.desktop/sun.awt
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual bug6435715
32+
*/
33+
34+
import java.awt.event.FocusAdapter;
35+
import java.awt.event.FocusEvent;
36+
import javax.swing.JButton;
37+
import javax.swing.JFrame;
38+
import javax.swing.JPanel;
39+
40+
public class bug6435715 {
41+
42+
private static final String INSTRUCTIONS = """
43+
1. after test started you will see frame with three buttons. Notice that focus is on Button2.
44+
2. Click on Button 3. Focus goes to Button3.
45+
3. Click on Button1 and quickly switch to another window. Via either alt/tab or
46+
clicking another window with the mouse.
47+
4. After a few seconds, come back to the frame. Notice that focus is around Button2
48+
5. Click at Button3. If focus remains at Button2 test failed, if focus is on Button3 - test passed.""";
49+
50+
public static void main(String[] args) throws Exception {
51+
PassFailJFrame.builder()
52+
.title("bug6435715 Instructions")
53+
.instructions(INSTRUCTIONS)
54+
.rows((int) INSTRUCTIONS.lines().count() + 5)
55+
.columns(35)
56+
.testUI(bug6435715::createTestUI)
57+
.build()
58+
.awaitAndCheck();
59+
}
60+
61+
private static JFrame createTestUI() {
62+
JFrame fr = new JFrame("FocusIssue");
63+
sun.awt.SunToolkit.setLWRequestStatus(fr, true);
64+
65+
JPanel panel = new JPanel();
66+
final JButton b1 = new JButton("Button 1");
67+
final JButton b2 = new JButton("Button 2");
68+
final JButton b3 = new JButton("Button 3");
69+
70+
panel.add(b1);
71+
panel.add(b2);
72+
panel.add(b3);
73+
74+
b1.addFocusListener(new FocusAdapter() {
75+
public void focusGained(FocusEvent event) {
76+
synchronized (this) {
77+
try {
78+
wait(1000);
79+
} catch (Exception ex) {
80+
ex.printStackTrace();
81+
}
82+
b2.requestFocus();
83+
}
84+
}
85+
});
86+
fr.getContentPane().add(panel);
87+
fr.pack();
88+
return fr;
89+
}
90+
91+
}

0 commit comments

Comments
 (0)