test/jdk/java/awt/Robot/AcceptExtraMouseButtons/AcceptExtraMouseButtons.java
author serb
Wed, 21 Feb 2018 12:49:00 -0800
changeset 49096 eaef201ec301
parent 47216 71c04702a3d5
permissions -rw-r--r--
8198333: ProblemList should be updated for headless mode Reviewed-by: psadhukhan, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21596
diff changeset
     2
 * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
21596
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     4
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     7
 * published by the Free Software Foundation.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     8
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    13
 * accompanied this code).
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    14
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    18
 *
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    21
 * questions.
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    22
 */
0e3a39f29dbc 8027696: Incorrect copyright header in the tests
serb
parents: 1962
diff changeset
    23
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    24
/*
49096
eaef201ec301 8198333: ProblemList should be updated for headless mode
serb
parents: 47216
diff changeset
    25
  @test
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 31442
diff changeset
    26
  @key headful
1962
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    27
  @bug 6315717
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    28
  @summary verifies that Robot is accepting extra mouse buttons
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    29
  @author Andrei Dmitriev : area=awt.mouse
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    30
  @library ../../regtesthelpers
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    31
  @build Util
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    32
  @run main AcceptExtraMouseButtons
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    33
 */
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    34
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    35
//if we do robot.mousePress(InputEvent.BUTTON1_DOWN_MASK) the test must
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    36
// 1) accept it (i.e. don't throw an IllegalArgumentException
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    37
// 2) actually post a MouseEvent
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    38
// Also, Robot should still accept InputEvent.BUTTONx_MASKs
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    39
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    40
import java.awt.*;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    41
import java.awt.event.*;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    42
import test.java.awt.regtesthelpers.Util;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    43
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    44
public class AcceptExtraMouseButtons extends Frame {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    45
    static String tk = Toolkit.getDefaultToolkit().getClass().getName();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    46
    static Robot robot;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    47
    static int [] standardButtonMasks = {InputEvent.BUTTON1_MASK,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    48
                                         InputEvent.BUTTON2_MASK,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    49
                                         InputEvent.BUTTON3_MASK};
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    50
    static int [] buttonsPressed;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    51
    static int [] buttonsReleased;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    52
    static int [] buttonsClicked;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    53
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    54
    static int buttonsNum = MouseInfo.getNumberOfButtons();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    55
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    56
    public static void main(String []s){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    57
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    58
        //MouseInfo.getNumberOfButtons() reports two more buttons on XToolkit
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    59
        //as they reserved for wheel (both directions).
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    60
        if (tk.equals("sun.awt.X11.XToolkit") || tk.equals("sun.awt.motif.MToolkit")) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    61
            buttonsNum = buttonsNum - 2;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    62
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    63
        System.out.println("Number Of Buttons = "+ buttonsNum);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    64
        if (buttonsNum < 3) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    65
            System.out.println("Linux and Windows systems should emulate three buttons if even there are only 1 or 2 are phsically available. Setting number of buttons to 3.");
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    66
            buttonsNum = 3;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    67
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    68
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    69
        buttonsPressed = new int [buttonsNum];
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    70
        buttonsReleased = new int [buttonsNum];
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    71
        buttonsClicked = new int [buttonsNum];
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    72
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    73
        AcceptExtraMouseButtons frame = new AcceptExtraMouseButtons();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    74
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    75
        MouseAdapter ma1 = new MouseAdapter() {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    76
                public void mousePressed(MouseEvent e) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    77
                    buttonsPressed[e.getButton() - 1] += 1;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    78
                    System.out.println("PRESSED "+e);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    79
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    80
                public void mouseReleased(MouseEvent e) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    81
                    buttonsReleased[e.getButton() - 1] += 1;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    82
                    System.out.println("RELEASED "+e);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    83
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    84
                public void mouseClicked(MouseEvent e) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    85
                    buttonsClicked[e.getButton() - 1] += 1;
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    86
                    System.out.println("CLICKED "+e);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    87
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    88
            };
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    89
        frame.addMouseListener(ma1);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    90
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    91
        frame.setSize(300, 300);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    92
        frame.setVisible(true);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    93
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    94
        Util.waitForIdle(robot);  //a time to show a Frame
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    95
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    96
        try {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    97
            robot = new Robot();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    98
            robot.delay(1000);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
    99
            robot.mouseMove(frame.getLocationOnScreen().x + frame.getWidth()/2,
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   100
                            frame.getLocationOnScreen().y + frame.getHeight()/2);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   101
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   102
            //TestCase 1: verify that all BUTTONx_DOWN_MASKs are accepted by the Robot.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   103
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   104
            for (int i = 0; i < buttonsNum; i++){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   105
                int buttonMask = InputEvent.getMaskForButton(i+1);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   106
                System.out.println("button to press = " +(i+1) + " : value passed to robot = " +buttonMask);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   107
                robot.mousePress(buttonMask);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   108
                robot.delay(30);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   109
                robot.mouseRelease(buttonMask);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   110
                Util.waitForIdle(robot);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   111
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   112
            for (int i = 0; i < buttonsNum; i++){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   113
                if (buttonsPressed[i] != 1 || buttonsReleased[i] != 1 || buttonsClicked[i] !=1 ) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   114
                    throw new RuntimeException("TESTCASE 1 FAILED : button " + (i+1) + " wasn't single pressed|released|clicked : "+ buttonsPressed[i] +" : "+ buttonsReleased[i] +" : "+ buttonsClicked[i]);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   115
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   116
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   117
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   118
            java.util.Arrays.fill(buttonsPressed, 0);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   119
            java.util.Arrays.fill(buttonsReleased, 0);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   120
            java.util.Arrays.fill(buttonsClicked, 0);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   121
            //TestCase 2: verify that all BUTTONx_MASKs are accepted by the Robot.
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   122
            for (int i = 0; i < standardButtonMasks.length; i++){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   123
                int buttonMask = standardButtonMasks[i];
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   124
                System.out.println("button to press = " +(i+1) + " : value passed to robot = " +buttonMask);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   125
                robot.mousePress(buttonMask);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   126
                robot.delay(30);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   127
                robot.mouseRelease(buttonMask);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   128
                Util.waitForIdle(robot);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   129
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   130
            for (int i = 0; i < standardButtonMasks.length; i++){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   131
                if (buttonsPressed[i] != 1 || buttonsReleased[i] != 1 || buttonsClicked[i] !=1 ) {
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   132
                    throw new RuntimeException("TESTCASE 2 FAILED : button " + (i+1) + " wasn't single pressed|released|clicked : "+ buttonsPressed[i] +" : "+ buttonsReleased[i] +" : "+ buttonsClicked[i]);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   133
                }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   134
            }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   135
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   136
        } catch (Exception e){
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   137
            e.printStackTrace();
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   138
            throw new RuntimeException(e);
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   139
        }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   140
    }
6c293d33645b 6315717: Support for mouse with multiple scroll wheels and 4 or more buttons
dav
parents:
diff changeset
   141
}