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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTest.java

Issue 2851313002: Adds end-to-end tests for VrShell navigation transitions. (Closed)
Patch Set: Created 3 years, 8 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
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..02c0f5d4b183901957811e255de5affc80323568
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTest.java
@@ -0,0 +1,265 @@
+// 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.test.util.DOMUtils;
+
+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.
+ */
+@CommandLineFlags.Add("enable-features=VrShell")
bsheedy 2017/05/01 21:48:17 FYI, I think the enabling of VR Shell won't automa
tiborg 2017/05/01 23:09:46 Done.
+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 }
+
+ 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();
+ }
+ runJavaScriptOrFail("window.location.href = '" + testPageUrl + "';", POLL_TIMEOUT_SHORT_MS,
bsheedy 2017/05/01 21:48:16 Was there an issue using loadUrl() for this? It se
tiborg 2017/05/01 23:09:45 I was not sure how many steps of the transition lo
bsheedy 2017/05/01 23:36:31 Makes sense, although I'd add a comment explaining
tiborg 2017/05/02 14:15:02 Done.
+ 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();
+ }
+ });
+ }
+ }, POLL_TIMEOUT_LONG_MS);
+ assertTrue(
+ "Page loaded", pageLoadedLatch.await(POLL_TIMEOUT_LONG_MS, TimeUnit.MILLISECONDS));
+ }
+
+ private void goFullscreened() throws InterruptedException, TimeoutException {
bsheedy 2017/05/01 21:48:16 nit: goFullscreened sounds a little odd to me - ma
tiborg 2017/05/01 23:09:45 Done.
+ DOMUtils.clickNode(getActivity().getActivityTab().getContentViewCore(), "fullscreen");
bsheedy 2017/05/01 21:48:16 I would suggest changing goFullscreened() to goFul
tiborg 2017/05/01 23:09:46 Done.
+ waitOnJavaScriptStep(mWebContents);
+ assertTrue(DOMUtils.isFullscreen(
+ getActivity().getActivityTab().getContentViewCore().getWebContents()));
+ }
+
+ private void present() throws InterruptedException, TimeoutException {
bsheedy 2017/05/01 21:48:16 There's already a function to do this in VrTestBas
tiborg 2017/05/01 23:09:45 I considered changing enterVrTap. However, then We
+ DOMUtils.clickNode(getActivity().getActivityTab().getContentViewCore(), "webgl-canvas");
bsheedy 2017/05/01 21:48:16 Same comment as above - pass in a CVC and use that
tiborg 2017/05/01 23:09:46 Done.
+ waitOnJavaScriptStep(mWebContents);
+ assertTrue(VrShellDelegate.getVrShellForTesting().getWebVrModeEnabled());
+ }
+
+ private void assertState(Page page, PresentationMode presentationMode,
+ FullscreenMode fullscreenMode) throws InterruptedException, TimeoutException {
+ String url;
+ switch (page) {
+ 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();
+ }
+ assertTrue("Browser is in VR", VrShellDelegate.isInVr());
+ assertEquals(
+ "Browser is on correct web site", url, getActivity().getActivityTab().getUrl());
bsheedy 2017/05/01 21:48:17 Consider making assertState take a WebContents obj
tiborg 2017/05/01 23:09:45 Done.
+ assertEquals("Browser is in VR Presentation Mode",
+ presentationMode == PresentationMode.PRESENTING,
+ VrShellDelegate.getVrShellForTesting().getWebVrModeEnabled());
+ assertEquals("Browser is in fullscreen", fullscreenMode == FullscreenMode.FULLSCREENED,
+ DOMUtils.isFullscreen(
+ getActivity().getActivityTab().getContentViewCore().getWebContents()));
+ }
+
+ @Override
+ public int loadUrl(String url, long secondsToWait)
bsheedy 2017/05/01 21:48:16 I think the base loadUrl blocks until the page is
tiborg 2017/05/01 23:09:46 I'm not sure if loadUrl waits until all resources
bsheedy 2017/05/01 23:36:31 In that case, I'll consider moving this into VrTes
tiborg 2017/05/02 14:15:02 Sounds good.
+ throws IllegalArgumentException, InterruptedException {
+ int result = super.loadUrl(url, secondsToWait);
+ waitOnJavaScriptStep(mWebContents);
+ return result;
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ VrUtils.forceEnterVr();
+ VrUtils.waitForVrSupported(POLL_TIMEOUT_LONG_MS);
+ assertTrue(VrShellDelegate.isInVr());
bsheedy 2017/05/01 21:48:16 nit: This assert doesn't really do anything since
tiborg 2017/05/01 23:09:46 Done.
+ }
+
+ @Override
+ public void startMainActivity() throws InterruptedException {
bsheedy 2017/05/01 21:48:17 Unnecessary override since VrTestBase's startMainA
tiborg 2017/05/01 23:09:45 Done.
+ startMainActivityOnBlankPage();
+ }
+
+ @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
bsheedy 2017/05/01 21:48:16 Since every test here seems to have the same restr
tiborg 2017/05/01 23:09:46 Done.
+ @MediumTest
+ public void test2dTo2d() throws InterruptedException, TimeoutException {
bsheedy 2017/05/01 21:48:17 I think test cases are supposed to have comments b
tiborg 2017/05/01 23:09:45 Done.
+ // Arrange.
bsheedy 2017/05/01 21:48:17 nit: The arrange/act/assert comments seem unnecess
tiborg 2017/05/01 23:09:45 Done.
+ loadUrl(TEST_PAGE_2D_URL, PAGE_LOAD_TIMEOUT_S);
+
+ // Act.
+ navigateTo(Page.PAGE_2D);
+
+ // Assert.
+ assertState(Page.PAGE_2D, PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
+ }
+
+ @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
+ @MediumTest
+ public void test2dToWebVr()
+ throws IllegalArgumentException, InterruptedException, TimeoutException {
+ // Arrange.
+ loadUrl(TEST_PAGE_2D_URL, PAGE_LOAD_TIMEOUT_S);
+
+ // Act.
+ navigateTo(Page.PAGE_WEBVR);
+
+ // Assert.
+ assertState(
+ Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
+ }
+
+ @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
+ @MediumTest
+ public void test2dFullscreenToWebVr()
+ throws IllegalArgumentException, InterruptedException, TimeoutException {
+ // Arrange.
+ loadUrl(TEST_PAGE_2D_URL, PAGE_LOAD_TIMEOUT_S);
+ goFullscreened();
+
+ // Act.
+ navigateTo(Page.PAGE_WEBVR);
+
+ // Assert.
+ assertState(
+ Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
+ }
+
+ @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
+ @MediumTest
+ public void testWebVrTo2d()
+ throws IllegalArgumentException, InterruptedException, TimeoutException {
+ // Arrange.
+ loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
+
+ // Act.
+ navigateTo(Page.PAGE_2D);
+
+ // Assert.
+ assertState(Page.PAGE_2D, PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
+ }
+
+ @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
+ @MediumTest
+ public void testWebVrToWebVr()
+ throws IllegalArgumentException, InterruptedException, TimeoutException {
+ // Arrange.
+ loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
+
+ // Act.
+ navigateTo(Page.PAGE_WEBVR);
+
+ // Assert.
+ assertState(
+ Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
+ }
+
+ @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
+ @MediumTest
+ public void testWebVrPresentingTo2d()
+ throws IllegalArgumentException, InterruptedException, TimeoutException {
+ // Arrange.
+ loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
+ present();
+
+ // Act.
+ navigateTo(Page.PAGE_2D);
+
+ // Assert.
+ assertState(Page.PAGE_2D, PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
+ }
+
+ @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
+ @MediumTest
+ public void testWebVrPresentingToWebVr()
+ throws IllegalArgumentException, InterruptedException, TimeoutException {
+ // Arrange.
+ loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
+ present();
+
+ // Act.
+ navigateTo(Page.PAGE_WEBVR);
+
+ // Assert.
+ assertState(
+ Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
+ }
+
+ @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
+ @MediumTest
+ public void testWebVrFullscreenTo2d()
+ throws IllegalArgumentException, InterruptedException, TimeoutException {
+ // Arrange.
+ loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
+ goFullscreened();
+
+ // Act.
+ navigateTo(Page.PAGE_2D);
+
+ // Assert.
+ assertState(Page.PAGE_2D, PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
+ }
+
+ @Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
+ @MediumTest
+ public void testWebVrFullscreenToWebVr()
+ throws IllegalArgumentException, InterruptedException, TimeoutException {
+ // Arrange.
+ loadUrl(TEST_PAGE_WEBVR_URL, PAGE_LOAD_TIMEOUT_S);
+ goFullscreened();
+
+ // Act.
+ navigateTo(Page.PAGE_WEBVR);
+
+ // Assert.
+ assertState(
+ Page.PAGE_WEBVR, PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698