|
1 /* |
|
2 * Copyright (c) 2014, 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 8013116 |
|
27 @summary Robot moves mouse to point which differs from set in mouseMove on |
|
28 Unity shell |
|
29 @author Oleg Pekhovskiy |
|
30 @library ../../regtesthelpers |
|
31 @build Util |
|
32 @run main MultiScreenLocationTest |
|
33 */ |
|
34 |
|
35 import java.awt.AWTException; |
|
36 import java.awt.Color; |
|
37 import java.awt.Frame; |
|
38 import java.awt.GraphicsConfiguration; |
|
39 import java.awt.GraphicsDevice; |
|
40 import java.awt.GraphicsEnvironment; |
|
41 import java.awt.MouseInfo; |
|
42 import java.awt.Point; |
|
43 import java.awt.Rectangle; |
|
44 import java.awt.Robot; |
|
45 import java.awt.image.BufferedImage; |
|
46 import test.java.awt.regtesthelpers.Util; |
|
47 |
|
48 public class MultiScreenLocationTest { |
|
49 private static final Point mouseOffset = new Point(150, 150); |
|
50 private static final Point frameOffset = new Point(100, 100); |
|
51 private static final Color color = Color.YELLOW; |
|
52 |
|
53 private static String getErrorText(final String name, int screen) |
|
54 { |
|
55 return name + " test failed on Screen #" + screen + "!"; |
|
56 } |
|
57 |
|
58 public static void main(String[] args) throws AWTException |
|
59 { |
|
60 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
61 GraphicsDevice[] gds = ge.getScreenDevices(); |
|
62 if (gds.length < 2) { |
|
63 System.out.println("It's a multiscreen test... skipping!"); |
|
64 return; |
|
65 } |
|
66 |
|
67 for (int i = 0; i < gds.length; ++i) { |
|
68 GraphicsDevice gd = gds[i]; |
|
69 GraphicsConfiguration gc = gd.getDefaultConfiguration(); |
|
70 Rectangle screen = gc.getBounds(); |
|
71 Robot robot = new Robot(gd); |
|
72 |
|
73 // check Robot.mouseMove() |
|
74 robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y); |
|
75 Point mouse = MouseInfo.getPointerInfo().getLocation(); |
|
76 Point point = screen.getLocation(); |
|
77 point.translate(mouseOffset.x, mouseOffset.y); |
|
78 if (!point.equals(mouse)) { |
|
79 throw new RuntimeException(getErrorText("Robot.mouseMove", i)); |
|
80 } |
|
81 |
|
82 // check Robot.getPixelColor() |
|
83 Frame frame = new Frame(gc); |
|
84 frame.setUndecorated(true); |
|
85 frame.setSize(100, 100); |
|
86 frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y); |
|
87 frame.setBackground(color); |
|
88 frame.setVisible(true); |
|
89 robot.waitForIdle(); |
|
90 Rectangle bounds = frame.getBounds(); |
|
91 if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) { |
|
92 throw new RuntimeException(getErrorText("Robot.getPixelColor", i)); |
|
93 } |
|
94 |
|
95 // check Robot.createScreenCapture() |
|
96 BufferedImage image = robot.createScreenCapture(bounds); |
|
97 int rgb = color.getRGB(); |
|
98 if (image.getRGB(0, 0) != rgb |
|
99 || image.getRGB(image.getWidth() - 1, 0) != rgb |
|
100 || image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb |
|
101 || image.getRGB(0, image.getHeight() - 1) != rgb) { |
|
102 throw new RuntimeException( |
|
103 getErrorText("Robot.createScreenCapture", i)); |
|
104 } |
|
105 frame.dispose(); |
|
106 } |
|
107 |
|
108 System.out.println("Test PASSED!"); |
|
109 } |
|
110 } |