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