tor-browser

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

browser_toolbox_telemetry_enter.js (4086B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 * http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const URL = "data:text/html;charset=utf8,browser_toolbox_telemetry_enter.js";
      7 const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
      8 const DATA = [
      9  {
     10    timestamp: null,
     11    category: "devtools.main",
     12    method: "enter",
     13    object: "inspector",
     14    value: null,
     15    extra: {
     16      host: "bottom",
     17      width: "1300",
     18      start_state: "initial_panel",
     19      panel_name: "inspector",
     20      cold: "true",
     21    },
     22  },
     23  {
     24    timestamp: null,
     25    category: "devtools.main",
     26    method: "enter",
     27    object: "jsdebugger",
     28    value: null,
     29    extra: {
     30      host: "bottom",
     31      width: "1300",
     32      start_state: "toolbox_show",
     33      panel_name: "jsdebugger",
     34      cold: "true",
     35    },
     36  },
     37  {
     38    timestamp: null,
     39    category: "devtools.main",
     40    method: "enter",
     41    object: "styleeditor",
     42    value: null,
     43    extra: {
     44      host: "bottom",
     45      width: "1300",
     46      start_state: "toolbox_show",
     47      panel_name: "styleeditor",
     48      cold: "true",
     49    },
     50  },
     51  {
     52    timestamp: null,
     53    category: "devtools.main",
     54    method: "enter",
     55    object: "netmonitor",
     56    value: null,
     57    extra: {
     58      host: "bottom",
     59      width: "1300",
     60      start_state: "toolbox_show",
     61      panel_name: "netmonitor",
     62      cold: "true",
     63    },
     64  },
     65  {
     66    timestamp: null,
     67    category: "devtools.main",
     68    method: "enter",
     69    object: "storage",
     70    value: null,
     71    extra: {
     72      host: "bottom",
     73      width: "1300",
     74      start_state: "toolbox_show",
     75      panel_name: "storage",
     76      cold: "true",
     77    },
     78  },
     79  {
     80    timestamp: null,
     81    category: "devtools.main",
     82    method: "enter",
     83    object: "netmonitor",
     84    value: null,
     85    extra: {
     86      host: "bottom",
     87      width: "1300",
     88      start_state: "toolbox_show",
     89      panel_name: "netmonitor",
     90      cold: "false",
     91    },
     92  },
     93 ];
     94 
     95 add_task(async function () {
     96  // Let's reset the counts.
     97  Services.telemetry.clearEvents();
     98 
     99  // Ensure no events have been logged
    100  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
    101  ok(!snapshot.parent, "No events have been logged for the main process");
    102 
    103  const tab = await addTab(URL);
    104 
    105  // Set up some cached messages for the web console.
    106  await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
    107    content.console.log("test 1");
    108    content.console.log("test 2");
    109    content.console.log("test 3");
    110    content.console.log("test 4");
    111    content.console.log("test 5");
    112  });
    113 
    114  // Open the toolbox
    115  await gDevTools.showToolboxForTab(tab, { toolId: "inspector" });
    116 
    117  // Switch between a few tools
    118  await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
    119  await gDevTools.showToolboxForTab(tab, { toolId: "styleeditor" });
    120  await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });
    121  await gDevTools.showToolboxForTab(tab, { toolId: "storage" });
    122  await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });
    123 
    124  await checkResults();
    125 });
    126 
    127 async function checkResults() {
    128  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
    129  const events = snapshot.parent.filter(
    130    event =>
    131      event[1] === "devtools.main" && event[2] === "enter" && event[4] === null
    132  );
    133 
    134  for (const i in DATA) {
    135    const [timestamp, category, method, object, value, extra] = events[i];
    136    const expected = DATA[i];
    137 
    138    // ignore timestamp
    139    Assert.greater(timestamp, 0, "timestamp is greater than 0");
    140    is(category, expected.category, "category is correct");
    141    is(method, expected.method, "method is correct");
    142    is(object, expected.object, "object is correct");
    143    is(value, expected.value, "value is correct");
    144 
    145    // extras
    146    is(extra.host, expected.extra.host, "host is correct");
    147    Assert.greater(Number(extra.width), 0, "width is greater than 0");
    148    is(extra.start_state, expected.extra.start_state, "start_state is correct");
    149    is(extra.panel_name, expected.extra.panel_name, "panel_name is correct");
    150    is(extra.cold, expected.extra.cold, "cold is correct");
    151  }
    152 }