<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="../../resources/js-test.js"></script>
<style>
canvas {
    border: 1px solid #000;
    margin: 2px;
}
</style>
<script>
var img;
var imgdata;

function imageLoaded() {
    var NUM_IMAGE = 16;
    for (var i = 0; i < NUM_IMAGE; i++) {
        var canvases = document.getElementById('canvases')
        var canvas = document.createElement('canvas');
        canvas.width = 9;
        canvas.height = 9;
        var ctx = canvas.getContext('2d');

        var pattern = ctx.createPattern(img, 'no-repeat');
        ctx.fillStyle = pattern;
        ctx.translate(img.width / 2, img.height / 2);
        var angle = 2 * Math.PI * i / NUM_IMAGE;
        ctx.rotate(angle);
        ctx.translate(- img.width / 2, - img.height / 2);
        ctx.fillRect(0, 0, img.width, img.height);

        var div = document.createElement('div');
        div.appendChild(canvas);
        canvases.appendChild(div);

        var imageData = ctx.getImageData(4, 4, 1, 1);
        imgdata = imageData.data;
        shouldBe("imgdata[0]", "0");
        shouldBe("imgdata[1]", "255");
        shouldBe("imgdata[2]", "0");
    }

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

function runTests() {
    if (window.testRunner) {
		testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }

    var patternCanvas = document.createElement('canvas');
    patternCanvas.width = 9;
    patternCanvas.height = 9;
    var patternCtx = patternCanvas.getContext('2d');
    patternCtx.fillStyle = '#0F0';
    patternCtx.fillRect(3, 3, 3, 3);
    img = new Image();
    img.onload = imageLoaded;
    img.src = patternCanvas.toDataURL();

}
</script>
</head>
<body onload="runTests();">
Visual result below is for debugging purposes only (test uses text baseline only). You should see sixteen canvases with a green dot (rotated square) in the center.
<div id="canvases"></div>
</pre>
</body>
</html>