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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package test.robot.com.sun.glass.ui.monocle; 27 28 import com.sun.glass.ui.monocle.TestLog; 29 import test.robot.com.sun.glass.ui.monocle.TestApplication; 30 import test.robot.com.sun.glass.ui.monocle.input.devices.TestTouchDevice; 31 import test.robot.com.sun.glass.ui.monocle.input.devices.TestTouchDevices; 32 import javafx.geometry.Rectangle2D; 33 import javafx.stage.Screen; 34 import org.junit.Assert; 35 import org.junit.Assume; 36 import org.junit.Test; 37 import org.junit.runners.Parameterized; 38 39 import java.util.Collection; 40 import test.com.sun.glass.ui.monocle.TestRunnable; 41 42 public class TouchEventLookaheadTest extends ParameterizedTestBase { 43 44 public TouchEventLookaheadTest(TestTouchDevice device) { 45 super(device); 46 } 47 48 @Parameterized.Parameters 49 public static Collection<Object[]> data() { 50 return TestTouchDevices.getTouchDeviceParameters(1); 51 } 52 53 /** Merge together similar moves */ 54 @Test 55 public void mergeMoves() throws Exception { 56 Assume.assumeTrue(TestApplication.isMonocle()); 57 TestApplication.showFullScreenScene(); 58 TestApplication.addMouseListeners(); 59 TestApplication.addTouchListeners(); 60 TestLog.reset(); 61 Rectangle2D r = Screen.getPrimary().getBounds(); 62 final int width = (int) r.getWidth(); 63 final int height = (int) r.getHeight(); 64 final int x1 = (int) Math.round(width * 0.1); 65 final int y1 = (int) Math.round(height * 0.1); 66 final int x2 = (int) Math.round(width * 0.9); 67 final int y2 = (int) Math.round(height * 0.9); 68 final int x3 = (int) Math.round(width * 0.5); 69 final int y3 = (int) Math.round(height * 0.5); 70 // Push events while on the event thread, making sure that events 71 // will be buffered up and enabling filtering to take place 72 TestRunnable.invokeAndWait(() -> { 73 int p = device.addPoint(x1, y1); 74 device.sync(); 75 for (int x = x1; x <= x2; x += (x2 - x1) / 100) { 76 device.setPoint(p, x, y1); 77 device.sync(); 78 } 79 for (int y = y1; y <= y2; y += (y2 - y1) / 100) { 80 device.setPoint(p, x2, y); 81 device.sync(); 82 } 83 device.setPoint(p, x3, y3); 84 device.sync(); 85 device.removePoint(p); 86 device.sync(); 87 }); 88 // Check that the initial point reported is correct 89 TestLog.waitForLog("Mouse pressed: " + x1 + ", " + y1, 3000); 90 TestLog.waitForLog("Touch pressed: " + x1 + ", " + y1, 3000); 91 // Check that the final point reported is correct 92 TestLog.waitForLog("Mouse released: " + x3 + ", " + y3, 3000); 93 TestLog.waitForLog("Touch released: " + x3 + ", " + y3, 3000); 94 // Check that moves in between were filtered 95 TestLog.waitForLog("Mouse dragged: " + x3 + ", " + y3, 3000); 96 TestLog.waitForLog("Touch moved: " + x3 + ", " + y3, 3000); 97 Assert.assertTrue(TestLog.countLogContaining("Mouse dragged") <= 3); 98 Assert.assertTrue(TestLog.countLogContaining("Touch moved") <= 3); 99 } 100 }