startupcache/test/TestStartupCacheTelemetry.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/startupcache/test/TestStartupCacheTelemetry.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,60 @@
     1.4 +const Cc = Components.classes;
     1.5 +const Ci = Components.interfaces;
     1.6 +const Cu = Components.utils;
     1.7 +
     1.8 +Cu.import("resource://gre/modules/Services.jsm");
     1.9 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.10 +
    1.11 +function shouldHaveChanged(a, b)
    1.12 +{
    1.13 +  if (a.length != b.length) {
    1.14 +    throw Error("TEST-UNEXPECTED-FAIL: telemetry count array size changed");
    1.15 +  }
    1.16 +
    1.17 +  for (let i = 0; i < a.length; ++i) {
    1.18 +    if (a[i] == b[i]) {
    1.19 +      continue;
    1.20 +    }
    1.21 +    return; // something was different, that's all that matters
    1.22 +  }
    1.23 +  throw Error("TEST-UNEXPECTED-FAIL: telemetry data didn't change");
    1.24 +}
    1.25 +
    1.26 +function TestStartupCacheTelemetry() { }
    1.27 +
    1.28 +TestStartupCacheTelemetry.prototype = {
    1.29 +  classID: Components.ID("{73cbeffd-d6c7-42f0-aaf3-f176430dcfc8}"),
    1.30 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
    1.31 +
    1.32 +  saveInitial: function() {
    1.33 +    let t = Services.telemetry;
    1.34 +    this._age = t.getHistogramById("STARTUP_CACHE_AGE_HOURS").snapshot.counts;
    1.35 +    this._invalid = t.getHistogramById("STARTUP_CACHE_INVALID").snapshot.counts;
    1.36 +  },
    1.37 +
    1.38 +  checkFinal: function() {
    1.39 +    let t = Services.telemetry;
    1.40 +    let newAge = t.getHistogramById("STARTUP_CACHE_AGE_HOURS").snapshot.counts;
    1.41 +    shouldHaveChanged(this._age, newAge);
    1.42 +
    1.43 +    let newInvalid = t.getHistogramById("STARTUP_CACHE_INVALID").snapshot.counts;
    1.44 +    shouldHaveChanged(this._invalid, newInvalid);
    1.45 +  },
    1.46 +
    1.47 +  observe: function(subject, topic, data) {
    1.48 +    switch (topic) {
    1.49 +    case "save-initial":
    1.50 +      this.saveInitial();
    1.51 +      break;
    1.52 +
    1.53 +    case "check-final":
    1.54 +      this.checkFinal();
    1.55 +      break;
    1.56 +
    1.57 +    default:
    1.58 +      throw Error("BADDOG, NO MILKBONE FOR YOU");
    1.59 +    }
    1.60 +  },
    1.61 +};
    1.62 +
    1.63 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestStartupCacheTelemetry]);

mercurial