summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/script-tests
diff options
context:
space:
mode:
authorcommit-queue@webkit.org <commit-queue@webkit.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538>2010-11-30 16:29:30 +0000
committercommit-queue@webkit.org <commit-queue@webkit.org@bbb929c8-8fbe-4397-9dbb-9b2b20218538>2010-11-30 16:29:30 +0000
commitbcf2d940023487e11893a580f62ba8c44f23c95f (patch)
treed4a8124511dd60c38e7009be32e3d77f0331808e /third_party/WebKit/LayoutTests/fast/canvas/script-tests
parent6bc1016f79d6f68f583d7d37192bd7587c19cf34 (diff)
downloadchromium_src-bcf2d940023487e11893a580f62ba8c44f23c95f.zip
chromium_src-bcf2d940023487e11893a580f62ba8c44f23c95f.tar.gz
chromium_src-bcf2d940023487e11893a580f62ba8c44f23c95f.tar.bz2
2010-11-30 Helder Correia <helder@sencha.com>
Reviewed by Kenneth Rohde Christiansen. New fast canvas test to ensure correct behavior of canvas with drawImage + shadow after scaling https://bugs.webkit.org/show_bug.cgi?id=50202 The shadow offsets of the drawn images must not be affected by the scaling transformation. * fast/canvas/canvas-scale-drawImage-shadow-expected.txt: Added. * fast/canvas/canvas-scale-drawImage-shadow.html: Added. * fast/canvas/script-tests/canvas-scale-drawImage-shadow.js: Added. git-svn-id: svn://svn.chromium.org/blink/trunk@72917 bbb929c8-8fbe-4397-9dbb-9b2b20218538
Diffstat (limited to 'third_party/WebKit/LayoutTests/fast/canvas/script-tests')
-rw-r--r--third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-scale-drawImage-shadow.js155
1 files changed, 155 insertions, 0 deletions
diff --git a/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-scale-drawImage-shadow.js b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-scale-drawImage-shadow.js
new file mode 100644
index 0000000..a5c5e77
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-scale-drawImage-shadow.js
@@ -0,0 +1,155 @@
+description("Ensure correct behavior of canvas with drawImage+shadow after scaling. A blue and red checkered pattern should be displayed.");
+
+function print(message, color)
+{
+ var paragraph = document.createElement("div");
+ paragraph.appendChild(document.createTextNode(message));
+ paragraph.style.fontFamily = "monospace";
+ if (color)
+ paragraph.style.color = color;
+ document.getElementById("console").appendChild(paragraph);
+}
+
+function shouldBeAround(a, b)
+{
+ var evalA;
+ try {
+ evalA = eval(a);
+ } catch(e) {
+ evalA = e;
+ }
+
+ if (Math.abs(evalA - b) < 10)
+ print("PASS " + a + " is around " + b , "green")
+ else
+ print("FAIL " + a + " is not around " + b + " (actual: " + evalA + ")", "red");
+}
+
+// Create auxiliary canvas to draw to and create an image from.
+// This is done instead of simply loading an image from the file system
+// because that would throw a SECURITY_ERR DOM Exception.
+var aCanvas = document.createElement('canvas');
+aCanvas.setAttribute('width', '50');
+aCanvas.setAttribute('height', '50');
+var aCtx = aCanvas.getContext('2d');
+
+// Fill the same canvas.
+aCtx.fillStyle = 'rgba(0, 0, 255, 1)';
+aCtx.fillRect(0, 0, 50, 50);
+
+// Create the image object to be drawn on the master canvas.
+var img = new Image();
+img.onload = drawImageToCanvasAndCheckPixels;
+img.src = aCanvas.toDataURL(); // set a data URI of the base64 encoded image as the source
+
+// Create master canvas.
+var canvas = document.createElement('canvas');
+document.body.appendChild(canvas);
+canvas.setAttribute('width', '1000');
+canvas.setAttribute('height', '1000');
+var ctx = canvas.getContext('2d');
+
+function drawImageToCanvasAndCheckPixels() {
+ ctx.scale(2, 2);
+ ctx.shadowOffsetX = 100;
+ ctx.shadowOffsetY = 100;
+ ctx.fillStyle = 'rgba(0, 0, 255, 1)';
+
+ ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
+ ctx.drawImage(img, 50, 50);
+
+ ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
+ ctx.drawImage(img, 50, 150);
+
+ ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
+ ctx.shadowBlur = 10;
+ ctx.drawImage(img, 150, 50);
+
+ ctx.shadowColor = 'rgba(255, 0, 0, 0.3)';
+ ctx.drawImage(img, 150, 150);
+
+ checkPixels();
+}
+
+var d; // imageData.data
+
+function checkPixels() {
+
+ // Verify solid shadow.
+ d = ctx.getImageData(205, 205, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBe('d[3]', '255');
+
+ d = ctx.getImageData(295, 295, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBe('d[3]', '255');
+
+ d = ctx.getImageData(205, 295, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBe('d[3]', '255');
+
+ // Verify solid alpha shadow.
+ d = ctx.getImageData(201, 401, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBeAround('d[3]', '76');
+
+ d = ctx.getImageData(290, 401, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBeAround('d[3]', '76');
+
+ d = ctx.getImageData(290, 498, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBeAround('d[3]', '76');
+
+ // Verify blurry shadow.
+ d = ctx.getImageData(398, 205, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBeAround('d[3]', '83');
+
+ d = ctx.getImageData(501, 205, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBeAround('d[3]', '83');
+
+ d = ctx.getImageData(500, 300, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBeAround('d[3]', '53');
+
+ // Verify blurry alpha shadow.
+ d = ctx.getImageData(398, 405, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBeAround('d[3]', '24');
+
+ d = ctx.getImageData(405, 501, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBeAround('d[3]', '24');
+
+ d = ctx.getImageData(405, 501, 1, 1).data;
+ shouldBe('d[0]', '255');
+ shouldBe('d[1]', '0');
+ shouldBe('d[2]', '0');
+ shouldBeAround('d[3]', '24');
+}
+
+var successfullyParsed = true;