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

Unified Diff: LayoutTests/fast/canvas/script-tests/canvas-pattern-set-transform.js

Issue 527193002: Support CanvasPattern.setTransform (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: putting under a runtime flag Created 6 years, 3 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/script-tests/canvas-pattern-set-transform.js
diff --git a/LayoutTests/fast/canvas/script-tests/canvas-pattern-set-transform.js b/LayoutTests/fast/canvas/script-tests/canvas-pattern-set-transform.js
new file mode 100644
index 0000000000000000000000000000000000000000..76fa74096ac93fb5f2bd3dcc9218d1c5ab227638
--- /dev/null
+++ b/LayoutTests/fast/canvas/script-tests/canvas-pattern-set-transform.js
@@ -0,0 +1,61 @@
+description("Test for supporting setTransform on canvas patterns");
+
+function pixelValueAt(context, x, y) {
+ var imageData = context.getImageData(x, y, 1, 1);
+ return imageData.data;
+}
+
+function pixelToString(p) {
+ return "[" + p[0] + ", " + p[1] + ", " + p[2] + ", " + p[3] + "]"
+}
+
+function pixelShouldBe(context, x, y, expectedPixelString) {
+ var pixel = pixelValueAt(context, x, y);
+ var expectedPixel = eval(expectedPixelString);
+
+ var pixelString = "pixel " + x + ", " + y;
+ if (areArraysEqual(pixel, expectedPixel)) {
+ testPassed(pixelString + " is " + pixelToString(pixel));
+ } else {
+ testFailed(pixelString + " should be " + pixelToString(expectedPixel) + " was " + pixelToString(pixel));
+ }
+}
+
+function fillWithColor(context, canvas, color1, color2) {
+ context.save();
+ context.fillStyle = color1;
+ context.fillRect(0, 0, canvas.width / 2, canvas.height);
+ context.fillStyle = color2;
+ context.fillRect(canvas.width / 2, 0, canvas.width / 2, canvas.height);
+ context.restore();
+}
+
+var canvas = document.createElement("canvas");
+canvas.height = 100;
+canvas.width = 100;
+canvas.style.height = "100";
+canvas.style.width = "100";
+
+document.body.appendChild(canvas);
+
+var patternImage = document.createElement("canvas");
+patternImage.height = 10;
+patternImage.width = 20;
+var patternImageCtx = patternImage.getContext('2d');
+fillWithColor(patternImageCtx, patternImage, "red", "green");
+var greenPixel = pixelValueAt(patternImageCtx, 10, 0);
+
+
+var ctx = canvas.getContext('2d');
+var pattern = ctx.createPattern(patternImage, "repeat-x");
+var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg");
+var matrix = svgElement.createSVGMatrix();
+matrix = matrix.translate(10, 0);
+pattern.setTransform(matrix);
+
+fillWithColor(ctx, canvas, "blue", "blue");
+
+ctx.fillStyle = pattern;
+ctx.translate(20, 20);
+ctx.fillRect(0, 0, 10, 10);
+pixelShouldBe(ctx, 20, 20, "greenPixel");

Powered by Google App Engine
This is Rietveld 408576698