xpcom/tests/unit/test_bug374754.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;
     4 var addedTopic = "xpcom-category-entry-added";
     5 var removedTopic = "xpcom-category-entry-removed";
     6 var testCategory = "bug-test-category";
     7 var testEntry = "@mozilla.org/bug-test-entry;1";
     9 var testValue= "check validity";
    10 var result = "";
    11 var expected = "add remove add remove ";
    12 var timer;
    14 var observer = {
    15   QueryInterface: function(iid) {
    16     if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIObserver))
    17       return this;
    19     throw Components.results.NS_ERROR_NO_INTERFACE;
    20   },
    22   observe: function(subject, topic, data) {
    23     if (topic == "timer-callback") {
    24       do_check_eq(result, expected);
    26       var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
    27       observerService.removeObserver(this, addedTopic);
    28       observerService.removeObserver(this, removedTopic);
    30       do_test_finished();
    32       timer = null;
    33     }
    35     if (subject.QueryInterface(Ci.nsISupportsCString).data != testEntry || data != testCategory)
    36       return;
    38     if (topic == addedTopic)
    39       result += "add ";
    40     else if (topic == removedTopic)
    41       result += "remove ";
    42   }
    43 };
    45 function run_test() {
    46   do_test_pending();
    48   var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
    49   observerService.addObserver(observer, addedTopic, false);
    50   observerService.addObserver(observer, removedTopic, false);
    52   var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
    53   categoryManager.addCategoryEntry(testCategory, testEntry, testValue, false, true);
    54   categoryManager.addCategoryEntry(testCategory, testEntry, testValue, false, true);
    55   categoryManager.deleteCategoryEntry(testCategory, testEntry, false);
    57   timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
    58   timer.init(observer, 0, timer.TYPE_ONE_SHOT);
    59 }

mercurial