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