tor-browser

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

browser_aboutdebugging_addons_debug_inspector.js (2828B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 /* import-globals-from helper-addons.js */
      6 Services.scriptloader.loadSubScript(CHROME_URL_ROOT + "helper-addons.js", this);
      7 
      8 // There are shutdown issues for which multiple rejections are left uncaught.
      9 // See bug 1018184 for resolving these issues.
     10 const { PromiseTestUtils } = ChromeUtils.importESModule(
     11  "resource://testing-common/PromiseTestUtils.sys.mjs"
     12 );
     13 PromiseTestUtils.allowMatchingRejectionsGlobally(/File closed/);
     14 
     15 // Avoid test timeouts that can occur while waiting for the "addon-console-works" message.
     16 requestLongerTimeout(2);
     17 
     18 const ADDON_ID = "test-devtools-webextension@mozilla.org";
     19 const ADDON_NAME = "test-devtools-webextension";
     20 
     21 /**
     22 * This test file ensures that the webextension addon developer toolbox:
     23 * - the webextension developer toolbox has a working Inspector panel, with the
     24 *   background page as default target;
     25 */
     26 add_task(async function testWebExtensionsToolboxWebConsole() {
     27  await enableExtensionDebugging();
     28  const { document, tab, window } = await openAboutDebugging();
     29  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     30 
     31  await installTemporaryExtensionFromXPI(
     32    {
     33      background() {
     34        document.body.innerText = "Background Page Body Test Content";
     35      },
     36      id: ADDON_ID,
     37      name: ADDON_NAME,
     38    },
     39    document
     40  );
     41 
     42  info("Open a toolbox to debug the addon");
     43  const { devtoolsWindow } = await openAboutDevtoolsToolbox(
     44    document,
     45    tab,
     46    window,
     47    ADDON_NAME
     48  );
     49  const toolbox = getToolbox(devtoolsWindow);
     50 
     51  const inspector = await toolbox.selectTool("inspector");
     52  const nodeActor = await inspector.walker.querySelector(
     53    inspector.walker.rootNode,
     54    "body"
     55  );
     56  ok(nodeActor, "Got a nodeActor");
     57  ok(nodeActor.inlineTextChild, "Got a nodeActor with an inline text child");
     58 
     59  const actualValue = nodeActor.inlineTextChild._form.nodeValue;
     60 
     61  is(
     62    String(actualValue).trim(),
     63    "Background Page Body Test Content",
     64    "nodeActor has the expected inlineTextChild value"
     65  );
     66 
     67  info("Check that the color scheme simulation buttons are hidden");
     68  const lightButtonIsHidden = inspector.panelDoc
     69    .querySelector("#color-scheme-simulation-light-toggle")
     70    ?.hasAttribute("hidden");
     71  const darkButtonIsHidded = inspector.panelDoc
     72    .querySelector("#color-scheme-simulation-dark-toggle")
     73    ?.hasAttribute("hidden");
     74  ok(
     75    lightButtonIsHidden,
     76    "The light color scheme simulation button exists and is hidden"
     77  );
     78  ok(
     79    darkButtonIsHidded,
     80    "The dark color scheme simulation button exists and is hidden"
     81  );
     82 
     83  await closeWebExtAboutDevtoolsToolbox(devtoolsWindow, window);
     84  await removeTemporaryExtension(ADDON_NAME, document);
     85  await removeTab(tab);
     86 });