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

Side by Side Diff: third_party/WebKit/LayoutTests/fast/canvas/canvas-pattern-behaviour.html

Issue 2689243002: Use testharness.js instead of js-test.js in LayoutTests/fast/canvas tests. (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
OLDNEW
1 <script src="../../resources/js-test.js"></script> 1 <script src="../../resources/testharness.js"></script>
2 <script src="canvas-pattern-behaviour.js"></script> 2 <script src="../../resources/testharnessreport.js"></script>
3 <script>
4
5 function pixelShouldBe(x, y, color) {
6 assert_array_equals(context.getImageData(x, y, 1, 1).data, color);
7 }
8
9 function createCanvasImage(width, height, color) {
10 var c = document.createElement("canvas");
11 c.width = width;
12 c.height = height;
13 var context = c.getContext("2d");
14 context.fillStyle = color;
15 context.fillRect(0, 0, width, height);
16 return c;
17 }
18
19 var green1x1 = createCanvasImage(1, 1, "green");
20 var green100x50 = createCanvasImage(100, 50, "green");
21
22 var canvas = document.createElement("canvas");
23 canvas.width = 100;
24 canvas.height = 50;
25 var context = canvas.getContext("2d");
26 context.fillStyle="red";
27 context.fillRect(0, 0, 100, 50);
28
29 test(function () {
30 var pattern = context.createPattern(green1x1, null);
Justin Novosad 2017/02/16 15:50:27 inconsistent indentation
31 context.fillStyle = pattern;
32 context.fillRect(0, 0, 100, 50);
33 pixelShouldBe(1, 1, [0, 128, 0, 255]);
34 pixelShouldBe(98, 1, [0, 128, 0, 255]);
35 pixelShouldBe(1, 48, [0, 128, 0, 255]);
36 pixelShouldBe(98, 48, [0, 128, 0, 255]);
37
38 assert_throws(null, function() {context.createPattern(green1x1, 'null'); });
39 assert_throws(null, function() {context.createPattern(green1x1, undefine d);});
40 assert_throws(null, function() {context.createPattern(green1x1, 'undefin ed');});
41 assert_throws(null, function() {context.createPattern(green1x1, {toStrin g:function(){ return null;}});});
42 assert_throws(null, function() {context.createPattern(null, '');});
43 assert_throws(null, function() {context.createPattern(undefined, '');});
44 assert_throws(null, function() {context.createPattern({}, '');});
45 assert_throws(null, function() {context.createPattern([], '');});
46
47 pattern = context.createPattern(green1x1, '');
48 context.fillStyle = pattern;
49 context.fillRect(0, 0, 100, 50);
50 pixelShouldBe(1, 1, [0, 128, 0, 255]);
51 pixelShouldBe(98, 1, [0, 128, 0, 255]);
52 pixelShouldBe(1, 48, [0, 128, 0, 255]);
53 pixelShouldBe(98, 48, [0, 128, 0, 255]);
54
55 pattern = context.createPattern(green1x1, {toString:function(){ return ' repeat';}});
56 context.fillStyle = pattern;
57 context.fillRect(0, 0, 100, 50);
58 pixelShouldBe(1, 1, [0, 128, 0, 255]);
59 pixelShouldBe(98, 1, [0, 128, 0, 255]);
60 pixelShouldBe(1, 48, [0, 128, 0, 255]);
61 pixelShouldBe(98, 48, [0, 128, 0, 255]);
62
63 context.fillStyle = "green";
64 context.fillRect(0, 0, 50, 50);
65 var pattern = context.createPattern(green100x50, "no-repeat");
66 context.fillStyle = pattern;
67 context.translate(50, 0);
68 context.fillRect(-50, 0, 100, 50);
69 pixelShouldBe(1, 1, [0, 128, 0, 255]);
70 pixelShouldBe(98, 1, [0, 128, 0, 255]);
71 pixelShouldBe(1, 48, [0, 128, 0, 255]);
72 pixelShouldBe(98, 48, [0, 128, 0, 255]);
73 }, "Test the behavior of pattern use and construction.");
74 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698