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 @@ + +Test ImageBitmap + + + + + + + + + + + + + diff --git a/dom/canvas/test/test_imagebitmap_on_worker.html b/dom/canvas/test/test_imagebitmap_on_worker.html new file mode 100644 index 000000000000..3dbe0a638e4b --- /dev/null +++ b/dom/canvas/test/test_imagebitmap_on_worker.html @@ -0,0 +1,139 @@ + +Test ImageBitmap on Worker + + + + + + diff --git a/dom/canvas/test/test_imagebitmap_structuredclone.html b/dom/canvas/test/test_imagebitmap_structuredclone.html new file mode 100644 index 000000000000..faf178c3c60c --- /dev/null +++ b/dom/canvas/test/test_imagebitmap_structuredclone.html @@ -0,0 +1,105 @@ + +Test ImageBitmap : Structured Clone + + + + + + diff --git a/dom/canvas/test/test_imagebitmap_structuredclone_iframe.html b/dom/canvas/test/test_imagebitmap_structuredclone_iframe.html new file mode 100644 index 000000000000..02f80b05c6cb --- /dev/null +++ b/dom/canvas/test/test_imagebitmap_structuredclone_iframe.html @@ -0,0 +1,112 @@ + +Test ImageBitmap : StructuredClone between main window and iframe + + + + +
+ + diff --git a/dom/canvas/test/test_imagebitmap_structuredclone_window.html b/dom/canvas/test/test_imagebitmap_structuredclone_window.html new file mode 100644 index 000000000000..5aa5bfd3781e --- /dev/null +++ b/dom/canvas/test/test_imagebitmap_structuredclone_window.html @@ -0,0 +1,95 @@ + +Test ImageBitmap : StructuredClone main window to main window + + + + + + diff --git a/dom/tests/mochitest/general/test_interfaces.html b/dom/tests/mochitest/general/test_interfaces.html index c4be02871a73..0b95b9af4845 100644 --- a/dom/tests/mochitest/general/test_interfaces.html +++ b/dom/tests/mochitest/general/test_interfaces.html @@ -675,6 +675,8 @@ var interfaceNamesInGlobalScope = "IDBVersionChangeEvent", // IMPORTANT: Do not change this list without review from a DOM peer! "Image", +// IMPORTANT: Do not change this list without review from a DOM peer! + "ImageBitmap", // IMPORTANT: Do not change this list without review from a DOM peer! {name: "ImageCapture", disabled: true}, // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js index 4f43c9e6f36e..dfd90510c671 100644 --- a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js +++ b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js @@ -149,6 +149,8 @@ var interfaceNamesInGlobalScope = "IDBTransaction", // IMPORTANT: Do not change this list without review from a DOM peer! "IDBVersionChangeEvent", +// IMPORTANT: Do not change this list without review from a DOM peer! + "ImageBitmap", // IMPORTANT: Do not change this list without review from a DOM peer! "ImageData", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/dom/workers/test/test_worker_interfaces.js b/dom/workers/test/test_worker_interfaces.js index 2bf74aaa29eb..99fe13a5867a 100644 --- a/dom/workers/test/test_worker_interfaces.js +++ b/dom/workers/test/test_worker_interfaces.js @@ -143,6 +143,8 @@ var interfaceNamesInGlobalScope = "IDBTransaction", // IMPORTANT: Do not change this list without review from a DOM peer! "IDBVersionChangeEvent", +// IMPORTANT: Do not change this list without review from a DOM peer! + "ImageBitmap", // IMPORTANT: Do not change this list without review from a DOM peer! "ImageData", // IMPORTANT: Do not change this list without review from a DOM peer!