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

Port WebVrTransitionTest to WebXR

Ports most of WebVrTransitionTest to have a WebXR equivalent. Does not
port testNfcFiresVrdisplayactivate or testTrustedIntentAllowsAutoPresent
since there is not currently an implemented equivalent of the
functionality they test in WebXR.

Bug: 804043
Change-Id: I20985416985ca777a541cf42e9a377c2c29a5456
Reviewed-on: https://chromium-review.googlesource.com/885098
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532540}
parent 38feaec8
...@@ -5,9 +5,16 @@ ...@@ -5,9 +5,16 @@
package org.chromium.chrome.browser.vr_shell; 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.PAGE_LOAD_TIMEOUT_S;
import static org.chromium.chrome.browser.vr_shell.XrTestFramework.POLL_CHECK_INTERVAL_SHORT_MS;
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_DON_ENABLED;
import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_VIEWER_DAYDREAM;
import android.os.Build; import android.os.Build;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.support.test.uiautomator.UiDevice;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -22,12 +29,16 @@ import org.chromium.base.test.params.ParameterSet; ...@@ -22,12 +29,16 @@ import org.chromium.base.test.params.ParameterSet;
import org.chromium.base.test.params.ParameterizedRunner; import org.chromium.base.test.params.ParameterizedRunner;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.MinAndroidSdkLevel; import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.base.test.util.Restriction;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.vr_shell.rules.VrActivityRestriction; import org.chromium.chrome.browser.vr_shell.rules.VrActivityRestriction;
import org.chromium.chrome.browser.vr_shell.util.VrTestRuleUtils; import org.chromium.chrome.browser.vr_shell.util.VrTestRuleUtils;
import org.chromium.chrome.browser.vr_shell.util.XrTransitionUtils; import org.chromium.chrome.browser.vr_shell.util.XrTransitionUtils;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate; import org.chromium.chrome.test.ChromeJUnit4RunnerDelegate;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
...@@ -72,4 +83,115 @@ public class WebXrTransitionTest { ...@@ -72,4 +83,115 @@ public class WebXrTransitionTest {
XrTransitionUtils.enterPresentationOrFail(mXrTestFramework.getFirstTabCvc()); XrTransitionUtils.enterPresentationOrFail(mXrTestFramework.getFirstTabCvc());
Assert.assertTrue("VrShellDelegate is in VR", VrShellDelegate.isInVr()); Assert.assertTrue("VrShellDelegate is in VR", VrShellDelegate.isInVr());
} }
/**
* Tests that WebXR is not exposed if the flag is not on and the page does
* not have an origin trial token.
*/
@Test
@MediumTest
@CommandLineFlags.Remove({"enable-features=WebXR"})
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
public void testWebXrDisabledWithoutFlagSet() throws InterruptedException {
// TODO(bsheedy): Remove this test once WebXR is on by default without
// requiring an origin trial.
mXrTestFramework.loadUrlAndAwaitInitialization(
XrTestFramework.getHtmlTestFile("test_webxr_disabled_without_flag_set"),
PAGE_LOAD_TIMEOUT_S);
XrTestFramework.waitOnJavaScriptStep(mXrTestFramework.getFirstTabWebContents());
XrTestFramework.endTest(mXrTestFramework.getFirstTabWebContents());
}
/**
* Tests that the exclusive session promise doesn't resolve if the DON flow is
* not completed.
*/
@Test
@MediumTest
@Restriction({RESTRICTION_TYPE_VIEWER_DAYDREAM, RESTRICTION_TYPE_DON_ENABLED})
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
public void testPresentationPromiseUnresolvedDuringDon() throws InterruptedException {
mXrTestFramework.loadUrlAndAwaitInitialization(
XrTestFramework.getHtmlTestFile(
"webxr_test_presentation_promise_unresolved_during_don"),
PAGE_LOAD_TIMEOUT_S);
XrTransitionUtils.enterPresentationAndWait(
mXrTestFramework.getFirstTabCvc(), mXrTestFramework.getFirstTabWebContents());
XrTestFramework.endTest(mXrTestFramework.getFirstTabWebContents());
}
/**
* Tests that the exclusive session promise is rejected if the DON flow is canceled.
*/
@Test
@MediumTest
@Restriction({RESTRICTION_TYPE_VIEWER_DAYDREAM, RESTRICTION_TYPE_DON_ENABLED})
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
public void testPresentationPromiseRejectedIfDonCanceled() throws InterruptedException {
mXrTestFramework.loadUrlAndAwaitInitialization(
XrTestFramework.getHtmlTestFile(
"webxr_test_presentation_promise_rejected_if_don_canceled"),
PAGE_LOAD_TIMEOUT_S);
final UiDevice uiDevice =
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
XrTransitionUtils.enterPresentation(mXrTestFramework.getFirstTabCvc());
// Wait until the DON flow appears to be triggered
// TODO(bsheedy): Make this less hacky if there's ever an explicit way to check if the
// DON flow is currently active https://crbug.com/758296
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
return uiDevice.getCurrentPackageName().equals("com.google.vr.vrcore");
}
}, POLL_TIMEOUT_LONG_MS, POLL_CHECK_INTERVAL_SHORT_MS);
uiDevice.pressBack();
mXrTestFramework.waitOnJavaScriptStep(mXrTestFramework.getFirstTabWebContents());
mXrTestFramework.endTest(mXrTestFramework.getFirstTabWebContents());
}
/**
* Tests that the omnibox reappears after exiting an exclusive session.
*/
@Test
@MediumTest
public void testControlsVisibleAfterExitingVr() throws InterruptedException {
mXrTestFramework.loadUrlAndAwaitInitialization(
XrTestFramework.getHtmlTestFile("generic_webxr_page"), PAGE_LOAD_TIMEOUT_S);
XrTransitionUtils.enterPresentationOrFail(mXrTestFramework.getFirstTabCvc());
XrTransitionUtils.forceExitVr();
// The hiding of the controls may only propagate after VR has exited, so give it a chance
// to propagate. In the worst case this test will erroneously pass, but should never
// erroneously fail, and should only be flaky if omnibox showing is broken.
Thread.sleep(100);
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
ChromeActivity activity = mXrTestFramework.getRule().getActivity();
return activity.getFullscreenManager().getBrowserControlHiddenRatio() == 0.0;
}
}, POLL_TIMEOUT_SHORT_MS, POLL_CHECK_INTERVAL_SHORT_MS);
}
/**
* Tests that window.requestAnimationFrame stops firing while in a WebXR exclusive session, but
* resumes afterwards.
*/
@Test
@MediumTest
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
public void testWindowRafStopsFiringWhilePresenting() throws InterruptedException {
mXrTestFramework.loadUrlAndAwaitInitialization(
XrTestFramework.getHtmlTestFile(
"webxr_test_window_raf_stops_firing_during_exclusive_session"),
PAGE_LOAD_TIMEOUT_S);
XrTestFramework.executeStepAndWait(
"stepVerifyBeforePresent()", mXrTestFramework.getFirstTabWebContents());
XrTransitionUtils.enterPresentationOrFail(mXrTestFramework.getFirstTabCvc());
XrTestFramework.executeStepAndWait(
"stepVerifyDuringPresent()", mXrTestFramework.getFirstTabWebContents());
XrTransitionUtils.forceExitVr();
XrTestFramework.executeStepAndWait(
"stepVerifyAfterPresent()", mXrTestFramework.getFirstTabWebContents());
XrTestFramework.endTest(mXrTestFramework.getFirstTabWebContents());
}
} }
\ No newline at end of file
...@@ -24,7 +24,7 @@ resolved or rejected while the DON flow is active. ...@@ -24,7 +24,7 @@ resolved or rejected while the DON flow is active.
assert_unreached("requestPresent promise rejected"); assert_unreached("requestPresent promise rejected");
}); });
}); });
window.setTimeout( () => {t.done();}, 1000); window.setTimeout( () => {t.done();}, 2000);
} }
webglCanvas.onclick = onVrRequestPresentWithDon; webglCanvas.onclick = onVrRequestPresentWithDon;
</script> </script>
......
<!doctype html>
<!--
Tests that the WebXR API is not present if the flag to enable it is not set.
-->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../resources/webxr_e2e.css">
</head>
<body>
<canvas id="webgl-canvas"></canvas>
<script src="../../../../../../third_party/WebKit/LayoutTests/resources/testharness.js"></script>
<script src="../resources/webxr_e2e.js"></script>
</body>
<script>
var t = async_test("WebXR API is not visible");
if (navigator.xr) {
t.step( () => {
assert_unreached("API is visible");
});
}
t.done();
</script>
</html>
<!doctype html>
<!--
Used to test that the promise returned by WebXR's requestSession rejects if
the DON flow is canceled.
-->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../resources/webxr_e2e.css">
</head>
<body>
<canvas id="webgl-canvas"></canvas>
<script src="../../../../../../third_party/WebKit/LayoutTests/resources/testharness.js"></script>
<script src="../resources/webxr_e2e.js"></script>
<script src="../resources/webxr_boilerplate.js"></script>
<script>
var t = async_test("Presentation promise is rejected after DON canceled");
function onExclusiveRequestWithDon() {
xrDevice.requestSession({exclusive: true}).then( (session) => {
t.step( () => {
assert_unreached("requestPresent promise resolved");
});
}, () => {
// Do nothing when the promise is rejected
}).then( () => {
t.done();
});
}
webglCanvas.onclick = onExclusiveRequestWithDon;
</script>
</body>
</html>
\ No newline at end of file
<!doctype html>
<!--
Used to test that the promise returned by WebXR's requestSession does not get
resolved or rejected while the DON flow is active.
-->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../resources/webxr_e2e.css">
</head>
<body>
<canvas id="webgl-canvas"></canvas>
<script src="../../../../../../third_party/WebKit/LayoutTests/resources/testharness.js"></script>
<script src="../resources/webxr_e2e.js"></script>
<script src="../resources/webxr_boilerplate.js"></script>
<script>
var t = async_test("Presentation promise is unresolved during DON flow");
function onExclusiveRequestWithDon() {
xrDevice.requestSession({exclusive: true}).then( (session) => {
t.step( () => {
assert_unreached("requestSession promise resolved");
});
}, () => {
t.step( () => {
assert_unreached("requestSession promise rejected");
});
});
window.setTimeout( () => {t.done();}, 2000);
}
webglCanvas.onclick = onExclusiveRequestWithDon;
</script>
</body>
</html>
<!doctype html>
<!--
Tests that window.requestAnimationFrame stops firing while in WebXR presentation
on Android.
-->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../resources/webxr_e2e.css">
</head>
<body>
<canvas id="webgl-canvas"></canvas>
<script src="../../../../../../third_party/WebKit/LayoutTests/resources/testharness.js"></script>
<script src="../resources/webxr_e2e.js"></script>
<script src="../resources/webxr_boilerplate.js"></script>
<script>
var t = async_test("window.rAF stops while presenting");
function stepVerifyBeforePresent() {
window.requestAnimationFrame( () => {
finishJavaScriptStep();
});
}
function stepVerifyDuringPresent() {
let handle = window.requestAnimationFrame( () => {
t.step( () => {
assert_unreached("window.rAF fired during presentation");
});
});
window.setTimeout( () => {
window.cancelAnimationFrame(handle);
finishJavaScriptStep();
}, 100);
}
function stepVerifyAfterPresent() {
window.requestAnimationFrame( () => {
t.done();
});
}
</script>
</body>
</html>
\ No newline at end of file
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