tor-browser

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

browser_shutdown_proxy_doc_acc_reference.js (2220B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 add_task(async function () {
      8  let docLoaded = waitForEvent(
      9    Ci.nsIAccessibleEvent.EVENT_DOCUMENT_LOAD_COMPLETE,
     10    "body"
     11  );
     12  const [a11yInitObserver, a11yInit] = initAccService();
     13  await a11yInitObserver;
     14 
     15  let accService = Cc["@mozilla.org/accessibilityService;1"].getService(
     16    Ci.nsIAccessibilityService
     17  );
     18  ok(accService, "Service initialized");
     19  await a11yInit;
     20 
     21  await BrowserTestUtils.withNewTab(
     22    {
     23      gBrowser,
     24      url: `data:text/html,
     25      <html>
     26        <head>
     27          <meta charset="utf-8"/>
     28          <title>Accessibility Test</title>
     29        </head>
     30        <body id="body"></body>
     31      </html>`,
     32    },
     33    async function () {
     34      let docLoadedEvent = await docLoaded;
     35      let docAcc = docLoadedEvent.accessibleDocument;
     36      ok(docAcc, "Accessible document proxy is created");
     37      // Remove unnecessary dangling references
     38      docLoaded = null;
     39      docLoadedEvent = null;
     40      forceGC();
     41 
     42      let canShutdown = false;
     43      const [a11yShutdownObserver, a11yShutdownPromise] = shutdownAccService();
     44      await a11yShutdownObserver;
     45      const a11yShutdown = new Promise((resolve, reject) =>
     46        a11yShutdownPromise.then(() =>
     47          canShutdown
     48            ? resolve()
     49            : reject("Accessible service was shut down incorrectly")
     50        )
     51      );
     52 
     53      accService = null;
     54      ok(!accService, "Service is removed");
     55      // Force garbage collection that should not trigger shutdown because there
     56      // is a reference to an accessible proxy.
     57      forceGC();
     58      // Have some breathing room when removing a11y service references.
     59      await TestUtils.waitForTick();
     60 
     61      // Now allow a11y service to shutdown.
     62      canShutdown = true;
     63      // Remove a last reference to an accessible document proxy.
     64      docAcc = null;
     65      ok(!docAcc, "Accessible document proxy is removed");
     66 
     67      // Force garbage collection that should now trigger shutdown.
     68      forceGC();
     69      await a11yShutdown;
     70    }
     71  );
     72 });