webxr_permissions_policy.https.html (3576B)
1 <!DOCTYPE html> 2 <script src="/resources/testharness.js"></script> 3 <script src="/resources/testharnessreport.js"></script> 4 <script src="resources/webxr_util.js"></script> 5 <script src="resources/webxr_test_constants.js"></script> 6 <canvas></canvas> 7 8 <script> 9 xr_promise_test( 10 "Validate isSessionSupported behavior without xr-spatial-tracking policy", 11 (t) => { 12 // Inline should never reject. 13 return navigator.xr.isSessionSupported("inline").then((supported) => { 14 t.step(() => { 15 assert_true(supported, 16 "inline should always be supported, even without permissions policy"); 17 }); 18 19 // It shouldn't matter that there's no device connected, the SecurityError 20 // should reject first. 21 return promise_rejects_dom(t, "SecurityError", 22 navigator.xr.isSessionSupported("immersive-vr"), 23 "Immersive isSessionSupported should reject"); 24 }); 25 }); 26 27 xr_promise_test( 28 "Validate requestSession behavior without xr-spatial-tracking policy", 29 (t) => { 30 return navigator.xr.test.simulateDeviceConnection(TRACKED_IMMERSIVE_DEVICE) 31 .then(() => { 32 return new Promise((resolve, reject) => { 33 navigator.xr.test.simulateUserActivation(() => { 34 35 // Technically the first "requestSession" doesn't need either the device 36 // or the activation, but this makes the test code a little cleaner since 37 // the others do, as lacking user activation or a valid backing device 38 // should also cause the session to reject. In order to guarantee that 39 // we're seeing the rejection we want, we eliminate those as possibilities. 40 resolve(Promise.all([ 41 navigator.xr.requestSession("inline").then(session => session.end()), 42 43 promise_rejects_dom(t, "NotSupportedError", 44 navigator.xr.requestSession("inline", { requiredFeatures: ["local"] }), 45 "Inline with features should reject without permissions policy"), 46 47 promise_rejects_dom(t, "NotSupportedError", 48 navigator.xr.requestSession("immersive-vr"), 49 "Immersive-vr should reject without permissions policy") 50 ])); 51 }); 52 }); 53 }); 54 }); 55 56 xr_promise_test( 57 "Validate devicechange event behavior without xr-spatial-tracking policy", 58 (t) => { 59 navigator.xr.addEventListener("devicechange", () => { 60 t.step(() => { assert_unreached("devicechange should not fire"); }); 61 }) 62 63 // We need to yield a short time to ensure that any event registration has 64 // propagated, as this can take some time. 65 // Note that device connection is not guaranteed to fire per the spec, if it's 66 // the first connection, but disconnect definitely should. 67 t.step_timeout(() => { 68 navigator.xr.test.simulateDeviceConnection(TRACKED_IMMERSIVE_DEVICE) 69 .then((testDeviceController) => { 70 return testDeviceController.disconnect(); 71 }); 72 }, 100); 73 74 // Wait an even longer time before finishing the test, so that if the event 75 // were to fire, it would've by now. 76 return new Promise((resolve) => { 77 t.step_timeout(() => { resolve(); }, 2000); 78 }); 79 80 }); 81 82 xr_promise_test( 83 "Validate xr compatibility requests without xr-spatial-tracking policy", 84 (t) => { 85 let canvas = document.createElement('canvas'); 86 let gl = canvas.getContext('webgl', {xrCompatible: true}); 87 88 t.step(() => { 89 assert_false(gl.getContextAttributes().xrCompatible, 90 "xrCompatibility shouldn't be set when requested without permissions policy"); 91 }); 92 93 return promise_rejects_dom(t, "SecurityError", 94 gl.makeXRCompatible(), 95 "makeXRCompatible should reject without permissions policy"); 96 }); 97 </script>