tor-browser

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

browser_toolbox_popups_debugging.js (1901B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Test opening toolboxes against a tab and its popup
      5 
      6 const TEST_URL = "data:text/html,test for debugging popups";
      7 const POPUP_URL = "data:text/html,popup";
      8 
      9 const POPUP_DEBUG_PREF = "devtools.popups.debug";
     10 
     11 add_task(async function () {
     12  const isPopupDebuggingEnabled = Services.prefs.getBoolPref(POPUP_DEBUG_PREF);
     13 
     14  info("Open a tab and debug it");
     15  const tab = await addTab(TEST_URL);
     16  const toolbox = await gDevTools.showToolboxForTab(tab, {
     17    toolId: "webconsole",
     18  });
     19 
     20  info("Open a popup");
     21  const onTabOpened = once(gBrowser.tabContainer, "TabOpen");
     22  const onToolboxSwitchedToTab = toolbox.once("switched-host-to-tab");
     23  await SpecialPowers.spawn(tab.linkedBrowser, [POPUP_URL], url => {
     24    content.open(url);
     25  });
     26  const tabOpenEvent = await onTabOpened;
     27  const popupTab = tabOpenEvent.target;
     28 
     29  const popupToolbox = await gDevTools.showToolboxForTab(popupTab);
     30  if (isPopupDebuggingEnabled) {
     31    ok(
     32      !popupToolbox,
     33      "When popup debugging is enabled, the popup should be debugged via the same toolbox as the original tab"
     34    );
     35    info("Wait for internal event notifying about the toolbox being moved");
     36    await onToolboxSwitchedToTab;
     37    const browserContainer = gBrowser.getBrowserContainer(
     38      popupTab.linkedBrowser
     39    );
     40    const iframe = browserContainer.querySelector(
     41      ".devtools-toolbox-bottom-iframe"
     42    );
     43    ok(iframe, "The original tab's toolbox moved to the popup tab");
     44  } else {
     45    ok(popupToolbox, "We were able to spawn a toolbox for the popup");
     46    info("Close the popup toolbox and its tab");
     47    await popupToolbox.destroy();
     48  }
     49 
     50  info("Close the popup tab");
     51  gBrowser.removeCurrentTab();
     52 
     53  info("Close the original tab toolbox and itself");
     54  await toolbox.destroy();
     55  gBrowser.removeCurrentTab();
     56 });