tor-browser

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

browser_dbg-javascript-tracer-next-load.js (3484B)


      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 tracing only on next page load
      6 
      7 "use strict";
      8 
      9 add_task(async function testTracingOnNextLoad() {
     10  // Cover tracing function argument values
     11  const jsCode = `function foo() {}; function bar() {}; foo(); dump("plop\\n")`;
     12  const dbg = await initDebuggerWithAbsoluteURL(
     13    "data:text/html," +
     14      encodeURIComponent(`<script>${jsCode}</script><body></body>`)
     15  );
     16 
     17  // This test covers the Web Console, whereas it is no longer the default output
     18  await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-console");
     19 
     20  let traceButton = dbg.toolbox.doc.getElementById("command-button-jstracer");
     21 
     22  ok(
     23    !traceButton.classList.contains("pending"),
     24    "Before toggling the trace button, it has no particular state"
     25  );
     26 
     27  await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-next-load");
     28 
     29  await toggleJsTracer(dbg.toolbox);
     30 
     31  info(
     32    "Wait for the split console to be automatically displayed when toggling this setting"
     33  );
     34  await dbg.toolbox.getPanelWhenReady("webconsole");
     35 
     36  invokeInTab("bar");
     37 
     38  // Let some time for the call to be traced
     39  await wait(500);
     40 
     41  is(
     42    (await findConsoleMessages(dbg.toolbox, "λ bar")).length,
     43    0,
     44    "The code isn't logged as the tracer shouldn't be started yet"
     45  );
     46 
     47  // Wait for the trace button to be highlighted
     48  await waitFor(() => {
     49    return traceButton.classList.contains("pending");
     50  }, "The tracer button is pending before reloading the page");
     51 
     52  info("Add an iframe to trigger a target creation");
     53  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
     54    const iframe = content.document.createElement("iframe");
     55    iframe.src = "data:text/html,iframe";
     56    content.document.body.appendChild(iframe);
     57  });
     58 
     59  // Let some time to regress and start the tracer
     60  await wait(500);
     61 
     62  ok(
     63    traceButton.classList.contains("pending"),
     64    "verify that the tracer is still pending after the iframe creation"
     65  );
     66 
     67  // Reload the page to trigger the tracer
     68  await reload(dbg);
     69 
     70  info("Wait for tracing to be enabled after page reload");
     71  await hasConsoleMessage(dbg, "Started tracing to Web Console");
     72  is(
     73    traceButton.getAttribute("aria-pressed"),
     74    "true",
     75    "The tracer button is now active after reload"
     76  );
     77 
     78  info("Wait for the split console to be displayed");
     79  await dbg.toolbox.getPanelWhenReady("webconsole");
     80 
     81  // Ensure that the very early code is traced
     82  await hasConsoleMessage(dbg, "λ foo");
     83 
     84  is(
     85    (await findConsoleMessages(dbg.toolbox, "λ bar")).length,
     86    0,
     87    "The code ran before the reload isn't logged"
     88  );
     89 
     90  info("Toggle OFF the tracing");
     91  await toggleJsTracer(dbg.toolbox);
     92 
     93  await waitFor(() => {
     94    return !traceButton.classList.contains("active");
     95  }, "The tracer button is no longer active after stop request");
     96 
     97  info("Toggle the setting back off");
     98  await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-next-load");
     99 
    100  await waitFor(() => {
    101    traceButton = dbg.toolbox.doc.getElementById("command-button-jstracer");
    102    return !traceButton.classList.contains("pending");
    103  }, "The tracer button is no longer pending after toggling the setting");
    104 
    105  // Reset the trace on next interaction setting
    106  Services.prefs.clearUserPref(
    107    "devtools.debugger.javascript-tracing-on-next-interaction"
    108  );
    109 });