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
|
/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set sts=2 sw=2 et tw=80: */
"use strict";
const HISTOGRAM = "WEBEXT_EXTENSION_STARTUP_MS";
const HISTOGRAM_KEYED = "WEBEXT_EXTENSION_STARTUP_MS_BY_ADDONID";
function processSnapshot(snapshot) {
return snapshot.sum > 0;
}
function processKeyedSnapshot(snapshot) {
let res = {};
for (let key of Object.keys(snapshot)) {
res[key] = snapshot[key].sum > 0;
}
return res;
}
add_task(async function test_telemetry() {
let extension1 = ExtensionTestUtils.loadExtension({});
let extension2 = ExtensionTestUtils.loadExtension({});
clearHistograms();
assertHistogramEmpty(HISTOGRAM);
assertKeyedHistogramEmpty(HISTOGRAM_KEYED);
await extension1.startup();
assertHistogramSnapshot(
HISTOGRAM,
{ processSnapshot, expectedValue: true },
`Data recorded for first extension for histogram: ${HISTOGRAM}.`
);
assertHistogramSnapshot(
HISTOGRAM_KEYED,
{
keyed: true,
processSnapshot: processKeyedSnapshot,
expectedValue: {
[extension1.extension.id]: true,
},
},
`Data recorded for first extension for histogram ${HISTOGRAM_KEYED}`
);
let histogram = Services.telemetry.getHistogramById(HISTOGRAM);
let histogramKeyed =
Services.telemetry.getKeyedHistogramById(HISTOGRAM_KEYED);
let histogramSum = histogram.snapshot().sum;
let histogramSumExt1 = histogramKeyed.snapshot()[extension1.extension.id].sum;
await extension2.startup();
assertHistogramSnapshot(
HISTOGRAM,
{
processSnapshot: snapshot => snapshot.sum > histogramSum,
expectedValue: true,
},
`Data recorded for second extension for histogram: ${HISTOGRAM}.`
);
assertHistogramSnapshot(
HISTOGRAM_KEYED,
{
keyed: true,
processSnapshot: processKeyedSnapshot,
expectedValue: {
[extension1.extension.id]: true,
[extension2.extension.id]: true,
},
},
`Data recorded for second extension for histogram ${HISTOGRAM_KEYED}`
);
equal(
histogramKeyed.snapshot()[extension1.extension.id].sum,
histogramSumExt1,
`Data recorder for first extension is unchanged on the keyed histogram ${HISTOGRAM_KEYED}`
);
await extension1.unload();
await extension2.unload();
});
|