Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/ContentViewZoomingTest.java

Issue 1288243004: Enable zoom through gamedpad trigger joystick (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed previous comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/input/JoystickZoomProvider.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/public/android/javatests/src/org/chromium/content/browser/ContentViewZoomingTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ContentViewZoomingTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewZoomingTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..d9fe3d5dad1035ad1a995daf2daa34cfd46438c7
--- /dev/null
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ContentViewZoomingTest.java
@@ -0,0 +1,108 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.content.browser;
+
+import android.os.SystemClock;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.view.InputDevice;
+import android.view.MotionEvent;
+
+import org.chromium.base.test.util.Feature;
+import org.chromium.base.test.util.UrlUtils;
+import org.chromium.content.browser.test.util.Criteria;
+import org.chromium.content.browser.test.util.CriteriaHelper;
+import org.chromium.content_shell_apk.ContentShellTestBase;
+
+/**
+ * Tests that ContentView running inside ContentShell can be zoomed using gamepad joystick.
+ */
+public class ContentViewZoomingTest extends ContentShellTestBase {
+ private static final String LARGE_PAGE = UrlUtils.encodeHtmlDataUri("<html><head>"
+ + "<meta name=\"viewport\" content=\"width=device-width, "
+ + "initial-scale=2.0, minimum-scale=2.0, maximum-scale=5.0\" />"
+ + "<style>body { width: 5000px; height: 5000px; }</style></head>"
+ + "<body>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</body>"
+ + "</html>");
+
+ private void assertWaitForZoom(final boolean isMinZoom, final float minThreshold,
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
+ final float maxThreshold) throws InterruptedException {
+ CriteriaHelper.pollForCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return isMinZoom ? getContentViewCore().getScale() <= minThreshold
+ : getContentViewCore().getScale() >= maxThreshold;
+ }
+ });
+ }
+
+ private void zoomWithJoystick(final float delta, final boolean isZoomInRequest)
+ throws Throwable {
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ // Synthesize joystick motion event and send to ContentViewCore.
+ final int axisVal =
+ (isZoomInRequest) ? MotionEvent.AXIS_RTRIGGER : MotionEvent.AXIS_LTRIGGER;
+ MotionEvent.PointerCoords[] cords = new MotionEvent.PointerCoords[1];
+ MotionEvent.PointerProperties[] pPts = new MotionEvent.PointerProperties[1];
+ cords[0] = new MotionEvent.PointerCoords();
+ pPts[0] = new MotionEvent.PointerProperties();
+ cords[0].setAxisValue(axisVal, delta);
+ pPts[0].id = 0;
+ MotionEvent joystickMotionEvent = MotionEvent.obtain((long) 0,
+ SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, 1, pPts, cords, 0, 0,
+ 0.01f, 0.01f, 3, 0, InputDevice.SOURCE_CLASS_JOYSTICK, 0);
+ getContentViewCore().getContainerView().onGenericMotionEvent(joystickMotionEvent);
+ }
+ });
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ launchContentShellWithUrl(LARGE_PAGE);
+ waitForActiveShellToBeDoneLoading();
+ assertWaitForPageScaleFactorMatch(2.0f);
+ }
+
+ @SmallTest
+ @Feature({"Zoom"})
+ public void testJoystickZoomIn() throws Throwable {
+ // Verify page does not zoom-in if trigger motion falls in deadzone.
+ zoomWithJoystick(0.1f, true);
+ assertWaitForZoom(true, 2.0f, 5.0f);
+
+ // Verify page zooms if trigger motion event falls beyond deadzone.
+ // Zoom page till max page scale == 5.0
+ zoomWithJoystick(0.5f, true);
+ assertWaitForZoom(false, 2.0f, 5.0f);
+
+ // 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
+ // After sending joystick event.
+ zoomWithJoystick(0.95f, true);
+ assertWaitForZoom(true, 5.0f, 5.5f);
+ }
+
+ @SmallTest
+ @Feature({"Zoom"})
+ public void testJoystickZoomOut() throws Throwable {
+ // Zoom page to max size
+ zoomWithJoystick(0.5f, true);
+ assertWaitForZoom(false, 2.0f, 5.0f);
+
+ // Verify page does not zoom-out if trigger motion falls in deadzone.
+ zoomWithJoystick(0.1f, false);
+ assertWaitForZoom(false, 2.0f, 5.0f);
+
+ // Verify page zoom-out when trigger axis motion is beyond deadzone.
+ // Zoom page till page scale == 2.0
+ zoomWithJoystick(0.5f, false);
+ assertWaitForZoom(true, 2.0f, 5.0f);
+
+ // Check whether page can be scaled less than minscale after sending joystick event.
+ zoomWithJoystick(0.95f, false);
+ assertWaitForZoom(false, 1.0f, 2.0f);
+ }
+}
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/input/JoystickZoomProvider.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698