Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b01b129553c3ca1d9b1ed419f73737c72510cd1b |
| --- /dev/null |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTest.java |
| @@ -0,0 +1,268 @@ |
| +// Copyright 2017 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.chrome.browser.vr_shell; |
| + |
| +import static org.chromium.chrome.browser.vr_shell.VrUtils.POLL_TIMEOUT_LONG_MS; |
| +import static org.chromium.chrome.browser.vr_shell.VrUtils.POLL_TIMEOUT_SHORT_MS; |
| +import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_VIEWER_DAYDREAM; |
| + |
| +import android.support.test.filters.MediumTest; |
| + |
| +import org.chromium.base.ThreadUtils; |
| +import org.chromium.base.test.util.CommandLineFlags; |
| +import org.chromium.base.test.util.Restriction; |
| +import org.chromium.chrome.test.util.ChromeTabUtils; |
| +import org.chromium.content.browser.ContentViewCore; |
| +import org.chromium.content.browser.test.util.DOMUtils; |
| +import org.chromium.content_public.browser.WebContents; |
| + |
| +import java.util.concurrent.CountDownLatch; |
| +import java.util.concurrent.TimeUnit; |
| +import java.util.concurrent.TimeoutException; |
| + |
| +/** |
| + * End-to-end tests for testing navigation transitions (e.g. link clicking) in VR Browser mode, aka |
| + * "VR Shell". This may require interacting with WebVR in addition to the VR browser, so inherit |
| + * from VrTestBase for the WebVR test framework. |
| + */ |
| +@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM) |
| +@CommandLineFlags.Add("enable-features=VrShell") |
| +public class VrShellNavigationTest extends VrTestBase { |
| + private static final String TEST_PAGE_2D_URL = |
| + VrTestBase.getHtmlTestFile("test_navigation_2d_page"); |
| + private static final String TEST_PAGE_WEBVR_URL = |
| + VrTestBase.getHtmlTestFile("test_navigation_webvr_page"); |
| + |
| + private enum Page { PAGE_2D, PAGE_WEBVR } |
| + private enum PresentationMode { NON_PRESENTING, PRESENTING } |
| + private enum FullscreenMode { NON_FULLSCREENED, FULLSCREENED } |
| + |
| + /** |
| + * Triggers navigation to either a 2D or WebVR page. Similar to |
| + * {@link ChromeActivityTestCaseBase#loadUrl loadUrl} but makes sure page initiates the |
| + * navigation. This is desirable since we are testing navigation transitions end-to-end. |
| + */ |
| + private void navigateTo(Page to) throws InterruptedException { |
| + // Trigger navigation to new page. |
| + String testPageUrl; |
| + switch (to) { |
| + case PAGE_2D: |
| + testPageUrl = TEST_PAGE_2D_URL + "?id=0"; |
| + break; |
| + case PAGE_WEBVR: |
| + testPageUrl = TEST_PAGE_WEBVR_URL + "?id=0"; |
| + break; |
| + default: |
| + throw new UnsupportedOperationException("Don't know page type " + to); |
| + } |
| + runJavaScriptOrFail("window.location.href = '" + testPageUrl + "';", POLL_TIMEOUT_SHORT_MS, |
|
David Trainor- moved to gerrit
2017/05/02 15:56:40
Should this just load the URL on the WebContents'
tiborg
2017/05/03 19:43:58
bsheedy@ and I discussed this. I chose to let the
|
| + mWebContents); |
| + // Wait until new page is loaded. |
| + final CountDownLatch pageLoadedLatch = new CountDownLatch(1); |
| + ChromeTabUtils.waitForTabPageLoaded(getActivity().getActivityTab(), new Runnable() { |
| + @Override |
| + public void run() { |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + pageLoadedLatch.countDown(); |
|
David Trainor- moved to gerrit
2017/05/02 15:56:40
I think this trigger action is supposed to actuall
tiborg
2017/05/03 19:43:58
Ohh, that makes a lot of sense! Changed it. Works
|
| + } |
| + }); |
| + } |
| + }, POLL_TIMEOUT_LONG_MS); |
| + assertTrue( |
| + "Page loaded", pageLoadedLatch.await(POLL_TIMEOUT_LONG_MS, TimeUnit.MILLISECONDS)); |
|
David Trainor- moved to gerrit
2017/05/02 15:56:40
Might not need this. The waitForTabPageLoaded is
tiborg
2017/05/03 19:43:58
Done.
|
| + } |
| + |
| + private void enterFullscreen(ContentViewCore cvc) |
| + throws InterruptedException, TimeoutException { |
| + DOMUtils.clickNode(cvc, "fullscreen"); |
| + waitOnJavaScriptStep(cvc.getWebContents()); |
| + assertTrue(DOMUtils.isFullscreen(cvc.getWebContents())); |
| + } |
| + |
| + private void present(ContentViewCore cvc) throws InterruptedException, TimeoutException { |
| + // 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()); |
| + } |
| + |
| + private void assertState(WebContents wc, Page page, PresentationMode presentationMode, |
| + FullscreenMode fullscreenMode) throws InterruptedException, TimeoutException { |
| + String url; |
| + switch (page) { |
|
David Trainor- moved to gerrit
2017/05/02 15:56:40
Maybe pull this and the code above out to a getUrl
tiborg
2017/05/03 19:43:58
Done.
|
| + case PAGE_2D: |
| + url = TEST_PAGE_2D_URL + "?id=0"; |
| + break; |
| + case PAGE_WEBVR: |
| + url = TEST_PAGE_WEBVR_URL + "?id=0"; |
| + break; |
| + default: |
| + throw new UnsupportedOperationException("Don't know page type " + page); |
| + } |
| + assertTrue("Browser is in VR", VrShellDelegate.isInVr()); |
| + assertEquals("Browser is on correct web site", url, wc.getVisibleUrl()); |
| + assertEquals("Browser is in VR Presentation Mode", |
| + presentationMode == PresentationMode.PRESENTING, |
| + VrShellDelegate.getVrShellForTesting().getWebVrModeEnabled()); |
| + 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()); |
| + return result; |
| + } |
| + |
| + @Override |
| + protected void setUp() throws Exception { |
| + super.setUp(); |
| + VrUtils.forceEnterVr(); |
| + VrUtils.waitForVrSupported(POLL_TIMEOUT_LONG_MS); |
| + } |
| + |
| + /** |
| + * Tests navigation from a 2D to a 2D page. |
| + */ |
| + @MediumTest |
| + public void test2dTo2d() throws InterruptedException, TimeoutException { |
| + loadUrl(TEST_PAGE_2D_URL, PAGE_LOAD_TIMEOUT_S); |
| + |
| + navigateTo(Page.PAGE_2D); |
|
David Trainor- moved to gerrit
2017/05/02 15:56:40
Should these just be loadUrl() calls?
tiborg
2017/05/03 19:43:58
As mentioned in my comment above, I wanted to make
|
| + |
| + assertState(mWebContents, Page.PAGE_2D, PresentationMode.NON_PRESENTING, |
| + FullscreenMode.NON_FULLSCREENED); |
| + } |
| + |
| + /** |
| + * Tests navigation from a 2D to a WebVR page. |
| + */ |
| + @CommandLineFlags.Add("enable-webvr") |
| + @MediumTest |
| + public void test2dToWebVr() |
| + throws IllegalArgumentException, InterruptedException, TimeoutException { |
| + loadUrl(TEST_PAGE_2D_URL, PAGE_LOAD_TIMEOUT_S); |
| + |
| + navigateTo(Page.PAGE_WEBVR); |
| + |
| + assertState(mWebContents, Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING, |
| + FullscreenMode.NON_FULLSCREENED); |
| + } |
| + |
| + /** |
| + * Tests navigation from a fullscreened 2D to a WebVR page. |
| + */ |
| + @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()); |
| + |
| + navigateTo(Page.PAGE_WEBVR); |
| + |
| + assertState(mWebContents, Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING, |
| + FullscreenMode.NON_FULLSCREENED); |
| + } |
| + |
| + /** |
| + * Tests navigation from a WebVR to a 2D page. |
| + */ |
| + @CommandLineFlags.Add("enable-webvr") |
| + @MediumTest |
| + public void testWebVrTo2d() |
| + throws IllegalArgumentException, InterruptedException, TimeoutException { |
| + loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S); |
| + |
| + navigateTo(Page.PAGE_2D); |
| + |
| + assertState(mWebContents, Page.PAGE_2D, PresentationMode.NON_PRESENTING, |
| + FullscreenMode.NON_FULLSCREENED); |
| + } |
| + |
| + /** |
| + * Tests navigation from a WebVR to a WebVR page. |
| + */ |
| + @CommandLineFlags.Add("enable-webvr") |
| + @MediumTest |
| + public void testWebVrToWebVr() |
| + throws IllegalArgumentException, InterruptedException, TimeoutException { |
| + loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S); |
| + |
| + navigateTo(Page.PAGE_WEBVR); |
| + |
| + assertState(mWebContents, Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING, |
| + FullscreenMode.NON_FULLSCREENED); |
| + } |
| + |
| + /** |
| + * Tests navigation from a presenting WebVR to a 2D page. |
| + */ |
| + @CommandLineFlags.Add("enable-webvr") |
| + @MediumTest |
| + public void testWebVrPresentingTo2d() |
| + throws IllegalArgumentException, InterruptedException, TimeoutException { |
| + loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S); |
| + present(getActivity().getActivityTab().getContentViewCore()); |
| + |
| + navigateTo(Page.PAGE_2D); |
| + |
| + assertState(mWebContents, Page.PAGE_2D, PresentationMode.NON_PRESENTING, |
| + FullscreenMode.NON_FULLSCREENED); |
| + } |
| + |
| + /** |
| + * Tests navigation from a presenting WebVR to a WebVR page. |
| + */ |
| + @CommandLineFlags.Add("enable-webvr") |
| + @MediumTest |
| + public void testWebVrPresentingToWebVr() |
| + throws IllegalArgumentException, InterruptedException, TimeoutException { |
| + loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S); |
| + present(getActivity().getActivityTab().getContentViewCore()); |
| + |
| + navigateTo(Page.PAGE_WEBVR); |
| + |
| + assertState(mWebContents, Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING, |
| + FullscreenMode.NON_FULLSCREENED); |
| + } |
| + |
| + /** |
| + * Tests navigation from a fullscreened WebVR to a 2D page. |
| + */ |
| + @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()); |
| + |
| + navigateTo(Page.PAGE_2D); |
| + |
| + assertState(mWebContents, Page.PAGE_2D, PresentationMode.NON_PRESENTING, |
| + FullscreenMode.NON_FULLSCREENED); |
| + } |
| + |
| + /** |
| + * Tests navigation from a fullscreened WebVR to a WebVR page. |
| + */ |
| + @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()); |
| + |
| + navigateTo(Page.PAGE_WEBVR); |
| + |
| + assertState(mWebContents, Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING, |
| + FullscreenMode.NON_FULLSCREENED); |
| + } |
| +} |