startupcache/test/TestStartupCacheTelemetry.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 const Cc = Components.classes;
     2 const Ci = Components.interfaces;
     3 const Cu = Components.utils;
     5 Cu.import("resource://gre/modules/Services.jsm");
     6 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
     8 function shouldHaveChanged(a, b)
     9 {
    10   if (a.length != b.length) {
    11     throw Error("TEST-UNEXPECTED-FAIL: telemetry count array size changed");
    12   }
    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 }
    23 function TestStartupCacheTelemetry() { }
    25 TestStartupCacheTelemetry.prototype = {
    26   classID: Components.ID("{73cbeffd-d6c7-42f0-aaf3-f176430dcfc8}"),
    27   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
    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   },
    35   checkFinal: function() {
    36     let t = Services.telemetry;
    37     let newAge = t.getHistogramById("STARTUP_CACHE_AGE_HOURS").snapshot.counts;
    38     shouldHaveChanged(this._age, newAge);
    40     let newInvalid = t.getHistogramById("STARTUP_CACHE_INVALID").snapshot.counts;
    41     shouldHaveChanged(this._invalid, newInvalid);
    42   },
    44   observe: function(subject, topic, data) {
    45     switch (topic) {
    46     case "save-initial":
    47       this.saveInitial();
    48       break;
    50     case "check-final":
    51       this.checkFinal();
    52       break;
    54     default:
    55       throw Error("BADDOG, NO MILKBONE FOR YOU");
    56     }
    57   },
    58 };
    60 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([TestStartupCacheTelemetry]);

mercurial