summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/xrSession_requestAnimationFrame_data_valid.https.html
blob: 812c79c1d58f8b05b08d6ad47c513d990216e696 (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
<!DOCTYPE html>
<body>
  <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>
    const testName = "RequestAnimationFrame resolves with good data";

    const fakeDeviceInitOptions = TRACKED_IMMERSIVE_DEVICE;

    let testSession;

    function checkView(view) {
      assert_not_equals(view, null);
      assert_not_equals(view.transform, null);

      let inv_view_transform = view.transform.inverse;
      assert_not_equals(inv_view_transform, null);
      assert_not_equals(inv_view_transform.matrix, null);
      assert_equals(inv_view_transform.matrix.length, 16);
    }

    let testFunction = function(session, testDeviceController) {
      testSession = session;
      return session.requestReferenceSpace('local')
        .then((referenceSpace) => new Promise((resolve) => {

          function onFrame(time, xrFrame) {
            assert_true(xrFrame instanceof XRFrame);

            let viewerPose = xrFrame.getViewerPose(referenceSpace);

            assert_not_equals(viewerPose, null);
            for(let i = 0; i < IDENTITY_MATRIX.length; i++) {
              assert_equals(viewerPose.transform.matrix[i], IDENTITY_MATRIX[i]);
            }

            assert_not_equals(viewerPose.views, null);
            assert_equals(viewerPose.views.length, 2);
            checkView(viewerPose.views[0]);
            checkView(viewerPose.views[1]);

            // Test does not complete until the returned promise resolves.
            resolve();
          }

          testSession.requestAnimationFrame(onFrame);
        })
      );
    }

    xr_session_promise_test(
      testName, testFunction, fakeDeviceInitOptions, 'immersive-vr');
  </script>
</body>