Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java
38821 views
/*1* Copyright (c) 2013, 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*/2223import java.awt.Color;24import java.awt.Dialog;25import java.awt.Frame;26import java.awt.Rectangle;27import java.awt.Robot;28import java.awt.Toolkit;29import java.awt.event.InputEvent;3031/**32* @test33* @bug 800872834* @summary [macosx] Swing. JDialog. Modal dialog goes to background35* @author Alexandr Scherbatiy36* @library ../../../../lib/testlibrary37* @build ExtendedRobot38* @run main ModalDialogOrderingTest39*/40public class ModalDialogOrderingTest {4142private static final Color DIALOG_COLOR = Color.GREEN;43private static final Color FRAME_COLOR = Color.BLUE;4445public static void main(String[] args) {4647final Frame frame = new Frame("Test");48frame.setSize(400, 400);49frame.setBackground(FRAME_COLOR);50frame.setVisible(true);5152final Dialog modalDialog = new Dialog(null, true);53modalDialog.setTitle("Modal Dialog");54modalDialog.setSize(400, 200);55modalDialog.setBackground(DIALOG_COLOR);56modalDialog.setModal(true);5758new Thread(new Runnable() {5960@Override61public void run() {62runTest(modalDialog, frame);63}64}).start();6566modalDialog.setVisible(true);67}6869private static void runTest(Dialog dialog, Frame frame) {70try {71ExtendedRobot robot = new ExtendedRobot();72robot.setAutoDelay(50);73robot.mouseMove(300, 300);7475while (!dialog.isVisible()) {76robot.waitForIdle(1000);77}7879Rectangle dialogBounds = dialog.getBounds();80Rectangle frameBounds = frame.getBounds();8182int y1 = dialogBounds.y + dialogBounds.height;83int y2 = frameBounds.y + frameBounds.height;8485int clickX = frameBounds.x + frameBounds.width / 2;86int clickY = y1 + (y2 - y1) / 2;8788robot.mouseMove(clickX, clickY);89robot.mousePress(InputEvent.BUTTON1_MASK);90robot.mouseRelease(InputEvent.BUTTON1_MASK);91robot.waitForIdle(1000);9293int colorX = dialogBounds.x + dialogBounds.width / 2;94int colorY = dialogBounds.y + dialogBounds.height / 2;9596Color color = robot.getPixelColor(colorX, colorY);979899if (!DIALOG_COLOR.equals(color)) {100throw new RuntimeException("The frame is on top"101+ " of the modal dialog!");102}else{103frame.dispose();104dialog.dispose();105}106} catch (Exception ex) {107throw new RuntimeException(ex);108}109}110}111112113