tor-browser

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

render_state_vertical_fov_inline.https.html (3211B)


      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 = "inlineVerticalFieldOfView is set appropriately on inline sessions";
      9 
     10 let fakeDeviceInitParams = VALID_NON_IMMERSIVE_DEVICE;
     11 
     12 // These are the min, max, and default from the WebXR Spec
     13 let minFOV = 0.0;
     14 let maxFOV = Math.PI;
     15 let defaultFOV = Math.PI/2;
     16 
     17 function assertNotEquals(n1, n2, message) {
     18  assert_greater_than(Math.abs(n1-n2), FLOAT_EPSILON, message);
     19 }
     20 
     21 let testFunction = function(session, fakeDeviceController, t) {
     22  // Helper method because the renderState does not (per the spec) get updated
     23  // until the next rAF after it was updated, so this method returns a promise
     24  // which will resolve when the updated state should be applied.
     25  function updateAndApplyInlineFOV(fov) {
     26    session.updateRenderState({
     27      inlineVerticalFieldOfView: fov
     28    });
     29 
     30    return new Promise((resolve, reject) => {
     31      session.requestAnimationFrame(() => { resolve(); });
     32    });
     33  }
     34 
     35  // Helper method to keep the line length reasonable with a long attribute name
     36  // and ensure that the nullable value actually has a value.
     37  function getFOV() {
     38    let fov = session.renderState.inlineVerticalFieldOfView;
     39    t.step(() => {
     40      assert_not_equals(fov, null);
     41    });
     42 
     43    return fov;
     44  }
     45 
     46  return new Promise((resolve, reject) => {
     47      // Begin by validating that the default is set as expected/specced.
     48      t.step(() => {
     49        assert_approx_equals(getFOV(), defaultFOV, FLOAT_EPSILON, "default");
     50      });
     51 
     52      // Set something below min, and assert that it is not set below the min,
     53      // and significantly different from the default.
     54      updateAndApplyInlineFOV(-10).then(() => {
     55 
     56        t.step(() => {
     57          let currentFOV = getFOV();
     58          assert_greater_than(currentFOV, minFOV, "FOV must be set to something greater than min");
     59          assert_less_than(currentFOV, maxFOV, "FOV must be set to something less than max");
     60          assertNotEquals(currentFOV, defaultFOV, "FOV should no longer be set to the default");
     61        });
     62 
     63        // Set something above the max and assert that it is set to the max.
     64        updateAndApplyInlineFOV(10).then(()=> {
     65          t.step(()=> {
     66            let currentFOV = getFOV();
     67            assert_greater_than(currentFOV, minFOV, "FOV must be set to something greater than min");
     68            assert_less_than(currentFOV, maxFOV, "FOV must be set to something less than max");
     69            assertNotEquals(currentFOV, defaultFOV, "FOV should not be set to the default");
     70          });
     71 
     72          // Set to something reasonable and assert that the value gets set.
     73          let normalFOV = 1.5;
     74          updateAndApplyInlineFOV(normalFOV).then(() => {
     75            t.step(() => {
     76              assert_approx_equals(getFOV(), normalFOV, FLOAT_EPSILON, "FOV within min and max should get set");
     77            });
     78 
     79            resolve();
     80          });
     81        });
     82      });
     83  });
     84 };
     85 
     86 xr_session_promise_test(
     87  testName, testFunction, fakeDeviceInitParams, 'inline');
     88 
     89 </script>