summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webxr/anchors/ar_anchor_freefloating_pause_resume_stop.https.html
blob: 6eb6bc76e64c963ab1512998c9262489f528d4f2 (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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!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_asserts.js"></script>
<script src="../resources/webxr_test_constants.js"></script>
<script src="../resources/webxr_test_constants_fake_world.js"></script>

<script>

// 1m above world origin.
const VIEWER_ORIGIN_TRANSFORM = {
  position: [0, 1, 0],
  orientation: [0, 0, 0, 1],
};

const fakeDeviceInitParams = {
  supportedModes: ["immersive-ar"],
  views: VALID_VIEWS,
  supportedFeatures: ALL_FEATURES,
  viewerOrigin: VIEWER_ORIGIN_TRANSFORM,
};

// All test cases require anchors.
const sessionInit = { 'requiredFeatures': ['anchors'] };

// Create an anchor, pause tracking, resume tracking, & stop tracking and validate
// that the state changes are propagated to the caller.
const anchorCreatePauseTrackingResumeAndDelete = function(session, fakeDeviceController, t) {
  const debug = xr_debug.bind(this, 'anchorCreatePauseTrackingResumeAndDelete');

  let anchorController = null;
  fakeDeviceController.setAnchorCreationCallback((parameters, controller) => {
      anchorController = controller;
      return Promise.resolve(true);
  });

  const watcherDone = new Event("watcherdone");
  const eventWatcher = new EventWatcher(t, session, ["watcherdone"]);
  const eventPromise = eventWatcher.wait_for(["watcherdone"]);

  session.requestReferenceSpace('local').then((localRefSpace) => {
    debug("requesting animation frame");

    session.requestAnimationFrame((time, frame) => {
      debug("rAF 1");

      let createdAnchor = null;
      frame.createAnchor(new XRRigidTransform(), localRefSpace)
        .then((anchor) => {
          createdAnchor = anchor;
        });

      session.requestAnimationFrame((time_2, frame_2) => {
        debug("rAF 2");

        t.step(() => {
          assert_true(frame_2.getPose(createdAnchor.anchorSpace, localRefSpace) != null,
                      "Newly created anchor should have a pose!");
          assert_true(frame_2.trackedAnchors.has(createdAnchor),
                      "Newly created anchor must be in tracked anchors set on subsequent RAF (2)!");
        });

        anchorController.pauseTracking();

        session.requestAnimationFrame((time_3, frame_3) => {
          debug("rAF 3");

          t.step(() => {
            assert_true(frame_3.getPose(createdAnchor.anchorSpace, localRefSpace) == null,
                        "Newly created anchor with paused tracking should not have a pose!");
            assert_true(frame_3.trackedAnchors.has(createdAnchor),
                        "Newly created anchor with paused tracking must be in tracked anchors set on subsequent RAF (3)!");
          });

          anchorController.resumeTracking();

          session.requestAnimationFrame((time_4, frame_4) => {
            debug("rAF 4");

            t.step(() => {
              assert_true(frame_4.trackedAnchors.has(createdAnchor),
                          "Newly created anchor with resumed tracking must be in tracked anchors set on subsequent RAF (4)!");
              assert_true(frame_4.getPose(createdAnchor.anchorSpace, localRefSpace) != null,
                          "Newly created anchor with resumed tracking should have a pose!");
            });

            anchorController.stopTracking();

            session.requestAnimationFrame((time_5, frame_5) => {
              debug("rAF 5");

              t.step(() => {
                assert_false(frame_5.trackedAnchors.has(createdAnchor),
                            "Newly created anchor with stopped tracking must not be in tracked anchors set on subsequent RAF (5)!");
              });

              session.dispatchEvent(watcherDone);
            });
          });
        });
      });
    });
  }); // session.requestReferenceSpace(...).then({...});

  return eventPromise;
};


xr_session_promise_test(
  "Ensures free-floating anchor state changes get propagated",
  anchorCreatePauseTrackingResumeAndDelete, fakeDeviceInitParams,
  'immersive-ar', sessionInit);

</script>