tor-browser

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

browser_dbg-tabs.js (5500B)


      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 // Tests adding and removing tabs
      6 
      7 "use strict";
      8 
      9 add_task(async function testTabsOnReload() {
     10  const dbg = await initDebugger(
     11    "doc-scripts.html",
     12    "simple1.js",
     13    "simple2.js"
     14  );
     15 
     16  await selectSource(dbg, "simple1.js");
     17  await selectSource(dbg, "simple2.js");
     18  is(countTabs(dbg), 2);
     19 
     20  info("Test reloading the debugger");
     21  await reload(dbg, "simple1.js", "simple2.js");
     22  await waitForSelectedSource(dbg, "simple2.js");
     23  is(countTabs(dbg), 2);
     24 
     25  info("Test reloading the debuggee a second time");
     26  await reload(dbg, "simple1.js", "simple2.js");
     27  await waitForSelectedSource(dbg, "simple2.js");
     28  is(countTabs(dbg), 2);
     29 });
     30 
     31 function assertTabs(dbg, tabs) {
     32  const { children } = findElement(dbg, "sourceTabs");
     33  is(children.length, tabs.length);
     34  for (let i = 0; i < tabs.length; i++) {
     35    is(tabs[i], children[i].textContent);
     36  }
     37 }
     38 
     39 add_task(async function testOpeningAndClosingTabs() {
     40  const dbg = await initDebugger(
     41    "doc-scripts.html",
     42    "simple1.js",
     43    "simple2.js",
     44    "simple3.js"
     45  );
     46 
     47  // /!\ Tabs are opened by default on the left/beginning
     48  // so that they are displayed in the other way around.
     49  // To make the test clearer insert them in a way so that
     50  // they are in the expected order: simple1 then simple2,...
     51  await selectSource(dbg, "simple3.js");
     52  await selectSource(dbg, "simple2.js");
     53  await selectSource(dbg, "simple1.js");
     54 
     55  assertTabs(dbg, ["simple1.js", "simple2.js", "simple3.js"]);
     56 
     57  info("Reselect simple2 so that we then close the selected tab");
     58  await selectSource(dbg, "simple2.js");
     59  await closeTab(dbg, "simple2.js");
     60  is(countTabs(dbg), 2);
     61  info("Removing the tab in the middle should select the following one");
     62  await waitForSelectedSource(dbg, "simple3.js");
     63 
     64  await closeTab(dbg, "simple3.js");
     65  is(countTabs(dbg), 1);
     66  info("Removing the last tab should select the first tab before");
     67  await waitForSelectedSource(dbg, "simple1.js");
     68 
     69  info("Re-open a second tab so that we can cover closing the first tab");
     70  await selectSource(dbg, "simple2.js");
     71  is(countTabs(dbg), 2);
     72  await closeTab(dbg, "simple1.js");
     73  info("Removing the first tab should select the first tab after");
     74  is(countTabs(dbg), 1);
     75  await waitForSelectedSource(dbg, "simple2.js");
     76 
     77  info("Close the last tab");
     78  await closeTab(dbg, "simple2.js");
     79  is(countTabs(dbg), 0);
     80  is(
     81    dbg.selectors.getSelectedLocation(),
     82    null,
     83    "Selected location is cleared when closing the last tab"
     84  );
     85 
     86  info("Test reloading the debugger with all tabs closed");
     87  await reload(dbg, "simple1.js", "simple2.js", "simple3.js");
     88  is(countTabs(dbg), 0, "No tab is reopened after reload");
     89 
     90  // /!\ Tabs are opened by default on the left/beginning
     91  // so that they are displayed in the other way around.
     92  // To make the test clearer insert them in a way so that
     93  // they are in the expected order: simple1 then simple2,...
     94  await selectSource(dbg, "simple3.js");
     95  await selectSource(dbg, "simple2.js");
     96  await selectSource(dbg, "simple1.js");
     97  is(countTabs(dbg), 3);
     98  assertTabs(dbg, ["simple1.js", "simple2.js", "simple3.js"]);
     99 
    100  info("Test reloading the debugger with tabs left opened");
    101  await reload(dbg, "simple1.js", "simple2.js", "simple3.js");
    102  is(countTabs(dbg), 3);
    103  assertTabs(dbg, ["simple1.js", "simple2.js", "simple3.js"]);
    104 
    105  info("Reselect simple3 so that we then close the selected tab");
    106  await selectSource(dbg, "simple3.js");
    107 
    108  info("Removing the last tab, should select the one before");
    109  await closeTab(dbg, "simple3.js");
    110  is(countTabs(dbg), 2);
    111  await waitForSelectedSource(dbg, "simple2.js");
    112 
    113  info(
    114    "Open tab for the HTML page, which has many source actors and may trigger more than one tab to be opened on reload"
    115  );
    116  await selectSource(dbg, "doc-scripts.html");
    117  is(countTabs(dbg), 3);
    118  await reload(
    119    dbg,
    120    "doc-scripts.html",
    121    "simple1.js",
    122    "simple2.js",
    123    "simple3.js"
    124  );
    125  is(countTabs(dbg), 3);
    126 
    127  // Inject lots of sources to have some tabs displayed in the dropdown
    128  const injectedSources = await SpecialPowers.spawn(
    129    gBrowser.selectedBrowser,
    130    [],
    131    function () {
    132      const sources = [];
    133      for (let i = 1; i <= 10; i++) {
    134        const value = String(i).padStart(3, "0");
    135        content.eval(
    136          `function evalSource() {}; //# sourceURL=eval-source-${value}.js`
    137        );
    138        sources.push(`eval-source-${value}.js`);
    139      }
    140      return sources;
    141    }
    142  );
    143  await waitForSources(dbg, ...injectedSources);
    144  for (const source of injectedSources) {
    145    await selectSource(dbg, source);
    146  }
    147  ok(
    148    findElementWithSelector(dbg, ".dbg-img-more-tabs"),
    149    "There is some hidden tabs displayed via a dropdown"
    150  );
    151 
    152  info("Test the close all tabs context menu");
    153  const waitForOpen = waitForContextMenu(dbg);
    154  info(`Open the current active tab context menu`);
    155  rightClickElement(dbg, "activeTab");
    156  await waitForOpen;
    157 
    158  info(`Select the close all tabs context menu item`);
    159  const onCloseTabsAction = waitForDispatch(
    160    dbg.store,
    161    "CLOSE_TABS_FOR_SOURCES"
    162  );
    163  selectContextMenuItem(dbg, `#node-menu-close-all-tabs`);
    164  await onCloseTabsAction;
    165  is(countTabs(dbg), 0);
    166  ok(
    167    !findElementWithSelector(dbg, ".dbg-img-more-tabs"),
    168    "After closing all tabs, hidden tabs dropdown is hidden"
    169  );
    170 });