Bug 1141979 - part18 - mochitest - cases while calling mapDataInto should throw; r=jrmuizel
authorKaku Kuo <tkuo@mozilla.com>
Thu, 17 Mar 2016 17:48:10 +0800
changeset 341169 df4c70f4b9f6a5403afc565f65262ac20e2d7086
parent 341168 2e661c7c4e071752c56dc6b6f410a4b3ae347e15
child 341170 403b82279b764fb278c651198e8e77018c71d400
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1141979
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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