1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/workers/test/WorkerTest_subworker.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,43 @@ 1.4 +/** 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 +onmessage = function(event) { 1.9 + let chromeURL = event.data.replace("test_chromeWorkerJSM.xul", 1.10 + "WorkerTest_badworker.js"); 1.11 + 1.12 + let mochitestURL = event.data.replace("test_chromeWorkerJSM.xul", 1.13 + "WorkerTest_badworker.js") 1.14 + .replace("chrome://mochitests/content/chrome", 1.15 + "http://mochi.test:8888/tests"); 1.16 + 1.17 + // We should be able to XHR to anything we want, including a chrome URL. 1.18 + let xhr = new XMLHttpRequest(); 1.19 + xhr.open("GET", mochitestURL, false); 1.20 + xhr.send(); 1.21 + 1.22 + if (!xhr.responseText) { 1.23 + throw "Can't load script file via XHR!"; 1.24 + } 1.25 + 1.26 + // We shouldn't be able to make a ChromeWorker to a non-chrome URL. 1.27 + let worker = new ChromeWorker(mochitestURL); 1.28 + worker.onmessage = function(event) { 1.29 + throw event.data; 1.30 + }; 1.31 + worker.onerror = function(event) { 1.32 + event.preventDefault(); 1.33 + 1.34 + // And we shouldn't be able to make a regular Worker to a non-chrome URL. 1.35 + worker = new Worker(mochitestURL); 1.36 + worker.onmessage = function(event) { 1.37 + throw event.data; 1.38 + }; 1.39 + worker.onerror = function(event) { 1.40 + event.preventDefault(); 1.41 + postMessage("Done"); 1.42 + }; 1.43 + worker.postMessage("Hi"); 1.44 + }; 1.45 + worker.postMessage("Hi"); 1.46 +};