tor-browser

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

browser_dbg-blackbox-all.js (7610B)


      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 // This contains tests for
      6 // 1) The context menu items that blackboxes multiple files in the Sources Panel.
      7 // Checks if submenu works correctly for options:
      8 // - 'Un/Blackbox files in this group'
      9 // - 'Un/Blackbox files outside this group'
     10 // - 'Un/Blackbox files in this directory'
     11 // - 'Un/Blackbox files outside this directory'
     12 // 2) The context menu item to hide/show the blackboxed files.
     13 
     14 "use strict";
     15 
     16 const SOURCE_FILES = {
     17  nestedSource: "nested-source.js",
     18  codeReload1: "code_reload_1.js",
     19 };
     20 
     21 const NODE_SELECTORS = {
     22  nodeBlackBoxAll: "#node-blackbox-all",
     23  nodeBlackBoxAllInside: "#node-blackbox-all-inside",
     24  nodeUnBlackBoxAllInside: "#node-unblackbox-all-inside",
     25  nodeBlackBoxAllOutside: "#node-blackbox-all-outside",
     26  nodeUnBlackBoxAllOutside: "#node-unblackbox-all-outside",
     27 };
     28 
     29 add_task(async function testBlackBoxOnMultipleFiles() {
     30  const dbg = await initDebugger(
     31    "doc-blackbox-all.html",
     32    SOURCE_FILES.nestedSource,
     33    SOURCE_FILES.codeReload1
     34  );
     35 
     36  // Expand the SourceTree and wait for all sources to be visible,
     37  // so that we can assert the visible state of blackboxing in the source tree.
     38  await waitForSourcesInSourceTree(dbg, Object.values(SOURCE_FILES));
     39 
     40  info("Loads the source file and sets a breakpoint at line 2.");
     41  await selectSource(dbg, SOURCE_FILES.nestedSource);
     42  await addBreakpoint(dbg, SOURCE_FILES.nestedSource, 2);
     43 
     44  info("Selecting the source will highlight it and expand the tree down to it");
     45  await waitForAllElements(dbg, "sourceTreeFolderNode", 3);
     46  const sourceTreeFolderNodeEls = findAllElements(dbg, "sourceTreeFolderNode");
     47  const sourceTreeRootNodeEl = findElement(dbg, "sourceTreeRootNode");
     48 
     49  info("Blackbox files in this directory.");
     50  rightClickEl(dbg, sourceTreeFolderNodeEls[1]);
     51  await waitForContextMenu(dbg);
     52  await openContextMenuSubmenu(dbg, NODE_SELECTORS.nodeBlackBoxAll);
     53  await assertContextMenuLabel(
     54    dbg,
     55    NODE_SELECTORS.nodeBlackBoxAllInside,
     56    "Ignore files in this directory"
     57  );
     58  await assertContextMenuLabel(
     59    dbg,
     60    NODE_SELECTORS.nodeBlackBoxAllOutside,
     61    "Ignore files outside this directory"
     62  );
     63  selectContextMenuItem(dbg, NODE_SELECTORS.nodeBlackBoxAllInside);
     64  await waitForDispatch(dbg.store, "BLACKBOX_WHOLE_SOURCES");
     65  await waitForBlackboxCount(dbg, 1);
     66  await waitForRequestsToSettle(dbg);
     67 
     68  assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.nestedSource, true);
     69  assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.codeReload1, false);
     70 
     71  info("The invoked function is blackboxed and the debugger does not pause.");
     72  invokeInTab("computeSomething");
     73  assertNotPaused(dbg);
     74 
     75  info("Unblackbox files outside this directory.");
     76  rightClickEl(dbg, sourceTreeFolderNodeEls[2]);
     77  await waitForContextMenu(dbg);
     78  await openContextMenuSubmenu(dbg, NODE_SELECTORS.nodeBlackBoxAll);
     79  await assertContextMenuLabel(
     80    dbg,
     81    NODE_SELECTORS.nodeBlackBoxAllInside,
     82    "Ignore files in this directory"
     83  );
     84  await assertContextMenuLabel(
     85    dbg,
     86    NODE_SELECTORS.nodeUnBlackBoxAllOutside,
     87    "Unignore files outside this directory"
     88  );
     89  selectContextMenuItem(dbg, NODE_SELECTORS.nodeUnBlackBoxAllOutside);
     90  await waitForDispatch(dbg.store, "UNBLACKBOX_WHOLE_SOURCES");
     91  await waitForBlackboxCount(dbg, 0);
     92  await waitForRequestsToSettle(dbg);
     93  info("Wait for any breakpoints in the source to get enabled");
     94  await waitForDispatch(dbg.store, "SET_BREAKPOINT");
     95 
     96  assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.nestedSource, false);
     97  assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.codeReload1, false);
     98 
     99  info("All sources are unblackboxed and the debugger pauses on line 2.");
    100  invokeInTab("computeSomething");
    101  await waitForPaused(dbg);
    102  await resume(dbg);
    103 
    104  info("Blackbox files in this group.");
    105  rightClickEl(dbg, sourceTreeRootNodeEl);
    106  await waitForContextMenu(dbg);
    107  await assertContextMenuLabel(
    108    dbg,
    109    NODE_SELECTORS.nodeBlackBoxAllInside,
    110    "Ignore files in this group"
    111  );
    112  selectContextMenuItem(dbg, NODE_SELECTORS.nodeBlackBoxAllInside);
    113  await waitForBlackboxCount(dbg, 2);
    114  await waitForRequestsToSettle(dbg);
    115 
    116  assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.nestedSource, true);
    117  assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.codeReload1, true);
    118 
    119  info("Unblackbox files in this group.");
    120  rightClickEl(dbg, sourceTreeRootNodeEl);
    121  await waitForContextMenu(dbg);
    122  await assertContextMenuLabel(
    123    dbg,
    124    NODE_SELECTORS.nodeUnBlackBoxAllInside,
    125    "Unignore files in this group"
    126  );
    127  selectContextMenuItem(dbg, NODE_SELECTORS.nodeUnBlackBoxAllInside);
    128  await waitForBlackboxCount(dbg, 0);
    129  await waitForRequestsToSettle(dbg);
    130 
    131  assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.nestedSource, false);
    132  assertSourceNodeIsBlackBoxed(dbg, SOURCE_FILES.codeReload1, false);
    133 });
    134 
    135 add_task(async function testHideAndShowBlackBoxedFiles() {
    136  Services.prefs.setBoolPref("devtools.debugger.hide-ignored-sources", false);
    137 
    138  const dbg = await initDebugger(
    139    "doc-blackbox-all.html",
    140    SOURCE_FILES.nestedSource,
    141    SOURCE_FILES.codeReload1
    142  );
    143 
    144  await waitForSourcesInSourceTree(dbg, Object.values(SOURCE_FILES));
    145  await selectSource(dbg, SOURCE_FILES.nestedSource);
    146  clickElement(dbg, "blackbox");
    147  await waitForDispatch(dbg.store, "BLACKBOX_WHOLE_SOURCES");
    148 
    149  info("Assert and click the hide ignored files button in the settings menu");
    150  await toggleSourcesTreeSettingsMenuItem(dbg, {
    151    className: ".debugger-settings-menu-item-hide-ignored-sources",
    152    isChecked: false,
    153  });
    154 
    155  info("Wait until ignored sources are no longer visible");
    156  await waitUntil(
    157    () => !findSourceNodeWithText(dbg, SOURCE_FILES.nestedSource)
    158  );
    159 
    160  is(
    161    Services.prefs.getBoolPref("devtools.debugger.hide-ignored-sources"),
    162    true,
    163    "Hide ignored files is enabled"
    164  );
    165 
    166  is(
    167    dbg.win.document.querySelector(".source-list-footer").innerText,
    168    "Ignored sources are hidden.\nShow all sources",
    169    "Notification is visible with the correct message"
    170  );
    171 
    172  info("Assert that newly ignored files are automatically hidden");
    173  await selectSource(dbg, SOURCE_FILES.codeReload1);
    174  await triggerSourceTreeContextMenu(
    175    dbg,
    176    findSourceNodeWithText(dbg, SOURCE_FILES.codeReload1),
    177    "#node-menu-blackbox"
    178  );
    179  await waitForDispatch(dbg.store, "BLACKBOX_WHOLE_SOURCES");
    180  await waitUntil(() => !findSourceNodeWithText(dbg, SOURCE_FILES.codeReload1));
    181 
    182  info("Show the hidden ignored files using the button in the notification");
    183  clickElementWithSelector(dbg, ".source-list-footer button");
    184 
    185  info("Wait until ignored sources are visible");
    186  await waitUntil(() => findSourceNodeWithText(dbg, SOURCE_FILES.nestedSource));
    187 
    188  is(
    189    Services.prefs.getBoolPref("devtools.debugger.hide-ignored-sources"),
    190    false,
    191    "Hide ignored files is disabled"
    192  );
    193 
    194  ok(
    195    !document.querySelector(".source-list-footer"),
    196    "Notification is no longer visible"
    197  );
    198 });
    199 
    200 function waitForBlackboxCount(dbg, count) {
    201  return waitForState(
    202    dbg,
    203    () => Object.keys(dbg.selectors.getBlackBoxRanges()).length === count
    204  );
    205 }
    206 
    207 function assertSourceNodeIsBlackBoxed(dbg, sourceFilename, shouldBeBlackBoxed) {
    208  const treeItem = findSourceNodeWithText(dbg, sourceFilename);
    209  ok(treeItem, `Found tree item for ${sourceFilename}`);
    210  is(
    211    !!treeItem.querySelector(".dbg-img-blackBox"),
    212    shouldBeBlackBoxed,
    213    `${sourceFilename} is ${shouldBeBlackBoxed ? "" : "not"} blackboxed`
    214  );
    215 }