tor-browser

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

browser_dbg-pretty-print-auto.js (4791B)


      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 the auto pretty printing feature
      6 
      7 "use strict";
      8 
      9 add_task(async function testAutoPrettyPrintedOff() {
     10  // Disable source map in order to allow pretty printing the bundle
     11  await pushPref("devtools.source-map.client-service.enabled", false);
     12 
     13  const dbg = await initDebugger("doc-sourcemaps3.html", "bundle.js");
     14 
     15  // Expand the tree to make the source visible
     16  await waitForSourcesInSourceTree(dbg, ["bundle.js"], {
     17    noExpand: false,
     18  });
     19  // Do not use selectSource test helper as it ultimately pass keepContext=false to selectLocation action.
     20  await selectSourceFromSourceTree(
     21    dbg,
     22    "bundle.js",
     23    "Select the `bundle.js` script for the tree"
     24  );
     25 
     26  is(
     27    findElement(dbg, "prettyPrintButton").disabled,
     28    false,
     29    "The pretty print button is enabled"
     30  );
     31 });
     32 
     33 add_task(async function testAutoPrettyPrintedOn() {
     34  let dbg = await initDebugger("doc-sourcemaps3.html", "bundle.js");
     35 
     36  info("Enable automatic pretty printing");
     37  await toggleDebuggerSettingsMenuItem(dbg, {
     38    className: ".debugger-settings-menu-item-toggle-auto-pretty-print",
     39    isChecked: false,
     40  });
     41 
     42  // Expand the tree to make the source visible
     43  await waitForSourcesInSourceTree(dbg, ["bundle.js"], {
     44    noExpand: false,
     45  });
     46  // Do not use selectSource test helper as it ultimately pass keepContext=false to selectLocation action.
     47  await selectSourceFromSourceTree(
     48    dbg,
     49    "bundle.js",
     50    "Select the `bundle.js` script for the tree"
     51  );
     52 
     53  await waitForSelectedSource(dbg, "bundle.js");
     54  ok(
     55    findElement(dbg, "prettyPrintButton").classList.contains("pretty"),
     56    "The pretty print button should report that the source has been pretty printed"
     57  );
     58 
     59  const source = findSource(dbg, "bundle.js:formatted");
     60  await addBreakpoint(dbg, "bundle.js:formatted", 49);
     61 
     62  invokeInTab("test");
     63  await waitForPaused(dbg);
     64 
     65  await assertPausedAtSourceAndLine(dbg, source.id, 49);
     66 
     67  await stepOver(dbg);
     68 
     69  await assertPausedAtSourceAndLine(dbg, source.id, 55);
     70 
     71  await resume(dbg);
     72 
     73  info("Reload and assert that the source keeps being pretty printed");
     74  await reload(dbg, "bundle.js:formatted");
     75  await waitForSelectedSource(dbg, "bundle.js");
     76  ok(
     77    findElement(dbg, "prettyPrintButton").classList.contains("pretty"),
     78    "The source should still be pretty printed after reload"
     79  );
     80 
     81  // Close the tab and see if the source is also reopened directly to the pretty printed version
     82  await closeTab(dbg, "bundle.js");
     83 
     84  await closeTabAndToolbox();
     85 
     86  // Do not use `initDebugger` as it resets all settings
     87  const toolbox = await openNewTabAndToolbox(
     88    EXAMPLE_URL + "doc-sourcemaps3.html",
     89    "jsdebugger"
     90  );
     91  dbg = createDebuggerContext(toolbox);
     92 
     93  await selectSourceFromSourceTree(
     94    dbg,
     95    "bundle.js",
     96    "Select the `bundle.js` script for the tree"
     97  );
     98  ok(
     99    findElement(dbg, "prettyPrintButton").classList.contains("pretty"),
    100    "The source is still pretty printed after toolbox restart"
    101  );
    102 
    103  invokeInTab("test");
    104  await waitForPaused(dbg);
    105 
    106  await assertPausedAtSourceAndLine(dbg, source.id, 49);
    107  is(dbg.selectors.getSelectedSource().isPrettyPrinted, true);
    108 
    109  info("Manually disable pretty printing on the source");
    110  await togglePrettyPrint(dbg);
    111 
    112  info("Assert that we are showing the minimized source");
    113  await assertPausedAtSourceAndLine(dbg, source.generatedSource.id, 1, 625);
    114  is(dbg.selectors.getSelectedSource().isPrettyPrinted, false);
    115 
    116  info("Assert that we keep showing the minimized source after steps");
    117  await stepIn(dbg);
    118  is(dbg.selectors.getSelectedSource().isPrettyPrinted, false);
    119  await assertPausedAtSourceAndLine(dbg, source.generatedSource.id, 1, 655);
    120 
    121  await resume(dbg);
    122 
    123  info(
    124    "Reload and assert that auto-pretty printing did *not* re-pretty printed the source"
    125  );
    126  await reload(dbg, "bundle.js");
    127  ok(
    128    !findElement(dbg, "prettyPrintButton").classList.contains("pretty"),
    129    "The source should still *not* be pretty printed after reload"
    130  );
    131 
    132  info("Pause in an evaled source which shouldn't be pretty printed");
    133  const onResumed = SpecialPowers.spawn(
    134    gBrowser.selectedBrowser,
    135    [],
    136    async function () {
    137      // Craft some source that makes `isMinified` function to consider the source as not minified
    138      // thanks to the indentations
    139      content.eval(`
    140      function foo() {
    141        debugger;
    142      }
    143      foo();`);
    144    }
    145  );
    146  await waitForPaused(dbg);
    147  ok(
    148    !findElement(dbg, "prettyPrintButton").classList.contains("pretty"),
    149    "Simple source should *not* be pretty printed"
    150  );
    151 
    152  await resume(dbg);
    153  await onResumed;
    154 });