tor-browser

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

browser_webconsole_console_trace_distinct.js (2124B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8><script>
      7    var bar = () => myFunc();
      8    var rab = () => myFunc();
      9    var myFunc = () => console.trace();
     10 
     11    bar();bar();
     12    rab();rab();
     13  </script>`;
     14 
     15 add_task(async function () {
     16  const hud = await openNewTabAndConsole(TEST_URI);
     17  await waitFor(() => findConsoleAPIMessage(hud, "trace"));
     18  ok(true, "console.trace() message is displayed in the console");
     19  const messages = findConsoleAPIMessages(hud, "console.trace()");
     20  is(messages.length, 4, "There are 4 console.trace() messages");
     21 
     22  info("Wait until the stacktraces are displayed");
     23  await waitFor(() => getFrames(hud).length === messages.length);
     24  const [traceBar1, traceBar2, traceRab1, traceRab2] = getFrames(hud);
     25 
     26  const framesBar1 = getFramesTitleFromTrace(traceBar1);
     27  is(
     28    framesBar1.join(" - "),
     29    "myFunc - bar - <anonymous>",
     30    "First bar trace has the expected frames"
     31  );
     32 
     33  const framesBar2 = getFramesTitleFromTrace(traceBar2);
     34  is(
     35    framesBar2.join(" - "),
     36    "myFunc - bar - <anonymous>",
     37    "Second bar trace has the expected frames"
     38  );
     39 
     40  const framesRab1 = getFramesTitleFromTrace(traceRab1);
     41  is(
     42    framesRab1.join(" - "),
     43    "myFunc - rab - <anonymous>",
     44    "First rab trace has the expected frames"
     45  );
     46 
     47  const framesRab2 = getFramesTitleFromTrace(traceRab2);
     48  is(
     49    framesRab2.join(" - "),
     50    "myFunc - rab - <anonymous>",
     51    "Second rab trace has the expected frames"
     52  );
     53 });
     54 
     55 /**
     56 * Get all the stacktrace `.frames` elements  displayed in the console output.
     57 *
     58 * @returns {Array<HTMLElement>}
     59 */
     60 function getFrames(hud) {
     61  return Array.from(hud.ui.outputNode.querySelectorAll(".stacktrace .frames"));
     62 }
     63 
     64 /**
     65 * Given a stacktrace element, return an array of the frame names displayed in it.
     66 *
     67 * @param {HTMLElement} traceEl
     68 * @returns {Array<string>}
     69 */
     70 function getFramesTitleFromTrace(traceEl) {
     71  return Array.from(traceEl.querySelectorAll(".frame .title")).map(
     72    t => t.textContent
     73  );
     74 }