| 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; | 12 import org.junit.Before; |
| 13 import org.junit.Rule; | 13 import org.junit.Rule; |
| 14 import org.junit.Test; | 14 import org.junit.Test; |
| 15 import org.junit.runner.RunWith; | 15 import org.junit.runner.RunWith; |
| 16 | 16 |
| 17 import org.chromium.base.test.BaseJUnit4ClassRunner; | 17 import org.chromium.base.test.BaseJUnit4ClassRunner; |
| 18 import org.chromium.base.test.util.Feature; | 18 import org.chromium.base.test.util.Feature; |
| 19 import org.chromium.base.test.util.UrlUtils; | 19 import org.chromium.base.test.util.UrlUtils; |
| 20 import org.chromium.content.browser.input.AnimationIntervalProvider; | |
| 21 import org.chromium.content.browser.input.JoystickZoomProvider; | 20 import org.chromium.content.browser.input.JoystickZoomProvider; |
| 22 import org.chromium.content_shell_apk.ContentShellActivityTestRule; | 21 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
| 23 | 22 |
| 24 /** | 23 /** |
| 25 * Tests that ContentView running inside ContentShell can be zoomed using gamepa
d joystick. | 24 * Tests that ContentView running inside ContentShell can be zoomed using gamepa
d joystick. |
| 26 */ | 25 */ |
| 27 @RunWith(BaseJUnit4ClassRunner.class) | 26 @RunWith(BaseJUnit4ClassRunner.class) |
| 28 public class ContentViewZoomingTest { | 27 public class ContentViewZoomingTest { |
| 29 @Rule | 28 @Rule |
| 30 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); | 29 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); |
| 31 | 30 |
| 32 private static final String LARGE_PAGE = UrlUtils.encodeHtmlDataUri("<html><
head>" | 31 private static final String LARGE_PAGE = UrlUtils.encodeHtmlDataUri("<html><
head>" |
| 33 + "<meta name=\"viewport\" content=\"width=device-width, " | 32 + "<meta name=\"viewport\" content=\"width=device-width, " |
| 34 + "initial-scale=2.0, minimum-scale=2.0, maximum-scale=5.0\" />" | 33 + "initial-scale=2.0, minimum-scale=2.0, maximum-scale=5.0\" />" |
| 35 + "<style>body { width: 5000px; height: 5000px; }</style></head>" | 34 + "<style>body { width: 5000px; height: 5000px; }</style></head>" |
| 36 + "<body>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</b
ody>" | 35 + "<body>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</b
ody>" |
| 37 + "</html>"); | 36 + "</html>"); |
| 38 | 37 |
| 39 private static class TestAnimationIntervalProvider implements AnimationInter
valProvider { | 38 private static class TestAnimationIntervalProvider |
| 39 implements JoystickZoomProvider.AnimationIntervalProvider { |
| 40 private long mAnimationTime; | 40 private long mAnimationTime; |
| 41 @Override | 41 @Override |
| 42 public long getLastAnimationFrameInterval() { | 42 public long getLastAnimationFrameInterval() { |
| 43 mAnimationTime += 16; | 43 mAnimationTime += 16; |
| 44 return mAnimationTime; | 44 return mAnimationTime; |
| 45 } | 45 } |
| 46 } | 46 } |
| 47 | 47 |
| 48 private class TestJoystickZoomProvider extends JoystickZoomProvider { | 48 private class TestJoystickZoomProvider extends JoystickZoomProvider { |
| 49 TestJoystickZoomProvider(ContentViewCore cvc, AnimationIntervalProvider
intervalProvider) { | 49 TestJoystickZoomProvider(ContentViewCore cvc, AnimationIntervalProvider
intervalProvider) { |
| 50 super(cvc, intervalProvider); | 50 super(cvc.getContainerView(), 2.0f, cvc.getViewportWidthPix() / 2, |
| 51 mDeviceScaleFactor = 2.0f; | 51 cvc.getViewportHeightPix() / 2, cvc); |
| 52 setAnimationIntervalProviderForTesting(intervalProvider); |
| 52 | 53 |
| 53 mZoomRunnable = new Runnable() { | 54 mZoomRunnable = new Runnable() { |
| 54 @Override | 55 @Override |
| 55 public void run() {} | 56 public void run() {} |
| 56 }; | 57 }; |
| 57 } | 58 } |
| 58 | 59 |
| 59 public void animateZoomTest(final MotionEvent joystickZoomEvent, final l
ong animationTicks) | 60 public void animateZoomTest(final MotionEvent joystickZoomEvent, final l
ong animationTicks) |
| 60 throws Throwable { | 61 throws Throwable { |
| 61 mActivityTestRule.runOnUiThread(new Runnable() { | 62 mActivityTestRule.runOnUiThread(new Runnable() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 92 mActivityTestRule.launchContentShellWithUrl(LARGE_PAGE); | 93 mActivityTestRule.launchContentShellWithUrl(LARGE_PAGE); |
| 93 mActivityTestRule.waitForActiveShellToBeDoneLoading(); | 94 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
| 94 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); | 95 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); |
| 95 } | 96 } |
| 96 | 97 |
| 97 @Test | 98 @Test |
| 98 @SmallTest | 99 @SmallTest |
| 99 @Feature({"JoystickZoom"}) | 100 @Feature({"JoystickZoom"}) |
| 100 public void testJoystickZoomIn() throws Throwable { | 101 public void testJoystickZoomIn() throws Throwable { |
| 101 MotionEvent rTriggerEvent; | 102 MotionEvent rTriggerEvent; |
| 102 AnimationIntervalProvider intervalProvider = new TestAnimationIntervalPr
ovider(); | |
| 103 TestJoystickZoomProvider rtJoystickZoomProvider = new TestJoystickZoomPr
ovider( | 103 TestJoystickZoomProvider rtJoystickZoomProvider = new TestJoystickZoomPr
ovider( |
| 104 mActivityTestRule.getContentViewCore(), intervalProvider); | 104 mActivityTestRule.getContentViewCore(), new TestAnimationInterva
lProvider()); |
| 105 // 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. |
| 106 rTriggerEvent = simulateJoystickEvent(0.1f, true); | 106 rTriggerEvent = simulateJoystickEvent(0.1f, true); |
| 107 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); | 107 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); |
| 108 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); | 108 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); |
| 109 | 109 |
| 110 rTriggerEvent = simulateJoystickEvent(0.3f, true); | 110 rTriggerEvent = simulateJoystickEvent(0.3f, true); |
| 111 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); | 111 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 20); |
| 112 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.2018466f); | 112 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.2018466f); |
| 113 | 113 |
| 114 rTriggerEvent = simulateJoystickEvent(0.5f, true); | 114 rTriggerEvent = simulateJoystickEvent(0.5f, true); |
| 115 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 40); | 115 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 40); |
| 116 mActivityTestRule.assertWaitForPageScaleFactorMatch(3.033731f); | 116 mActivityTestRule.assertWaitForPageScaleFactorMatch(3.033731f); |
| 117 | 117 |
| 118 rTriggerEvent = simulateJoystickEvent(0.75f, true); | 118 rTriggerEvent = simulateJoystickEvent(0.75f, true); |
| 119 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 50); | 119 rtJoystickZoomProvider.animateZoomTest(rTriggerEvent, 50); |
| 120 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); | 120 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); |
| 121 } | 121 } |
| 122 | 122 |
| 123 @Test | 123 @Test |
| 124 @SmallTest | 124 @SmallTest |
| 125 @Feature({"JoystickZoom"}) | 125 @Feature({"JoystickZoom"}) |
| 126 public void testJoystickZoomOut() throws Throwable { | 126 public void testJoystickZoomOut() throws Throwable { |
| 127 MotionEvent lTriggerEvent; | 127 MotionEvent lTriggerEvent; |
| 128 AnimationIntervalProvider intervalProvider = new TestAnimationIntervalPr
ovider(); | |
| 129 TestJoystickZoomProvider ltJoystickZoomProvider = new TestJoystickZoomPr
ovider( | 128 TestJoystickZoomProvider ltJoystickZoomProvider = new TestJoystickZoomPr
ovider( |
| 130 mActivityTestRule.getContentViewCore(), intervalProvider); | 129 mActivityTestRule.getContentViewCore(), new TestAnimationInterva
lProvider()); |
| 131 | 130 |
| 132 // Zoom page to max size. | 131 // Zoom page to max size. |
| 133 lTriggerEvent = simulateJoystickEvent(1.0f, true); | 132 lTriggerEvent = simulateJoystickEvent(1.0f, true); |
| 134 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); | 133 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); |
| 135 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); | 134 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); |
| 136 | 135 |
| 137 // Verify page does not zoom-out if trigger motion falls in deadzone. | 136 // Verify page does not zoom-out if trigger motion falls in deadzone. |
| 138 lTriggerEvent = simulateJoystickEvent(0.1f, false); | 137 lTriggerEvent = simulateJoystickEvent(0.1f, false); |
| 139 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 20); | 138 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 20); |
| 140 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); | 139 mActivityTestRule.assertWaitForPageScaleFactorMatch(5.0f); |
| 141 | 140 |
| 142 lTriggerEvent = simulateJoystickEvent(0.3f, false); | 141 lTriggerEvent = simulateJoystickEvent(0.3f, false); |
| 143 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 40); | 142 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 40); |
| 144 mActivityTestRule.assertWaitForPageScaleFactorMatch(4.125306f); | 143 mActivityTestRule.assertWaitForPageScaleFactorMatch(4.125306f); |
| 145 | 144 |
| 146 lTriggerEvent = simulateJoystickEvent(0.5f, false); | 145 lTriggerEvent = simulateJoystickEvent(0.5f, false); |
| 147 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 50); | 146 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 50); |
| 148 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.7635581f); | 147 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.7635581f); |
| 149 | 148 |
| 150 lTriggerEvent = simulateJoystickEvent(0.75f, false); | 149 lTriggerEvent = simulateJoystickEvent(0.75f, false); |
| 151 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); | 150 ltJoystickZoomProvider.animateZoomTest(lTriggerEvent, 60); |
| 152 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); | 151 mActivityTestRule.assertWaitForPageScaleFactorMatch(2.0f); |
| 153 } | 152 } |
| 154 } | 153 } |
| OLD | NEW |