<!DOCTYPE html>
<title>Upgrade Insecure Requests: Basics.</title>
<script src="/js-test-resources/testharness.js"></script>
<script src="/js-test-resources/testharnessreport.js"></script>

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<div id="console"></div>
<script>
if (window.testRunner)
    testRunner.dumpAsText();

// This is a bit of a hack. UPGRADE doesn't upgrade the port number, so we
// specify this non-existent URL ('http' over port 8443). If UPGRADE doesn't
// work, it won't load.
var insecureImage = "http://127.0.0.1:8443/security/resources/abe.png";

(function() {
    var t = async_test("Verify that images have correct cross-origin behavior.");
    t.step(function () {
        var i = document.createElement('img');
        i.onload = t.step_func(function () {
            // Draw the image onto a canvas.
            var canvas = document.createElement('canvas');
            var ctx = canvas.getContext('2d');
            ctx.drawImage(i, 0, 0);

            // Grab a pixel to verify that the image is same-origin:
            try {
                var pixel = ctx.getImageData(0, 0, 1, 1);
                t.done();
                console.log("PASS: Successfully retrieved image data.");
            } catch (e) {
                console.log("FAIL: The image should be same-origin with this document.");
            }
        });
        i.onerror = t.step_func(function () {
            console.log("FAIL: The image should load successfully.");
        });

        i.src = insecureImage;
    });
}());
</script>
