Return proper exception on CreateImageBitmap WPT test

There is a test for createImageBitmap that checks whether the source
image can not be allocated (DstBufferSizeHasOverflow) and rejects
the promise returning a null object when it should reject with
kInvalidStateError

Bug: 799025
Change-Id: I57b3afad681161e89c3cff746c3e433c31fe9895
Reviewed-on: https://chromium-review.googlesource.com/c/1495835
Commit-Queue: David Quiroz Marin <davidqu@chromium.org>
Reviewed-by: Fernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636575}
diff --git a/third_party/blink/renderer/core/html/canvas/image_element_base.cc b/third_party/blink/renderer/core/html/canvas/image_element_base.cc
index 00a0774..ad3bb0f 100644
--- a/third_party/blink/renderer/core/html/canvas/image_element_base.cc
+++ b/third_party/blink/renderer/core/html/canvas/image_element_base.cc
@@ -159,9 +159,6 @@
               "dimensions, and no resize options or crop region are "
               "specified."));
     }
-  }
-
-  if (IsSVGSource()) {
     return ImageBitmap::CreateAsync(this, crop_rect,
                                     event_target.ToLocalDOMWindow()->document(),
                                     script_state, options);
diff --git a/third_party/blink/renderer/core/imagebitmap/image_bitmap.cc b/third_party/blink/renderer/core/imagebitmap/image_bitmap.cc
index 70950b9..ec3a2d57 100644
--- a/third_party/blink/renderer/core/imagebitmap/image_bitmap.cc
+++ b/third_party/blink/renderer/core/imagebitmap/image_bitmap.cc
@@ -8,6 +8,7 @@
 #include "base/memory/scoped_refptr.h"
 #include "base/numerics/checked_math.h"
 #include "base/single_thread_task_runner.h"
+#include "third_party/blink/renderer/core/dom/dom_exception.h"
 #include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h"
 #include "third_party/blink/renderer/core/html/canvas/image_data.h"
 #include "third_party/blink/renderer/core/html/media/html_video_element.h"
@@ -971,8 +972,8 @@
       ParseOptions(options, crop_rect, image->BitmapSourceSize());
   if (DstBufferSizeHasOverflow(parsed_options)) {
     resolver->Reject(
-        ScriptValue(resolver->GetScriptState(),
-                    v8::Null(resolver->GetScriptState()->GetIsolate())));
+        DOMException::Create(DOMExceptionCode::kInvalidStateError,
+                             "The ImageBitmap could not be allocated."));
     return promise;
   }
 
@@ -990,8 +991,8 @@
       resolver->Resolve(bitmap);
     } else {
       resolver->Reject(
-          ScriptValue(resolver->GetScriptState(),
-                      v8::Null(resolver->GetScriptState()->GetIsolate())));
+          DOMException::Create(DOMExceptionCode::kInvalidStateError,
+                               "The ImageBitmap could not be allocated."));
     }
     return promise;
   }
diff --git a/third_party/blink/web_tests/external/wpt/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt b/third_party/blink/web_tests/external/wpt/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt
deleted file mode 100644
index 9824e58..0000000
--- a/third_party/blink/web_tests/external/wpt/2dcontext/imagebitmap/createImageBitmap-invalid-args-expected.txt
+++ /dev/null
@@ -1,52 +0,0 @@
-This is a testharness.js-based test.
-PASS createImageBitmap with an HTMLCanvasElement source and sw set to 0
-PASS createImageBitmap with an HTMLCanvasElement source and sh set to 0
-PASS createImageBitmap with an HTMLCanvasElement source and oversized (unallocatable) crop region
-PASS createImageBitmap with an HTMLVideoElement source and sw set to 0
-PASS createImageBitmap with an HTMLVideoElement source and sh set to 0
-PASS createImageBitmap with an HTMLVideoElement source and oversized (unallocatable) crop region
-PASS createImageBitmap with an HTMLVideoElement from a data URL source and sw set to 0
-PASS createImageBitmap with an HTMLVideoElement from a data URL source and sh set to 0
-PASS createImageBitmap with an HTMLVideoElement from a data URL source and oversized (unallocatable) crop region
-PASS createImageBitmap with a bitmap HTMLImageElement source and sw set to 0
-PASS createImageBitmap with a bitmap HTMLImageElement source and sh set to 0
-PASS createImageBitmap with a bitmap HTMLImageElement source and oversized (unallocatable) crop region
-PASS createImageBitmap with a vector HTMLImageElement source and sw set to 0
-PASS createImageBitmap with a vector HTMLImageElement source and sh set to 0
-FAIL createImageBitmap with a vector HTMLImageElement source and oversized (unallocatable) crop region assert_throws: function "() => { throw e }" threw null, not an object
-PASS createImageBitmap with a bitmap SVGImageElement source and sw set to 0
-PASS createImageBitmap with a bitmap SVGImageElement source and sh set to 0
-PASS createImageBitmap with a bitmap SVGImageElement source and oversized (unallocatable) crop region
-PASS createImageBitmap with a vector SVGImageElement source and sw set to 0
-PASS createImageBitmap with a vector SVGImageElement source and sh set to 0
-FAIL createImageBitmap with a vector SVGImageElement source and oversized (unallocatable) crop region assert_throws: function "() => { throw e }" threw null, not an object
-PASS createImageBitmap with an OffscreenCanvas source and sw set to 0
-PASS createImageBitmap with an OffscreenCanvas source and sh set to 0
-PASS createImageBitmap with an OffscreenCanvas source and oversized (unallocatable) crop region
-PASS createImageBitmap with an ImageData source and sw set to 0
-PASS createImageBitmap with an ImageData source and sh set to 0
-PASS createImageBitmap with an ImageData source and oversized (unallocatable) crop region
-PASS createImageBitmap with an ImageBitmap source and sw set to 0
-PASS createImageBitmap with an ImageBitmap source and sh set to 0
-PASS createImageBitmap with an ImageBitmap source and oversized (unallocatable) crop region
-PASS createImageBitmap with a Blob source and sw set to 0
-PASS createImageBitmap with a Blob source and sh set to 0
-PASS createImageBitmap with a Blob source and oversized (unallocatable) crop region
-PASS createImageBitmap with undefined image source.
-PASS createImageBitmap with null image source.
-PASS createImageBitmap with CanvasRenderingContext2D image source.
-PASS createImageBitmap with WebGLRenderingContext image source.
-PASS createImageBitmap with Uint8Array image source.
-PASS createImageBitmap with ArrayBuffer image source.
-PASS createImageBitmap with empty image source.
-PASS createImageBitmap with empty video source.
-PASS createImageBitmap with an oversized canvas source.
-PASS createImageBitmap with an invalid OffscreenCanvas source.
-PASS createImageBitmap with an undecodable blob source.
-PASS createImageBitmap with a broken image source.
-PASS createImageBitmap with an available but undecodable image source.
-PASS createImageBitmap with an available but zero height image source.
-PASS createImageBitmap with an available but zero width image source.
-PASS createImageBitmap with a closed ImageBitmap.
-Harness: the test ran to completion.
-