| Index: chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTest.java
|
| index b9fb03656cef2dd9807b6cc648d62ad54ab54395..a978bd6d12fd5475daf2d9d3a439884747582a03 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTest.java
|
| @@ -10,8 +10,18 @@ import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_V
|
|
|
| import android.support.test.filters.MediumTest;
|
|
|
| +import org.junit.Assert;
|
| +import org.junit.Before;
|
| +import org.junit.Rule;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
| +
|
| import org.chromium.base.test.util.CommandLineFlags;
|
| import org.chromium.base.test.util.Restriction;
|
| +import org.chromium.chrome.browser.ChromeSwitches;
|
| +import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| +import org.chromium.chrome.test.ChromeActivityTestRule;
|
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| import org.chromium.chrome.test.util.ChromeTabUtils;
|
| import org.chromium.content.browser.ContentViewCore;
|
| import org.chromium.content.browser.test.util.DOMUtils;
|
| @@ -24,13 +34,19 @@ import java.util.concurrent.TimeoutException;
|
| * "VR Shell". This may require interacting with WebVR in addition to the VR browser, so inherit
|
| * from VrTestBase for the WebVR test framework.
|
| */
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| +@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| + ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG, "enable-features=VrShell"})
|
| @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
|
| -@CommandLineFlags.Add("enable-features=VrShell")
|
| -public class VrShellNavigationTest extends VrTestBase {
|
| +
|
| +public class VrShellNavigationTest {
|
| + @Rule
|
| + public VrTestRule mVrTestRule = new VrTestRule();
|
| +
|
| private static final String TEST_PAGE_2D_URL =
|
| - VrTestBase.getHtmlTestFile("test_navigation_2d_page");
|
| + VrTestRule.getHtmlTestFile("test_navigation_2d_page");
|
| private static final String TEST_PAGE_WEBVR_URL =
|
| - VrTestBase.getHtmlTestFile("test_navigation_webvr_page");
|
| + VrTestRule.getHtmlTestFile("test_navigation_webvr_page");
|
|
|
| private enum Page { PAGE_2D, PAGE_WEBVR }
|
| private enum PresentationMode { NON_PRESENTING, PRESENTING }
|
| @@ -53,20 +69,22 @@ public class VrShellNavigationTest extends VrTestBase {
|
| * navigation. This is desirable since we are testing navigation transitions end-to-end.
|
| */
|
| private void navigateTo(final Page to) throws InterruptedException {
|
| - ChromeTabUtils.waitForTabPageLoaded(getActivity().getActivityTab(), new Runnable() {
|
| - @Override
|
| - public void run() {
|
| - runJavaScriptOrFail("window.location.href = '" + getUrl(to) + "';",
|
| - POLL_TIMEOUT_SHORT_MS, mWebContents);
|
| - }
|
| - }, POLL_TIMEOUT_LONG_MS);
|
| + ChromeTabUtils.waitForTabPageLoaded(
|
| + mVrTestRule.getActivity().getActivityTab(), new Runnable() {
|
| + @Override
|
| + public void run() {
|
| + mVrTestRule.runJavaScriptOrFail(
|
| + "window.location.href = '" + getUrl(to) + "';",
|
| + POLL_TIMEOUT_SHORT_MS, mVrTestRule.getWebContents());
|
| + }
|
| + }, POLL_TIMEOUT_LONG_MS);
|
| }
|
|
|
| private void enterFullscreen(ContentViewCore cvc)
|
| throws InterruptedException, TimeoutException {
|
| DOMUtils.clickNode(cvc, "fullscreen");
|
| - waitOnJavaScriptStep(cvc.getWebContents());
|
| - assertTrue(DOMUtils.isFullscreen(cvc.getWebContents()));
|
| + mVrTestRule.waitOnJavaScriptStep(cvc.getWebContents());
|
| + Assert.assertTrue(DOMUtils.isFullscreen(cvc.getWebContents()));
|
| }
|
|
|
| private void enterPresentation(ContentViewCore cvc)
|
| @@ -74,32 +92,31 @@ public class VrShellNavigationTest extends VrTestBase {
|
| // TODO(bsheedy): check if we could use DOMUtils.clickNode in VrTestBase#enterVrTap and
|
| // then use VrTestBase#enterVrTap here.
|
| DOMUtils.clickNode(cvc, "webgl-canvas");
|
| - waitOnJavaScriptStep(mWebContents);
|
| - assertTrue(VrShellDelegate.getVrShellForTesting().getWebVrModeEnabled());
|
| + mVrTestRule.waitOnJavaScriptStep(mVrTestRule.getWebContents());
|
| + Assert.assertTrue(VrShellDelegate.getVrShellForTesting().getWebVrModeEnabled());
|
| }
|
|
|
| private void assertState(WebContents wc, Page page, PresentationMode presentationMode,
|
| FullscreenMode fullscreenMode) throws InterruptedException, TimeoutException {
|
| - assertTrue("Browser is in VR", VrShellDelegate.isInVr());
|
| - assertEquals("Browser is on correct web site", getUrl(page), wc.getVisibleUrl());
|
| - assertEquals("Browser is in VR Presentation Mode",
|
| + Assert.assertTrue("Browser is in VR", VrShellDelegate.isInVr());
|
| + Assert.assertEquals("Browser is on correct web site", getUrl(page), wc.getVisibleUrl());
|
| + Assert.assertEquals("Browser is in VR Presentation Mode",
|
| presentationMode == PresentationMode.PRESENTING,
|
| VrShellDelegate.getVrShellForTesting().getWebVrModeEnabled());
|
| - assertEquals("Browser is in fullscreen", fullscreenMode == FullscreenMode.FULLSCREENED,
|
| - DOMUtils.isFullscreen(wc));
|
| + Assert.assertEquals("Browser is in fullscreen",
|
| + fullscreenMode == FullscreenMode.FULLSCREENED, DOMUtils.isFullscreen(wc));
|
| }
|
|
|
| - @Override
|
| public int loadUrl(String url, long secondsToWait)
|
| throws IllegalArgumentException, InterruptedException {
|
| - int result = super.loadUrl(url, secondsToWait);
|
| - waitOnJavaScriptStep(getActivity().getActivityTab().getWebContents());
|
| + int result = mVrTestRule.loadUrl(url, secondsToWait);
|
| + mVrTestRule.waitOnJavaScriptStep(
|
| + mVrTestRule.getActivity().getActivityTab().getWebContents());
|
| return result;
|
| }
|
|
|
| - @Override
|
| - protected void setUp() throws Exception {
|
| - super.setUp();
|
| + @Before
|
| + public void setUp() throws Exception {
|
| VrUtils.forceEnterVr();
|
| VrUtils.waitForVrSupported(POLL_TIMEOUT_LONG_MS);
|
| }
|
| @@ -107,138 +124,147 @@ public class VrShellNavigationTest extends VrTestBase {
|
| /**
|
| * Tests navigation from a 2D to a 2D page.
|
| */
|
| + @Test
|
| @MediumTest
|
| public void test2dTo2d() throws InterruptedException, TimeoutException {
|
| - loadUrl(TEST_PAGE_2D_URL, PAGE_LOAD_TIMEOUT_S);
|
| + loadUrl(TEST_PAGE_2D_URL, VrTestRule.PAGE_LOAD_TIMEOUT_S);
|
|
|
| navigateTo(Page.PAGE_2D);
|
|
|
| - assertState(mWebContents, Page.PAGE_2D, PresentationMode.NON_PRESENTING,
|
| + assertState(mVrTestRule.getWebContents(), Page.PAGE_2D, PresentationMode.NON_PRESENTING,
|
| FullscreenMode.NON_FULLSCREENED);
|
| }
|
|
|
| /**
|
| * Tests navigation from a 2D to a WebVR page.
|
| */
|
| + @Test
|
| @CommandLineFlags.Add("enable-webvr")
|
| @MediumTest
|
| public void test2dToWebVr()
|
| throws IllegalArgumentException, InterruptedException, TimeoutException {
|
| - loadUrl(TEST_PAGE_2D_URL, PAGE_LOAD_TIMEOUT_S);
|
| + loadUrl(TEST_PAGE_2D_URL, VrTestRule.PAGE_LOAD_TIMEOUT_S);
|
|
|
| navigateTo(Page.PAGE_WEBVR);
|
|
|
| - assertState(mWebContents, Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING,
|
| + assertState(mVrTestRule.getWebContents(), Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING,
|
| FullscreenMode.NON_FULLSCREENED);
|
| }
|
|
|
| /**
|
| * Tests navigation from a fullscreened 2D to a WebVR page.
|
| */
|
| + @Test
|
| @CommandLineFlags.Add("enable-webvr")
|
| @MediumTest
|
| public void test2dFullscreenToWebVr()
|
| throws IllegalArgumentException, InterruptedException, TimeoutException {
|
| - loadUrl(TEST_PAGE_2D_URL, PAGE_LOAD_TIMEOUT_S);
|
| - enterFullscreen(getActivity().getActivityTab().getContentViewCore());
|
| + loadUrl(TEST_PAGE_2D_URL, VrTestRule.PAGE_LOAD_TIMEOUT_S);
|
| + enterFullscreen(mVrTestRule.getActivity().getActivityTab().getContentViewCore());
|
|
|
| navigateTo(Page.PAGE_WEBVR);
|
|
|
| - assertState(mWebContents, Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING,
|
| + assertState(mVrTestRule.getWebContents(), Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING,
|
| FullscreenMode.NON_FULLSCREENED);
|
| }
|
|
|
| /**
|
| * Tests navigation from a WebVR to a 2D page.
|
| */
|
| + @Test
|
| @CommandLineFlags.Add("enable-webvr")
|
| @MediumTest
|
| public void testWebVrTo2d()
|
| throws IllegalArgumentException, InterruptedException, TimeoutException {
|
| - loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
|
| + loadUrl(TEST_PAGE_WEBVR_URL, VrTestRule.PAGE_LOAD_TIMEOUT_S);
|
|
|
| navigateTo(Page.PAGE_2D);
|
|
|
| - assertState(mWebContents, Page.PAGE_2D, PresentationMode.NON_PRESENTING,
|
| + assertState(mVrTestRule.getWebContents(), Page.PAGE_2D, PresentationMode.NON_PRESENTING,
|
| FullscreenMode.NON_FULLSCREENED);
|
| }
|
|
|
| /**
|
| * Tests navigation from a WebVR to a WebVR page.
|
| */
|
| + @Test
|
| @CommandLineFlags.Add("enable-webvr")
|
| @MediumTest
|
| public void testWebVrToWebVr()
|
| throws IllegalArgumentException, InterruptedException, TimeoutException {
|
| - loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
|
| + loadUrl(TEST_PAGE_WEBVR_URL, VrTestRule.PAGE_LOAD_TIMEOUT_S);
|
|
|
| navigateTo(Page.PAGE_WEBVR);
|
|
|
| - assertState(mWebContents, Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING,
|
| + assertState(mVrTestRule.getWebContents(), Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING,
|
| FullscreenMode.NON_FULLSCREENED);
|
| }
|
|
|
| /**
|
| * Tests navigation from a presenting WebVR to a 2D page.
|
| */
|
| + @Test
|
| @CommandLineFlags.Add("enable-webvr")
|
| @MediumTest
|
| public void testWebVrPresentingTo2d()
|
| throws IllegalArgumentException, InterruptedException, TimeoutException {
|
| - loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
|
| - enterPresentation(getActivity().getActivityTab().getContentViewCore());
|
| + loadUrl(TEST_PAGE_WEBVR_URL, VrTestRule.PAGE_LOAD_TIMEOUT_S);
|
| + enterPresentation(mVrTestRule.getActivity().getActivityTab().getContentViewCore());
|
|
|
| navigateTo(Page.PAGE_2D);
|
|
|
| - assertState(mWebContents, Page.PAGE_2D, PresentationMode.NON_PRESENTING,
|
| + assertState(mVrTestRule.getWebContents(), Page.PAGE_2D, PresentationMode.NON_PRESENTING,
|
| FullscreenMode.NON_FULLSCREENED);
|
| }
|
|
|
| /**
|
| * Tests navigation from a presenting WebVR to a WebVR page.
|
| */
|
| + @Test
|
| @CommandLineFlags.Add("enable-webvr")
|
| @MediumTest
|
| public void testWebVrPresentingToWebVr()
|
| throws IllegalArgumentException, InterruptedException, TimeoutException {
|
| - loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
|
| - enterPresentation(getActivity().getActivityTab().getContentViewCore());
|
| + loadUrl(TEST_PAGE_WEBVR_URL, VrTestRule.PAGE_LOAD_TIMEOUT_S);
|
| + enterPresentation(mVrTestRule.getActivity().getActivityTab().getContentViewCore());
|
|
|
| navigateTo(Page.PAGE_WEBVR);
|
|
|
| - assertState(mWebContents, Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING,
|
| + assertState(mVrTestRule.getWebContents(), Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING,
|
| FullscreenMode.NON_FULLSCREENED);
|
| }
|
|
|
| /**
|
| * Tests navigation from a fullscreened WebVR to a 2D page.
|
| */
|
| + @Test
|
| @CommandLineFlags.Add("enable-webvr")
|
| @MediumTest
|
| public void testWebVrFullscreenTo2d()
|
| throws IllegalArgumentException, InterruptedException, TimeoutException {
|
| - loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
|
| - enterFullscreen(getActivity().getActivityTab().getContentViewCore());
|
| + loadUrl(TEST_PAGE_WEBVR_URL, VrTestRule.PAGE_LOAD_TIMEOUT_S);
|
| + enterFullscreen(mVrTestRule.getActivity().getActivityTab().getContentViewCore());
|
|
|
| navigateTo(Page.PAGE_2D);
|
|
|
| - assertState(mWebContents, Page.PAGE_2D, PresentationMode.NON_PRESENTING,
|
| + assertState(mVrTestRule.getWebContents(), Page.PAGE_2D, PresentationMode.NON_PRESENTING,
|
| FullscreenMode.NON_FULLSCREENED);
|
| }
|
|
|
| /**
|
| * Tests navigation from a fullscreened WebVR to a WebVR page.
|
| */
|
| + @Test
|
| @CommandLineFlags.Add("enable-webvr")
|
| @MediumTest
|
| public void testWebVrFullscreenToWebVr()
|
| throws IllegalArgumentException, InterruptedException, TimeoutException {
|
| - loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
|
| - enterFullscreen(getActivity().getActivityTab().getContentViewCore());
|
| + loadUrl(TEST_PAGE_WEBVR_URL, VrTestRule.PAGE_LOAD_TIMEOUT_S);
|
| + enterFullscreen(mVrTestRule.getActivity().getActivityTab().getContentViewCore());
|
|
|
| navigateTo(Page.PAGE_WEBVR);
|
|
|
| - assertState(mWebContents, Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING,
|
| + assertState(mVrTestRule.getWebContents(), Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING,
|
| FullscreenMode.NON_FULLSCREENED);
|
| }
|
| }
|
|
|