tor-browser

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

xrView_visibility_mask_change.https.html (3383B)


      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 <script src="resources/webxr_test_asserts.js"></script>
      7 
      8 <script>
      9 
     10 let testName = "VisibilityMaskChangeEvent properly fires with expected values";
     11 
     12 let fakeViews = [{
     13        eye:"left",
     14        viewOffset: LEFT_OFFSET,
     15        resolution: VALID_RESOLUTION,
     16        fieldOfView: VALID_FIELD_OF_VIEW,
     17        // The webxr-test-api requires that we still set this for now, but it is
     18        // supposed to be ignored.
     19        projectionMatrix: IDENTITY_MATRIX
     20    }, {
     21        eye:"right",
     22        viewOffset: RIGHT_OFFSET,
     23        resolution: VALID_RESOLUTION,
     24        fieldOfView: VALID_FIELD_OF_VIEW,
     25        // The webxr-test-api requires that we still set this for now, but it is
     26        // supposed to be ignored.
     27        projectionMatrix: IDENTITY_MATRIX
     28    },
     29 ];
     30 
     31 const leftMask = {
     32  vertices: [ 0, 0, 0, 1, 1, 0, 1, 1 ],
     33  indices: [0, 1, 2, 0, 2, 3]
     34 };
     35 
     36 const rightMask = {
     37  vertices: [ 1, 1, 1, 2, 2, 1, 2, 2 ],
     38  indices: [0, 2, 3, 0, 1, 2]
     39 };
     40 
     41 let fakeDeviceInitParams = {
     42    supportsImmersive: true,
     43    supportedModes: ["inline", "immersive-vr"],
     44    views: fakeViews,
     45    viewerOrigin: IDENTITY_TRANSFORM,
     46    supportedFeatures: ALL_FEATURES
     47 };
     48 
     49 function assert_list_approx_equals(actual, expected, prefix) {
     50  assert_equals(expected.length, actual.length, prefix + ": lengths not equal");
     51  for (let i = 0; i < expected.length; i++) {
     52    assert_approx_equals(actual[i], expected[i], FLOAT_EPSILON, prefix +
     53    ": mismatch in list at component: " + i +
     54    ", expected=" + expected, " actual=" + actual);
     55  }
     56 }
     57 
     58 function validateMask(fakeView, mask) {
     59  assert_equals(mask.eye, fakeView.eye);
     60  assert_list_approx_equals(mask.vertices, fakeView.visibilityMask.vertices, fakeView.eye);
     61  assert_list_approx_equals(mask.indices, fakeView.visibilityMask.indices, fakeView.eye);
     62 }
     63 
     64 let testFunction = function(session, fakeDeviceController, t) {
     65  let eventWatcher = new EventWatcher(t, session, ["watcherdone"]);
     66  let visibilityMaskEvents = 0;
     67  session.addEventListener('visibilitymaskchange', (mask)=> {
     68    visibilityMaskEvents++;
     69    t.step(() => {
     70      assert_equals(mask.session, session);
     71      assert_less_than(mask.index, fakeViews.length, "Received an unexpected view");
     72      validateMask(fakeViews[mask.index], mask);
     73 
     74 
     75      if (visibilityMaskEvents >= 2) {
     76        session.dispatchEvent(new Event("watcherdone"))
     77      }
     78    });
     79  });
     80 
     81  // We *could* set the visibilityMasks on the views by default; but UAs do not
     82  // HAVE to, but MAY send events during the session resolution. By setting this
     83  // after the session is resolved and the event is subscribed, we ensure we
     84  // don't miss the event due to UA allowable differences.
     85  fakeViews[0].visibilityMask = leftMask;
     86  fakeViews[1].visibilityMask = rightMask;
     87  fakeDeviceController.setViews(fakeViews);
     88 
     89  // We don't need to do anything on the next animation frame, the act of
     90  // requesting it after we update the views should be enough to trigger our
     91  // events.
     92  session.requestAnimationFrame(()=>{});
     93  return eventWatcher.wait_for(["watcherdone"]);
     94 };
     95 
     96 xr_session_promise_test(
     97  testName, testFunction, fakeDeviceInitParams, 'immersive-vr');
     98 
     99 </script>