tor-browser

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

browser_dbg-javascript-tracer-values-preview.js (3478B)


      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 Javascript Tracing feature.
      6 
      7 "use strict";
      8 
      9 const TEST_URL =
     10  "data:text/html," +
     11  encodeURIComponent(
     12    `<script>function main(){foo({a: 1}); foo({b: 2})}; function foo(arg){}</script>`
     13  );
     14 
     15 add_task(async function () {
     16  const dbg = await initDebuggerWithAbsoluteURL(TEST_URL);
     17 
     18  info("Force the log method to be the debugger sidebar");
     19  await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-debugger-sidebar");
     20  info("Also enable values recording");
     21  await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-log-values");
     22 
     23  info("Enable the tracing");
     24  await toggleJsTracer(dbg.toolbox);
     25 
     26  const topLevelThreadActorID =
     27    dbg.toolbox.commands.targetCommand.targetFront.threadFront.actorID;
     28  info("Wait for tracing to be enabled");
     29  await waitForState(dbg, () => {
     30    return dbg.selectors.getIsThreadCurrentlyTracing(topLevelThreadActorID);
     31  });
     32 
     33  info("Trigger some code to record");
     34  invokeInTab("main");
     35 
     36  info("Wait for the call tree to appear in the tracer panel");
     37  const tracerTree = await waitForElementWithSelector(
     38    dbg,
     39    "#tracer-tab-panel .tree"
     40  );
     41 
     42  info("Wait for the expected traces to appear in the call tree");
     43  const traces = await waitFor(() => {
     44    const elements = tracerTree.querySelectorAll(".trace-line");
     45    if (elements.length == 3) {
     46      return elements;
     47    }
     48    return false;
     49  });
     50  tracerTree.ownerGlobal.focus();
     51  ok(traces[0].textContent.startsWith("λ main"));
     52  ok(traces[1].textContent.startsWith("λ foo"));
     53  ok(traces[2].textContent.startsWith("λ foo"));
     54 
     55  info("Select the trace for the first call to `foo`");
     56  EventUtils.synthesizeMouse(traces[1], 0, 0, {}, dbg.win);
     57 
     58  info("Wait for the trace location to be selected");
     59  await waitForSelectedLocation(dbg, 1, 70);
     60 
     61  const focusedTrace = tracerTree.querySelector(
     62    ".tree-node.focused .trace-line"
     63  );
     64  is(focusedTrace, traces[1], "The clicked trace is now focused");
     65 
     66  {
     67    const { element: popupEl, tokenEl } = await tryHovering(
     68      dbg,
     69      1,
     70      65,
     71      "previewPopup"
     72    );
     73    info("Wait for the preview popup to be populated");
     74    const objectPreview = await waitFor(() =>
     75      popupEl.querySelector(".node:nth-child(2)")
     76    );
     77    is(objectPreview.textContent, "a: 1");
     78    await closePreviewForToken(dbg, tokenEl, "previewPopup");
     79  }
     80 
     81  info("Select the trace for the second call to `foo`");
     82  EventUtils.synthesizeMouse(traces[2], 0, 0, {}, dbg.win);
     83 
     84  {
     85    const { element: popupEl, tokenEl } = await tryHovering(
     86      dbg,
     87      1,
     88      65,
     89      "previewPopup"
     90    );
     91    info("Wait for the preview popup to be populated");
     92    const objectPreview = await waitFor(() =>
     93      popupEl.querySelector(".node:nth-child(2)")
     94    );
     95    is(objectPreview.textContent, "b: 2");
     96    await closePreviewForToken(dbg, tokenEl, "previewPopup");
     97  }
     98 
     99  // Test Disabling tracing
    100  info("Disable the tracing");
    101  await toggleJsTracer(dbg.toolbox);
    102  info("Wait for tracing to be disabled");
    103  await waitForState(dbg, () => {
    104    return !dbg.selectors.getIsThreadCurrentlyTracing(topLevelThreadActorID);
    105  });
    106 
    107  info("Reset back to the default value");
    108  await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-console");
    109  await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-log-values");
    110 });