tor-browser

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

browser_inspector-retain.js (3022B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 Services.scriptloader.loadSubScript(
      7  "chrome://mochitests/content/browser/devtools/server/tests/browser/inspector-helpers.js",
      8  this
      9 );
     10 
     11 // Get a hold of a node, remove it from the doc and retain it at the same time.
     12 // We should always win that race (even though the mutation happens before the
     13 // retain request), because we haven't issued `getMutations` yet.
     14 add_task(async function testWinRace() {
     15  const { walker } = await initInspectorFront(
     16    MAIN_DOMAIN + "inspector-traversal-data.html"
     17  );
     18 
     19  const front = await walker.querySelector(walker.rootNode, "#a");
     20  const onMutation = waitForMutation(walker, isChildList);
     21  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     22    const contentNode = content.document.querySelector("#a");
     23    contentNode.remove();
     24  });
     25  // Now wait for that mutation and retain response to come in.
     26  await walker.retainNode(front);
     27  await onMutation;
     28 
     29  await assertOwnershipTrees(walker);
     30  is(walker._retainedOrphans.size, 1, "Should have a retained orphan.");
     31  ok(
     32    walker._retainedOrphans.has(front),
     33    "Should have retained our expected node."
     34  );
     35  await walker.unretainNode(front);
     36 
     37  // Make sure we're clear for the next test.
     38  await assertOwnershipTrees(walker);
     39  is(walker._retainedOrphans.size, 0, "Should have no more retained orphans.");
     40 });
     41 
     42 // Same as above, but issue the request right after the 'new-mutations' event, so that
     43 // we *lose* the race.
     44 add_task(async function testLoseRace() {
     45  const { walker } = await initInspectorFront(
     46    MAIN_DOMAIN + "inspector-traversal-data.html"
     47  );
     48 
     49  const front = await walker.querySelector(walker.rootNode, "#z");
     50  const onMutation = walker.once("new-mutations");
     51  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     52    const contentNode = content.document.querySelector("#z");
     53    contentNode.remove();
     54  });
     55  await onMutation;
     56 
     57  // Verify that we have an outstanding request (no good way to tell that it's a
     58  // getMutations request, but there's nothing else it would be).
     59  is(walker._requests.length, 1, "Should have an outstanding request.");
     60  try {
     61    await walker.retainNode(front);
     62    ok(false, "Request should not have succeeded!");
     63  } catch (err) {
     64    // XXX: Switched to from ok() to todo_is() in Bug 1467712. Follow up in
     65    // 1500960
     66    // This is throwing because of
     67    // `gInspectee.querySelector("#z").parentNode = null;` two blocks above...
     68    // Even if you fix that, the test is still failing because "#a" was removed
     69    // by the previous test. I am switching this to "#z" because I think that
     70    // was the original intent. Still not failing with the expected error message
     71    // Needs more work.
     72    // ok(err, "noSuchActor", "Should have lost the race.");
     73    is(
     74      walker._retainedOrphans.size,
     75      0,
     76      "Should have no more retained orphans."
     77    );
     78    // Don't re-throw the error.
     79  }
     80 });