blob: 2e34188919e52a86681350b5403699c5741ed217 [file] [log] [blame]
<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script id="myWorker" type="text/worker">
self.onmessage = function(e) {
};
</script>
<script>
function makeWorker(script)
{
var blob = new Blob([script]);
return new Worker(URL.createObjectURL(blob));
}
async_test(function(t) {
var worker = makeWorker(document.getElementById("myWorker").textContent);
var offscreenCanvas = new OffscreenCanvas(10, 10);
worker.postMessage({offscreenCanvas}, [offscreenCanvas]);
offscreenCanvas.convertToBlob().then(t.step_func_done(function() {
assert_false("convertToBlob didn't throw, but should be");
}), t.step_func_done(function(e) {
assert_true(e instanceof DOMException);
assert_equals(e.name, "InvalidStateError");
}));
}, "Test that call convertToBlob on a detached OffscreenCanvas throws exception");
async_test(function(t) {
var offscreenCanvas = new OffscreenCanvas(0, 0);
offscreenCanvas.convertToBlob().then(t.step_func_done(function(blob) {
assert_equals(null, blob, "convertToBlob should return null as result blob.");
}), t.step_func_done(function(e) {
assert_false("convertToBlob should not throw exception.");
}));
}, "Test that call convertToBlob on an OffscreenCanvas with size 0 throws exception");
async_test(function(t) {
// Based on third_party/libwebp/src/webp/encode.h:WEBP_MAX_DIMENSION
var webp_max_dimension = 16383;
// This test simulates the encoding failure.
var offscreenCanvas = new OffscreenCanvas(10, webp_max_dimension + 1);
var ctx = offscreenCanvas.getContext("2d");
offscreenCanvas.convertToBlob({type: "image/webp"}).then(t.step_func_done(function(blob) {
assert_equals(null, blob, "convertToBlob should return null as result blob.");
}), t.step_func_done(function(e) {
assert_false("convertToBlob should not throw exception.");
}));
}, "Test that call convertToBlob throws EncodingError exception when encoding fails");
</script>