Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.content.browser; | |
| 6 | |
| 7 import android.os.SystemClock; | |
| 8 import android.test.suitebuilder.annotation.SmallTest; | |
| 9 import android.view.InputDevice; | |
| 10 import android.view.MotionEvent; | |
| 11 | |
| 12 import org.chromium.base.test.util.Feature; | |
| 13 import org.chromium.base.test.util.UrlUtils; | |
| 14 import org.chromium.content.browser.test.util.Criteria; | |
| 15 import org.chromium.content.browser.test.util.CriteriaHelper; | |
| 16 import org.chromium.content_shell_apk.ContentShellTestBase; | |
| 17 | |
| 18 /** | |
| 19 * Tests that ContentView running inside ContentShell can be zoomed using gamepa d joystick. | |
| 20 */ | |
| 21 public class ContentViewZoomingTest extends ContentShellTestBase { | |
| 22 private static final String LARGE_PAGE = UrlUtils.encodeHtmlDataUri("<html>< head>" | |
| 23 + "<meta name=\"viewport\" content=\"width=device-width, " | |
| 24 + "initial-scale=2.0, minimum-scale=2.0, maximum-scale=5.0\" />" | |
| 25 + "<style>body { width: 5000px; height: 5000px; }</style></head>" | |
| 26 + "<body>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</b ody>" | |
| 27 + "</html>"); | |
| 28 | |
| 29 private void assertWaitForZoom(final boolean isMinZoom, final float minThres hold, | |
|
aelias_OOO_until_Jul13
2016/01/20 04:10:43
Please wait for an exact value instead of having a
sshelke
2016/01/25 09:19:16
I have designed test case on similar lines of scro
tdresser
2016/01/25 13:12:13
We should wait until we're done zooming, in which
aelias_OOO_until_Jul13
2016/01/26 03:39:04
Yeah, there's no race if you wait until the min/ma
| |
| 30 final float maxThreshold) throws InterruptedException { | |
| 31 CriteriaHelper.pollForCriteria(new Criteria() { | |
| 32 @Override | |
| 33 public boolean isSatisfied() { | |
| 34 return isMinZoom ? getContentViewCore().getScale() <= minThresho ld | |
| 35 : getContentViewCore().getScale() >= maxThresho ld; | |
| 36 } | |
| 37 }); | |
| 38 } | |
| 39 | |
| 40 private void zoomWithJoystick(final float delta, final boolean isZoomInReque st) | |
| 41 throws Throwable { | |
| 42 runTestOnUiThread(new Runnable() { | |
| 43 @Override | |
| 44 public void run() { | |
| 45 // Synthesize joystick motion event and send to ContentViewCore. | |
| 46 final int axisVal = | |
| 47 (isZoomInRequest) ? MotionEvent.AXIS_RTRIGGER : MotionEv ent.AXIS_LTRIGGER; | |
| 48 MotionEvent.PointerCoords[] cords = new MotionEvent.PointerCoord s[1]; | |
| 49 MotionEvent.PointerProperties[] pPts = new MotionEvent.PointerPr operties[1]; | |
| 50 cords[0] = new MotionEvent.PointerCoords(); | |
| 51 pPts[0] = new MotionEvent.PointerProperties(); | |
| 52 cords[0].setAxisValue(axisVal, delta); | |
| 53 pPts[0].id = 0; | |
| 54 MotionEvent joystickMotionEvent = MotionEvent.obtain((long) 0, | |
| 55 SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, 1, pPts, cords, 0, 0, | |
| 56 0.01f, 0.01f, 3, 0, InputDevice.SOURCE_CLASS_JOYSTICK, 0 ); | |
| 57 getContentViewCore().getContainerView().onGenericMotionEvent(joy stickMotionEvent); | |
| 58 } | |
| 59 }); | |
| 60 } | |
| 61 | |
| 62 @Override | |
| 63 protected void setUp() throws Exception { | |
| 64 super.setUp(); | |
| 65 launchContentShellWithUrl(LARGE_PAGE); | |
| 66 waitForActiveShellToBeDoneLoading(); | |
| 67 assertWaitForPageScaleFactorMatch(2.0f); | |
| 68 } | |
| 69 | |
| 70 @SmallTest | |
| 71 @Feature({"Zoom"}) | |
| 72 public void testJoystickZoomIn() throws Throwable { | |
| 73 // Verify page does not zoom-in if trigger motion falls in deadzone. | |
| 74 zoomWithJoystick(0.1f, true); | |
| 75 assertWaitForZoom(true, 2.0f, 5.0f); | |
| 76 | |
| 77 // Verify page zooms if trigger motion event falls beyond deadzone. | |
| 78 // Zoom page till max page scale == 5.0 | |
| 79 zoomWithJoystick(0.5f, true); | |
| 80 assertWaitForZoom(false, 2.0f, 5.0f); | |
| 81 | |
| 82 // Check whether page can be scaled beyond max page scale | |
|
aelias_OOO_until_Jul13
2016/01/20 04:10:43
I don't see what this is testing, please delete it
sshelke
2016/01/25 09:19:16
This test case ensures that
1) Page should not be
aelias_OOO_until_Jul13
2016/01/26 03:39:04
I don't see why this assertion would fail even if
| |
| 83 // After sending joystick event. | |
| 84 zoomWithJoystick(0.95f, true); | |
| 85 assertWaitForZoom(true, 5.0f, 5.5f); | |
| 86 } | |
| 87 | |
| 88 @SmallTest | |
| 89 @Feature({"Zoom"}) | |
| 90 public void testJoystickZoomOut() throws Throwable { | |
| 91 // Zoom page to max size | |
| 92 zoomWithJoystick(0.5f, true); | |
| 93 assertWaitForZoom(false, 2.0f, 5.0f); | |
| 94 | |
| 95 // Verify page does not zoom-out if trigger motion falls in deadzone. | |
| 96 zoomWithJoystick(0.1f, false); | |
| 97 assertWaitForZoom(false, 2.0f, 5.0f); | |
| 98 | |
| 99 // Verify page zoom-out when trigger axis motion is beyond deadzone. | |
| 100 // Zoom page till page scale == 2.0 | |
| 101 zoomWithJoystick(0.5f, false); | |
| 102 assertWaitForZoom(true, 2.0f, 5.0f); | |
| 103 | |
| 104 // Check whether page can be scaled less than minscale after sending joy stick event. | |
| 105 zoomWithJoystick(0.95f, false); | |
| 106 assertWaitForZoom(false, 1.0f, 2.0f); | |
| 107 } | |
| 108 } | |
| OLD | NEW |