summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/xrWebGLLayer_viewports.https.html
blob: 8654e9e58708f4b056502905040f7dc2b0182aa7 (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
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/webxr_test_constants.js"></script>
<script src="resources/webxr_util.js"></script>
<script src="resources/webxr_test_asserts.js"></script>

<script>

let immersiveTestName = "XRWebGLLayer reports a valid viewports for immersive sessions";
let inlineTestName = "XRWebGLLayer reports a valid viewports for inline sessions";

let fakeDeviceInitParams = TRACKED_IMMERSIVE_DEVICE;

let testFunction = function(session, fakeDeviceController, t) {
  return session.requestReferenceSpace('viewer')
      .then((space) => new Promise((resolve) => {
    function onFrame(time, xrFrame) {
      let viewer_pose = xrFrame.getViewerPose(space);

      let layer = xrFrame.session.renderState.baseLayer;
      for (view of viewer_pose.views) {
        let viewport = layer.getViewport(view);

        t.step(() => {
          // Ensure the returned object is an XRViewport object
          assert_not_equals(viewport, null);
          assert_true(viewport instanceof XRViewport);

          // Ensure the viewport dimensions are valid
          assert_greater_than_equal(viewport.x, 0);
          assert_greater_than_equal(viewport.y, 0);
          assert_greater_than_equal(viewport.width, 1);
          assert_greater_than_equal(viewport.height, 1);
        });

        // Ensure none of the viewports overlap
        for (other of viewer_pose.views) {
          if (view !== other) {
            let otherport = layer.getViewport(other);
            let no_overlap = (viewport.x + viewport.width <= otherport.x) ||
              (otherport.x + otherport.width <= viewport.x) ||
              (viewport.y + viewport.height <= otherport.y) ||
              (otherport.y + otherport.height <= viewport.y);

            t.step(() => {
              assert_true(no_overlap, "Overlap between viewport " + view.eye + " and " + other.eye);
            });
          }
        }
      }

      // Finished test.
      resolve();
    }

    session.requestAnimationFrame(onFrame);
  }));
};

xr_session_promise_test(immersiveTestName, testFunction,
  fakeDeviceInitParams, 'immersive-vr');
xr_session_promise_test(immersiveTestName + ' with secondary views requested', testFunction,
  fakeDeviceInitParams, 'immersive-vr', {'optionalFeatures': ['secondary-views']});
xr_session_promise_test(inlineTestName, testFunction,
  fakeDeviceInitParams, 'inline');
xr_session_promise_test(inlineTestName + ' with secondary views requested', testFunction,
  fakeDeviceInitParams, 'inline', {'optionalFeatures': ['secondary-views']});
</script>