Bug 1141979 - part18 - mochitest - cases while calling mapDataInto should throw; r=jrmuizel draft
authorKaku Kuo <tkuo@mozilla.com>
Thu, 17 Mar 2016 17:48:10 +0800
changeset 373857 f4b33755f6bcf81610a8e2defde7c7961ef75e29
parent 373856 27f415c03ed4c165e66b364d99b4cc52f0d4cda4
child 522482 f3f97766da2b85e74830773233c048509db67935
push id19853
push usertkuo@mozilla.com
push dateWed, 01 Jun 2016 09:17:41 +0000
reviewersjrmuizel
bugs1141979
milestone49.0a1
Bug 1141979 - part18 - 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,42 @@ 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(); });
+    });
+  };
+
+  var testCases = sources.map( function(source) {
+    return promiseThrows(callMapDataIntoWithImageBitmapCroppedOutSideOfTheSourceImage(source),
+                         "[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