tor-browser

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

ar_hittest_source_cancel.https.html (3747B)


      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_asserts.js"></script>
      6 <script src="../resources/webxr_test_constants.js"></script>
      7 <script src="../resources/webxr_test_constants_fake_world.js"></script>
      8 
      9 <script>
     10 
     11 // at world origin.
     12 const VIEWER_ORIGIN_TRANSFORM = {
     13  position: [0, 0, 0],
     14  orientation: [0, 0, 0, 1],
     15 };
     16 
     17 // at world origin.
     18 const FLOOR_ORIGIN_TRANSFORM = {
     19  position: [0, 0, 0],
     20  orientation: [0, 0, 0, 1],
     21 };
     22 
     23 const fakeDeviceInitParams = {
     24  supportedModes: ["immersive-ar"],
     25  views: VALID_VIEWS,
     26  floorOrigin: FLOOR_ORIGIN_TRANSFORM,    // aka mojo_from_floor
     27  viewerOrigin: VIEWER_ORIGIN_TRANSFORM,  // aka mojo_from_viewer
     28  supportedFeatures: ALL_FEATURES,
     29  world: createFakeWorld(5.0, 2.0, 5.0),  // webxr_test_constants_fake_world.js has detailed description of the fake world
     30 };
     31 
     32 const test_function_generator = function(isTransientTest, isSessionEndedTest) {
     33  return function(session, fakeDeviceController, t) {
     34 
     35    let done = false;
     36 
     37    return session.requestReferenceSpace('local').then((localSpace) => {
     38      const validation_function = (hitTestSource) => {
     39 
     40        const rAFcb = function(time, frame) {
     41          if(isSessionEndedTest) {
     42            // Session is marked as "ended" synchronously, there is no need to
     43            // wait for the promise it returns to settle.
     44            session.end();
     45 
     46            // Currently, the specification does not say what happen
     47            // when a hit test source gets cancelled post-session-end.
     48            hitTestSource.cancel();
     49            done = true;
     50          } else {
     51            hitTestSource.cancel();
     52            t.step(() => {
     53              assert_throws_dom("InvalidStateError", () => hitTestSource.cancel());
     54            });
     55            done = true;
     56          }
     57        };
     58 
     59        session.requestAnimationFrame(rAFcb);
     60 
     61        return t.step_wait(() => done);
     62      };
     63 
     64      // Same validation will happen both in transient and non-transient variant
     65      if(isTransientTest) {
     66        return session.requestHitTestSourceForTransientInput({
     67          profile: "generic-touchscreen",
     68          offsetRay: new XRRay(),
     69        }).then(validation_function);
     70      } else {
     71        return session.requestHitTestSource({
     72          space: localSpace,
     73          offsetRay: new XRRay(),
     74        }).then(validation_function);
     75      }
     76    }); // return session.requestReferenceSpace('local').then((localSpace) => { ...
     77  };  // return function(session, fakeDeviceController, t) { ...
     78 }
     79 
     80 xr_session_promise_test("Ensures hit test source cancellation works when the session has not ended.",
     81  test_function_generator(/*isTransientTest=*/false, /*isSessionEndedTest=*/false),
     82  fakeDeviceInitParams,
     83  'immersive-ar', { 'requiredFeatures': ['hit-test'] });
     84 
     85 xr_session_promise_test("Ensures transient input hit test source cancellation works when the session has not ended.",
     86  test_function_generator(/*isTransientTest=*/true, /*isSessionEndedTest=*/false),
     87  fakeDeviceInitParams,
     88  'immersive-ar', { 'requiredFeatures': ['hit-test'] });
     89 
     90 xr_session_promise_test("Ensures hit test source cancellation works when the session has ended",
     91  test_function_generator(/*isTransientTest=*/false, /*isSessionEndedTest=*/true),
     92  fakeDeviceInitParams,
     93  'immersive-ar', { 'requiredFeatures': ['hit-test'] });
     94 
     95 xr_session_promise_test("Ensures transient input hit test source cancellation works when the session has ended",
     96  test_function_generator(/*isTransientTest=*/true, /*isSessionEndedTest=*/true),
     97  fakeDeviceInitParams,
     98  'immersive-ar', { 'requiredFeatures': ['hit-test'] });
     99 
    100 </script>