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

Side by Side Diff: LayoutTests/fast/canvas/script-tests/canvas-path-addpath.js

Issue 178673002: Rename Path to Path2D (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@path
Patch Set: Merge to head which includes isPoint and addPath changes. 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 unified diff | Download patch
OLDNEW
1 description("Test addPath() method."); 1 description("Test addPath() method.");
2 var ctx = document.createElement('canvas').getContext('2d'); 2 var ctx = document.createElement('canvas').getContext('2d');
3 3
4 debug("Test addPath() with transform as identity matrix.") 4 debug("Test addPath() with transform as identity matrix.")
5 ctx.beginPath(); 5 ctx.beginPath();
6 var p1 = new Path(); 6 var p1 = new Path2D();
7 p1.rect(0,0,100,100); 7 p1.rect(0,0,100,100);
8 var p2 = new Path(); 8 var p2 = new Path2D();
9 p2.rect(0,100,100,100); 9 p2.rect(0,100,100,100);
10 var m = ctx.currentTransform; 10 var m = ctx.currentTransform;
11 p1.addPath(p2, m); 11 p1.addPath(p2, m);
12 ctx.fillStyle = 'yellow'; 12 ctx.fillStyle = 'yellow';
13 ctx.currentPath = p1; 13 ctx.currentPath = p1;
14 ctx.fill(); 14 ctx.fill();
15 var imageData = ctx.getImageData(0, 100, 100, 100); 15 var imageData = ctx.getImageData(0, 100, 100, 100);
16 var imgdata = imageData.data; 16 var imgdata = imageData.data;
17 shouldBe("imgdata[4]", "255"); 17 shouldBe("imgdata[4]", "255");
18 shouldBe("imgdata[5]", "255"); 18 shouldBe("imgdata[5]", "255");
19 shouldBe("imgdata[6]", "0"); 19 shouldBe("imgdata[6]", "0");
20 shouldBe("imgdata[7]", "255"); 20 shouldBe("imgdata[7]", "255");
21 debug(""); 21 debug("");
22 22
23 debug("Test addPath() with transform as translate(100, -100).") 23 debug("Test addPath() with transform as translate(100, -100).")
24 ctx.beginPath(); 24 ctx.beginPath();
25 var p3 = new Path(); 25 var p3 = new Path2D();
26 p3.rect(0,0,100,100); 26 p3.rect(0,0,100,100);
27 var p4 = new Path(); 27 var p4 = new Path2D();
28 p4.rect(0,100,100,100); 28 p4.rect(0,100,100,100);
29 m.a = 1; m.b = 0; 29 m.a = 1; m.b = 0;
30 m.c = 0; m.d = 1; 30 m.c = 0; m.d = 1;
31 m.e = 100; m.f = -100; 31 m.e = 100; m.f = -100;
32 p3.addPath(p4, m); 32 p3.addPath(p4, m);
33 ctx.fillStyle = 'yellow'; 33 ctx.fillStyle = 'yellow';
34 ctx.currentPath = p3; 34 ctx.currentPath = p3;
35 ctx.fill(); 35 ctx.fill();
36 imageData = ctx.getImageData(100, 0, 100, 100); 36 imageData = ctx.getImageData(100, 0, 100, 100);
37 imgdata = imageData.data; 37 imgdata = imageData.data;
38 shouldBe("imgdata[4]", "255"); 38 shouldBe("imgdata[4]", "255");
39 shouldBe("imgdata[5]", "255"); 39 shouldBe("imgdata[5]", "255");
40 shouldBe("imgdata[6]", "0"); 40 shouldBe("imgdata[6]", "0");
41 shouldBe("imgdata[7]", "255"); 41 shouldBe("imgdata[7]", "255");
42 debug(""); 42 debug("");
43 43
44 debug("Test addPath() with non-invertible transform.") 44 debug("Test addPath() with non-invertible transform.")
45 ctx.beginPath(); 45 ctx.beginPath();
46 var p5 = new Path(); 46 var p5 = new Path2D();
47 p5.rect(0,0,100,100); 47 p5.rect(0,0,100,100);
48 var p6 = new Path(); 48 var p6 = new Path2D();
49 p6.rect(100,100,100,100); 49 p6.rect(100,100,100,100);
50 m.a = 0; m.b = 0; 50 m.a = 0; m.b = 0;
51 m.c = 0; m.d = 0; 51 m.c = 0; m.d = 0;
52 m.e = 0; m.f = 0; 52 m.e = 0; m.f = 0;
53 p5.addPath(p6, m); 53 p5.addPath(p6, m);
54 ctx.fillStyle = 'yellow'; 54 ctx.fillStyle = 'yellow';
55 ctx.currentPath = p5; 55 ctx.currentPath = p5;
56 ctx.fill(); 56 ctx.fill();
57 imageData = ctx.getImageData(100, 100, 100, 100); 57 imageData = ctx.getImageData(100, 100, 100, 100);
58 imgdata = imageData.data; 58 imgdata = imageData.data;
59 shouldNotBe("imgdata[4]", "255"); 59 shouldNotBe("imgdata[4]", "255");
60 shouldNotBe("imgdata[5]", "255"); 60 shouldNotBe("imgdata[5]", "255");
61 shouldBe("imgdata[6]", "0"); 61 shouldBe("imgdata[6]", "0");
62 shouldNotBe("imgdata[7]", "255"); 62 shouldNotBe("imgdata[7]", "255");
63 debug(""); 63 debug("");
64 64
65 debug("Test addPath() with transform as null or invalid type.") 65 debug("Test addPath() with transform as null or invalid type.")
66 ctx.beginPath(); 66 ctx.beginPath();
67 var p7 = new Path(); 67 var p7 = new Path2D();
68 p7.rect(0,0,100,100); 68 p7.rect(0,0,100,100);
69 var p8 = new Path(); 69 var p8 = new Path2D();
70 p8.rect(100,100,100,100); 70 p8.rect(100,100,100,100);
71 p7.addPath(p8, null); 71 p7.addPath(p8, null);
72 p7.addPath(p8, []); 72 p7.addPath(p8, []);
73 p7.addPath(p8, {}); 73 p7.addPath(p8, {});
74 ctx.fillStyle = 'red'; 74 ctx.fillStyle = 'red';
75 ctx.currentPath = p7; 75 ctx.currentPath = p7;
76 ctx.fill(); 76 ctx.fill();
77 imageData = ctx.getImageData(100, 100, 100, 100); 77 imageData = ctx.getImageData(100, 100, 100, 100);
78 imgdata = imageData.data; 78 imgdata = imageData.data;
79 shouldBe("imgdata[4]", "255"); 79 shouldBe("imgdata[4]", "255");
80 shouldBe("imgdata[5]", "0"); 80 shouldBe("imgdata[5]", "0");
81 shouldBe("imgdata[6]", "0"); 81 shouldBe("imgdata[6]", "0");
82 shouldBe("imgdata[7]", "255"); 82 shouldBe("imgdata[7]", "255");
83 debug(""); 83 debug("");
84 84
85 debug("Test addPath() with path as null and invalid type"); 85 debug("Test addPath() with path as null and invalid type");
86 var p9 = new Path(); 86 var p9 = new Path2D();
87 p9.rect(0,0,100,100); 87 p9.rect(0,0,100,100);
88 shouldThrow("p7.addPath(null, m)"); 88 shouldThrow("p7.addPath(null, m)");
89 shouldThrow("p7.addPath([], m)"); 89 shouldThrow("p7.addPath([], m)");
90 shouldThrow("p7.addPath({}, m)"); 90 shouldThrow("p7.addPath({}, m)");
91 debug(""); 91 debug("");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698