tor-browser

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

browser_browser_toolbox_unavailable_children.js (4921B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // There are shutdown issues for which multiple rejections are left uncaught.
      5 // See bug 1018184 for resolving these issues.
      6 const { PromiseTestUtils } = ChromeUtils.importESModule(
      7  "resource://testing-common/PromiseTestUtils.sys.mjs"
      8 );
      9 PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/);
     10 
     11 Services.scriptloader.loadSubScript(
     12  "chrome://mochitests/content/browser/devtools/client/inspector/test/shared-head.js",
     13  this
     14 );
     15 
     16 // On debug test machine, it takes about 50s to run the test.
     17 requestLongerTimeout(4);
     18 
     19 // This test is used to test a badge displayed in the markup view under content
     20 // browser elements when switching from Multi Process mode to Parent Process
     21 // mode.
     22 
     23 add_task(async function () {
     24  // Forces the Browser Toolbox to open on the inspector by default
     25  await pushPref("devtools.browsertoolbox.panel", "inspector");
     26  await pushPref("devtools.browsertoolbox.scope", "everything");
     27 
     28  const tab = await addTab(
     29    "https://example.com/document-builder.sjs?html=<div id=pick-me>Pickme"
     30  );
     31  tab.linkedBrowser.setAttribute("test-tab", "true");
     32 
     33  const ToolboxTask = await initBrowserToolboxTask();
     34 
     35  await ToolboxTask.importFunctions({
     36    waitUntil,
     37    getNodeFront,
     38    selectNode,
     39  });
     40 
     41  await ToolboxTask.spawn([], async () => {
     42    /* global gToolbox */
     43    const inspector = gToolbox.getPanel("inspector");
     44 
     45    info("Select the test browser element.");
     46    await selectNode('browser[remote="true"][test-tab]', inspector);
     47 
     48    info("Retrieve the node front for selected node.");
     49    const browserNodeFront = inspector.selection.nodeFront;
     50    ok(!!browserNodeFront, "Retrieved a node front for the browser");
     51    is(browserNodeFront.displayName, "browser");
     52 
     53    // Small helper to expand containers and return the child container
     54    // matching the provided display name.
     55    async function expandContainer(container, expectedChildName) {
     56      info(`Expand the node expected to contain a ${expectedChildName}`);
     57      await inspector.markup.expandNode(container.node);
     58      await waitUntil(() => !!container.getChildContainers().length);
     59 
     60      const children = container
     61        .getChildContainers()
     62        .filter(child => child.node.displayName === expectedChildName);
     63      is(children.length, 1);
     64      return children[0];
     65    }
     66 
     67    info("Check that the corresponding markup view container has children");
     68    const browserContainer = inspector.markup.getContainer(browserNodeFront);
     69    ok(browserContainer.hasChildren);
     70    ok(
     71      !browserContainer.node.childrenUnavailable,
     72      "childrenUnavailable un-set"
     73    );
     74    ok(
     75      !browserContainer.elt.querySelector(".unavailable-children"),
     76      "The unavailable badge is not displayed"
     77    );
     78 
     79    // Store the asserts as a helper to reuse it later in the test.
     80    async function assertMarkupView() {
     81      info("Check that the children are #document > html > body > div");
     82      let container = await expandContainer(browserContainer, "#document");
     83      container = await expandContainer(container, "html");
     84      container = await expandContainer(container, "body");
     85      container = await expandContainer(container, "div");
     86 
     87      info("Select the #pick-me div");
     88      await selectNode(container.node, inspector);
     89      is(inspector.selection.nodeFront.id, "pick-me");
     90    }
     91    await assertMarkupView();
     92 
     93    const parentProcessScope = gToolbox.doc.querySelector(
     94      'input[name="chrome-debug-mode"][value="parent-process"]'
     95    );
     96 
     97    info("Switch to parent process only scope");
     98    const onInspectorUpdated = inspector.once("inspector-updated");
     99    parentProcessScope.click();
    100    await onInspectorUpdated;
    101 
    102    // Note: `getChildContainers` returns null when the container has no
    103    // children, instead of an empty array.
    104    await waitUntil(() => browserContainer.getChildContainers() === null);
    105 
    106    ok(!browserContainer.hasChildren, "browser container has no children");
    107    ok(browserContainer.node.childrenUnavailable, "childrenUnavailable set");
    108    ok(
    109      !!browserContainer.elt.querySelector(".unavailable-children"),
    110      "The unavailable badge is displayed"
    111    );
    112 
    113    const everythingScope = gToolbox.doc.querySelector(
    114      'input[name="chrome-debug-mode"][value="everything"]'
    115    );
    116 
    117    info("Switch to multi process scope");
    118    everythingScope.click();
    119 
    120    info("Wait until browserContainer has children");
    121    await waitUntil(() => browserContainer.hasChildren);
    122    ok(browserContainer.hasChildren, "browser container has children");
    123    ok(
    124      !browserContainer.node.childrenUnavailable,
    125      "childrenUnavailable un-set"
    126    );
    127    ok(
    128      !browserContainer.elt.querySelector(".unavailable-children"),
    129      "The unavailable badge is no longer displayed"
    130    );
    131 
    132    await assertMarkupView();
    133  });
    134 
    135  await ToolboxTask.destroy();
    136 });