summaryrefslogtreecommitdiffstats
path: root/devtools/client/framework/test/browser_toolbox_telemetry_enter.js
blob: ac1253ec790b6be1adfd1ac5024d306e37acbec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const URL = "data:text/html;charset=utf8,browser_toolbox_telemetry_enter.js";
const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
const DATA = [
  {
    timestamp: null,
    category: "devtools.main",
    method: "enter",
    object: "inspector",
    value: null,
    extra: {
      host: "bottom",
      width: "1300",
      start_state: "initial_panel",
      panel_name: "inspector",
      cold: "true",
    },
  },
  {
    timestamp: null,
    category: "devtools.main",
    method: "enter",
    object: "jsdebugger",
    value: null,
    extra: {
      host: "bottom",
      width: "1300",
      start_state: "toolbox_show",
      panel_name: "jsdebugger",
      cold: "true",
    },
  },
  {
    timestamp: null,
    category: "devtools.main",
    method: "enter",
    object: "styleeditor",
    value: null,
    extra: {
      host: "bottom",
      width: "1300",
      start_state: "toolbox_show",
      panel_name: "styleeditor",
      cold: "true",
    },
  },
  {
    timestamp: null,
    category: "devtools.main",
    method: "enter",
    object: "netmonitor",
    value: null,
    extra: {
      host: "bottom",
      width: "1300",
      start_state: "toolbox_show",
      panel_name: "netmonitor",
      cold: "true",
    },
  },
  {
    timestamp: null,
    category: "devtools.main",
    method: "enter",
    object: "storage",
    value: null,
    extra: {
      host: "bottom",
      width: "1300",
      start_state: "toolbox_show",
      panel_name: "storage",
      cold: "true",
    },
  },
  {
    timestamp: null,
    category: "devtools.main",
    method: "enter",
    object: "netmonitor",
    value: null,
    extra: {
      host: "bottom",
      width: "1300",
      start_state: "toolbox_show",
      panel_name: "netmonitor",
      cold: "false",
    },
  },
];

add_task(async function () {
  // Let's reset the counts.
  Services.telemetry.clearEvents();

  // Ensure no events have been logged
  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
  ok(!snapshot.parent, "No events have been logged for the main process");

  const tab = await addTab(URL);

  // Set up some cached messages for the web console.
  await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
    content.console.log("test 1");
    content.console.log("test 2");
    content.console.log("test 3");
    content.console.log("test 4");
    content.console.log("test 5");
  });

  // Open the toolbox
  await gDevTools.showToolboxForTab(tab, { toolId: "inspector" });

  // Switch between a few tools
  await gDevTools.showToolboxForTab(tab, { toolId: "jsdebugger" });
  await gDevTools.showToolboxForTab(tab, { toolId: "styleeditor" });
  await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });
  await gDevTools.showToolboxForTab(tab, { toolId: "storage" });
  await gDevTools.showToolboxForTab(tab, { toolId: "netmonitor" });

  await checkResults();
});

async function checkResults() {
  const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
  const events = snapshot.parent.filter(
    event =>
      event[1] === "devtools.main" && event[2] === "enter" && event[4] === null
  );

  for (const i in DATA) {
    const [timestamp, category, method, object, value, extra] = events[i];
    const expected = DATA[i];

    // ignore timestamp
    Assert.greater(timestamp, 0, "timestamp is greater than 0");
    is(category, expected.category, "category is correct");
    is(method, expected.method, "method is correct");
    is(object, expected.object, "object is correct");
    is(value, expected.value, "value is correct");

    // extras
    is(extra.host, expected.extra.host, "host is correct");
    Assert.greater(Number(extra.width), 0, "width is greater than 0");
    is(extra.start_state, expected.extra.start_state, "start_state is correct");
    is(extra.panel_name, expected.extra.panel_name, "panel_name is correct");
    is(extra.cold, expected.extra.cold, "cold is correct");
  }
}