jdk/test/java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java
author ihse
Tue, 09 May 2017 12:57:30 +0200
changeset 45028 b0ea3c0bfb81
parent 40128 e635645d2a8a
permissions -rw-r--r--
8179889: Fix typographic errors in copyright headers Reviewed-by: erikj, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45028
b0ea3c0bfb81 8179889: Fix typographic errors in copyright headers
ihse
parents: 40128
diff changeset
     2
 * Copyright (c) 2007, 2015, 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
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 32680
diff changeset
    26
  @key headful
32680
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    27
  @bug 6566434 8039467
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
  @library ../../regtesthelpers
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
  @build Util Sysout AbstractTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
  @summary Choice in unfocusable window responds to keyboard
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
  @author Andrei Dmitriev: area=awt-choice
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  @run main UnfocusableToplevel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * UnfocusableToplevel.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * summary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import test.java.awt.regtesthelpers.AbstractTest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import test.java.awt.regtesthelpers.Sysout;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import test.java.awt.regtesthelpers.Util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
public class UnfocusableToplevel {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    final static Robot robot = Util.createRobot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    final static int REASONABLE_PATH_TIME = 5000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static void main(String []s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        Frame f = new Frame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        Window w = new Window(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        final Choice ch = new Choice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        ch.add("item 1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        ch.add("item 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        ch.add("item 3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        ch.add("item 4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        ch.add("item 5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        w.add(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        w.setLayout(new FlowLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        w.setSize(200, 200);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
32680
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    67
        // Note that Window w is non focusable. Key press events will not be
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    68
        // consumed by w, but by any previously focused window & this can
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    69
        // disturb the environment. So creating tempFrameToHoldFocus frame,
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    70
        // to consume key press events.
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    71
        Frame tempFrameToHoldFocus = new Frame();
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    72
        tempFrameToHoldFocus.setVisible(true);
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    73
        Util.waitForIdle(robot);
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    74
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    75
        tempFrameToHoldFocus.requestFocus();
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    76
        Util.clickOnComp(tempFrameToHoldFocus, robot);
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    77
        Util.waitForIdle(robot);
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
    78
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        ch.addKeyListener(new KeyAdapter(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                public void keyTyped(KeyEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                    traceEvent("keytyped", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                public void keyPressed(KeyEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                    traceEvent("keypress", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                public void keyReleased(KeyEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    traceEvent("keyrelease", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        ch.addItemListener(new ItemListener(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                public void itemStateChanged(ItemEvent ie){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    traceEvent("stateChanged", ie);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        w.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        Util.waitForIdle(robot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        Util.clickOnComp(ch, 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
        // will not test if the dropdown become opened as there is no reliable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        // technique to accomplish that rather then checking color of dropdown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        // Will suppose that the dropdown appears
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        testKeys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        Util.waitForIdle(robot);
32680
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
   110
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
   111
        tempFrameToHoldFocus.dispose();
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
   112
        w.dispose();
93639d43d72f 8039467: [TEST_BUG] Test java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java lefts keystrokes in a keyboard buffer on Windows
alexsch
parents: 5506
diff changeset
   113
        f.dispose();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private static void testKeys(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        typeKey(KeyEvent.VK_UP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        typeKey(KeyEvent.VK_DOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        typeKey(KeyEvent.VK_K);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        typeKey(KeyEvent.VK_PAGE_UP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        typeKey(KeyEvent.VK_PAGE_DOWN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private static void typeKey(int keyChar){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            robot.keyPress(keyChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            robot.delay(5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            robot.keyRelease(keyChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        robot.delay(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private static void traceEvent(String message, AWTEvent e){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        AbstractTest.fail(message + " " + e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
}