1 /* 2 * Copyright (c) 2016, 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 * @key headful 27 * @bug 8080729 28 * @summary Dialogs on multiscreen jump to parent frame on focus gain 29 * @author Dmitry Markov 30 * @library ../../regtesthelpers 31 * @build Util 32 * @run main WindowJumpingTest 33 */ 34 import java.awt.*; 35 36 import test.java.awt.regtesthelpers.Util; 37 38 public class WindowJumpingTest { 39 public static void main(String[] args) throws AWTException { 40 Robot r = Util.createRobot(); 41 42 GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment(); 43 GraphicsDevice[] graphicsDevices = graphicsEnvironment.getScreenDevices(); 44 if (graphicsDevices.length < 2) { 45 System.out.println("This is multi-screen test... Skipping!"); 46 return; 47 } 48 49 Frame frame = new Frame("Frame", graphicsDevices[0].getDefaultConfiguration()); 50 frame.setSize(400, 300); 51 frame.setVisible(true); 52 Util.waitForIdle(r); 53 54 Dialog dialog = new Dialog(frame, "Dialog", false, graphicsDevices[1].getDefaultConfiguration()); 55 dialog.setSize(400, 300); 56 dialog.setVisible(true); 57 Util.waitForIdle(r); 58 59 checkGraphicsDevice(frame, graphicsDevices[0]); 60 checkGraphicsDevice(dialog, graphicsDevices[1]); 61 62 Util.clickOnComp(frame, r); 63 Util.waitForIdle(r); 64 65 checkGraphicsDevice(frame, graphicsDevices[0]); 66 checkGraphicsDevice(dialog, graphicsDevices[1]); 67 68 Util.clickOnComp(dialog, r); 69 Util.waitForIdle(r); 70 71 checkGraphicsDevice(frame, graphicsDevices[0]); 72 checkGraphicsDevice(dialog, graphicsDevices[1]); 73 74 dialog.dispose(); 75 frame.dispose(); 76 } 77 78 private static void checkGraphicsDevice(Window window, GraphicsDevice graphicsDevice) { 79 GraphicsDevice actualGraphicsDevice = window.getGraphicsConfiguration().getDevice(); 80 81 if (!actualGraphicsDevice.equals(graphicsDevice)) { 82 System.err.println("Expected screen: " + graphicsDevice); 83 System.err.println("Actual screen: "+ actualGraphicsDevice); 84 throw new RuntimeException("Test FAILED: " + window + " is displayed on wrong screen"); 85 } 86 } 87 } 88