tor-browser

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

test_browser_lifetime.js (1524B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const { XPCShellContentUtils } = ChromeUtils.importESModule(
      7  "resource://testing-common/XPCShellContentUtils.sys.mjs"
      8 );
      9 XPCShellContentUtils.ensureInitialized(this);
     10 const server = XPCShellContentUtils.createHttpServer({
     11  hosts: ["example.com"],
     12 });
     13 server.registerPathHandler("/dummy", (request, response) => {
     14  response.setStatusLine(request.httpVersion, 200, "OK");
     15  response.write("ok");
     16 });
     17 
     18 add_task(async function () {
     19  const { FxAccountsPairingChannel } = ChromeUtils.importESModule(
     20    "resource://gre/modules/FxAccountsPairingChannel.sys.mjs"
     21  );
     22 
     23  // Collect the module top-level variables and the pointed objects.
     24  for (let i = 0; i < 100; i++) {
     25    Cu.forceGC();
     26    Cu.forceCC();
     27    await new Promise(resolve => executeSoon(resolve));
     28  }
     29 
     30  let caught = false;
     31  try {
     32    // The windowless browser in FxAccountsPairingChannel.sys.mjs should still
     33    // be alive, and the `new WebSocket(...)` call inside it shouldn't hit the
     34    // dead object error.
     35    //
     36    // NOTE: The connection itself will hit error.
     37    await FxAccountsPairingChannel._makePairingChannel(
     38      "ws://example.com/dummy"
     39    );
     40  } catch (e) {
     41    caught = true;
     42    Assert.notEqual(
     43      e.message,
     44      "can't access dead object",
     45      "Touching the windowless browser after GC/CC should not hit dead object"
     46    );
     47  }
     48  Assert.ok(caught, "Exception should be caught for connection");
     49 });