tor-browser

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

permissions-garbage-collect.https.html (1781B)


      1 <!DOCTYPE html>
      2 <meta charset="utf-8" />
      3 <title>Test Permission garbage collection persistance.</title>
      4 <link rel="help" href="https://github.com/w3c/permissions/pull/256" />
      5 <script src="/resources/testharness.js"></script>
      6 <script src="/resources/testharnessreport.js"></script>
      7 <script src="/resources/testdriver.js"></script>
      8 <script src="/resources/testdriver-vendor.js"></script>
      9 <body>
     10  <script>
     11    async function createABunchOfGarbage() {
     12      const promises = [];
     13      for (let i = 0; i < 25; i++) {
     14        const promise = new Promise((r) => {
     15          const iframe = document.createElement("iframe");
     16          iframe.onload = () => r(iframe);
     17          iframe.src = "about:blank";
     18          document.body.appendChild(iframe);
     19        });
     20        promises.push(promise);
     21      }
     22      const iframes = await Promise.all(promises);
     23      iframes.forEach((iframe) => iframe.remove());
     24    }
     25 
     26    promise_test(async (t) => {
     27      t.add_cleanup(() => {
     28        return test_driver.set_permission({ name: "geolocation" }, "prompt");
     29      });
     30 
     31      const eventPromise = new Promise(
     32        async (r) => {
     33          // we create the status here, but it goes out of scope
     34          // at the end of the function. Thus, we assume it will be
     35          // garbage collected.
     36          const status = await navigator.permissions.query({
     37            name: "geolocation",
     38          });
     39          status.addEventListener("change", r);
     40        },
     41        { once: true }
     42      );
     43 
     44      // Maybe got garbage collected.
     45      await createABunchOfGarbage();
     46 
     47      // Causes event to fire.
     48      await test_driver.set_permission({ name: "geolocation" }, "granted");
     49      await eventPromise;
     50    }, "Events fire even if the status object is garbage collected");
     51  </script>
     52 </body>