Commit 4ff66377 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Port VrShellNavigationTest to WebXR

Adds VrShellNavigationTestWebXr, which contains copies of all the tests
in VrShellNavigationTest that make use of WebVR. These will be merged
back in to VrShellNavigationTest once WebVR is removed.

Bug: 804043
Change-Id: I50c6a8618d9f1ef09de92a44b88aef5dff4bd46d
Reviewed-on: https://chromium-review.googlesource.com/887165Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533318}
parent 3184e875
...@@ -631,6 +631,7 @@ if (enable_vr) { ...@@ -631,6 +631,7 @@ if (enable_vr) {
"javatests/src/org/chromium/chrome/browser/vr_shell/VrShellControllerInputTest.java", "javatests/src/org/chromium/chrome/browser/vr_shell/VrShellControllerInputTest.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNativeUiTest.java", "javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNativeUiTest.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTest.java", "javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTest.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/VrShellNavigationTestWebXr.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/VrShellTransitionTest.java", "javatests/src/org/chromium/chrome/browser/vr_shell/VrShellTransitionTest.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/VrTestFramework.java", "javatests/src/org/chromium/chrome/browser/vr_shell/VrTestFramework.java",
"javatests/src/org/chromium/chrome/browser/vr_shell/WebVrDeviceTest.java", "javatests/src/org/chromium/chrome/browser/vr_shell/WebVrDeviceTest.java",
......
...@@ -291,7 +291,8 @@ public class VrShellNavigationTest { ...@@ -291,7 +291,8 @@ public class VrShellNavigationTest {
} }
/** /**
* Tests navigation from a fullscreened WebVR to a WebVR page. * Tests that the back button is disabled in VR if pressing it in regular 2D Chrome would result
* in Chrome being backgrounded.
*/ */
@Test @Test
@MediumTest @MediumTest
......
// Copyright 2018 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.XrTestFramework.PAGE_LOAD_TIMEOUT_S;
import static org.chromium.chrome.browser.vr_shell.XrTestFramework.POLL_TIMEOUT_LONG_MS;
import static org.chromium.chrome.browser.vr_shell.XrTestFramework.POLL_TIMEOUT_SHORT_MS;
import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_DEVICE_DAYDREAM;
import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_VIEWER_DAYDREAM;
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.browser.vr_shell.rules.ChromeTabbedActivityVrTestRule;
import org.chromium.chrome.browser.vr_shell.util.VrInfoBarUtils;
import org.chromium.chrome.browser.vr_shell.util.XrTransitionUtils;
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;
import org.chromium.content_public.browser.WebContents;
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 is a temporary class for testing navigation with WebXR - it will be merged with
* VrShellNavigationTest once WebVR is replaced with WebXR.
*/
@RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, "enable-features=WebXR"})
@Restriction(RESTRICTION_TYPE_DEVICE_DAYDREAM)
public class VrShellNavigationTestWebXr {
// We explicitly instantiate a rule here instead of using parameterization since this class
// only ever runs in ChromeTabbedActivity.
@Rule
public ChromeTabbedActivityVrTestRule mVrTestRule = new ChromeTabbedActivityVrTestRule();
private XrTestFramework mXrTestFramework;
private static final String TEST_PAGE_2D_URL =
XrTestFramework.getHtmlTestFile("test_navigation_2d_page");
private static final String TEST_PAGE_WEBXR_URL =
XrTestFramework.getHtmlTestFile("test_navigation_webxr_page");
private enum Page { PAGE_2D, PAGE_WEBXR }
private enum PresentationMode { NON_PRESENTING, PRESENTING }
private enum FullscreenMode { NON_FULLSCREENED, FULLSCREENED }
@Before
public void setUp() throws Exception {
mXrTestFramework = new XrTestFramework(mVrTestRule);
XrTransitionUtils.forceEnterVr();
XrTransitionUtils.waitForVrEntry(POLL_TIMEOUT_LONG_MS);
}
private String getUrl(Page page) {
switch (page) {
case PAGE_2D:
return TEST_PAGE_2D_URL + "?id=0";
case PAGE_WEBXR:
return TEST_PAGE_WEBXR_URL + "?id=0";
default:
throw new UnsupportedOperationException("Don't know page type " + page);
}
}
/**
* Triggers navigation to either a 2D or WebXR page. Similar to
* {@link ChromeActivityTestRule#loadUrl loadUrl} but makes sure page initiates the
* navigation. This is desirable since we are testing navigation transitions end-to-end.
*/
private void navigateTo(final Page to) throws InterruptedException {
ChromeTabUtils.waitForTabPageLoaded(
mVrTestRule.getActivity().getActivityTab(), new Runnable() {
@Override
public void run() {
XrTestFramework.runJavaScriptOrFail(
"window.location.href = '" + getUrl(to) + "';",
POLL_TIMEOUT_SHORT_MS, mXrTestFramework.getFirstTabWebContents());
}
}, POLL_TIMEOUT_LONG_MS);
}
private void enterFullscreenOrFail(ContentViewCore cvc)
throws InterruptedException, TimeoutException {
DOMUtils.clickNode(cvc, "fullscreen", false /* goThroughRootAndroidView */);
XrTestFramework.waitOnJavaScriptStep(cvc.getWebContents());
Assert.assertTrue(DOMUtils.isFullscreen(cvc.getWebContents()));
}
private void assertState(WebContents wc, Page page, PresentationMode presentationMode,
FullscreenMode fullscreenMode) throws InterruptedException, TimeoutException {
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,
TestVrShellDelegate.getVrShellForTesting().getWebVrModeEnabled());
Assert.assertEquals("Browser is in fullscreen",
fullscreenMode == FullscreenMode.FULLSCREENED, DOMUtils.isFullscreen(wc));
// Feedback infobar should never show up during navigations.
VrInfoBarUtils.expectInfoBarPresent(mXrTestFramework, false);
}
/**
* Tests navigation from a 2D to a WebXR page.
*/
@Test
@MediumTest
public void test2dToWebXr()
throws IllegalArgumentException, InterruptedException, TimeoutException {
mXrTestFramework.loadUrlAndAwaitInitialization(TEST_PAGE_2D_URL, PAGE_LOAD_TIMEOUT_S);
navigateTo(Page.PAGE_WEBXR);
assertState(mXrTestFramework.getFirstTabWebContents(), Page.PAGE_WEBXR,
PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
}
/**
* Tests navigation from a fullscreened 2D to a WebXR page.
*/
@Test
@MediumTest
public void test2dFullscreenToWebXr()
throws IllegalArgumentException, InterruptedException, TimeoutException {
mXrTestFramework.loadUrlAndAwaitInitialization(TEST_PAGE_2D_URL, PAGE_LOAD_TIMEOUT_S);
enterFullscreenOrFail(mXrTestFramework.getFirstTabCvc());
navigateTo(Page.PAGE_WEBXR);
assertState(mXrTestFramework.getFirstTabWebContents(), Page.PAGE_WEBXR,
PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
}
/**
* Tests navigation from a WebXR to a 2D page.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testWebXrTo2d()
throws IllegalArgumentException, InterruptedException, TimeoutException {
mXrTestFramework.loadUrlAndAwaitInitialization(TEST_PAGE_WEBXR_URL, PAGE_LOAD_TIMEOUT_S);
navigateTo(Page.PAGE_2D);
assertState(mXrTestFramework.getFirstTabWebContents(), Page.PAGE_2D,
PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
}
/**
* Tests navigation from a WebVR to a WebVR page.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testWebXrToWebXr()
throws IllegalArgumentException, InterruptedException, TimeoutException {
mXrTestFramework.loadUrlAndAwaitInitialization(TEST_PAGE_WEBXR_URL, PAGE_LOAD_TIMEOUT_S);
navigateTo(Page.PAGE_WEBXR);
assertState(mXrTestFramework.getFirstTabWebContents(), Page.PAGE_WEBXR,
PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
}
/**
* Tests navigation from a presenting WebXR to a 2D page.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testWebXrPresentingTo2d()
throws IllegalArgumentException, InterruptedException, TimeoutException {
mXrTestFramework.loadUrlAndAwaitInitialization(TEST_PAGE_WEBXR_URL, PAGE_LOAD_TIMEOUT_S);
XrTransitionUtils.enterPresentationOrFail(mXrTestFramework.getFirstTabCvc());
navigateTo(Page.PAGE_2D);
assertState(mXrTestFramework.getFirstTabWebContents(), Page.PAGE_2D,
PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
}
/**
* Tests navigation from a presenting WebXR to a WebXR page.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testWebXrPresentingToWebXr()
throws IllegalArgumentException, InterruptedException, TimeoutException {
mXrTestFramework.loadUrlAndAwaitInitialization(TEST_PAGE_WEBXR_URL, PAGE_LOAD_TIMEOUT_S);
XrTransitionUtils.enterPresentationOrFail(mXrTestFramework.getFirstTabCvc());
navigateTo(Page.PAGE_WEBXR);
assertState(mXrTestFramework.getFirstTabWebContents(), Page.PAGE_WEBXR,
PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
}
/**
* Tests navigation from a fullscreened WebXR to a 2D page.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testWebXrFullscreenTo2d()
throws IllegalArgumentException, InterruptedException, TimeoutException {
mXrTestFramework.loadUrlAndAwaitInitialization(TEST_PAGE_WEBXR_URL, PAGE_LOAD_TIMEOUT_S);
enterFullscreenOrFail(mXrTestFramework.getFirstTabCvc());
navigateTo(Page.PAGE_2D);
assertState(mXrTestFramework.getFirstTabWebContents(), Page.PAGE_2D,
PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
}
/**
* Tests navigation from a fullscreened WebXR to a WebXR page.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
public void testWebXrFullscreenToWebXr()
throws IllegalArgumentException, InterruptedException, TimeoutException {
mXrTestFramework.loadUrlAndAwaitInitialization(TEST_PAGE_WEBXR_URL, PAGE_LOAD_TIMEOUT_S);
enterFullscreenOrFail(mXrTestFramework.getFirstTabCvc());
navigateTo(Page.PAGE_WEBXR);
assertState(mXrTestFramework.getFirstTabWebContents(), Page.PAGE_WEBXR,
PresentationMode.NON_PRESENTING, FullscreenMode.NON_FULLSCREENED);
}
}
...@@ -9,7 +9,7 @@ import static org.chromium.chrome.browser.vr_shell.VrTestFramework.POLL_TIMEOUT_ ...@@ -9,7 +9,7 @@ import static org.chromium.chrome.browser.vr_shell.VrTestFramework.POLL_TIMEOUT_
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.chrome.browser.infobar.InfoBar; import org.chromium.chrome.browser.infobar.InfoBar;
import org.chromium.chrome.browser.vr_shell.VrTestFramework; import org.chromium.chrome.browser.vr_shell.TestFramework;
import org.chromium.chrome.test.util.InfoBarUtil; import org.chromium.chrome.test.util.InfoBarUtil;
import org.chromium.content.browser.test.util.Criteria; import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
...@@ -29,7 +29,7 @@ public class VrInfoBarUtils { ...@@ -29,7 +29,7 @@ public class VrInfoBarUtils {
* @return True if there are any InfoBars present, false otherwise * @return True if there are any InfoBars present, false otherwise
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static boolean isInfoBarPresent(VrTestFramework framework) { public static boolean isInfoBarPresent(TestFramework framework) {
List<InfoBar> infoBars = framework.getRule().getInfoBars(); List<InfoBar> infoBars = framework.getRule().getInfoBars();
return infoBars != null && !infoBars.isEmpty(); return infoBars != null && !infoBars.isEmpty();
} }
...@@ -38,10 +38,10 @@ public class VrInfoBarUtils { ...@@ -38,10 +38,10 @@ public class VrInfoBarUtils {
* Clicks on either the primary or secondary button of the first InfoBar * Clicks on either the primary or secondary button of the first InfoBar
* in the activity. * in the activity.
* @param button Which button to click * @param button Which button to click
* @param framework The VrTestFramework to get the current activity from * @param framework The TestFramework to get the current activity from
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void clickInfoBarButton(final Button button, VrTestFramework framework) { public static void clickInfoBarButton(final Button button, TestFramework framework) {
if (!isInfoBarPresent(framework)) return; if (!isInfoBarPresent(framework)) return;
final List<InfoBar> infoBars = framework.getRule().getInfoBars(); final List<InfoBar> infoBars = framework.getRule().getInfoBars();
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
...@@ -61,10 +61,10 @@ public class VrInfoBarUtils { ...@@ -61,10 +61,10 @@ public class VrInfoBarUtils {
/** /**
* Clicks on the close button of the first InfoBar in the activity. * Clicks on the close button of the first InfoBar in the activity.
* @param framework The VrTestFramework to get the current activity from * @param framework The TestFramework to get the current activity from
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static void clickInfobarCloseButton(VrTestFramework framework) { public static void clickInfobarCloseButton(TestFramework framework) {
if (!isInfoBarPresent(framework)) return; if (!isInfoBarPresent(framework)) return;
final List<InfoBar> infoBars = framework.getRule().getInfoBars(); final List<InfoBar> infoBars = framework.getRule().getInfoBars();
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
...@@ -78,10 +78,10 @@ public class VrInfoBarUtils { ...@@ -78,10 +78,10 @@ public class VrInfoBarUtils {
/** /**
* Determines is there is any InfoBar present in the given View hierarchy. * Determines is there is any InfoBar present in the given View hierarchy.
* @param parentView The View to start the search in * @param framework The TestFramework that will be used to get the current activity/view from
* @param present Whether an InfoBar should be present. * @param present Whether an InfoBar should be present.
*/ */
public static void expectInfoBarPresent(final VrTestFramework framework, boolean present) { public static void expectInfoBarPresent(final TestFramework framework, boolean present) {
CriteriaHelper.pollUiThread(Criteria.equals(present, new Callable<Boolean>() { CriteriaHelper.pollUiThread(Criteria.equals(present, new Callable<Boolean>() {
@Override @Override
public Boolean call() { public Boolean call() {
......
<!doctype html>
<!-- WebVR page to test transitions. -->
<html>
<body>
<input type="checkbox" onclick="setFullscreen(this)" id="fullscreen">Fullscreen
<canvas id="webgl-canvas"></canvas>
<script src="../resources/webxr_e2e.js"></script>
<script src="../resources/webxr_boilerplate.js"></script>
<script src="../resources/navigation_e2e.js"></script>
</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