tor-browser

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

browser_toolbox_swap_browsers.js (5431B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 // Verify that toolbox remains open when opening and closing RDM.
      7 
      8 const TEST_URL = "http://example.com/";
      9 
     10 function getServerConnections(browser) {
     11  ok(browser.isRemoteBrowser, "Content browser is remote");
     12  return SpecialPowers.spawn(browser, [], async function () {
     13    const { require } = ChromeUtils.importESModule(
     14      "resource://devtools/shared/loader/Loader.sys.mjs"
     15    );
     16    const {
     17      DevToolsServer,
     18    } = require("resource://devtools/server/devtools-server.js");
     19    if (!DevToolsServer._connections) {
     20      return 0;
     21    }
     22    return Object.getOwnPropertyNames(DevToolsServer._connections);
     23  });
     24 }
     25 
     26 const checkServerConnectionCount = async function (browser, expected, msg) {
     27  const conns = await getServerConnections(browser);
     28  is(conns.length || 0, expected, "Server connection count: " + msg);
     29 };
     30 
     31 const checkToolbox = function (tab, location) {
     32  const toolbox = gDevTools.getToolboxForTab(tab);
     33  ok(!!toolbox, `Toolbox exists ${location}`);
     34 };
     35 
     36 addRDMTask(
     37  "",
     38  async function () {
     39    const tab = await addTab(TEST_URL);
     40 
     41    const tabsInDifferentProcesses =
     42      E10S_MULTI_ENABLED &&
     43      gBrowser.tabs[0].linkedBrowser.frameLoader.childID !=
     44        gBrowser.tabs[1].linkedBrowser.frameLoader.childID;
     45 
     46    info("Open toolbox outside RDM");
     47    {
     48      // 0: No DevTools connections yet
     49      await checkServerConnectionCount(
     50        tab.linkedBrowser,
     51        0,
     52        "0: No DevTools connections yet"
     53      );
     54      const { toolbox } = await openInspector();
     55      if (tabsInDifferentProcesses) {
     56        // 1: Two tabs open, but only one per content process
     57        await checkServerConnectionCount(
     58          tab.linkedBrowser,
     59          1,
     60          "1: Two tabs open, but only one per content process"
     61        );
     62      } else {
     63        // 2: One for each tab (starting tab plus the one we opened)
     64        await checkServerConnectionCount(
     65          tab.linkedBrowser,
     66          2,
     67          "2: One for each tab (starting tab plus the one we opened)"
     68        );
     69      }
     70      checkToolbox(tab, "outside RDM");
     71      const { ui } = await openRDM(tab);
     72      if (tabsInDifferentProcesses) {
     73        // 2: RDM UI adds an extra connection, 1 + 1 = 2
     74        await checkServerConnectionCount(
     75          ui.getViewportBrowser(),
     76          2,
     77          "2: RDM UI uses an extra connection"
     78        );
     79      } else {
     80        // 3: RDM UI adds an extra connection, 2 + 1 = 3
     81        await checkServerConnectionCount(
     82          ui.getViewportBrowser(),
     83          3,
     84          "3: RDM UI uses an extra connection"
     85        );
     86      }
     87      checkToolbox(tab, "after opening RDM");
     88      await closeRDM(tab);
     89      if (tabsInDifferentProcesses) {
     90        // 1: RDM UI closed, return to previous connection count
     91        await checkServerConnectionCount(
     92          tab.linkedBrowser,
     93          1,
     94          "1: RDM UI closed, return to previous connection count"
     95        );
     96      } else {
     97        // 2: RDM UI closed, return to previous connection count
     98        await checkServerConnectionCount(
     99          tab.linkedBrowser,
    100          2,
    101          "2: RDM UI closed, return to previous connection count"
    102        );
    103      }
    104      checkToolbox(tab, tab.linkedBrowser, "after closing RDM");
    105      await toolbox.destroy();
    106      // 0: All DevTools usage closed
    107      await checkServerConnectionCount(
    108        tab.linkedBrowser,
    109        0,
    110        "0: All DevTools usage closed"
    111      );
    112    }
    113 
    114    info("Open toolbox inside RDM");
    115    {
    116      // 0: No DevTools connections yet
    117      await checkServerConnectionCount(
    118        tab.linkedBrowser,
    119        0,
    120        "0: No DevTools connections yet"
    121      );
    122      const { ui } = await openRDM(tab);
    123      // 1: RDM UI uses an extra connection
    124      await checkServerConnectionCount(
    125        ui.getViewportBrowser(),
    126        1,
    127        "1: RDM UI uses an extra connection"
    128      );
    129      const { toolbox } = await openInspector();
    130      if (tabsInDifferentProcesses) {
    131        // 2: Two tabs open, but only one per content process
    132        await checkServerConnectionCount(
    133          ui.getViewportBrowser(),
    134          2,
    135          "2: Two tabs open, but only one per content process"
    136        );
    137      } else {
    138        // 3: One for each tab (starting tab plus the one we opened)
    139        await checkServerConnectionCount(
    140          ui.getViewportBrowser(),
    141          3,
    142          "3: One for each tab (starting tab plus the one we opened)"
    143        );
    144      }
    145      checkToolbox(tab, ui.getViewportBrowser(), "inside RDM");
    146      await closeRDM(tab);
    147      if (tabsInDifferentProcesses) {
    148        // 1: RDM UI closed, one less connection
    149        await checkServerConnectionCount(
    150          tab.linkedBrowser,
    151          1,
    152          "1: RDM UI closed, one less connection"
    153        );
    154      } else {
    155        // 2: RDM UI closed, one less connection
    156        await checkServerConnectionCount(
    157          tab.linkedBrowser,
    158          2,
    159          "2: RDM UI closed, one less connection"
    160        );
    161      }
    162      checkToolbox(tab, tab.linkedBrowser, "after closing RDM");
    163      await toolbox.destroy();
    164      // 0: All DevTools usage closed
    165      await checkServerConnectionCount(
    166        tab.linkedBrowser,
    167        0,
    168        "0: All DevTools usage closed"
    169      );
    170    }
    171 
    172    await removeTab(tab);
    173  },
    174  { onlyPrefAndTask: true }
    175 );