Commit 707f495a authored by Jacob DeWitt's avatar Jacob DeWitt Committed by Commit Bot

Update tests to check XRInputSource profiles + gamepad.id

Per the latest WebXR spec, XRInputSource.gamepad.id must be the empty
string. Update the browser and layout tests to actually check this.

Also update the browser tests that run on Windows to check the profiles
array contents against expected values for WMR and OpenVR.

Bug: 989114, 942201
Change-Id: I36dff42cff55728d5d90384623623ea871d3a13e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1742439
Commit-Queue: Jacob DeWitt <jacde@chromium.org>
Reviewed-by: default avatarBrian Sheedy <bsheedy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#685270}
parent 05b7089d
......@@ -17,6 +17,25 @@
namespace vr {
// Helper function for verifying the XRInputSource.profiles array contents.
void VerifyInputSourceProfilesArray(
WebXrVrBrowserTestBase* t,
const std::vector<std::string>& expected_values) {
t->PollJavaScriptBooleanOrFail(
"isProfileCountEqualTo(" + base::NumberToString(expected_values.size()) +
")",
WebXrVrBrowserTestBase::kPollTimeoutShort);
// We don't expect the contents of the profiles array to change once we've
// verified its size above, so we can check the expressions a single time
// here instead of polling them.
for (size_t i = 0; i < expected_values.size(); ++i) {
t->RunJavaScriptAndExtractBoolOrFail("isProfileEqualTo(" +
base::NumberToString(i) + ", '" +
expected_values[i] + "')");
}
}
// Test that focus is locked to the presenting display for the purposes of VR/XR
// input.
void TestPresentationLocksFocusImpl(WebXrVrBrowserTestBase* t,
......@@ -423,6 +442,7 @@ IN_PROC_BROWSER_TEST_F(WebXrVrOpenVrBrowserTest, TestGamepadIncompleteData) {
GetFileUrlForHtmlTestFile("test_webxr_gamepad_support"));
EnterSessionWithUserGestureOrFail();
PollJavaScriptBooleanOrFail("inputSourceHasNoGamepad()", kPollTimeoutShort);
PollJavaScriptBooleanOrFail("isProfileCountEqualTo(0)", kPollTimeoutShort);
RunJavaScriptOrFail("done()");
EndTest();
}
......@@ -462,6 +482,18 @@ IN_PROC_MULTI_CLASS_BROWSER_TEST_F2(WebXrVrOpenVrBrowserTest,
WebXrVrBrowserTestBase::kPollTimeoutShort);
t->PollJavaScriptBooleanOrFail("isButtonPressedEqualTo(0, true)",
WebXrVrBrowserTestBase::kPollTimeoutShort);
if (t->GetRuntimeType() == XrBrowserTestBase::RuntimeType::RUNTIME_WMR) {
// WMR will still report having grip, touchpad, and thumbstick because it
// only supports that type of controller and fills in default values if
// those inputs don't exist.
VerifyInputSourceProfilesArray(
t, {"windows-mixed-reality", "grip-touchpad-thumbstick-controller"});
} else if (t->GetRuntimeType() ==
XrBrowserTestBase::RuntimeType::RUNTIME_OPENVR) {
VerifyInputSourceProfilesArray(t, {"test-value-test-value", "controller"});
}
t->RunJavaScriptOrFail("done()");
t->EndTest();
}
......@@ -552,6 +584,18 @@ IN_PROC_MULTI_CLASS_BROWSER_TEST_F2(WebXrVrOpenVrBrowserTest,
t->PollJavaScriptBooleanOrFail("isButtonTouchedEqualTo(3, true)",
WebVrBrowserTestBase::kPollTimeoutShort);
if (t->GetRuntimeType() == XrBrowserTestBase::RuntimeType::RUNTIME_WMR) {
// WMR will still report having grip, touchpad, and thumbstick because it
// only supports that type of controller and fills in default values if
// those inputs don't exist.
VerifyInputSourceProfilesArray(
t, {"windows-mixed-reality", "grip-touchpad-thumbstick-controller"});
} else if (t->GetRuntimeType() ==
XrBrowserTestBase::RuntimeType::RUNTIME_OPENVR) {
VerifyInputSourceProfilesArray(
t, {"test-value-test-value", "grip-touchpad-thumbstick-controller"});
}
t->RunJavaScriptOrFail("done()");
t->EndTest();
}
......@@ -660,6 +704,9 @@ IN_PROC_BROWSER_TEST_F(WebXrVrOpenVrBrowserTest, TestGamepadReservedData) {
PollJavaScriptBooleanOrFail("isButtonPressedEqualTo(4, true)",
kPollTimeoutShort);
VerifyInputSourceProfilesArray(
this, {"test-value-test-value", "touchpad-controller"});
RunJavaScriptOrFail("done()");
EndTest();
}
......@@ -698,6 +745,9 @@ IN_PROC_BROWSER_TEST_F(WebXrVrOpenVrBrowserTest, TestGamepadOptionalData) {
kPollTimeoutShort);
PollJavaScriptBooleanOrFail("isButtonCountEqualTo(3)", kPollTimeoutShort);
VerifyInputSourceProfilesArray(
this, {"test-value-test-value", "grip-touchpad-controller"});
RunJavaScriptOrFail("done()");
EndTest();
}
......
......@@ -103,6 +103,13 @@ circumstances.
// The spec requires all WebXR Gamepads to have index -1.
return false;
}
if (gamepad.id !== "") {
// The spec requires all WebXR Gamepads to have the empty string for
// their ID. Related information should go on the XRInputSource
// profiles array instead.
return false;
}
if (!verificationFunction(gamepad)) {
return false;
}
......@@ -111,6 +118,22 @@ circumstances.
return true;
}
function isFirstInputSourceAsExpected(verificationFunction) {
// There should only be one input source.
if (inputSourceCount() != 1) {
return false;
}
if (verificationFunction) {
let source = currentImmersiveSession().inputSources[0];
if (!verificationFunction(source)) {
return false;
}
}
return true;
}
function isMappingEqualTo(expected_mapping) {
let verificationFunction = function(gamepad) {
return gamepad.mapping == expected_mapping;
......@@ -189,6 +212,26 @@ circumstances.
return isFirstGamepadAsExpected(verificationFunction);
}
function isProfileCountEqualTo(expected_count) {
let verificationFunction = function(source) {
return source.profiles.length == expected_count;
}
return isFirstInputSourceAsExpected(verificationFunction);
}
function isProfileEqualTo(profile_index, expected_string) {
let verificationFunction = function(source) {
if (profile_index >= source.profiles.length) {
return false;
}
return source.profiles[profile_index] === expected_string;
}
return isFirstInputSourceAsExpected(verificationFunction);
}
</script>
</body>
</html>
......@@ -77,6 +77,8 @@ let testFunction = function(session, fakeDeviceController, t) {
"Expect to have a gamepad, iteration: " + inputChangeEvents);
assert_equals(cached_input_source.gamepad.index, -1,
"WebXR Gamepad.index must be -1, iteration: " + inputChangeEvents);
assert_equals(cached_input_source.gamepad.id, "",
"WebXR Gamepad.id must be empty string, iteration: " + inputChangeEvents);
assert_true(cached_input_source.gamepad.connected,
"Expect the gamepad to be connected, iteration: " + inputChangeEvents);
}
......@@ -88,6 +90,8 @@ let testFunction = function(session, fakeDeviceController, t) {
"Expect to have a gamepad on cached_input_source, iteration: " + inputChangeEvents);
assert_equals(cached_input_source.gamepad.index, -1,
"WebXR Gamepad.index must be -1, iteration: " + inputChangeEvents);
assert_equals(cached_input_source.gamepad.id, "",
"WebXR Gamepad.id must be empty string, iteration: " + inputChangeEvents);
assert_false(cached_input_source.gamepad.connected,
"Expect cached gamepad to be disconnected, iteration: " + inputChangeEvents);
}
......
......@@ -52,7 +52,11 @@ let testFunction = function(session, fakeDeviceController, t) {
function assertSameObjects() {
assert_equals(session.inputSources[0], cached_input_source);
assert_equals(cached_input_source.gamepad, cached_gamepad);
// Also make sure that WebXR gamepads have the index and id values required
// by the spec.
assert_equals(cached_gamepad.index, -1);
assert_equals(cached_gamepad.id, "");
}
// Input events and gamepad state changes (button presses, axis movements)
......@@ -74,6 +78,7 @@ let testFunction = function(session, fakeDeviceController, t) {
cached_gamepad = cached_input_source.gamepad;
t.step(() => {
assert_equals(cached_gamepad.index, -1);
assert_equals(cached_gamepad.id, "");
assert_equals(cached_gamepad.buttons.length, 3);
assert_equals(cached_gamepad.axes.length, 2);
// Initially, the button should not be pressed and the axes values should
......
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