tor-browser

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

ar_dom_overlay_hit_test.https.html (4622B)


      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_constants.js"></script>
      6 <script src="../resources/webxr_test_constants_fake_world.js"></script>
      7 <script src="../resources/webxr_test_asserts.js"></script>
      8 
      9 <style type="text/css">
     10  div {
     11      padding: 10px;
     12      min-width: 10px;
     13      min-height: 10px;
     14  }
     15  iframe {
     16    border: 0;
     17    width: 20px;
     18    height: 20px;
     19  }
     20 </style>
     21 <div id="div_overlay">
     22  <div id="inner_b">
     23  </div>
     24  <!-- This SVG iframe is treated as cross-origin content. -->
     25  <iframe id="iframe" src='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><rect height="20" width="20" fill="red" fill-opacity="0.3"/></svg>'>
     26  </iframe>
     27  <canvas>
     28  </canvas>
     29 </div>
     30 
     31 <script>
     32 
     33 const fakeDeviceInitParams = {
     34  supportedModes: ["immersive-ar"],
     35  views: VALID_VIEWS,
     36  viewerOrigin: IDENTITY_TRANSFORM,
     37  supportedFeatures: ALL_FEATURES,
     38  world: createFakeWorld(5.0, 2.0, 5.0),  // see webxr_test_constants_fake_world.js for details
     39 };
     40 
     41 const hitTestOptionsInit = {
     42  profile: "generic-touchscreen",
     43  offsetRay: new XRRay(),
     44 };
     45 
     46 const SCREEN_POINTER_TRANSFORM = {
     47    position: [0, 0, 0],      // middle of the screen
     48    orientation: [0, 0, 0, 1] // forward-facing
     49 };
     50 
     51 const screen_controller_init = {
     52    handedness: "none",
     53    targetRayMode: "screen",
     54    pointerOrigin: SCREEN_POINTER_TRANSFORM,  // aka mojo_from_pointer
     55    profiles: ["generic-touchscreen",]
     56 };
     57 
     58 const testCrossOriginContent = function(overlayElement, session, fakeDeviceController, t) {
     59  const iframe = document.getElementById('iframe');
     60  const inner_b = document.getElementById('inner_b');
     61 
     62  let debug = xr_debug.bind(this, 'testCrossOriginContent');
     63 
     64  const input_source =
     65      fakeDeviceController.simulateInputSourceConnection(screen_controller_init);
     66  debug('start');
     67  return session.requestReferenceSpace('viewer').then(function(viewerSpace) {
     68    debug('got viewerSpace');
     69    return session.requestHitTestSourceForTransientInput(hitTestOptionsInit)
     70                  .then((hitTestSource) => {
     71      debug('got hitTestSource');
     72      return new Promise((resolve) => {
     73        // Press the primary input button and then release it a short time later.
     74        session.requestAnimationFrame((time, xrFrame) => {
     75          debug('got rAF 1');
     76          input_source.setOverlayPointerPosition(iframe.offsetLeft + 1,
     77                                                 iframe.offsetTop + 1);
     78          input_source.startSelection();
     79 
     80          session.requestAnimationFrame((time, xrFrame) => {
     81            input_source.endSelection();
     82 
     83            // There should be no results for transient input for cross origin content:
     84            const results = xrFrame.getHitTestResultsForTransientInput(hitTestSource);
     85            t.step(() => {
     86              assert_equals(results.length, 0, "Hit test results should be suppressed for cross-origin content");
     87            });
     88 
     89            session.requestAnimationFrame((time, xrFrame) => {
     90              debug('got rAF 2');
     91              // Need to process one more frame to allow select to propagate
     92 
     93              session.requestAnimationFrame((time, xrFrame) => {
     94                debug('got rAF 3');
     95                input_source.setOverlayPointerPosition(inner_b.offsetLeft + 1,
     96                                                       inner_b.offsetTop + 1);
     97                input_source.startSelection();
     98 
     99                session.requestAnimationFrame((time, xrFrame) => {
    100                  debug('got rAF 4');
    101                  input_source.endSelection();
    102 
    103                  const results = xrFrame.getHitTestResultsForTransientInput(hitTestSource);
    104                  t.step(() => {
    105                    // TODO(bialpio): this assertion is currently failing, FIXME
    106                    assert_equals(results.length, 1, "Hit test results should be available for same-origin content");
    107                  });
    108                  debug('resolving');
    109                  resolve();
    110                });
    111              });
    112            });
    113          });
    114        });
    115      });
    116    });
    117  });
    118 };
    119 
    120 xr_session_promise_test(
    121  "Ensures DOM Overlay interactions on cross origin iframe do not cause hit test results to come up",
    122  testCrossOriginContent.bind(this, document.getElementById('div_overlay')),
    123  fakeDeviceInitParams, 'immersive-ar', {
    124    requiredFeatures: ['dom-overlay', 'hit-test'],
    125    domOverlay: { root: document.getElementById('div_overlay') }
    126  });
    127 
    128 </script>