Skip to content

Commit

Permalink
Bug 1581791 [wpt PR 19119] - Update xr feature policy name and behavi…
Browse files Browse the repository at this point in the history
…or to match spec, a=testonly

Automatic update from web-platform-tests
Update xr feature policy name and behavior to match spec

As a result of TPAC there were some spec changes to the xr feature
policy (FP). These were made in:
immersive-web/webxr#842
The following changes were needed to become spec compliant:

* rename FP from "xr" to "xr-spatial-tracking"
* supportsSession always resolves for "inline"
* supportsSession rejects for immersive-vr with a SecurityError if FP
  not set
* default features per mode are now required features for that mode
* requestSession does not unconditionally reject if FP is not set,
  instead resolving specific features now depends on FP status.
* While resolving features, if any required features depend on a missing
  FP, the requestSession call will fail with a "NotSupportedError"
* While resolving features, if any optional features depend on a missing
  FP, those features will be silently ignored.
* devicechange events will not fire for documents that do not have
  FP set.

Bug: 1003842
Change-Id: Ie9ae16b5c1d863b730e556b511c024bae8a4503c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1808800
Commit-Queue: Alexander Cooper <alcooper@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Reviewed-by: Ian Clelland <iclelland@chromium.org>
Reviewed-by: Jacob DeWitt <jacde@chromium.org>
Auto-Submit: Alexander Cooper <alcooper@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701740}

--

wpt-commits: dc17f8c8e3372dd30ce98d542874843f87726e8e
wpt-pr: 19119
  • Loading branch information
alcooper91 authored and moz-wptsync-bot committed Oct 14, 2019
1 parent 62bf275 commit 79dbbe3
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const report = reports[0];
assert_equals(report.type, "feature-policy-violation");
assert_equals(report.url, document.location.href);
assert_equals(report.body.featureId, "xr");
assert_equals(report.body.featureId, "xr-spatial-tracking");
assert_equals(report.body.sourceFile, document.location.href);
assert_equals(typeof report.body.lineNumber, "number");
assert_equals(typeof report.body.columnNumber, "number");
Expand All @@ -23,11 +23,12 @@
{types: ['feature-policy-violation']}).observe();
});
try {
await navigator.xr.supportsSession('inline');
let supported = await navigator.xr.isSessionSupported('immersive-vr');
} catch (err) {
// If no XR devices are available, supportsSession() will reject with a
// NotSupportedError, but the report should be generated anyway.
assert_equals(err.name, 'NotSupportedError');
// IsSessionSupported should only throw with a feature policy violation;
// however, inline does not trigger the feature policy,
// so immersive-vr must be used.
assert_unreached("isSessionSupported should not throw in ReportOnly mode");
}
check_report_format(await report);
}, "XR report only mode");
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Feature-Policy-Report-Only: xr 'none'
Feature-Policy-Report-Only: xr-spatial-tracking 'none'
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let report = reports[0];
assert_equals(report.type, "feature-policy-violation");
assert_equals(report.url, document.location.href);
assert_equals(report.body.featureId, "xr");
assert_equals(report.body.featureId, "xr-spatial-tracking");
assert_equals(report.body.sourceFile, document.location.href);
assert_equals(typeof report.body.lineNumber, "number");
assert_equals(typeof report.body.columnNumber, "number");
Expand All @@ -22,8 +22,9 @@
new ReportingObserver((reports, observer) => resolve([reports, observer]),
{types: ['feature-policy-violation']}).observe();
});
await promise_rejects(t, 'SecurityError', navigator.xr.supportsSession('inline'),
"XR device access should not be allowed in this document.");
await promise_rejects(t, 'SecurityError',
navigator.xr.isSessionSupported('immersive-vr'),
"XR spatial tracking should not be allowed in this document.");
const [reports, observer] = await report;
check_report_format(reports, observer);
}, "XR Report Format");
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Feature-Policy: xr 'none'
Feature-Policy: xr-spatial-tracking 'none'
30 changes: 18 additions & 12 deletions testing/web-platform/tests/webxr/resources/webxr_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ function xr_promise_test(name, func, properties) {
await loadChromiumResources;
}

// Ensure that any devices are disconnected when done. If this were done in
// a .then() for the success case, a test that expected failure would
// already be marked done at the time that runs and the shutdown would
// interfere with the next test.
t.add_cleanup(async () => {
// Ensure system state is cleaned up.
await navigator.xr.test.disconnectAllDevices();
});

return func(t);
}, name, properties);
}
Expand Down Expand Up @@ -44,19 +53,16 @@ function xr_session_promise_test(
xr_promise_test(
name,
(t) => {
// Ensure that any pending sessions are ended and devices are
// disconnected when done. This needs to use a cleanup function to
// ensure proper sequencing. If this were done in a .then() for the
// success case, a test that expected failure would already be marked
// done at the time that runs, and the shutdown would interfere with
// the next test which may have started already.
// Ensure that any pending sessions are ended when done. This needs to
// use a cleanup function to ensure proper sequencing. If this were
// done in a .then() for the success case, a test that expected
// failure would already be marked done at the time that runs, and the
// shutdown would interfere with the next test which may have started.
t.add_cleanup(async () => {
// If a session was created, end it.
if (testSession) {
await testSession.end().catch(() => {});
}
// Cleanup system state.
await navigator.xr.test.disconnectAllDevices();
// If a session was created, end it.
if (testSession) {
await testSession.end().catch(() => {});
}
});

return navigator.xr.test.simulateDeviceConnection(fakeDeviceInit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
<script src="/resources/testharnessreport.js"></script>
<script>
test(() => {
assert_in_array('xr', document.featurePolicy.features());
}, 'document.featurePolicy.features should advertise xr.');
assert_in_array('xr-spatial-tracking', document.featurePolicy.features());
}, 'document.featurePolicy.features should advertise xr-spatial-tracking.');
</script>
81 changes: 81 additions & 0 deletions testing/web-platform/tests/webxr/webxr_feature_policy.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/webxr_util.js"></script>
<script src="resources/webxr_test_constants.js"></script>
<canvas />

<script>
xr_promise_test(
"Validate isSessionSupported behavior without xr-spatial-tracking policy",
(t) => {
// Inline should never reject.
return navigator.xr.isSessionSupported("inline").then((supported) => {
t.step(() => {
assert_true(supported,
"inline should always be supported, even without feature policy");
});

// It shouldn't matter that there's no device connected, the SecurityError
// should reject first.
return promise_rejects(t, "SecurityError",
navigator.xr.isSessionSupported("immersive-vr"),
"Immersive isSessionSupported should reject");
});
});

xr_promise_test(
"Validate requestSession behavior without xr-spatial-tracking policy",
(t) => {
return navigator.xr.test.simulateDeviceConnection(TRACKED_IMMERSIVE_DEVICE)
.then(() => {
return new Promise((resolve, reject) => {
navigator.xr.test.simulateUserActivation(() => {

// Technically the first "requestSession" doesn't need either the device
// or the activation, but this makes the test code a little cleaner since
// the others do, as lacking user activation or a valid backing device
// should also cause the session to reject. In order to guarantee that
// we're seeing the rejection we want, we eliminate those as possibilities.
resolve(Promise.all([
navigator.xr.requestSession("inline").then(session => session.end()),

promise_rejects(t, "NotSupportedError",
navigator.xr.requestSession("inline", { requiredFeatures: ["local"] }),
"Inline with features should reject without feature policy"),

promise_rejects(t, "NotSupportedError",
navigator.xr.requestSession("immersive-vr"),
"Immersive-vr should reject without feature policy")
]));
});
});
});
});

xr_promise_test(
"Validate devicechange event behavior without xr-spatial-tracking policy",
(t) => {
navigator.xr.addEventListener("devicechange", () => {
t.step(() => { assert_unreached("devicechange should not fire"); });
})

// We need to yield a short time to ensure that any event registration has
// propagated, as this can take some time.
// Note that device connection is not guaranteed to fire per the spec, if it's
// the first connection, but disconnect definitely should.
t.step_timeout(() => {
navigator.xr.test.simulateDeviceConnection(TRACKED_IMMERSIVE_DEVICE)
.then((testDeviceController) => {
return testDeviceController.disconnect();
});
}, 100);

// Wait an even longer time before finishing the test, so that if the event
// were to fire, it would've by now.
return new Promise((resolve) => {
t.step_timeout(() => { resolve(); }, 2000);
});

});
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Feature-Policy: xr-spatial-tracking 'none'

0 comments on commit 79dbbe3

Please sign in to comment.