4890N/A/*
4890N/A * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
4890N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4890N/A *
4890N/A * This code is free software; you can redistribute it and/or modify it
4890N/A * under the terms of the GNU General Public License version 2 only, as
4890N/A * published by the Free Software Foundation.
4890N/A *
4890N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4890N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4890N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4890N/A * version 2 for more details (a copy is included in the LICENSE file that
4890N/A * accompanied this code).
4890N/A *
4890N/A * You should have received a copy of the GNU General Public License version
4890N/A * 2 along with this work; if not, write to the Free Software Foundation,
4890N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4890N/A *
4890N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4890N/A * or visit www.oracle.com if you need additional information or have any
4890N/A * questions.
4890N/A */
4890N/A
4890N/A/*
4890N/A @test
4890N/A @bug 7154072
4890N/A @summary Tests that key events with modifiers are not swallowed.
4890N/A @author anton.tarasov: area=awt.focus
4890N/A @library ../../../regtesthelpers
4890N/A @build Util
4890N/A @run main SwallowKeyEvents
4890N/A*/
4890N/A
4890N/Aimport java.awt.AWTException;
4890N/Aimport java.awt.Frame;
4890N/Aimport java.awt.Robot;
4890N/Aimport java.awt.TextField;
4890N/Aimport java.awt.event.KeyAdapter;
4890N/Aimport java.awt.event.KeyEvent;
4890N/Aimport test.java.awt.regtesthelpers.Util;
4890N/A
4890N/Apublic class SwallowKeyEvents {
4890N/A static final int PRESS_COUNT = 10;
4890N/A
4890N/A static int keyPressedCount = 0;
4890N/A
4890N/A static Frame f = new Frame("Frame");
4890N/A static TextField t = new TextField("text");
4890N/A static Robot r;
4890N/A
4890N/A public static void main(String[] args) {
4890N/A f.add(t);
4890N/A f.pack();
4890N/A f.setVisible(true);
4890N/A
4890N/A t.requestFocus();
4890N/A
4890N/A try {
4890N/A r = new Robot();
4890N/A } catch (AWTException ex) {
4890N/A throw new RuntimeException(ex);
4890N/A }
4890N/A
4890N/A Util.waitForIdle(r);
4890N/A
4890N/A t.addKeyListener(new KeyAdapter() {
4890N/A public void keyPressed(KeyEvent ke) {
4890N/A System.out.println(ke);
4890N/A if (ke.getKeyCode() == KeyEvent.VK_M) {
4890N/A keyPressedCount++;
4890N/A }
4890N/A }
4890N/A });
4890N/A
4890N/A test();
4890N/A
4890N/A System.out.println("key_pressed count: " + keyPressedCount);
4890N/A
4890N/A if (keyPressedCount != PRESS_COUNT) {
4890N/A throw new RuntimeException("Test failed!");
4890N/A } else {
4890N/A System.out.println("Test passed.");
4890N/A }
4890N/A }
4890N/A
4890N/A public static void test() {
4890N/A r.keyPress(KeyEvent.VK_SHIFT);
4890N/A r.keyPress(KeyEvent.VK_META);
4890N/A
4890N/A for (int i=0; i<PRESS_COUNT; i++) {
4890N/A r.delay(100);
4890N/A r.keyPress(KeyEvent.VK_M);
4890N/A r.delay(100);
4890N/A r.keyRelease(KeyEvent.VK_M);
4890N/A }
4890N/A
4890N/A r.keyRelease(KeyEvent.VK_META);
4890N/A r.keyRelease(KeyEvent.VK_SHIFT);
4890N/A }
4890N/A}