Path: blob/master/test/jdk/java/awt/Modal/ModalDialogOrderingTest/ModalDialogOrderingTest.java
41155 views
/*1* Copyright (c) 2013, 2016, 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* @key headful34* @bug 800872835* @summary [macosx] Swing. JDialog. Modal dialog goes to background36* @author Alexandr Scherbatiy37* @library /lib/client38* @build ExtendedRobot39* @run main ModalDialogOrderingTest40*/41public class ModalDialogOrderingTest {4243private static final Color DIALOG_COLOR = Color.GREEN;44private static final Color FRAME_COLOR = Color.BLUE;4546public static void main(String[] args) {4748final Frame frame = new Frame("Test");49frame.setSize(400, 400);50frame.setBackground(FRAME_COLOR);51frame.setVisible(true);5253final Dialog modalDialog = new Dialog(null, true);54modalDialog.setTitle("Modal Dialog");55modalDialog.setSize(400, 200);56modalDialog.setBackground(DIALOG_COLOR);57modalDialog.setModal(true);5859new Thread(new Runnable() {6061@Override62public void run() {63runTest(modalDialog, frame);64}65}).start();6667modalDialog.setVisible(true);68}6970private static void runTest(Dialog dialog, Frame frame) {71try {72ExtendedRobot robot = new ExtendedRobot();73robot.setAutoDelay(50);74robot.mouseMove(300, 300);7576while (!dialog.isVisible()) {77robot.waitForIdle(1000);78}7980Rectangle dialogBounds = dialog.getBounds();81Rectangle frameBounds = frame.getBounds();8283int y1 = dialogBounds.y + dialogBounds.height;84int y2 = frameBounds.y + frameBounds.height;8586int clickX = frameBounds.x + frameBounds.width / 2;87int clickY = y1 + (y2 - y1) / 2;8889robot.mouseMove(clickX, clickY);90robot.mousePress(InputEvent.BUTTON1_MASK);91robot.mouseRelease(InputEvent.BUTTON1_MASK);92robot.waitForIdle(1000);9394int colorX = dialogBounds.x + dialogBounds.width / 2;95int colorY = dialogBounds.y + dialogBounds.height / 2;9697Color color = robot.getPixelColor(colorX, colorY);9899100if (!DIALOG_COLOR.equals(color)) {101throw new RuntimeException("The frame is on top"102+ " of the modal dialog!");103}else{104frame.dispose();105dialog.dispose();106}107} catch (Exception ex) {108throw new RuntimeException(ex);109}110}111}112113114