author | serb |
Wed, 27 Feb 2019 18:46:55 -0800 | |
changeset 54231 | e4813eded7cb |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
17893
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
1 |
/* |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
17893
diff
changeset
|
2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
17893
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
4 |
* |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
8 |
* |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
13 |
* accompanied this code). |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
14 |
* |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
18 |
* |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
21 |
* questions. |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
22 |
*/ |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
23 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
24 |
/* |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
25 |
@test |
39056
d99e63b6d962
8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents:
17893
diff
changeset
|
26 |
@key headful |
17893
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
27 |
@bug 8013773 |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
28 |
@summary Tests that disabled component is not retained as most recent focus owner. |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
29 |
@library ../../regtesthelpers |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
30 |
@build Util |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
31 |
@run main ResetMostRecentFocusOwnerTest |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
32 |
*/ |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
33 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
34 |
import java.awt.AWTEvent; |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
35 |
import java.awt.Robot; |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
36 |
import java.awt.Toolkit; |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
37 |
import java.awt.event.AWTEventListener; |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
38 |
import java.awt.event.FocusEvent; |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
39 |
import java.awt.event.WindowEvent; |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
40 |
import javax.swing.JButton; |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
41 |
import javax.swing.JFrame; |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
42 |
import test.java.awt.regtesthelpers.Util; |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
43 |
|
54231
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
44 |
public class ResetMostRecentFocusOwnerTest { |
17893
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
45 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
46 |
public static void main(String[] args) { |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
47 |
ResetMostRecentFocusOwnerTest app = new ResetMostRecentFocusOwnerTest(); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
48 |
app.start(); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
49 |
} |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
50 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
51 |
public void start() { |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
52 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
53 |
Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
54 |
public void eventDispatched(AWTEvent e) { |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
55 |
System.err.println(e); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
56 |
} |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
57 |
}, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
58 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
59 |
boolean gained = false; |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
60 |
final Robot robot = Util.createRobot(); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
61 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
62 |
JFrame frame1 = new JFrame("Main Frame"); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
63 |
final JButton b1 = new JButton("button1"); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
64 |
frame1.add(b1); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
65 |
frame1.pack(); |
54231
e4813eded7cb
8213110: Remove the use of applets in automatic tests
serb
parents:
47216
diff
changeset
|
66 |
frame1.setLocation(100, 300); |
17893
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
67 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
68 |
Util.showWindowWait(frame1); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
69 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
70 |
final JFrame frame2 = new JFrame("Test Frame"); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
71 |
final JButton b2 = new JButton("button2"); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
72 |
frame2.add(b2); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
73 |
frame2.pack(); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
74 |
frame2.setLocation(300, 300); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
75 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
76 |
b2.setEnabled(false); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
77 |
b2.requestFocus(); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
78 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
79 |
Util.showWindowWait(frame2); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
80 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
81 |
robot.delay(500); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
82 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
83 |
// |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
84 |
// It's expeced that the focus is restored to <button1>. |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
85 |
// If not, click <button1> to set focus on it. |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
86 |
// |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
87 |
if (!b1.hasFocus()) { |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
88 |
gained = Util.trackFocusGained(b1, new Runnable() { |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
89 |
public void run() { |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
90 |
Util.clickOnComp(b1, robot); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
91 |
} |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
92 |
}, 5000, false); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
93 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
94 |
if (!gained) { |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
95 |
throw new RuntimeException("Unexpected state: focus is not on <button1>"); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
96 |
} |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
97 |
} |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
98 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
99 |
robot.delay(500); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
100 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
101 |
// |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
102 |
// Click <button2>, check that focus is set on the parent frame. |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
103 |
// |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
104 |
gained = false; |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
105 |
gained = Util.trackFocusGained(frame2, new Runnable() { |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
106 |
public void run() { |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
107 |
Util.clickOnComp(b2, robot); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
108 |
} |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
109 |
}, 5000, false); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
110 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
111 |
if (!gained) { |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
112 |
throw new RuntimeException("Test failed: focus wasn't set to <frame2>"); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
113 |
} |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
114 |
|
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
115 |
System.out.println("Test passed."); |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
116 |
} |
a34977112c8b
8013773: requestFocusInWindow to a disabled component prevents window of getting focused
ant
parents:
diff
changeset
|
117 |
} |