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

Unified Diff: LayoutTests/fast/canvas/script-tests/canvas-extremely-large-dimensions.js

Issue 44253005: 2D Canvas: Refactor code re-attempting to allocate an imageBuffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@convertL
Patch Set: Merge with CL 74533004 to test on win and mac. Created 7 years, 1 month 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: LayoutTests/fast/canvas/script-tests/canvas-extremely-large-dimensions.js
diff --git a/LayoutTests/fast/canvas/script-tests/canvas-extremely-large-dimensions.js b/LayoutTests/fast/canvas/script-tests/canvas-extremely-large-dimensions.js
new file mode 100644
index 0000000000000000000000000000000000000000..7de4f41c63ce288558d40bd823282f682c3d5960
--- /dev/null
+++ b/LayoutTests/fast/canvas/script-tests/canvas-extremely-large-dimensions.js
@@ -0,0 +1,85 @@
+description("Series of tests to ensure correct behaviour when canvas size is extremely large.");
+var canvas = document.createElement('canvas')
+var ctx = canvas.getContext('2d');
+
+// WebIDL defines width and height as int. 2147483647 is int max.
+var extremelyLargeNumber = 2147483647;
+canvas.width = extremelyLargeNumber;
+canvas.height = extremelyLargeNumber;
+
+debug("check for crash on extremely large canvas size.");
+useCanvasContext(ctx);
+var imageData = ctx.getImageData(1, 1, 98, 98);
+var imgdata = imageData.data;
+// Blink returns zero color if the image buffer does not exist.
+shouldBe("imgdata[4]", "0");
+shouldBe("imgdata[5]", "0");
+shouldBe("imgdata[6]", "0");
+
+debug("check for crash after resetting to the same size.");
+canvas.width = extremelyLargeNumber;
+useCanvasContext(ctx);
+imageData = ctx.getImageData(1, 1, 98, 98);
+imgdata = imageData.data;
+shouldBe("imgdata[4]", "0");
+shouldBe("imgdata[5]", "0");
+shouldBe("imgdata[6]", "0");
+
+// googol is parsed to 0.
+var googol = Math.pow(10, 100);
+debug("check for crash after resizing to googol.");
+canvas.width = googol;
+canvas.height = googol;
+useCanvasContext(ctx);
+imageData = ctx.getImageData(1, 1, 98, 98);
+imgdata = imageData.data;
+shouldBe("imgdata[4]", "0");
+shouldBe("imgdata[5]", "0");
+shouldBe("imgdata[6]", "0");
+
+debug("check for crash after resetting to the same size.");
+canvas.width = googol;
+useCanvasContext(ctx);
+imageData = ctx.getImageData(1, 1, 98, 98);
+imgdata = imageData.data;
+shouldBe("imgdata[4]", "0");
+shouldBe("imgdata[5]", "0");
+shouldBe("imgdata[6]", "0");
+
+debug("check again for crash on extremely large canvas size.");
+canvas.width = extremelyLargeNumber;
+canvas.height = extremelyLargeNumber;
+useCanvasContext(ctx);
+imageData = ctx.getImageData(1, 1, 98, 98);
+imgdata = imageData.data;
+shouldBe("imgdata[4]", "0");
+shouldBe("imgdata[5]", "0");
+shouldBe("imgdata[6]", "0");
+
+function useCanvasContext(ctx) {
+ ctx.fillStyle = 'green';
+ ctx.fillRect(0, 0, 100, 100);
+ for(var i = 0; i < 100; i++) {
+ // This API tries to create an image buffer if the image buffer is not created.
+ ctx.getImageData(1, 1, 1, 1);
+ }
+ ctx.beginPath();
+ ctx.rect(0,0,100,100);
+ ctx.save();
+ ctx.fillStyle = 'red';
+ ctx.fillRect(0, 0, 100, 100);
+ ctx.restore();
+ ctx.fillStyle = 'green';
+ ctx.fill();
+}
+
+debug("after resizing to normal size, the canvas must be in a valid state.");
+canvas.width = 100;
+canvas.height = 100;
+ctx.fillStyle = 'blue';
+ctx.fillRect(0, 0, 100, 100);
+imageData = ctx.getImageData(1, 1, 98, 98);
+imgdata = imageData.data;
+shouldBe("imgdata[4]", "0");
+shouldBe("imgdata[5]", "0");
+shouldBe("imgdata[6]", "255");
« no previous file with comments | « LayoutTests/fast/canvas/canvas-extremely-large-dimensions-expected.txt ('k') | Source/core/html/HTMLCanvasElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698