<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="worker-src http:; script-src 'unsafe-inline'; child-src 'none'">
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}
</script>
</head>
<body>
<p>This tests that in an isolated world the Content Security Policy of the parent origin (this page) is bypassed and a Web Worker is allowed to be instantiated with a script URL not listed in the CSP of the page.</p>
<pre id="result"></pre>
<script>
window.onmessage = function (event)
{
    document.getElementById("result").textContent = event.data;
    if (window.testRunner)
        testRunner.notifyDone();
}

function runTest()
{
    var worker;
    try {
        // We ignore the message posted by the worker (by not registering an onmessage handler) as we are only interested in knowing whether an exception occurred.
        worker = new Worker("http://127.0.0.1:8000/security/contentSecurityPolicy/resources/worker.py?type=post-message-pass");
        window.postMessage("PASS worker instantiated.", "*");
    } catch (exception) {
        window.postMessage("FAIL should not have thrown an exception when creating worker. Threw exception " + exception + ".", "*");
    }
}

if (window.testRunner)
    testRunner.evaluateScriptInIsolatedWorld(0, runTest.toString() + ";runTest();");
</script>
</body>
</html>
