diff --git a/dom/canvas/test/image_error-early.png b/dom/canvas/test/image_error-early.png new file mode 100644 index 000000000000..5df7507e2de1 --- /dev/null +++ b/dom/canvas/test/image_error-early.png @@ -0,0 +1 @@ +ERROR diff --git a/dom/canvas/test/imagebitmap_on_worker.js b/dom/canvas/test/imagebitmap_on_worker.js new file mode 100644 index 000000000000..96a01e459f82 --- /dev/null +++ b/dom/canvas/test/imagebitmap_on_worker.js @@ -0,0 +1,81 @@ +function ok(expect, msg) { + postMessage({type: "status", status: !!expect, msg: msg}); +} + +function doneTask() { + postMessage({type: "doneTask"}); +} + +function promiseThrows(p, name) { + var didThrow; + return p.then(function() { didThrow = false; }, + function() { didThrow = true; }) + .then(function() { ok(didThrow, "[TestException] " + name); }); +} + +onmessage = function(event) { + if (event.data.type == "testImageData") { + var width = event.data.width; + var height = event.data.height; + var imageData = event.data.source; + ok(imageData, "[CreateFromImageData] An ImageData is passed into worker.") + ok(imageData.width == width, "[CreateFromImageData] Passed ImageData has right width = " + width); + ok(imageData.height == height, "[CreateFromImageData] Passed ImageData has right height = " + height); + + var promise = createImageBitmap(imageData); + promise.then(function(bitmap) { + ok(bitmap, "[CreateFromImageData] ImageBitmap is created successfully."); + ok(bitmap.width == width, "[CreateFromImageData] ImageBitmap.width = " + bitmap.width + ", expected witdth = " + width); + ok(bitmap.height == height, "[CreateFromImageData] ImageBitmap.height = " + bitmap.height + ", expected height = " + height); + + doneTask(); + }); + } else if (event.data.type == "testBlob") { + var width = event.data.width; + var height = event.data.height; + var blob = event.data.source; + ok(blob, "[CreateFromBlob] A Blob object is passed into worker."); + + var promise = createImageBitmap(blob); + promise.then(function(bitmap) { + ok(bitmap, "[CreateFromBlob] ImageBitmap is created successfully."); + ok(bitmap.width == width, "[CreateFromBlob] ImageBitmap.width = " + bitmap.width + ", expected witdth = " + width); + ok(bitmap.height == height, "[CreateFromBlob] ImageBitmap.height = " + bitmap.height + ", expected height = " + height); + + doneTask(); + }); + } else if (event.data.type == "testImageBitmap") { + var width = event.data.width; + var height = event.data.height; + var source = event.data.source; + ok(source, "[CreateFromImageBitmap] A soruce object is passed into worker."); + + var promise = createImageBitmap(source); + promise.then(function(bitmap) { + ok(bitmap, "[CreateFromImageBitmap] ImageBitmap is created successfully."); + ok(bitmap.width == width, "[CreateFromImageBitmap] ImageBitmap.width = " + bitmap.width + ", expected witdth = " + width); + ok(bitmap.height == height, "[CreateFromImageBitmap] ImageBitmap.height = " + bitmap.height + ", expected height = " + height); + + var promise2 = createImageBitmap(bitmap); + promise2.then(function(bitmap2) { + ok(bitmap2, "[CreateFromImageBitmap] 2nd ImageBitmap is created successfully."); + ok(bitmap.width == width, "[CreateFromImageBitmap] ImageBitmap.width = " + bitmap.width + ", expected witdth = " + width); + ok(bitmap.height == height, "[CreateFromImageBitmap] ImageBitmap.height = " + bitmap.height + ", expected height = " + height); + + doneTask(); + }); + }); + } else if (event.data.type == "testException") { + var source = event.data.source; + if (event.data.sx) { + var sx = event.data.sx; + var sy = event.data.sy; + var sw = event.data.sw; + var sh = event.data.sh; + promiseThrows(createImageBitmap(source, sx, sy, sw, sh), event.data.msg); + } else { + promiseThrows(createImageBitmap(source), event.data.msg); + } + doneTask(); + } +}; \ No newline at end of file diff --git a/dom/canvas/test/imagebitmap_structuredclone.js b/dom/canvas/test/imagebitmap_structuredclone.js new file mode 100644 index 000000000000..80640e461c65 --- /dev/null +++ b/dom/canvas/test/imagebitmap_structuredclone.js @@ -0,0 +1,30 @@ +function ok(expect, msg) { + postMessage({"type": "status", status: !!expect, msg: msg}); +} + +onmessage = function(event) { + ok(!!event.data.bitmap1, "Get the 1st ImageBitmap from the main script."); + ok(!!event.data.bitmap2, "Get the 2st ImageBitmap from the main script."); + + // send the first original ImageBitmap back to the main-thread + postMessage({"type":"bitmap1", + "bitmap":event.data.bitmap1}); + + // create a new ImageBitmap from the 2nd original ImageBitmap + // and then send the newly created ImageBitmap back to the main-thread + var promise = createImageBitmap(event.data.bitmap2); + promise.then( + function(bitmap) { + ok(true, "Successfully create a new ImageBitmap from the 2nd original bitmap in worker."); + + // send the newly created ImageBitmap back to the main-thread + postMessage({"type":"bitmap2", "bitmap":bitmap}); + + // finish the test + postMessage({"type": "finish"}); + }, + function() { + ok(false, "Cannot create a new bitmap from the original bitmap in worker."); + } + ); +} diff --git a/dom/canvas/test/imagebitmap_structuredclone_iframe.html b/dom/canvas/test/imagebitmap_structuredclone_iframe.html new file mode 100644 index 000000000000..b14b40312314 --- /dev/null +++ b/dom/canvas/test/imagebitmap_structuredclone_iframe.html @@ -0,0 +1,38 @@ + + +
+ + diff --git a/dom/canvas/test/mochitest.ini b/dom/canvas/test/mochitest.ini index 6be7e59f67d0..bc2c2c2a6533 100644 --- a/dom/canvas/test/mochitest.ini +++ b/dom/canvas/test/mochitest.ini @@ -6,6 +6,7 @@ support-files = image_anim-gr.png image_anim-poster-gr.png image_broken.png + image_error-early.png image_ggrr-256x256.png image_green-16x16.png image_green-1x1.png @@ -23,6 +24,9 @@ support-files = image_transparent50.png image_yellow.png image_yellow75.png + imagebitmap_on_worker.js + imagebitmap_structuredclone.js + imagebitmap_structuredclone_iframe.html [test_2d.clearRect.image.offscreen.html] [test_2d.clip.winding.html] @@ -234,6 +238,11 @@ support-files = captureStream_common.js [test_drawWindow.html] support-files = file_drawWindow_source.html file_drawWindow_common.js skip-if = buildapp == 'mulet' || (buildapp == 'b2g' && toolkit != 'gonk') +[test_imagebitmap.html] +[test_imagebitmap_on_worker.html] +[test_imagebitmap_structuredclone.html] +[test_imagebitmap_structuredclone_iframe.html] +[test_imagebitmap_structuredclone_window.html] [test_ImageData_ctor.html] [test_isPointInStroke.html] [test_mozDashOffset.html] diff --git a/dom/canvas/test/test_imagebitmap.html b/dom/canvas/test/test_imagebitmap.html new file mode 100644 index 000000000000..df9a2ec4af43 --- /dev/null +++ b/dom/canvas/test/test_imagebitmap.html @@ -0,0 +1,342 @@ + +