tor-browser

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

browser_dbg-javascript-tracer-sidebar-values-search.js (4874B)


      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 const jsCode = `
      9  function foo() { bar(42); };
     10  function bar(num) {plop(window)};
     11  function plop(win) {hey(win, false, null, undefined)};
     12  function hey(win) {}`;
     13 const TEST_URL = `data:text/html,test-page<script>${encodeURIComponent(
     14  jsCode
     15 )}</script>`;
     16 
     17 add_task(async function () {
     18  const dbg = await initDebuggerWithAbsoluteURL(TEST_URL);
     19 
     20  info("Force the log method to be the debugger sidebar");
     21  await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-debugger-sidebar");
     22  info("Also enable values recording");
     23  await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-log-values");
     24 
     25  info("Enable the tracing");
     26  await toggleJsTracer(dbg.toolbox);
     27 
     28  is(
     29    dbg.selectors.getSelectedPrimaryPaneTab(),
     30    "tracer",
     31    "The tracer sidebar is automatically shown on start"
     32  );
     33 
     34  invokeInTab("foo");
     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  // There is only one top level trace being displayed for `foo`  and one immediate children call to `bar`
     44  await waitFor(() => tracerTree.querySelectorAll(".trace-line").length == 2);
     45 
     46  ok(
     47    !findElementWithSelector(
     48      dbg,
     49      `#tracer-tab-panel .call-tree-container .search-exception`
     50    ),
     51    "No exception is shown after receiving the first traces"
     52  );
     53 
     54  const argumentSearchInput = findElementWithSelector(
     55    dbg,
     56    `#tracer-tab-panel .call-tree-container input`
     57  );
     58  is(
     59    argumentSearchInput.disabled,
     60    false,
     61    "The input to search by values isn't disabled"
     62  );
     63 
     64  async function checkSearchExpression(
     65    searchQuery,
     66    previewString,
     67    matchesCount
     68  ) {
     69    argumentSearchInput.value = "";
     70    argumentSearchInput.focus();
     71    type(dbg, searchQuery);
     72 
     73    await waitFor(() => {
     74      const argumentSearchValue = findElementWithSelector(
     75        dbg,
     76        `#tracer-tab-panel .call-tree-container .search-value`
     77      );
     78      return (
     79        argumentSearchValue &&
     80        argumentSearchValue.textContent ==
     81          `Searching for:${previewString} (${matchesCount} match(es))`
     82      );
     83    });
     84  }
     85 
     86  info("Search for function call whose arguments contains '42'");
     87  await checkSearchExpression("42", "42", 1);
     88 
     89  pressKey(dbg, "Enter");
     90 
     91  info("Wait for the matched trace to be focused");
     92  await waitFor(() =>
     93    tracerTree.querySelector(".tree-node.focused .trace-line")
     94  );
     95 
     96  let focusedTrace = tracerTree.querySelector(".tree-node.focused .trace-line");
     97  Assert.stringContains(focusedTrace.textContent, "λ bar");
     98 
     99  info("Search for some falsy values");
    100  await checkSearchExpression("false", "false", 1);
    101  await checkSearchExpression("null", "null", 1);
    102  await checkSearchExpression("undefined", "undefined", 1);
    103 
    104  info("Lookup for 'window' usages");
    105  await checkSearchExpression("window", `Window ${TEST_URL}`, 2);
    106 
    107  pressKey(dbg, "Enter");
    108 
    109  info("Wait for the matched trace to be focused");
    110  await waitFor(
    111    () =>
    112      tracerTree.querySelector(".tree-node.focused .trace-line") != focusedTrace
    113  );
    114 
    115  focusedTrace = tracerTree.querySelector(".tree-node.focused .trace-line");
    116  Assert.stringContains(focusedTrace.textContent, "λ plop");
    117 
    118  info("Lookup for the next match");
    119  pressKey(dbg, "Enter");
    120 
    121  await waitFor(
    122    () =>
    123      tracerTree.querySelector(".tree-node.focused .trace-line") !=
    124      focusedTrace,
    125    "Wait for focusing a different line"
    126  );
    127 
    128  focusedTrace = tracerTree.querySelector(".tree-node.focused .trace-line");
    129  Assert.stringContains(focusedTrace.textContent, "λ hey");
    130 
    131  info("Get back to the previous match");
    132  pressKey(dbg, "ShiftEnter");
    133 
    134  await waitFor(
    135    () =>
    136      tracerTree.querySelector(".tree-node.focused .trace-line") !=
    137      focusedTrace,
    138    "Wait for focusing back the first match"
    139  );
    140 
    141  focusedTrace = tracerTree.querySelector(".tree-node.focused .trace-line");
    142  Assert.stringContains(focusedTrace.textContent, "λ plop");
    143 
    144  info("Now type a bogus expression");
    145  argumentSearchInput.value = "";
    146  type(dbg, "bogus");
    147  info("Wait for the exception to be displayed");
    148  const argumentSearchException = await waitFor(() =>
    149    findElementWithSelector(
    150      dbg,
    151      `#tracer-tab-panel .call-tree-container .search-exception`
    152    )
    153  );
    154  await waitFor(() => {
    155    return (
    156      argumentSearchException.textContent ==
    157      "ReferenceError: bogus is not defined"
    158    );
    159  });
    160 
    161  info("Disable values recording before switching to next test");
    162  await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-log-values");
    163 });