diff --git a/dom/canvas/test/mochitest.ini b/dom/canvas/test/mochitest.ini index 2fddb72ef7a3..71cbcf769de5 100644 --- a/dom/canvas/test/mochitest.ini +++ b/dom/canvas/test/mochitest.ini @@ -193,6 +193,7 @@ tags = imagebitmap [test_ImageData_ctor.html] [test_isPointInStroke.html] [test_mozGetAsFile.html] +prefs = canvas.mozgetasfile.enabled=true [test_strokeText_throw.html] [test_toBlob.html] [test_toBlob_zero_dimension.html] diff --git a/dom/canvas/test/test_toBlob.html b/dom/canvas/test/test_toBlob.html index 34d87dba8a90..bcffdc0f16a6 100644 --- a/dom/canvas/test/test_toBlob.html +++ b/dom/canvas/test/test_toBlob.html @@ -14,7 +14,7 @@ function BlobListener(type, canvas, callback, file) reader.onload = function(e) { is(e.target.result, canvas.toDataURL(type), - ".mozGetAsFile().getAsDataURL() should equal .toDataURL()"); + ".toBlob() should equal .toDataURL()"); callback(canvas); }; reader.readAsDataURL(file); diff --git a/dom/file/tests/common_blob.js b/dom/file/tests/common_blob.js index dd1963a9ebd4..1750c71a1067 100644 --- a/dom/file/tests/common_blob.js +++ b/dom/file/tests/common_blob.js @@ -135,7 +135,11 @@ function testBlob(file, contents, testName) { function testSlice(file, size, type, contents, fileType, range) { is(file.type, type, fileType + " file is correct type"); is(file.size, size, fileType + " file is correct size"); - ok(file instanceof File, fileType + " file is a File"); + if (fileType == "fileFile") { + ok(file instanceof File, fileType + " file is a File"); + } else if (fileType == "memFile") { + ok(!(file instanceof File), fileType + " file is not a File"); + } ok(file instanceof Blob, fileType + " file is also a Blob"); let slice = file.slice(0, size); @@ -377,3 +381,15 @@ function createFile(data, name) { }); }); } + +function toBlobPromise(canvas) { + function BlobListener(callback, file) { + var reader = new FileReader(); + reader.onload = () => callback(file); + reader.readAsDataURL(file); + } + + return new Promise(resolve => { + canvas.toBlob(BlobListener.bind(undefined, resolve)); + }); +} diff --git a/dom/file/tests/test_fileapi_slice_memFile_1.html b/dom/file/tests/test_fileapi_slice_memFile_1.html index 53532d52df18..56d63d15ba58 100644 --- a/dom/file/tests/test_fileapi_slice_memFile_1.html +++ b/dom/file/tests/test_fileapi_slice_memFile_1.html @@ -21,7 +21,12 @@ SimpleTest.requestLongerTimeout(4); createCanvasURL() .then(data => { let cx = $("canvas").getContext('2d'); - let memFile = cx.canvas.mozGetAsFile("image/png"); + return Promise.all([toBlobPromise(cx.canvas), + Promise.resolve(data)]); +}) + +.then(args => { + let [memFile, data] = args; return testSlice(memFile, data.length, "image/png", data, "memFile", RANGE_1); }) diff --git a/dom/file/tests/test_fileapi_slice_memFile_2.html b/dom/file/tests/test_fileapi_slice_memFile_2.html index 3f9793a1fcea..aef8813bf5f3 100644 --- a/dom/file/tests/test_fileapi_slice_memFile_2.html +++ b/dom/file/tests/test_fileapi_slice_memFile_2.html @@ -21,7 +21,12 @@ SimpleTest.requestLongerTimeout(4); createCanvasURL() .then(data => { let cx = $("canvas").getContext('2d'); - let memFile = cx.canvas.mozGetAsFile("image/png"); + return Promise.all([toBlobPromise(cx.canvas), + Promise.resolve(data)]); +}) + +.then(args => { + let [memFile, data] = args; return testSlice(memFile, data.length, "image/png", data, "memFile", RANGE_2); }) diff --git a/dom/webidl/HTMLCanvasElement.webidl b/dom/webidl/HTMLCanvasElement.webidl index 1ecd479afcdf..dbb23168b8a2 100644 --- a/dom/webidl/HTMLCanvasElement.webidl +++ b/dom/webidl/HTMLCanvasElement.webidl @@ -38,7 +38,7 @@ interface HTMLCanvasElement : HTMLElement { partial interface HTMLCanvasElement { [Pure, SetterThrows] attribute boolean mozOpaque; - [Throws, NeedsSubjectPrincipal] + [Throws, NeedsSubjectPrincipal, Pref="canvas.mozgetasfile.enabled"] File mozGetAsFile(DOMString name, optional DOMString? type = null); // A Mozilla-only extension to get a canvas context backed by double-buffered // shared memory. Only privileged callers can call this. diff --git a/image/test/crashtests/crashtests.list b/image/test/crashtests/crashtests.list index 2a0b55aa9e37..cb693fca63c1 100644 --- a/image/test/crashtests/crashtests.list +++ b/image/test/crashtests/crashtests.list @@ -9,7 +9,7 @@ load 570451.png # Bug 1390704 - Skip on debug because it triggers a quadratic behavior that makes it take # so much time that it can trip on the reftest timeout of 5 minutes. skip-if(Android||isDebugBuild) load 694165-1.xhtml -load 681190.html +pref(canvas.mozgetasfile.enabled,true) load 681190.html load 732319-1.html load 844403-1.html load 856616.gif diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml index 36a690efa03c..c437c9a013cd 100644 --- a/modules/libpref/init/StaticPrefList.yaml +++ b/modules/libpref/init/StaticPrefList.yaml @@ -1063,6 +1063,12 @@ value: false mirror: always +# Provide ability to turn on support for canvas mozGetAsFile API. +- name: canvas.mozgetasfile.enabled + type: bool + value: false + mirror: always + #--------------------------------------------------------------------------- # Prefs starting with "channelclassifier." #---------------------------------------------------------------------------