tor-browser

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

browser_toolbox_telemetry_exit.js (3534B)


      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: "exit",
     13    object: "inspector",
     14    value: null,
     15    extra: {
     16      host: "bottom",
     17      width: 1300,
     18      panel_name: "inspector",
     19      next_panel: "jsdebugger",
     20      reason: "toolbox_show",
     21    },
     22  },
     23  {
     24    timestamp: null,
     25    category: "devtools.main",
     26    method: "exit",
     27    object: "jsdebugger",
     28    value: null,
     29    extra: {
     30      host: "bottom",
     31      width: 1300,
     32      panel_name: "jsdebugger",
     33      next_panel: "styleeditor",
     34      reason: "toolbox_show",
     35    },
     36  },
     37  {
     38    timestamp: null,
     39    category: "devtools.main",
     40    method: "exit",
     41    object: "styleeditor",
     42    value: null,
     43    extra: {
     44      host: "bottom",
     45      width: 1300,
     46      panel_name: "styleeditor",
     47      next_panel: "netmonitor",
     48      reason: "toolbox_show",
     49    },
     50  },
     51  {
     52    timestamp: null,
     53    category: "devtools.main",
     54    method: "exit",
     55    object: "netmonitor",
     56    value: null,
     57    extra: {
     58      host: "bottom",
     59      width: 1300,
     60      panel_name: "netmonitor",
     61      next_panel: "storage",
     62      reason: "toolbox_show",
     63    },
     64  },
     65  {
     66    timestamp: null,
     67    category: "devtools.main",
     68    method: "exit",
     69    object: "storage",
     70    value: null,
     71    extra: {
     72      host: "bottom",
     73      width: 1300,
     74      panel_name: "storage",
     75      next_panel: "netmonitor",
     76      reason: "toolbox_show",
     77    },
     78  },
     79 ];
     80 
     81 add_task(async function () {
     82  // Let's reset the counts.
     83  Services.telemetry.clearEvents();
     84 
     85  // Ensure no events have been logged
     86  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
     87  ok(!snapshot.parent, "No events have been logged for the main process");
     88 
     89  const tab = await addTab(URL);
     90 
     91  // Open the toolbox
     92  await gDevTools.showToolboxForTab(tab, { toolId: "inspector" });
     93 
     94  // Switch between a few tools
     95  await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
     96  await gDevTools.showToolboxForTab(tab, { toolId: "styleeditor" });
     97  await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });
     98  await gDevTools.showToolboxForTab(tab, { toolId: "storage" });
     99  await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });
    100 
    101  await checkResults();
    102 });
    103 
    104 async function checkResults() {
    105  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
    106  const events = snapshot.parent.filter(
    107    event =>
    108      event[1] === "devtools.main" && event[2] === "exit" && event[4] === null
    109  );
    110 
    111  for (const i in DATA) {
    112    const [timestamp, category, method, object, value, extra] = events[i];
    113    const expected = DATA[i];
    114 
    115    // ignore timestamp
    116    Assert.greater(timestamp, 0, "timestamp is greater than 0");
    117    is(category, expected.category, "category is correct");
    118    is(method, expected.method, "method is correct");
    119    is(object, expected.object, "object is correct");
    120    is(value, expected.value, "value is correct");
    121 
    122    // extras
    123    is(extra.host, expected.extra.host, "host is correct");
    124    Assert.greater(Number(extra.width), 0, "width is greater than 0");
    125    is(extra.panel_name, expected.extra.panel_name, "panel_name is correct");
    126    is(extra.next_panel, expected.extra.next_panel, "next_panel is correct");
    127    is(extra.reason, expected.extra.reason, "reason is correct");
    128  }
    129 }