OLD | NEW |
1 description("Test the behavior of currentPath in Canvas"); | 1 description("Test the behavior of currentPath in Canvas"); |
2 var ctx = document.createElement('canvas').getContext('2d'); | 2 var ctx = document.createElement('canvas').getContext('2d'); |
3 | 3 |
4 var testStrings = [ | 4 var testStrings = [ |
5 "ctx.isPointInPath(49,49)", | 5 "ctx.isPointInPath(49,49)", |
6 "ctx.isPointInPath(99,99)", | 6 "ctx.isPointInPath(99,99)", |
7 "ctx.isPointInPath(149,149)", | 7 "ctx.isPointInPath(149,149)", |
8 "ctx.isPointInPath(199,199)", | 8 "ctx.isPointInPath(199,199)", |
9 "ctx.isPointInPath(249,249)" | 9 "ctx.isPointInPath(249,249)" |
10 ]; | 10 ]; |
11 | 11 |
12 // Test collection of points. Each point has an offset of 50,50 to previous poin
t. | 12 // Test collection of points. Each point has an offset of 50,50 to previous poin
t. |
13 function testPointCollection(hitResults) { | 13 function testPointCollection(hitResults) { |
14 for (var i = 0; i < hitResults.length; i++) { | 14 for (var i = 0; i < hitResults.length; i++) { |
15 if (hitResults[i]) | 15 if (hitResults[i]) |
16 shouldBeTrue(testStrings[i]); | 16 shouldBeTrue(testStrings[i]); |
17 else | 17 else |
18 shouldBeFalse(testStrings[i]); | 18 shouldBeFalse(testStrings[i]); |
19 } | 19 } |
20 } | 20 } |
21 | 21 |
22 document.body.appendChild(ctx.canvas); | 22 document.body.appendChild(ctx.canvas); |
23 | 23 |
24 ctx.fillStyle = '#0f0'; | 24 ctx.fillStyle = '#0f0'; |
25 ctx.beginPath(); | 25 ctx.beginPath(); |
26 | 26 |
27 debug("Create path object, replace current context path with the path of this ob
ject."); | 27 debug("Create path object, replace current context path with the path of this ob
ject."); |
28 var p = new Path(); | 28 var p = new Path2D(); |
29 p.rect(0,0,200,200); | 29 p.rect(0,0,200,200); |
30 testPointCollection([false, false, false, false, false]); | 30 testPointCollection([false, false, false, false, false]); |
31 | 31 |
32 ctx.currentPath = p; | 32 ctx.currentPath = p; |
33 | 33 |
34 testPointCollection([true, true, true, true, false]); | 34 testPointCollection([true, true, true, true, false]); |
35 debug(""); | 35 debug(""); |
36 | 36 |
37 debug("Add new segment to context path and check that this is not added to the p
ath object (not live).") | 37 debug("Add new segment to context path and check that this is not added to the p
ath object (not live).") |
38 | 38 |
(...skipping 14 matching lines...) Expand all Loading... |
53 testPointCollection([false, false, true, true, true]); | 53 testPointCollection([false, false, true, true, true]); |
54 | 54 |
55 debug(""); | 55 debug(""); |
56 | 56 |
57 debug("Test that currentPath returns a path object."); | 57 debug("Test that currentPath returns a path object."); |
58 p = null; | 58 p = null; |
59 shouldBeNull("p"); | 59 shouldBeNull("p"); |
60 ctx.beginPath(); | 60 ctx.beginPath(); |
61 ctx.rect(0,0,200,200); | 61 ctx.rect(0,0,200,200); |
62 p = ctx.currentPath; | 62 p = ctx.currentPath; |
63 shouldBeType("p", "Path"); | 63 shouldBeType("p", "Path2D"); |
64 debug(""); | 64 debug(""); |
65 | 65 |
66 debug("Create context path and test that it exists."); | 66 debug("Create context path and test that it exists."); |
67 testPointCollection([true, true, true, true, false]); | 67 testPointCollection([true, true, true, true, false]); |
68 debug(""); | 68 debug(""); |
69 | 69 |
70 debug("Clear context path."); | 70 debug("Clear context path."); |
71 ctx.beginPath(); | 71 ctx.beginPath(); |
72 testPointCollection([false, false, false, false, false]); | 72 testPointCollection([false, false, false, false, false]); |
73 debug(""); | 73 debug(""); |
(...skipping 13 matching lines...) Expand all Loading... |
87 p = ctx.currentPath; | 87 p = ctx.currentPath; |
88 | 88 |
89 debug("Clear current path on object and check that it is cleaned up."); | 89 debug("Clear current path on object and check that it is cleaned up."); |
90 ctx.beginPath(); | 90 ctx.beginPath(); |
91 testPointCollection([false, false, false, false, false]); | 91 testPointCollection([false, false, false, false, false]); |
92 debug(""); | 92 debug(""); |
93 | 93 |
94 debug("Apply path back to context path.") | 94 debug("Apply path back to context path.") |
95 ctx.currentPath = p; | 95 ctx.currentPath = p; |
96 testPointCollection([true, true, false, true, true]); | 96 testPointCollection([true, true, false, true, true]); |
OLD | NEW |