Skip to content

Commit 388dbeb

Browse files
committed
8341148: Open source several Choice related tests
Backport-of: 19642bd3833fa96eb4bc7a8a11e902782e0b7844
1 parent 89ad022 commit 388dbeb

File tree

5 files changed

+398
-0
lines changed

5 files changed

+398
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 1998, 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 4130788
27+
* @summary Choice components move unexpectedly when in lightweight containers
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual ChoiceInLWTest
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.Choice;
35+
import java.awt.Container;
36+
import java.awt.FlowLayout;
37+
import java.awt.Frame;
38+
import java.awt.Label;
39+
import java.awt.event.WindowAdapter;
40+
import java.awt.event.WindowEvent;
41+
import java.lang.reflect.InvocationTargetException;
42+
43+
public class ChoiceInLWTest extends Frame implements Runnable {
44+
private final Choice choices;
45+
static final String INSTRUCTIONS = """
46+
After test starts wait for two seconds and open a choice.
47+
If choice's popup obscures the label above it press Fail.
48+
Otherwise press Pass.
49+
""";
50+
51+
public ChoiceInLWTest() {
52+
setLayout(new BorderLayout());
53+
Container lwCont = new Container();
54+
lwCont.setLayout(new FlowLayout());
55+
choices = new Choice();
56+
choices.add("This is just a token item to get a nice width.");
57+
lwCont.add(choices);
58+
add("Center", lwCont);
59+
Label label = new Label("You should see an unobscured Choice below.");
60+
label.setAlignment(Label.CENTER);
61+
add("North", label);
62+
addChoiceItem();
63+
addWindowListener(new WindowAdapter() {
64+
@Override
65+
public void windowOpened(WindowEvent e) {
66+
super.windowOpened(e);
67+
new Thread(ChoiceInLWTest.this).start();
68+
}
69+
});
70+
pack();
71+
}
72+
73+
private void addChoiceItem() {
74+
choices.add("Adding an item used to move the Choice!");
75+
}
76+
77+
public void run() {
78+
try {
79+
Thread.sleep(1000);
80+
} catch (InterruptedException ignore) {
81+
}
82+
addChoiceItem();
83+
}
84+
85+
public static void main(String[] args) throws InterruptedException,
86+
InvocationTargetException {
87+
PassFailJFrame.builder()
88+
.title("Choice in LW Container Test")
89+
.testUI(ChoiceInLWTest::new)
90+
.instructions(INSTRUCTIONS)
91+
.columns(40)
92+
.build()
93+
.awaitAndCheck();
94+
95+
}
96+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 6367251
27+
* @summary 2 items are highlighted when pressing, dragging the mouse inside the choice, XToolkit
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual MultiItemSelected_DragOut
31+
*/
32+
33+
import java.awt.Choice;
34+
import java.awt.FlowLayout;
35+
import java.awt.Frame;
36+
import java.lang.reflect.InvocationTargetException;
37+
38+
public class MultiItemSelected_DragOut extends Frame {
39+
static final String INSTRUCTIONS = """
40+
1) Open Choice.
41+
2) Start drag from first item to second or third one.
42+
3) Without releasing left mouse button
43+
press and release right mouse button.
44+
4) Release left mouse button.
45+
5) Open choice again.
46+
6) If there is only one selection cursor
47+
in the dropdown list press Pass otherwise press Fail.
48+
""";
49+
50+
public MultiItemSelected_DragOut() {
51+
Choice choice = new Choice();
52+
53+
for (int i = 1; i < 10; i++) {
54+
choice.add("item " + i);
55+
}
56+
add(choice);
57+
choice.addItemListener(ie -> System.out.println(ie));
58+
59+
setLayout(new FlowLayout());
60+
setSize(200, 200);
61+
validate();
62+
}
63+
64+
public static void main(String[] args) throws InterruptedException,
65+
InvocationTargetException {
66+
PassFailJFrame.builder()
67+
.title("MultiItemSelected Drag Out Test")
68+
.testUI(MultiItemSelected_DragOut::new)
69+
.instructions(INSTRUCTIONS)
70+
.columns(40)
71+
.build()
72+
.awaitAndCheck();
73+
}
74+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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 6367251
27+
* @summary 2 items are highlighted when dragging inside and press ESC or ENTER
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual MultiItemSelected_KeySelect
31+
*/
32+
33+
import java.awt.Choice;
34+
import java.awt.FlowLayout;
35+
import java.awt.Frame;
36+
import java.lang.reflect.InvocationTargetException;
37+
38+
public class MultiItemSelected_KeySelect extends Frame {
39+
static final String INSTRUCTIONS = """
40+
1) Open Choice.
41+
2) Start drag from first item to another one.
42+
3) Without releasing the mouse button press ESC key.
43+
4) Open choice again.
44+
5) Verify that there is only one
45+
selection cursor in the dropdown list.
46+
6) Repeat steps 2-5 once again but this time
47+
press ENTER key instead of ESC.
48+
7) If in both scenarios there is only one selection cursor
49+
press Pass otherwise press Fail.
50+
""";
51+
52+
public MultiItemSelected_KeySelect() {
53+
Choice choice = new Choice();
54+
55+
for (int i = 1; i < 10; i++) {
56+
choice.add("item " + i);
57+
}
58+
add(choice);
59+
choice.addItemListener(ie -> System.out.println(ie));
60+
setLayout(new FlowLayout());
61+
setSize(200, 200);
62+
validate();
63+
}
64+
65+
public static void main(String[] args) throws InterruptedException,
66+
InvocationTargetException {
67+
PassFailJFrame.builder()
68+
.title("MultiItemSelected Key Select Test")
69+
.testUI(MultiItemSelected_KeySelect::new)
70+
.instructions(INSTRUCTIONS)
71+
.columns(40)
72+
.build()
73+
.awaitAndCheck();
74+
}
75+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 6367251
27+
* @summary 2 items are highlighted when dragging outside and press UP or DOWN
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual MultiItemSelected_UpDown
31+
*/
32+
33+
import java.awt.Choice;
34+
import java.awt.FlowLayout;
35+
import java.awt.Frame;
36+
import java.lang.reflect.InvocationTargetException;
37+
38+
public class MultiItemSelected_UpDown extends Frame {
39+
static final String INSTRUCTIONS = """
40+
1) Open Choice.
41+
2) Start drag from first item to another one.
42+
3) Without interrupting drag
43+
move mouse cursor outside the choice popup.
44+
4) Press UP, DOWN key several times to position
45+
selection cursor to a different item.
46+
5) Release mouse button.
47+
6) If popup is closed upon mouse button release open Choice again.
48+
7) Verify that there is only one
49+
selection cursor in the dropdown list.
50+
8) If true then press Pass, otherwise press Fail.
51+
""";
52+
53+
public MultiItemSelected_UpDown() {
54+
Choice choice = new Choice();
55+
56+
for (int i = 1; i < 20; i++) {
57+
choice.add(" item " + i);
58+
}
59+
add(choice);
60+
choice.addItemListener(ie -> System.out.println(ie));
61+
setLayout(new FlowLayout());
62+
setSize(200, 200);
63+
validate();
64+
}
65+
66+
public static void main(String[] args) throws InterruptedException,
67+
InvocationTargetException {
68+
PassFailJFrame.builder()
69+
.title("MultiItemSelected Up/Down Test")
70+
.testUI(MultiItemSelected_UpDown::new)
71+
.instructions(INSTRUCTIONS)
72+
.columns(40)
73+
.build()
74+
.awaitAndCheck();
75+
}
76+
}

0 commit comments

Comments
 (0)