tor-browser

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

browser_dbg-breakpoints-reloading.js (3927B)


      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 breakpoints syncing when reloading
      6 
      7 "use strict";
      8 
      9 requestLongerTimeout(3);
     10 
     11 // Tests that a breakpoint set is correctly synced after reload
     12 // and gets hit correctly.
     13 add_task(async function () {
     14  const dbg = await initDebugger("doc-scripts.html", "simple1.js", "long.js");
     15 
     16  await selectSource(dbg, "simple1.js");
     17 
     18  // Setting 2 breakpoints, one on line 64 which is expected
     19  // to get hit, while the other on line 56 which is not expected
     20  // to get hit, but to assert that it correctly set after reload.
     21  await addBreakpointViaGutter(dbg, 64);
     22  await addBreakpointViaGutter(dbg, 56);
     23 
     24  await selectSource(dbg, "long.js");
     25 
     26  await addBreakpointViaGutter(dbg, 1);
     27 
     28  const onReloaded = reload(dbg);
     29  await waitForPaused(dbg);
     30 
     31  info("Assert that the source is not long.js");
     32  // Adding this is redundant but just to make it explicit that we
     33  // make sure long.js should not exist yet
     34  assertSourceDoesNotExist(dbg, "long.js");
     35 
     36  const source = findSource(dbg, "simple1.js");
     37 
     38  await assertPausedAtSourceAndLine(dbg, source.id, 64);
     39 
     40  info("The breakpoint for long.js does not exist yet");
     41  await waitForState(dbg, () => dbg.selectors.getBreakpointCount() == 2);
     42 
     43  // The breakpoints are available once their corresponding source
     44  // has been processed. Let's assert that all the breakpoints for
     45  // simple1.js have been restored.
     46  await assertBreakpoint(dbg, 56);
     47  await assertBreakpoint(dbg, 64);
     48 
     49  await resume(dbg);
     50  await waitForPaused(dbg);
     51 
     52  const source2 = findSource(dbg, "long.js");
     53 
     54  await assertPausedAtSourceAndLine(dbg, source2.id, 1);
     55 
     56  info("All 3 breakpoints from simple1.js and long.js still exist");
     57  await waitForState(dbg, () => dbg.selectors.getBreakpointCount() == 3);
     58 
     59  await assertBreakpoint(dbg, 1);
     60 
     61  await resume(dbg);
     62 
     63  info("Wait for reload to complete after resume");
     64  await onReloaded;
     65 
     66  // remove breakpoints so they do not affect other
     67  // tests.
     68  await removeBreakpoint(dbg, source.id, 56);
     69  await removeBreakpoint(dbg, source.id, 64);
     70  await removeBreakpoint(dbg, source2.id, 1);
     71 
     72  await dbg.toolbox.closeToolbox();
     73 });
     74 
     75 // Test that pending breakpoints are installed in inline scripts as they are
     76 // sent to the client.
     77 add_task(async function () {
     78  const dbg = await initDebugger("doc-scripts.html", "doc-scripts.html");
     79 
     80  await selectSource(dbg, "doc-scripts.html");
     81  await addBreakpointViaGutter(dbg, 22);
     82  await addBreakpointViaGutter(dbg, 27);
     83 
     84  const onReloaded = reload(dbg, "doc-scripts.html");
     85  await waitForPaused(dbg);
     86 
     87  const source = findSource(dbg, "doc-scripts.html");
     88 
     89  await assertPausedAtSourceAndLine(dbg, source.id, 22);
     90 
     91  info("Only the breakpoint for the first inline script should exist");
     92  await waitForState(dbg, () => dbg.selectors.getBreakpointCount() == 1);
     93 
     94  await assertBreakpoint(dbg, 22);
     95 
     96  // The second breakpoint we added is in a later inline script, and won't
     97  // appear until after we have resumed from the first breakpoint and the
     98  // second inline script has been created.
     99  await assertNoBreakpoint(dbg, 27);
    100 
    101  await resume(dbg);
    102  await waitForPaused(dbg);
    103 
    104  info("All 2 breakpoints from both inline scripts still exist");
    105  await waitForState(dbg, () => dbg.selectors.getBreakpointCount() == 2);
    106 
    107  await assertPausedAtSourceAndLine(dbg, source.id, 27);
    108  await assertBreakpoint(dbg, 27);
    109 
    110  await resume(dbg);
    111 
    112  info("Wait for reload to complete after resume");
    113  await onReloaded;
    114 
    115  await removeBreakpoint(dbg, source.id, 22);
    116  await removeBreakpoint(dbg, source.id, 27);
    117 
    118  await dbg.toolbox.closeToolbox();
    119 });
    120 
    121 function assertSourceDoesNotExist(dbg, url) {
    122  const source = findSource(dbg, url, { silent: true });
    123  ok(!source, `Source for ${url} does not exist`);
    124 }