Path: blob/master/test/jdk/java/awt/EmbeddedFrame/GraphicsConfigTest/GraphicsConfigTest.java
41155 views
/*1* Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 635632226* @key headful27* @summary Tests that embedded frame's graphics configuration is updated28* correctly when it is moved to another screen in multiscreen system,29* XToolkit30* @author [email protected]: area=awt.multiscreen31* @requires os.family == "linux"32* @modules java.desktop/sun.awt33* java.desktop/sun.awt.X1134* java.desktop/java.awt.peer35* @run main GraphicsConfigTest36*/3738import java.awt.*;39import java.awt.peer.*;40import java.lang.reflect.*;41import java.util.*;42import sun.awt.*;4344public class GraphicsConfigTest {4546private static void init()47throws InterruptedException, AWTException {48if (!isXToolkit()) {49System.err.println("The test should be run only on XToolkit");50return;51}5253GraphicsEnvironment ge =54GraphicsEnvironment.getLocalGraphicsEnvironment();55GraphicsDevice[] gds = ge.getScreenDevices();56if (gds.length < 2) {57System.err.println("The test should be run only in"58+ " multiscreen configuration");59return;60}6162boolean xinerama = Arrays.stream(gds)63.map((gd) -> gd.getDefaultConfiguration().getBounds())64.filter((r) -> r.x != 0 || r.y != 0).findFirst().isPresent();6566if (!xinerama) {67System.err.println("The test should be run only with Xinerama ON");68return;69}7071Rectangle r0 = gds[0].getDefaultConfiguration().getBounds();72Rectangle r1 = gds[1].getDefaultConfiguration().getBounds();7374System.setProperty("sun.awt.xembedserver", "true");75Frame f = new Frame("F");76try {77final Robot robot = new Robot();7879f.setBounds(r0.x + 100, r0.y + 100, 200, 200);80f.setVisible(true);81robot.waitForIdle();82Thread.sleep(1000);8384Canvas c = new Canvas();85f.add(c);86AWTAccessor.ComponentAccessor acc =87AWTAccessor.getComponentAccessor();88WindowIDProvider wip = acc.getPeer(c);89long h = wip.getWindow();9091EmbeddedFrame e = createEmbeddedFrame(h);92acc.<FramePeer>getPeer(e).setBoundsPrivate(0, 0, 100,93100); // triggers XConfigureEvent94e.registerListeners();95e.setVisible(true);96robot.waitForIdle();97Thread.sleep(1000);9899if (!checkGC(f, e)) {100throw new RuntimeException("Failed at checkpoint 1");101}102103f.setLocation(r1.x + 100, r1.y + 100);104Thread.sleep(100);105acc.<FramePeer>getPeer(e).setBoundsPrivate(0, 0, 101,106101); // triggers XConfigureEvent107robot.waitForIdle();108Thread.sleep(1000);109110if (!checkGC(f, e)) {111throw new RuntimeException("Failed at checkpoint 2");112}113114f.setLocation(r0.x + 100, r0.y + 100);115Thread.sleep(100);116acc.<FramePeer>getPeer(e).setBoundsPrivate(0, 0, 102,117102); // triggers XConfigureEvent118robot.waitForIdle();119Thread.sleep(1000);120121if (!checkGC(f, e)) {122throw new RuntimeException("Failed at checkpoint 3");123}124125} finally {126f.dispose();127}128}129130private static boolean isXToolkit() {131return Toolkit.getDefaultToolkit().getClass()132.getName().equals("sun.awt.X11.XToolkit");133}134135private static EmbeddedFrame createEmbeddedFrame(long window) {136try {137Class cl = Class.forName("sun.awt.X11.XEmbeddedFrame");138Constructor cons = cl.getConstructor(139new Class[]{Long.TYPE, Boolean.TYPE});140return (EmbeddedFrame) cons.newInstance(new Object[]{window, true});141} catch (Exception e) {142e.printStackTrace();143throw new RuntimeException("Can't create embedded frame");144}145}146147private static boolean checkGC(Component c, Component d) {148GraphicsConfiguration g1 = c.getGraphicsConfiguration();149System.err.println(g1);150GraphicsConfiguration g2 = d.getGraphicsConfiguration();151System.err.println(g2);152153return g1.equals(g2);154}155156public static void main(String args[]) throws InterruptedException, AWTException {157init();158}159}160161162