| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
| 13 import org.chromium.base.test.util.UrlUtils; | 13 import org.chromium.base.test.util.UrlUtils; |
| 14 import org.chromium.content.browser.input.AnimationIntervalProvider; | 14 import org.chromium.content.browser.input.AnimationIntervalProvider; |
| 15 import org.chromium.content.browser.input.JoystickZoomProvider; | 15 import org.chromium.content.browser.input.JoystickZoomProvider; |
| 16 import org.chromium.content_shell_apk.ContentShellTestBase; | 16 import org.chromium.content_shell_apk.ContentShellTestBase; |
| 17 import org.junit.Rule; |
| 18 import org.junit.Test; |
| 19 import org.chromium.base.test.BaseJUnit4ClassRunner; |
| 20 import org.junit.runner.RunWith; |
| 21 import org.junit.Before; |
| 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 |
| 30 @Rule |
| 31 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); |
| 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 |
| 82 super.setUp(); | 92 public void setUp() throws Exception { |
| 83 launchContentShellWithUrl(LARGE_PAGE); | 93 mActivityTestRule.launchContentShellWithUrl(LARGE_PAGE); |
| 84 waitForActiveShellToBeDoneLoading(); | 94 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
| 85 assertWaitForPageScaleFactorMatch(2.0f); | 95 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); |
| 86 } | 96 } |
| 87 | 97 |
| 98 @Test |
| 88 @SmallTest | 99 @SmallTest |
| 89 @Feature({"JoystickZoom"}) | 100 @Feature({"JoystickZoom"}) |
| 90 public void testJoystickZoomIn() throws Throwable { | 101 public void testJoystickZoomIn() throws Throwable { |
| 91 MotionEvent rTriggerEvent; | 102 MotionEvent rTriggerEvent; |
| 92 AnimationIntervalProvider intervalProvider = new TestAnimationIntervalPr
ovider(); | 103 AnimationIntervalProvider intervalProvider = new TestAnimationIntervalPr
ovider(); |
| 93 TestJoystickZoomProvider rtJoystickZoomProvider = | 104 TestJoystickZoomProvider rtJoystickZoomProvider = |
| 94 new TestJoystickZoomProvider(getContentViewCore(), intervalProvi
der); | 105 new TestJoystickZoomProvider(mActivityTestRule.getContentViewCor
e(), intervalProvider); |
| 95 // Verify page does not zoom-in if trigger motion falls in deadzone. | 106 // Verify page does not zoom-in if trigger motion falls in deadzone. |
| 96 rTriggerEvent = simulateJoystickEvent(0.1f, true); | 107 rTriggerEvent = simulateJoystickEvent(0.1f, true); |
| 97 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); | 108 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); |
| 98 assertWaitForPageScaleFactorMatch(2.0f); | 109 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); |
| 99 | 110 |
| 100 rTriggerEvent = simulateJoystickEvent(0.3f, true); | 111 rTriggerEvent = simulateJoystickEvent(0.3f, true); |
| 101 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); | 112 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); |
| 102 assertWaitForPageScaleFactorMatch(2.2018466f); | 113 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.2018466f); |
| 103 | 114 |
| 104 rTriggerEvent = simulateJoystickEvent(0.5f, true); | 115 rTriggerEvent = simulateJoystickEvent(0.5f, true); |
| 105 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 40); | 116 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 40); |
| 106 assertWaitForPageScaleFactorMatch(3.033731f); | 117 mActivityTestRule.assertWaitForPageScaleFactorMatch(3.033731f); |
| 107 | 118 |
| 108 rTriggerEvent = simulateJoystickEvent(0.75f, true); | 119 rTriggerEvent = simulateJoystickEvent(0.75f, true); |
| 109 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 50); | 120 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 50); |
| 110 assertWaitForPageScaleFactorMatch(5.0f); | 121 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); |
| 111 } | 122 } |
| 112 | 123 |
| 124 @Test |
| 113 @SmallTest | 125 @SmallTest |
| 114 @Feature({"JoystickZoom"}) | 126 @Feature({"JoystickZoom"}) |
| 115 public void testJoystickZoomOut() throws Throwable { | 127 public void testJoystickZoomOut() throws Throwable { |
| 116 MotionEvent lTriggerEvent; | 128 MotionEvent lTriggerEvent; |
| 117 AnimationIntervalProvider intervalProvider = new TestAnimationIntervalPr
ovider(); | 129 AnimationIntervalProvider intervalProvider = new TestAnimationIntervalPr
ovider(); |
| 118 TestJoystickZoomProvider ltJoystickZoomProvider = | 130 TestJoystickZoomProvider ltJoystickZoomProvider = |
| 119 new TestJoystickZoomProvider(getContentViewCore(), intervalProvi
der); | 131 new TestJoystickZoomProvider(mActivityTestRule.getContentViewCor
e(), intervalProvider); |
| 120 | 132 |
| 121 // Zoom page to max size. | 133 // Zoom page to max size. |
| 122 lTriggerEvent = simulateJoystickEvent(1.0f, true); | 134 lTriggerEvent = simulateJoystickEvent(1.0f, true); |
| 123 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); | 135 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); |
| 124 assertWaitForPageScaleFactorMatch(5.0f); | 136 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); |
| 125 | 137 |
| 126 // Verify page does not zoom-out if trigger motion falls in deadzone. | 138 // Verify page does not zoom-out if trigger motion falls in deadzone. |
| 127 lTriggerEvent = simulateJoystickEvent(0.1f, false); | 139 lTriggerEvent = simulateJoystickEvent(0.1f, false); |
| 128 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 20); | 140 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 20); |
| 129 assertWaitForPageScaleFactorMatch(5.0f); | 141 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); |
| 130 | 142 |
| 131 lTriggerEvent = simulateJoystickEvent(0.3f, false); | 143 lTriggerEvent = simulateJoystickEvent(0.3f, false); |
| 132 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 40); | 144 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 40); |
| 133 assertWaitForPageScaleFactorMatch(4.125306f); | 145 mActivityTestRule.assertWaitForPageScaleFactorMatch(4.125306f); |
| 134 | 146 |
| 135 lTriggerEvent = simulateJoystickEvent(0.5f, false); | 147 lTriggerEvent = simulateJoystickEvent(0.5f, false); |
| 136 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 50); | 148 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 50); |
| 137 assertWaitForPageScaleFactorMatch(2.7635581f); | 149 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.7635581f); |
| 138 | 150 |
| 139 lTriggerEvent = simulateJoystickEvent(0.75f, false); | 151 lTriggerEvent = simulateJoystickEvent(0.75f, false); |
| 140 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); | 152 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); |
| 141 assertWaitForPageScaleFactorMatch(2.0f); | 153 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); |
| 142 } | 154 } |
| 143 } | 155 } |
| OLD | NEW |