Commit 6ded7989 authored by bsheedy's avatar bsheedy Committed by Commit Bot

Add additional WebXR gamepad tests

Removes the --enable-gamepad-extensions flag from the WebVrInputTest
class since all its tests should work without it. Also adds DDView/
Cardboard tests for the following scenarios.

1. WebXR enabled, WebXRGamepadSupport disabled -> no gamepads available
2. WebXR enabled, WebXRGamepadSupport enabled -> gamepad available
3. WebXR disabled, WebXRGamepadsupport disabled -> no gamepads available

Bug: 832399
Change-Id: Ic73a7d312faad19b33020fc790bc22f0b33ede43
Reviewed-on: https://chromium-review.googlesource.com/1038442Reviewed-by: default avatarBill Orr <billorr@chromium.org>
Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarBrandon Jones <bajones@chromium.org>
Commit-Queue: Brian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#563120}
parent 8f614e9f
......@@ -66,8 +66,7 @@ import java.util.concurrent.atomic.AtomicReference;
*/
@RunWith(ParameterizedRunner.class)
@UseRunnerDelegate(ChromeJUnit4RunnerDelegate.class)
@CommandLineFlags.
Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, "enable-webvr", "enable-gamepad-extensions"})
@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, "enable-webvr"})
@MinAndroidSdkLevel(Build.VERSION_CODES.KITKAT) // WebVR and WebXR are only supported on K+
public class WebVrInputTest {
@ClassParameter
......@@ -255,6 +254,18 @@ public class WebVrInputTest {
});
}
private void spamScreenTaps(final View view, final int x, final int y, final int iterations) {
// Tap the screen a bunch of times.
// Android doesn't seem to like sending touch events too quickly, so have a short delay
// between events.
for (int i = 0; i < iterations; i++) {
long downTime = sendScreenTouchDown(view, x, y);
SystemClock.sleep(100);
sendScreenTouchUp(view, x, y, downTime);
SystemClock.sleep(100);
}
}
/**
* Tests that screen touches are still registered when the viewer is Cardboard.
*/
......@@ -314,14 +325,7 @@ public class WebVrInputTest {
.getPresentationViewForTesting();
// Tap the screen a bunch of times and make sure that they're all registered.
// Android doesn't seem to like sending touch events too quickly, so have a short delay
// between events.
for (int i = 0; i < numIterations; i++) {
long downTime = sendScreenTouchDown(presentationView, x, y);
SystemClock.sleep(100);
sendScreenTouchUp(presentationView, x, y, downTime);
SystemClock.sleep(100);
}
spamScreenTaps(presentationView, x, y, numIterations);
XrTestFramework.waitOnJavaScriptStep(mXrTestFramework.getFirstTabWebContents());
XrTestFramework.endTest(mXrTestFramework.getFirstTabWebContents());
......@@ -628,4 +632,139 @@ public class WebVrInputTest {
controller.pressReleaseAppButton();
assertAppButtonEffect(true /* shouldHaveExited */, framework);
}
/**
* Verifies that a Gamepad API gamepad is not returned when using WebXR and a Daydream View if
* WebXRGamepadSupport is not explicitly enabled. Correctness testing for
* https://crbug.com/830935.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@CommandLineFlags.Remove({"enable-webvr"})
@CommandLineFlags.Add({"enable-features=WebXR"})
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
public void testWebXrGamepadNotReturnedWithoutGamepadSupport() throws InterruptedException {
webxrGamepadSupportImpl(
0 /* numExpectedGamepads */, true /* webxrPresent */, true /* daydream */);
}
/**
* Verifies that a Gamepad API gamepad is not returned when using WebXR and Cardboard if
* WebXRGamepadSupport is not explicitly enabled. Correctness testing for
* https://crbug.com/830935.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_NON_DAYDREAM)
@CommandLineFlags.Remove({"enable-webvr"})
@CommandLineFlags.Add({"enable-features=WebXR"})
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
public void testWebXrGamepadNotReturnedWithoutGamepadSupport_Cardboard()
throws InterruptedException {
webxrGamepadSupportImpl(
0 /* numExpectedGamepads */, true /* webxrPresent */, false /* daydream */);
}
/**
* Verifies that a Gamepad API gamepad is returned when using WebXR and Daydream View if
* WebXRGamepadSupport is explicitly enabled. Correctness testing for https://crbug.com/830935.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@CommandLineFlags.Remove({"enable-webvr"})
@CommandLineFlags.Add({"enable-features=WebXR,WebXRGamepadSupport"})
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
public void testWebXrGamepadReturnedWithGamepadSupport() throws InterruptedException {
webxrGamepadSupportImpl(
1 /* numExpectedGamepads */, true /* webxrPresent */, true /* daydream */);
}
/**
* Verifies that a Gamepad API gamepad is returned when using WebXR and Cardboard if
* WebXRGamepadSupport is explicitly enabled. Correctness testing for https://crbug.com/830935.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_NON_DAYDREAM)
@CommandLineFlags.Remove({"enable-webvr"})
@CommandLineFlags.Add({"enable-features=WebXR,WebXRGamepadSupport"})
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
public void testWebXrGamepadReturnedWithGamepadSupport_Cardboard()
throws InterruptedException {
webxrGamepadSupportImpl(
1 /* numExpectedGamepads */, true /* webxrPresent */, false /* daydream */);
}
/**
* Verifies that a Gamepad API gamepad is not returned when not using WebXR, WebVR, or the
* WebXRGamepadSupport feature with Daydream View. Correctness testing for
* https://crbug.com/830935.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_DAYDREAM)
@CommandLineFlags.Remove({"enable-webvr"})
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
public void testWebXrGamepadNotReturnedWithoutAnyFeatures() throws InterruptedException {
webxrGamepadSupportImpl(
0 /* numExpectedGamepads */, false /* webxrPresent */, true /* daydream */);
}
/**
* Verifies that a Gamepad API gamepad is not returned when not using WebXR, WebVR, or the
* WebXRGamepadSupport feature with Cardboard. Correctness testing for https://crbug.com/830935.
*/
@Test
@MediumTest
@Restriction(RESTRICTION_TYPE_VIEWER_NON_DAYDREAM)
@CommandLineFlags.Remove({"enable-webvr"})
@VrActivityRestriction({VrActivityRestriction.SupportedActivity.ALL})
public void testWebXrGamepadNotReturnedWithoutAnyFeatures_Cardboard()
throws InterruptedException {
webxrGamepadSupportImpl(
0 /* numExpectedGamepads */, false /* webxrPresent */, false /* daydream */);
}
private void webxrGamepadSupportImpl(int numExpectedGamepads, boolean webxrPresent,
boolean daydream) throws InterruptedException {
if (webxrPresent) {
mXrTestFramework.loadUrlAndAwaitInitialization(
XrTestFramework.getFileUrlForHtmlTestFile("test_webxr_gamepad_support"),
PAGE_LOAD_TIMEOUT_S);
TransitionUtils.enterPresentationOrFail(mXrTestFramework);
} else {
mXrTestFramework.loadUrlAndAwaitInitialization(
XrTestFramework.getFileUrlForHtmlTestFile("test_webxr_gamepad_support_nowebxr"),
PAGE_LOAD_TIMEOUT_S);
}
// Spam input to make sure the Gamepad API registers the gamepad if it should.
int numIterations = 10;
if (daydream) {
EmulatedVrController controller = new EmulatedVrController(mTestRule.getActivity());
for (int i = 0; i < numIterations; i++) {
controller.performControllerClick();
}
} else {
int x = mXrTestFramework.getFirstTabContentView().getWidth() / 2;
int y = mXrTestFramework.getFirstTabContentView().getHeight() / 2;
View presentationView;
if (webxrPresent) {
presentationView = ((VrShellImpl) TestVrShellDelegate.getVrShellForTesting())
.getPresentationViewForTesting();
} else {
presentationView = mTestRule.getActivity().getWindow().getDecorView();
}
spamScreenTaps(presentationView, x, y, numIterations);
}
XrTestFramework.executeStepAndWait("stepAssertNumGamepadsMatchesExpectation("
+ String.valueOf(numExpectedGamepads) + ")",
mXrTestFramework.getFirstTabWebContents());
XrTestFramework.endTest(mXrTestFramework.getFirstTabWebContents());
}
}
<!doctype html>
<!--
Tests that a Gamepad API gamepad is or is not returned under different
circumstances.
-->
<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("Gamepad returned while using WebXR when expected.");
// We apparently need to register a listener, otherwise all gamepads are
// always null.
window.addEventListener("gamepadconnected", function(e) {});
function stepAssertNumGamepadsMatchesExpectation(numExpectedGamepads) {
var numGamepads = 0;
for (gamepad of navigator.getGamepads()) {
if (gamepad !== null) {
numGamepads++;
}
}
t.step( () => {
assert_equals(numGamepads, numExpectedGamepads,
"Number of returned gamepads matches expectation");
});
t.done();
}
</script>
</body>
</html>
\ No newline at end of file
<!doctype html>
<!--
Tests that a Gamepad API gamepad is or is not returned under different
circumstances. Does not have WebXR code.
-->
<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>
var t = async_test("Gamepad returned while using WebXR when expected.");
// We apparently need to register a listener, otherwise all gamepads are
// always null.
window.addEventListener("gamepadconnected", function(e) {});
function stepAssertNumGamepadsMatchesExpectation(numExpectedGamepads) {
var numGamepads = 0;
for (gamepad of navigator.getGamepads()) {
if (gamepad !== null) {
numGamepads++;
}
}
t.step( () => {
assert_equals(numGamepads, numExpectedGamepads,
"Number of returned gamepads matches expectation");
});
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