author | ihse |
Tue, 09 May 2017 12:57:30 +0200 | |
changeset 45028 | b0ea3c0bfb81 |
parent 40128 | e635645d2a8a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
45028
b0ea3c0bfb81
8179889: Fix typographic errors in copyright headers
ihse
parents:
40128
diff
changeset
|
2 |
* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
@test |
|
40128
e635645d2a8a
8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents:
32680
diff
changeset
|
26 |
@key headful |
32680
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
27 |
@bug 6566434 8039467 |
2 | 28 |
@library ../../regtesthelpers |
29 |
@build Util Sysout AbstractTest |
|
30 |
@summary Choice in unfocusable window responds to keyboard |
|
31 |
@author Andrei Dmitriev: area=awt-choice |
|
32 |
@run main UnfocusableToplevel |
|
33 |
*/ |
|
34 |
||
35 |
/** |
|
36 |
* UnfocusableToplevel.java |
|
37 |
* |
|
38 |
* summary: |
|
39 |
*/ |
|
40 |
||
41 |
import java.awt.*; |
|
42 |
import java.awt.event.*; |
|
43 |
import test.java.awt.regtesthelpers.AbstractTest; |
|
44 |
import test.java.awt.regtesthelpers.Sysout; |
|
45 |
import test.java.awt.regtesthelpers.Util; |
|
46 |
||
47 |
public class UnfocusableToplevel { |
|
48 |
||
49 |
final static Robot robot = Util.createRobot(); |
|
50 |
final static int REASONABLE_PATH_TIME = 5000; |
|
51 |
||
52 |
public static void main(String []s) |
|
53 |
{ |
|
54 |
Frame f = new Frame(); |
|
55 |
Window w = new Window(f); |
|
56 |
final Choice ch = new Choice(); |
|
57 |
||
58 |
ch.add("item 1"); |
|
59 |
ch.add("item 2"); |
|
60 |
ch.add("item 3"); |
|
61 |
ch.add("item 4"); |
|
62 |
ch.add("item 5"); |
|
63 |
w.add(ch); |
|
64 |
w.setLayout(new FlowLayout()); |
|
65 |
w.setSize(200, 200); |
|
66 |
||
32680
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
67 |
// Note that Window w is non focusable. Key press events will not be |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
68 |
// consumed by w, but by any previously focused window & this can |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
69 |
// disturb the environment. So creating tempFrameToHoldFocus frame, |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
70 |
// to consume key press events. |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
71 |
Frame tempFrameToHoldFocus = new Frame(); |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
72 |
tempFrameToHoldFocus.setVisible(true); |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
73 |
Util.waitForIdle(robot); |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
74 |
|
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
75 |
tempFrameToHoldFocus.requestFocus(); |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
76 |
Util.clickOnComp(tempFrameToHoldFocus, robot); |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
77 |
Util.waitForIdle(robot); |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
78 |
|
2 | 79 |
ch.addKeyListener(new KeyAdapter(){ |
80 |
public void keyTyped(KeyEvent e){ |
|
81 |
traceEvent("keytyped", e); |
|
82 |
} |
|
83 |
public void keyPressed(KeyEvent e){ |
|
84 |
traceEvent("keypress", e); |
|
85 |
} |
|
86 |
public void keyReleased(KeyEvent e){ |
|
87 |
traceEvent("keyrelease", e); |
|
88 |
} |
|
89 |
}); |
|
90 |
||
91 |
ch.addItemListener(new ItemListener(){ |
|
92 |
public void itemStateChanged(ItemEvent ie){ |
|
93 |
traceEvent("stateChanged", ie); |
|
94 |
} |
|
95 |
}); |
|
96 |
||
97 |
w.setVisible(true); |
|
98 |
||
99 |
Util.waitForIdle(robot); |
|
100 |
||
101 |
Util.clickOnComp(ch, robot); |
|
102 |
Util.waitForIdle(robot); |
|
103 |
||
104 |
// will not test if the dropdown become opened as there is no reliable |
|
105 |
// technique to accomplish that rather then checking color of dropdown |
|
106 |
// Will suppose that the dropdown appears |
|
107 |
||
108 |
testKeys(); |
|
109 |
Util.waitForIdle(robot); |
|
32680
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
110 |
|
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
111 |
tempFrameToHoldFocus.dispose(); |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
112 |
w.dispose(); |
93639d43d72f
8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents:
5506
diff
changeset
|
113 |
f.dispose(); |
2 | 114 |
} |
115 |
||
116 |
private static void testKeys(){ |
|
117 |
typeKey(KeyEvent.VK_UP); |
|
118 |
typeKey(KeyEvent.VK_DOWN); |
|
119 |
typeKey(KeyEvent.VK_K); |
|
120 |
typeKey(KeyEvent.VK_PAGE_UP); |
|
121 |
typeKey(KeyEvent.VK_PAGE_DOWN); |
|
122 |
} |
|
123 |
||
124 |
private static void typeKey(int keyChar){ |
|
125 |
try { |
|
126 |
robot.keyPress(keyChar); |
|
127 |
robot.delay(5); |
|
128 |
} finally { |
|
129 |
robot.keyRelease(keyChar); |
|
130 |
} |
|
131 |
robot.delay(100); |
|
132 |
} |
|
133 |
||
134 |
private static void traceEvent(String message, AWTEvent e){ |
|
135 |
AbstractTest.fail(message + " " + e.toString()); |
|
136 |
} |
|
137 |
} |