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.ScrollTestBase;
  30 import test.robot.com.sun.glass.ui.monocle.input.devices.TestTouchDevice;
  31 import org.junit.Assert;
  32 import org.junit.Assume;
  33 import org.junit.Test;
  34 
  35 /**
  36  * Scroll tests generated by one and more touch points.
  37  *  */
  38 public class ScrollTest extends ScrollTestBase {
  39 
  40     public ScrollTest(TestTouchDevice device) {
  41         super(device);
  42     }
  43 
  44     private int getDelta() throws Exception {
  45         int max = Math.max(getScrollThreshold(), device.getTapRadius());
  46         return Math.max(max, 30) + 1;
  47     }
  48 
  49     /**
  50      * Tap one finger, drag it up few times in order to scroll
  51      */
  52     @Test
  53     public void testScrollUp() throws Exception {
  54         pressFirstFinger();
  55         moveOneFinger(0, -getDelta(), 3, true);
  56         releaseFirstFinger();
  57     }
  58 
  59     /**
  60      * Tap one finger, drag it to the right few times in order to scroll
  61      */
  62     @Test
  63     public void testScrollRight() throws Exception {
  64         pressFirstFinger();
  65         moveOneFinger(getDelta(), 0, 2, true);
  66         releaseFirstFinger();
  67     }
  68 
  69     /**
  70      * Tap one finger, drag it down few times in order to scroll
  71      */
  72     @Test
  73     public void testScrollDown() throws Exception {
  74         pressFirstFinger();
  75         moveOneFinger(0, getDelta(), 5, true);
  76         releaseFirstFinger();
  77     }
  78 
  79     /**
  80      * Tap one finger, drag it to the left few times in order to scroll
  81      */
  82     @Test
  83     public void testScrollLeft() throws Exception {
  84         pressFirstFinger();
  85         moveOneFinger(-getDelta() * 2, 0, 4, true);
  86         releaseFirstFinger();
  87     }
  88 
  89     /**
  90      * Tap one finger, drag it up & right few times in order to scroll
  91      */
  92     @Test
  93     public void testScrollUpAndRight() throws Exception {
  94         pressFirstFinger();
  95         moveOneFinger(getDelta(), -getDelta(), 3, true);
  96         releaseFirstFinger();
  97     }
  98 
  99     /**
 100      * Tap one finger, drag it down & right few times in order to scroll
 101      */
 102     @Test
 103     public void testScrollDownAndRight() throws Exception {
 104         pressFirstFinger();
 105         moveOneFinger(getDelta(), getDelta(), 2, true);
 106         releaseFirstFinger();
 107     }
 108 
 109     /**
 110      * Tap one finger, drag it left & down few times in order to scroll
 111      */
 112     @Test
 113     public void testScrollDownAndLeft() throws Exception {
 114         pressFirstFinger();
 115         moveOneFinger(-getDelta(), getDelta(), 5, true);
 116         releaseFirstFinger();
 117     }
 118 
 119     /**
 120      * Tap one finger, drag it left & up few times in order to scroll
 121      */
 122     @Test
 123     public void testScrollUpAndLeft() throws Exception {
 124         pressFirstFinger();
 125         moveOneFinger(-getDelta(), -getDelta() * 2, 4, true);
 126         releaseFirstFinger();
 127     }
 128 
 129     /**
 130      * Tap two fingers, scroll up
 131      */
 132     @Test
 133     public void testTwoFingersScrollUp() throws Exception {
 134         Assume.assumeTrue(device.getPointCount() >= 2);
 135         pressFirstFinger();
 136         pressSecondFinger();
 137         moveTwoFingers(0, -getDelta(), 3, true, false);
 138         releaseAllFingers();
 139     }
 140 
 141     /**
 142      * Tap two fingers, scroll up, scroll down
 143      */
 144     @Test
 145     public void testTwoFingersScrollTwice() throws Exception {
 146         Assume.assumeTrue(device.getPointCount() >= 2);
 147         pressFirstFinger();
 148         pressSecondFinger();
 149         moveTwoFingers(0, -getDelta(), 1, true, false);
 150         moveTwoFingers(0, getDelta() * 2, 1, false, false);
 151         releaseAllFingers();
 152     }
 153 
 154     /**
 155      * Tap one finger, scroll down, add second finger, continue scrolling down
 156      */
 157     @Test
 158     public void testTwoFingersScroll1() throws Exception {
 159         Assume.assumeTrue(device.getPointCount() >= 2);
 160         pressFirstFinger();
 161         moveOneFinger(0, getDelta(), 2, true);
 162         pressSecondFinger();
 163         moveTwoFingers(0, getDelta(), 3, false, true);
 164         releaseAllFingers();
 165     }
 166 
 167 
 168     /**
 169      * Tap two fingers, scroll down, release one finger, continue scrolling down
 170      */
 171     @Test
 172     public void testTwoFingersScroll2()
 173             throws Exception {
 174         Assume.assumeTrue(device.getPointCount() >= 2);
 175         pressFirstFinger();
 176         pressSecondFinger();
 177         moveTwoFingers(0, getDelta(), 1, true, false);
 178         releaseSecondFinger();
 179         moveOneFinger(0, getDelta(), 2, false);
 180         releaseFirstFinger();
 181     }
 182 
 183     /**
 184      * Tap one finger, scroll down,
 185      * add second finger, continue scrolling down,
 186      * remove second finger, continue scrolling down.
 187      */
 188     @Test
 189     public void testTwoFingersScroll3()
 190             throws Exception {
 191         Assume.assumeTrue(device.getPointCount() >= 2);
 192         pressFirstFinger();
 193         moveOneFinger(0, getDelta(), 2, true);
 194         pressSecondFinger();
 195         moveTwoFingers(0, -getDelta() * 2, 2, false, true);
 196         releaseSecondFinger();
 197         moveOneFinger(0, getDelta(), 2, false);
 198         releaseFirstFinger();
 199     }
 200 
 201     /**
 202      * Tap two fingers, scroll them down asymmetrically: first finger's location
 203      * changed by delta, second finger's location changed by (delta * 2)
 204      */
 205     @Test
 206     public void testTwoFingersAsymmetricScroll() throws Exception {
 207         Assume.assumeTrue(device.getPointCount() >= 2);
 208         int deltaY1 = getDelta() + 1;
 209         int deltaY2 = deltaY1 * 2;
 210         int numOfIterations = 4;
 211         Assert.assertTrue(paramsValid(0, deltaY1, numOfIterations,
 212                 point1X, point1Y) &&
 213                 paramsValid(0, deltaY2, numOfIterations,
 214                         point2X, point2Y));
 215         TestLog.reset();
 216         p1 = device.addPoint(point1X, point1Y);
 217         p2 = device.addPoint(point2X, point2Y);
 218         device.sync();
 219         //verify fingers pressed
 220         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", point1X, point1Y);
 221         TestLog.waitForLogContaining("TouchPoint: PRESSED %d, %d", point2X, point2Y);
 222         point1Y += deltaY1;
 223         point2Y += deltaY2;
 224         int avgDelta = (deltaY1 + deltaY2) / 2;
 225         //scroll fingers
 226         TestLog.reset();
 227         device.setPoint(p1, point1X, point1Y);
 228         device.setPoint(p2, point2X, point2Y);
 229         device.sync();
 230         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", point1X, point1Y);
 231         TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", point2X, point2Y);
 232         totalDeltaY = avgDelta;
 233         TestLog.waitForLogContaining("Scroll started, DeltaX: " + 0
 234                 + ", DeltaY: " + 0
 235                 + ", totalDeltaX: " + 0
 236                 + ", totalDeltaY: " + 0
 237                 + ", touch points: " + 2
 238                 + ", inertia value: false");
 239         TestLog.waitForLogContaining("Scroll, DeltaX: " + 0
 240                 + ", DeltaY: " + avgDelta
 241                 + ", totalDeltaX: " + 0
 242                 + ", totalDeltaY: " + totalDeltaY
 243                 + ", touch points: " + 2
 244                 + ", inertia value: false");
 245         String expectedLog;
 246         for (int i = 2; i <= numOfIterations; i++) {
 247             point1Y += deltaY1;
 248             point2Y += deltaY2;
 249             TestLog.reset();
 250             device.setPoint(p1, point1X, point1Y);
 251             device.setPoint(p2, point2X, point2Y);
 252             device.sync();
 253             TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", point1X, point1Y);
 254             TestLog.waitForLogContaining("TouchPoint: MOVED %d, %d", point2X, point2Y);
 255             totalDeltaY = avgDelta * i;
 256             expectedLog = "Scroll, DeltaX: " + 0 + ", DeltaY: " + avgDelta
 257                     + ", totalDeltaX: " + 0
 258                     + ", totalDeltaY: " + totalDeltaY
 259                     + ", touch points: " + 2 + ", inertia value: false";
 260             TestLog.waitForLogContaining(expectedLog);
 261         }
 262         releaseAllFingers();
 263     }
 264 }