Path: blob/master/test/jdk/java/awt/Choice/GrabLockTest/GrabLockTest.java
41152 views
/*1* Copyright (c) 2003, 2016, 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*/22/*23@test24@key headful25@bug 480063826@summary Tests that Choice does not lock the Desktop27@run main GrabLockTest28*/29import java.awt.*;30import java.awt.event.*;3132public class GrabLockTest33{34public static void main (String args[])35{36Frame frame = new TestFrame();37}38}3940class TestFrame extends Frame implements MouseListener {41public TestFrame() {42Choice choice = new Choice();43choice.addItem("Fist Item");44choice.addItem("Second Item");45add(choice,BorderLayout.NORTH);46Panel panel = new Panel();47panel.addMouseListener(this);48panel.setBackground(Color.RED);49add(panel);50setSize(200, 200);51setVisible(true);52toFront();5354try {55Robot robot = new Robot();56robot.setAutoWaitForIdle(true);57robot.setAutoDelay(50);5859robot.waitForIdle();6061Point pt = choice.getLocationOnScreen();62robot.mouseMove(pt.x + choice.getWidth() - choice.getHeight()/2,63pt.y + choice.getHeight()/2);64robot.mousePress(InputEvent.BUTTON1_MASK);65robot.waitForIdle();66robot.mouseMove(pt.x + choice.getWidth()/2,67pt.y + choice.getHeight()*2);68robot.waitForIdle();69robot.mousePress(InputEvent.BUTTON2_MASK);70robot.waitForIdle();71Point pt1 = panel.getLocationOnScreen();72robot.mouseMove(pt1.x + panel.getWidth()/2,73pt1.y + panel.getHeight()/2);74robot.waitForIdle();75robot.mouseRelease(InputEvent.BUTTON1_MASK);76robot.mouseRelease(InputEvent.BUTTON2_MASK);7778robot.waitForIdle();7980robot.mousePress(InputEvent.BUTTON1_MASK);81robot.delay(30);82robot.mouseRelease(InputEvent.BUTTON1_MASK);83robot.waitForIdle();84if (nPressed == 0) {85robot.keyPress(KeyEvent.VK_ESCAPE);86robot.keyRelease(KeyEvent.VK_ESCAPE);87throw new RuntimeException("GrabLockTest failed." + nPressed);88}89} catch (Exception e) {90throw new RuntimeException("The test was not completed.\n\n" + e);91}9293}9495public int nPressed = 0;9697public void mouseClicked(MouseEvent e) {98}99100public void mousePressed(MouseEvent e) {101nPressed++;102System.out.println("Pressed!");103}104105public void mouseReleased(MouseEvent e) {106}107108public void mouseEntered(MouseEvent e) {}109public void mouseExited(MouseEvent e) {}110}// class TestFrame111112113