Sat, 03 Jan 2015 20:18:00 +0100
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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | let SocialService = Components.utils.import("resource://gre/modules/SocialService.jsm", {}).SocialService; |
michael@0 | 6 | |
michael@0 | 7 | // A helper to run a suite of tests. |
michael@0 | 8 | // The "test object" should be an object with function names as keys and a |
michael@0 | 9 | // function as the value. The functions will be called with a "cbnext" param |
michael@0 | 10 | // which should be called when the test is complete. |
michael@0 | 11 | // eg: |
michael@0 | 12 | // test = { |
michael@0 | 13 | // foo: function(cbnext) {... cbnext();} |
michael@0 | 14 | // } |
michael@0 | 15 | function runTests(tests, cbPreTest, cbPostTest, cbFinish) { |
michael@0 | 16 | let testIter = Iterator(tests); |
michael@0 | 17 | |
michael@0 | 18 | if (cbPreTest === undefined) { |
michael@0 | 19 | cbPreTest = function(cb) {cb()}; |
michael@0 | 20 | } |
michael@0 | 21 | if (cbPostTest === undefined) { |
michael@0 | 22 | cbPostTest = function(cb) {cb()}; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | function runNextTest() { |
michael@0 | 26 | let name, func; |
michael@0 | 27 | try { |
michael@0 | 28 | [name, func] = testIter.next(); |
michael@0 | 29 | } catch (err if err instanceof StopIteration) { |
michael@0 | 30 | // out of items: |
michael@0 | 31 | (cbFinish || finish)(); |
michael@0 | 32 | return; |
michael@0 | 33 | } |
michael@0 | 34 | // We run on a timeout as the frameworker also makes use of timeouts, so |
michael@0 | 35 | // this helps keep the debug messages sane. |
michael@0 | 36 | executeSoon(function() { |
michael@0 | 37 | function cleanupAndRunNextTest() { |
michael@0 | 38 | info("sub-test " + name + " complete"); |
michael@0 | 39 | cbPostTest(runNextTest); |
michael@0 | 40 | } |
michael@0 | 41 | cbPreTest(function() { |
michael@0 | 42 | info("sub-test " + name + " starting"); |
michael@0 | 43 | try { |
michael@0 | 44 | func.call(tests, cleanupAndRunNextTest); |
michael@0 | 45 | } catch (ex) { |
michael@0 | 46 | ok(false, "sub-test " + name + " failed: " + ex.toString() +"\n"+ex.stack); |
michael@0 | 47 | cleanupAndRunNextTest(); |
michael@0 | 48 | } |
michael@0 | 49 | }) |
michael@0 | 50 | }); |
michael@0 | 51 | } |
michael@0 | 52 | runNextTest(); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | // A mock notifications server. Based on: |
michael@0 | 56 | // dom/tests/mochitest/notification/notification_common.js |
michael@0 | 57 | const FAKE_CID = Cc["@mozilla.org/uuid-generator;1"]. |
michael@0 | 58 | getService(Ci.nsIUUIDGenerator).generateUUID(); |
michael@0 | 59 | |
michael@0 | 60 | const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1"; |
michael@0 | 61 | const ALERTS_SERVICE_CID = Components.ID(Cc[ALERTS_SERVICE_CONTRACT_ID].number); |
michael@0 | 62 | |
michael@0 | 63 | function MockAlertsService() {} |
michael@0 | 64 | |
michael@0 | 65 | MockAlertsService.prototype = { |
michael@0 | 66 | |
michael@0 | 67 | showAlertNotification: function(imageUrl, title, text, textClickable, |
michael@0 | 68 | cookie, alertListener, name) { |
michael@0 | 69 | let obData = JSON.stringify({ |
michael@0 | 70 | imageUrl: imageUrl, |
michael@0 | 71 | title: title, |
michael@0 | 72 | text:text, |
michael@0 | 73 | textClickable: textClickable, |
michael@0 | 74 | cookie: cookie, |
michael@0 | 75 | name: name |
michael@0 | 76 | }); |
michael@0 | 77 | Services.obs.notifyObservers(null, "social-test:notification-alert", obData); |
michael@0 | 78 | |
michael@0 | 79 | if (textClickable) { |
michael@0 | 80 | // probably should do this async.... |
michael@0 | 81 | alertListener.observe(null, "alertclickcallback", cookie); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | alertListener.observe(null, "alertfinished", cookie); |
michael@0 | 85 | }, |
michael@0 | 86 | |
michael@0 | 87 | QueryInterface: function(aIID) { |
michael@0 | 88 | if (aIID.equals(Ci.nsISupports) || |
michael@0 | 89 | aIID.equals(Ci.nsIAlertsService)) |
michael@0 | 90 | return this; |
michael@0 | 91 | throw Cr.NS_ERROR_NO_INTERFACE; |
michael@0 | 92 | } |
michael@0 | 93 | }; |
michael@0 | 94 | |
michael@0 | 95 | var factory = { |
michael@0 | 96 | createInstance: function(aOuter, aIID) { |
michael@0 | 97 | if (aOuter != null) |
michael@0 | 98 | throw Cr.NS_ERROR_NO_AGGREGATION; |
michael@0 | 99 | return new MockAlertsService().QueryInterface(aIID); |
michael@0 | 100 | } |
michael@0 | 101 | }; |
michael@0 | 102 | |
michael@0 | 103 | function replaceAlertsService() { |
michael@0 | 104 | Components.manager.QueryInterface(Ci.nsIComponentRegistrar) |
michael@0 | 105 | .registerFactory(FAKE_CID, "", |
michael@0 | 106 | ALERTS_SERVICE_CONTRACT_ID, |
michael@0 | 107 | factory) |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | function restoreAlertsService() { |
michael@0 | 111 | Components.manager.QueryInterface(Ci.nsIComponentRegistrar) |
michael@0 | 112 | .registerFactory(ALERTS_SERVICE_CID, "", |
michael@0 | 113 | ALERTS_SERVICE_CONTRACT_ID, |
michael@0 | 114 | null); |
michael@0 | 115 | } |
michael@0 | 116 | // end of alerts service mock. |