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 file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; |
michael@0 | 6 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 7 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 8 | |
michael@0 | 9 | XPCOMUtils.defineLazyModuleGetter(this, "Promise", |
michael@0 | 10 | "resource://gre/modules/Promise.jsm"); |
michael@0 | 11 | XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", |
michael@0 | 12 | "resource://gre/modules/PlacesUtils.jsm"); |
michael@0 | 13 | |
michael@0 | 14 | const MANIFEST_PREFS = Services.prefs.getBranch("social.manifest."); |
michael@0 | 15 | const gProfD = do_get_profile(); |
michael@0 | 16 | |
michael@0 | 17 | const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1"; |
michael@0 | 18 | const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}"); |
michael@0 | 19 | |
michael@0 | 20 | function createAppInfo(id, name, version, platformVersion) { |
michael@0 | 21 | gAppInfo = { |
michael@0 | 22 | // nsIXULAppInfo |
michael@0 | 23 | vendor: "Mozilla", |
michael@0 | 24 | name: name, |
michael@0 | 25 | ID: id, |
michael@0 | 26 | version: version, |
michael@0 | 27 | appBuildID: "2007010101", |
michael@0 | 28 | platformVersion: platformVersion ? platformVersion : "1.0", |
michael@0 | 29 | platformBuildID: "2007010101", |
michael@0 | 30 | |
michael@0 | 31 | // nsIXULRuntime |
michael@0 | 32 | inSafeMode: false, |
michael@0 | 33 | logConsoleErrors: true, |
michael@0 | 34 | OS: "XPCShell", |
michael@0 | 35 | XPCOMABI: "noarch-spidermonkey", |
michael@0 | 36 | invalidateCachesOnRestart: function invalidateCachesOnRestart() { |
michael@0 | 37 | // Do nothing |
michael@0 | 38 | }, |
michael@0 | 39 | |
michael@0 | 40 | // nsICrashReporter |
michael@0 | 41 | annotations: {}, |
michael@0 | 42 | |
michael@0 | 43 | annotateCrashReport: function(key, data) { |
michael@0 | 44 | this.annotations[key] = data; |
michael@0 | 45 | }, |
michael@0 | 46 | |
michael@0 | 47 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, |
michael@0 | 48 | Ci.nsIXULRuntime, |
michael@0 | 49 | Ci.nsICrashReporter, |
michael@0 | 50 | Ci.nsISupports]) |
michael@0 | 51 | }; |
michael@0 | 52 | |
michael@0 | 53 | var XULAppInfoFactory = { |
michael@0 | 54 | createInstance: function (outer, iid) { |
michael@0 | 55 | if (outer != null) |
michael@0 | 56 | throw Components.results.NS_ERROR_NO_AGGREGATION; |
michael@0 | 57 | return gAppInfo.QueryInterface(iid); |
michael@0 | 58 | } |
michael@0 | 59 | }; |
michael@0 | 60 | var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
michael@0 | 61 | registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo", |
michael@0 | 62 | XULAPPINFO_CONTRACTID, XULAppInfoFactory); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | function initApp() { |
michael@0 | 66 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); |
michael@0 | 67 | // prepare a blocklist file for the blocklist service |
michael@0 | 68 | var blocklistFile = gProfD.clone(); |
michael@0 | 69 | blocklistFile.append("blocklist.xml"); |
michael@0 | 70 | if (blocklistFile.exists()) |
michael@0 | 71 | blocklistFile.remove(false); |
michael@0 | 72 | var source = do_get_file("blocklist.xml"); |
michael@0 | 73 | source.copyTo(gProfD, "blocklist.xml"); |
michael@0 | 74 | blocklistFile.lastModifiedTime = Date.now(); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function AsyncRunner() { |
michael@0 | 78 | do_test_pending(); |
michael@0 | 79 | do_register_cleanup((function () this.destroy()).bind(this)); |
michael@0 | 80 | |
michael@0 | 81 | this._callbacks = { |
michael@0 | 82 | done: do_test_finished, |
michael@0 | 83 | error: function (err) { |
michael@0 | 84 | // xpcshell test functions like do_check_eq throw NS_ERROR_ABORT on |
michael@0 | 85 | // failure. Ignore those so they aren't rethrown here. |
michael@0 | 86 | if (err !== Cr.NS_ERROR_ABORT) { |
michael@0 | 87 | if (err.stack) { |
michael@0 | 88 | err = err + " - See following stack:\n" + err.stack + |
michael@0 | 89 | "\nUseless do_throw stack"; |
michael@0 | 90 | } |
michael@0 | 91 | do_throw(err); |
michael@0 | 92 | } |
michael@0 | 93 | }, |
michael@0 | 94 | consoleError: function (scriptErr) { |
michael@0 | 95 | // Try to ensure the error is related to the test. |
michael@0 | 96 | let filename = scriptErr.sourceName || scriptErr.toString() || ""; |
michael@0 | 97 | if (filename.indexOf("/toolkit/components/social/") >= 0) |
michael@0 | 98 | do_throw(scriptErr); |
michael@0 | 99 | }, |
michael@0 | 100 | }; |
michael@0 | 101 | this._iteratorQueue = []; |
michael@0 | 102 | |
michael@0 | 103 | // This catches errors reported to the console, e.g., via Cu.reportError, but |
michael@0 | 104 | // not on the runner's stack. |
michael@0 | 105 | Cc["@mozilla.org/consoleservice;1"]. |
michael@0 | 106 | getService(Ci.nsIConsoleService). |
michael@0 | 107 | registerListener(this); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | AsyncRunner.prototype = { |
michael@0 | 111 | |
michael@0 | 112 | appendIterator: function appendIterator(iter) { |
michael@0 | 113 | this._iteratorQueue.push(iter); |
michael@0 | 114 | }, |
michael@0 | 115 | |
michael@0 | 116 | next: function next(/* ... */) { |
michael@0 | 117 | if (!this._iteratorQueue.length) { |
michael@0 | 118 | this.destroy(); |
michael@0 | 119 | this._callbacks.done(); |
michael@0 | 120 | return; |
michael@0 | 121 | } |
michael@0 | 122 | |
michael@0 | 123 | // send() discards all arguments after the first, so there's no choice here |
michael@0 | 124 | // but to send only one argument to the yielder. |
michael@0 | 125 | let args = [arguments.length <= 1 ? arguments[0] : Array.slice(arguments)]; |
michael@0 | 126 | try { |
michael@0 | 127 | var val = this._iteratorQueue[0].send.apply(this._iteratorQueue[0], args); |
michael@0 | 128 | } |
michael@0 | 129 | catch (err if err instanceof StopIteration) { |
michael@0 | 130 | this._iteratorQueue.shift(); |
michael@0 | 131 | this.next(); |
michael@0 | 132 | return; |
michael@0 | 133 | } |
michael@0 | 134 | catch (err) { |
michael@0 | 135 | this._callbacks.error(err); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | // val is an iterator => prepend it to the queue and start on it |
michael@0 | 139 | // val is otherwise truthy => call next |
michael@0 | 140 | if (val) { |
michael@0 | 141 | if (typeof(val) != "boolean") |
michael@0 | 142 | this._iteratorQueue.unshift(val); |
michael@0 | 143 | this.next(); |
michael@0 | 144 | } |
michael@0 | 145 | }, |
michael@0 | 146 | |
michael@0 | 147 | destroy: function destroy() { |
michael@0 | 148 | Cc["@mozilla.org/consoleservice;1"]. |
michael@0 | 149 | getService(Ci.nsIConsoleService). |
michael@0 | 150 | unregisterListener(this); |
michael@0 | 151 | this.destroy = function alreadyDestroyed() {}; |
michael@0 | 152 | }, |
michael@0 | 153 | |
michael@0 | 154 | observe: function observe(msg) { |
michael@0 | 155 | if (msg instanceof Ci.nsIScriptError && |
michael@0 | 156 | !(msg.flags & Ci.nsIScriptError.warningFlag)) |
michael@0 | 157 | { |
michael@0 | 158 | this._callbacks.consoleError(msg); |
michael@0 | 159 | } |
michael@0 | 160 | }, |
michael@0 | 161 | }; |
michael@0 | 162 | |
michael@0 | 163 | |
michael@0 | 164 | function promiseAddVisits(aPlaceInfo) |
michael@0 | 165 | { |
michael@0 | 166 | let deferred = Promise.defer(); |
michael@0 | 167 | let places = []; |
michael@0 | 168 | if (aPlaceInfo instanceof Ci.nsIURI) { |
michael@0 | 169 | places.push({ uri: aPlaceInfo }); |
michael@0 | 170 | } |
michael@0 | 171 | else if (Array.isArray(aPlaceInfo)) { |
michael@0 | 172 | places = places.concat(aPlaceInfo); |
michael@0 | 173 | } else { |
michael@0 | 174 | places.push(aPlaceInfo) |
michael@0 | 175 | } |
michael@0 | 176 | |
michael@0 | 177 | // Create mozIVisitInfo for each entry. |
michael@0 | 178 | let now = Date.now(); |
michael@0 | 179 | for (let i = 0; i < places.length; i++) { |
michael@0 | 180 | if (!places[i].title) { |
michael@0 | 181 | places[i].title = "test visit for " + places[i].uri.spec; |
michael@0 | 182 | } |
michael@0 | 183 | places[i].visits = [{ |
michael@0 | 184 | transitionType: places[i].transition === undefined ? Ci.nsINavHistoryService.TRANSITION_LINK |
michael@0 | 185 | : places[i].transition, |
michael@0 | 186 | visitDate: places[i].visitDate || (now++) * 1000, |
michael@0 | 187 | referrerURI: places[i].referrer |
michael@0 | 188 | }]; |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | PlacesUtils.asyncHistory.updatePlaces( |
michael@0 | 192 | places, |
michael@0 | 193 | { |
michael@0 | 194 | handleError: function handleError(aResultCode, aPlaceInfo) { |
michael@0 | 195 | let ex = new Components.Exception("Unexpected error in adding visits.", |
michael@0 | 196 | aResultCode); |
michael@0 | 197 | deferred.reject(ex); |
michael@0 | 198 | }, |
michael@0 | 199 | handleResult: function () {}, |
michael@0 | 200 | handleCompletion: function handleCompletion() { |
michael@0 | 201 | deferred.resolve(); |
michael@0 | 202 | } |
michael@0 | 203 | } |
michael@0 | 204 | ); |
michael@0 | 205 | |
michael@0 | 206 | return deferred.promise; |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | function promiseTopicObserved(aTopic) |
michael@0 | 210 | { |
michael@0 | 211 | let deferred = Promise.defer(); |
michael@0 | 212 | |
michael@0 | 213 | Services.obs.addObserver( |
michael@0 | 214 | function PTO_observe(aSubject, aTopic, aData) { |
michael@0 | 215 | Services.obs.removeObserver(PTO_observe, aTopic); |
michael@0 | 216 | deferred.resolve([aSubject, aData]); |
michael@0 | 217 | }, aTopic, false); |
michael@0 | 218 | |
michael@0 | 219 | return deferred.promise; |
michael@0 | 220 | } |
michael@0 | 221 | |
michael@0 | 222 | function promiseClearHistory() { |
michael@0 | 223 | let promise = promiseTopicObserved(PlacesUtils.TOPIC_EXPIRATION_FINISHED); |
michael@0 | 224 | do_execute_soon(function() PlacesUtils.bhistory.removeAllPages()); |
michael@0 | 225 | return promise; |
michael@0 | 226 | } |