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