Bug 1500734 - createImageBitmap should throw RangeError if sw or sh is 0 - r=aosmond
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 23 Oct 2018 08:17:28 +0200
changeset 490748 ce374302821c1a202263562910e7888ed455f5d8
parent 490747 29f0a8f38d05b8d0d7ad63aebe715590f9813e02
child 490749 1e036ba2e247a79a10dc8f6841b2992aafd711e4
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersaosmond
bugs1500734
milestone65.0a1
Bug 1500734 - createImageBitmap should throw RangeError if sw or sh is 0 - r=aosmond
dom/canvas/ImageBitmap.cpp
testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-invalid-args.html.ini
testing/web-platform/tests/2dcontext/imagebitmap/createImageBitmap-invalid-args.html
--- a/dom/canvas/ImageBitmap.cpp
+++ b/dom/canvas/ImageBitmap.cpp
@@ -1392,17 +1392,17 @@ ImageBitmap::Create(nsIGlobalObject* aGl
 
   RefPtr<Promise> promise = Promise::Create(aGlobal, aRv);
 
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   if (aCropRect.isSome() && (aCropRect->Width() == 0 || aCropRect->Height() == 0)) {
-    aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
+    aRv.Throw(NS_ERROR_RANGE_ERR);
     return promise.forget();
   }
 
   RefPtr<ImageBitmap> imageBitmap;
 
   if (aSrc.IsHTMLImageElement()) {
     MOZ_ASSERT(NS_IsMainThread(),
                "Creating ImageBitmap from HTMLImageElement off the main thread.");
--- a/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-invalid-args.html.ini
+++ b/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-invalid-args.html.ini
@@ -1,139 +1,46 @@
 [createImageBitmap-invalid-args.html]
-  [createImageBitmap with a HTMLImageElement source and sw set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a HTMLImageElement source and sh set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a HTMLImageElement source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.]
-    expected: FAIL
-
-  [createImageBitmap with a HTMLVideoElement source and sw set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a HTMLVideoElement source and sh set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a HTMLVideoElement source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.]
-    expected: FAIL
-
-  [createImageBitmap with a HTMLCanvasElement source and sw set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a HTMLCanvasElement source and sh set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a HTMLCanvasElement source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.]
-    expected: FAIL
-
-  [createImageBitmap with a OffscreenCanvas source and sw set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a OffscreenCanvas source and sh set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a OffscreenCanvas source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.]
-    expected: FAIL
-
-  [createImageBitmap with a ImageData source and sw set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a ImageData source and sh set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a ImageData source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.]
-    expected: FAIL
-
-  [createImageBitmap with a ImageBitmap source and sw set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a ImageBitmap source and sh set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a ImageBitmap source and oversized (unallocatable) crop region rejects with an InvalidStateError DOMException.]
-    expected: FAIL
-
-  [createImageBitmap with a Blob source and sw set to 0 rejects with a RangeError.]
-    expected: FAIL
-
-  [createImageBitmap with a Blob source and sh set to 0 rejects with a RangeError.]
-    expected: FAIL
-
   [createImageBitmap with an oversized canvas source rejects with a RangeError.]
     expected: FAIL
 
   [createImageBitmap with an invalid OffscreenCanvas source rejects with a RangeError.]
     expected: FAIL
 
   [createImageBitmap with a broken image source rejects with an InvalidStateError.]
     expected: FAIL
 
   [createImageBitmap with an available but undecodable image source rejects with an InvalidStateError.]
     expected: FAIL
 
-  [createImageBitmap with a an HTMLCanvasElement source and sw set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a an HTMLCanvasElement source and sh set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a an HTMLCanvasElement source and oversized (unallocatable) crop region]
-    expected: FAIL
-
-  [createImageBitmap with a an HTMLVideoElement source and sw set to 0]
+  [createImageBitmap with an HTMLCanvasElement source and oversized (unallocatable) crop region]
     expected: FAIL
 
-  [createImageBitmap with a an HTMLVideoElement source and sh set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a an HTMLVideoElement source and oversized (unallocatable) crop region]
+  [createImageBitmap with an HTMLVideoElement source and oversized (unallocatable) crop region]
     expected: FAIL
 
-  [createImageBitmap with a an HTMLImageElement source and sw set to 0]
+  [createImageBitmap with an HTMLImageElement source and sw set to 0]
     expected: FAIL
 
-  [createImageBitmap with a an HTMLImageElement source and sh set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a an HTMLImageElement source and oversized (unallocatable) crop region]
+  [createImageBitmap with an HTMLImageElement source and oversized (unallocatable) crop region]
     expected: FAIL
 
-  [createImageBitmap with a an OffscreenCanvas source and sw set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a an OffscreenCanvas source and sh set to 0]
+  [createImageBitmap with an OffscreenCanvas source and sw set to 0]
     expected: FAIL
 
-  [createImageBitmap with a an OffscreenCanvas source and oversized (unallocatable) crop region]
-    expected: FAIL
-
-  [createImageBitmap with a an ImageData source and sw set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a an ImageData source and sh set to 0]
+  [createImageBitmap with an OffscreenCanvas source and sh set to 0]
     expected: FAIL
 
-  [createImageBitmap with a an ImageData source and oversized (unallocatable) crop region]
-    expected: FAIL
-
-  [createImageBitmap with a an ImageBitmap source and sw set to 0]
+  [createImageBitmap with an OffscreenCanvas source and oversized (unallocatable) crop region]
     expected: FAIL
 
-  [createImageBitmap with a an ImageBitmap source and sh set to 0]
+  [createImageBitmap with an ImageData source and oversized (unallocatable) crop region]
     expected: FAIL
 
-  [createImageBitmap with a an ImageBitmap source and oversized (unallocatable) crop region]
-    expected: FAIL
-
-  [createImageBitmap with a a Blob source and sw set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a a Blob source and sh set to 0]
+  [createImageBitmap with an ImageBitmap source and oversized (unallocatable) crop region]
     expected: FAIL
 
   [createImageBitmap with an oversized canvas source.]
     expected: FAIL
 
   [createImageBitmap with an invalid OffscreenCanvas source.]
     expected: FAIL
 
@@ -141,59 +48,41 @@
     expected: FAIL
 
   [createImageBitmap with an available but undecodable image source.]
     expected: FAIL
 
   [createImageBitmap with a closed ImageBitmap.]
     expected: FAIL
 
-  [createImageBitmap with a a bitmap HTMLImageElement source and sw set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a a bitmap HTMLImageElement source and sh set to 0]
+  [createImageBitmap with a bitmap HTMLImageElement source and oversized (unallocatable) crop region]
     expected: FAIL
 
-  [createImageBitmap with a a bitmap HTMLImageElement source and oversized (unallocatable) crop region]
+  [createImageBitmap with a bitmap SVGImageElement source and sw set to 0]
     expected: FAIL
 
-  [createImageBitmap with a a vector HTMLImageElement source and sw set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a a vector HTMLImageElement source and sh set to 0]
+  [createImageBitmap with a bitmap SVGImageElement source and sh set to 0]
     expected: FAIL
 
-  [createImageBitmap with a a bitmap SVGImageElement source and sw set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a a bitmap SVGImageElement source and sh set to 0]
+  [createImageBitmap with a bitmap SVGImageElement source and oversized (unallocatable) crop region]
     expected: FAIL
 
-  [createImageBitmap with a a bitmap SVGImageElement source and oversized (unallocatable) crop region]
+  [createImageBitmap with a vector SVGImageElement source and sw set to 0]
     expected: FAIL
 
-  [createImageBitmap with a a vector SVGImageElement source and sw set to 0]
+  [createImageBitmap with a vector SVGImageElement source and sh set to 0]
     expected: FAIL
 
-  [createImageBitmap with a a vector SVGImageElement source and sh set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a a vector SVGImageElement source and oversized (unallocatable) crop region]
+  [createImageBitmap with a vector SVGImageElement source and oversized (unallocatable) crop region]
     expected: FAIL
 
   [createImageBitmap with CanvasRenderingContext2D image source.]
     expected: FAIL
 
   [createImageBitmap with Uint8Array image source.]
     expected: FAIL
 
   [createImageBitmap with ArrayBuffer image source.]
     expected: FAIL
 
-  [createImageBitmap with a an HTMLVideoElement from a data URL source and sw set to 0]
+  [createImageBitmap with an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region]
     expected: FAIL
 
-  [createImageBitmap with a an HTMLVideoElement from a data URL source and sh set to 0]
-    expected: FAIL
-
-  [createImageBitmap with a an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region]
-    expected: FAIL
-
--- a/testing/web-platform/tests/2dcontext/imagebitmap/createImageBitmap-invalid-args.html
+++ b/testing/web-platform/tests/2dcontext/imagebitmap/createImageBitmap-invalid-args.html
@@ -44,38 +44,38 @@ function makeAvailableButBrokenImage(pat
     image.src = path;
     image.onload = () => resolve(image);
     image.onerror = reject;
   });
 }
 
 testCases = [
   {
-    description: 'createImageBitmap with a <sourceType> source and sw set to 0',
+    description: 'createImageBitmap with <sourceType> source and sw set to 0',
     promiseTestFunction:
       (source, t) => {
         return promise_rejects(t, new RangeError(),
             createImageBitmap(source, 0, 0, 0, 10));
       }
   },
   {
-    description: 'createImageBitmap with a <sourceType> source and sh set to 0',
+    description: 'createImageBitmap with <sourceType> source and sh set to 0',
     promiseTestFunction:
       (source, t) => {
         return promise_rejects(t, new RangeError(),
             createImageBitmap(source, 0, 0, 10, 0));
       }
   },
   {
     // This case is not explicitly documented in the specification for
     // createImageBitmap, but it is expected that internal failures cause
     // InvalidStateError.
     //
     // Note: https://bugs.chromium.org/p/chromium/issues/detail?id=799025
-    description: 'createImageBitmap with a <sourceType> source and oversized ' +
+    description: 'createImageBitmap with <sourceType> source and oversized ' +
         '(unallocatable) crop region',
     promiseTestFunction:
       (source, t) => {
         return promise_rejects(t, new DOMException('', 'InvalidStateError'),
             createImageBitmap(source, 0, 0, 100000000, 100000000));
       }
   },
 ];