Commit 3e2e2882 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Add horizontal scrolling to VR browser scrolling test

Adds horizontal scrolling to the VR browser scrolling test, so now both
vertical and horizontal scrolling using the Daydream controller are
tested.

This should hopefully be good enough to remove the need to manually test
basic scroll functionality.

Bug: 728779
Change-Id: I882755999485b6610fcd865953cb1b06ca47edd5
Reviewed-on: https://chromium-review.googlesource.com/567033Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486003}
parent cc213072
...@@ -9,6 +9,8 @@ import android.os.SystemClock; ...@@ -9,6 +9,8 @@ import android.os.SystemClock;
import com.google.vr.testframework.controller.ControllerTestApi; import com.google.vr.testframework.controller.ControllerTestApi;
import org.junit.Assert;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
...@@ -21,6 +23,7 @@ import java.util.concurrent.TimeUnit; ...@@ -21,6 +23,7 @@ import java.util.concurrent.TimeUnit;
* - PairedControllerAddress: "FOO" * - PairedControllerAddress: "FOO"
*/ */
public class EmulatedVrController { public class EmulatedVrController {
public enum ScrollDirection { UP, DOWN, LEFT, RIGHT }
private final ControllerTestApi mApi; private final ControllerTestApi mApi;
public EmulatedVrController(Context context) { public EmulatedVrController(Context context) {
...@@ -87,31 +90,41 @@ public class EmulatedVrController { ...@@ -87,31 +90,41 @@ public class EmulatedVrController {
} }
/** /**
* Performs an upward swipe on the touchpad, which scrolls down in VR Shell. * Performs an swipe on the touchpad in order to scroll in the specified
* direction while in the VR browser.
* Note that scrolling this way is not consistent, i.e. scrolling down then * Note that scrolling this way is not consistent, i.e. scrolling down then
* scrolling up at the same speed won't necessarily scroll back to the exact * scrolling up at the same speed won't necessarily scroll back to the exact
* starting position on the page. * starting position on the page.
* *
* @param direction the ScrollDirection to scroll with
* @param steps the number of intermediate steps to send while scrolling * @param steps the number of intermediate steps to send while scrolling
* @param speed how long to wait between steps in the scroll, with higher * @param speed how long to wait between steps in the scroll, with higher
* numbers resulting in a faster scroll * numbers resulting in a faster scroll
*/ */
public void scrollDown(int steps, int speed) { public void scroll(ScrollDirection direction, int steps, int speed) {
performLinearTouchpadMovement(0.5f, 0.9f, 0.5f, 0.1f, steps, speed); float startX, startY, endX, endY;
} startX = startY = endX = endY = 0.5f;
switch (direction) {
/** case UP:
* Performs a downward swipe on the touchpad, which scrolls up in VR Shell. startY = 0.1f;
* Note that scrolling this way is not consistent, i.e. scrolling down then endY = 0.9f;
* scrolling up at the same speed won't necessarily scroll back to the exact break;
* starting position on the page. case DOWN:
* startY = 0.9f;
* @param steps the number of intermediate steps to send while scrolling endY = 0.1f;
* @param speed how long to wait between steps in the scroll, with higher break;
* numbers resulting in a faster scroll case LEFT:
*/ startX = 0.1f;
public void scrollUp(int steps, int speed) { endX = 0.9f;
performLinearTouchpadMovement(0.5f, 0.1f, 0.5f, 0.9f, steps, speed); break;
case RIGHT:
startX = 0.9f;
endX = 0.1f;
break;
default:
Assert.fail("Unknown scroll direction enum given");
}
performLinearTouchpadMovement(startX, startY, endX, endY, steps, speed);
} }
/** /**
......
...@@ -37,17 +37,17 @@ public class VrShellControllerInputTest { ...@@ -37,17 +37,17 @@ public class VrShellControllerInputTest {
@Rule @Rule
public VrTestRule mVrTestRule = new VrTestRule(); public VrTestRule mVrTestRule = new VrTestRule();
// TODO(bsheedy): Modify test to also check horizontal scrolling
/** /**
* Verifies that swiping up/down on the Daydream controller's touchpad scrolls * Verifies that swiping up/down/left/right on the Daydream controller's
* the webpage while in the VR browser. * touchpad scrolls the webpage while in the VR browser.
*/ */
@Test @Test
@Restriction({RESTRICTION_TYPE_DEVICE_DAYDREAM, RESTRICTION_TYPE_VIEWER_DAYDREAM}) @Restriction({RESTRICTION_TYPE_DEVICE_DAYDREAM, RESTRICTION_TYPE_VIEWER_DAYDREAM})
@MediumTest @MediumTest
public void testControllerScrolling() throws InterruptedException { public void testControllerScrolling() throws InterruptedException {
// Load page in VR and make sure the controller is pointed at the content quad // Load page in VR and make sure the controller is pointed at the content quad
mVrTestRule.loadUrl("chrome://credits", PAGE_LOAD_TIMEOUT_S); mVrTestRule.loadUrl(
mVrTestRule.getHtmlTestFile("test_controller_scrolling"), PAGE_LOAD_TIMEOUT_S);
VrTransitionUtils.forceEnterVr(); VrTransitionUtils.forceEnterVr();
VrTransitionUtils.waitForVrEntry(POLL_TIMEOUT_LONG_MS); VrTransitionUtils.waitForVrEntry(POLL_TIMEOUT_LONG_MS);
EmulatedVrController controller = new EmulatedVrController(mVrTestRule.getActivity()); EmulatedVrController controller = new EmulatedVrController(mVrTestRule.getActivity());
...@@ -59,23 +59,39 @@ public class VrShellControllerInputTest { ...@@ -59,23 +59,39 @@ public class VrShellControllerInputTest {
CriteriaHelper.pollUiThread(new Criteria() { CriteriaHelper.pollUiThread(new Criteria() {
@Override @Override
public boolean isSatisfied() { public boolean isSatisfied() {
return cvc.computeVerticalScrollRange() > cvc.getContainerView().getHeight(); return cvc.computeVerticalScrollRange() > cvc.getContainerView().getHeight()
&& cvc.computeHorizontalScrollRange() > cvc.getContainerView().getWidth();
} }
}, POLL_TIMEOUT_LONG_MS, POLL_CHECK_INTERVAL_LONG_MS); }, POLL_TIMEOUT_LONG_MS, POLL_CHECK_INTERVAL_LONG_MS);
// Test that scrolling down works // Test that scrolling down works
int startScrollY = cvc.getNativeScrollYForTest(); int startScrollPoint = cvc.getNativeScrollYForTest();
// Arbitrary, but valid values to scroll smoothly // Arbitrary, but valid values to scroll smoothly
int scrollSteps = 20; int scrollSteps = 20;
int scrollSpeed = 60; int scrollSpeed = 60;
controller.scrollDown(scrollSteps, scrollSpeed); controller.scroll(EmulatedVrController.ScrollDirection.DOWN, scrollSteps, scrollSpeed);
int endScrollY = cvc.getNativeScrollYForTest(); // We need this second scroll down, otherwise the horizontal scrolling becomes flaky
Assert.assertTrue("Controller was able to scroll down", startScrollY < endScrollY); // TODO(bsheedy): Figure out why this is the case
controller.scroll(EmulatedVrController.ScrollDirection.DOWN, scrollSteps, scrollSpeed);
int endScrollPoint = cvc.getNativeScrollYForTest();
Assert.assertTrue("Controller was able to scroll down", startScrollPoint < endScrollPoint);
// Test that scrolling up works // Test that scrolling up works
startScrollY = endScrollY; startScrollPoint = endScrollPoint;
controller.scrollUp(scrollSteps, scrollSpeed); controller.scroll(EmulatedVrController.ScrollDirection.UP, scrollSteps, scrollSpeed);
endScrollY = cvc.getNativeScrollYForTest(); endScrollPoint = cvc.getNativeScrollYForTest();
Assert.assertTrue("Controller was able to scroll up", startScrollY > endScrollY); Assert.assertTrue("Controller was able to scroll up", startScrollPoint > endScrollPoint);
// Test that scrolling right works
startScrollPoint = cvc.getNativeScrollXForTest();
controller.scroll(EmulatedVrController.ScrollDirection.RIGHT, scrollSteps, scrollSpeed);
endScrollPoint = cvc.getNativeScrollXForTest();
Assert.assertTrue("Controller was able to scroll right", startScrollPoint < endScrollPoint);
// Test that scrolling left works
startScrollPoint = endScrollPoint;
controller.scroll(EmulatedVrController.ScrollDirection.LEFT, scrollSteps, scrollSpeed);
endScrollPoint = cvc.getNativeScrollXForTest();
Assert.assertTrue("Controller was able to scroll left", startScrollPoint > endScrollPoint);
} }
} }
<!DOCTYPE html>
<!--
Used to test that vertical and horizontal scrolling work with the Daydream
controller.
-->
<html>
<head>
<style>
body {
width: 10000px;
height: 10000px;
}
</style>
</head>
<body>
This is a test page.
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment