Path: blob/master/test/jdk/java/awt/Debug/DumpOnKey/DumpOnKey.java
41154 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.AWTException;24import java.awt.Frame;25import java.awt.Robot;26import java.awt.Window;27import java.awt.event.InputEvent;28import java.awt.event.KeyEvent;29import java.io.PrintStream;3031/**32* @test33* @key headful34* @bug 437940335* @run main/othervm DumpOnKey false36* @run main/othervm DumpOnKey -Dsun.awt.nativedebug=true true37* @run main/othervm DumpOnKey -Dsun.awt.nativedebug=true -Dawtdebug.on=true true38* @run main/othervm DumpOnKey -Dsun.awt.nativedebug=false -Dawtdebug.on=true false39* @run main/othervm DumpOnKey -Dsun.awt.nativedebug=true -Dawtdebug.on=false false40* @run main/othervm DumpOnKey -Dsun.awt.nativedebug=false -Dawtdebug.on=false false41* @run main/othervm/java.security.policy=dump.policy/secure=java.lang.SecurityManager DumpOnKey -Dsun.awt.nativedebug=true true42* @run main/othervm/java.security.policy=dump.policy/secure=java.lang.SecurityManager DumpOnKey -Dsun.awt.nativedebug=true -Dawtdebug.on=false false43*/44public final class DumpOnKey {4546private static volatile boolean dumped;4748public static void main(final String[] args) throws AWTException {49final boolean dump = Boolean.parseBoolean(args[0]);50final Window w = new Frame() {51@Override52public void list(final PrintStream out, final int indent) {53super.list(out, indent);54dumped = true;55}56};57w.setSize(200, 200);58w.setLocationRelativeTo(null);59w.setVisible(true);6061final Robot robot = new Robot();62robot.setAutoDelay(50);63robot.setAutoWaitForIdle(true);64robot.mouseMove(w.getX() + w.getWidth() / 2,65w.getY() + w.getHeight() / 2);66robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);67robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);6869robot.keyPress(KeyEvent.VK_CONTROL);70robot.keyPress(KeyEvent.VK_SHIFT);71robot.keyPress(KeyEvent.VK_F1);72robot.keyRelease(KeyEvent.VK_F1);73robot.keyRelease(KeyEvent.VK_SHIFT);74robot.keyRelease(KeyEvent.VK_CONTROL);7576w.dispose();77if (dumped != dump) {78throw new RuntimeException("Exp:" + dump + ", actual:" + dumped);79}80}81}828384