dom/workers/test/WorkerTest_subworker.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /**
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 */
michael@0 5 onmessage = function(event) {
michael@0 6 let chromeURL = event.data.replace("test_chromeWorkerJSM.xul",
michael@0 7 "WorkerTest_badworker.js");
michael@0 8
michael@0 9 let mochitestURL = event.data.replace("test_chromeWorkerJSM.xul",
michael@0 10 "WorkerTest_badworker.js")
michael@0 11 .replace("chrome://mochitests/content/chrome",
michael@0 12 "http://mochi.test:8888/tests");
michael@0 13
michael@0 14 // We should be able to XHR to anything we want, including a chrome URL.
michael@0 15 let xhr = new XMLHttpRequest();
michael@0 16 xhr.open("GET", mochitestURL, false);
michael@0 17 xhr.send();
michael@0 18
michael@0 19 if (!xhr.responseText) {
michael@0 20 throw "Can't load script file via XHR!";
michael@0 21 }
michael@0 22
michael@0 23 // We shouldn't be able to make a ChromeWorker to a non-chrome URL.
michael@0 24 let worker = new ChromeWorker(mochitestURL);
michael@0 25 worker.onmessage = function(event) {
michael@0 26 throw event.data;
michael@0 27 };
michael@0 28 worker.onerror = function(event) {
michael@0 29 event.preventDefault();
michael@0 30
michael@0 31 // And we shouldn't be able to make a regular Worker to a non-chrome URL.
michael@0 32 worker = new Worker(mochitestURL);
michael@0 33 worker.onmessage = function(event) {
michael@0 34 throw event.data;
michael@0 35 };
michael@0 36 worker.onerror = function(event) {
michael@0 37 event.preventDefault();
michael@0 38 postMessage("Done");
michael@0 39 };
michael@0 40 worker.postMessage("Hi");
michael@0 41 };
michael@0 42 worker.postMessage("Hi");
michael@0 43 };

mercurial