Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / canvas / script-tests / canvas-currentPath.js
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');
5
6 var testStrings = [
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)"
12 ];
13
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++) {
17         if (hitResults[i])
18             shouldBeTrue(testStrings[i]);
19         else
20             shouldBeFalse(testStrings[i]);
21     }
22 }
23
24 document.body.appendChild(ctx.canvas);
25
26 ctx.fillStyle = '#0f0';
27 ctx.beginPath();
28
29 debug("Create path object, replace current context path with the path of this object.");
30 var p = new Path2D();
31 p.rect(0,0,200,200);
32 testPointCollection([false, false, false, false, false]);
33
34 ctx.currentPath = p;
35
36 testPointCollection([true, true, true, true, false]);
37 debug("");
38
39 debug("Add new segment to context path and check that this is not added to the path object (not live).")
40
41 ctx.rect(50,50,200,200);
42 testPointCollection([true, true, true, true, true]);
43
44 ctx.currentPath = p;
45
46 testPointCollection([true, true, true, true, false]);
47 debug("");
48
49 debug("Test that path object can get applied to transformed context, respecting the CTM.");
50
51 ctx.beginPath();
52 ctx.translate(100,100);
53 ctx.currentPath = p;
54 ctx.translate(-100,-100);
55 testPointCollection([false, false, true, true, true]);
56
57 debug("");
58
59 debug("Test that currentPath returns a path object.");
60 p = null;
61 shouldBeNull("p");
62 ctx.beginPath();
63 ctx.rect(0,0,200,200);
64 p = ctx.currentPath;
65 shouldBeType("p", "Path2D");
66 debug("");
67
68 debug("Create context path and test that it exists.");
69 testPointCollection([true, true, true, true, false]);
70 debug("");
71
72 debug("Clear context path.");
73 ctx.beginPath();
74 testPointCollection([false, false, false, false, false]);
75 debug("");
76
77 debug("Apply stored (non-live) path object back to context.");
78 ctx.currentPath = p;
79 testPointCollection([true, true, true, true, false]);
80 debug("");
81
82 debug("Transform CTM in the process of adding segments to context path. Check that currentPath's path object archive these transformations.");
83 ctx.beginPath();
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]);
89 p = ctx.currentPath;
90
91 debug("Clear current path on object and check that it is cleaned up.");
92 ctx.beginPath();
93 testPointCollection([false, false, false, false, false]);
94 debug("");
95
96 debug("Apply path back to context path.")
97 ctx.currentPath = p;
98 testPointCollection([true, true, false, true, true]);