summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/render_state_vertical_fov_inline.https.html
blob: 3b33fb15c31ef472d90e5a751b31ef1e27f6081b (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html>
<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>
let testName = "inlineVerticalFieldOfView is set appropriately on inline sessions";

let fakeDeviceInitParams = VALID_NON_IMMERSIVE_DEVICE;

// These are the min, max, and default from the WebXR Spec
let minFOV = 0.0;
let maxFOV = Math.PI;
let defaultFOV = Math.PI/2;

function assertNotEquals(n1, n2, message) {
  assert_greater_than(Math.abs(n1-n2), FLOAT_EPSILON, message);
}

let testFunction = function(session, fakeDeviceController, t) {
  // Helper method because the renderState does not (per the spec) get updated
  // until the next rAF after it was updated, so this method returns a promise
  // which will resolve when the updated state should be applied.
  function updateAndApplyInlineFOV(fov) {
    session.updateRenderState({
      inlineVerticalFieldOfView: fov
    });

    return new Promise((resolve, reject) => {
      session.requestAnimationFrame(() => { resolve(); });
    });
  }

  // Helper method to keep the line length reasonable with a long attribute name
  // and ensure that the nullable value actually has a value.
  function getFOV() {
    let fov = session.renderState.inlineVerticalFieldOfView;
    t.step(() => {
      assert_not_equals(fov, null);
    });

    return fov;
  }

  return new Promise((resolve, reject) => {
      // Begin by validating that the default is set as expected/specced.
      t.step(() => {
        assert_approx_equals(getFOV(), defaultFOV, FLOAT_EPSILON, "default");
      });

      // Set something below min, and assert that it is not set below the min,
      // and significantly different from the default.
      updateAndApplyInlineFOV(-10).then(() => {

        t.step(() => {
          let currentFOV = getFOV();
          assert_greater_than(currentFOV, minFOV, "FOV must be set to something greater than min");
          assert_less_than(currentFOV, maxFOV, "FOV must be set to something less than max");
          assertNotEquals(currentFOV, defaultFOV, "FOV should no longer be set to the default");
        });

        // Set something above the max and assert that it is set to the max.
        updateAndApplyInlineFOV(10).then(()=> {
          t.step(()=> {
            let currentFOV = getFOV();
            assert_greater_than(currentFOV, minFOV, "FOV must be set to something greater than min");
            assert_less_than(currentFOV, maxFOV, "FOV must be set to something less than max");
            assertNotEquals(currentFOV, defaultFOV, "FOV should not be set to the default");
          });

          // Set to something reasonable and assert that the value gets set.
          let normalFOV = 1.5;
          updateAndApplyInlineFOV(normalFOV).then(() => {
            t.step(() => {
              assert_approx_equals(getFOV(), normalFOV, FLOAT_EPSILON, "FOV within min and max should get set");
            });

            resolve();
          });
        });
      });
  });
};

xr_session_promise_test(
  testName, testFunction, fakeDeviceInitParams, 'inline');

</script>