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 5097801 8163270 28 @summary Tests that no mouse events are sent to component if robot is 29 moving mouse on another screen, Xinerama 30 @run main SpuriousMouseEvents 31 */ 32import java.awt.AWTException; 33import java.awt.GraphicsEnvironment; 34import java.awt.GraphicsDevice; 35import java.awt.Robot; 36import java.awt.GraphicsConfiguration; 37import java.awt.Frame; 38import java.awt.event.MouseMotionAdapter; 39import java.awt.event.MouseEvent; 40 41public class SpuriousMouseEvents { 42 43 private static volatile boolean testPassed = true; 44 45 public static void main(String args[]) throws AWTException { 46 GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 47 GraphicsDevice[] gds = ge.getScreenDevices(); 48 if (gds.length < 2) { 49 return; 50 } 51 52 Robot r = null; 53 try { 54 r = new Robot(); 55 } catch (Exception e) { 56 throw new RuntimeException("Couldn't create AWT robot" + e); 57 } 58 59 for (int i = 1; i >= 0; i--) { 60 GraphicsDevice gd = gds[i]; 61 GraphicsDevice gdo = gds[1 - i]; 62 GraphicsConfiguration gc = gd.getDefaultConfiguration(); 63 GraphicsConfiguration gco = gdo.getDefaultConfiguration(); 64 Frame f = new Frame("Frame", gc); 65 f.setBounds(gc.getBounds().x + 100, gc.getBounds().y + 100, 200, 200); 66 f.addMouseMotionListener(new MouseMotionAdapter() { 67 public void mouseMoved(MouseEvent me) { 68 testPassed = false; 69 } 70 }); 71 f.setVisible(true); 72 73 r = new Robot(gdo); 74 int x = (int) gco.getBounds().x; 75 for (int j = x; j < x + 400; j += 10) { 76 r.mouseMove(j, 200); 77 r.delay(10); 78 } 79 r.delay(1000); 80 81 f.setVisible(false); 82 f.dispose(); 83 84 if (!testPassed) { 85 break; 86 } 87 } 88 89 if (!testPassed) { 90 throw new RuntimeException("Wrong mouse events are sent"); 91 } 92 } 93} 94