Skip to content

Commit

Permalink
Add tests to validate XR compatible request scenarios that should throw
Browse files Browse the repository at this point in the history
This change adds tests that validate scenarios where requesting XR
compatibility should fail:
- If the WebXR feature policy isn't allowed, a SecurityError is thrown
- If there are no devices available, an InvalidStateError is thrown

A runtime enabled feature is added for WebXR multi GPU that syncs with
the corresponding Chromium feature flag.

Bug: 1124024
Change-Id: Ia79b06ecffa936471a6fd80172717c7724245bf2
  • Loading branch information
patrto authored and chromium-wpt-export-bot committed Sep 17, 2020
1 parent 80c4b6a commit 5e06993
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
7 changes: 6 additions & 1 deletion resources/chromium/webxr-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,13 @@ class MockVRService {
// Only handles asynchronous calls to makeXrCompatible. Synchronous calls are
// not supported in Javascript.
makeXrCompatible() {
if (this.runtimes_.length == 0) {
return Promise.resolve({
xrCompatibleResult: device.mojom.XrCompatibleResult.kNoDeviceAvailable
});
}
return Promise.resolve({
xr_compatible_result: device.mojom.XrCompatibleResult.kAlreadyCompatible
xrCompatibleResult: device.mojom.XrCompatibleResult.kAlreadyCompatible
});
}
}
Expand Down
10 changes: 9 additions & 1 deletion webxr/webGLCanvasContext_create_xrcompatible.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
<script src="resources/webxr_test_constants.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
xr_promise_test("Creating a webglCanvasContext with no device",
(t) => {
let webglCanvas = document.createElement('canvas');
let gl = webglCanvas.getContext('webgl');

assert_false(gl.getContextAttributes().xrCompatible);
return promise_rejects_dom(t, "InvalidStateError", gl.makeXRCompatible());
});

xr_promise_test("An XR-compatible webglCanvasContext can be created",
(t) => {
let gl = null;
Expand All @@ -26,6 +35,5 @@
assert_true(offscreenGl.getContextAttributes().xrCompatible);
});
});

</script>
</body>
16 changes: 16 additions & 0 deletions webxr/webxr_feature_policy.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,20 @@
});

});

xr_promise_test(
"Validate xr compatibility requests without xr-spatial-tracking policy",
(t) => {
let canvas = document.createElement('canvas');
let gl = canvas.getContext('webgl', {xrCompatible: true});

t.step(() => {
assert_false(gl.getContextAttributes().xrCompatible,
"xrCompatibility shouldn't be set when requested without feature policy");
});

return promise_rejects_dom(t, "SecurityError",
gl.makeXRCompatible(),
"makeXRCompatible should reject without feature policy");
});
</script>

0 comments on commit 5e06993

Please sign in to comment.