tor-browser

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

1-reload-same-original.js (5153B)


      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 /* import-globals-from ../head.js */
      6 
      7 /**
      8 * This first test will focus on original.js file whose content changes
      9 * which affects the related generated file: bundle.js
     10 *
     11 * In the first reload, v2/original.js will only change with new lines being added
     12 * before the line where we set a breakpoint. So that the breakpoint, if not
     13 * automatically shifted, will now be against an empty line.
     14 *
     15 * In the second reload, v3/original.js will be trimmed, so that the line
     16 * where we set a breakpoint against, has been removed.
     17 */
     18 
     19 "use strict";
     20 
     21 addIntegrationTask(async function testReloadingStableOriginalSource(
     22  testServer,
     23  testUrl,
     24  { isCompressed }
     25 ) {
     26  info("  # Test reload a stable source whose content changes");
     27  const dbg = await initDebuggerWithAbsoluteURL(testUrl, "original.js");
     28 
     29  info("Add initial breakpoint");
     30  await selectSource(dbg, "original.js");
     31  await addBreakpoint(dbg, "original.js", 8);
     32 
     33  info("Check that only one breakpoint is set");
     34  is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint exists");
     35  is(
     36    dbg.client.getServerBreakpointsList().length,
     37    1,
     38    "One breakpoint exists on the server"
     39  );
     40 
     41  info("Check that the breakpoint location info is correct");
     42  let breakpoint = dbg.selectors.getBreakpointsList(dbg)[0];
     43  is(breakpoint.location.line, 8);
     44  if (isCompressed) {
     45    is(breakpoint.generatedLocation.line, 1);
     46    is(breakpoint.generatedLocation.column, 1056);
     47  } else {
     48    is(breakpoint.generatedLocation.line, 84);
     49  }
     50 
     51  const expectedOriginalFileContentOnBreakpointLine =
     52    "await nonSourceMappedFunction();";
     53  const expectedGeneratedFileContentOnBreakpointLine =
     54    "await nonSourceMappedFunction();";
     55 
     56  info("Check that the breakpoint is displayed on the correct line in the ui");
     57  await assertBreakpoint(dbg, 8);
     58 
     59  info("Check that breakpoint is on the first line within the function `foo`");
     60  assertTextContentOnLine(dbg, 8, expectedOriginalFileContentOnBreakpointLine);
     61 
     62  info(
     63    "Check that the source text snippet displayed in breakpoints panel is correct"
     64  );
     65  assertBreakpointSnippet(
     66    dbg,
     67    1,
     68    isCompressed
     69      ? "nonSourceMappedFunction();"
     70      : "await nonSourceMappedFunction();"
     71  );
     72 
     73  info(
     74    "Check that the breakpoint is displayed in correct location in bundle.js (generated source)"
     75  );
     76  await selectSource(dbg, "bundle.js");
     77  if (isCompressed) {
     78    await assertBreakpoint(dbg, 1);
     79  } else {
     80    await assertBreakpoint(dbg, 84);
     81    assertTextContentOnLine(
     82      dbg,
     83      84,
     84      expectedGeneratedFileContentOnBreakpointLine
     85    );
     86  }
     87  info(
     88    "The breakpoint snippet doesn't change when moving to generated content"
     89  );
     90  assertBreakpointSnippet(
     91    dbg,
     92    1,
     93    isCompressed
     94      ? `nonSourceMappedFunction(),console.log("YO")}}]);`
     95      : "await nonSourceMappedFunction();"
     96  );
     97 
     98  await closeTab(dbg, "bundle.js");
     99 
    100  // This reload changes the content of the original file
    101  // which will cause the location of the breakpoint to change
    102  info("Reload with a new version of the file");
    103  testServer.switchToNextVersion();
    104  await reload(dbg, "bundle.js", "original.js");
    105  await wait(1000);
    106 
    107  info(
    108    "Check that no breakpoint is restore as original line 6 is no longer breakable"
    109  );
    110  is(dbg.selectors.getBreakpointCount(), 0, "No breakpoint exists");
    111 
    112  info("Invoke `foo` to trigger breakpoint");
    113  invokeInTab("foo");
    114  await wait(1000);
    115 
    116  // TODO: Intermittently pauses (especially when in compressed)
    117  // Need to investigate
    118  if (isPaused(dbg)) {
    119    await resume(dbg);
    120  }
    121  assertNotPaused(dbg);
    122 
    123  await closeTab(dbg, "bundle.js");
    124 
    125  info("Add a second breakpoint");
    126  await addBreakpoint(dbg, "original.js", 13);
    127 
    128  is(dbg.selectors.getBreakpointCount(dbg), 1, "The breakpoint exist");
    129 
    130  info("Check that the original location of the new breakpoint is correct");
    131  breakpoint = dbg.selectors.getBreakpointsList(dbg)[0];
    132  is(breakpoint.location.line, 13);
    133  if (isCompressed) {
    134    is(breakpoint.generatedLocation.line, 1);
    135    is(breakpoint.generatedLocation.column, 1089);
    136  } else {
    137    is(breakpoint.generatedLocation.line, 89);
    138  }
    139  assertBreakpointSnippet(
    140    dbg,
    141    1,
    142    isCompressed ? `log("HEY")` : `console.log("HEY")`
    143  );
    144 
    145  // This reload removes the content related to the lines in the original
    146  // file where the breakpoints where set.
    147  // NOTE: When we reload, the `foo` function no longer exists
    148  // and the original.js file is now 3 lines long
    149  info("Reload and observe no breakpoints");
    150  testServer.switchToNextVersion();
    151  await reload(dbg, "original.js");
    152 
    153  // There will initially be zero breakpoints, but wait to make sure none are
    154  // installed while syncing.
    155  await wait(1000);
    156 
    157  assertNotPaused(dbg);
    158 
    159  is(dbg.selectors.getBreakpointCount(dbg), 0, "No breakpoints");
    160  // TODO: fails intermitently, look to fix
    161  /*is(
    162    dbg.client.getServerBreakpointsList().length,
    163    2,
    164    "No breakpoint exists on the server"
    165  );*/
    166 });