Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-behaviour.html |
| diff --git a/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-behaviour.html b/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-behaviour.html |
| index b2be952f4056c551d872d882d01f4ef6ad8b2b15..22d3819b24f07c3245e7637796de93c66c808162 100644 |
| --- a/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-behaviour.html |
| +++ b/third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-behaviour.html |
| @@ -1,2 +1,74 @@ |
| -<script src="../../resources/js-test.js"></script> |
| -<script src="canvas-pattern-behaviour.js"></script> |
| +<script src="../../resources/testharness.js"></script> |
| +<script src="../../resources/testharnessreport.js"></script> |
| +<script> |
| + |
| +function pixelShouldBe(x, y, color) { |
| + assert_array_equals(context.getImageData(x, y, 1, 1).data, color); |
| +} |
| + |
| +function createCanvasImage(width, height, color) { |
| + var c = document.createElement("canvas"); |
| + c.width = width; |
| + c.height = height; |
| + var context = c.getContext("2d"); |
| + context.fillStyle = color; |
| + context.fillRect(0, 0, width, height); |
| + return c; |
| +} |
| + |
| +var green1x1 = createCanvasImage(1, 1, "green"); |
| +var green100x50 = createCanvasImage(100, 50, "green"); |
| + |
| +var canvas = document.createElement("canvas"); |
| +canvas.width = 100; |
| +canvas.height = 50; |
| +var context = canvas.getContext("2d"); |
| +context.fillStyle="red"; |
| +context.fillRect(0, 0, 100, 50); |
| + |
| +test(function () { |
| + var pattern = context.createPattern(green1x1, null); |
|
Justin Novosad
2017/02/16 15:50:27
inconsistent indentation
|
| + context.fillStyle = pattern; |
| + context.fillRect(0, 0, 100, 50); |
| + pixelShouldBe(1, 1, [0, 128, 0, 255]); |
| + pixelShouldBe(98, 1, [0, 128, 0, 255]); |
| + pixelShouldBe(1, 48, [0, 128, 0, 255]); |
| + pixelShouldBe(98, 48, [0, 128, 0, 255]); |
| + |
| + assert_throws(null, function() {context.createPattern(green1x1, 'null');}); |
| + assert_throws(null, function() {context.createPattern(green1x1, undefined);}); |
| + assert_throws(null, function() {context.createPattern(green1x1, 'undefined');}); |
| + assert_throws(null, function() {context.createPattern(green1x1, {toString:function(){ return null;}});}); |
| + assert_throws(null, function() {context.createPattern(null, '');}); |
| + assert_throws(null, function() {context.createPattern(undefined, '');}); |
| + assert_throws(null, function() {context.createPattern({}, '');}); |
| + assert_throws(null, function() {context.createPattern([], '');}); |
| + |
| + pattern = context.createPattern(green1x1, ''); |
| + context.fillStyle = pattern; |
| + context.fillRect(0, 0, 100, 50); |
| + pixelShouldBe(1, 1, [0, 128, 0, 255]); |
| + pixelShouldBe(98, 1, [0, 128, 0, 255]); |
| + pixelShouldBe(1, 48, [0, 128, 0, 255]); |
| + pixelShouldBe(98, 48, [0, 128, 0, 255]); |
| + |
| + pattern = context.createPattern(green1x1, {toString:function(){ return 'repeat';}}); |
| + context.fillStyle = pattern; |
| + context.fillRect(0, 0, 100, 50); |
| + pixelShouldBe(1, 1, [0, 128, 0, 255]); |
| + pixelShouldBe(98, 1, [0, 128, 0, 255]); |
| + pixelShouldBe(1, 48, [0, 128, 0, 255]); |
| + pixelShouldBe(98, 48, [0, 128, 0, 255]); |
| + |
| + context.fillStyle = "green"; |
| + context.fillRect(0, 0, 50, 50); |
| + var pattern = context.createPattern(green100x50, "no-repeat"); |
| + context.fillStyle = pattern; |
| + context.translate(50, 0); |
| + context.fillRect(-50, 0, 100, 50); |
| + pixelShouldBe(1, 1, [0, 128, 0, 255]); |
| + pixelShouldBe(98, 1, [0, 128, 0, 255]); |
| + pixelShouldBe(1, 48, [0, 128, 0, 255]); |
| + pixelShouldBe(98, 48, [0, 128, 0, 255]); |
| + }, "Test the behavior of pattern use and construction."); |
| +</script> |