blob: 49422853d4ebd66ecd005e10ae3648645feda30c [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="script-src 'unsafe-inline'">
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
</script>
</head>
<body>
<p>This tests that when calling WorkerGlobalScope.importScripts() will two script URLs that the second script is not loaded if the first script URL was blocked by the Content Security Policy of the worker (inherited from this page).</p>
<pre id="result"></pre>
<script>
function reportResultAndNotifyDone(message)
{
document.getElementById("result").textContent = message;
if (window.testRunner)
testRunner.notifyDone();
}
var script = [
'self.loadedSource1 = false;',
'self.loadedSource2 = false;',
'var exception;',
'try {',
' importScripts("http://localhost:8000/workers/resources/worker-importScripts-source1.js", "http://localhost:8000/workers/resources/worker-importScripts-source2.js");',
'} catch (e) {',
' exception = e;',
'}',
'var expectedExceptionCode = 19; // DOMException.NETWORK_ERR',
'if (!exception)',
' self.postMessage("FAIL should throw " + expectedExceptionCode + ". But did not throw an exception.");',
'else {',
' if (self.loadedSource1)',
' self.postMessage("FAIL should not have loaded and executed the first script.");',
' else if (self.loadedSource2)',
' self.postMessage("FAIL should not have loaded and executed the second script.");',
' else if (exception.code == expectedExceptionCode)',
' self.postMessage("PASS threw exception " + exception + ".");',
' else',
' self.postMessage("FAIL should throw " + expectedExceptionCode + ". Threw exception " + exception + ".");',
'}',
].join("\n");
var worker;
try {
worker = new Worker(window.URL.createObjectURL(new Blob([script])));
worker.onmessage = function (event) { reportResultAndNotifyDone(event.data); };
} catch (exception) {
reportResultAndNotifyDone("FAIL should not have thrown an exception when creating worker. Threw exception " + exception + ".");
}
</script>
</body>
</html>