blob: 6e791297924775976b5da96a8edf4d0eaa493161 [file] [log] [blame]
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<script>
jsTestIsAsync = true;
var worker = new Worker('./resources/worker-onmessage-noop.js');
description("Tests that the close method of ImageBitmap does dispose the image data");
var imgHeight = 10;
var imgWidth = 10;
var imageData = new ImageData(10, 10);
var bitmap;
var ctx;
createImageBitmap(imageData).then(imageBitmap => {
bitmap = imageBitmap;
shouldBe("bitmap.width", "imgWidth");
shouldBe("bitmap.height", "imgHeight");
// Apply structured clone to the bitmap, nothing should be changed
worker.postMessage({data: bitmap});
shouldBe("bitmap.width", "imgWidth");
shouldBe("bitmap.height", "imgHeight");
// After calling close, the image data associated with the bitmap should no longer exist
bitmap.close();
shouldBe("bitmap.width", "0");
shouldBe("bitmap.height", "0");
var canvas = document.createElement("canvas");
canvas.width = imgWidth;
canvas.height = imgHeight;
ctx = canvas.getContext("2d");
shouldThrow("ctx.drawImage(bitmap, 0, 0)");
// Try to apply structured clone to an already closed bitmap
try {
worker.postMessage({data: bitmap});
testFailed("Apply structured clone to an already closed bitmap passed unexpectedly");
} catch(ex) {
testPassed("Apply structured clone to an already closed bitmap is rejected as expected: " + ex);
}
// Try to apply transfering to an already closed bitmap
try {
worker.postMessage({data: bitmap}, [bitmap]);
testFailed("Apply transfering to an already closed bitmap passed unexpectedly");
} catch(ex) {
testPassed("Apply transfering to an already closed bitmap is rejected as expected: " + ex);
}
// Calling createImageBitmap from a closed bitmap should be rejected
return createImageBitmap(bitmap).then(function() {
testFailed("Promise accepted, expected to be rejected");
finishJSTest();
}, ex => {
testPassed("createImageBitmap from a closed ImageBitmap was rejected. " + ex);
});
}).then(() => {
// Call close to a already closed bitmap should be noop.
bitmap.close();
shouldBe("bitmap.width", "0");
shouldBe("bitmap.height", "0");
return createImageBitmap(imageData).then(imageBitmap => {
bitmap = imageBitmap;
shouldBe("bitmap.width", "imgWidth");
shouldBe("bitmap.height", "imgHeight");
// Transfer the bitmap to a worker
worker.postMessage({data: bitmap}, [bitmap]);
// After transfering, the bitmap is neutered.
shouldBe("bitmap.width", "0");
shouldBe("bitmap.height", "0");
// Calling close to a neutered bitmap should be noop.
bitmap.close();
shouldBe("bitmap.width", "0");
shouldBe("bitmap.height", "0");
});
}).catch(function(ex) {
testFailed("Unexpected failure: " + ex);
}).then(() => { finishJSTest(); });
</script>