tor-browser

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

browser_dbg-breakpoints.js (5333B)


      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 "use strict";
      6 // Test enabling and disabling a breakpoint using the check boxes
      7 add_task(async function testEnableDisableBreakpoints() {
      8  const dbg = await initDebugger("doc-scripts.html", "simple2.js");
      9 
     10  // Create two breakpoints
     11  await selectSource(dbg, "simple2.js");
     12  await addBreakpoint(dbg, "simple2.js", 3);
     13  await addBreakpoint(dbg, "simple2.js", 5);
     14 
     15  // Disable the first one
     16  await disableBreakpoint(dbg, 0);
     17  let bp1 = findBreakpoint(dbg, "simple2.js", 3);
     18  let bp2 = findBreakpoint(dbg, "simple2.js", 5);
     19  is(bp1.disabled, true, "first breakpoint is disabled");
     20  is(bp2.disabled, false, "second breakpoint is enabled");
     21 
     22  // Disable and Re-Enable the second one
     23  await disableBreakpoint(dbg, 1);
     24  await enableBreakpoint(dbg, 1);
     25  bp2 = findBreakpoint(dbg, "simple2.js", 5);
     26  is(bp2.disabled, false, "second breakpoint is enabled");
     27 
     28  // Cleanup
     29  await cleanupBreakpoints(dbg);
     30 
     31  // Test enabling and disabling a breakpoint using the context menu
     32  await selectSource(dbg, "simple2.js");
     33  await addBreakpoint(dbg, "simple2.js", 3);
     34  await addBreakpoint(dbg, "simple2.js", 5);
     35 
     36  assertBreakpointSnippet(dbg, 3, "return x + y;");
     37 
     38  rightClickElement(dbg, "breakpointItem", 2);
     39  await waitForContextMenu(dbg);
     40  const disableBreakpointDispatch = waitForDispatch(
     41    dbg.store,
     42    "SET_BREAKPOINT"
     43  );
     44  selectContextMenuItem(dbg, selectors.breakpointContextMenu.disableSelf);
     45  await disableBreakpointDispatch;
     46 
     47  bp1 = findBreakpoint(dbg, "simple2.js", 3);
     48  bp2 = findBreakpoint(dbg, "simple2.js", 5);
     49  is(bp1.disabled, true, "first breakpoint is disabled");
     50  is(bp2.disabled, false, "second breakpoint is enabled");
     51 
     52  rightClickElement(dbg, "breakpointItem", 2);
     53  await waitForContextMenu(dbg);
     54  const enableBreakpointDispatch = waitForDispatch(dbg.store, "SET_BREAKPOINT");
     55  selectContextMenuItem(dbg, selectors.breakpointContextMenu.enableSelf);
     56  await enableBreakpointDispatch;
     57 
     58  bp1 = findBreakpoint(dbg, "simple2.js", 3);
     59  bp2 = findBreakpoint(dbg, "simple2.js", 5);
     60  is(bp1.disabled, false, "first breakpoint is enabled");
     61  is(bp2.disabled, false, "second breakpoint is enabled");
     62 
     63  // Cleanup
     64  await cleanupBreakpoints(dbg);
     65 
     66  // Test creation of disabled breakpoint with shift-click
     67  await shiftClickElement(dbg, "gutterElement", 3);
     68  await waitForBreakpoint(dbg, "simple2.js", 3);
     69 
     70  const bp = findBreakpoint(dbg, "simple2.js", 3);
     71  is(bp.disabled, true, "breakpoint is disabled");
     72 
     73  // Cleanup
     74  await cleanupBreakpoints(dbg);
     75 });
     76 
     77 // Test the keyboard events on the breakpoint list
     78 add_task(async function testBreakpointsKeyboardEvents() {
     79  const dbg = await initDebugger("doc-scripts.html", "simple2.js");
     80 
     81  // Create two breakpoints
     82  await selectSource(dbg, "simple2.js");
     83 
     84  info("Add two breakpoints");
     85  await addBreakpoint(dbg, "simple2.js", 3);
     86  await addBreakpoint(dbg, "simple2.js", 4);
     87 
     88  info("Add conditional breakpoint to line 5");
     89  await setEditorCursorAt(dbg, 5, 2);
     90  await setConditionalBreakpointWithKeyboardShortcut(dbg, "3");
     91  pressKey(dbg, "Enter");
     92  await waitForCondition(dbg, "3");
     93 
     94  info("Focus and select first breakpoint with the keyboard shortcut");
     95  let bp = findAllElements(dbg, "breakpointItems")[0];
     96  bp.focus();
     97  pressKey(dbg, "Enter");
     98 
     99  info("Wait for line with the first breakpoint to be selected");
    100  await waitFor(() => dbg.selectors.getSelectedLocation().line == 3);
    101 
    102  info("Focus and select second breakpoint with the keyboard shortcut");
    103  bp = findAllElements(dbg, "breakpointItems")[1];
    104  bp.focus();
    105  pressKey(dbg, "Space");
    106 
    107  info("Wait for line with the second breakpoint to be selected");
    108  await waitFor(() => dbg.selectors.getSelectedLocation().line == 4);
    109 
    110  info(
    111    "Focus and select and update conditional breakpoint with the keyboard shortcut"
    112  );
    113  bp = findAllElements(dbg, "breakpointItems")[2];
    114  bp.focus();
    115  pressKey(dbg, "ShiftEnter");
    116  typeInPanel(dbg, "5");
    117  await waitForCondition(dbg, "35");
    118 
    119  // Cleanup
    120  await cleanupBreakpoints(dbg);
    121 });
    122 
    123 function toggleBreakpoint(dbg, index) {
    124  const bp = findAllElements(dbg, "breakpointItems")[index];
    125  const input = bp.querySelector("input");
    126  input.click();
    127 }
    128 
    129 async function disableBreakpoint(dbg, index) {
    130  const disabled = waitForDispatch(dbg.store, "SET_BREAKPOINT");
    131  toggleBreakpoint(dbg, index);
    132  await disabled;
    133 }
    134 
    135 async function enableBreakpoint(dbg, index) {
    136  const enabled = waitForDispatch(dbg.store, "SET_BREAKPOINT");
    137  toggleBreakpoint(dbg, index);
    138  await enabled;
    139 }
    140 
    141 async function cleanupBreakpoints(dbg) {
    142  ok(
    143    findBreakpoint(dbg, "simple2.js", 3),
    144    "Breakpoint on line 3 exists before trying to remove it"
    145  );
    146  let dispatched = waitForDispatch(dbg.store, "REMOVE_BREAKPOINT");
    147  clickElement(dbg, "gutterElement", 3);
    148  await dispatched;
    149  await waitForBreakpointRemoved(dbg, "simple2.js", 3);
    150 
    151  // Breakpoint on line 5 doesn't always exists
    152  if (!findBreakpoint(dbg, "simple2.js", 5)) {
    153    return;
    154  }
    155  dispatched = waitForDispatch(dbg.store, "REMOVE_BREAKPOINT");
    156  clickElement(dbg, "gutterElement", 5);
    157  await dispatched;
    158  await waitForBreakpointRemoved(dbg, "simple2.js", 5);
    159 }