Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(702)

Unified Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DAPITest.cpp

Issue 1775613002: Throw a RangeError exception from get/createImageData when out of memory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix assert in test Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DAPITest.cpp
diff --git a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DAPITest.cpp b/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DAPITest.cpp
index ef9e97fb65da0228c294700779f294648624e49d..905931fdd776f23564ee632fdfa78f33e9483458 100644
--- a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DAPITest.cpp
+++ b/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DAPITest.cpp
@@ -216,7 +216,8 @@ TEST_F(CanvasRenderingContext2DAPITest, CreateImageData)
// createImageData(imageData) should create a new ImageData of the same size as 'imageData'
// but filled with transparent black
- ImageData* sameSizeImageData = context2d()->createImageData(imageData);
+ ImageData* sameSizeImageData = context2d()->createImageData(imageData, exceptionState);
+ EXPECT_FALSE(exceptionState.hadException());
EXPECT_EQ(100, sameSizeImageData->width());
EXPECT_EQ(50, sameSizeImageData->height());
EXPECT_EQ(0, sameSizeImageData->data()->data()[32]);
@@ -238,6 +239,26 @@ TEST_F(CanvasRenderingContext2DAPITest, CreateImageData)
EXPECT_EQ((unsigned)800, imgdata4->data()->length());
}
+TEST_F(CanvasRenderingContext2DAPITest, CreateImageDataTooBig)
+{
+ createContext(NonOpaque);
+ TrackExceptionState exceptionState;
+ ImageData* tooBigImageData = context2d()->createImageData(1000000, 1000000, exceptionState);
+ EXPECT_EQ(nullptr, tooBigImageData);
+ EXPECT_TRUE(exceptionState.hadException());
+ EXPECT_EQ(V8RangeError, exceptionState.code());
+}
+
+TEST_F(CanvasRenderingContext2DAPITest, GetImageDataTooBig)
+{
+ createContext(NonOpaque);
+ TrackExceptionState exceptionState;
+ ImageData* imageData = context2d()->getImageData(0, 0, 1000000, 1000000, exceptionState);
+ EXPECT_EQ(nullptr, imageData);
+ EXPECT_TRUE(exceptionState.hadException());
+ EXPECT_EQ(V8RangeError, exceptionState.code());
+}
+
void resetCanvasForAccessibilityRectTest(HTMLDocument& document)
{
document.documentElement()->setInnerHTML(

Powered by Google App Engine
This is Rietveld 408576698