tor-browser

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

browser_dbg-breakpoints-list.js (5713B)


      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 // Testing displaying breakpoints in the breakpoints list and the tooltip
      6 // shows the source url.
      7 
      8 "use strict";
      9 
     10 add_task(async function testBreakpointsListForMultipleTargets() {
     11  const dbg = await initDebugger(
     12    "doc_dbg-fission-frame-sources.html",
     13    "simple1.js",
     14    "simple2.js"
     15  );
     16 
     17  info("Add breakpoint to the source (simple1.js) in the main thread");
     18  await selectSource(dbg, "simple1.js");
     19  const source1 = findSource(dbg, "simple1.js");
     20  await addBreakpoint(dbg, "simple1.js", 5);
     21 
     22  info("Add breakpoint to the source (simple2.js) in the frame");
     23  await selectSource(dbg, "simple2.js");
     24  const source2 = findSource(dbg, "simple2.js");
     25  await addBreakpoint(dbg, "simple2.js", 3);
     26 
     27  const breakpointHeadings = findAllElements(dbg, "breakpointHeadings");
     28  const breakpointItems = findAllElements(dbg, "breakpointItems");
     29 
     30  is(
     31    breakpointHeadings.length,
     32    2,
     33    "The breakpoint list shows two breakpoints sources"
     34  );
     35  is(
     36    breakpointItems.length,
     37    2,
     38    "The breakpoint list shows only two breakpoints"
     39  );
     40 
     41  is(
     42    breakpointHeadings[0].title,
     43    source1.url,
     44    "The breakpoint heading tooltip shows the source info for the first breakpoint"
     45  );
     46  is(
     47    breakpointHeadings[0].textContent,
     48    "simple1.js",
     49    "The info displayed for the breakpoint heading of the 1st breakpoint is correct"
     50  );
     51  is(
     52    breakpointItems[0].textContent,
     53    "func();5:18",
     54    "The info displayed for the 1st breakpoint is correct"
     55  );
     56 
     57  is(
     58    breakpointHeadings[1].title,
     59    source2.url,
     60    "The breakpoint heading tooltip shows the source info for the second breakpoint"
     61  );
     62  is(
     63    breakpointHeadings[1].textContent,
     64    "simple2.js",
     65    "The info displayed for the breakpoint heading of the 2nd breakpoint is correct"
     66  );
     67  is(
     68    breakpointItems[1].textContent,
     69    "return x + y;3:5",
     70    "The info displayed for the 2nd breakpoint is correct"
     71  );
     72 
     73  await removeBreakpoint(dbg, source1.id, 5);
     74  await removeBreakpoint(dbg, source2.id, 3);
     75 });
     76 
     77 add_task(async function testBreakpointsListForOriginalFiles() {
     78  const dbg = await initDebugger("doc-sourcemaps.html", "entry.js");
     79 
     80  info("Add breakpoint to the entry.js (original source)");
     81  await selectSource(dbg, "entry.js");
     82  const source = findSource(dbg, "entry.js");
     83  await addBreakpoint(dbg, "entry.js", 5);
     84 
     85  const breakpointHeadings = findAllElements(dbg, "breakpointHeadings");
     86  const breakpointItems = findAllElements(dbg, "breakpointItems");
     87 
     88  is(
     89    breakpointHeadings.length,
     90    1,
     91    "The breakpoint list shows one breakpoints sources"
     92  );
     93  is(
     94    breakpointItems.length,
     95    1,
     96    "The breakpoint list shows only one breakpoints"
     97  );
     98 
     99  is(
    100    breakpointHeadings[0].title,
    101    source.url,
    102    "The breakpoint heading tooltip shows the source info for the first breakpoint"
    103  );
    104  is(
    105    breakpointHeadings[0].textContent,
    106    "entry.js",
    107    "The info displayed for the breakpoint heading of the 1st breakpoint is correct"
    108  );
    109  is(
    110    breakpointItems[0].textContent,
    111    "output(times2(1));5",
    112    "The info displayed for the 1st breakpoint is correct"
    113  );
    114 
    115  await removeBreakpoint(dbg, source.id, 5);
    116 });
    117 
    118 add_task(async function testBreakpointsListForIgnoredLines() {
    119  const dbg = await initDebugger("doc-sourcemaps.html", "entry.js");
    120 
    121  info("Add breakpoint to the entry.js (original source)");
    122  await selectSource(dbg, "entry.js");
    123  await addBreakpoint(dbg, "entry.js", 5);
    124 
    125  info("Ignoring line 5 to 6 which has a breakpoint already set");
    126  await selectEditorLinesAndOpenContextMenu(dbg, {
    127    startLine: 5,
    128    endLine: 6,
    129  });
    130  await selectBlackBoxContextMenuItem(dbg, "blackbox-lines");
    131 
    132  info("Assert the breakpoint on the ignored line");
    133  let breakpointItems = findAllElements(dbg, "breakpointItems");
    134  is(
    135    breakpointItems[0].textContent,
    136    "output(times2(1));5",
    137    "The info displayed for the 1st breakpoint is correct"
    138  );
    139  const firstBreakpointCheck = breakpointItems[0].querySelector("input");
    140  ok(
    141    firstBreakpointCheck.disabled,
    142    "The first breakpoint checkbox on an ignored line is disabled"
    143  );
    144  ok(
    145    !firstBreakpointCheck.checked,
    146    "The first breakpoint on an ignored line is not checked"
    147  );
    148 
    149  info("Ignoring line 8 to 9 which currently has not breakpoint");
    150  await selectEditorLinesAndOpenContextMenu(dbg, {
    151    startLine: 8,
    152    endLine: 9,
    153  });
    154  await selectBlackBoxContextMenuItem(dbg, "blackbox-lines");
    155 
    156  await addBreakpointViaGutter(dbg, 9);
    157 
    158  breakpointItems = findAllElements(dbg, "breakpointItems");
    159  is(
    160    breakpointItems[1].textContent,
    161    "output(times2(3));9",
    162    "The info displayed for the 2nd breakpoint is correct"
    163  );
    164  const secondBreakpointCheck = breakpointItems[1].querySelector("input");
    165  ok(
    166    secondBreakpointCheck.disabled,
    167    "The second breakpoint checkbox on an ignored line is disabled"
    168  );
    169  ok(
    170    !secondBreakpointCheck.checked,
    171    "The second breakpoint on an ignored line is not checked"
    172  );
    173 
    174  await clickElement(dbg, "blackbox");
    175  await waitForDispatch(dbg.store, "UNBLACKBOX_WHOLE_SOURCES");
    176 
    177  info("Assert that both breakpoints are now enabled");
    178  breakpointItems = findAllElements(dbg, "breakpointItems");
    179  [...breakpointItems].forEach(breakpointItem => {
    180    const check = breakpointItem.querySelector("input");
    181    ok(
    182      !check.disabled,
    183      "The breakpoint checkbox on the unignored line is enabled"
    184    );
    185    ok(check.checked, "The breakpoint on the unignored line is checked");
    186  });
    187 
    188  await dbg.toolbox.closeToolbox();
    189 });