gecko/content/canvas/test/test_2d.imageData.get.source.outside.html

57 lines
2.0 KiB
HTML

<!DOCTYPE HTML>
<title>Canvas test: 2d.imageData.get.source.outside</title>
<!-- Testing: getImageData() returns transparent black outside the canvas -->
<script src="/MochiKit/MochiKit.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<body>
<canvas id="c" width="100" height="50"><p class="fallback">FAIL (fallback content)</p></canvas>
<script>
SimpleTest.waitForExplicitFinish();
MochiKit.DOM.addLoadEvent(function () {
var canvas = document.getElementById('c');
var ctx = canvas.getContext('2d');
var _thrown_outer = false;
try {
ctx.fillStyle = '#08f';
ctx.fillRect(0, 0, 100, 50);
var imgdata1 = ctx.getImageData(-10, 5, 1, 1);
ok(imgdata1.data[0] === 0, "imgdata1.data[\""+(0)+"\"] === 0");
ok(imgdata1.data[1] === 0, "imgdata1.data[\""+(1)+"\"] === 0");
ok(imgdata1.data[2] === 0, "imgdata1.data[\""+(2)+"\"] === 0");
ok(imgdata1.data[3] === 0, "imgdata1.data[\""+(3)+"\"] === 0");
var imgdata2 = ctx.getImageData(10, -5, 1, 1);
ok(imgdata2.data[0] === 0, "imgdata2.data[\""+(0)+"\"] === 0");
ok(imgdata2.data[1] === 0, "imgdata2.data[\""+(1)+"\"] === 0");
ok(imgdata2.data[2] === 0, "imgdata2.data[\""+(2)+"\"] === 0");
ok(imgdata2.data[3] === 0, "imgdata2.data[\""+(3)+"\"] === 0");
var imgdata3 = ctx.getImageData(200, 5, 1, 1);
ok(imgdata3.data[0] === 0, "imgdata3.data[\""+(0)+"\"] === 0");
ok(imgdata3.data[1] === 0, "imgdata3.data[\""+(1)+"\"] === 0");
ok(imgdata3.data[2] === 0, "imgdata3.data[\""+(2)+"\"] === 0");
ok(imgdata3.data[3] === 0, "imgdata3.data[\""+(3)+"\"] === 0");
var imgdata4 = ctx.getImageData(10, 60, 1, 1);
ok(imgdata4.data[0] === 0, "imgdata4.data[\""+(0)+"\"] === 0");
ok(imgdata4.data[1] === 0, "imgdata4.data[\""+(1)+"\"] === 0");
ok(imgdata4.data[2] === 0, "imgdata4.data[\""+(2)+"\"] === 0");
ok(imgdata4.data[3] === 0, "imgdata4.data[\""+(3)+"\"] === 0");
} catch (e) {
_thrown_outer = true;
}
todo(!_thrown_outer, 'should not throw exception');
SimpleTest.finish();
});
</script>