blob: bf00acf8408ff0f764894a2f86b3f5be91292fb0 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005-2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/*
25 * @test
26 * @bug 6541987
27 * @summary Tests closing by ESC
28 * @author Sergey Malenkov
29 */
30
31import java.awt.AWTException;
32import java.awt.Color;
33import java.awt.Robot;
34import java.awt.Toolkit;
35import java.awt.Window;
36import java.awt.event.KeyEvent;
37
38import javax.swing.JColorChooser;
39import javax.swing.JFrame;
40import javax.swing.SwingUtilities;
41
42import sun.awt.SunToolkit;
43
44public class Test6541987 implements Runnable {
45 private static final SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
46 private static Robot robot;
47
48 public static void main(String[] args) throws AWTException {
49 robot = new Robot();
50 // test escape after selection
51 start();
52 click(KeyEvent.VK_ESCAPE);
53 toolkit.realSync();
54 // test double escape after editing
55 start();
56 click(KeyEvent.VK_1);
57 click(KeyEvent.VK_0);
58 click(KeyEvent.VK_ESCAPE);
59 click(KeyEvent.VK_ESCAPE);
60 toolkit.realSync();
61 // all windows should be closed
62 for (Window window : Window.getWindows()) {
63 if (window.isVisible()) {
64 throw new Error("found visible window: " + window.getName());
65 }
66 }
67 }
68
69 private static void start() {
70 SwingUtilities.invokeLater(new Test6541987());
71 click(KeyEvent.VK_ALT, KeyEvent.VK_H);
72 click(KeyEvent.VK_TAB);
73 click(KeyEvent.VK_TAB);
74 click(KeyEvent.VK_TAB);
75 click(KeyEvent.VK_TAB);
76 }
77
78 private static void click(int...keys) {
79 toolkit.realSync();
80 for (int key : keys) {
81 robot.keyPress(key);
82 }
83 for (int key : keys) {
84 robot.keyRelease(key);
85 }
86 }
87
88 public void run() {
89 String title = getClass().getName();
90 JFrame frame = new JFrame(title);
91 frame.setVisible(true);
92
93 Color color = JColorChooser.showDialog(frame, title, Color.BLACK);
94 if (color != null) {
95 throw new Error("unexpected color: " + color);
96 }
97 frame.setVisible(false);
98 frame.dispose();
99 }
100}