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  * @run main FullscreenDialogModality
  29  * @run main/othervm FullscreenDialogModality
  30  * @author vkravets
  31  */
  32 
  33 import test.java.awt.regtesthelpers.Util;
  34 
  35 import java.awt.*;
  36 import java.lang.reflect.InvocationTargetException;
  37 
  38 public class FullscreenDialogModality extends Frame {
  39 
  40     static Robot robot = null;
  41 
  42     public void enterFS() {
  43         GraphicsDevice gd = getGraphicsConfiguration().getDevice();
  44         final boolean fs = gd.isFullScreenSupported();
  45         System.out.println("FullscreenSupported: " + (fs ? "yes" : "no"));
  46         gd.setFullScreenWindow(this);
  47         try {
  48             // Give the system time to set the FS window and display it
  49             // properly
  50             Thread.sleep(2000);
  51         } catch (Exception e) {}
  52     }
  53 
  54     public void exitFS() {
  55         GraphicsDevice gd = getGraphicsConfiguration().getDevice();
  56         // reset window
  57         gd.setFullScreenWindow(null);
  58         try {
  59             // Give the system time to set the FS window and display it
  60             // properly
  61             Thread.sleep(2000);
  62         } catch (Exception e) {}
  63     }
  64 
  65     public void checkDialogModality() throws InvocationTargetException, InterruptedException {
  66         // Dialog
  67         final Dialog d = new Dialog(FullscreenDialogModality.this, "Modal dialog", Dialog.ModalityType.APPLICATION_MODAL);
  68         d.setBounds(500, 500, 160, 160);
  69         d.setModal(true);
  70         d.setBackground(Color.red);
  71         EventQueue.invokeLater(new Runnable()
  72         {
  73             public void run()
  74             {
  75                 d.setVisible(true);
  76             }
  77         });
  78         // Wait until the dialog is shown
  79         EventQueue.invokeLater(new Runnable() {
  80             public void run() {
  81                 // Empty
  82             }
  83         });
  84 
  85         Util.waitForIdle(robot);
  86         try {
  87             //Check color
  88             Point checkPoint = new Point(d.getX() + d.getWidth() / 2, d.getY() + d.getHeight() / 2);
  89             Color actual = robot.getPixelColor(checkPoint.x, checkPoint.y);
  90             System.out.println("Color = " + actual);
  91             if (actual.getRGB() == Color.GREEN.getRGB()) {
  92                 throw new RuntimeException("Test FAILED: Modal dialog shown below fullscreen window");
  93             } else if (actual.getRGB() == Color.RED.getRGB()) {
  94                 System.out.println("Test PASSED: Modal dialog shown above fullscreen window");
  95             } else {
  96                 System.out.println("pixelColor " +
  97                         Integer.toHexString(actual.getRGB()) +
  98                         " at coordinates (" + checkPoint.x + ", " + checkPoint.y + ")");
  99                 throw new RuntimeException("Test FAILED: Unexpected behavior");
 100             }
 101 
 102             robot.delay(2000);
 103             Util.waitForIdle(robot);
 104         } finally {
 105             d.dispose();
 106         }
 107     }
 108 
 109     public static void main(String args[]) throws InvocationTargetException, InterruptedException {
 110         if (Util.getWMID() != Util.METACITY_WM) {
 111             System.out.println("This test is only useful on Metacity");
 112             return;
 113         }
 114         robot = Util.createRobot();
 115         Util.waitForIdle(robot);
 116         final FullscreenDialogModality frame = new FullscreenDialogModality();
 117         frame.setUndecorated(true);
 118         frame.setBackground(Color.green);
 119         frame.setSize(500, 500);
 120         frame.setVisible(true);
 121         try {
 122             robot.delay(100);
 123             Util.waitForIdle(robot);
 124 
 125             EventQueue.invokeAndWait(new Runnable() {
 126                 public void run() {
 127                     frame.enterFS();
 128                 }
 129             });
 130             robot.delay(200);
 131             Util.waitForIdle(robot);
 132 
 133             frame.checkDialogModality();
 134 
 135             EventQueue.invokeAndWait(new Runnable() {
 136                 public void run() {
 137                     frame.exitFS();
 138                 }
 139             });
 140         } finally {
 141             frame.dispose();
 142         }
 143     }
 144 }