tor-browser

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

browser_webconsole_telemetry_object_expanded.js (2623B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 // Tests the object_expanded telemetry event.
      5 
      6 "use strict";
      7 
      8 const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8><script>
      9  console.log("test message", [1,2,3]);
     10 </script>`;
     11 
     12 const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
     13 
     14 add_task(async function () {
     15  // Let's reset the counts.
     16  Services.telemetry.clearEvents();
     17 
     18  // Ensure no events have been logged
     19  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
     20  ok(!snapshot.parent, "No events have been logged for the main process");
     21 
     22  const hud = await openNewTabAndConsole(TEST_URI);
     23 
     24  const message = await waitFor(() =>
     25    findConsoleAPIMessage(hud, "test message")
     26  );
     27 
     28  info("Click on the arrow icon to expand the node");
     29  const arrowIcon = message.querySelector(".theme-twisty");
     30  arrowIcon.click();
     31 
     32  // let's wait until we have 2 arrows (i.e. the object was expanded)
     33  await waitFor(() => message.querySelectorAll(".theme-twisty").length === 2);
     34 
     35  let events = getObjectExpandedEventsExtra();
     36  is(events.length, 1, "There was 1 event logged");
     37  const [event] = events;
     38  Assert.greater(
     39    Number(event.session_id),
     40    0,
     41    "There is a valid session_id in the logged event"
     42  );
     43 
     44  info("Click on the second arrow icon to expand the prototype node");
     45  const secondArrowIcon = message.querySelectorAll(".theme-twisty")[1];
     46  secondArrowIcon.click();
     47  // let's wait until we have more than 2 arrows displayed, i.e. the prototype node was
     48  // expanded.
     49  await waitFor(() => message.querySelectorAll(".theme-twisty").length > 2);
     50 
     51  events = getObjectExpandedEventsExtra();
     52  is(events.length, 1, "There was an event logged when expanding a child node");
     53 
     54  info("Click the first arrow to collapse the object");
     55  arrowIcon.click();
     56  // Let's wait until there's only one arrow visible, i.e. the node is collapsed.
     57  await waitFor(() => message.querySelectorAll(".theme-twisty").length === 1);
     58 
     59  ok(!snapshot.parent, "There was no event logged when collapsing the node");
     60 });
     61 
     62 function getObjectExpandedEventsExtra() {
     63  // Retrieve and clear telemetry events.
     64  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
     65 
     66  const events = snapshot.parent.filter(
     67    event =>
     68      event[1] === "devtools.main" &&
     69      event[2] === "object_expanded" &&
     70      event[3] === "webconsole"
     71  );
     72 
     73  // Since we already know we have the correct event, we only return the `extra` field
     74  // that was passed to it (which is event[5] here).
     75  return events.map(event => event[5]);
     76 }