tor-browser

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

browser_webconsole_telemetry_jump_to_definition.js (1700B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Tests the jump_to_definition telemetry event.
      5 
      6 "use strict";
      7 
      8 const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8><script>
      9  function x(){}
     10  console.log("test message", x);
     11 </script>`;
     12 
     13 const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
     14 
     15 add_task(async function () {
     16  // Let's reset the counts.
     17  Services.telemetry.clearEvents();
     18 
     19  // Ensure no events have been logged
     20  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
     21  ok(!snapshot.parent, "No events have been logged for the main process");
     22 
     23  const hud = await openNewTabAndConsole(TEST_URI);
     24 
     25  const message = await waitFor(() =>
     26    findConsoleAPIMessage(hud, "test message")
     27  );
     28  info("Click on the 'jump to definition' button");
     29  const jumpIcon = message.querySelector(".jump-definition");
     30  jumpIcon.click();
     31 
     32  const events = getJumpToDefinitionEventsExtra();
     33  is(events.length, 1, "There was 1 event logged");
     34  const [event] = events;
     35  Assert.greater(
     36    Number(event.session_id),
     37    0,
     38    "There is a valid session_id in the logged event"
     39  );
     40 });
     41 
     42 function getJumpToDefinitionEventsExtra() {
     43  // Retrieve and clear telemetry events.
     44  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
     45 
     46  const events = snapshot.parent.filter(
     47    event =>
     48      event[1] === "devtools.main" &&
     49      event[2] === "jump_to_definition" &&
     50      event[3] === "webconsole"
     51  );
     52 
     53  // Since we already know we have the correct event, we only return the `extra` field
     54  // that was passed to it (which is event[5] here).
     55  return events.map(event => event[5]);
     56 }