jdk/test/java/awt/List/ActionEventTest/ActionEventTest.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 37572 7b0c62fdb5d8
child 41786 fe9fb004e014
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37572
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 37572
diff changeset
     2
 * Copyright (c) 2016, 2016, Oracle and/or its affiliates. All rights reserved.
37572
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
     4
 *
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
     8
 *
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    13
 * accompanied this code).
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    14
 *
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    18
 *
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    21
 * questions.
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    22
 */
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    23
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    24
/*
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    25
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 37572
diff changeset
    26
 * @key headful
37572
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    27
 * @bug 6191390
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    28
 * @summary Verify that ActionEvent is received with correct modifiers set.
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    29
 * @run main ActionEventTest
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    30
 */
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    31
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    32
import java.awt.AWTException;
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    33
import java.awt.FlowLayout;
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    34
import java.awt.Frame;
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    35
import java.awt.List;
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    36
import java.awt.Robot;
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    37
import java.awt.event.ActionEvent;
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    38
import java.awt.event.ActionListener;
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    39
import java.awt.event.KeyEvent;
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    40
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    41
public class ActionEventTest extends Frame {
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    42
    List list;
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    43
    Robot robot;
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    44
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    45
    public ActionEventTest() {
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    46
        try {
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    47
            robot = new Robot();
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    48
        } catch(AWTException e) {
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    49
            throw new RuntimeException(e.getMessage());
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    50
        }
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    51
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    52
        list = new List(1, false);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    53
        list.add("0");
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    54
        add(list);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    55
        setSize(400,400);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    56
        setLayout(new FlowLayout());
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    57
        pack();
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    58
        setVisible(true);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    59
        robot.waitForIdle();
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    60
    }
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    61
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    62
    void performTest() {
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    63
        list.addActionListener(new ActionListener() {
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    64
            @Override
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    65
            public void actionPerformed(ActionEvent ae) {
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    66
                int md = ae.getModifiers();
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    67
                int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    68
                        | ActionEvent.SHIFT_MASK;
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    69
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    70
                if ((md & expectedMask) != expectedMask) {
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    71
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    72
                    robot.keyRelease(KeyEvent.VK_ALT);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    73
                    robot.keyRelease(KeyEvent.VK_SHIFT);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    74
                    robot.keyRelease(KeyEvent.VK_CONTROL);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    75
                    dispose();
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    76
                    throw new RuntimeException("Action Event modifiers are not"
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    77
                        + " set correctly.");
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    78
                }
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    79
            }
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    80
        });
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    81
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    82
        list.select(0);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    83
        robot.keyPress(KeyEvent.VK_ALT);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    84
        robot.keyPress(KeyEvent.VK_SHIFT);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    85
        robot.keyPress(KeyEvent.VK_CONTROL);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    86
        // Press Enter on list item, to generate action event.
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    87
        robot.keyPress(KeyEvent.VK_ENTER);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    88
        robot.keyRelease(KeyEvent.VK_ENTER);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    89
        robot.waitForIdle();
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    90
        robot.keyRelease(KeyEvent.VK_ALT);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    91
        robot.keyRelease(KeyEvent.VK_SHIFT);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    92
        robot.keyRelease(KeyEvent.VK_CONTROL);
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    93
        robot.waitForIdle();
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    94
    }
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    95
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    96
    public static void main(String args[]) {
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    97
       ActionEventTest test = new ActionEventTest();
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    98
       test.performTest();
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
    99
       test.dispose();
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
   100
    }
7b0c62fdb5d8 6191390: Action Event triggered by list does not reflect the modifiers properly on win32
arapte
parents:
diff changeset
   101
}