1 description("Test the behavior of currentPath in Canvas");
2 var c = document.createElement('canvas');
3 document.body.appendChild(c);
4 var ctx = c.getContext('2d');
7 "ctx.isPointInPath(49,49)",
8 "ctx.isPointInPath(99,99)",
9 "ctx.isPointInPath(149,149)",
10 "ctx.isPointInPath(199,199)",
11 "ctx.isPointInPath(249,249)"
14 // Test collection of points. Each point has an offset of 50,50 to previous point.
15 function testPointCollection(hitResults) {
16 for (var i = 0; i < hitResults.length; i++) {
18 shouldBeTrue(testStrings[i]);
20 shouldBeFalse(testStrings[i]);
24 document.body.appendChild(ctx.canvas);
26 ctx.fillStyle = '#0f0';
29 debug("Create path object, replace current context path with the path of this object.");
32 testPointCollection([false, false, false, false, false]);
36 testPointCollection([true, true, true, true, false]);
39 debug("Add new segment to context path and check that this is not added to the path object (not live).")
41 ctx.rect(50,50,200,200);
42 testPointCollection([true, true, true, true, true]);
46 testPointCollection([true, true, true, true, false]);
49 debug("Test that path object can get applied to transformed context, respecting the CTM.");
52 ctx.translate(100,100);
54 ctx.translate(-100,-100);
55 testPointCollection([false, false, true, true, true]);
59 debug("Test that currentPath returns a path object.");
63 ctx.rect(0,0,200,200);
65 shouldBeType("p", "Path2D");
68 debug("Create context path and test that it exists.");
69 testPointCollection([true, true, true, true, false]);
72 debug("Clear context path.");
74 testPointCollection([false, false, false, false, false]);
77 debug("Apply stored (non-live) path object back to context.");
79 testPointCollection([true, true, true, true, false]);
82 debug("Transform CTM in the process of adding segments to context path. Check that currentPath's path object archive these transformations.");
84 ctx.rect(0,0,100,100);
85 ctx.translate(150,150);
86 ctx.rect(0,0,100,100);
87 ctx.translate(-150,-150);
88 testPointCollection([true, true, false, true, true]);
91 debug("Clear current path on object and check that it is cleaned up.");
93 testPointCollection([false, false, false, false, false]);
96 debug("Apply path back to context path.")
98 testPointCollection([true, true, false, true, true]);