Commit f94f82d9 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Add VR NativePage scroll test

Adds VrShellControllerInputTest#testControllerScrollingNative, which
ensures that scrolling via the Daydream controller works on the
chrome://history NativePage.

Bug: 737168
Change-Id: Idfa83286ee56a4c245634e64dc3d80a3ef0a8d43
Reviewed-on: https://chromium-review.googlesource.com/959609
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542834}
parent 14d69d6e
......@@ -485,4 +485,9 @@ public class HistoryManager implements OnMenuItemClickListener, SignInStateObser
TextView getEmptyViewForTests() {
return mEmptyView;
}
@VisibleForTesting
public RecyclerView getRecyclerViewForTests() {
return mRecyclerView;
}
}
......@@ -119,6 +119,9 @@ public class EmulatedVrController {
float startX, startY, endX, endY;
// We need to perform the scroll over a shorter area of the touchpad in order for flinging
// to work properly.
// There's technically nothing that prevents fling scrolling if fling is set to false, but
// we have yet to find any combination of steps and speed that results in a fling with the
// larger scroll area that setting fling to false uses.
// TODO(https://crbug.com/820281): Figure out why this is the case - not fling scrolling
// because we're using more of the touchpad doesn't make sense.
float offset = fling ? 0.5f : 0.1f;
......@@ -144,11 +147,6 @@ public class EmulatedVrController {
Assert.fail("Unknown scroll direction enum given");
}
performLinearTouchpadMovement(startX, startY, endX, endY, steps, speed);
// There's technically nothing that prevents fling scrolling if fling is set to false, but
// we have yet to find any combination of steps and speed that results in a fling with the
// larger scroll area that setting fling to false uses. As an added precaution, assume that
// a fling occurred and cancel it immediately if we're not supposed to be flinging.
if (!fling) cancelFlingScroll();
}
/**
......
......@@ -13,6 +13,7 @@ import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_V
import android.os.SystemClock;
import android.support.test.filters.MediumTest;
import android.support.v7.widget.RecyclerView;
import org.junit.Assert;
import org.junit.Before;
......@@ -24,6 +25,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.history.HistoryPage;
import org.chromium.chrome.browser.vr_shell.rules.ChromeTabbedActivityVrTestRule;
import org.chromium.chrome.browser.vr_shell.util.VrTransitionUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
......@@ -214,6 +216,56 @@ public class VrShellControllerInputTest {
VrTestFramework.getHtmlTestFile("test_navigation_2d_page"));
}
/*
* Verifies that swiping up/down on the Daydream controller's touchpad
* scrolls a native page while in the VR browser.
*/
@Test
@MediumTest
public void testControllerScrollingNative() throws InterruptedException {
VrTransitionUtils.forceEnterVr();
VrTransitionUtils.waitForVrEntry(POLL_TIMEOUT_LONG_MS);
// Fill history with enough items to scroll
mVrTestRule.loadUrl(
VrTestFramework.getHtmlTestFile("test_navigation_2d_page"), PAGE_LOAD_TIMEOUT_S);
mVrTestRule.loadUrl(
VrTestFramework.getHtmlTestFile("test_controller_scrolling"), PAGE_LOAD_TIMEOUT_S);
mVrTestRule.loadUrl(
VrTestFramework.getHtmlTestFile("generic_webvr_page"), PAGE_LOAD_TIMEOUT_S);
mVrTestRule.loadUrl(
VrTestFramework.getHtmlTestFile("test_navigation_webvr_page"), PAGE_LOAD_TIMEOUT_S);
mVrTestRule.loadUrl(
VrTestFramework.getHtmlTestFile("test_webvr_autopresent"), PAGE_LOAD_TIMEOUT_S);
mVrTestRule.loadUrl(
VrTestFramework.getHtmlTestFile("generic_webxr_page"), PAGE_LOAD_TIMEOUT_S);
mVrTestRule.loadUrl(
VrTestFramework.getHtmlTestFile("test_gamepad_button"), PAGE_LOAD_TIMEOUT_S);
mVrTestRule.loadUrl("chrome://history", PAGE_LOAD_TIMEOUT_S);
RecyclerView recyclerView =
((HistoryPage) (mVrTestRule.getActivity().getActivityTab().getNativePage()))
.getHistoryManagerForTesting()
.getRecyclerViewForTests();
// Test that scrolling down works
int startScrollPoint = recyclerView.computeVerticalScrollOffset();
// Arbitrary, but valid values to scroll smoothly
int scrollSteps = 20;
int scrollSpeed = 60;
mController.scroll(EmulatedVrController.ScrollDirection.DOWN, scrollSteps, scrollSpeed,
/* fling */ false);
int endScrollPoint = recyclerView.computeVerticalScrollOffset();
Assert.assertTrue("Controller was able to scroll down", startScrollPoint < endScrollPoint);
// Test that scrolling up works
startScrollPoint = endScrollPoint;
mController.scroll(EmulatedVrController.ScrollDirection.UP, scrollSteps, scrollSpeed,
/* fling */ false);
endScrollPoint = recyclerView.computeVerticalScrollOffset();
Assert.assertTrue("Controller was able to scroll up", startScrollPoint > endScrollPoint);
}
/**
* Verifies that pressing the Daydream controller's 'app' button causes the user to exit
* fullscreen
......
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