tor-browser

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

3-reload-changed-generated.js (6272B)


      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-with-no-update.js file where the bundle-with-another-original.js file
      9 * content changes because of another-original.js
     10 */
     11 
     12 "use strict";
     13 
     14 addIntegrationTask(async function testReloadingChangedGeneratedSource(
     15  testServer,
     16  testUrl,
     17  { isCompressed }
     18 ) {
     19  info(
     20    "  # Test reload an original source whose generated source content changes"
     21  );
     22  testServer.backToFirstVersion();
     23  const dbg = await initDebuggerWithAbsoluteURL(
     24    testUrl,
     25    "original-with-no-update.js"
     26  );
     27 
     28  info("Add initial breakpoint");
     29  await selectSource(dbg, "original-with-no-update.js");
     30  await addBreakpoint(dbg, "original-with-no-update.js", 6);
     31 
     32  info("Check that only one breakpoint is set");
     33  is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint exists");
     34 
     35  info("Check that the breakpoint location info is correct");
     36  let breakpoint = dbg.selectors.getBreakpointsList(dbg)[0];
     37  is(breakpoint.location.line, 6);
     38  if (isCompressed) {
     39    is(breakpoint.generatedLocation.line, 1);
     40    is(breakpoint.generatedLocation.column, 1062);
     41  } else {
     42    is(breakpoint.generatedLocation.line, 82);
     43  }
     44 
     45  const expectedOriginalFileContentOnBreakpointLine = "await baabar();";
     46  const expectedGeneratedFileContentOnBreakpointLine = "await baabar();";
     47 
     48  info("Check that the breakpoint is displayed on the correct line in the ui");
     49  await assertBreakpoint(dbg, 6);
     50 
     51  info("Check that breakpoint is on the first line within the function `foo`");
     52  assertTextContentOnLine(dbg, 6, expectedOriginalFileContentOnBreakpointLine);
     53 
     54  info(
     55    "Check that the breakpoint is displayed in correct location in bundle-with-another-original.js (generated source)"
     56  );
     57  await selectSource(dbg, "bundle-with-another-original.js");
     58  if (isCompressed) {
     59    await assertBreakpoint(dbg, 1);
     60  } else {
     61    await assertBreakpoint(dbg, 82);
     62    assertTextContentOnLine(
     63      dbg,
     64      82,
     65      expectedGeneratedFileContentOnBreakpointLine
     66    );
     67  }
     68  info(
     69    "Check that the source code snipper shown in the breakpoint panel is correct"
     70  );
     71  assertBreakpointSnippet(
     72    dbg,
     73    1,
     74    isCompressed
     75      ? `baabar(),console.log("YO")},foobar()}]);`
     76      : `await baabar();`
     77  );
     78 
     79  await closeTab(dbg, "bundle-with-another-original.js");
     80 
     81  // This reload changes the content of the generated file
     82  // which will cause the location of the breakpoint to change
     83  info("Reload with a new version of the file");
     84  const waitUntilNewBreakpointIsSet = waitForDispatch(
     85    dbg.store,
     86    "SET_BREAKPOINT"
     87  );
     88  testServer.switchToNextVersion();
     89  const onReloaded = reload(
     90    dbg,
     91    "bundle-with-another-original.js",
     92    "original-with-no-update.js"
     93  );
     94  await waitUntilNewBreakpointIsSet;
     95 
     96  if (!isCompressed) {
     97    await waitForPaused(dbg);
     98 
     99    // This is a bug where the server does not recieve updates to breakpoints
    100    // early, therefore is pauses at the old position, where no breakpoint is
    101    // displayed in the UI
    102    info("Assert that the breakpoint paused in the other original file");
    103    await assertPausedAtSourceAndLine(
    104      dbg,
    105      findSource(dbg, "another-original.js").id,
    106      5
    107    );
    108    await assertNoBreakpoint(dbg, 5);
    109    assertTextContentOnLine(dbg, 5, "funcC();");
    110 
    111    info("Switch to generated source and assert that the location is correct");
    112    await dbg.actions.jumpToMappedSelectedLocation();
    113    await assertPausedAtSourceAndLine(
    114      dbg,
    115      findSource(dbg, "bundle-with-another-original.js").id,
    116      82
    117    );
    118    await assertNoBreakpoint(dbg, 82);
    119    assertTextContentOnLine(dbg, 82, "funcC();");
    120 
    121    info("Switch back to original location before resuming");
    122    await dbg.actions.jumpToMappedSelectedLocation();
    123    await resume(dbg);
    124    await waitForPaused(dbg);
    125 
    126    info(
    127      "Check that the breakpoint is displayed and paused on the correct line"
    128    );
    129    await assertPausedAtSourceAndLine(
    130      dbg,
    131      findSource(dbg, "original-with-no-update.js").id,
    132      6
    133    );
    134  } else {
    135    await onReloaded;
    136    // Assert that it does not pause in commpressed files
    137    assertNotPaused(dbg);
    138  }
    139 
    140  await selectSource(dbg, "original-with-no-update.js");
    141  await waitForBreakpoint(dbg, "original-with-no-update.js", 6);
    142  await assertBreakpoint(dbg, 6);
    143 
    144  info(
    145    "Check that though the breakpoint has moved, it is still on the first line within the function `foo`"
    146  );
    147  assertTextContentOnLine(dbg, 6, expectedOriginalFileContentOnBreakpointLine);
    148 
    149  info(
    150    "Check that the breakpoint is displayed in correct location in bundle-with-another-original.js (generated source)"
    151  );
    152  await selectSource(dbg, "bundle-with-another-original.js");
    153  // This scrolls the line into view so the content
    154  // on the line is rendered and avaliable for dom querying.
    155  await scrollEditorIntoView(dbg, 103, 0);
    156 
    157  if (isCompressed) {
    158    await assertBreakpoint(dbg, 1);
    159  } else {
    160    await assertPausedAtSourceAndLine(
    161      dbg,
    162      findSource(dbg, "bundle-with-another-original.js").id,
    163      103
    164    );
    165    await assertBreakpoint(dbg, 103);
    166    assertTextContentOnLine(
    167      dbg,
    168      103,
    169      expectedGeneratedFileContentOnBreakpointLine
    170    );
    171  }
    172 
    173  info("Check that only one breakpoint is still set");
    174  is(dbg.selectors.getBreakpointCount(), 1, "Only one breakpoint exists");
    175 
    176  info("Check that the original location has changed");
    177  breakpoint = dbg.selectors.getBreakpointsList(dbg)[0];
    178  is(breakpoint.location.line, 6);
    179  if (isCompressed) {
    180    is(breakpoint.generatedLocation.line, 1);
    181    is(breakpoint.generatedLocation.column, 1132);
    182  } else {
    183    is(breakpoint.generatedLocation.line, 103);
    184  }
    185 
    186  info("Check that the breakpoint snippet is still the same");
    187  assertBreakpointSnippet(
    188    dbg,
    189    1,
    190    isCompressed
    191      ? `baabar(),console.log("YO")},foobar()}]);`
    192      : `await baabar();`
    193  );
    194 
    195  if (!isCompressed) {
    196    await resume(dbg);
    197    info("Wait for reload to complete after resume");
    198    await onReloaded;
    199  }
    200  await closeTab(dbg, "bundle-with-another-original.js");
    201 });