startupcache/test/TestStartupCacheTelemetry.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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