summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/webxr_feature_policy.https.html
blob: b493ec73cce687832cfc0784a1a798d665eb10af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!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_dom(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_dom(t, "NotSupportedError",
            navigator.xr.requestSession("inline", { requiredFeatures: ["local"] }),
            "Inline with features should reject without feature policy"),

          promise_rejects_dom(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);
  });

});

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>