author | goetz |
Tue, 14 Jun 2016 10:44:59 +0200 | |
changeset 39056 | d99e63b6d962 |
parent 37541 | 34e985130348 |
child 45524 | ba8c2add2e0b |
permissions | -rw-r--r-- |
37541
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
1 |
/* |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
37541
diff
changeset
|
2 |
* Copyright (c) 2016, 2016, Oracle and/or its affiliates. All rights reserved. |
37541
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
4 |
* |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
8 |
* |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
13 |
* accompanied this code). |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
14 |
* |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
18 |
* |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
21 |
* questions. |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
22 |
*/ |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
23 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
24 |
/* |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
37541
diff
changeset
|
25 |
* @test |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
37541
diff
changeset
|
26 |
* @key headful |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
37541
diff
changeset
|
27 |
* @bug 8033936 |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
37541
diff
changeset
|
28 |
* @summary Verify that correct ItemEvent is received while selection & |
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
37541
diff
changeset
|
29 |
* deselection of multi select List items. |
37541
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
30 |
*/ |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
31 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
32 |
import java.awt.AWTException; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
33 |
import java.awt.Event; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
34 |
import java.awt.FlowLayout; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
35 |
import java.awt.Frame; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
36 |
import java.awt.List; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
37 |
import java.awt.Point; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
38 |
import java.awt.Rectangle; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
39 |
import java.awt.Robot; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
40 |
import java.awt.event.KeyEvent; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
41 |
import java.awt.event.InputEvent; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
42 |
import java.awt.event.ItemEvent; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
43 |
import java.awt.event.ItemListener; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
44 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
45 |
public class ItemEventTest extends Frame |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
46 |
{ |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
47 |
List list; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
48 |
final String expectedSelectionOrder; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
49 |
StringBuilder actualSelectionOrder; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
50 |
Robot robot; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
51 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
52 |
public ItemEventTest() |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
53 |
{ |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
54 |
try { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
55 |
robot = new Robot(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
56 |
} catch(AWTException e) { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
57 |
throw new RuntimeException(e.getMessage()); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
58 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
59 |
expectedSelectionOrder = "01230123"; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
60 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
61 |
list = new List(4, true); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
62 |
list.add("0"); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
63 |
list.add("1"); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
64 |
list.add("2"); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
65 |
list.add("3"); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
66 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
67 |
add(list); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
68 |
setSize(400,400); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
69 |
setLayout(new FlowLayout()); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
70 |
pack(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
71 |
setVisible(true); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
72 |
robot.waitForIdle(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
73 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
74 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
75 |
@Override |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
76 |
public boolean handleEvent(Event e) { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
77 |
if (e.target instanceof List) { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
78 |
if (e.id == Event.LIST_DESELECT || e.id == Event.LIST_SELECT) { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
79 |
actualSelectionOrder.append(e.arg); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
80 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
81 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
82 |
return true; |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
83 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
84 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
85 |
void testHandleEvent() { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
86 |
// When no ItemListener is added to List, parent's handleEvent is |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
87 |
// called with ItemEvent. |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
88 |
performTest(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
89 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
90 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
91 |
void testItemListener() { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
92 |
list.addItemListener(new ItemListener() { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
93 |
@Override |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
94 |
public void itemStateChanged(ItemEvent ie) { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
95 |
actualSelectionOrder.append(ie.getItem()); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
96 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
97 |
}); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
98 |
performTest(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
99 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
100 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
101 |
void performTest() { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
102 |
actualSelectionOrder = new StringBuilder(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
103 |
Point loc = list.getLocationOnScreen(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
104 |
Rectangle rect = list.getBounds(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
105 |
int dY = rect.height / list.getItemCount(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
106 |
loc = new Point(loc.x + 10, loc.y + 5); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
107 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
108 |
String osName = System.getProperty("os.name"); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
109 |
boolean isMac = osName.contains("Mac") || osName.contains("mac"); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
110 |
if(isMac) { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
111 |
robot.keyPress(KeyEvent.VK_META); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
112 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
113 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
114 |
// First loop to select & Second loop to deselect the list items. |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
115 |
for (int j = 0; j < 2; ++j) { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
116 |
for (int i = 0; i < list.getItemCount(); ++i) { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
117 |
robot.mouseMove(loc.x, loc.y + i * dY); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
118 |
robot.mousePress(InputEvent.BUTTON1_MASK); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
119 |
robot.delay(100); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
120 |
robot.mouseRelease(InputEvent.BUTTON1_MASK); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
121 |
robot.waitForIdle(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
122 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
123 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
124 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
125 |
if(isMac) { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
126 |
robot.keyRelease(KeyEvent.VK_META); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
127 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
128 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
129 |
if (!expectedSelectionOrder.equals(actualSelectionOrder.toString())) { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
130 |
dispose(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
131 |
throw new RuntimeException("ItemEvent for selection & deselection" |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
132 |
+ " of multi select List's item is not correct" |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
133 |
+ " Expected : " + expectedSelectionOrder |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
134 |
+ " Actual : " + actualSelectionOrder); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
135 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
136 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
137 |
|
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
138 |
public static void main(String args[]) { |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
139 |
ItemEventTest test = new ItemEventTest(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
140 |
test.testHandleEvent(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
141 |
test.testItemListener(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
142 |
test.dispose(); |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
143 |
} |
34e985130348
8033936: java.awt.List events are not sent properly to handleEvent or ItemListener
arapte
parents:
diff
changeset
|
144 |
} |