mobile/android/base/tests/testAxisLocking.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testAxisLocking.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import org.mozilla.gecko.Actions;
     1.7 +import org.mozilla.gecko.PaintedSurface;
     1.8 +
     1.9 +/**
    1.10 + * Basic test for axis locking behaviour.
    1.11 + * - Load page and verify it draws
    1.12 + * - Drag page upwards 100 pixels at a 5-degree angle off the vertical axis
    1.13 + * - Verify that the 5-degree angle was thrown out and it dragged vertically
    1.14 + * - Drag page upwards at a 45-degree angle
    1.15 + * - Verify that the 45-degree angle was not thrown out and it dragged diagonally
    1.16 + */
    1.17 +public class testAxisLocking extends PixelTest {
    1.18 +    public void testAxisLocking() {
    1.19 +        String url = getAbsoluteUrl("/robocop/robocop_boxes.html");
    1.20 +
    1.21 +        MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
    1.22 +
    1.23 +        blockForGeckoReady();
    1.24 +
    1.25 +        // load page and check we're at 0,0
    1.26 +        loadAndVerifyBoxes(url);
    1.27 +
    1.28 +        // drag page upwards by 100 pixels with a slight angle. verify that
    1.29 +        // axis locking prevents any horizontal scrolling
    1.30 +        Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
    1.31 +        meh.dragSync(20, 150, 10, 50);
    1.32 +        PaintedSurface painted = waitForPaint(paintExpecter);
    1.33 +        paintExpecter.unregisterListener();
    1.34 +        try {
    1.35 +            checkScrollWithBoxes(painted, 0, 100);
    1.36 +            // since checkScrollWithBoxes only checks 4 points, it may not pick up a
    1.37 +            // sub-100 pixel horizontal shift. so we check another point manually to make sure.
    1.38 +            int[] color = getBoxColorAt(0, 100);
    1.39 +            mAsserter.ispixel(painted.getPixelAt(99, 0), color[0], color[1], color[2], "Pixel at 99, 0 indicates no horizontal scroll");
    1.40 +
    1.41 +            // now drag at a 45-degree angle to ensure we break the axis lock, and
    1.42 +            // verify that we have both horizontal and vertical scrolling
    1.43 +            paintExpecter = mActions.expectPaint();
    1.44 +            meh.dragSync(150, 150, 50, 50);
    1.45 +        } finally {
    1.46 +            painted.close();
    1.47 +        }
    1.48 +
    1.49 +        painted = waitForPaint(paintExpecter);
    1.50 +        paintExpecter.unregisterListener();
    1.51 +        try {
    1.52 +            checkScrollWithBoxes(painted, 100, 200);
    1.53 +        } finally {
    1.54 +            painted.close();
    1.55 +        }
    1.56 +    }
    1.57 +}

mercurial