commit eaeb778b28d2f300403a721db8374ea72f8499b6 Author: Arthur Edelstein arthuredelstein@gmail.com Date: Mon Jun 22 16:18:46 2015 -0700
fixup! Bug #15502, Part 2: Regression tests for blob URL isolation --- dom/base/test/bug15502_page_blobify.html | 3 ++- dom/base/test/bug15502_page_deblobify.html | 3 ++- dom/base/test/bug15502_tab.html | 5 +++-- dom/base/test/bug15502_utils.js | 15 +++++++-------- dom/base/test/bug15502_worker_blobify.html | 3 ++- dom/base/test/bug15502_worker_deblobify.html | 3 ++- dom/base/test/test_tor_bug15502.html | 17 ++++++++++++----- 7 files changed, 30 insertions(+), 19 deletions(-)
diff --git a/dom/base/test/bug15502_page_blobify.html b/dom/base/test/bug15502_page_blobify.html index d883929..5d81bec 100644 --- a/dom/base/test/bug15502_page_blobify.html +++ b/dom/base/test/bug15502_page_blobify.html @@ -6,6 +6,7 @@ https://bugs.torproject.org/15502 <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Page blobifier for Tor Browser Bug 15502</title> + <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script> <script type="text/javascript;version=1.7" src="bug15502_utils.js"></script> </head> <body> @@ -13,7 +14,7 @@ https://bugs.torproject.org/15502
<script type="text/javascript;version=1.7">
-Task.spawn(function* () { +spawnTask(function* () { sendMessage(window.parent, "ready"); let message = yield receiveMessage(window.parent), blobURL = stringToBlobURL(message); diff --git a/dom/base/test/bug15502_page_deblobify.html b/dom/base/test/bug15502_page_deblobify.html index e8cbd51..c728c79 100644 --- a/dom/base/test/bug15502_page_deblobify.html +++ b/dom/base/test/bug15502_page_deblobify.html @@ -6,6 +6,7 @@ https://bugs.torproject.org/15502 <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Page deblobifier for Tor Browser Bug 15502</title> + <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script> <script type="text/javascript;version=1.7" src="bug15502_utils.js"></script> </head> <body> @@ -13,7 +14,7 @@ https://bugs.torproject.org/15502
<script type="text/javascript;version=1.7">
-Task.spawn(function* () { +spawnTask(function* () { sendMessage(window.parent, "ready"); let blobURL = yield receiveMessage(window.parent), string; diff --git a/dom/base/test/bug15502_tab.html b/dom/base/test/bug15502_tab.html index 7bd4744..b41274e 100644 --- a/dom/base/test/bug15502_tab.html +++ b/dom/base/test/bug15502_tab.html @@ -6,6 +6,7 @@ https://bugs.torproject.org/15502 <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Tab for Tor Browser Bug 15502</title> + <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script> <script type="text/javascript;version=1.7" src="bug15502_utils.js"></script> </head> <body> @@ -18,7 +19,7 @@ https://bugs.torproject.org/15502 let iframe = document.getElementById("child");
let connect = function (sourceObject, destinationObject) { - Task.spawn(function* () { + spawnTask(function* () { for (;;) { let message = yield receiveMessage(sourceObject); sendMessage(destinationObject, message); @@ -26,7 +27,7 @@ let connect = function (sourceObject, destinationObject) { }); };
-Task.spawn(function* () { +spawnTask(function* () { sendMessage(window.opener, "ready"); let firstParentMessage = yield receiveMessage(window.opener); iframe.src = firstParentMessage; diff --git a/dom/base/test/bug15502_utils.js b/dom/base/test/bug15502_utils.js index 9d69c12..23f61c4 100644 --- a/dom/base/test/bug15502_utils.js +++ b/dom/base/test/bug15502_utils.js @@ -1,11 +1,8 @@ -// Import Task.jsm -let { Task } = SpecialPowers.Cu.import("resource://gre/modules/Task.jsm"); - // __listen(target, eventType, timeoutMs, useCapture)__. // Calls addEventListener on target, with the given eventType. // Returns a Promise that resolves to an Event object, if the event fires. // If a timeout occurs, then Promise is rejected with a "Timed out" error. -// For use with Task.jsm. +// For use with SpawnTask.js. let listen = function (target, eventType, timeoutMs, useCapture) { return new Promise(function (resolve, reject) { let listenFunction = function (event) { @@ -13,17 +10,19 @@ let listen = function (target, eventType, timeoutMs, useCapture) { resolve(event); }; target.addEventListener(eventType, listenFunction, useCapture); - setTimeout(() => reject(new Error("Timed out")), timeoutMs); + if (timeoutMs) { + setTimeout(() => reject(new Error("Timed out")), timeoutMs); + } }); };
// __receiveMessage(source)__. // Returns an event object for the next message received from source. -// A Task.jsm coroutine. +// A SpawnTask.js coroutine. let receiveMessage = function* (source) { let event; do { - event = yield listen(self, "message", 5000, false); + event = yield listen(self, "message", null, false); } while (event.source !== source); return event.data; }; @@ -94,7 +93,7 @@ let stringToBlobURL = function (s) { // __workerIO(scriptFile, inputString)__. // Sends inputString for the worker, and waits // for the worker to return an outputString. -// Task.jsm coroutine. +// SpawnTask.js coroutine. let workerIO = function* (scriptFile, inputString) { let worker = new Worker(scriptFile); worker.postMessage(inputString); diff --git a/dom/base/test/bug15502_worker_blobify.html b/dom/base/test/bug15502_worker_blobify.html index 3dd7926..7084366 100644 --- a/dom/base/test/bug15502_worker_blobify.html +++ b/dom/base/test/bug15502_worker_blobify.html @@ -6,6 +6,7 @@ https://bugs.torproject.org/15502 <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Worker blobifier for Tor Browser Bug 15502</title> + <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script> <script type="text/javascript;version=1.7" src="bug15502_utils.js"></script> </head> <body> @@ -14,7 +15,7 @@ https://bugs.torproject.org/15502 <pre id="test"> <script type="text/javascript;version=1.7">
-Task.spawn(function* () { +spawnTask(function* () { sendMessage(window.parent, "ready"); let message = yield receiveMessage(window.parent), blobURL = yield workerIO("bug15502_worker_blobify.js", message); diff --git a/dom/base/test/bug15502_worker_deblobify.html b/dom/base/test/bug15502_worker_deblobify.html index 30ec6b4..4f498f1 100644 --- a/dom/base/test/bug15502_worker_deblobify.html +++ b/dom/base/test/bug15502_worker_deblobify.html @@ -6,6 +6,7 @@ https://bugs.torproject.org/15502 <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Worker deblobifier for Tor Browser Bug 15502</title> + <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script> <script type="text/javascript;version=1.7" src="bug15502_utils.js"></script> </head> <body> @@ -14,7 +15,7 @@ https://bugs.torproject.org/15502 <pre id="test"> <script type="text/javascript;version=1.7">
-Task.spawn(function* () { +spawnTask(function* () { sendMessage(window.parent, "ready"); let blobURL = yield receiveMessage(window.parent), result = yield workerIO("bug15502_worker_deblobify.js", blobURL); diff --git a/dom/base/test/test_tor_bug15502.html b/dom/base/test/test_tor_bug15502.html index 06bcc1c..18b8459 100644 --- a/dom/base/test/test_tor_bug15502.html +++ b/dom/base/test/test_tor_bug15502.html @@ -7,6 +7,7 @@ https://bugs.torproject.org/15502 <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>Test for Tor Browser Bug 15502</title> <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script> <script type="text/javascript;version=1.7" src="bug15502_utils.js"></script> <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> </head> @@ -17,8 +18,14 @@ https://bugs.torproject.org/15502 <script class="testbody" type="application/javascript;version=1.7"> SimpleTest.waitForExplicitFinish();
-// __prefs__. Import the `Serivces.prefs` object. -let prefs = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm").Services.prefs; +// __setPref(key, value)__. +// Set a pref value asynchronously, returning a prmoise that resolves +// when it succeeds. +let setPref = function* (key, value) { + return new Promise(function(resolve, reject) { + SpecialPowers.pushPrefEnv({"set": [[key, value]]}, resolve); + }); +};
// ## Testing constants let domain1 = "http://example.com", @@ -47,7 +54,7 @@ let tabIO = function* (domain, child, input) { // and then attempt to retrieve the object from the blobURL in `domainB`, using // the page `deblobPage`. let blobTest = function* (isolationOn, domainA, domainB, blobPage, deblobPage) { - prefs.setIntPref("privacy.thirdparty.isolate", isolationOn ? 2 : 0); + yield setPref("privacy.thirdparty.isolate", isolationOn ? 2 : 0); let input = "" + Math.random(), blobURL = yield tabIO(domainA, blobPage, input), result = yield tabIO(domainB, deblobPage, blobURL), @@ -71,9 +78,9 @@ let blobTest = function* (isolationOn, domainA, domainB, blobPage, deblobPage) {
// ## The main test -// Run a Task.jsm coroutine that tests various combinations of domains +// Run a coroutine that tests various combinations of domains // methods, and isolation states for reading and writing blob URLs. -Task.spawn(function* () { +spawnTask(function* () { for (let isolate of [false, true]) { for (let domainB of [domain1, domain2]) { for (let blob of [page_blob, worker_blob]) {
tor-commits@lists.torproject.org