blob: 16d45006854693e36cbb31956104375c40562f64 [file] [log] [blame]
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script>
// Create an image with invalid data.
var invalidImage = new Image();
invalidImage.src = 'resources/shadow-offset.js';
var ctx = document.createElement("canvas").getContext('2d');
function draw() {
// null and undefined images should throw TypeError
assert_throws(null, function() {ctx.drawImage(null, 0, 0)});
assert_throws(null, function() {ctx.drawImage(null, 0, 0, 20, 20)});
assert_throws(null, function() {ctx.drawImage(null, 0, 0, 20, 20, 0, 0, 20, 20)});
assert_throws(null, function() {ctx.drawImage(undefined, 0, 0)});
assert_throws(null, function() {ctx.drawImage(undefined, 0, 0, 20, 20)});
assert_throws(null, function() {ctx.drawImage(undefined, 0, 0, 20, 20, 0, 0, 20, 20)});
// broken images should not throw
assert_throws(null, function() {ctx.drawImage(invalidImage, 0, 0)});
assert_throws(null, function() {ctx.drawImage(invalidImage, 0, 0, 20, 20)});
assert_throws(null, function() {ctx.drawImage(invalidImage, 0, 0, 20, 20, 0, 0, 20, 20)});
assert_throws(null, function() {ctx.drawImage(invalidImage, 0, 0, 0, 20)});
assert_throws(null, function() {ctx.drawImage(invalidImage, 0, 0, 0, 20, 0, 0, 20, 20)});
}
async_test(t => {
invalidImage.onerror = function() {
t.step(draw);
t.done();
}
}, "This test checks behavior of Canvas::drawImage with a broken source image.");
</script>
</body>
</html>