Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Robot/RobotExtraButton/RobotExtraButton.java
38828 views
/*1* Copyright (c) 2008, 2013, 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*/2223/*24@test %I% %E%25@bug 631571726@summary verifies that robot could accept extra buttons27@author Andrei Dmitriev : area=awt.mouse28@library ../../regtesthelpers29@build Util30@run main RobotExtraButton31*/3233import java.awt.*;34import java.awt.event.*;35import test.java.awt.regtesthelpers.Util;3637public class RobotExtraButton extends Frame {38static Robot robot;39public static void main(String []s){40RobotExtraButton frame = new RobotExtraButton();41frame.setSize(300, 300);42frame.setVisible(true);43frame.addMouseListener(new MouseAdapter() {44public void mousePressed(MouseEvent e) {45System.out.println("PRESSED "+e);46}47public void mouseReleased(MouseEvent e) {48System.out.println("RELEASED "+e);49}50public void mouseClicked(MouseEvent e) {51System.out.println("CLICKED "+e);52}53});54Util.waitForIdle(robot);55int [] buttonMask = new int[MouseInfo.getNumberOfButtons()]; // = InputEvent.getButtonDownMasks();56for (int i = 0; i < MouseInfo.getNumberOfButtons(); i++){57buttonMask[i] = InputEvent.getMaskForButton(i+1);58System.out.println("TEST: "+buttonMask[i]);59}6061try {62robot = new Robot();63robot.mouseMove(frame.getLocationOnScreen().x + frame.getWidth()/2, frame.getLocationOnScreen().y + frame.getHeight()/2);64/*65if (MouseInfo.getNumberOfButtons() <= 3) {66System.out.println("Number Of Buttons = "+ MouseInfo.getNumberOfButtons() +". Finish!");67return;68}*/6970System.out.println("TEST: press 1");71robot.mousePress(InputEvent.BUTTON1_MASK);72robot.delay(50);73robot.mouseRelease(InputEvent.BUTTON1_MASK);74Util.waitForIdle(robot);7576System.out.println("TEST: press 2");7778robot.mousePress(InputEvent.BUTTON2_MASK);79robot.delay(50);80robot.mouseRelease(InputEvent.BUTTON2_MASK);81Util.waitForIdle(robot);82System.out.println("TEST: press 3");8384robot.mousePress(InputEvent.BUTTON3_MASK);85robot.delay(50);86robot.mouseRelease(InputEvent.BUTTON3_MASK);87Util.waitForIdle(robot);88System.out.println("--------------------------------------------------");89for (int i = 0; i < buttonMask.length; i++){90System.out.println("button would = " +i + " : value = " +buttonMask[i]);91robot.mousePress(buttonMask[i]);92robot.delay(50);93robot.mouseRelease(buttonMask[i]);94Util.waitForIdle(robot);95}96} catch (Exception e){97e.printStackTrace();98throw new RuntimeException("Test failed.", e);99}100}101}102103104