summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/xrDevice_disconnect_ends.https.html
blob: 644a4d68e4336b9b5532046a7f8e454483a36bb6 (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
<!DOCTYPE html>
<body>
  <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>

  <script>
    const testName = "Immersive session ends when device is disconnected";
    let watcherDone = new Event("watcherdone");
    const fakeDeviceInitParams = TRACKED_IMMERSIVE_DEVICE;

    let testFunction = function(session, testDeviceController, t) {
      let sessionWatcher = new EventWatcher(t, session, ["end", "watcherdone"]);
      let sessionPromise = sessionWatcher.wait_for(["end", "watcherdone"]);

      let xrWatcher = new EventWatcher(t, navigator.xr, ["devicechange"]);
      let xrPromise = xrWatcher.wait_for(["devicechange"]);

      function onSessionEnd(event) {
        t.step( () => {
          assert_equals(event.session, session);
          session.dispatchEvent(watcherDone);
        });
      }

      session.addEventListener("end", onSessionEnd, false);

      // The javascript needs to yield so that the event registration processes.
      t.step_timeout(() => { testDeviceController.disconnect(); }, 0);

      return Promise.all([sessionPromise, xrPromise]);
    };

    xr_session_promise_test(testName, testFunction,
      fakeDeviceInitParams, 'immersive-vr');
  </script>
</body>