Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Focus/OwnedWindowFocusIMECrashTest/OwnedWindowFocusIMECrashTest.java
47490 views
/*1* Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24@test25@bug 654297526@summary Tests that switching focus from an owned window doesn't crash.27@author [email protected]: area=awt-focus28@library ../../regtesthelpers29@build Util30@run main OwnedWindowFocusIMECrashTest31*/3233import java.awt.*;34import javax.swing.*;35import test.java.awt.regtesthelpers.Util;3637public class OwnedWindowFocusIMECrashTest {38Robot robot;39JFrame owner = new JFrame("Owner Frame");40JFrame frame = new JFrame("Other Frame");41JWindow window = new JWindow(owner);42JButton button = new JButton("Button");4344public static void main(String[] args) {45OwnedWindowFocusIMECrashTest app = new OwnedWindowFocusIMECrashTest();46app.init();47app.start();48}4950public void init() {51robot = Util.createRobot();52}5354public void start() {55owner.setBounds(100, 100, 200, 100);56window.setBounds(100, 250, 200, 100);57frame.setBounds(350, 100, 200, 100);58window.add(button);5960owner.setVisible(true);61frame.setVisible(true);62window.setVisible(true);6364Util.waitForIdle(robot);6566test();6768System.out.println("Test passed");69}7071void test() {72Util.clickOnComp(button, robot);73if (!button.hasFocus()) {74throw new TestErrorException("the button couldn't be focused by click");75}76Util.clickOnTitle(frame, robot); // here there was a crash77}78}7980/**81* Thrown when an error not related to the behavior being verified is encountered.82*/83class TestErrorException extends RuntimeException {84TestErrorException(String msg) {85super("Unexpected error: " + msg);86}87}888990