tor-browser

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

browser_dbg-features-browser-toolbox-source-tree.js (4092B)


      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 /**
      6 * This test focuses on the SourceTree component, within the browser toolbox.
      7 */
      8 
      9 "use strict";
     10 
     11 requestLongerTimeout(2);
     12 
     13 Services.scriptloader.loadSubScript(
     14  "chrome://mochitests/content/browser/devtools/client/framework/browser-toolbox/test/helpers-browser-toolbox.js",
     15  this
     16 );
     17 
     18 // Test that the Web extension name is shown in source tree rather than
     19 // the extensions internal UUID. This checks both the web toolbox and the
     20 // browser toolbox.
     21 add_task(async function testSourceTreeNamesForWebExtensions() {
     22  await pushPref("devtools.browsertoolbox.scope", "everything");
     23 
     24  // Ensure showing the content scripts
     25  await pushPref("devtools.debugger.show-content-scripts", true);
     26 
     27  const extension = await installAndStartContentScriptExtension();
     28 
     29  const dbg = await initDebugger("doc-content-script-sources.html");
     30  await waitForSourcesInSourceTree(dbg, [], {
     31    noExpand: true,
     32  });
     33 
     34  is(
     35    getSourceTreeLabel(dbg, 4),
     36    "Test content script extension",
     37    "Test content script extension is labeled properly"
     38  );
     39 
     40  await dbg.toolbox.closeToolbox();
     41  await extension.unload();
     42 
     43  // Make sure the toolbox opens with the debugger selected.
     44  await pushPref("devtools.browsertoolbox.panel", "jsdebugger");
     45 
     46  const ToolboxTask = await initBrowserToolboxTask();
     47  await ToolboxTask.importFunctions({
     48    createDebuggerContext,
     49    waitUntil,
     50    findSourceNodeWithText,
     51    findAllElements,
     52    getSelector,
     53    findAllElementsWithSelector,
     54    assertSourceTreeNode,
     55  });
     56 
     57  await ToolboxTask.spawn(selectors, async _selectors => {
     58    this.selectors = _selectors;
     59  });
     60 
     61  await ToolboxTask.spawn(null, async () => {
     62    // Disable autofixing to `Assert` methods which are not available here.
     63    /* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
     64    try {
     65      /* global gToolbox */
     66      // Wait for the debugger to finish loading.
     67      await gToolbox.getPanelWhenReady("jsdebugger");
     68      const dbgx = createDebuggerContext(gToolbox);
     69      let rootNodeForExtensions = null;
     70      await waitUntil(() => {
     71        rootNodeForExtensions = findSourceNodeWithText(dbgx, "extension");
     72        return !!rootNodeForExtensions;
     73      });
     74      // Find the root node for extensions and expand it if needed
     75      if (
     76        !!rootNodeForExtensions &&
     77        !rootNodeForExtensions.querySelector(".theme-twisty.open")
     78      ) {
     79        rootNodeForExtensions.querySelector(".theme-twisty").click();
     80      }
     81 
     82      // Assert that extensions are displayed in the source tree
     83      // with their extension name.
     84      await assertSourceTreeNode(dbgx, "Picture-In-Picture");
     85      await assertSourceTreeNode(dbgx, "Form Autofill");
     86 
     87      const threadLabels = [...findAllElements(dbgx, "sourceTreeThreads")].map(
     88        el => {
     89          return el.textContent;
     90        }
     91      );
     92      is(
     93        threadLabels[0],
     94        "Main Thread",
     95        "The first thread is always the main thread"
     96      );
     97      let lastPID = -1,
     98        lastThreadLabel = "";
     99      for (let i = 1; i < threadLabels.length; i++) {
    100        const label = threadLabels[i];
    101        if (label.startsWith("(pid ")) {
    102          ok(
    103            !lastThreadLabel,
    104            "We should only have content process threads first after the main thread"
    105          );
    106          const pid = parseInt(label.match(/pid (\d+)\)/)[1], 10);
    107          ok(
    108            pid >= lastPID,
    109            `The content process threads are sorted by incremental PID ${pid} > ${lastPID}`
    110          );
    111          lastPID = pid;
    112        } else {
    113          ok(
    114            label.localeCompare(lastThreadLabel) >= 0,
    115            `Worker thread labels are sorted alphabeticaly: ${label} vs ${lastThreadLabel}`
    116          );
    117          lastThreadLabel = label;
    118        }
    119      }
    120    } catch (e) {
    121      console.log("Caught exception in spawn", e);
    122      throw e;
    123    }
    124  });
    125 
    126  await ToolboxTask.destroy();
    127 });