jdk/test/java/awt/Focus/OwnedWindowFocusIMECrashTest/OwnedWindowFocusIMECrashTest.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:
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
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.
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
     4
 *
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
     8
 *
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    13
 * accompanied this code).
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    14
 *
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2472
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2472
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2472
diff changeset
    21
 * questions.
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    22
 */
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    23
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    24
/*
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    25
  @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 5506
diff changeset
    26
  @key headful
2472
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    27
  @bug       6542975
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    28
  @summary   Tests that switching focus from an owned window doesn't crash.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    29
  @author    anton.tarasov@sun.com: area=awt-focus
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    30
  @library    ../../regtesthelpers
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    31
  @build     Util
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    32
  @run       main OwnedWindowFocusIMECrashTest
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    33
*/
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    34
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    35
import java.awt.*;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    36
import javax.swing.*;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    37
import test.java.awt.regtesthelpers.Util;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    38
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    39
public class OwnedWindowFocusIMECrashTest {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    40
    Robot robot;
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    41
    JFrame owner = new JFrame("Owner Frame");
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    42
    JFrame frame = new JFrame("Other Frame");
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    43
    JWindow window = new JWindow(owner);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    44
    JButton button = new JButton("Button");
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    45
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    46
    public static void main(String[] args) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    47
        OwnedWindowFocusIMECrashTest app = new OwnedWindowFocusIMECrashTest();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    48
        app.init();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    49
        app.start();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    50
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    51
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    52
    public void init() {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    53
        robot = Util.createRobot();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    54
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    55
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    56
    public void start() {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    57
        owner.setBounds(100, 100, 200, 100);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    58
        window.setBounds(100, 250, 200, 100);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    59
        frame.setBounds(350, 100, 200, 100);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    60
        window.add(button);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    61
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    62
        owner.setVisible(true);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    63
        frame.setVisible(true);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    64
        window.setVisible(true);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    65
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    66
        Util.waitForIdle(robot);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    67
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    68
        test();
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    69
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    70
        System.out.println("Test passed");
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    71
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    72
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    73
    void test() {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    74
        Util.clickOnComp(button, robot);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    75
        if (!button.hasFocus()) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    76
            throw new TestErrorException("the button couldn't be focused by click");
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    77
        }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    78
        Util.clickOnTitle(frame, robot); // here there was a crash
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    79
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    80
}
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    81
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    82
/**
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    83
 * Thrown when an error not related to the behavior being verified is encountered.
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    84
 */
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    85
class TestErrorException extends RuntimeException {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    86
    TestErrorException(String msg) {
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    87
        super("Unexpected error: " + msg);
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    88
    }
b7aba00cabb6 6693253: Security Warning appearance requires enhancements
anthony
parents:
diff changeset
    89
}