jdk/test/java/awt/Choice/ItemStateChangeTest/ItemStateChangeTest.java
author bagiras
Wed, 03 Oct 2012 21:01:47 +0400
changeset 13997 8889b37053e6
child 29514 973914c573fc
permissions -rw-r--r--
7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call Reviewed-by: art, denis
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13997
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
     1
/*
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
     4
 *
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
     8
 *
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    13
 * accompanied this code).
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    14
 *
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    18
 *
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    21
 * questions.
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    22
 */
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    23
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    24
/*
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    25
  @test
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    26
  @bug 7171412
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    27
  @summary awt Choice doesn't fire ItemStateChange when selecting item after select() call
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    28
  @author Oleg Pekhovskiy: area=awt-choice
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    29
  @library ../../regtesthelpers
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    30
  @build Util
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    31
  @run main ItemStateChangeTest
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    32
*/
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    33
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    34
import test.java.awt.regtesthelpers.Util;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    35
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    36
import java.awt.*;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    37
import java.awt.event.*;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    38
import sun.awt.OSInfo;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    39
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    40
public class ItemStateChangeTest extends Frame {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    41
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    42
    int events = 0;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    43
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    44
    public static void main(String args[]) {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    45
        new ItemStateChangeTest();
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    46
    }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    47
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    48
    public ItemStateChangeTest() {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    49
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    50
        if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    51
            return;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    52
        }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    53
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    54
        try {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    55
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    56
            final Robot robot = new Robot();
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    57
            robot.setAutoDelay(20);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    58
            Util.waitForIdle(robot);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    59
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    60
            addWindowListener(new WindowAdapter() {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    61
                @Override
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    62
                public void windowClosing(WindowEvent e) {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    63
                    System.exit(0);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    64
                }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    65
            });
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    66
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    67
            final Choice choice = new Choice();
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    68
            choice.add("A");
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    69
            choice.add("B");
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    70
            choice.addItemListener(new ItemListener() {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    71
                @Override
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    72
                public void itemStateChanged(ItemEvent e) {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    73
                    ++events;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    74
                }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    75
            });
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    76
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    77
            add(choice);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    78
            setSize(200, 150);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    79
            setVisible(true);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    80
            toFront();
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    81
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    82
            // choose B
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    83
            int y = chooseB(choice, robot, 16);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    84
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    85
            // reset to A
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    86
            choice.select(0);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    87
            robot.delay(20);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    88
            Util.waitForIdle(robot);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    89
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    90
            // choose B again
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    91
            chooseB(choice, robot, y);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    92
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    93
            if (events == 2) {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    94
                System.out.println("Test passed!");
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    95
            }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    96
            else {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    97
                throw new RuntimeException("Test failed!");
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    98
            }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
    99
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   100
        }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   101
        catch (AWTException e) {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   102
            throw new RuntimeException("Test failed!");
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   103
        }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   104
    }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   105
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   106
    final int chooseB(Choice choice, Robot robot, int y) {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   107
        while (true) {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   108
            // show drop-down list
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   109
            Util.clickOnComp(choice, robot);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   110
            Util.waitForIdle(robot);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   111
            Point pt = choice.getLocationOnScreen();
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   112
            Dimension size = choice.getSize();
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   113
            // try to click B item
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   114
            robot.mouseMove(pt.x + size.width / 2, pt.y + size.height + y);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   115
            Util.waitForIdle(robot);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   116
            robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   117
            Util.waitForIdle(robot);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   118
            robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   119
            Util.waitForIdle(robot);
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   120
            if (choice.getSelectedIndex() == 1) {
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   121
                break;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   122
            }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   123
            // if it's not B, position cursor lower by 2 pixels and try again
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   124
            y += 2;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   125
        }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   126
        return y;
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   127
    }
8889b37053e6 7171412: awt Choice doesn't fire ItemStateChange when selecting item after select() call
bagiras
parents:
diff changeset
   128
}