6113N/A/*
6113N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
6113N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6113N/A *
6113N/A * This code is free software; you can redistribute it and/or modify it
6113N/A * under the terms of the GNU General Public License version 2 only, as
6113N/A * published by the Free Software Foundation.
6113N/A *
6113N/A * This code is distributed in the hope that it will be useful, but WITHOUT
6113N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6113N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6113N/A * version 2 for more details (a copy is included in the LICENSE file that
6113N/A * accompanied this code).
6113N/A *
6113N/A * You should have received a copy of the GNU General Public License version
6113N/A * 2 along with this work; if not, write to the Free Software Foundation,
6113N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6113N/A *
6113N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6113N/A * or visit www.oracle.com if you need additional information or have any
6113N/A * questions.
6113N/A */
6113N/A
6113N/A/*
6113N/A * @test
6113N/A * @bug 8012586
6113N/A * @summary verify that modal dialog will appeared above fullscreen window under Metacity WM.
6113N/A * @library ../../regtesthelpers
6113N/A * @build Util
6113N/A * @run main FullscreenDialogModality
6113N/A * @run main/othervm FullscreenDialogModality
6113N/A * @author vkravets
6113N/A */
6113N/A
6113N/Aimport test.java.awt.regtesthelpers.Util;
6113N/A
6113N/Aimport java.awt.*;
6113N/Aimport java.lang.reflect.InvocationTargetException;
6113N/A
6113N/Apublic class FullscreenDialogModality extends Frame {
6113N/A
6113N/A static Robot robot = null;
6113N/A
6113N/A public void enterFS() {
6113N/A GraphicsDevice gd = getGraphicsConfiguration().getDevice();
6113N/A final boolean fs = gd.isFullScreenSupported();
6113N/A System.out.println("FullscreenSupported: " + (fs ? "yes" : "no"));
6113N/A gd.setFullScreenWindow(this);
6113N/A try {
6113N/A // Give the system time to set the FS window and display it
6113N/A // properly
6113N/A Thread.sleep(2000);
6113N/A } catch (Exception e) {}
6113N/A }
6113N/A
6113N/A public void exitFS() {
6113N/A GraphicsDevice gd = getGraphicsConfiguration().getDevice();
6113N/A // reset window
6113N/A gd.setFullScreenWindow(null);
6113N/A try {
6113N/A // Give the system time to set the FS window and display it
6113N/A // properly
6113N/A Thread.sleep(2000);
6113N/A } catch (Exception e) {}
6113N/A }
6113N/A
6113N/A public void checkDialogModality() throws InvocationTargetException, InterruptedException {
6113N/A // Dialog
6113N/A final Dialog d = new Dialog(FullscreenDialogModality.this, "Modal dialog", Dialog.ModalityType.APPLICATION_MODAL);
6113N/A d.setBounds(500, 500, 160, 160);
6113N/A d.setModal(true);
6113N/A d.setBackground(Color.red);
6113N/A EventQueue.invokeLater(new Runnable()
6113N/A {
6113N/A public void run()
6113N/A {
6113N/A d.setVisible(true);
6113N/A }
6113N/A });
6113N/A // Wait until the dialog is shown
6113N/A EventQueue.invokeLater(new Runnable() {
6113N/A public void run() {
6113N/A // Empty
6113N/A }
6113N/A });
6113N/A
6113N/A Util.waitForIdle(robot);
6113N/A try {
6113N/A //Check color
6113N/A Point checkPoint = new Point(d.getX() + d.getWidth() / 2, d.getY() + d.getHeight() / 2);
6113N/A Color actual = robot.getPixelColor(checkPoint.x, checkPoint.y);
6113N/A System.out.println("Color = " + actual);
6113N/A if (actual.getRGB() == Color.GREEN.getRGB()) {
6113N/A throw new RuntimeException("Test FAILED: Modal dialog shown below fullscreen window");
6113N/A } else if (actual.getRGB() == Color.RED.getRGB()) {
6113N/A System.out.println("Test PASSED: Modal dialog shown above fullscreen window");
6113N/A } else {
6113N/A System.out.println("pixelColor " +
6113N/A Integer.toHexString(actual.getRGB()) +
6113N/A " at coordinates (" + checkPoint.x + ", " + checkPoint.y + ")");
6113N/A throw new RuntimeException("Test FAILED: Unexpected behavior");
6113N/A }
6113N/A
6113N/A robot.delay(2000);
6113N/A Util.waitForIdle(robot);
6113N/A } finally {
6113N/A d.dispose();
6113N/A }
6113N/A }
6113N/A
6113N/A public static void main(String args[]) throws InvocationTargetException, InterruptedException {
6113N/A if (Util.getWMID() != Util.METACITY_WM) {
6113N/A System.out.println("This test is only useful on Metacity");
6113N/A return;
6113N/A }
6113N/A robot = Util.createRobot();
6113N/A Util.waitForIdle(robot);
6113N/A final FullscreenDialogModality frame = new FullscreenDialogModality();
6113N/A frame.setUndecorated(true);
6113N/A frame.setBackground(Color.green);
6113N/A frame.setSize(500, 500);
6113N/A frame.setVisible(true);
6113N/A try {
6113N/A robot.delay(100);
6113N/A Util.waitForIdle(robot);
6113N/A
6113N/A EventQueue.invokeAndWait(new Runnable() {
6113N/A public void run() {
6113N/A frame.enterFS();
6113N/A }
6113N/A });
6113N/A robot.delay(200);
6113N/A Util.waitForIdle(robot);
6113N/A
6113N/A frame.checkDialogModality();
6113N/A
6113N/A EventQueue.invokeAndWait(new Runnable() {
6113N/A public void run() {
6113N/A frame.exitFS();
6113N/A }
6113N/A });
6113N/A } finally {
6113N/A frame.dispose();
6113N/A }
6113N/A }
6113N/A}