tor-browser

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

browser_aboutdebugging_addons_debug_toolbox.js (4042B)


      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 const ADDON_ID = "test-devtools-webextension@mozilla.org";
     16 const ADDON_NAME = "test-devtools-webextension";
     17 
     18 /**
     19 * This test file ensures that the webextension addon developer toolbox:
     20 * - always on top is enabled by default and can be toggled off
     21 */
     22 add_task(async function testWebExtensionsToolbox() {
     23  await enableExtensionDebugging();
     24  const { document, tab, window } = await openAboutDebugging();
     25  await selectThisFirefoxPage(document, window.AboutDebugging.store);
     26 
     27  await installTemporaryExtensionFromXPI(
     28    {
     29      background() {
     30        document.body.innerText = "Background Page Body Test Content";
     31      },
     32      id: ADDON_ID,
     33      name: ADDON_NAME,
     34    },
     35    document
     36  );
     37 
     38  info("Open a toolbox to debug the addon");
     39  const { devtoolsWindow } = await openAboutDevtoolsToolbox(
     40    document,
     41    tab,
     42    window,
     43    ADDON_NAME
     44  );
     45 
     46  const toolbox = getToolbox(devtoolsWindow);
     47 
     48  ok(
     49    isWindowAlwaysOnTop(devtoolsWindow),
     50    "The toolbox window is always on top"
     51  );
     52  const toggleButton = toolbox.doc.querySelector(".toolbox-always-on-top");
     53  ok(!!toggleButton, "The always on top toggle button is visible");
     54  ok(
     55    toggleButton.classList.contains("checked"),
     56    "The button is highlighted to report that always on top is enabled"
     57  );
     58 
     59  // When running the test, the devtools window might not be focused, while it does IRL.
     60  // Force it to be focused to better reflect the default behavior.
     61  info("Force focusing the devtools window");
     62  devtoolsWindow.focus();
     63 
     64  // As we update the button with a debounce, we have to wait for it to updates
     65  await waitFor(
     66    () => toggleButton.classList.contains("toolbox-is-focused"),
     67    "Wait for the button to be highlighting that the toolbox is focused (the button isn't highlighted)"
     68  );
     69  ok(true, "Expected class is added when toolbox is focused");
     70 
     71  info("Focus the browser window");
     72  window.focus();
     73 
     74  await waitFor(
     75    () => !toggleButton.classList.contains("toolbox-is-focused"),
     76    "Wait for the button to be highlighting that the toolbox is no longer focused (the button is highlighted)"
     77  );
     78  ok(true, "Focused class is removed when browser window gets focused");
     79 
     80  info("Re-focus the DevTools window");
     81  devtoolsWindow.focus();
     82 
     83  await waitFor(
     84    () => toggleButton.classList.contains("toolbox-is-focused"),
     85    "Wait for the button to be re-highlighting that the toolbox is focused"
     86  );
     87 
     88  const onToolboxReady = gDevTools.once("toolbox-ready");
     89  info("Click on the button");
     90  toggleButton.click();
     91 
     92  info("Wait for a new toolbox to be created");
     93  const secondToolbox = await onToolboxReady;
     94 
     95  ok(
     96    !isWindowAlwaysOnTop(secondToolbox.win),
     97    "The toolbox window is no longer always on top"
     98  );
     99  const secondToggleButton = secondToolbox.doc.querySelector(
    100    ".toolbox-always-on-top"
    101  );
    102  ok(!!secondToggleButton, "The always on top toggle button is still visible");
    103 
    104  ok(
    105    !secondToggleButton.classList.contains("checked"),
    106    "The button is no longer highlighted to report that always on top is disabled"
    107  );
    108 
    109  await closeWebExtAboutDevtoolsToolbox(secondToolbox.win, window);
    110  await removeTemporaryExtension(ADDON_NAME, document);
    111  await removeTab(tab);
    112 });
    113 
    114 // Check if the window has the "alwaysontop" chrome flag
    115 function isWindowAlwaysOnTop(window) {
    116  return (
    117    window.docShell.treeOwner
    118      .QueryInterface(Ci.nsIInterfaceRequestor)
    119      .getInterface(Ci.nsIAppWindow).chromeFlags &
    120    Ci.nsIWebBrowserChrome.CHROME_ALWAYS_ON_TOP
    121  );
    122 }