tor-browser

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

non-fully-active.https.html (2956B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8" />
      3 <title>Digital Credentials Test: non-fully active document</title>
      4 <link
      5  rel="help"
      6  href="https://github.com/w3c/webappsec-credential-management"
      7 />
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 <script src="/resources/testdriver.js"></script>
     11 <script src="/resources/testdriver-vendor.js"></script>
     12 <body></body>
     13 <script type="module">
     14  import { makeGetOptions } from "./support/helper.js";
     15  async function createIframe() {
     16    const iframe = document.createElement("iframe");
     17    await new Promise((resolve) => {
     18      iframe.addEventListener("load", resolve, { once: true });
     19      iframe.src = "about:blank";
     20      document.body.appendChild(iframe);
     21    });
     22    return iframe;
     23  }
     24 
     25  promise_test(async (t) => {
     26    const iframe = await createIframe();
     27 
     28    // The signal check happens after the fully active check.
     29    // This allows us to confirm the right error is thrown
     30    // and in the right order.
     31    const controller = new iframe.contentWindow.AbortController();
     32    const signal = controller.signal;
     33    controller.abort();
     34 
     35    // Steal all the needed references.
     36    const { credentials } = iframe.contentWindow.navigator;
     37    const DOMExceptionCtor = iframe.contentWindow.DOMException;
     38 
     39    // No longer fully active.
     40    iframe.remove();
     41 
     42    // Try to get credentials while not fully active...
     43    await promise_rejects_dom(
     44      t,
     45      "InvalidStateError",
     46      DOMExceptionCtor,
     47      credentials.get({ signal }),
     48      "Expected InvalidStateError for get() on non-fully-active document"
     49    );
     50 
     51    // Try to create credentials while not fully active...
     52    await promise_rejects_dom(
     53      t,
     54      "InvalidStateError",
     55      DOMExceptionCtor,
     56      credentials.create({ signal }),
     57      "Expected InvalidStateError for create() on non-fully-active document"
     58    );
     59 
     60    // Try to prevent silent access while not fully active...
     61    await promise_rejects_dom(
     62      t,
     63      "InvalidStateError",
     64      DOMExceptionCtor,
     65      credentials.preventSilentAccess(),
     66      "Expected InvalidStateError for preventSilentAccess() on non-fully-active document"
     67    );
     68  }, "non-fully active document behavior for CredentialsContainer");
     69 
     70  promise_test(async (t) => {
     71    let iframe = await createIframe();
     72    const DOMExceptionCtor = iframe.contentWindow.DOMException;
     73    let stolenNavigator = iframe.contentWindow.navigator;
     74    const request = makeGetOptions();
     75    await test_driver.bless("User activation", null, iframe.contentWindow);
     76    await iframe.focus();
     77    const p = promise_rejects_dom(
     78      t,
     79      "AbortError",
     80      DOMExceptionCtor,
     81      iframe.contentWindow.navigator.credentials.get(request),
     82      "Expect promise to reject if the document becomes non-fully active"
     83    );
     84    iframe.remove();
     85    await p;
     86  }, "Promise rejects with DOMException when the document becomes non-fully active");
     87 </script>