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.

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

mercurial