OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.os.SystemClock; | 7 import android.os.SystemClock; |
8 import android.support.test.filters.SmallTest; | 8 import android.support.test.filters.SmallTest; |
9 import android.view.InputDevice; | 9 import android.view.InputDevice; |
10 import android.view.MotionEvent; | 10 import android.view.MotionEvent; |
11 | 11 |
| 12 import org.junit.Before; |
| 13 import org.junit.Rule; |
| 14 import org.junit.Test; |
| 15 import org.junit.runner.RunWith; |
| 16 |
| 17 import org.chromium.base.test.BaseJUnit4ClassRunner; |
12 import org.chromium.base.test.util.Feature; | 18 import org.chromium.base.test.util.Feature; |
13 import org.chromium.base.test.util.UrlUtils; | 19 import org.chromium.base.test.util.UrlUtils; |
14 import org.chromium.content.browser.input.AnimationIntervalProvider; | 20 import org.chromium.content.browser.input.AnimationIntervalProvider; |
15 import org.chromium.content.browser.input.JoystickZoomProvider; | 21 import org.chromium.content.browser.input.JoystickZoomProvider; |
16 import org.chromium.content_shell_apk.ContentShellTestBase; | 22 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
17 | 23 |
18 /** | 24 /** |
19 * Tests that ContentView running inside ContentShell can be zoomed using gamepa
d joystick. | 25 * Tests that ContentView running inside ContentShell can be zoomed using gamepa
d joystick. |
20 */ | 26 */ |
21 public class ContentViewZoomingTest extends ContentShellTestBase { | 27 @RunWith(BaseJUnit4ClassRunner.class) |
| 28 public class ContentViewZoomingTest { |
| 29 @Rule |
| 30 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); |
| 31 |
22 private static final String LARGE_PAGE = UrlUtils.encodeHtmlDataUri("<html><
head>" | 32 private static final String LARGE_PAGE = UrlUtils.encodeHtmlDataUri("<html><
head>" |
23 + "<meta name=\"viewport\" content=\"width=device-width, " | 33 + "<meta name=\"viewport\" content=\"width=device-width, " |
24 + "initial-scale=2.0, minimum-scale=2.0, maximum-scale=5.0\" />" | 34 + "initial-scale=2.0, minimum-scale=2.0, maximum-scale=5.0\" />" |
25 + "<style>body { width: 5000px; height: 5000px; }</style></head>" | 35 + "<style>body { width: 5000px; height: 5000px; }</style></head>" |
26 + "<body>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</b
ody>" | 36 + "<body>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</b
ody>" |
27 + "</html>"); | 37 + "</html>"); |
28 | 38 |
29 private static class TestAnimationIntervalProvider implements AnimationInter
valProvider { | 39 private static class TestAnimationIntervalProvider implements AnimationInter
valProvider { |
30 private long mAnimationTime; | 40 private long mAnimationTime; |
31 @Override | 41 @Override |
32 public long getLastAnimationFrameInterval() { | 42 public long getLastAnimationFrameInterval() { |
33 mAnimationTime += 16; | 43 mAnimationTime += 16; |
34 return mAnimationTime; | 44 return mAnimationTime; |
35 } | 45 } |
36 } | 46 } |
37 | 47 |
38 private class TestJoystickZoomProvider extends JoystickZoomProvider { | 48 private class TestJoystickZoomProvider extends JoystickZoomProvider { |
39 TestJoystickZoomProvider(ContentViewCore cvc, AnimationIntervalProvider
intervalProvider) { | 49 TestJoystickZoomProvider(ContentViewCore cvc, AnimationIntervalProvider
intervalProvider) { |
40 super(cvc, intervalProvider); | 50 super(cvc, intervalProvider); |
41 mDeviceScaleFactor = 2.0f; | 51 mDeviceScaleFactor = 2.0f; |
42 | 52 |
43 mZoomRunnable = new Runnable() { | 53 mZoomRunnable = new Runnable() { |
44 @Override | 54 @Override |
45 public void run() {} | 55 public void run() {} |
46 }; | 56 }; |
47 } | 57 } |
48 | 58 |
49 public void animateZoomTest(final MotionEvent joystickZoomEvent, final l
ong animationTicks) | 59 public void animateZoomTest(final MotionEvent joystickZoomEvent, final l
ong animationTicks) |
50 throws Throwable { | 60 throws Throwable { |
51 runTestOnUiThread(new Runnable() { | 61 mActivityTestRule.runOnUiThread(new Runnable() { |
52 @Override | 62 @Override |
53 public void run() { | 63 public void run() { |
54 onMotion(joystickZoomEvent); | 64 onMotion(joystickZoomEvent); |
55 for (int index = 0; index < animationTicks; index++) { | 65 for (int index = 0; index < animationTicks; index++) { |
56 animateZoom(); | 66 animateZoom(); |
57 } | 67 } |
58 stop(); | 68 stop(); |
59 } | 69 } |
60 }); | 70 }); |
61 } | 71 } |
62 } | 72 } |
63 | 73 |
64 private MotionEvent simulateJoystickEvent(final float delta, final boolean i
sZoomInRequest) { | 74 private MotionEvent simulateJoystickEvent(final float delta, final boolean i
sZoomInRequest) { |
65 // Synthesize joystick motion event and send to ContentViewCore. | 75 // Synthesize joystick motion event and send to ContentViewCore. |
66 final int axisVal = | 76 final int axisVal = |
67 (isZoomInRequest) ? MotionEvent.AXIS_RTRIGGER : MotionEvent.AXIS
_LTRIGGER; | 77 (isZoomInRequest) ? MotionEvent.AXIS_RTRIGGER : MotionEvent.AXIS
_LTRIGGER; |
68 MotionEvent.PointerCoords[] cords = new MotionEvent.PointerCoords[1]; | 78 MotionEvent.PointerCoords[] cords = new MotionEvent.PointerCoords[1]; |
69 MotionEvent.PointerProperties[] pPts = new MotionEvent.PointerProperties
[1]; | 79 MotionEvent.PointerProperties[] pPts = new MotionEvent.PointerProperties
[1]; |
70 cords[0] = new MotionEvent.PointerCoords(); | 80 cords[0] = new MotionEvent.PointerCoords(); |
71 pPts[0] = new MotionEvent.PointerProperties(); | 81 pPts[0] = new MotionEvent.PointerProperties(); |
72 cords[0].setAxisValue(axisVal, delta); | 82 cords[0].setAxisValue(axisVal, delta); |
73 pPts[0].id = 0; | 83 pPts[0].id = 0; |
74 MotionEvent joystickMotionEvent = MotionEvent.obtain((long) 0, SystemClo
ck.uptimeMillis(), | 84 MotionEvent joystickMotionEvent = MotionEvent.obtain((long) 0, SystemClo
ck.uptimeMillis(), |
75 MotionEvent.ACTION_MOVE, 1, pPts, cords, 0, 0, 0.01f, 0.01f, 3,
0, | 85 MotionEvent.ACTION_MOVE, 1, pPts, cords, 0, 0, 0.01f, 0.01f, 3,
0, |
76 InputDevice.SOURCE_CLASS_JOYSTICK, 0); | 86 InputDevice.SOURCE_CLASS_JOYSTICK, 0); |
77 return joystickMotionEvent; | 87 return joystickMotionEvent; |
78 } | 88 } |
79 | 89 |
80 @Override | 90 @Before |
81 protected void setUp() throws Exception { | 91 public void setUp() throws Exception { |
82 super.setUp(); | 92 mActivityTestRule.launchContentShellWithUrl(LARGE_PAGE); |
83 launchContentShellWithUrl(LARGE_PAGE); | 93 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
84 waitForActiveShellToBeDoneLoading(); | 94 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); |
85 assertWaitForPageScaleFactorMatch(2.0f); | |
86 } | 95 } |
87 | 96 |
| 97 @Test |
88 @SmallTest | 98 @SmallTest |
89 @Feature({"JoystickZoom"}) | 99 @Feature({"JoystickZoom"}) |
90 public void testJoystickZoomIn() throws Throwable { | 100 public void testJoystickZoomIn() throws Throwable { |
91 MotionEvent rTriggerEvent; | 101 MotionEvent rTriggerEvent; |
92 AnimationIntervalProvider intervalProvider = new TestAnimationIntervalPr
ovider(); | 102 AnimationIntervalProvider intervalProvider = new TestAnimationIntervalPr
ovider(); |
93 TestJoystickZoomProvider rtJoystickZoomProvider = | 103 TestJoystickZoomProvider rtJoystickZoomProvider = new TestJoystickZoomPr
ovider( |
94 new TestJoystickZoomProvider(getContentViewCore(), intervalProvi
der); | 104 mActivityTestRule.getContentViewCore(), intervalProvider); |
95 // Verify page does not zoom-in if trigger motion falls in deadzone. | 105 // Verify page does not zoom-in if trigger motion falls in deadzone. |
96 rTriggerEvent = simulateJoystickEvent(0.1f, true); | 106 rTriggerEvent = simulateJoystickEvent(0.1f, true); |
97 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); | 107 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); |
98 assertWaitForPageScaleFactorMatch(2.0f); | 108 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); |
99 | 109 |
100 rTriggerEvent = simulateJoystickEvent(0.3f, true); | 110 rTriggerEvent = simulateJoystickEvent(0.3f, true); |
101 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); | 111 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); |
102 assertWaitForPageScaleFactorMatch(2.2018466f); | 112 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.2018466f); |
103 | 113 |
104 rTriggerEvent = simulateJoystickEvent(0.5f, true); | 114 rTriggerEvent = simulateJoystickEvent(0.5f, true); |
105 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 40); | 115 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 40); |
106 assertWaitForPageScaleFactorMatch(3.033731f); | 116 mActivityTestRule.assertWaitForPageScaleFactorMatch(3.033731f); |
107 | 117 |
108 rTriggerEvent = simulateJoystickEvent(0.75f, true); | 118 rTriggerEvent = simulateJoystickEvent(0.75f, true); |
109 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 50); | 119 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 50); |
110 assertWaitForPageScaleFactorMatch(5.0f); | 120 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); |
111 } | 121 } |
112 | 122 |
| 123 @Test |
113 @SmallTest | 124 @SmallTest |
114 @Feature({"JoystickZoom"}) | 125 @Feature({"JoystickZoom"}) |
115 public void testJoystickZoomOut() throws Throwable { | 126 public void testJoystickZoomOut() throws Throwable { |
116 MotionEvent lTriggerEvent; | 127 MotionEvent lTriggerEvent; |
117 AnimationIntervalProvider intervalProvider = new TestAnimationIntervalPr
ovider(); | 128 AnimationIntervalProvider intervalProvider = new TestAnimationIntervalPr
ovider(); |
118 TestJoystickZoomProvider ltJoystickZoomProvider = | 129 TestJoystickZoomProvider ltJoystickZoomProvider = new TestJoystickZoomPr
ovider( |
119 new TestJoystickZoomProvider(getContentViewCore(), intervalProvi
der); | 130 mActivityTestRule.getContentViewCore(), intervalProvider); |
120 | 131 |
121 // Zoom page to max size. | 132 // Zoom page to max size. |
122 lTriggerEvent = simulateJoystickEvent(1.0f, true); | 133 lTriggerEvent = simulateJoystickEvent(1.0f, true); |
123 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); | 134 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); |
124 assertWaitForPageScaleFactorMatch(5.0f); | 135 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); |
125 | 136 |
126 // Verify page does not zoom-out if trigger motion falls in deadzone. | 137 // Verify page does not zoom-out if trigger motion falls in deadzone. |
127 lTriggerEvent = simulateJoystickEvent(0.1f, false); | 138 lTriggerEvent = simulateJoystickEvent(0.1f, false); |
128 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 20); | 139 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 20); |
129 assertWaitForPageScaleFactorMatch(5.0f); | 140 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); |
130 | 141 |
131 lTriggerEvent = simulateJoystickEvent(0.3f, false); | 142 lTriggerEvent = simulateJoystickEvent(0.3f, false); |
132 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 40); | 143 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 40); |
133 assertWaitForPageScaleFactorMatch(4.125306f); | 144 mActivityTestRule.assertWaitForPageScaleFactorMatch(4.125306f); |
134 | 145 |
135 lTriggerEvent = simulateJoystickEvent(0.5f, false); | 146 lTriggerEvent = simulateJoystickEvent(0.5f, false); |
136 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 50); | 147 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 50); |
137 assertWaitForPageScaleFactorMatch(2.7635581f); | 148 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.7635581f); |
138 | 149 |
139 lTriggerEvent = simulateJoystickEvent(0.75f, false); | 150 lTriggerEvent = simulateJoystickEvent(0.75f, false); |
140 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); | 151 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); |
141 assertWaitForPageScaleFactorMatch(2.0f); | 152 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); |
142 } | 153 } |
143 } | 154 } |
OLD | NEW |