Skip to content

Commit 255a4aa

Browse files
committed
8340719: Open source AWT List tests
Backport-of: b11066b56b69b2c526539e712cef47723098597f
1 parent ca90fda commit 255a4aa

File tree

5 files changed

+414
-0
lines changed

5 files changed

+414
-0
lines changed

test/jdk/ProblemList.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ java/awt/PopupMenu/PopupMenuLocation.java 8238720 windows-all
494494
java/awt/GridLayout/ComponentPreferredSize/ComponentPreferredSize.java 8238720,8324782 windows-all,macosx-all
495495
java/awt/GridLayout/ChangeGridSize/ChangeGridSize.java 8238720,8324782 windows-all,macosx-all
496496
java/awt/event/MouseEvent/FrameMouseEventAbsoluteCoordsTest/FrameMouseEventAbsoluteCoordsTest.java 8238720 windows-all
497+
java/awt/List/HandlingKeyEventIfMousePressedTest.java 6848358 macosx-all,windows-all
497498

498499
# Several tests which fail sometimes on macos11
499500
java/awt/Window/MainKeyWindowTest/TestMainKeyWindow.java 8265985 macosx-all
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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 6293432
27+
* @summary Key events ('SPACE', 'UP', 'DOWN') aren't blocked
28+
* if mouse is kept in 'PRESSED' state for List
29+
* @key headful
30+
* @run main HandlingKeyEventIfMousePressedTest
31+
*/
32+
33+
import java.awt.EventQueue;
34+
import java.awt.FlowLayout;
35+
import java.awt.Frame;
36+
import java.awt.List;
37+
import java.awt.Point;
38+
import java.awt.Robot;
39+
import java.awt.event.ActionEvent;
40+
import java.awt.event.ActionListener;
41+
import java.awt.event.FocusAdapter;
42+
import java.awt.event.FocusEvent;
43+
import java.awt.event.InputEvent;
44+
import java.awt.event.ItemEvent;
45+
import java.awt.event.ItemListener;
46+
import java.awt.event.KeyEvent;
47+
import java.awt.event.MouseAdapter;
48+
import java.awt.event.MouseEvent;
49+
import java.awt.event.MouseMotionAdapter;
50+
51+
public class HandlingKeyEventIfMousePressedTest {
52+
53+
static Frame frame;
54+
static List list;
55+
static volatile Point loc;
56+
57+
public static void main(String[] args) throws Exception {
58+
Robot robot = new Robot();
59+
robot.setAutoDelay(100);
60+
try {
61+
EventQueue.invokeAndWait(() -> createUI());
62+
robot.waitForIdle();
63+
robot.delay(1000);
64+
EventQueue.invokeAndWait(() -> {
65+
loc = list.getLocationOnScreen();
66+
});
67+
robot.mouseMove(loc.x + 10, loc.y + 10);
68+
robot.waitForIdle();
69+
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
70+
71+
// key pressing when the mouse is kept in the 'pressed' state
72+
robot.keyPress(KeyEvent.VK_DOWN);
73+
robot.keyRelease(KeyEvent.VK_DOWN);
74+
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
75+
robot.waitForIdle();
76+
77+
int selectedIndex = list.getSelectedIndex();
78+
if (selectedIndex != 0) {
79+
throw new RuntimeException("Test failed: list.getCurrentItem = " + selectedIndex);
80+
}
81+
} finally {
82+
EventQueue.invokeAndWait(() -> {
83+
if (frame != null) {
84+
frame.dispose();
85+
}
86+
});
87+
}
88+
}
89+
90+
private static void createUI() {
91+
frame = new Frame("HandlingKeyEventIfMousePressedTest");
92+
list = new List(10, false);
93+
94+
list.add("111");
95+
list.add("222");
96+
list.add("333");
97+
list.add("444");
98+
frame.add(list);
99+
100+
addListeners();
101+
102+
frame.setLayout(new FlowLayout());
103+
frame.pack();
104+
frame.setLocationRelativeTo(null);
105+
frame.setVisible(true);
106+
}
107+
108+
// added in order to have more information in failed case
109+
private static void addListeners() {
110+
111+
list.addMouseMotionListener(
112+
new MouseMotionAdapter() {
113+
@Override
114+
public void mouseDragged(MouseEvent me) {
115+
System.out.println(me);
116+
}
117+
118+
@Override
119+
public void mouseMoved(MouseEvent me) {
120+
System.out.println(me);
121+
}
122+
});
123+
124+
list.addMouseListener(
125+
new MouseAdapter(){
126+
public void mousePressed(MouseEvent me) {
127+
System.out.println(me);
128+
}
129+
public void mouseClicked(MouseEvent me) {
130+
System.out.println(me);
131+
}
132+
public void mouseEntered(MouseEvent me) {
133+
System.out.println(me);
134+
}
135+
public void mouseExited(MouseEvent me) {
136+
System.out.println(me);
137+
}
138+
public void mouseReleased(MouseEvent me) {
139+
System.out.println(me);
140+
}
141+
});
142+
143+
list.addActionListener(
144+
new ActionListener() {
145+
public void actionPerformed(ActionEvent ae) {
146+
System.out.println(ae);
147+
}
148+
});
149+
150+
list.addItemListener(
151+
new ItemListener() {
152+
public void itemStateChanged(ItemEvent ie) {
153+
System.out.println(ie);
154+
}
155+
});
156+
157+
list.addFocusListener(
158+
new FocusAdapter() {
159+
public void focusGained(FocusEvent fe) {
160+
System.out.println(fe);
161+
}
162+
public void focusLost(FocusEvent fe) {
163+
System.out.println(fe);
164+
}
165+
});
166+
}
167+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2002, 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 4089604
27+
* @summary Enter key doesn't fire List actionPerformed as specified
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual ListActionEventTest
31+
*/
32+
33+
import java.awt.BorderLayout;
34+
import java.awt.Frame;
35+
import java.awt.List;
36+
import java.awt.Panel;
37+
import java.awt.event.ActionEvent;
38+
import java.awt.event.ActionListener;
39+
import java.awt.event.ItemEvent;
40+
import java.awt.event.ItemListener;
41+
42+
public class ListActionEventTest {
43+
44+
private static final String INSTRUCTIONS = """
45+
A frame will be shown.
46+
1. Click any item in the list (say item 1) in the frame
47+
2. A message 'ItemSelected' is displayed on the message window.
48+
3. Press the return key on the selected item.
49+
4. If the text 'ActionPerformed' is displayed on the message window,
50+
then press PASS else press FAIL.""";
51+
52+
public static void main(String[] args) throws Exception {
53+
PassFailJFrame.builder()
54+
.title("ListActionEventTest Instructions")
55+
.instructions(INSTRUCTIONS)
56+
.rows((int) INSTRUCTIONS.lines().count() + 2)
57+
.columns(35)
58+
.testUI(ListActionEventTest::createTestUI)
59+
.logArea()
60+
.build()
61+
.awaitAndCheck();
62+
}
63+
64+
private static Frame createTestUI() {
65+
Frame frame = new Frame("ListActionEventTest frame");
66+
67+
Panel pnl1 = new Panel();
68+
frame.add(pnl1);
69+
pnl1.setLayout(new BorderLayout());
70+
71+
List list = new List();
72+
for (int i = 0; i < 5; i++) {
73+
list.addItem("Item " + i);
74+
}
75+
pnl1.add(list);
76+
77+
list.addActionListener(new ActionListener() {
78+
@Override
79+
public void actionPerformed(ActionEvent ev) {
80+
PassFailJFrame.log("ActionPerformed");
81+
}
82+
});
83+
84+
list.addItemListener(new ItemListener() {
85+
@Override
86+
public void itemStateChanged(ItemEvent ev) {
87+
PassFailJFrame.log("ItemSelected");
88+
}
89+
});
90+
frame.pack();
91+
return frame;
92+
}
93+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 4102881
27+
* @summary Ensure multiple selection Lists have horizontal scrollbars when necessary
28+
* @library /java/awt/regtesthelpers
29+
* @build PassFailJFrame
30+
* @run main/manual MultiSelectionListHorizScrollbar
31+
*/
32+
33+
import java.awt.Frame;
34+
import java.awt.GridLayout;
35+
import java.awt.List;
36+
37+
public class MultiSelectionListHorizScrollbar {
38+
39+
private static final String INSTRUCTIONS = """
40+
Resize the frame so that the lists are not wide enough
41+
to fully display the lines of text they contain.
42+
Once the lists are in this state, press pass
43+
if both lists display an horizontal scrollbar. Otherwise press fail.""";
44+
45+
public static void main(String[] args) throws Exception {
46+
PassFailJFrame.builder()
47+
.title("MultiSelectionListHorizScrollbar Instructions")
48+
.instructions(INSTRUCTIONS)
49+
.rows((int) INSTRUCTIONS.lines().count() + 2)
50+
.columns(35)
51+
.testUI(MultiSelectionListHorizScrollbar::createTestUI)
52+
.build()
53+
.awaitAndCheck();
54+
}
55+
56+
private static Frame createTestUI() {
57+
Frame frame = new Frame("MultiSelectionListHorizScrollbar Frame");
58+
List singleList = new List(3);
59+
List multiList = new List(3, true);
60+
61+
frame.setLayout(new GridLayout(1, 2));
62+
frame.add(singleList);
63+
frame.add(multiList);
64+
65+
singleList.addItem("This is the 1st item in the list! Does it scroll horizontally??");
66+
singleList.addItem("This is the 2nd item in the list! Does it scroll horizontally??");
67+
singleList.addItem("This is the 4th item in the list! Does it scroll horizontally??");
68+
singleList.addItem("This is the 5th item in the list! Does it scroll horizontally??");
69+
singleList.addItem("This is the 6th item in the list! Does it scroll horizontally??");
70+
71+
multiList.addItem("This is the 1st item in the list! Does it scroll horizontally??");
72+
multiList.addItem("This is the 2nd item in the list! Does it scroll horizontally??");
73+
multiList.addItem("This is the 4th item in the list! Does it scroll horizontally??");
74+
multiList.addItem("This is the 5th item in the list! Does it scroll horizontally??");
75+
multiList.addItem("This is the 6th item in the list! Does it scroll horizontally??");
76+
77+
frame.pack();
78+
return frame;
79+
}
80+
}

0 commit comments

Comments
 (0)