Path: blob/master/test/jdk/java/awt/Dialog/MakeWindowAlwaysOnTop/MakeWindowAlwaysOnTop.java
41152 views
/*1* Copyright (c) 2010, 2018, 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@key headful26@bug 6829546 819780827@summary tests that an always-on-top modal dialog doesn't make any windows always-on-top28@author artem.ananiev: area=awt.modal29@library ../../regtesthelpers30@build Util31@run main MakeWindowAlwaysOnTop32*/3334import java.awt.Frame;35import java.awt.Dialog;36import java.awt.EventQueue;37import java.awt.Color;38import java.awt.Robot;39import java.awt.Point;40import java.awt.event.InputEvent;41import test.java.awt.regtesthelpers.Util;4243public class MakeWindowAlwaysOnTop44{45private static Frame f;46private static Dialog d;4748public static void main(String[] args) throws Exception49{50Robot r = Util.createRobot();51Util.waitForIdle(r);5253// Frame54f = new Frame("Test frame");55f.setBounds(100, 100, 400, 300);56f.setBackground(Color.RED);57f.setVisible(true);58r.delay(100);59Util.waitForIdle(r);6061// Dialog62d = new Dialog(null, "Modal dialog", Dialog.ModalityType.APPLICATION_MODAL);63d.setBounds(500, 500, 160, 160);64d.setAlwaysOnTop(true);65EventQueue.invokeLater(() -> d.setVisible(true) );66// Wait until the dialog is shown67EventQueue.invokeAndWait(() -> { /* Empty */ });68r.delay(100);69Util.waitForIdle(r);7071// Click on the frame to trigger modality72Point p = f.getLocationOnScreen();73r.mouseMove(p.x + f.getWidth() / 2, p.y + f.getHeight() / 2);74Util.waitForIdle(r);75r.mousePress(InputEvent.BUTTON1_MASK);76Util.waitForIdle(r);77r.mouseRelease(InputEvent.BUTTON1_MASK);78Util.waitForIdle(r);7980r.delay(100);81Util.waitForIdle(r);8283// Dispose dialog84d.dispose();85r.delay(100);86Util.waitForIdle(r);8788// Show another frame at the same location89Frame t = new Frame("Check");90t.setBounds(100, 100, 400, 300);91t.setBackground(Color.BLUE);92t.setVisible(true);93r.delay(100);94Util.waitForIdle(r);9596// Bring it above the first frame97t.toFront();9899r.delay(200);100Util.waitForIdle(r);101102103Color c = r.getPixelColor(p.x + f.getWidth() / 2, p.y + f.getHeight() / 2);104System.out.println("Color = " + c);105106String exceptionMessage = null;107// If the color is RED, then the first frame is now always-on-top108if (Color.RED.equals(c)) {109exceptionMessage = "Test FAILED: the frame is always-on-top";110} else if (!Color.BLUE.equals(c)) {111exceptionMessage = "Test FAILED: unknown window is on top of the frame";112}113114// Dispose all the windows115t.dispose();116f.dispose();117118if (exceptionMessage != null) {119throw new RuntimeException(exceptionMessage);120} else {121System.out.println("Test PASSED");122}123}124}125126127