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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests the filters_changed telemetry event.
"use strict";
const TEST_URI = `data:text/html,<!DOCTYPE html><meta charset=utf8><script>
console.log("test message");
</script>`;
const ALL_CHANNELS = Ci.nsITelemetry.DATASET_ALL_CHANNELS;
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 hud = await openNewTabAndConsole(TEST_URI);
info("Click on the 'log' filter");
await setFilterState(hud, {
log: false,
});
checkTelemetryEvent({
trigger: "log",
active: "error,warn,info,debug",
inactive: "text,log,css,net,netxhr",
});
info("Click on the 'netxhr' filter");
await setFilterState(hud, {
netxhr: true,
});
checkTelemetryEvent({
trigger: "netxhr",
active: "error,warn,info,debug,netxhr",
inactive: "text,log,css,net",
});
info("Filter the output using the text filter input");
await setFilterState(hud, { text: "no match" });
checkTelemetryEvent({
trigger: "text",
active: "text,error,warn,info,debug,netxhr",
inactive: "log,css,net",
});
});
function checkTelemetryEvent(expectedEvent) {
const events = getFiltersChangedEventsExtra();
is(events.length, 1, "There was only 1 event logged");
const [event] = events;
Assert.greater(
Number(event.session_id),
0,
"There is a valid session_id in the logged event"
);
const f = e => JSON.stringify(e, null, 2);
is(
f(event),
f({
...expectedEvent,
session_id: event.session_id,
}),
"The event has the expected data"
);
}
function getFiltersChangedEventsExtra() {
// Retrieve and clear telemetry events.
const snapshot = Services.telemetry.snapshotEvents(ALL_CHANNELS, true);
const filtersChangedEvents = snapshot.parent.filter(
event =>
event[1] === "devtools.main" &&
event[2] === "filters_changed" &&
event[3] === "webconsole"
);
// Since we already know we have the correct event, we only return the `extra` field
// that was passed to it (which is event[5] here).
return filtersChangedEvents.map(event => event[5]);
}
|