Bug 1141979 - part14 - mochitest - cases while calling mapDataInto should throw; r?jrmuizel draft
authorKaku Kuo <tkuo@mozilla.com>
Thu, 17 Mar 2016 17:48:10 +0800
changeset 342002 a5107836f7188b92d9e9219d6dce85fffa7bf0bc
parent 342001 2c8ce1ac12b278df0b97023ef18de19dc83fdc02
child 516511 9a1cd79295032526cdb50ec799c2ad7203bf1e66
push id13340
push usertkuo@mozilla.com
push dateFri, 18 Mar 2016 09:53:30 +0000
reviewersjrmuizel
bugs1141979
milestone48.0a1
Bug 1141979 - part14 - mochitest - cases while calling mapDataInto should throw; r?jrmuizel MozReview-Commit-ID: 3QUJy5E907G
dom/canvas/test/imagebitmap_extensions.html
dom/canvas/test/imagebitmap_extensions.js
dom/canvas/test/imagebitmap_extensions_on_worker.js
--- a/dom/canvas/test/imagebitmap_extensions.html
+++ b/dom/canvas/test/imagebitmap_extensions.html
@@ -36,13 +36,14 @@ function runTests() {
                                            testCreateFromArrayBffer_randomTest("ImageData", gImageData, 0),
                                            testCreateFromArrayBffer_randomTest("ImageBitmap", gImageBitmap, 0),
                                            testCreateFromArrayBffer_randomTest("PNG", gPNGBlob, 0),
                                            testCreateFromArrayBffer_randomTest("JPEG", gJPEGBlob, 10) // JPEG loses information
                                           ]); }).
     then(testDraw()).
     then(testExceptions).
     then(testColorConversions()).
+    then(function() { return testInvalidAccess([gVideo, gImage, gCanvas, gCtx, gImageData, gImageBitmap, gPNGBlob, gJPEGBlob]); } ).
     then(function() {window.parent.postMessage({"type": "finish"}, "*");}, function(ev) { failed(ev); window.parent.postMessage({"type": "finish"}, "*"); });
 }
 
 </script>
 </body>
--- a/dom/canvas/test/imagebitmap_extensions.js
+++ b/dom/canvas/test/imagebitmap_extensions.js
@@ -83,16 +83,68 @@ function testExceptions() {
     promiseThrows(testColorConversion("YUV420P", "DEPTH", undefined, true), "[Exception] Cannot convert from YUV420P to DEPTH"),
     promiseThrows(testColorConversion("YUV420SP_NV12", "DEPTH", undefined, true), "[Exception] Cannot convert from YUV420SP_NV12 to DEPTH"),
     promiseThrows(testColorConversion("YUV420SP_NV21", "DEPTH", undefined, true), "[Exception] Cannot convert from YUV420SP_NV21 to DEPTH"),
     promiseThrows(testColorConversion("HSV", "DEPTH", undefined, true), "[Exception] Cannot convert from HSV to DEPTH"),
     promiseThrows(testColorConversion("Lab", "DEPTH", undefined, true), "[Exception] Cannot convert from Lab to DEPTH"),
   ]);
 }
 
+function testInvalidAccess(sources) {
+
+  function callMapDataIntoWithImageBitmapCroppedOutSideOfTheSourceImage(source) {
+    return new Promise(function(resolve, reject) {
+      var p = createImageBitmap(source, -1, -1, 2, 2);
+      p.then(
+        function(bitmap) {
+          var format = bitmap.findOptimalFormat();
+          var length = bitmap.mappedDataLength(format);
+          var buffer = new ArrayBuffer(length);
+          bitmap.mapDataInto(format, buffer, 0).then(
+            function(layout) { resolve(); },
+            function(error) { reject(error); }
+          );
+        },
+        function() { resolve(); });
+    });
+  };
+
+  function callWithArrayBuffer() {
+    return new Promise(function(resolve, reject) {
+      var srcData = getData("RGBA32");
+      var p = createImageBitmap(srcData.buffer,
+                               0,
+                               srcData.bufferLength,
+                               srcData.format,
+                               srcData.pixelLayout,
+                               -1, -1, 2, 2);
+      p.then(
+        function(bitmap) {
+          var format = bitmap.findOptimalFormat();
+          var length = bitmap.mappedDataLength(format);
+          var buffer = new ArrayBuffer(length);
+          bitmap.mapDataInto(format, buffer, 0).then(
+            function(layout) { resolve(); },
+            function(error) { reject(error); }
+          );
+        },
+        function() { resolve(); });
+    });
+  }
+
+  var testCases = sources.map( function(source) {
+    return promiseThrows(callMapDataIntoWithImageBitmapCroppedOutSideOfTheSourceImage(source),
+                         "[Exception] mapDataInto() should throw with transparent black."); });
+
+  testCases.push(promiseThrows(callWithArrayBuffer(),
+                               "[Exception] mapDataInto() should throw with transparent black."));
+
+  return Promise.all(testCases);
+}
+
 function testColorConversions() {
   return Promise.all([// From RGBA32
                       testColorConversion("RGBA32", "RGBA32"),
                       testColorConversion("RGBA32", "BGRA32"),
                       testColorConversion("RGBA32", "RGB24"),
                       testColorConversion("RGBA32", "BGR24"),
                       testColorConversion("RGBA32", "GRAY8"),
                       testColorConversion("RGBA32", "YUV444P"),
--- a/dom/canvas/test/imagebitmap_extensions_on_worker.js
+++ b/dom/canvas/test/imagebitmap_extensions_on_worker.js
@@ -37,10 +37,11 @@ function runTests() {
                                          testAccessing_randomTest("PNG", gPNGBlob, 0),
                                          testAccessing_randomTest("JPEG", gJPEGBlob, 10) // JPEG loses information
                                         ]); }).
   then( function() { return Promise.all([testCreateFromArrayBffer_randomTest("ImageData", gImageData, 0),
                                          testCreateFromArrayBffer_randomTest("ImageBitmap", gImageBitmap, 0),
                                          testCreateFromArrayBffer_randomTest("PNG", gPNGBlob, 0),
                                          testCreateFromArrayBffer_randomTest("JPEG", gJPEGBlob, 10) // JPEG loses information
                                         ]); }).
+  then(function() { return testInvalidAccess([gImageData, gImageBitmap, gPNGBlob, gJPEGBlob]); } ).
   then(function() {postMessage({"type": "finish"});}, function(ev) { failed(ev); postMessage({"type": "finish"}); });
 }
\ No newline at end of file