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.*;
  31 import org.junit.runners.Parameterized;
  32 
  33 import java.util.Collection;
  34 
  35 /** Zoom tests with two touch points */
  36 public class ZoomTest extends ParameterizedTestBase {
  37 
  38     public ZoomTest(TestTouchDevice device) {
  39         super(device);
  40     }
  41 
  42     @Parameterized.Parameters
  43     public static Collection<Object[]> data() {
  44         return TestTouchDevices.getTouchDeviceParameters(2);
  45     }
  46 
  47     @Before
  48     public void verifyZoomEnabled() {
  49         Assume.assumeTrue(Boolean.getBoolean("com.sun.javafx.gestures.zoom"));
  50     }
  51 
  52     /**
  53      * Touch down two fingers,
  54      * drag upper finger up in order move but not enough for zooming,
  55      * drag again to zoom in (make it twice bigger)
  56      */
  57     @Ignore("RT-37942")
  58     @Test
  59     public void testZoomInSmallStepBigStep() throws Exception {
  60         int x1 = (int) Math.round(width / 2);
  61         int y1 = (int) Math.round(height * 0.3);
  62         int x2 = (int) Math.round(width / 2);
  63         int y2 = (int) Math.round(height * 0.7);
  64         int step = (int) Math.round(height * 0.1);
  65         int smallStep = (int) device.getTapRadius() + 1;
  66         double threshold = 0;
  67         String s = System.getProperty("com.sun.javafx.gestures.zoom.threshold");
  68         if (s != null) {
  69             threshold = Double.valueOf(s);
  70         } else {
  71             threshold = 0.1;
  72         }
  73         Assume.assumeTrue(((y2 - y1) * threshold) > smallStep);
  74 
  75         TestLog.reset();
  76         //tap two fingers
  77         int p1 = device.addPoint(x1, y1);
  78         int p2 = device.addPoint(x2, y2);
  79         device.sync();
  80 
  81         //verify pressing two fingers
  82         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1);
  83         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2);
  84 
  85         //drag upper finger up in order move but not enough for zooming
  86         int newy1 = y1 - smallStep;
  87         int newy2 = 0;
  88         TestLog.reset();
  89         device.setPoint(p1, x1, newy1);
  90         device.sync();
  91 
  92         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
  93         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2, y2);
  94         Assert.assertEquals(0, TestLog.countLogContaining("Zoom started"));
  95 
  96         //drag upper finger up and lower down in order to zoom in
  97         newy1 = y1 - step;
  98         newy2 = y2 + step;
  99         TestLog.reset();
 100         device.setPoint(p1, x1, newy1);
 101         device.setPoint(p2, x2, newy2);
 102         device.sync();
 103         double factor0 = 1.0;
 104         double factor1 = (double) (newy2 - newy1)/(y2 - y1);
 105 
 106         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 107         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 108         TestLog.waitForLogContaining("Zoom started, factor: " + factor0
 109                 + ", total factor: " + factor0  + ", inertia value: false");
 110         TestLog.waitForLogContaining("Zoom, factor: " + factor1
 111                 + ", total factor: " + factor1 + ", inertia value: false");
 112 
 113         step = step * 2;
 114         newy1 = y1 - step;
 115         newy2 = y2 + step;
 116         TestLog.reset();
 117         device.setPoint(p1, x1, newy1);
 118         device.setPoint(p2, x2, newy2);
 119         device.sync();
 120         double factor2 = (double) (newy2 - newy1)/(y2 - y1 + step);
 121 
 122         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 123         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 124         TestLog.waitForLogContaining("Zoom, factor: " + factor2
 125                 + ", total factor: " + (factor1 * factor2)
 126                 + ", inertia value: false");
 127 
 128         //release first finger
 129         TestLog.reset();
 130         device.removePoint(p1);
 131         device.sync();
 132         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x1, newy1);
 133         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2, newy2);
 134         TestLog.waitForLogContaining("Zoom finished, factor: " + factor0
 135                 + ", total factor: " + (factor1 * factor2)
 136                 + ", inertia value: false");
 137         //release second finger
 138         TestLog.reset();
 139         device.removePoint(p2);
 140         device.sync();
 141         TestLog.waitForLogContaining("Touch released: %d, %d", x2, newy2);
 142         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d", x2, newy2);
 143         TestLog.waitForLog("Mouse released: %d, %d", x2, newy2);
 144         TestLog.waitForLog("Mouse clicked: %d, %d", x2, newy2);
 145         TestLog.waitForLogContainingSubstrings("Zoom", "inertia value: true");
 146         Assert.assertEquals(1, TestLog.countLogContaining("Mouse clicked: "
 147                 + x2 +", " + newy2));
 148     }
 149 
 150     /**
 151      * Touch down two fingers, zoom in (make it twice bigger)
 152      */
 153     @Ignore("RT-37942")
 154     @Test
 155     public void testZoomIn() throws Exception {
 156         int x1 = (int) Math.round(width / 2);
 157         int y1 = (int) Math.round(height * 0.3);
 158         int x2 = (int) Math.round(width / 2);
 159         int y2 = (int) Math.round(height * 0.7);
 160         int step = (int) Math.round(height * 0.1);
 161 
 162         TestLog.reset();
 163         //tap two fingers
 164         int p1 = device.addPoint(x1, y1);
 165         int p2 = device.addPoint(x2, y2);
 166         device.sync();
 167 
 168         //verify pressing two fingers
 169         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1);
 170         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2);
 171 
 172         //drag upper finger up and lower down in order to zoom in
 173         int newy1 = y1 - step;
 174         int newy2 = y2 + step;
 175         TestLog.reset();
 176         device.setPoint(p1, x1, newy1);
 177         device.setPoint(p2, x2, newy2);
 178         device.sync();
 179         double factor0 = 1.0;
 180         double factor1 = (double) (newy2 - newy1)/(y2 - y1);
 181 
 182         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 183         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 184         TestLog.waitForLogContaining("Zoom started, factor: " + factor0
 185                 + ", total factor: " + factor0 + ", inertia value: false");
 186         TestLog.waitForLogContaining("Zoom, factor: " + factor1
 187                 + ", total factor: " + factor1  + ", inertia value: false");
 188 
 189         step = step * 2;
 190         newy1 = y1 - step;
 191         newy2 = y2 + step;
 192         TestLog.reset();
 193         device.setPoint(p1, x1, newy1);
 194         device.setPoint(p2, x2, newy2);
 195         device.sync();
 196         double factor2 = (double) (newy2 - newy1)/(y2 - y1 + step);
 197 
 198         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 199         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 200         TestLog.waitForLogContaining("Zoom, factor: " + factor2
 201                 + ", total factor: " + (factor1 * factor2)
 202                 + ", inertia value: false");
 203 
 204         //release first finger
 205         TestLog.reset();
 206         device.removePoint(p1);
 207         device.sync();
 208         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 209                 x1, newy1);
 210         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d",
 211                 x2, newy2);
 212         TestLog.waitForLogContaining("Zoom finished, factor: " + factor0
 213                 + ", total factor: " + (factor1 * factor2)
 214                 + ", inertia value: false");
 215 
 216         //release second finger
 217         TestLog.reset();
 218         device.removePoint(p2);
 219         device.sync();
 220         TestLog.waitForLogContaining("Touch released: %d, %d", x2, newy2);
 221         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 222                 x2, newy2);
 223         TestLog.waitForLog("Mouse released: %d, %d", x2, newy2);
 224         TestLog.waitForLog("Mouse clicked: %d, %d", x2, newy2);
 225         TestLog.waitForLogContainingSubstrings("Zoom", "inertia value: true");
 226         Assert.assertEquals(1, TestLog.countLogContaining("Mouse clicked: "
 227                 + x2 +", " + newy2));
 228     }
 229 
 230     /**
 231      * Touch down two fingers, zoom out (make it quarter of original size)
 232      */
 233     @Ignore("RT-37942")
 234     @Test
 235     public void testZoomOut() throws Exception {
 236         int x1 = (int) Math.round(width / 2);
 237         int y1 = (int) Math.round(height * 0.1);
 238         int x2 = (int) Math.round(width / 2);
 239         int y2 = (int) Math.round(height * 0.9);
 240         int step = (int) Math.round(height * 0.1);
 241         double factor0 = 1.0;
 242 
 243         //tap two fingers
 244         TestLog.reset();
 245         int p1 = device.addPoint(x1, y1);
 246         int p2 = device.addPoint(x2, y2);
 247         device.sync();
 248 
 249         //verify pressing two fingers
 250         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1);
 251         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2);
 252 
 253         //drag upper finger down and lower - up, in order to zoom out
 254         TestLog.reset();
 255         int newy1 = y1 + step;
 256         int newy2 = y2 - step;
 257         device.setPoint(p1, x1, newy1);
 258         device.setPoint(p2, x2, newy2);
 259         device.sync();
 260         double factor1 = (double) (newy2 - newy1)/(y2 - y1);
 261 
 262         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 263         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 264         TestLog.waitForLogContaining("Zoom started, factor: " + factor0
 265                 + ", total factor: " + factor0 + ", inertia value: false");
 266         TestLog.waitForLogContaining("Zoom, factor: " + factor1
 267                 + ", total factor: " + factor1 + ", inertia value: false");
 268 
 269         TestLog.reset();
 270         y1 = y1 + step;
 271         y2 = y2 - step;
 272         newy1 = y1 + step;
 273         newy2 = y2 - step;
 274 
 275         device.setPoint(p1, x1, newy1);
 276         device.setPoint(p2, x2, newy2);
 277         device.sync();
 278         double factor2 = (double) (newy2 - newy1)/(y2 - y1);
 279 
 280         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 281         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 282         TestLog.waitForLogContaining("Zoom, factor: " + factor2
 283                 + ", total factor: " + (factor1 * factor2)
 284                 + ", inertia value: false");
 285 
 286         TestLog.reset();
 287         y1 = y1 + step;
 288         y2 = y2 - step;
 289         newy1 = y1 + step;
 290         newy2 = y2 - step;
 291 
 292         device.setPoint(p1, x1, newy1);
 293         device.setPoint(p2, x2, newy2);
 294         device.sync();
 295         double factor3 = (double) (newy2 - newy1)/(y2 - y1);
 296 
 297         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 298         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 299         TestLog.waitForLogContaining("Zoom, factor: " + factor3
 300                 + ", total factor: " + (factor1 * factor2 * factor3)
 301                 + ", inertia value: false");
 302 
 303         //release first finger
 304         TestLog.reset();
 305         device.removePoint(p1);
 306         device.sync();
 307         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 308                 x1, newy1);
 309         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d",
 310                 x2, newy2);
 311         TestLog.waitForLogContaining("Zoom finished, factor: " + factor0
 312                 + ", total factor: " + (factor1 * factor2 * factor3)
 313                 + ", inertia value: false");
 314 
 315         //release second finger
 316         TestLog.reset();
 317         device.removePoint(p2);
 318         device.sync();
 319         TestLog.waitForLogContaining("Touch released: %d, %d", x2, newy2);
 320         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 321                 x2, newy2);
 322         TestLog.waitForLog("Mouse released: %d, %d", x2, newy2);
 323         TestLog.waitForLog("Mouse clicked: %d, %d", x2, newy2);
 324         TestLog.waitForLogContainingSubstrings("Zoom", "inertia value: true");
 325         Assert.assertEquals(1, TestLog.countLogContaining("Mouse clicked: "
 326                 + x2 +", " + newy2));
 327     }
 328 
 329     /**
 330      * Touch down two fingers,
 331      * drag upper finger down in order move but not enough for zooming,
 332      * drag again to zoom out (quarter of original size)
 333      */
 334     @Ignore("RT-37942")
 335     @Test
 336     public void testZoomOutSmallStepBigStep() throws Exception {
 337         int x1 = (int) Math.round(width / 2);
 338         int y1 = (int) Math.round(height * 0.1);
 339         int x2 = (int) Math.round(width / 2);
 340         int y2 = (int) Math.round(height * 0.9);
 341         int step = (int) Math.round(height * 0.1);
 342         int smallStep = (int) device.getTapRadius() + 1;
 343         double threshold = 0;
 344         String s = System.getProperty("com.sun.javafx.gestures.zoom.threshold");
 345         if (s != null) {
 346             threshold = Double.valueOf(s);
 347         } else {
 348             threshold = 0.1;
 349         }
 350         Assume.assumeTrue(((y2 - y1) * threshold) > smallStep);
 351         double factor0 = 1.0;
 352 
 353         TestLog.reset();
 354         //tap two fingers
 355         int p1 = device.addPoint(x1, y1);
 356         int p2 = device.addPoint(x2, y2);
 357         device.sync();
 358 
 359         //verify pressing two fingers
 360         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x1, y1);
 361         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", x2, y2);
 362 
 363         //drag upper finger down in order move but not enough for zooming
 364         TestLog.reset();
 365         int newy1 = y1 + smallStep;
 366         int newy2 = 0;
 367 
 368         device.setPoint(p1, x1, newy1);
 369         device.sync();
 370 
 371         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 372         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d", x2, y2);
 373         Assert.assertEquals(0, TestLog.countLogContaining("Zoom started"));
 374 
 375         //drag upper finger up and lower down in order to zoom in
 376         TestLog.reset();
 377         newy1 = y1 + step;
 378         newy2 = y2 - step;
 379         device.setPoint(p1, x1, newy1);
 380         device.setPoint(p2, x2, newy2);
 381         device.sync();
 382         double factor1 = (double) (newy2 - newy1)/(y2 - y1);
 383 
 384         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 385         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 386         TestLog.waitForLogContaining("Zoom started, factor: " + factor0
 387                 + ", total factor: " + factor0 + ", inertia value: false");
 388         TestLog.waitForLogContaining("Zoom, factor: " + factor1
 389                 + ", total factor: " + factor1 + ", inertia value: false");
 390         TestLog.reset();
 391         y1 = y1 + step;
 392         y2 = y2 - step;
 393         newy1 = y1 + step;
 394         newy2 = y2 - step;
 395         device.setPoint(p1, x1, newy1);
 396         device.setPoint(p2, x2, newy2);
 397         device.sync();
 398         double factor2 = (double) (newy2 - newy1)/(y2 - y1);
 399 
 400         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 401         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 402         TestLog.waitForLogContaining("Zoom, factor: " + factor2
 403                 + ", total factor: " + (factor1 * factor2)
 404                 + ", inertia value: false");
 405 
 406         TestLog.reset();
 407         y1 = y1 + step;
 408         y2 = y2 - step;
 409         newy1 = y1 + step;
 410         newy2 = y2 - step;
 411         device.setPoint(p1, x1, newy1);
 412         device.setPoint(p2, x2, newy2);
 413         device.sync();
 414         double factor3 = (double) (newy2 - newy1)/(y2 - y1);
 415 
 416         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x1, newy1);
 417         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", x2, newy2);
 418         TestLog.waitForLogContaining("Zoom, factor: " + factor3
 419                 + ", total factor: " + (factor1 * factor2 * factor3)
 420                 + ", inertia value: false");
 421 
 422         //release first finger
 423         TestLog.reset();
 424         device.removePoint(p1);
 425         device.sync();
 426         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 427                 x1, newy1);
 428         TestLog.waitForLogContaining("TouchPoint: STATIONARY %d, %d",
 429                 x2, newy2);
 430         TestLog.waitForLogContaining("Zoom finished, factor: " + factor0
 431                 + ", total factor: " + (factor1 * factor2 * factor3)
 432                 + ", inertia value: false");
 433 
 434         //release second finger
 435         TestLog.reset();
 436         device.removePoint(p2);
 437         device.sync();
 438         TestLog.waitForLogContaining("Touch released: %d, %d", x2, newy2);
 439         TestLog.waitForLogContaining("TouchPoint: RELEASED %d, %d",
 440                 x2, newy2);
 441         TestLog.waitForLog("Mouse released: %d, %d", x2, newy2);
 442         TestLog.waitForLog("Mouse clicked: %d, %d", x2, newy2);
 443         TestLog.waitForLogContainingSubstrings("Zoom", "inertia value: true");
 444         Assert.assertEquals(1, TestLog.countLogContaining("Mouse clicked: "
 445                 + x2 +", " + newy2));
 446     }
 447 }