1 /*
   2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8012586
  27  * @summary verify that modal dialog will appeared above fullscreen window under Metacity WM.
  28  * @library ../../regtesthelpers
  29  * @build Util
  30  * @run main FullscreenDialogModality
  31  * @run main/othervm FullscreenDialogModality
  32  * @author vkravets
  33  */
  34 
  35 import test.java.awt.regtesthelpers.Util;
  36 
  37 import java.awt.*;
  38 import java.lang.reflect.InvocationTargetException;
  39 
  40 public class FullscreenDialogModality extends Frame {
  41 
  42     static Robot robot = null;
  43 
  44     public void enterFS() {
  45         GraphicsDevice gd = getGraphicsConfiguration().getDevice();
  46         final boolean fs = gd.isFullScreenSupported();
  47         System.out.println("FullscreenSupported: " + (fs ? "yes" : "no"));
  48         gd.setFullScreenWindow(this);
  49         try {
  50             // Give the system time to set the FS window and display it
  51             // properly
  52             Thread.sleep(2000);
  53         } catch (Exception e) {}
  54     }
  55 
  56     public void exitFS() {
  57         GraphicsDevice gd = getGraphicsConfiguration().getDevice();
  58         // reset window
  59         gd.setFullScreenWindow(null);
  60         try {
  61             // Give the system time to set the FS window and display it
  62             // properly
  63             Thread.sleep(2000);
  64         } catch (Exception e) {}
  65     }
  66 
  67     public void checkDialogModality() throws InvocationTargetException, InterruptedException {
  68         // Dialog
  69         final Dialog d = new Dialog(FullscreenDialogModality.this, "Modal dialog", Dialog.ModalityType.APPLICATION_MODAL);
  70         d.setBounds(500, 500, 160, 160);
  71         d.setModal(true);
  72         d.setBackground(Color.red);
  73         EventQueue.invokeLater(new Runnable()
  74         {
  75             public void run()
  76             {
  77                 d.setVisible(true);
  78             }
  79         });
  80         // Wait until the dialog is shown
  81         EventQueue.invokeLater(new Runnable() {
  82             public void run() {
  83                 // Empty
  84             }
  85         });
  86 
  87         Util.waitForIdle(robot);
  88         try {
  89             //Check color
  90             Point checkPoint = new Point(d.getX() + d.getWidth() / 2, d.getY() + d.getHeight() / 2);
  91             Color actual = robot.getPixelColor(checkPoint.x, checkPoint.y);
  92             System.out.println("Color = " + actual);
  93             if (actual.getRGB() == Color.GREEN.getRGB()) {
  94                 throw new RuntimeException("Test FAILED: Modal dialog shown below fullscreen window");
  95             } else if (actual.getRGB() == Color.RED.getRGB()) {
  96                 System.out.println("Test PASSED: Modal dialog shown above fullscreen window");
  97             } else {
  98                 System.out.println("pixelColor " +
  99                         Integer.toHexString(actual.getRGB()) +
 100                         " at coordinates (" + checkPoint.x + ", " + checkPoint.y + ")");
 101                 throw new RuntimeException("Test FAILED: Unexpected behavior");
 102             }
 103 
 104             robot.delay(2000);
 105             Util.waitForIdle(robot);
 106         } finally {
 107             d.dispose();
 108         }
 109     }
 110 
 111     public static void main(String args[]) throws InvocationTargetException, InterruptedException {
 112         if (Util.getWMID() != Util.METACITY_WM) {
 113             System.out.println("This test is only useful on Metacity");
 114             return;
 115         }
 116         robot = Util.createRobot();
 117         Util.waitForIdle(robot);
 118         final FullscreenDialogModality frame = new FullscreenDialogModality();
 119         frame.setUndecorated(true);
 120         frame.setBackground(Color.green);
 121         frame.setSize(500, 500);
 122         frame.setVisible(true);
 123         try {
 124             robot.delay(100);
 125             Util.waitForIdle(robot);
 126 
 127             EventQueue.invokeAndWait(new Runnable() {
 128                 public void run() {
 129                     frame.enterFS();
 130                 }
 131             });
 132             robot.delay(200);
 133             Util.waitForIdle(robot);
 134 
 135             frame.checkDialogModality();
 136 
 137             EventQueue.invokeAndWait(new Runnable() {
 138                 public void run() {
 139                     frame.exitFS();
 140                 }
 141             });
 142         } finally {
 143             frame.dispose();
 144         }
 145     }
 146 }