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 | // This file tests features made available to the frameworker via the sandbox. |
michael@0 | 6 | // For other frameworker tests, see browser_frameworker.js |
michael@0 | 7 | |
michael@0 | 8 | function makeWorkerUrl(runner) { |
michael@0 | 9 | let prefix = "http://example.com/browser/toolkit/components/social/test/browser/echo.sjs?"; |
michael@0 | 10 | if (typeof runner == "function") { |
michael@0 | 11 | runner = "var run=" + runner.toSource() + ";run();"; |
michael@0 | 12 | } |
michael@0 | 13 | return prefix + encodeURI(runner); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | var getFrameWorkerHandle; |
michael@0 | 17 | function test() { |
michael@0 | 18 | waitForExplicitFinish(); |
michael@0 | 19 | |
michael@0 | 20 | let scope = {}; |
michael@0 | 21 | Cu.import("resource://gre/modules/FrameWorker.jsm", scope); |
michael@0 | 22 | getFrameWorkerHandle = scope.getFrameWorkerHandle; |
michael@0 | 23 | |
michael@0 | 24 | runTests(tests); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | let tests = { |
michael@0 | 28 | testArrayUsingBuffer: function(cbnext) { |
michael@0 | 29 | let run = function() { |
michael@0 | 30 | onconnect = function(e) { |
michael@0 | 31 | let port = e.ports[0]; |
michael@0 | 32 | port.onmessage = function(e) { |
michael@0 | 33 | if (e.data.topic == "go") { |
michael@0 | 34 | let buffer = new ArrayBuffer(10); |
michael@0 | 35 | // this one has always worked in the past, but worth checking anyway... |
michael@0 | 36 | if (new Uint8Array(buffer).length != 10) { |
michael@0 | 37 | port.postMessage({topic: "result", reason: "first length was not 10"}); |
michael@0 | 38 | return; |
michael@0 | 39 | } |
michael@0 | 40 | let reader = new FileReader(); |
michael@0 | 41 | reader.onload = function(event) { |
michael@0 | 42 | if (new Uint8Array(buffer).length != 10) { |
michael@0 | 43 | port.postMessage({topic: "result", reason: "length in onload handler was not 10"}); |
michael@0 | 44 | return; |
michael@0 | 45 | } |
michael@0 | 46 | // all seems good! |
michael@0 | 47 | port.postMessage({topic: "result", reason: "ok"}); |
michael@0 | 48 | } |
michael@0 | 49 | let blob = new Blob([buffer], {type: "binary"}); |
michael@0 | 50 | reader.readAsArrayBuffer(blob); |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | let worker = getFrameWorkerHandle(makeWorkerUrl(run), undefined, "testArray"); |
michael@0 | 56 | worker.port.onmessage = function(e) { |
michael@0 | 57 | if (e.data.topic == "result") { |
michael@0 | 58 | is(e.data.reason, "ok", "check the array worked"); |
michael@0 | 59 | worker.terminate(); |
michael@0 | 60 | cbnext(); |
michael@0 | 61 | } |
michael@0 | 62 | } |
michael@0 | 63 | worker.port.postMessage({topic: "go"}); |
michael@0 | 64 | }, |
michael@0 | 65 | |
michael@0 | 66 | testArrayUsingReader: function(cbnext) { |
michael@0 | 67 | let run = function() { |
michael@0 | 68 | onconnect = function(e) { |
michael@0 | 69 | let port = e.ports[0]; |
michael@0 | 70 | port.onmessage = function(e) { |
michael@0 | 71 | if (e.data.topic == "go") { |
michael@0 | 72 | let buffer = new ArrayBuffer(10); |
michael@0 | 73 | let reader = new FileReader(); |
michael@0 | 74 | reader.onload = function(event) { |
michael@0 | 75 | try { |
michael@0 | 76 | if (new Uint8Array(reader.result).length != 10) { |
michael@0 | 77 | port.postMessage({topic: "result", reason: "length in onload handler was not 10"}); |
michael@0 | 78 | return; |
michael@0 | 79 | } |
michael@0 | 80 | // all seems good! |
michael@0 | 81 | port.postMessage({topic: "result", reason: "ok"}); |
michael@0 | 82 | } catch (ex) { |
michael@0 | 83 | port.postMessage({topic: "result", reason: ex.toString()}); |
michael@0 | 84 | } |
michael@0 | 85 | } |
michael@0 | 86 | let blob = new Blob([buffer], {type: "binary"}); |
michael@0 | 87 | reader.readAsArrayBuffer(blob); |
michael@0 | 88 | } |
michael@0 | 89 | } |
michael@0 | 90 | } |
michael@0 | 91 | } |
michael@0 | 92 | let worker = getFrameWorkerHandle(makeWorkerUrl(run), undefined, "testArray"); |
michael@0 | 93 | worker.port.onmessage = function(e) { |
michael@0 | 94 | if (e.data.topic == "result") { |
michael@0 | 95 | is(e.data.reason, "ok", "check the array worked"); |
michael@0 | 96 | worker.terminate(); |
michael@0 | 97 | cbnext(); |
michael@0 | 98 | } |
michael@0 | 99 | } |
michael@0 | 100 | worker.port.postMessage({topic: "go"}); |
michael@0 | 101 | }, |
michael@0 | 102 | |
michael@0 | 103 | testXHR: function(cbnext) { |
michael@0 | 104 | // NOTE: this url MUST be in the same origin as worker_xhr.js fetches from! |
michael@0 | 105 | let url = "https://example.com/browser/toolkit/components/social/test/browser/worker_xhr.js"; |
michael@0 | 106 | let worker = getFrameWorkerHandle(url, undefined, "testXHR"); |
michael@0 | 107 | worker.port.onmessage = function(e) { |
michael@0 | 108 | if (e.data.topic == "done") { |
michael@0 | 109 | is(e.data.result, "ok", "check the xhr test worked"); |
michael@0 | 110 | worker.terminate(); |
michael@0 | 111 | cbnext(); |
michael@0 | 112 | } |
michael@0 | 113 | } |
michael@0 | 114 | }, |
michael@0 | 115 | |
michael@0 | 116 | testLocalStorage: function(cbnext) { |
michael@0 | 117 | let run = function() { |
michael@0 | 118 | onconnect = function(e) { |
michael@0 | 119 | let port = e.ports[0]; |
michael@0 | 120 | try { |
michael@0 | 121 | localStorage.setItem("foo", "1"); |
michael@0 | 122 | } catch(e) { |
michael@0 | 123 | port.postMessage({topic: "done", result: "FAILED to set localStorage, " + e.toString() }); |
michael@0 | 124 | return; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | var ok; |
michael@0 | 128 | try { |
michael@0 | 129 | ok = localStorage["foo"] == 1; |
michael@0 | 130 | } catch (e) { |
michael@0 | 131 | port.postMessage({topic: "done", result: "FAILED to read localStorage, " + e.toString() }); |
michael@0 | 132 | return; |
michael@0 | 133 | } |
michael@0 | 134 | port.postMessage({topic: "done", result: "ok"}); |
michael@0 | 135 | } |
michael@0 | 136 | } |
michael@0 | 137 | let worker = getFrameWorkerHandle(makeWorkerUrl(run), undefined, "testLocalStorage", null, true); |
michael@0 | 138 | worker.port.onmessage = function(e) { |
michael@0 | 139 | if (e.data.topic == "done") { |
michael@0 | 140 | is(e.data.result, "ok", "check the localStorage test worked"); |
michael@0 | 141 | worker.terminate(); |
michael@0 | 142 | cbnext(); |
michael@0 | 143 | } |
michael@0 | 144 | } |
michael@0 | 145 | }, |
michael@0 | 146 | |
michael@0 | 147 | testNoLocalStorage: function(cbnext) { |
michael@0 | 148 | let run = function() { |
michael@0 | 149 | onconnect = function(e) { |
michael@0 | 150 | let port = e.ports[0]; |
michael@0 | 151 | try { |
michael@0 | 152 | localStorage.setItem("foo", "1"); |
michael@0 | 153 | } catch(e) { |
michael@0 | 154 | port.postMessage({topic: "done", result: "ok"}); |
michael@0 | 155 | return; |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | port.postMessage({topic: "done", result: "FAILED because localStorage was exposed" }); |
michael@0 | 159 | } |
michael@0 | 160 | } |
michael@0 | 161 | let worker = getFrameWorkerHandle(makeWorkerUrl(run), undefined, "testNoLocalStorage"); |
michael@0 | 162 | worker.port.onmessage = function(e) { |
michael@0 | 163 | if (e.data.topic == "done") { |
michael@0 | 164 | is(e.data.result, "ok", "check that retrieving localStorage fails by default"); |
michael@0 | 165 | worker.terminate(); |
michael@0 | 166 | cbnext(); |
michael@0 | 167 | } |
michael@0 | 168 | } |
michael@0 | 169 | }, |
michael@0 | 170 | |
michael@0 | 171 | testBase64: function (cbnext) { |
michael@0 | 172 | let run = function() { |
michael@0 | 173 | onconnect = function(e) { |
michael@0 | 174 | let port = e.ports[0]; |
michael@0 | 175 | var ok = false; |
michael@0 | 176 | try { |
michael@0 | 177 | ok = btoa("1234") == "MTIzNA=="; |
michael@0 | 178 | } catch(e) { |
michael@0 | 179 | port.postMessage({topic: "done", result: "FAILED to call btoa, " + e.toString() }); |
michael@0 | 180 | return; |
michael@0 | 181 | } |
michael@0 | 182 | if (!ok) { |
michael@0 | 183 | port.postMessage({topic: "done", result: "FAILED calling btoa"}); |
michael@0 | 184 | return; |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | try { |
michael@0 | 188 | ok = atob("NDMyMQ==") == "4321"; |
michael@0 | 189 | } catch (e) { |
michael@0 | 190 | port.postMessage({topic: "done", result: "FAILED to call atob, " + e.toString() }); |
michael@0 | 191 | return; |
michael@0 | 192 | } |
michael@0 | 193 | if (!ok) { |
michael@0 | 194 | port.postMessage({topic: "done", result: "FAILED calling atob"}); |
michael@0 | 195 | return; |
michael@0 | 196 | } |
michael@0 | 197 | |
michael@0 | 198 | port.postMessage({topic: "done", result: "ok"}); |
michael@0 | 199 | } |
michael@0 | 200 | } |
michael@0 | 201 | let worker = getFrameWorkerHandle(makeWorkerUrl(run), undefined, "testBase64"); |
michael@0 | 202 | worker.port.onmessage = function(e) { |
michael@0 | 203 | if (e.data.topic == "done") { |
michael@0 | 204 | is(e.data.result, "ok", "check the atob/btoa test worked"); |
michael@0 | 205 | worker.terminate(); |
michael@0 | 206 | cbnext(); |
michael@0 | 207 | } |
michael@0 | 208 | } |
michael@0 | 209 | }, |
michael@0 | 210 | |
michael@0 | 211 | testTimeouts: function (cbnext) { |
michael@0 | 212 | let run = function() { |
michael@0 | 213 | onconnect = function(e) { |
michael@0 | 214 | let port = e.ports[0]; |
michael@0 | 215 | |
michael@0 | 216 | var timeout; |
michael@0 | 217 | try { |
michael@0 | 218 | timeout = setTimeout(function () { |
michael@0 | 219 | port.postMessage({topic: "done", result: "FAILED cancelled timeout was called"}); |
michael@0 | 220 | }, 100); |
michael@0 | 221 | } catch (ex) { |
michael@0 | 222 | port.postMessage({topic: "done", result: "FAILED calling setTimeout: " + ex}); |
michael@0 | 223 | return; |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | try { |
michael@0 | 227 | clearTimeout(timeout); |
michael@0 | 228 | } catch (ex) { |
michael@0 | 229 | port.postMessage({topic: "done", result: "FAILED calling clearTimeout: " + ex}); |
michael@0 | 230 | return; |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | var counter = 0; |
michael@0 | 234 | try { |
michael@0 | 235 | timeout = setInterval(function () { |
michael@0 | 236 | if (++counter == 2) { |
michael@0 | 237 | clearInterval(timeout); |
michael@0 | 238 | setTimeout(function () { |
michael@0 | 239 | port.postMessage({topic: "done", result: "ok"}); |
michael@0 | 240 | return; |
michael@0 | 241 | }, 0); |
michael@0 | 242 | } |
michael@0 | 243 | }, 100); |
michael@0 | 244 | } catch (ex) { |
michael@0 | 245 | port.postMessage({topic: "done", result: "FAILED calling setInterval: " + ex}); |
michael@0 | 246 | return; |
michael@0 | 247 | } |
michael@0 | 248 | } |
michael@0 | 249 | } |
michael@0 | 250 | let worker = getFrameWorkerHandle(makeWorkerUrl(run), undefined, "testTimeouts"); |
michael@0 | 251 | worker.port.onmessage = function(e) { |
michael@0 | 252 | if (e.data.topic == "done") { |
michael@0 | 253 | is(e.data.result, "ok", "check that timeouts worked"); |
michael@0 | 254 | worker.terminate(); |
michael@0 | 255 | cbnext(); |
michael@0 | 256 | } |
michael@0 | 257 | } |
michael@0 | 258 | }, |
michael@0 | 259 | |
michael@0 | 260 | testWebSocket: function (cbnext) { |
michael@0 | 261 | let run = function() { |
michael@0 | 262 | onconnect = function(e) { |
michael@0 | 263 | let port = e.ports[0]; |
michael@0 | 264 | |
michael@0 | 265 | try { |
michael@0 | 266 | var exampleSocket = new WebSocket("ws://mochi.test:8888/socketserver"); |
michael@0 | 267 | } catch (e) { |
michael@0 | 268 | port.postMessage({topic: "done", result: "FAILED calling WebSocket constructor: " + e}); |
michael@0 | 269 | return; |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | port.postMessage({topic: "done", result: "ok"}); |
michael@0 | 273 | } |
michael@0 | 274 | } |
michael@0 | 275 | let worker = getFrameWorkerHandle(makeWorkerUrl(run), undefined, "testWebSocket"); |
michael@0 | 276 | worker.port.onmessage = function(e) { |
michael@0 | 277 | if (e.data.topic == "done") { |
michael@0 | 278 | is(e.data.result, "ok", "check that websockets worked"); |
michael@0 | 279 | worker.terminate(); |
michael@0 | 280 | cbnext(); |
michael@0 | 281 | } |
michael@0 | 282 | } |
michael@0 | 283 | }, |
michael@0 | 284 | |
michael@0 | 285 | testEventSource: function(cbnext) { |
michael@0 | 286 | let worker = getFrameWorkerHandle("https://example.com/browser/toolkit/components/social/test/browser/worker_eventsource.js", undefined, "testEventSource"); |
michael@0 | 287 | worker.port.onmessage = function(e) { |
michael@0 | 288 | let m = e.data; |
michael@0 | 289 | if (m.topic == "eventSourceTest") { |
michael@0 | 290 | if (m.result.ok != undefined) |
michael@0 | 291 | ok(m.result.ok, e.data.result.msg); |
michael@0 | 292 | if (m.result.is != undefined) |
michael@0 | 293 | is(m.result.is, m.result.match, m.result.msg); |
michael@0 | 294 | if (m.result.info != undefined) |
michael@0 | 295 | info(m.result.info); |
michael@0 | 296 | } else if (e.data.topic == "pong") { |
michael@0 | 297 | worker.terminate(); |
michael@0 | 298 | cbnext(); |
michael@0 | 299 | } |
michael@0 | 300 | } |
michael@0 | 301 | worker.port.postMessage({topic: "ping"}) |
michael@0 | 302 | }, |
michael@0 | 303 | |
michael@0 | 304 | testIndexedDB: function(cbnext) { |
michael@0 | 305 | let worker = getFrameWorkerHandle("https://example.com/browser/toolkit/components/social/test/browser/worker_social.js", undefined, "testIndexedDB"); |
michael@0 | 306 | worker.port.onmessage = function(e) { |
michael@0 | 307 | let m = e.data; |
michael@0 | 308 | if (m.topic == "social.indexeddb-result") { |
michael@0 | 309 | is(m.data.result, "ok", "created indexeddb"); |
michael@0 | 310 | worker.terminate(); |
michael@0 | 311 | cbnext(); |
michael@0 | 312 | } |
michael@0 | 313 | } |
michael@0 | 314 | worker.port.postMessage({topic: "test-indexeddb-create"}) |
michael@0 | 315 | }, |
michael@0 | 316 | |
michael@0 | 317 | testSubworker: function(cbnext) { |
michael@0 | 318 | // the main "frameworker"... |
michael@0 | 319 | let mainworker = function() { |
michael@0 | 320 | onconnect = function(e) { |
michael@0 | 321 | let port = e.ports[0]; |
michael@0 | 322 | port.onmessage = function(e) { |
michael@0 | 323 | if (e.data.topic == "go") { |
michael@0 | 324 | let suburl = e.data.data; |
michael@0 | 325 | let worker = new Worker(suburl); |
michael@0 | 326 | worker.onmessage = function(sube) { |
michael@0 | 327 | port.postMessage({topic: "sub-message", data: sube.data}); |
michael@0 | 328 | } |
michael@0 | 329 | } |
michael@0 | 330 | } |
michael@0 | 331 | } |
michael@0 | 332 | } |
michael@0 | 333 | |
michael@0 | 334 | // The "subworker" that is actually a real, bona-fide worker. |
michael@0 | 335 | let subworker = function() { |
michael@0 | 336 | postMessage("hello"); |
michael@0 | 337 | } |
michael@0 | 338 | let worker = getFrameWorkerHandle(makeWorkerUrl(mainworker), undefined, "testSubWorker"); |
michael@0 | 339 | worker.port.onmessage = function(e) { |
michael@0 | 340 | if (e.data.topic == "sub-message" && e.data.data == "hello") { |
michael@0 | 341 | worker.terminate(); |
michael@0 | 342 | cbnext(); |
michael@0 | 343 | } |
michael@0 | 344 | } |
michael@0 | 345 | worker.port.postMessage({topic: "go", data: makeWorkerUrl(subworker)}); |
michael@0 | 346 | } |
michael@0 | 347 | } |