michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: function shouldHaveChanged(a, b) michael@0: { michael@0: if (a.length != b.length) { michael@0: throw Error("TEST-UNEXPECTED-FAIL: telemetry count array size changed"); michael@0: } michael@0: michael@0: for (let i = 0; i < a.length; ++i) { michael@0: if (a[i] == b[i]) { michael@0: continue; michael@0: } michael@0: return; // something was different, that's all that matters michael@0: } michael@0: throw Error("TEST-UNEXPECTED-FAIL: telemetry data didn't change"); michael@0: } michael@0: michael@0: function TestStartupCacheTelemetry() { } michael@0: michael@0: TestStartupCacheTelemetry.prototype = { michael@0: classID: Components.ID("{73cbeffd-d6c7-42f0-aaf3-f176430dcfc8}"), michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), michael@0: michael@0: saveInitial: function() { michael@0: let t = Services.telemetry; michael@0: this._age = t.getHistogramById("STARTUP_CACHE_AGE_HOURS").snapshot.counts; michael@0: this._invalid = t.getHistogramById("STARTUP_CACHE_INVALID").snapshot.counts; michael@0: }, michael@0: michael@0: checkFinal: function() { michael@0: let t = Services.telemetry; michael@0: let newAge = t.getHistogramById("STARTUP_CACHE_AGE_HOURS").snapshot.counts; michael@0: shouldHaveChanged(this._age, newAge); michael@0: michael@0: let newInvalid = t.getHistogramById("STARTUP_CACHE_INVALID").snapshot.counts; michael@0: shouldHaveChanged(this._invalid, newInvalid); michael@0: }, michael@0: michael@0: observe: function(subject, topic, data) { michael@0: switch (topic) { michael@0: case "save-initial": michael@0: this.saveInitial(); michael@0: break; michael@0: michael@0: case "check-final": michael@0: this.checkFinal(); michael@0: break; michael@0: michael@0: default: michael@0: throw Error("BADDOG, NO MILKBONE FOR YOU"); michael@0: } michael@0: }, michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestStartupCacheTelemetry]);