1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 package org.mozilla.gecko.tests;
6 
7 import org.mozilla.gecko.Actions;
8 import org.mozilla.gecko.PaintedSurface;
9 
10 /**
11  * Basic test for axis locking behaviour.
12  * - Load page and verify it draws
13  * - Drag page upwards 100 pixels at a 5-degree angle off the vertical axis
14  * - Verify that the 5-degree angle was thrown out and it dragged vertically
15  * - Drag page upwards at a 45-degree angle
16  * - Verify that the 45-degree angle was not thrown out and it dragged diagonally
17  */
18 public class testAxisLocking extends PixelTest {
testAxisLocking()19     public void testAxisLocking() {
20         String url = getAbsoluteUrl(mStringHelper.ROBOCOP_BOXES_URL);
21 
22         MotionEventHelper meh = new MotionEventHelper(getInstrumentation(), mDriver.getGeckoLeft(), mDriver.getGeckoTop());
23 
24         blockForGeckoReady();
25 
26         // load page and check we're at 0,0
27         loadAndVerifyBoxes(url);
28 
29         // drag page upwards by 100 pixels with a slight angle. verify that
30         // axis locking prevents any horizontal scrolling
31         Actions.RepeatedEventExpecter paintExpecter = mActions.expectPaint();
32         meh.dragSync(20, 150, 10, 50);
33         PaintedSurface painted = waitForPaint(paintExpecter);
34         paintExpecter.unregisterListener();
35         try {
36             checkScrollWithBoxes(painted, 0, 100);
37             // since checkScrollWithBoxes only checks 4 points, it may not pick up a
38             // sub-100 pixel horizontal shift. so we check another point manually to make sure.
39             int[] color = getBoxColorAt(0, 100);
40             mAsserter.ispixel(painted.getPixelAt(99, 0), color[0], color[1], color[2], "Pixel at 99, 0 indicates no horizontal scroll");
41 
42             // now drag at a 45-degree angle to ensure we break the axis lock, and
43             // verify that we have both horizontal and vertical scrolling
44             paintExpecter = mActions.expectPaint();
45             meh.dragSync(150, 150, 50, 50);
46         } finally {
47             painted.close();
48         }
49 
50         painted = waitForPaint(paintExpecter);
51         paintExpecter.unregisterListener();
52         try {
53             checkScrollWithBoxes(painted, 100, 200);
54         } finally {
55             painted.close();
56         }
57     }
58 }
59