tor-browser

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

xrSession_visibilityState.https.html (2716B)


      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 
      7 <script>
      8 let testName = "Ensures that the XRSession's visibilityState is correctly "
      9  + "reported and that the associated visibilitychange event fires.";
     10 
     11 let watcherDone = new Event("watcherdone");
     12 let frameFired = new Event("framefired");
     13 
     14 let fakeDeviceInitParams = TRACKED_IMMERSIVE_DEVICE;
     15 
     16 let testFunction = function(session, fakeDeviceController, t) {
     17  let eventWatcher = new EventWatcher(
     18    t, session, ["visibilitychange", "framefired", "watcherdone"]);
     19  let eventPromise = eventWatcher.wait_for(
     20    ["visibilitychange", "visibilitychange", "framefired", "watcherdone"]);
     21 
     22  function onFrame(timestamp, frame) {
     23    t.step( () => {
     24      // The session should not fire any animation frames while the visibility
     25      // state is hidden.
     26      assert_not_equals(session.visibilityState, "hidden");
     27    });
     28 
     29    // Make sure the frame does fire when the visibility is changed back to "visible"
     30    session.dispatchEvent(frameFired);
     31  }
     32 
     33  function onSessionVisibilityChangeHidden(event) {
     34    t.step( () => {
     35      assert_equals(session.visibilityState, "hidden");
     36    });
     37 
     38    session.removeEventListener("visibilitychange", onSessionVisibilityChangeHidden, false);
     39    session.addEventListener("visibilitychange", onSessionVisibilityChangeVisible, false);
     40 
     41    session.requestAnimationFrame(onFrame)
     42 
     43    t.step_timeout(() => {
     44      fakeDeviceController.simulateVisibilityChange("visible");
     45    }, 300);
     46  }
     47 
     48  function onSessionVisibilityChangeVisible(event) {
     49    t.step( () => {
     50      assert_equals(session.visibilityState, "visible");
     51    });
     52 
     53    session.removeEventListener("visibilitychange", onSessionVisibilityChangeVisible, false);
     54    session.addEventListener("visibilitychange", onSessionVisibilityChangeInvalid, false);
     55    fakeDeviceController.simulateVisibilityChange("visible");
     56 
     57    t.step_timeout(() => {
     58      session.dispatchEvent(watcherDone);
     59    }, 300);
     60  }
     61 
     62  function onSessionVisibilityChangeInvalid(event) {
     63    t.step( () => {
     64      assert_not_reached("Should not fire visibilitychange events for the same state");
     65    });
     66  }
     67 
     68  t.step( () => {
     69    // Session visibility should start out as "visible"
     70    assert_equals(session.visibilityState, "visible");
     71  });
     72 
     73  session.addEventListener("visibilitychange", onSessionVisibilityChangeHidden, false);
     74  fakeDeviceController.simulateVisibilityChange("hidden");
     75 
     76  return eventPromise;
     77 };
     78 
     79 xr_session_promise_test(
     80  testName, testFunction, fakeDeviceInitParams, 'immersive-vr');
     81 
     82 </script>