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.ParameterizedTestBase; 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 org.junit.Test; 33 import org.junit.runners.Parameterized; 34 35 import java.util.Collection; 36 37 /** Multitouch tests with two points */ 38 public class MultiTouch2Test extends ParameterizedTestBase { 39 40 public MultiTouch2Test(TestTouchDevice device) { 41 super(device); 42 } 43 44 @Parameterized.Parameters 45 public static Collection<Object[]> data() { 46 return TestTouchDevices.getTouchDeviceParameters(2); 47 } 48 49 @Test 50 public void twoFingerTap() throws Exception { 51 final int x1 = (int) Math.round(width * 0.5f); 52 final int y1 = (int) Math.round(height * 0.5f); 53 final int x2 = (int) Math.round(width * 0.75f); 54 final int y2 = (int) Math.round(height * 0.75f); 55 TestLog.reset(); 56 // first finger 57 int p1 = device.addPoint(x1, y1); 58 // second finger 59 int p2 = device.addPoint(x2, y2); 60 device.sync(); 61 TestLog.waitForLog("Touch pressed: " 62 + x1 + ", " + y1, 3000); 63 TestLog.waitForLogContaining("TouchPoint: PRESSED " + x1 + ", " + y1, 3000); 64 TestLog.waitForLogContaining("TouchPoint: PRESSED " + x2 + ", " + y2, 3000); 65 TestLog.reset(); 66 // release 67 device.removePoint(p1); 68 device.removePoint(p2); 69 device.sync(); 70 TestLog.waitForLog("Touch released: " + x1 + ", " + y1, 3000); 71 } 72 73 /** 74 * Touch down two fingers, release first, release second 75 */ 76 @Test 77 public void pressTwoFingersReleaseOne() throws Exception { 78 final int x1 = (int) Math.round(width / 8.0); 79 final int y1 = (int) Math.round(height / 8.0); 80 final int x2 = (int) Math.round(width / 5.0); 81 final int y2 = (int) Math.round(height / 5.0); 82 final int x3 = (int) Math.round(width / 3.0); 83 final int y3 = (int) Math.round(height / 3.0); 84 85 TestLog.reset(); 86 //press first finger 87 int p1 = device.addPoint(x1, y1); 88 //add a second finger 89 int p2 = device.addPoint(x2, y2); 90 device.sync(); 91 TestLog.waitForLog("Mouse pressed: " + x1 + ", " + y1, 3000l); 92 TestLog.waitForLog("Touch pressed: " + x1 + ", " + y1, 3000l); 93 TestLog.waitForLogContaining("TouchPoint: PRESSED " + x1 + ", " + y1, 3000l); 94 TestLog.waitForLogContaining("TouchPoint: PRESSED " + x2 + ", " + y2, 3000l); 95 TestLog.waitForLog("Touch pressed: " + x2 + ", " + y2, 3000l); 96 97 //release one finger 98 TestLog.reset(); 99 device.removePoint(p1); 100 device.sync(); 101 TestLog.waitForLog("Touch released: " + x1 + ", " + y1, 3000l); 102 TestLog.waitForLogContaining("TouchPoint: RELEASED " + x1 + ", " + y1, 3000l); 103 TestLog.waitForLogContaining("TouchPoint: STATIONARY " + x2 + ", " + y2, 3000l); 104 105 TestLog.reset(); 106 device.setPoint(p2, x3, y3); 107 device.sync(); 108 TestLog.waitForLog("Mouse dragged: " + x3 + ", " + y3, 3000l); 109 110 //release second finger 111 TestLog.reset(); 112 device.removePoint(p2); 113 device.sync(); 114 TestLog.waitForLogContaining("Mouse released: " + x3 + ", " + y3, 3000l); 115 TestLog.waitForLogContaining("TouchPoint: RELEASED " + x3 + ", " + y3, 3000l); 116 } 117 118 @Test 119 // @Ignore("RT-35546") 120 public void twoFingerDrag() throws Exception { 121 final int x1 = (int) Math.round(width * 0.5f); 122 final int y1 = (int) Math.round(height * 0.5f); 123 final int x2 = (int) Math.round(width * 0.75f); 124 final int y2 = (int) Math.round(height * 0.75f); 125 final int dx = device.getTapRadius(); 126 final int dy = device.getTapRadius(); 127 // first finger 128 int p1 = device.addPoint(x1, y1); 129 device.sync(); 130 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1); 131 // add a second finger 132 int p2 = device.addPoint(x2, y2); 133 device.sync(); 134 TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x1, y1); 135 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2); 136 // drag both fingers 137 for (int i = 1; i < 10; i++) { 138 TestLog.reset(); 139 device.setPoint(p1, x1 + dx * i, y1 + dy * i); 140 device.setPoint(p2, x2 + dx * i, y2 + dy * i); 141 device.sync(); 142 TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", 143 x1 + dx * i, y1 + dy * i); 144 TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", 145 x2 + dx * i, y2 + dy * i); 146 } 147 for (int i = 8; i >= 0; i--) { 148 TestLog.reset(); 149 device.setPoint(p1, x1 + dx * i, y1 + dy * i); 150 device.setPoint(p2, x2 + dx * i, y2 + dy * i); 151 device.sync(); 152 TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", 153 x1 + dx * i, y1 + dy * i); 154 TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", 155 x2 + dx * i, y2 + dy * i); 156 } 157 TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, y1); 158 TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, y2); 159 //release first finger 160 TestLog.reset(); 161 device.removePoint(p1); 162 device.sync(); 163 TestLog.waitForLogContaining("Touch released: %d, %d", x1, y1); 164 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x1, y1); 165 TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2, y2); 166 //release second finger 167 TestLog.reset(); 168 device.removePoint(p2); 169 device.sync(); 170 TestLog.waitForLogContaining("Touch released: %d, %d", x2, y2); 171 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x2, y2); 172 TestLog.reset(); 173 // tap to cancel inertia 174 int p3 = device.addPoint(x1, y1); 175 device.sync(); 176 device.removePoint(p3); 177 device.sync(); 178 TestLog.waitForLog("Mouse clicked: %d, %d", x1, y1); 179 } 180 181 /** 182 * Touch down two fingers, release both, 183 * touch down two fingers again and release them 184 */ 185 @Test 186 public void pressReleasePressTest() throws Exception { 187 int x1 = (int) Math.round(width / 2); 188 int y1 = (int) Math.round(height * 0.3); 189 int x2 = (int) Math.round(width / 2); 190 int y2 = (int) Math.round(height * 0.7); 191 192 //press two fingers 193 TestLog.reset(); 194 int p1 = device.addPoint(x1, y1); 195 int p2 = device.addPoint(x2, y2); 196 device.sync(); 197 198 //verify pressing two fingers 199 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1); 200 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2); 201 202 //release both fingers 203 TestLog.reset(); 204 device.removePoint(p1); 205 device.removePoint(p2); 206 device.sync(); 207 208 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x1, y1); 209 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x2, y2); 210 211 //press two fingers second time 212 TestLog.reset(); 213 p1 = device.addPoint(x1, y1); 214 p2 = device.addPoint(x2, y2); 215 device.sync(); 216 217 //verify pressing two fingers 218 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1); 219 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2); 220 221 //release both fingers 222 TestLog.reset(); 223 device.removePoint(p1); 224 device.removePoint(p2); 225 device.sync(); 226 227 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x1, y1); 228 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x2, y2); 229 } 230 231 @Test 232 public void twoFingerDragSingleFingerTap() throws Exception { 233 final int x1 = (int) Math.round(width * 0.5f); 234 final int y1 = (int) Math.round(height * 0.5f); 235 final int x2 = (int) Math.round(width * 0.75f); 236 final int y2 = (int) Math.round(height * 0.75f); 237 final int dx = device.getTapRadius(); 238 final int dy = device.getTapRadius(); 239 // first finger 240 int p1 = device.addPoint(x1, y1); 241 device.sync(); 242 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1); 243 // add a second finger 244 int p2 = device.addPoint(x2, y2); 245 device.sync(); 246 TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x1, y1); 247 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2); 248 // drag both fingers 249 device.setPoint(p1, x1 + dx, y1); 250 device.setPoint(p2, x2 + dx, y2); 251 device.sync(); 252 TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1 + dx, y1); 253 TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2 + dx, y2); 254 255 // release first finger 256 TestLog.reset(); 257 device.removePoint(p1); 258 device.sync(); 259 TestLog.waitForLogContaining("Touch released: %d, %d", x1 + dx, y1); 260 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x1 + dx, y1); 261 TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2 + dx, y2); 262 // release second finger 263 TestLog.reset(); 264 device.removePoint(p2); 265 device.sync(); 266 TestLog.waitForLogContaining("Touch released: %d, %d", x2 + dx, y2); 267 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x2 + dx, y2); 268 269 // tap 270 int p3 = device.addPoint(x1, y1 + dy); 271 device.sync(); 272 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1 + dy); 273 // release 274 device.removePoint(p3); 275 device.sync(); 276 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x1, y1 + dy); 277 } 278 279 @Test 280 public void twoFingersPressDragOne() throws Exception { 281 int delta = device.getTapRadius() + 1; 282 TestLog.reset(); 283 int x1 = (int) Math.round(width * 0.2); 284 int y1 = (int) Math.round(height * 0.2); 285 int x2 = (int) Math.round(width * 0.5); 286 int y2 = (int) Math.round(height * 0.5); 287 288 //press two fingers 289 int p1 = device.addPoint(x1, y1); 290 int p2 = device.addPoint(x2, y2); 291 device.sync(); 292 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1); 293 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2); 294 295 //drag second finger only 296 TestLog.reset(); 297 for (int i = 1; i < 4; i++) { 298 x2 += delta; 299 device.setPoint(p2, x2, y2); 300 device.sync(); 301 TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, y2); 302 } 303 304 TestLog.reset(); 305 device.removePoint(p1); 306 device.removePoint(p2); 307 device.sync(); 308 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x1, y1); 309 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x2, y2); 310 311 //press one finger 312 TestLog.reset(); 313 int p3 = device.addPoint(x1, y1); 314 device.sync(); 315 TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1); 316 TestLog.waitForLogContaining("Mouse pressed: %d, %d", x1, y1); 317 TestLog.waitForLogContaining("Touch points count: [1]"); 318 319 //release finger 320 device.removePoint(p3); 321 device.sync(); 322 TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x1, y1); 323 TestLog.waitForLogContaining("Mouse released: %d, %d", x1, y1); 324 TestLog.waitForLogContaining("Mouse clicked: %d, %d", x1, y1); 325 } 326 }