tor-browser

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

browser_dbg-pretty-print-paused-anonymous.js (4434B)


      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 pretty-printing a file with no URL works while paused.
      6 
      7 "use strict";
      8 
      9 add_task(async function () {
     10  const dbg = await initDebugger("doc-minified.html");
     11 
     12  info("Evaluate an expression with scriptCommand.execute");
     13  const debuggerDone = dbg.commands.scriptCommand.execute(
     14    `debugger; var foo; document.addEventListener("click", e => { debugger; }, {once: true})`
     15  );
     16  await waitForPaused(dbg);
     17  const evaluatedSourceId = dbg.selectors.getSelectedSourceId();
     18 
     19  // This will throw if things fail to pretty-print and render properly.
     20  info("Pretty print the source created by the evaluated expression");
     21  await togglePrettyPrint(dbg);
     22 
     23  const prettyEvaluatedSourceFilename =
     24    evaluatedSourceId.split("/").at(-1) + ":formatted";
     25  const prettySource = await waitForSource(dbg, prettyEvaluatedSourceFilename);
     26 
     27  info("Check that the script was pretty-printed as expected");
     28  const { value: prettySourceValue } = findSourceContent(dbg, prettySource);
     29 
     30  is(
     31    prettySourceValue.trim(),
     32    `debugger;
     33 var foo;
     34 document.addEventListener('click', e => {
     35  debugger;
     36 }, {
     37  once: true
     38 })
     39 `.trim(),
     40    "script was pretty printed as expected"
     41  );
     42 
     43  await resume(dbg);
     44  await debuggerDone;
     45 
     46  info("Check if we can pause inside the pretty-printed source");
     47  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     48    content.document.body.click();
     49  });
     50  await waitForPaused(dbg);
     51  await assertPausedAtSourceAndLine(dbg, prettySource.id, 4);
     52  await resume(dbg);
     53 
     54  info("Check that pretty printing works in `eval`'d source");
     55  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     56    content.eval(
     57      `setTimeout(() => {debugger;document.addEventListener("click", e => { debugger; }, {once: true})}, 100)`
     58    );
     59  });
     60  await waitForPaused(dbg);
     61  const evalSourceId = dbg.selectors.getSelectedSourceId();
     62 
     63  // This will throw if things fail to pretty-print and render properly.
     64  info("Pretty print the source created by the `eval` expression");
     65  await togglePrettyPrint(dbg);
     66 
     67  const prettyEvalSourceFilename =
     68    evalSourceId.split("/").at(-1) + ":formatted";
     69  const prettyEvalSource = await waitForSource(dbg, prettyEvalSourceFilename);
     70 
     71  info("Check that the script was pretty-printed as expected");
     72  const { value: prettyEvalSourceValue } = findSourceContent(
     73    dbg,
     74    prettyEvalSource
     75  );
     76 
     77  is(
     78    prettyEvalSourceValue.trim(),
     79    `
     80 setTimeout(
     81  () => {
     82    debugger;
     83    document.addEventListener('click', e => {
     84      debugger;
     85    }, {
     86      once: true
     87    })
     88  },
     89  100
     90 )`.trim(),
     91    "script was pretty printed as expected"
     92  );
     93  await resume(dbg);
     94 
     95  info("Check if we can pause inside the pretty-printed eval source");
     96  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
     97    content.document.body.click();
     98  });
     99  await waitForPaused(dbg);
    100  await assertPausedAtSourceAndLine(dbg, prettyEvalSource.id, 5);
    101  await resume(dbg);
    102 
    103  info("Check that pretty printing works in `new Function` source");
    104  invokeInTab("breakInNewFunction");
    105  await waitForPaused(dbg);
    106  const newFunctionSourceId = dbg.selectors.getSelectedSourceId();
    107 
    108  // This will throw if things fail to pretty-print and render properly.
    109  info("Pretty print the source created with `new Function`");
    110  await togglePrettyPrint(dbg);
    111 
    112  const prettyNewFunctionSourceFilename =
    113    newFunctionSourceId.split("/").at(-1) + ":formatted";
    114  const prettyNewFunctionSource = await waitForSource(
    115    dbg,
    116    prettyNewFunctionSourceFilename
    117  );
    118 
    119  info("Check that the script was pretty-printed as expected");
    120  const { value: prettyNewFunctionSourceValue } = findSourceContent(
    121    dbg,
    122    prettyNewFunctionSource
    123  );
    124 
    125  is(
    126    prettyNewFunctionSourceValue.trim(),
    127    `function anonymous() {
    128  debugger;
    129  document.addEventListener('click', function () {
    130    debugger;
    131  })
    132 }
    133 `.trim(),
    134    "script was pretty printed as expected"
    135  );
    136  await resume(dbg);
    137 
    138  info("Check if we can pause inside the pretty-printed eval source");
    139  SpecialPowers.spawn(gBrowser.selectedBrowser, [], function () {
    140    content.document.body.click();
    141  });
    142  await waitForPaused(dbg);
    143  await assertPausedAtSourceAndLine(dbg, prettyNewFunctionSource.id, 4);
    144  await resume(dbg);
    145 });