Skip to content

Commit 6d7e679

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

File tree

5 files changed

+517
-0
lines changed

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+
}

0 commit comments

Comments
 (0)