tor-browser

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

test-fully-active.https.html (2646B)


      1 <!DOCTYPE html>
      2 <html>
      3  <head>
      4    <meta charset="utf-8" />
      5    <title>WebShare Test: consume user activation</title>
      6    <link rel="help" href="https://github.com/w3c/web-share/pull/219" />
      7    <script src="/resources/testharness.js"></script>
      8    <script src="/resources/testharnessreport.js"></script>
      9    <script src="/resources/testdriver.js"></script>
     10    <script src="/resources/testdriver-vendor.js"></script>
     11  </head>
     12  <body>
     13    <script>
     14      async function loadIframe() {
     15        const iframe = document.createElement("iframe");
     16        iframe.src = "./resources/blank.html";
     17        document.body.appendChild(iframe);
     18        await new Promise((resolve) => {
     19          iframe.addEventListener("load", resolve);
     20        });
     21        return iframe;
     22      }
     23 
     24      promise_test(async (t) => {
     25        const iframe = await loadIframe();
     26        const { contentWindow } = iframe;
     27        const { navigator, DOMException } = contentWindow;
     28        const data = { text: "text" };
     29        iframe.remove();
     30        await promise_rejects_dom(
     31          t,
     32          "InvalidStateError",
     33          DOMException,
     34          navigator.share(data),
     35          "Expected promise rejected with InvalidStateError from .share()"
     36        );
     37      }, "calling share() on non-fully active document returns a promise rejected with InvalidStateError");
     38 
     39      promise_test(async (t) => {
     40        const iframe = await loadIframe();
     41        const { contentWindow } = iframe;
     42        const { navigator, DOMException } = contentWindow;
     43        const data = { text: "text" };
     44 
     45        // Acquire transient activation, but make the iframe non-fully-active
     46        await test_driver.bless(
     47          "web share",
     48          () => {
     49            iframe.remove();
     50          },
     51          contentWindow
     52        );
     53 
     54        await promise_rejects_dom(
     55          t,
     56          "InvalidStateError",
     57          DOMException,
     58          navigator.share(data),
     59          "Expected promise rejected with InvalidStateError from .share()"
     60        );
     61      }, "calling share() with transient activation on non-fully active document returns a promise rejected with InvalidStateError");
     62 
     63      promise_test(async (t) => {
     64        const iframe = await loadIframe();
     65        const { contentWindow } = iframe;
     66        const { navigator } = contentWindow;
     67        const data = { text: "text" };
     68 
     69        assert_true(navigator.canShare(data), "doc is fully active, so true");
     70 
     71        iframe.remove();
     72 
     73        assert_false(navigator.canShare(data), "not fully active, so false");
     74      }, "calling canShare() on a non-fully active document returns false");
     75    </script>
     76  </body>
     77 </html>