1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/*
* Copyright 2012 Red Hat, Inc. All Rights Reserved.
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 7043963
@summary Tests that the screen location of windows is
updated properly after a maximize.
@requires (os.family == "linux" | os.family == "solaris")
@modules java.desktop/sun.awt.X11
@author Denis Lila
@library ../../regtesthelpers
@build Util
@run main MutterMaximizeTest
*/
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Point;
import java.awt.Robot;
import java.awt.Window;
import java.awt.event.InputEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import test.java.awt.regtesthelpers.Util;
@SuppressWarnings("serial")
public class MutterMaximizeTest extends Frame {
public static void main(String[] args) throws InterruptedException {
if (Util.getWMID() != Util.MUTTER_WM) {
System.out.println("This test is only useful on Mutter");
return;
}
MutterMaximizeTest frame = new MutterMaximizeTest();
frame.addWindowListener(Util.getClosingWindowAdapter());
//Display the window.
frame.setSize(500, 500);
Util.showWindowWait(frame);
runRobotTest(frame);
}
private static void runRobotTest(Frame frame) {
try {
Thread robotThread = startRegTest(frame);
robotThread.start();
waitForThread(robotThread);
} finally {
frame.dispose();
}
}
private static void waitForThread(Thread t) {
while (t.isAlive()) {
try {
t.join();
} catch (InterruptedException e) {
}
}
}
private static void sleepFor(long millis) {
long dT = 0;
long start = System.nanoTime();
while (dT < millis) {
try {
long toSleep = millis - dT/1000000;
if (toSleep > 0) {
Thread.sleep(toSleep);
}
// if this ends without an interrupted exception,
// that's good enough.
break;
} catch (InterruptedException e) {
long now = System.nanoTime();
dT = now - start;
}
}
}
private static void rmove(Robot robot, Point p) {
robot.mouseMove(p.x, p.y);
}
private static void rdown(Robot robot) {
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(50);
}
private static void rup(Robot robot) {
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(50);
}
public static void click(Robot robot) {
rdown(robot);
rup(robot);
}
public static void doubleClick(Robot robot) {
click(robot);
click(robot);
}
private static void dragWindow(Window w, int dx, int dy, Robot robot) {
Point p = Util.getTitlePoint(w);
rmove(robot, p);
rdown(robot);
p.translate(dx, dy);
rmove(robot, p);
rup(robot);
}
// f must be visible
private static Thread startRegTest(final Frame f) {
Thread robot = new Thread(new Runnable() {
public void run() {
Robot r = Util.createRobot();
dragWindow(f, 100, 100, r);
// wait for the location to be set.
sleepFor(2000);
final Point l2 = f.getLocationOnScreen();
// double click should maximize the frame
doubleClick(r);
// wait for location again.
sleepFor(2000);
final Point l3 = f.getLocationOnScreen();
if (l3.equals(l2)) {
throw new RuntimeException("Bad location after maximize. Window location has not moved");
}
}
});
return robot;
}
}
|