<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="img-src 'none'; script-src 'unsafe-inline'">
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}
</script>
</head>
<body>
<p>Tests that we prevent the document from loading an image that was loaded earlier from a user agent shadow tree. This test can only be run in the test tool. This test PASSED if you see the word PASS below and there is exactly one Content Security Policy console message about a blocked image load.</p>
<div id="shadow-host"></div>
<pre id="console"></pre>
<script>
function log(message)
{
    document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
}

function runTest()
{
    if (!window.testRunner || !window.internals)
        return;

    var userAgentShadowRoot = internals.ensureUserAgentShadowRoot(document.getElementById("shadow-host"));
    var image = new Image;
    userAgentShadowRoot.appendChild(image);

    image.onload = function () {
        // Load image again in document; should be prevented by Content Security Policy.
        var unprivilegedImage = new Image;
        unprivilegedImage.src = "../../resources/abe.png";
        unprivilegedImage.onload = function () {
            log("FAIL image should not have been loaded by document. But it was loaded.");
            testRunner.notifyDone();
        }
        unprivilegedImage.onerror = function () {
            log("PASS image was not loaded by document.");
            testRunner.notifyDone();
        }
    }
    image.onerror = function () {
        log("FAIL image did not load.");
        testRunner.notifyDone();
    }
    image.src = "../../resources/abe.png";
}

runTest();
</script>
</body>
</html>
