tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

xrSession_requestSessionDuringEnd.https.html (2728B)


      1 <!DOCTYPE html>
      2 <body>
      3  <script src=/resources/testharness.js></script>
      4  <script src=/resources/testharnessreport.js></script>
      5  <script src="resources/webxr_util.js"></script>
      6  <script src="resources/webxr_test_constants.js"></script>
      7 
      8  <script>
      9    function testFunctionGenerator(createSessionFromEventCallback) {
     10        return function(session, testDeviceController, t) {
     11            let done = false;
     12 
     13            function createSession() {
     14              return new Promise((resolve) => {
     15                  navigator.xr.requestSession("immersive-vr")
     16                  .then((new_session) => {
     17                    // The test framework ensures that the created session ends,
     18                    // but will not do cleanup for this session, so if it gets
     19                    // created, we need to ensure that it gets cleaned up.
     20                    return new_session.end();
     21                  }).then(() => {
     22                    done = true;
     23                    resolve();
     24                  }).catch((err) => {
     25                    // Only one catch is needed for the whole promise chain.
     26                    // If ending the new session throws, it's fine to fail as
     27                    // we'd otherwise end up in a bad state.
     28                    t.step(() => {
     29                      assert_unreached("Session creation should not throw: " + err);
     30                    });
     31                  });
     32              });
     33            }
     34 
     35            function onSessionEnd() {
     36                if (createSessionFromEventCallback) {
     37                  createSession();
     38                }
     39            }
     40 
     41            session.addEventListener("end", onSessionEnd, false);
     42 
     43            // We need to simulate the user activation before we call end as
     44            // otherwise (depending on the implementation) it can interfere with
     45            // the scheduling of the dispatched event/promise, and make session
     46            // creation succeed even when there may be bugs preventing it from
     47            // doing so in real scenarios.
     48            navigator.xr.test.simulateUserActivation(() => {
     49              session.end().then(() => {
     50                if (!createSessionFromEventCallback) {
     51                  createSession();
     52                }
     53              });
     54            });
     55 
     56            return t.step_wait(() => done);
     57        };
     58    }
     59 
     60    xr_session_promise_test("Create new session in OnSessionEnded event",
     61      testFunctionGenerator(/*createSessionFromEventCallback=*/true),
     62      TRACKED_IMMERSIVE_DEVICE, 'immersive-vr');
     63 
     64    xr_session_promise_test("Create mew session in end promise",
     65      testFunctionGenerator(/*createSessionFromEventCallback=*/false),
     66      TRACKED_IMMERSIVE_DEVICE, 'immersive-vr');
     67  </script>
     68 </body>