tor-browser

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

user-activation.https.html (2501B)


      1 <!DOCTYPE html>
      2 <title>Digital Credential API: get() consumes user activation.</title>
      3 <script src="/resources/testdriver.js"></script>
      4 <script src="/resources/testdriver-vendor.js"></script>
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="support/helper.js" type="module"></script>
      8 <body></body>
      9 <script type="module">
     10  import { makeGetOptions, makeCreateOptions } from "./support/helper.js";
     11 
     12  promise_test(async (t) => {
     13    assert_false(
     14      navigator.userActivation.isActive,
     15      "User activation should not be active"
     16    );
     17    const options = makeGetOptions();
     18    await promise_rejects_dom(
     19      t,
     20      "NotAllowedError",
     21      navigator.credentials.get(options)
     22    );
     23  }, "navigator.credentials.get() calling the API without user activation should reject with NotAllowedError.");
     24 
     25  promise_test(async (t) => {
     26    await test_driver.bless();
     27    const abort = new AbortController();
     28    const options = makeGetOptions({ signal: abort.signal });
     29    assert_true(
     30      navigator.userActivation.isActive,
     31      "User activation should be active after test_driver.bless()."
     32    );
     33 
     34    const getPromise = navigator.credentials.get(options);
     35    abort.abort();
     36    await promise_rejects_dom(t, "AbortError", getPromise);
     37    assert_false(
     38      navigator.userActivation.isActive,
     39      "User activation should be consumed after navigator.credentials.get()."
     40    );
     41  }, "navigator.credentials.get() consumes user activation.");
     42 
     43  promise_test(async (t) => {
     44    assert_false(
     45      navigator.userActivation.isActive,
     46      "User activation should not be active"
     47    );
     48    const options = makeCreateOptions({protocol: []});
     49    await promise_rejects_dom(
     50      t,
     51      "NotAllowedError",
     52      navigator.credentials.create(options)
     53    );
     54  }, "navigator.credentials.create() calling the API without user activation should reject with NotAllowedError.");
     55 
     56  promise_test(async (t) => {
     57    await test_driver.bless();
     58    assert_true(
     59      navigator.userActivation.isActive,
     60      "User activation should be active after test_driver.bless()."
     61    );
     62    const options = makeCreateOptions({protocol: []});
     63    await promise_rejects_js(t, TypeError, navigator.credentials.create(options));
     64    assert_false(
     65      navigator.userActivation.isActive,
     66      "User activation should be consumed after navigator.credentials.create()."
     67    );
     68  }, "navigator.credentials.create() consumes user activation.");
     69 </script>