tor-browser

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

browser_dbg-pretty-print-breakpoints.js (4318B)


      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 that breakpoints set in the pretty printed files display and paused
      6 // correctly.
      7 
      8 "use strict";
      9 
     10 add_task(async function () {
     11  const dbg = await initDebugger("doc-pretty.html", "pretty.js");
     12 
     13  await selectSource(dbg, "pretty.js");
     14  await togglePrettyPrint(dbg);
     15 
     16  await addBreakpoint(dbg, "pretty.js:formatted", 5);
     17 
     18  is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint is created");
     19 
     20  invokeInTab("stuff");
     21  await waitForPaused(dbg);
     22 
     23  await assertBreakpointsInNonPrettyAndPrettySources(dbg);
     24 
     25  is(
     26    dbg.selectors.getBreakpointCount(),
     27    1,
     28    "Only one breakpoint still exists after pause "
     29  );
     30 
     31  await resume(dbg);
     32 
     33  info("Wait for another pause because of a debugger statement on line 8");
     34  await waitForPaused(dbg);
     35 
     36  await resume(dbg);
     37  assertNotPaused(dbg);
     38 
     39  await closeTab(dbg, "pretty.js");
     40 });
     41 
     42 // Tests that breakpoints appear and work when you reload a page
     43 // with pretty-printed files.
     44 add_task(async function () {
     45  const dbg = await initDebugger("doc-pretty.html", "pretty.js");
     46 
     47  await selectSource(dbg, "pretty.js");
     48  await togglePrettyPrint(dbg);
     49 
     50  await addBreakpoint(dbg, "pretty.js:formatted", 5);
     51 
     52  info("Check that equivalent breakpoint to pretty.js (generated source)");
     53  await togglePrettyPrint(dbg);
     54  await assertBreakpoint(dbg, 4);
     55 
     56  await togglePrettyPrint(dbg);
     57 
     58  is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint exists");
     59 
     60  await reload(dbg, "pretty.js", "pretty.js:formatted");
     61 
     62  await waitForSelectedSource(dbg, "pretty.js:formatted");
     63 
     64  invokeInTab("stuff");
     65  await waitForPaused(dbg);
     66 
     67  await assertBreakpointsInNonPrettyAndPrettySources(dbg);
     68 
     69  is(
     70    dbg.selectors.getBreakpointCount(),
     71    1,
     72    "Only one breakpoint still exists after reload and pause "
     73  );
     74 });
     75 
     76 // Test that breakpoints appear and work when set in the minified source
     77 add_task(async function () {
     78  const dbg = await initDebugger("doc-pretty.html", "pretty.js");
     79 
     80  await selectSource(dbg, "pretty.js");
     81 
     82  info("Add breakpoint to pretty.js (generated source)");
     83  await addBreakpoint(dbg, "pretty.js", 4, 8);
     84 
     85  await togglePrettyPrint(dbg);
     86 
     87  info(
     88    "Check that equivalent breakpoint is added to pretty.js:formatted (original source)"
     89  );
     90  await assertBreakpoint(dbg, 5);
     91 
     92  is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint created");
     93 
     94  await reload(dbg, "pretty.js", "pretty.js:formatted");
     95 
     96  await waitForSelectedSource(dbg, "pretty.js:formatted");
     97 
     98  invokeInTab("stuff");
     99  await waitForPaused(dbg);
    100 
    101  await assertBreakpointsInNonPrettyAndPrettySources(dbg);
    102 
    103  is(
    104    dbg.selectors.getBreakpointCount(),
    105    1,
    106    "Only one breakpoint still exists after reload and pause "
    107  );
    108 });
    109 
    110 // Bug 1954109 - Breakpoint not shown in the gutter of a pretty-printed file
    111 add_task(async function () {
    112  const dbg = await initDebugger("doc-pretty.html", "pretty.js");
    113 
    114  await selectSource(dbg, "pretty.js");
    115  await addBreakpoint(dbg, "pretty.js", 9);
    116 
    117  await togglePrettyPrint(dbg);
    118  await assertBreakpoint(dbg, 11);
    119 
    120  await togglePrettyPrint(dbg);
    121 
    122  // Column breakpoints updates are awaited by togglePrettyPrint and are done asynchronously
    123  await waitFor(() => !!findAllElements(dbg, "columnBreakpoints").length);
    124  ok(
    125    findAllElements(dbg, "columnBreakpoints").length,
    126    "Column breakpoints are still shown in the minified file after pretty-printing"
    127  );
    128  await addBreakpoint(dbg, "pretty.js", 9, 55);
    129 
    130  await togglePrettyPrint(dbg);
    131  await assertBreakpoint(dbg, 16);
    132 });
    133 
    134 async function assertBreakpointsInNonPrettyAndPrettySources(dbg) {
    135  info(
    136    "Asserts breakpoint pause and display on the correct line in the pretty printed source"
    137  );
    138  const prettyPrintedSource = findSource(dbg, "pretty.js:formatted");
    139  await assertPausedAtSourceAndLine(dbg, prettyPrintedSource.id, 5);
    140  await assertBreakpoint(dbg, 5);
    141 
    142  await togglePrettyPrint(dbg);
    143 
    144  info("Assert pause and display on the correct line in the minified source");
    145  const minifiedSource = findSource(dbg, "pretty.js");
    146  await assertPausedAtSourceAndLine(dbg, minifiedSource.id, 4, 8);
    147  await assertBreakpoint(dbg, 4);
    148 }