jdk/test/java/awt/Focus/ChoiceFocus/ChoiceFocus.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 5506 202f599c92aa
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:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
     2
 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
    26
  @key headful
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
  @bug 4053856
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @summary Choice components don't honour key focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
  @library ../../regtesthelpers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  @build Util
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  @author Andrei Dmitriev : area=awt.choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  @run main ChoiceFocus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.applet.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import test.java.awt.regtesthelpers.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
Here is the old description for the test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
This bug occurs in jdk <= 1.1.6, 1.2b3. The problem is that key press
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
and release events will not be delivered to a choice component with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
the focus if the mouse is over another component (of any type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
This bug occurs in Motif and was fixed in the native code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
1. Set the focus on choice component 1 by selecting an item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
2. Move the mouse over choice component 2, BUT do not set the focus on it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
3. Type some characters e.g. 'a', 'b' etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
4. Verify by the console output that all the key events are delivered to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
   choice component 1, not 2. If all the key events are delivered to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
   choice 1, the test passes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public class ChoiceFocus {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static Robot robot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    volatile static boolean keyPressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    volatile static boolean keyReleased = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    volatile static boolean keyTyped = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        Frame f = new Frame("Test Frame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        f.setLayout(new GridLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        Choice c1 = new Choice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        c1.add("Choice 1, Item 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        c1.add("Choice 1, Item 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        Choice c2 = new Choice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        c2.add("Choice 2, Item 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        c2.add("Choice 2, Item 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        c1.addKeyListener(new KeyListener(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                public void keyPressed(KeyEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                    System.out.println("Key Pressed Event "+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                    keyPressed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                public void keyReleased(KeyEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                    System.out.println("Key Released Event "+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                    keyReleased = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                public void keyTyped(KeyEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                    System.out.println("Key Typed Event "+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                    keyTyped = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        f.add(c1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        f.add(c2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        f.pack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        f.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        robot = Util.createRobot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        robot.setAutoWaitForIdle(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        robot.setAutoDelay(50);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        //transfer focus to Choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        Util.clickOnComp(c1, robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        //close choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        Util.clickOnComp(c1, robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        //position a mouse over a different component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        Point pt = c2.getLocationOnScreen();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        robot.mouseMove(pt.x + c2.getWidth()/2, pt.y + c2.getHeight()/2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        robot.keyPress(KeyEvent.VK_A);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        robot.keyRelease(KeyEvent.VK_A);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (!keyPressed || !keyReleased || !keyTyped){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            throw new RuntimeException("Failed. Some of event wasn't come "+keyPressed + " : "+keyReleased+" : "+keyTyped);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            System.out.println("Test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
}////~