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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* eslint-disable mozilla/no-arbitrary-setTimeout */
"use strict";
const TEST_URI =
"data:text/html;charset=utf-8,<p>browser_telemetry_sidebar.js</p>";
const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
// Because we need to gather stats for the period of time that a tool has been
// opened we make use of setTimeout() to create tool active times.
const TOOL_DELAY = 200;
const DATA = [
{
timestamp: null,
category: "devtools.main",
method: "sidepanel_changed",
object: "inspector",
value: null,
extra: {
oldpanel: "layoutview",
newpanel: "animationinspector",
},
},
{
timestamp: null,
category: "devtools.main",
method: "sidepanel_changed",
object: "inspector",
value: null,
extra: {
oldpanel: "animationinspector",
newpanel: "fontinspector",
},
},
{
timestamp: null,
category: "devtools.main",
method: "sidepanel_changed",
object: "inspector",
value: null,
extra: {
oldpanel: "fontinspector",
newpanel: "layoutview",
},
},
{
timestamp: null,
category: "devtools.main",
method: "sidepanel_changed",
object: "inspector",
value: null,
extra: {
oldpanel: "layoutview",
newpanel: "computedview",
},
},
{
timestamp: null,
category: "devtools.main",
method: "sidepanel_changed",
object: "inspector",
value: null,
extra: {
oldpanel: "computedview",
newpanel: "animationinspector",
},
},
{
timestamp: null,
category: "devtools.main",
method: "sidepanel_changed",
object: "inspector",
value: null,
extra: {
oldpanel: "animationinspector",
newpanel: "fontinspector",
},
},
{
timestamp: null,
category: "devtools.main",
method: "sidepanel_changed",
object: "inspector",
value: null,
extra: {
oldpanel: "fontinspector",
newpanel: "layoutview",
},
},
{
timestamp: null,
category: "devtools.main",
method: "sidepanel_changed",
object: "inspector",
value: null,
extra: {
oldpanel: "layoutview",
newpanel: "computedview",
},
},
];
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");
await addTab(TEST_URI);
startTelemetry();
const tab = gBrowser.selectedTab;
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
});
info("inspector opened");
await testSidebar(toolbox);
checkResults();
checkEventTelemetry();
await toolbox.destroy();
gBrowser.removeCurrentTab();
});
function testSidebar(toolbox) {
info("Testing sidebar");
const inspector = toolbox.getCurrentPanel();
let sidebarTools = [
"computedview",
"layoutview",
"fontinspector",
"animationinspector",
];
// Concatenate the array with itself so that we can open each tool twice.
sidebarTools = [...sidebarTools, ...sidebarTools];
return new Promise(resolve => {
// See TOOL_DELAY for why we need setTimeout here
setTimeout(function selectSidebarTab() {
const tool = sidebarTools.pop();
if (tool) {
inspector.sidebar.select(tool);
setTimeout(function () {
setTimeout(selectSidebarTab, TOOL_DELAY);
}, TOOL_DELAY);
} else {
resolve();
}
}, TOOL_DELAY);
});
}
function checkResults() {
// For help generating these tests use generateTelemetryTests("DEVTOOLS_")
// here.
checkTelemetry(
"DEVTOOLS_INSPECTOR_OPENED_COUNT",
"",
{ 0: 1, 1: 0 },
"array"
);
checkTelemetry("DEVTOOLS_RULEVIEW_OPENED_COUNT", "", { 0: 1, 1: 0 }, "array");
checkTelemetry(
"DEVTOOLS_COMPUTEDVIEW_OPENED_COUNT",
"",
{ 0: 2, 1: 0 },
"array"
);
checkTelemetry(
"DEVTOOLS_LAYOUTVIEW_OPENED_COUNT",
"",
{ 0: 3, 1: 0 },
"array"
);
checkTelemetry(
"DEVTOOLS_FONTINSPECTOR_OPENED_COUNT",
"",
{ 0: 2, 1: 0 },
"array"
);
checkTelemetry(
"DEVTOOLS_COMPUTEDVIEW_TIME_ACTIVE_SECONDS",
"",
null,
"hasentries"
);
checkTelemetry(
"DEVTOOLS_LAYOUTVIEW_TIME_ACTIVE_SECONDS",
"",
null,
"hasentries"
);
checkTelemetry(
"DEVTOOLS_FONTINSPECTOR_TIME_ACTIVE_SECONDS",
"",
null,
"hasentries"
);
}
function checkEventTelemetry() {
const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
const events = snapshot.parent.filter(
event =>
event[1] === "devtools.main" &&
event[2] === "sidepanel_changed" &&
event[3] === "inspector" &&
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");
is(extra.oldpanel, expected.extra.oldpanel, "oldpanel is correct");
is(extra.newpanel, expected.extra.newpanel, "newpanel is correct");
}
}
|