startupcache/test/TestStartupCacheTelemetry.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:9a7382c122e8
1 const Cc = Components.classes;
2 const Ci = Components.interfaces;
3 const Cu = Components.utils;
4
5 Cu.import("resource://gre/modules/Services.jsm");
6 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
7
8 function shouldHaveChanged(a, b)
9 {
10 if (a.length != b.length) {
11 throw Error("TEST-UNEXPECTED-FAIL: telemetry count array size changed");
12 }
13
14 for (let i = 0; i < a.length; ++i) {
15 if (a[i] == b[i]) {
16 continue;
17 }
18 return; // something was different, that's all that matters
19 }
20 throw Error("TEST-UNEXPECTED-FAIL: telemetry data didn't change");
21 }
22
23 function TestStartupCacheTelemetry() { }
24
25 TestStartupCacheTelemetry.prototype = {
26 classID: Components.ID("{73cbeffd-d6c7-42f0-aaf3-f176430dcfc8}"),
27 QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
28
29 saveInitial: function() {
30 let t = Services.telemetry;
31 this._age = t.getHistogramById("STARTUP_CACHE_AGE_HOURS").snapshot.counts;
32 this._invalid = t.getHistogramById("STARTUP_CACHE_INVALID").snapshot.counts;
33 },
34
35 checkFinal: function() {
36 let t = Services.telemetry;
37 let newAge = t.getHistogramById("STARTUP_CACHE_AGE_HOURS").snapshot.counts;
38 shouldHaveChanged(this._age, newAge);
39
40 let newInvalid = t.getHistogramById("STARTUP_CACHE_INVALID").snapshot.counts;
41 shouldHaveChanged(this._invalid, newInvalid);
42 },
43
44 observe: function(subject, topic, data) {
45 switch (topic) {
46 case "save-initial":
47 this.saveInitial();
48 break;
49
50 case "check-final":
51 this.checkFinal();
52 break;
53
54 default:
55 throw Error("BADDOG, NO MILKBONE FOR YOU");
56 }
57 },
58 };
59
60 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestStartupCacheTelemetry]);

mercurial