tor-browser

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

permissions-query-feature-policy-attribute.https.sub.html (2074B)


      1 <!doctype html>
      2 <meta charset=utf-8>
      3 <title>Test permissions query againts feature policy allow attribute</title>
      4 <script src=/resources/testharness.js></script>
      5 <script src=/resources/testharnessreport.js></script>
      6 <div id="log"></div>
      7 
      8 <script>
      9  "use strict";
     10 
     11  function test_permissions_query(
     12    feature_description, test, src, expect_state, allow_attribute) {
     13    let frame = document.createElement('iframe');
     14    frame.src = src;
     15 
     16    if (typeof allow_attribute !== 'undefined') {
     17      frame.allow = allow_attribute;
     18    }
     19 
     20    window.addEventListener('message', test.step_func(function handler(evt) {
     21      if (evt.source === frame.contentWindow) {
     22        assert_equals(evt.data.state, expect_state, feature_description);
     23        document.body.removeChild(frame);
     24        window.removeEventListener('message', handler);
     25        test.done();
     26      }
     27    }));
     28 
     29    document.body.appendChild(frame);
     30  }
     31 
     32  const same_origin_src =
     33    "/permissions/feature-policy-permissions-query.html";
     34  const cross_origin_src =
     35    "https://{{domains[www]}}:{{ports[https][0]}}" + same_origin_src;
     36 
     37   async_test(t => {
     38    test_permissions_query(
     39      'navigator.permissions.query("geolocation")',
     40      t,
     41      same_origin_src,
     42      "prompt",
     43      "geolocation"
     44    );
     45  }, 'Permissions.state is "prompt" with allow="geolocation" in same-origin iframes.');
     46 
     47  async_test(t => {
     48    test_permissions_query(
     49      'navigator.permissions.query("geolocation")',
     50      t,
     51      cross_origin_src,
     52      "prompt",
     53      "geolocation"
     54    );
     55  }, 'Permissions.state is "prompt" with allow="geolocation" in cross-origin iframes.');
     56 
     57   async_test(t => {
     58    test_permissions_query(
     59      'navigator.permissions.query("geolocation")',
     60      t,
     61      same_origin_src,
     62      "prompt"
     63    );
     64  }, 'Permission.state is "prompt" in same-origin iframes.');
     65 
     66  async_test(t => {
     67    test_permissions_query(
     68      'navigator.permissions.query("geolocation")',
     69      t,
     70      cross_origin_src,
     71      "denied"
     72    );
     73  }, 'Permission.state is "denied" in cross-origin iframes.');
     74 
     75 </script>