Skip to content

Commit 6d7e679

Browse files
author
Tejesh R
committedOct 16, 2024
8340790: Open source several AWT Dialog tests - Batch 4
Reviewed-by: honkar, prr
1 parent 86ce19e commit 6d7e679

5 files changed

+517
-0
lines changed
 

‎test/jdk/ProblemList.txt

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ java/awt/KeyboardFocusmanager/ConsumeNextMnemonicKeyTypedTest/ConsumeNextMnemoni
478478

479479
java/awt/Window/GetScreenLocation/GetScreenLocationTest.java 8225787 linux-x64
480480
java/awt/Dialog/MakeWindowAlwaysOnTop/MakeWindowAlwaysOnTop.java 8266243 macosx-aarch64
481+
java/awt/Dialog/ChoiceModalDialogTest.java 8161475 macosx-all
481482
java/awt/Dialog/FileDialogUserFilterTest.java 8001142 generic-all
482483

483484
java/awt/dnd/BadSerializationTest/BadSerializationTest.java 8277817 linux-x64,windows-x64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright (c) 2005, 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 6213128
27+
* @key headful
28+
* @summary Tests that choice is releasing input capture when a modal
29+
* dialog is shown
30+
* @run main ChoiceModalDialogTest
31+
*/
32+
33+
import java.awt.Choice;
34+
import java.awt.Dialog;
35+
import java.awt.EventQueue;
36+
import java.awt.FlowLayout;
37+
import java.awt.Frame;
38+
import java.awt.Robot;
39+
import java.awt.TextField;
40+
import java.awt.event.FocusAdapter;
41+
import java.awt.event.FocusEvent;
42+
import java.awt.event.InputEvent;
43+
import java.awt.event.KeyAdapter;
44+
import java.awt.event.KeyEvent;
45+
import java.awt.event.MouseAdapter;
46+
import java.awt.event.MouseEvent;
47+
48+
public class ChoiceModalDialogTest {
49+
static Frame f;
50+
static Dialog d;
51+
static volatile boolean keyOK;
52+
static volatile boolean mouseOK;
53+
static TextField tf;
54+
static Choice c;
55+
56+
public static void main(String[] args) throws Exception {
57+
Robot r;
58+
try {
59+
r = new Robot();
60+
r.setAutoDelay(100);
61+
EventQueue.invokeAndWait(() -> {
62+
f = new Frame("Frame");
63+
c = new Choice();
64+
f.setBounds(100, 300, 300, 200);
65+
f.setLayout(new FlowLayout());
66+
tf = new TextField(3);
67+
f.add(tf);
68+
69+
c.add("1");
70+
c.add("2");
71+
c.add("3");
72+
c.add("4");
73+
f.add(c);
74+
75+
tf.addFocusListener(new FocusAdapter() {
76+
public void focusLost(FocusEvent ev) {
77+
d = new Dialog(f, "Dialog", true);
78+
d.setBounds(300, 300, 200, 150);
79+
d.addKeyListener(new KeyAdapter() {
80+
public void keyPressed(KeyEvent ev) {
81+
keyOK = true;
82+
}
83+
});
84+
d.addMouseListener(new MouseAdapter() {
85+
public void mousePressed(MouseEvent ev) {
86+
mouseOK = true;
87+
}
88+
});
89+
d.setVisible(true);
90+
}
91+
});
92+
93+
f.setVisible(true);
94+
f.toFront();
95+
});
96+
r.waitForIdle();
97+
r.delay(1000);
98+
EventQueue.invokeAndWait(() -> {
99+
r.mouseMove(tf.getLocationOnScreen().x + tf.getSize().width / 2,
100+
tf.getLocationOnScreen().y + tf.getSize().height / 2);
101+
});
102+
r.waitForIdle();
103+
r.delay(500);
104+
EventQueue.invokeAndWait(() -> {
105+
r.mouseMove(c.getLocationOnScreen().x + c.getSize().width - 4,
106+
c.getLocationOnScreen().y + c.getSize().height / 2);
107+
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
108+
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
109+
});
110+
r.waitForIdle();
111+
r.delay(500);
112+
EventQueue.invokeAndWait(() -> {
113+
r.mouseMove(d.getLocationOnScreen().x + d.getSize().width / 2,
114+
d.getLocationOnScreen().y + d.getSize().height / 2);
115+
r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
116+
r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
117+
r.keyPress(KeyEvent.VK_A);
118+
r.keyRelease(KeyEvent.VK_A);
119+
});
120+
r.waitForIdle();
121+
r.delay(500);
122+
if (!mouseOK) {
123+
throw new RuntimeException("Test Failed due to Mouse release failure!");
124+
}
125+
if (!keyOK) {
126+
throw new RuntimeException("Test Failed due to Key release failure!");
127+
}
128+
System.out.println("Test Passed!");
129+
} finally {
130+
EventQueue.invokeAndWait(() -> {
131+
if (d != null) {
132+
d.dispose();
133+
}
134+
if (f != null) {
135+
f.dispose();
136+
}
137+
});
138+
}
139+
}
140+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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 4255230 4191946
27+
* @summary Tests to verify Dialog inherits background from its owner
28+
* @requires (os.family == "windows")
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual DialogBackgroundTest
32+
*/
33+
34+
import java.awt.Button;
35+
import java.awt.Color;
36+
import java.awt.Dialog;
37+
import java.awt.FlowLayout;
38+
import java.awt.Frame;
39+
import java.awt.Label;
40+
import java.awt.Menu;
41+
import java.awt.MenuBar;
42+
import java.awt.MenuItem;
43+
import java.awt.TextField;
44+
import java.awt.Window;
45+
import java.awt.event.ActionEvent;
46+
import java.awt.event.ActionListener;
47+
import java.awt.event.WindowAdapter;
48+
import java.awt.event.WindowEvent;
49+
50+
public class DialogBackgroundTest {
51+
public static void main(String[] args) throws Exception {
52+
String INSTRUCTIONS = """
53+
Perform the following steps:
54+
1) Select "New Frame" from the "File" menu of the
55+
"TreeCopy Frame #1" frame.
56+
2) Select "Configure" from the "File" menu in the
57+
*new* frame.
58+
If label text "This is a label:" in the appeared
59+
"Configuration Dialog" dialog has a grey background
60+
test PASSES, otherwise it FAILS
61+
""";
62+
TreeCopy treeCopy = new TreeCopy(++TreeCopy.windowCount, null);
63+
PassFailJFrame.builder()
64+
.title("Test Instructions")
65+
.instructions(INSTRUCTIONS)
66+
.rows((int) INSTRUCTIONS.lines().count() + 2)
67+
.columns(35)
68+
.testUI(treeCopy)
69+
.logArea(8)
70+
.build()
71+
.awaitAndCheck();
72+
}
73+
}
74+
75+
class TreeCopy extends Frame implements ActionListener {
76+
TextField tfRoot;
77+
ConfigDialog configDlg;
78+
MenuItem miConfigure = new MenuItem("Configure...");
79+
MenuItem miNewWindow = new MenuItem("New Frame");
80+
static int windowCount = 0;
81+
Window parent;
82+
83+
public TreeCopy(int windowNum, Window myParent) {
84+
super();
85+
setTitle("TreeCopy Frame #" + windowNum);
86+
MenuBar mb = new MenuBar();
87+
Menu m = new Menu("File");
88+
configDlg = new ConfigDialog(this);
89+
parent = myParent;
90+
91+
m.add(miConfigure);
92+
m.add(miNewWindow);
93+
miConfigure.addActionListener(this);
94+
miNewWindow.addActionListener(this);
95+
mb.add(m);
96+
setMenuBar(mb);
97+
m.addActionListener(this);
98+
99+
tfRoot = new TextField();
100+
tfRoot.setEditable(false);
101+
add(tfRoot);
102+
103+
addWindowListener(new WindowAdapter() {
104+
public void windowClosing(WindowEvent we) {
105+
dispose();
106+
}
107+
});
108+
109+
setSize(200, 100);
110+
setLocationRelativeTo(parent);
111+
}
112+
113+
public void actionPerformed(ActionEvent ae) {
114+
Object source = ae.getSource();
115+
116+
if (source == miConfigure) {
117+
configDlg.setVisible(true);
118+
if (configDlg.getBackground() != configDlg.labelColor)
119+
PassFailJFrame.log("FAIL: Test failed!!!");
120+
} else if (source == miNewWindow) {
121+
new TreeCopy(++windowCount, this).setVisible(true);
122+
}
123+
}
124+
}
125+
126+
class ConfigDialog extends Dialog implements ActionListener {
127+
public Button okButton;
128+
public Button cancelButton;
129+
public Label l2;
130+
public Color labelColor;
131+
132+
public ConfigDialog(Frame parent) {
133+
super(parent, "Configuration Dialog");
134+
okButton = new Button("OK");
135+
cancelButton = new Button("Cancel");
136+
l2 = new Label("This is a label:");
137+
138+
setLayout(new FlowLayout());
139+
add(l2);
140+
add(okButton);
141+
add(cancelButton);
142+
143+
okButton.addActionListener(this);
144+
cancelButton.addActionListener(this);
145+
146+
pack();
147+
labelColor = l2.getBackground();
148+
}
149+
150+
public void actionPerformed(ActionEvent ae) {
151+
dispose();
152+
}
153+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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 4232374
27+
* @summary Tests that dismissing a modal dialog does not enable
28+
* disabled components
29+
* @library /java/awt/regtesthelpers
30+
* @build PassFailJFrame
31+
* @run main/manual EnabledResetTest
32+
*/
33+
34+
import java.awt.BorderLayout;
35+
import java.awt.Button;
36+
import java.awt.Dialog;
37+
import java.awt.FlowLayout;
38+
import java.awt.Frame;
39+
import java.awt.Window;
40+
import java.awt.event.ActionEvent;
41+
import java.awt.event.ActionListener;
42+
43+
public class EnabledResetTest {
44+
public static void main(String[] args) throws Exception {
45+
String INSTRUCTIONS = """
46+
1. Press "Create Child" twice to create three windows
47+
Verify that the parent windows are disabled
48+
2. Press "Create Modal Dialog"
49+
Verify that the parent windows are disabled
50+
3. Press "enable"
51+
Verify that no windows accept mouse events
52+
4. Press "ok"
53+
Verify that the first window is still disabled
54+
If all the verifications are done, then test is
55+
PASSED, else test fails.
56+
""";
57+
PassFailJFrame.builder()
58+
.title("Test Instructions")
59+
.instructions(INSTRUCTIONS)
60+
.rows((int) INSTRUCTIONS.lines().count() + 2)
61+
.columns(35)
62+
.testUI(new ChildDialog(1, null))
63+
.build()
64+
.awaitAndCheck();
65+
}
66+
}
67+
68+
class ChildDialog extends Frame implements ActionListener {
69+
Window parent;
70+
int id;
71+
Button b, c, d;
72+
73+
public ChildDialog(int frameNumber, Window myParent) {
74+
super();
75+
id = frameNumber;
76+
parent = myParent;
77+
78+
setTitle("Frame Number " + id);
79+
80+
b = new Button("Dismiss me");
81+
c = new Button("Create Child");
82+
d = new Button("Create Modal Dialog");
83+
84+
setLayout(new BorderLayout());
85+
add("North", c);
86+
add("Center", d);
87+
add("South", b);
88+
pack();
89+
90+
b.addActionListener(this);
91+
c.addActionListener(this);
92+
d.addActionListener(this);
93+
}
94+
95+
public void setVisible(boolean b) {
96+
if (parent != null) {
97+
if (b) {
98+
parent.setEnabled(false);
99+
} else {
100+
parent.setEnabled(true);
101+
parent.requestFocus();
102+
}
103+
}
104+
105+
super.setVisible(b);
106+
}
107+
108+
public void dispose() {
109+
if (parent != null) {
110+
parent.setEnabled(true);
111+
parent.requestFocus();
112+
}
113+
super.dispose();
114+
}
115+
116+
117+
public void actionPerformed(ActionEvent evt) {
118+
if (evt.getSource() == c) {
119+
(new ChildDialog(id + 1, this)).setVisible(true);
120+
} else if (evt.getSource() == d) {
121+
Dialog D = new Dialog(this, "Modal Dialog ");
122+
D.setLayout(new FlowLayout());
123+
Button b = new Button("ok");
124+
Button e = new Button("enable");
125+
D.add(b);
126+
D.add(e);
127+
D.setModal(true);
128+
D.pack();
129+
b.addActionListener(this);
130+
e.addActionListener(this);
131+
D.setVisible(true);
132+
} else if (evt.getSource() == b) {
133+
dispose();
134+
} else if (evt.getSource() instanceof Button) {
135+
if ("ok".equals(evt.getActionCommand())) {
136+
Button target = (Button) evt.getSource();
137+
Window w = (Window) target.getParent();
138+
w.dispose();
139+
}
140+
if ("enable".equals(evt.getActionCommand())) {
141+
parent.setEnabled(true);
142+
}
143+
}
144+
}
145+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2001, 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 4414105
27+
* @summary Tests that FileDialog returns null when cancelled
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual FileDialogGetFileTest
31+
*/
32+
33+
import java.awt.Button;
34+
import java.awt.FileDialog;
35+
import java.awt.Frame;
36+
37+
public class FileDialogGetFileTest {
38+
static FileDialog fd;
39+
static Frame frame;
40+
41+
public static void main(String[] args) throws Exception {
42+
String INSTRUCTIONS = """
43+
1. Open FileDialog from "Show File Dialog" button.
44+
2. Click cancel button without selecting any file/folder.
45+
3. If FileDialog.getFile return null then test PASSES,
46+
else test FAILS automatically.
47+
""";
48+
49+
PassFailJFrame.builder()
50+
.title("Test Instructions")
51+
.instructions(INSTRUCTIONS)
52+
.rows((int) INSTRUCTIONS.lines().count() + 2)
53+
.columns(35)
54+
.testUI(initialize())
55+
.logArea(4)
56+
.build()
57+
.awaitAndCheck();
58+
}
59+
60+
public static Frame initialize() {
61+
frame = new Frame("FileDialog GetFile test");
62+
fd = new FileDialog(frame);
63+
fd.setFile("FileDialogGetFileTest.html");
64+
fd.setBounds(100, 100, 400, 400);
65+
Button showBtn = new Button("Show File Dialog");
66+
frame.add(showBtn);
67+
frame.pack();
68+
showBtn.addActionListener(e -> {
69+
fd.setVisible(true);
70+
if (fd.getFile() != null) {
71+
PassFailJFrame.forceFail("Test failed: FileDialog returned non-null value");
72+
} else {
73+
PassFailJFrame.log("Test Passed!");
74+
}
75+
});
76+
return frame;
77+
}
78+
}

0 commit comments

Comments
 (0)
Please sign in to comment.