chromium/third_party/blink/web_tests/http/tests/security/canvas-remote-read-data-url-image.html

<pre id="console"></pre>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

log = function(msg)
{
    document.getElementById('console').appendChild(document.createTextNode(msg + "\n"));
}

testGetImageData = function(context, description)
{
    description = "Calling getImageData() from a canvas tainted by a " + description;
    try {
        var imageData = context.getImageData(0,0,100,100);
        log("PASS: " + description + " was allowed.");
    } catch (e) {
        log("FAIL: " + description + " was not allowed - Threw error: " + e + ".");
    }
}

testToDataURL = function(canvas, description)
{
    description = "Calling toDataURL() on a canvas tainted by a " + description;
    try {
        var dataURL = canvas.toDataURL();
        log("PASS: " + description + " was allowed.");
    } catch (e) {
        log("FAIL: " + description + " was not allowed - Threw error: " + e + ".");
    }
}

test = function(canvas, description)
{
    testGetImageData(canvas.getContext("2d"), description);
    testToDataURL(canvas, description);
}

var image = new Image();
image.onload = function() {
    var canvas = document.createElement("canvas");
    canvas.width = 100;
    canvas.height = 100;
    var context = canvas.getContext("2d");

    // Test reading from a canvas after drawing a data URL image onto it
    context.drawImage(image, 0, 0, 100, 100);

    test(canvas, "data URL image");

    // Test reading after using a data URL pattern
    canvas = document.createElement("canvas");
    canvas.width = 100;
    canvas.height = 100;
    var context = canvas.getContext("2d");
    var remoteImagePattern = context.createPattern(image, "repeat");
    context.fillStyle = remoteImagePattern;
    context.fillRect(0, 0, 100, 100);

    test(canvas, "data URL image pattern");

    if (window.testRunner)
        testRunner.notifyDone();
}

// A small red dot.
image.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IAAAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1JREFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jqch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0vr4MkhoXe0rZigAAAABJRU5ErkJggg==";
</script>