1/* 2 * Copyright (c) 2005, 2007, 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 * @key headful 27 * @bug 6541987 28 * @summary Tests closing by ESC 29 * @author Sergey Malenkov 30 */ 31 32import java.awt.AWTException; 33import java.awt.Color; 34import java.awt.Robot; 35import java.awt.Toolkit; 36import java.awt.Window; 37import java.awt.event.KeyEvent; 38 39import javax.swing.JColorChooser; 40import javax.swing.JFrame; 41import javax.swing.SwingUtilities; 42 43public class Test6541987 implements Runnable { 44 private static Robot robot; 45 46 public static void main(String[] args) throws AWTException { 47 robot = new Robot(); 48 // test escape after selection 49 start(); 50 click(KeyEvent.VK_ESCAPE); 51 robot.waitForIdle(); 52 // test double escape after editing 53 start(); 54 click(KeyEvent.VK_1); 55 click(KeyEvent.VK_0); 56 click(KeyEvent.VK_ESCAPE); 57 click(KeyEvent.VK_ESCAPE); 58 robot.waitForIdle(); 59 // all windows should be closed 60 for (Window window : Window.getWindows()) { 61 if (window.isVisible()) { 62 throw new Error("found visible window: " + window.getName()); 63 } 64 } 65 } 66 67 private static void start() { 68 SwingUtilities.invokeLater(new Test6541987()); 69 click(KeyEvent.VK_ALT, KeyEvent.VK_H); 70 click(KeyEvent.VK_TAB); 71 click(KeyEvent.VK_TAB); 72 click(KeyEvent.VK_TAB); 73 click(KeyEvent.VK_TAB); 74 } 75 76 private static void click(int...keys) { 77 robot.waitForIdle(); 78 for (int key : keys) { 79 robot.keyPress(key); 80 } 81 for (int key : keys) { 82 robot.keyRelease(key); 83 } 84 } 85 86 public void run() { 87 String title = getClass().getName(); 88 JFrame frame = new JFrame(title); 89 frame.setVisible(true); 90 91 Color color = JColorChooser.showDialog(frame, title, Color.BLACK); 92 if (color != null) { 93 throw new Error("unexpected color: " + color); 94 } 95 frame.setVisible(false); 96 frame.dispose(); 97 } 98} 99