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 | 'use strict'; |
michael@0 | 6 | |
michael@0 | 7 | module.metadata = { |
michael@0 | 8 | 'engines': { |
michael@0 | 9 | 'Firefox': '*' |
michael@0 | 10 | } |
michael@0 | 11 | }; |
michael@0 | 12 | |
michael@0 | 13 | const { Cc, Ci, Cu } = require('chrome'); |
michael@0 | 14 | const { getFavicon } = require('sdk/places/favicon'); |
michael@0 | 15 | const tabs = require('sdk/tabs'); |
michael@0 | 16 | const open = tabs.open; |
michael@0 | 17 | const port = 8099; |
michael@0 | 18 | const host = 'http://localhost:' + port; |
michael@0 | 19 | const { onFaviconChange, serve, binFavicon } = require('../favicon-helpers'); |
michael@0 | 20 | const { once } = require('sdk/system/events'); |
michael@0 | 21 | const { defer } = require('sdk/core/promise'); |
michael@0 | 22 | const { resetPlaces } = require('../places-helper'); |
michael@0 | 23 | const faviconService = Cc["@mozilla.org/browser/favicon-service;1"]. |
michael@0 | 24 | getService(Ci.nsIFaviconService); |
michael@0 | 25 | |
michael@0 | 26 | exports.testStringGetFaviconCallbackSuccess = function (assert, done) { |
michael@0 | 27 | let name = 'callbacksuccess' |
michael@0 | 28 | let srv = makeServer(name); |
michael@0 | 29 | let url = host + '/' + name + '.html'; |
michael@0 | 30 | let favicon = host + '/' + name + '.ico'; |
michael@0 | 31 | let tab; |
michael@0 | 32 | |
michael@0 | 33 | onFaviconChange(url, function (faviconUrl) { |
michael@0 | 34 | getFavicon(url, function (url) { |
michael@0 | 35 | assert.equal(favicon, url, 'Callback returns correct favicon url'); |
michael@0 | 36 | complete(tab, srv, done); |
michael@0 | 37 | }); |
michael@0 | 38 | }); |
michael@0 | 39 | |
michael@0 | 40 | open({ |
michael@0 | 41 | url: url, |
michael@0 | 42 | onOpen: function (newTab) tab = newTab, |
michael@0 | 43 | inBackground: true |
michael@0 | 44 | }); |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | exports.testStringGetFaviconCallbackFailure = function (assert, done) { |
michael@0 | 48 | let name = 'callbackfailure'; |
michael@0 | 49 | let srv = makeServer(name); |
michael@0 | 50 | let url = host + '/' + name + '.html'; |
michael@0 | 51 | let tab; |
michael@0 | 52 | |
michael@0 | 53 | waitAndExpire(url).then(function () { |
michael@0 | 54 | getFavicon(url, function (url) { |
michael@0 | 55 | assert.equal(url, null, 'Callback returns null'); |
michael@0 | 56 | complete(tab, srv, done); |
michael@0 | 57 | }); |
michael@0 | 58 | }); |
michael@0 | 59 | |
michael@0 | 60 | open({ |
michael@0 | 61 | url: url, |
michael@0 | 62 | onOpen: function (newTab) tab = newTab, |
michael@0 | 63 | inBackground: true |
michael@0 | 64 | }); |
michael@0 | 65 | }; |
michael@0 | 66 | |
michael@0 | 67 | exports.testStringGetFaviconPromiseSuccess = function (assert, done) { |
michael@0 | 68 | let name = 'promisesuccess' |
michael@0 | 69 | let srv = makeServer(name); |
michael@0 | 70 | let url = host + '/' + name + '.html'; |
michael@0 | 71 | let favicon = host + '/' + name + '.ico'; |
michael@0 | 72 | let tab; |
michael@0 | 73 | |
michael@0 | 74 | onFaviconChange(url, function (faviconUrl) { |
michael@0 | 75 | getFavicon(url).then(function (url) { |
michael@0 | 76 | assert.equal(url, favicon, 'Callback returns null'); |
michael@0 | 77 | }, function (err) { |
michael@0 | 78 | assert.fail('Reject should not be called'); |
michael@0 | 79 | }).then(complete.bind(null, tab, srv, done)); |
michael@0 | 80 | }); |
michael@0 | 81 | |
michael@0 | 82 | open({ |
michael@0 | 83 | url: url, |
michael@0 | 84 | onOpen: function (newTab) tab = newTab, |
michael@0 | 85 | inBackground: true |
michael@0 | 86 | }); |
michael@0 | 87 | }; |
michael@0 | 88 | |
michael@0 | 89 | exports.testStringGetFaviconPromiseFailure = function (assert, done) { |
michael@0 | 90 | let name = 'promisefailure' |
michael@0 | 91 | let srv = makeServer(name); |
michael@0 | 92 | let url = host + '/' + name + '.html'; |
michael@0 | 93 | let tab; |
michael@0 | 94 | |
michael@0 | 95 | waitAndExpire(url).then(function () { |
michael@0 | 96 | getFavicon(url).then(invalidResolve(assert), validReject(assert, 'expired url')) |
michael@0 | 97 | .then(complete.bind(null, tab, srv, done)); |
michael@0 | 98 | }); |
michael@0 | 99 | |
michael@0 | 100 | open({ |
michael@0 | 101 | url: url, |
michael@0 | 102 | onOpen: function (newTab) tab = newTab, |
michael@0 | 103 | inBackground: true |
michael@0 | 104 | }); |
michael@0 | 105 | }; |
michael@0 | 106 | |
michael@0 | 107 | exports.testTabsGetFaviconPromiseSuccess = function (assert, done) { |
michael@0 | 108 | let name = 'tabs-success' |
michael@0 | 109 | let srv = makeServer(name); |
michael@0 | 110 | let url = host + '/' + name + '.html'; |
michael@0 | 111 | let favicon = host + '/' + name + '.ico'; |
michael@0 | 112 | let tab; |
michael@0 | 113 | |
michael@0 | 114 | onFaviconChange(url, function () { |
michael@0 | 115 | getFavicon(tab).then(function (url) { |
michael@0 | 116 | assert.equal(url, favicon, "getFavicon should return url for tab"); |
michael@0 | 117 | complete(tab, srv, done); |
michael@0 | 118 | }); |
michael@0 | 119 | }); |
michael@0 | 120 | |
michael@0 | 121 | open({ |
michael@0 | 122 | url: url, |
michael@0 | 123 | onOpen: function (newTab) tab = newTab, |
michael@0 | 124 | inBackground: true |
michael@0 | 125 | }); |
michael@0 | 126 | }; |
michael@0 | 127 | |
michael@0 | 128 | |
michael@0 | 129 | exports.testTabsGetFaviconPromiseFailure = function (assert, done) { |
michael@0 | 130 | let name = 'tabs-failure' |
michael@0 | 131 | let srv = makeServer(name); |
michael@0 | 132 | let url = host + '/' + name + '.html'; |
michael@0 | 133 | let tab; |
michael@0 | 134 | |
michael@0 | 135 | waitAndExpire(url).then(function () { |
michael@0 | 136 | getFavicon(tab).then(invalidResolve(assert), validReject(assert, 'expired tab')) |
michael@0 | 137 | .then(complete.bind(null, tab, srv, done)); |
michael@0 | 138 | }); |
michael@0 | 139 | |
michael@0 | 140 | open({ |
michael@0 | 141 | url: url, |
michael@0 | 142 | onOpen: function (newTab) tab = newTab, |
michael@0 | 143 | inBackground: true |
michael@0 | 144 | }); |
michael@0 | 145 | }; |
michael@0 | 146 | |
michael@0 | 147 | exports.testRejects = function (assert, done) { |
michael@0 | 148 | getFavicon({}) |
michael@0 | 149 | .then(invalidResolve(assert), validReject(assert, 'Object')) |
michael@0 | 150 | .then(() => getFavicon(null)) |
michael@0 | 151 | .then(invalidResolve(assert), validReject(assert, 'null')) |
michael@0 | 152 | .then(() => getFavicon(undefined)) |
michael@0 | 153 | .then(invalidResolve(assert), validReject(assert, 'undefined')) |
michael@0 | 154 | .then(() => getFavicon([])) |
michael@0 | 155 | .then(invalidResolve(assert), validReject(assert, 'Array')) |
michael@0 | 156 | .catch(assert.fail).then(done); |
michael@0 | 157 | }; |
michael@0 | 158 | |
michael@0 | 159 | function invalidResolve (assert) { |
michael@0 | 160 | return function () assert.fail('Promise should not be resolved successfully'); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | function validReject (assert, name) { |
michael@0 | 164 | return function () assert.pass(name + ' correctly rejected'); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | function makeServer (name) { |
michael@0 | 168 | return serve({name: name, favicon: binFavicon, port: port, host: host}); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | function waitAndExpire (url) { |
michael@0 | 172 | let deferred = defer(); |
michael@0 | 173 | onFaviconChange(url, function (faviconUrl) { |
michael@0 | 174 | once('places-favicons-expired', function () { |
michael@0 | 175 | deferred.resolve(); |
michael@0 | 176 | }); |
michael@0 | 177 | faviconService.expireAllFavicons(); |
michael@0 | 178 | }); |
michael@0 | 179 | return deferred.promise; |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | function complete(tab, srv, done) { |
michael@0 | 183 | tab.close(function () { |
michael@0 | 184 | resetPlaces(() => { |
michael@0 | 185 | srv.stop(done); |
michael@0 | 186 | }); |
michael@0 | 187 | }); |
michael@0 | 188 | } |