DumpOnKey.java revision 14851:980da45565c8
1/* 2 * Copyright (c) 2015, 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 24import java.awt.AWTException; 25import java.awt.Frame; 26import java.awt.Robot; 27import java.awt.Window; 28import java.awt.event.InputEvent; 29import java.awt.event.KeyEvent; 30import java.io.PrintStream; 31 32/** 33 * @test 34 * @key headful 35 * @bug 4379403 36 * @run main/othervm DumpOnKey false 37 * @run main/othervm DumpOnKey -Dsun.awt.nativedebug=true true 38 * @run main/othervm DumpOnKey -Dsun.awt.nativedebug=true -Dawtdebug.on=true true 39 * @run main/othervm DumpOnKey -Dsun.awt.nativedebug=false -Dawtdebug.on=true false 40 * @run main/othervm DumpOnKey -Dsun.awt.nativedebug=true -Dawtdebug.on=false false 41 * @run main/othervm DumpOnKey -Dsun.awt.nativedebug=false -Dawtdebug.on=false false 42 * @run main/othervm/java.security.policy=dump.policy/secure=java.lang.SecurityManager DumpOnKey -Dsun.awt.nativedebug=true true 43 * @run main/othervm/java.security.policy=dump.policy/secure=java.lang.SecurityManager DumpOnKey -Dsun.awt.nativedebug=true -Dawtdebug.on=false false 44 */ 45public final class DumpOnKey { 46 47 private static volatile boolean dumped; 48 49 public static void main(final String[] args) throws AWTException { 50 final boolean dump = Boolean.parseBoolean(args[0]); 51 final Window w = new Frame() { 52 @Override 53 public void list(final PrintStream out, final int indent) { 54 super.list(out, indent); 55 dumped = true; 56 } 57 }; 58 w.setSize(200, 200); 59 w.setLocationRelativeTo(null); 60 w.setVisible(true); 61 62 final Robot robot = new Robot(); 63 robot.setAutoDelay(50); 64 robot.setAutoWaitForIdle(true); 65 robot.mouseMove(w.getX() + w.getWidth() / 2, 66 w.getY() + w.getHeight() / 2); 67 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); 68 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); 69 70 robot.keyPress(KeyEvent.VK_CONTROL); 71 robot.keyPress(KeyEvent.VK_SHIFT); 72 robot.keyPress(KeyEvent.VK_F1); 73 robot.keyRelease(KeyEvent.VK_F1); 74 robot.keyRelease(KeyEvent.VK_SHIFT); 75 robot.keyRelease(KeyEvent.VK_CONTROL); 76 77 w.dispose(); 78 if (dumped != dump) { 79 throw new RuntimeException("Exp:" + dump + ", actual:" + dumped); 80 } 81 } 82} 83