tor-browser

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

browser_inspector_sidebarstate.js (3314B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 "use strict";
      4 
      5 const TEST_URI =
      6  "data:text/html;charset=UTF-8," +
      7  "<h1>browser_inspector_sidebarstate.js</h1>";
      8 const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
      9 
     10 const TELEMETRY_DATA = [
     11  {
     12    timestamp: null,
     13    category: "devtools.main",
     14    method: "tool_timer",
     15    object: "layoutview",
     16    value: null,
     17    extra: {
     18      time_open: "",
     19    },
     20  },
     21  {
     22    timestamp: null,
     23    category: "devtools.main",
     24    method: "tool_timer",
     25    object: "fontinspector",
     26    value: null,
     27    extra: {
     28      time_open: "",
     29    },
     30  },
     31  {
     32    timestamp: null,
     33    category: "devtools.main",
     34    method: "tool_timer",
     35    object: "compatibilityview",
     36    value: null,
     37    extra: {
     38      time_open: "",
     39    },
     40  },
     41  {
     42    timestamp: null,
     43    category: "devtools.main",
     44    method: "tool_timer",
     45    object: "computedview",
     46    value: null,
     47    extra: {
     48      time_open: "",
     49    },
     50  },
     51 ];
     52 
     53 add_task(async function () {
     54  // Let's reset the counts.
     55  Services.telemetry.clearEvents();
     56 
     57  // Ensure no events have been logged
     58  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
     59  ok(!snapshot.parent, "No events have been logged for the main process");
     60 
     61  let { inspector, toolbox } = await openInspectorForURL(TEST_URI);
     62 
     63  info("Selecting font inspector.");
     64  inspector.sidebar.select("fontinspector");
     65 
     66  is(
     67    inspector.sidebar.getCurrentTabID(),
     68    "fontinspector",
     69    "Font Inspector is selected"
     70  );
     71 
     72  info("Selecting compatibility view.");
     73  const onCompatibilityViewInitialized = inspector.once(
     74    "compatibilityview-initialized"
     75  );
     76  inspector.sidebar.select("compatibilityview");
     77  await onCompatibilityViewInitialized;
     78 
     79  is(
     80    inspector.sidebar.getCurrentTabID(),
     81    "compatibilityview",
     82    "Compatibility View is selected"
     83  );
     84 
     85  info("Selecting computed view.");
     86  inspector.sidebar.select("computedview");
     87 
     88  is(
     89    inspector.sidebar.getCurrentTabID(),
     90    "computedview",
     91    "Computed View is selected"
     92  );
     93 
     94  info("Closing inspector.");
     95  await toolbox.destroy();
     96 
     97  info("Re-opening inspector.");
     98  inspector = (await openInspector()).inspector;
     99 
    100  if (!inspector.sidebar.getCurrentTabID()) {
    101    info("Default sidebar still to be selected, adding select listener.");
    102    await inspector.sidebar.once("select");
    103  }
    104 
    105  is(
    106    inspector.sidebar.getCurrentTabID(),
    107    "computedview",
    108    "Computed view is selected by default."
    109  );
    110 
    111  checkTelemetryResults();
    112 });
    113 
    114 function checkTelemetryResults() {
    115  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
    116  const events = snapshot.parent.filter(
    117    event => event[1] === "devtools.main" && event[2] === "tool_timer"
    118  );
    119 
    120  for (const i in TELEMETRY_DATA) {
    121    const [timestamp, category, method, object, value, extra] = events[i];
    122    const expected = TELEMETRY_DATA[i];
    123 
    124    // ignore timestamp
    125    Assert.greater(timestamp, 0, "timestamp is greater than 0");
    126    Assert.greater(Number(extra.time_open), 0, "time_open is greater than 0");
    127    is(category, expected.category, "category is correct");
    128    is(method, expected.method, "method is correct");
    129    is(object, expected.object, "object is correct");
    130    is(value, expected.value, "value is correct");
    131  }
    132 }