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

Unified Diff: LayoutTests/fast/canvas/canvas-lose-restore-max-int-size.html

Issue 211503006: Implementation of 2D canvas context lost/restored events (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase Created 6 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: LayoutTests/fast/canvas/canvas-lose-restore-max-int-size.html
diff --git a/LayoutTests/fast/canvas/script-tests/canvas-extremely-large-dimensions.js b/LayoutTests/fast/canvas/canvas-lose-restore-max-int-size.html
similarity index 13%
rename from LayoutTests/fast/canvas/script-tests/canvas-extremely-large-dimensions.js
rename to LayoutTests/fast/canvas/canvas-lose-restore-max-int-size.html
index 7de4f41c63ce288558d40bd823282f682c3d5960..ec412cb3393c4658b566bfbe61225df7a71243fe 100644
--- a/LayoutTests/fast/canvas/script-tests/canvas-extremely-large-dimensions.js
+++ b/LayoutTests/fast/canvas/canvas-lose-restore-max-int-size.html
@@ -1,85 +1,71 @@
-description("Series of tests to ensure correct behaviour when canvas size is extremely large.");
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+</head>
+<body>
+<script>
+description("Tests to ensure correct behaviour of canvas loss and restoration when size is extremely large then, restored to a reasonable value.");
+
+if (window.testRunner) {
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+}
+
var canvas = document.createElement('canvas')
+canvas.addEventListener('contextlost', contextLost);
+canvas.addEventListener('contextrestored', contextRestored);
var ctx = canvas.getContext('2d');
+var lostEventHasFired = false;
+verifyContextLost(false);
// 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.");
+verifyContextLost(true);
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");
+verifyContextLost(true);
+canvas.width = 100;
+canvas.height = 100;
+verifyContextLost(true); // Restoration is async.
+// Restore a sane dimension
-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 verifyContextLost(shouldBeLost) {
+ // Verify context loss experimentally as well as isContextLost()
+ ctx.fillStyle = '#0f0';
+ ctx.fillRect(0, 0, 1, 1);
+ contextLostTest = ctx.getImageData(0, 0, 1, 1).data[1] == 0;
+ if (shouldBeLost) {
+ shouldBeTrue('contextLostTest');
+ shouldBeTrue('ctx.isContextLost()');
+ } else {
+ shouldBeFalse('contextLostTest');
+ shouldBeFalse('ctx.isContextLost()');
+ }
+}
-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);
+function contextLost() {
+ if (lostEventHasFired) {
+ testFailed('Context lost event was dispatched more than once.');
+ } else {
+ testPassed('Graphics context lost event dispatched.');
}
- 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();
+ lostEventHasFired = true;
+ verifyContextLost(true);
}
-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");
+function contextRestored() {
+ if (lostEventHasFired) {
+ testPassed('Context restored event dispatched after context lost.');
+ } else {
+ testFailed('Context restored event was dispatched before a context lost event.');
+ }
+ verifyContextLost(false);
+ if (window.testRunner) {
+ testRunner.notifyDone();
+ }
+}
+</script>
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698