tor-browser

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

2-reload-replaced-original.js (5030B)


      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 second test will focus on v1/removed-original.js which is an original source mapped file.
      9 * This source is mapped to replaced-bundle.js.
     10 * In the first reload (v2), this original source is removed and another original file: v2/new-original.js
     11 * will replace the content of the removed-original.js in the replaced-bundle.js generated file.
     12 * And finally, in the second reload (v3) everything is removed, both original and generated source.
     13 *
     14 * Note that great care is done to ensure that new-original replaces removed-original with the
     15 * exact same breakable lines and columns. So that the breakpoint isn't simply removed
     16 * because the location is no longer breakable.
     17 */
     18 
     19 "use strict";
     20 
     21 addIntegrationTask(async function testReloadingRemovedOriginalSources(
     22  testServer,
     23  testUrl,
     24  { isCompressed }
     25 ) {
     26  info("  # Test reloading a source that is replaced and then removed");
     27  testServer.backToFirstVersion();
     28 
     29  const dbg = await initDebuggerWithAbsoluteURL(testUrl, "removed-original.js");
     30 
     31  info("Add initial breakpoint");
     32  await selectSource(dbg, "removed-original.js");
     33  await addBreakpoint(dbg, "removed-original.js", 4);
     34 
     35  // Assert the precise behavior of the breakpoint before reloading
     36  invokeInTab("removedOriginal");
     37  await waitForPaused(dbg);
     38  const replacedSource = findSource(dbg, "removed-original.js");
     39  await assertPausedAtSourceAndLine(dbg, replacedSource.id, 4);
     40  assertTextContentOnLine(dbg, 4, 'console.log("Removed original");');
     41  await assertBreakpoint(dbg, 4);
     42 
     43  is(dbg.selectors.getBreakpointCount(), 1, "One breakpoint exists");
     44  is(
     45    dbg.client.getServerBreakpointsList().length,
     46    1,
     47    "One breakpoint exists on the server"
     48  );
     49 
     50  let breakpoint = dbg.selectors.getBreakpointsList()[0];
     51  is(breakpoint.location.source.url, replacedSource.url);
     52  is(breakpoint.location.line, 4);
     53  if (isCompressed) {
     54    is(breakpoint.generatedLocation.line, 1);
     55    is(breakpoint.generatedLocation.column, 992);
     56  } else {
     57    is(breakpoint.generatedLocation.line, 80);
     58  }
     59  info(
     60    "Assert that the breakpoint snippet is originaly set to the to-be-removed original source content"
     61  );
     62  assertBreakpointSnippet(dbg, 1, `console.log("Removed original");`);
     63 
     64  await resume(dbg);
     65 
     66  info(
     67    "Reload, which should remove the original file and a add a new original file which will replace its content in the  generated file"
     68  );
     69  const syncBp = waitForDispatch(dbg.store, "SET_BREAKPOINT");
     70  testServer.switchToNextVersion();
     71  const onReloaded = reload(dbg, "new-original.js");
     72  await syncBp;
     73 
     74  // Assert the new breakpoint being created after reload
     75  // For now, the current behavior of the debugger is that:
     76  // the breakpoint is still hit based on the generated source/bundle file
     77  // and the UI updates itself to mention the new original file.
     78  await waitForPaused(dbg);
     79  const newSource = findSource(dbg, "new-original.js");
     80  await assertPausedAtSourceAndLine(dbg, newSource.id, 4);
     81  assertTextContentOnLine(dbg, 4, 'console.log("New original");');
     82  await assertBreakpoint(dbg, 4);
     83 
     84  is(dbg.selectors.getBreakpointCount(), 1, "One breakpoint exists");
     85  is(
     86    dbg.client.getServerBreakpointsList().length,
     87    1,
     88    "One breakpoint exists on the server"
     89  );
     90 
     91  breakpoint = dbg.selectors.getBreakpointsList()[0];
     92  is(breakpoint.location.source.url, newSource.url);
     93  is(breakpoint.location.line, 4);
     94  if (isCompressed) {
     95    is(breakpoint.generatedLocation.line, 1);
     96    is(breakpoint.generatedLocation.column, 992);
     97  } else {
     98    is(breakpoint.generatedLocation.line, 80);
     99  }
    100  info(
    101    "Assert that the breakpoint snippet changed to the new original source content"
    102  );
    103  assertBreakpointSnippet(dbg, 1, `console.log("New original");`);
    104 
    105  await resume(dbg);
    106  info("Wait for reload to complete after resume");
    107  await onReloaded;
    108 
    109  info(
    110    "Reload a last time to remove both original and generated sources entirely"
    111  );
    112  testServer.switchToNextVersion();
    113  await reload(dbg);
    114 
    115  // Let some time for breakpoint syncing to be buggy and recreated unexpected breakpoint
    116  await wait(1000);
    117  info("Assert that sources and breakpoints are gone and we aren't paused");
    118  ok(
    119    !sourceExists(dbg, "removed-original.js"),
    120    "removed-original is not present"
    121  );
    122  ok(!sourceExists(dbg, "new-original.js"), "new-original is not present");
    123  ok(
    124    !sourceExists(dbg, "replaced-bundle.js"),
    125    "replaced-bundle is not present"
    126  );
    127  assertNotPaused(dbg);
    128  is(dbg.selectors.getBreakpointCount(), 0, "We no longer have any breakpoint");
    129  // The breakpoint for the removed source still exists, atm this difficult to fix
    130  // as the frontend never loads the source.
    131  is(
    132    dbg.client.getServerBreakpointsList().length,
    133    1,
    134    "One breakpoint still exists on the server"
    135  );
    136 });