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.TestLogShim; 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 org.junit.After; 33 import org.junit.Assert; 34 import org.junit.Assume; 35 import org.junit.Before; 36 import org.junit.runners.Parameterized; 37 38 import java.util.Collection; 39 40 /** 41 * Base class, intended for extending and creation of different types of scroll tests 42 * */ 43 public abstract class ScrollTestBase extends ParameterizedTestBase { 44 45 protected int point1X; 46 protected int point1Y; 47 protected int point2X; 48 protected int point2Y; 49 protected int p1; 50 protected int p2; 51 protected int totalDeltaX = 0; 52 protected int totalDeltaY = 0; 53 54 public ScrollTestBase(TestTouchDevice device) { 55 super(device); 56 } 57 58 @Parameterized.Parameters 59 public static Collection<Object[]> data() { 60 return TestTouchDevices.getTouchDeviceParameters(1); 61 } 62 63 @Before 64 public void init() { 65 Assume.assumeTrue(TestApplication.isMonocle()); 66 //Scroll tests should be running only on platforms that support current feature 67 Assume.assumeTrue(Boolean.getBoolean("com.sun.javafx.gestures.scroll")); 68 point1X = (int) Math.round(width * 0.5); 69 point1Y = (int) Math.round(height * 0.5); 70 point2X = point1X + 40; 71 point2Y = point1Y; 72 } 73 74 @After 75 public void releaseAll() throws Exception { 76 if (device.getPressedPoints() == 1) { 77 releaseFirstFinger(); 78 } else if (device.getPressedPoints() == 2){ 79 releaseAllFingers(); 80 } 81 } 82 83 protected int getScrollThreshold() { 84 String s = System.getProperty("com.sun.javafx.gestures.scroll.threshold"); 85 if (s != null) { 86 return Integer.valueOf(s); 87 } else { 88 return 10; 89 } 90 } 91 92 protected boolean paramsValid(int dX, int dY, int num, int x, int y) { 93 if ((0 < x + (dX * num)) 94 && (x + (dX * num) < (int) Math.round(width)) 95 && (0 < y + (dY * num)) 96 && (y + (dY * num) < (int) Math.round(height))) { 97 return true; 98 } else { 99 return false; 100 } 101 } 102 103 protected void pressFirstFinger() throws Exception { 104 Assert.assertEquals(0, device.getPressedPoints()); 105 TestLogShim.reset(); 106 p1 = device.addPoint(point1X, point1Y); 107 device.sync(); 108 TestLogShim.waitForLogContaining("TouchPoint: PRESSED %d, %d", point1X, point1Y); 109 } 110 111 protected void pressSecondFinger() throws Exception { 112 Assert.assertEquals(1, device.getPressedPoints()); 113 TestLogShim.reset(); 114 point2X = point1X + 40; 115 point2Y = point1Y; 116 p2 = device.addPoint(point2X, point2Y); 117 device.sync(); 118 //verify fingers pressed 119 TestLogShim.waitForLogContaining("TouchPoint: STATIONARY %d, %d", 120 point1X, point1Y); 121 TestLogShim.waitForLogContaining("TouchPoint: PRESSED %d, %d", 122 point2X, point2Y); 123 } 124 125 /** 126 * The method drags one finger 127 * @param firstMove - reflects if it's the first action in the drag sequence. 128 */ 129 protected void moveOneFinger(int deltaX, int deltaY, int numOfIterations, 130 boolean firstMove) throws Exception { 131 TestLogShim.reset(); 132 Assert.assertEquals(1, device.getPressedPoints()); 133 Assert.assertTrue(paramsValid(deltaX, deltaY, numOfIterations, 134 point1X, point1Y)); 135 point1X += deltaX; 136 point1Y += deltaY; 137 device.setPoint(p1, point1X, point1Y); 138 device.sync(); 139 TestLogShim.waitForLogContaining("TouchPoint: MOVED %d, %d", point1X, 140 point1Y); 141 if (firstMove) { 142 totalDeltaX = deltaX; 143 totalDeltaY = deltaY; 144 if (Math.abs(deltaX) > getScrollThreshold() 145 || Math.abs(deltaY) > getScrollThreshold()) { 146 TestLogShim.waitForLogContaining("Scroll started, DeltaX: " + 0 147 + ", DeltaY: " + 0 148 + ", totalDeltaX: " + 0 149 + ", totalDeltaY: " + 0 150 + ", touch points: " + 1 151 + ", inertia value: false"); 152 TestLogShim.waitForLogContaining("Scroll, DeltaX: " + deltaX 153 + ", DeltaY: " + deltaY 154 + ", totalDeltaX: " + totalDeltaX 155 + ", totalDeltaY: " + totalDeltaY 156 + ", touch points: " + 1 157 + ", inertia value: false"); 158 } else { 159 Assert.assertEquals(0, TestLogShim.countLogContaining("Scroll started")); 160 Assert.assertEquals(0, TestLogShim.countLogContaining("Scroll, DeltaX:")); 161 } 162 } else { 163 totalDeltaX += deltaX; 164 totalDeltaY += deltaY; 165 TestLogShim.waitForLogContaining("Scroll, DeltaX: " + deltaX 166 + ", DeltaY: " + deltaY 167 + ", totalDeltaX: " + totalDeltaX 168 + ", totalDeltaY: " + totalDeltaY 169 + ", touch points: " + 1 170 + ", inertia value: false"); 171 } 172 String expectedLog; 173 boolean passedTheThreshold =false; 174 if (numOfIterations >= 2) { 175 for (int i = 2; i <= numOfIterations; i++) { 176 point1X += deltaX; 177 point1Y += deltaY; 178 TestLogShim.reset(); 179 device.setPoint(p1, point1X, point1Y); 180 device.sync(); 181 TestLogShim.waitForLogContaining("TouchPoint: MOVED %d, %d", 182 point1X, point1Y); 183 totalDeltaX += deltaX; 184 totalDeltaY += deltaY; 185 expectedLog = "Scroll, DeltaX: " + deltaX + ", DeltaY: " + deltaY 186 + ", totalDeltaX: " + totalDeltaX 187 + ", totalDeltaY: " + totalDeltaY 188 + ", touch points: " + 1 189 + ", inertia value: false"; 190 if (Math.abs(deltaX) < getScrollThreshold() 191 && Math.abs(deltaY) < getScrollThreshold()) { 192 if(Math.abs(totalDeltaX) > getScrollThreshold() 193 || Math.abs(totalDeltaY) > getScrollThreshold()) { 194 if (!passedTheThreshold) { 195 expectedLog = "Scroll, DeltaX: " + totalDeltaX 196 + ", DeltaY: " + totalDeltaY 197 + ", totalDeltaX: " + totalDeltaX 198 + ", totalDeltaY: " + totalDeltaY 199 + ", touch points: " + 1 200 + ", inertia value: false"; 201 passedTheThreshold = true; 202 } 203 } else { 204 expectedLog = "sync"; 205 } 206 } 207 TestLogShim.waitForLogContaining(expectedLog); 208 } 209 } 210 } 211 212 /** 213 * The method drags two-fingers 214 * @param firstMove - reflects if it's the first action in the drag sequence. 215 * @param fingersChanged - reflects if previous move/drag action used 216 * different number of touch-points 217 */ 218 protected void moveTwoFingers(int deltaX, int deltaY, int numOfIterations, 219 boolean firstMove, boolean fingersChanged) 220 throws Exception { 221 TestLogShim.reset(); 222 Assert.assertEquals(2, device.getPressedPoints()); 223 Assert.assertTrue(paramsValid(deltaX, deltaY, numOfIterations, 224 point1X, point1Y) && paramsValid(deltaX, deltaY, numOfIterations, 225 point2X, point2Y)); 226 point1X += deltaX; 227 point1Y += deltaY; 228 point2X += deltaX; 229 point2Y += deltaY; 230 device.setPoint(p1, point1X, point1Y); 231 device.setPoint(p2, point2X, point2Y); 232 device.sync(); 233 TestLogShim.waitForLogContaining("TouchPoint: MOVED %d, %d", point1X, point1Y); 234 TestLogShim.waitForLogContaining("TouchPoint: MOVED %d, %d", point2X, point2Y); 235 boolean passedTheThreshold = false; 236 if (firstMove) { 237 totalDeltaX = deltaX; 238 totalDeltaY = deltaY; 239 if (Math.abs(deltaX) > getScrollThreshold() 240 || Math.abs(deltaY) > getScrollThreshold()) { 241 TestLogShim.waitForLogContaining("Scroll started, DeltaX: " + 0 242 + ", DeltaY: " + 0 243 + ", totalDeltaX: " + 0 244 + ", totalDeltaY: " + 0 245 + ", touch points: " + 2 246 + ", inertia value: false"); 247 TestLogShim.waitForLogContaining("Scroll, DeltaX: " + deltaX 248 + ", DeltaY: " + deltaY 249 + ", totalDeltaX: " + totalDeltaX 250 + ", totalDeltaY: " + totalDeltaY 251 + ", touch points: " + 2 252 + ", inertia value: false"); 253 } else { 254 Assert.assertEquals(0, TestLogShim.countLogContaining("Scroll " + 255 "started")); 256 Assert.assertEquals(0, TestLogShim.countLogContaining("Scroll, DeltaX:")); 257 } 258 } else { 259 if (fingersChanged) { 260 totalDeltaX = deltaX; 261 totalDeltaY = deltaY; 262 } else { 263 totalDeltaX += deltaX; 264 totalDeltaY += deltaY; 265 } 266 TestLogShim.waitForLogContaining("Scroll, DeltaX: " + deltaX 267 + ", DeltaY: " + deltaY 268 + ", totalDeltaX: " + totalDeltaX 269 + ", totalDeltaY: " + totalDeltaY 270 + ", touch points: " + 2 271 + ", inertia value: false"); 272 passedTheThreshold = true; 273 } 274 String expectedLog; 275 if (numOfIterations >= 2) { 276 for (int i = 2; i <= numOfIterations; i++) { 277 point1X += deltaX; 278 point1Y += deltaY; 279 point2X += deltaX; 280 point2Y += deltaY; 281 TestLogShim.reset(); 282 device.setPoint(p1, point1X, point1Y); 283 device.setPoint(p2, point2X, point2Y); 284 device.sync(); 285 TestLogShim.waitForLogContaining("TouchPoint: MOVED %d, %d", 286 point1X, point1Y); 287 TestLogShim.waitForLogContaining("TouchPoint: MOVED %d, %d", 288 point2X, point2Y); 289 totalDeltaX += deltaX; 290 totalDeltaY += deltaY; 291 expectedLog = "Scroll, DeltaX: " + deltaX + ", DeltaY: " + deltaY 292 + ", totalDeltaX: " + totalDeltaX 293 + ", totalDeltaY: " + totalDeltaY 294 + ", touch points: " + 2 295 + ", inertia value: false"; 296 if (firstMove && Math.abs(deltaX) < getScrollThreshold() 297 && Math.abs(deltaY) < getScrollThreshold()) { 298 if(Math.abs(totalDeltaX) > getScrollThreshold() 299 || Math.abs(totalDeltaY) > getScrollThreshold()) { 300 if (!passedTheThreshold) { 301 expectedLog = "Scroll, DeltaX: " + totalDeltaX 302 + ", DeltaY: " + totalDeltaY 303 + ", totalDeltaX: " + totalDeltaX 304 + ", totalDeltaY: " + totalDeltaY 305 + ", touch points: " + 2 306 + ", inertia value: false"; 307 passedTheThreshold = true; 308 } 309 } else { 310 expectedLog = "sync"; 311 } 312 } 313 TestLogShim.waitForLogContaining(expectedLog); 314 } 315 } 316 } 317 318 /** 319 * The method releases one finger that is currently pressing on the screen 320 */ 321 protected void releaseFirstFinger() throws Exception { 322 Assert.assertEquals(1, device.getPressedPoints()); 323 String expectedLog; 324 TestLogShim.reset(); 325 device.removePoint(p1); 326 device.sync(); 327 //verify finger release 328 int expectedValue = 0; 329 expectedLog = "Scroll finished, DeltaX: " + 0 330 + ", DeltaY: " + 0 331 + ", totalDeltaX: " + totalDeltaX 332 + ", totalDeltaY: " + totalDeltaY 333 + ", touch points: " + 1 334 + ", inertia value: false"; 335 TestLogShim.waitForLogContaining("TouchPoint: RELEASED %d, %d", 336 point1X, point1Y); 337 if (Math.abs(totalDeltaX) > getScrollThreshold() 338 || Math.abs(totalDeltaY) > getScrollThreshold()) { 339 expectedValue = 1; 340 TestLogShim.waitForLogContaining(expectedLog); 341 } 342 totalDeltaX = 0; 343 totalDeltaY = 0; 344 Assert.assertEquals(expectedValue, TestLogShim.countLogContaining(expectedLog)); 345 if (TestLogShim.countLogContaining("Scroll finished") > 0) { 346 TestLogShim.waitForLogContainingSubstrings("Scroll", "inertia value: true"); 347 } 348 } 349 350 /** 351 * The method releases second of two fingers that are currently 352 * pressing on the screen 353 */ 354 protected void releaseSecondFinger() throws Exception { 355 Assert.assertEquals(2, device.getPressedPoints()); 356 String expectedLog; 357 TestLogShim.reset(); 358 device.removePoint(p2); 359 device.sync(); 360 //verify finger release 361 int expectedValue = 0; 362 expectedLog = "Scroll finished, DeltaX: " + 0 363 + ", DeltaY: " + 0 364 + ", totalDeltaX: " + totalDeltaX 365 + ", totalDeltaY: " + totalDeltaY 366 + ", touch points: " + 2 367 + ", inertia value: false"; 368 TestLogShim.waitForLogContaining("TouchPoint: RELEASED %d, %d", 369 point2X, point2Y); 370 if (Math.abs(totalDeltaX) > getScrollThreshold() 371 || Math.abs(totalDeltaY) > getScrollThreshold()) { 372 expectedValue = 1; 373 TestLogShim.waitForLogContaining(expectedLog); 374 } 375 totalDeltaX = 0; 376 totalDeltaY = 0; 377 Assert.assertEquals(expectedValue, TestLogShim.countLogContaining(expectedLog)); 378 } 379 380 /** 381 * The method releases two fingers that are currently pressing on the screen 382 */ 383 protected void releaseAllFingers() throws Exception { 384 Assert.assertEquals(2, device.getPressedPoints()); 385 String expectedLog; 386 TestLogShim.reset(); 387 device.removePoint(p1); 388 device.removePoint(p2); 389 device.sync(); 390 //verify finger release 391 int expectedValue = 0; 392 expectedLog = "Scroll finished, DeltaX: " + 0 393 + ", DeltaY: " + 0 394 + ", totalDeltaX: " + totalDeltaX 395 + ", totalDeltaY: " + totalDeltaY 396 + ", touch points: " + 2 397 + ", inertia value: false"; 398 TestLogShim.waitForLogContaining("TouchPoint: RELEASED %d, %d", point1X, point1Y); 399 TestLogShim.waitForLogContaining("TouchPoint: RELEASED %d, %d", point2X, point2Y); 400 if (Math.abs(totalDeltaX) > getScrollThreshold() || 401 Math.abs(totalDeltaY) > getScrollThreshold()) { 402 expectedValue = 1; 403 TestLogShim.waitForLogContaining(expectedLog); 404 } 405 totalDeltaX = 0; 406 totalDeltaY = 0; 407 Assert.assertEquals(expectedValue, TestLogShim.countLogContaining(expectedLog)); 408 if (TestLogShim.countLogContaining("Scroll finished") > 0) { 409 TestLogShim.waitForLogContainingSubstrings("Scroll", "inertia value: true"); 410 } 411 } 412 413 protected void tapToStopInertia() throws Exception { 414 Assert.assertEquals(0, device.getPressedPoints()); 415 TestLogShim.reset(); 416 int p = device.addPoint(point1X, point1Y); 417 device.sync(); 418 device.removePoint(p); 419 device.sync(); 420 TestLogShim.waitForLogContaining("TouchPoint: RELEASED %d, %d", point1X, point1Y); 421 } 422 }