jdk/test/java/awt/Focus/WrongKeyTypedConsumedTest/WrongKeyTypedConsumedTest.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:
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
     2
 * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
     4
 *
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
     8
 *
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    13
 * accompanied this code).
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    14
 *
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 425
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 425
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 425
diff changeset
    21
 * questions.
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    22
 */
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    23
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    24
/*
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
    26
  @key headful
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    27
  @bug      4782886
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    28
  @summary  FocusManager consumes wrong KEY_TYPED events
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    29
  @author   Oleg.Sukhodolsky: area=awt.focus
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    30
  @library  ../../regtesthelpers
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    31
  @build    Util
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    32
  @run      main WrongKeyTypedConsumedTest
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    33
*/
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    34
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    35
import java.applet.Applet;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    36
import java.awt.AWTException;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    37
import java.awt.AWTKeyStroke;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    38
import java.awt.BorderLayout;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    39
import java.awt.Dialog;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    40
import java.awt.Dimension;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    41
import java.awt.FlowLayout;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    42
import java.awt.Frame;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    43
import java.awt.KeyboardFocusManager;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    44
import java.awt.Point;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    45
import java.awt.Robot;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    46
import java.awt.TextArea;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    47
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    48
import java.awt.event.KeyEvent;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    49
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    50
import java.util.HashSet;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    51
import java.util.Set;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    52
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    53
import javax.swing.JCheckBox;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    54
import javax.swing.JFrame;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    55
import javax.swing.JTextArea;
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    56
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    57
import test.java.awt.regtesthelpers.Util;
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    58
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    59
public class WrongKeyTypedConsumedTest extends Applet
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    60
{
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    61
    Robot robot = Util.createRobot();
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    62
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    63
    public static void main(String[] args) {
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    64
        WrongKeyTypedConsumedTest test = new WrongKeyTypedConsumedTest();
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    65
        test.start();
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    66
    }
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    67
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    68
    public void start ()
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    69
    {
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    70
        setSize (200,200);
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    71
        setVisible(true);
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    72
        validate();
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    73
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    74
        JFrame frame = new JFrame("The Frame");
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    75
        Set ftk = new HashSet();
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    76
        ftk.add(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_DOWN, 0));
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    77
        frame.getContentPane().
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    78
            setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    79
                                  ftk);
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    80
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    81
        JCheckBox checkbox = new JCheckBox("test");
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    82
        frame.getContentPane().add(checkbox, BorderLayout.NORTH);
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    83
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    84
        JTextArea textarea = new JTextArea(40, 10);
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    85
        frame.getContentPane().add(textarea);
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    86
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    87
        frame.pack();
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    88
        frame.setVisible(true);
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    89
        Util.waitForIdle(robot);
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    90
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    91
        if (!frame.isActive()) {
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    92
            throw new RuntimeException("Test Fialed: frame isn't active");
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    93
        }
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    94
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    95
        // verify if checkbox has focus
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    96
        if (!checkbox.isFocusOwner()) {
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    97
            checkbox.requestFocusInWindow();
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
    98
            Util.waitForIdle(robot);
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
    99
            if (!checkbox.isFocusOwner()) {
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   100
                throw new RuntimeException("Test Failed: checkbox doesn't have focus");
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
   101
            }
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
   102
        }
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
   103
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   104
        // press VK_DOWN
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   105
        robot.keyPress(KeyEvent.VK_DOWN);
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   106
        robot.delay(50);
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   107
        robot.keyRelease(KeyEvent.VK_DOWN);
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   108
        robot.delay(50);
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
   109
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   110
        Util.waitForIdle(robot);
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
   111
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   112
        // verify if text area has focus
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   113
        if (!textarea.isFocusOwner()) {
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   114
            throw new RuntimeException("Test Failed: focus wasn't transfered to text area");
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   115
        }
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   116
        // press '1'
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   117
        robot.keyPress(KeyEvent.VK_1);
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   118
        robot.delay(50);
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   119
        robot.keyRelease(KeyEvent.VK_1);
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   120
        robot.delay(50);
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
   121
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   122
        Util.waitForIdle(robot);
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
   123
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   124
        // verify if KEY_TYPED arrived
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   125
        if (!"1".equals(textarea.getText())) {
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   126
            throw new RuntimeException("Test Failed: text area text is \"" + textarea.getText() + "\", not \"1\"");
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   127
        }
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   128
        System.out.println("Test Passed");
423
1c607ab74068 6680135: A number of test/closed/java/awt/Focus/* tests should be opened
ant
parents:
diff changeset
   129
    }
425
89b44fab010f 6616792: five AWT focus regression tests should be fixed
ant
parents: 423
diff changeset
   130
}