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

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: Use extremely instead of insanely. Amend test a bit. 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..4043d94fe76fc593672c60db65d07f3279f4a231
--- /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');
+
+// IDL defines width and height as int. 2147483647 is int max.
+var extremelyLargeNumber = 2147483647;
+canvas.width = extremelyLargeNumber;
+canvas.height = extremelyLargeNumber;
+
+debug("check whether crash or not with extremely large size.");
Stephen White 2013/11/18 21:42:15 Nit: check for crash on extremely large canvas siz
+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 whether crash after reset to the same size.");
Stephen White 2013/11/18 21:42:15 Nit: check for crash after resetting to the same s
+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 whether crash after resize to googol.");
Stephen White 2013/11/18 21:42:15 Nit: check for crash after resizing to googol. (h
+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 whether crash after reset to the same size.");
Stephen White 2013/11/18 21:42:15 Nit: check for crash after resetting to the same s
+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 whether crash or not with extremely large size.");
Stephen White 2013/11/18 21:42:15 Nit: check again for crash with extremely large si
+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 < 10000; i++) {
Stephen White 2013/11/18 21:42:15 I'm a little nervous about 10,000 calls to getImag
+ // This API tries to create an image buffer if the image buffer is not created.
+ ctx.getImageData(1, 1, 98, 98);
+ }
+ 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 resize to normal size, canvas must be in valid state.");
Stephen White 2013/11/18 21:42:15 Nit: after resizing to normal size, the canvas mus
+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