Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / fast / canvas / script-tests / canvas-isPointInPath-winding.js
1 description("Series of tests to ensure correct results of the winding rule in isPointInPath.");
2
3 var tmpimg = document.createElement('canvas');
4 tmpimg.width = 200;
5 tmpimg.height = 200;
6 ctx = tmpimg.getContext('2d');
7
8 // Execute test.
9 function prepareTestScenario() {
10     debug('Testing default isPointInPath');
11     ctx.beginPath();
12     ctx.rect(0, 0, 100, 100);
13     ctx.rect(25, 25, 50, 50);
14     shouldBeTrue("ctx.isPointInPath(50, 50)");
15     shouldBeFalse("ctx.isPointInPath(NaN, 50)");
16     shouldBeFalse("ctx.isPointInPath(50, NaN)");
17     debug('');
18
19     debug('Testing nonzero isPointInPath');
20     ctx.beginPath();
21     ctx.rect(0, 0, 100, 100);
22     ctx.rect(25, 25, 50, 50);
23     shouldBeTrue("ctx.isPointInPath(50, 50, 'nonzero')");
24     debug('');
25         
26     debug('Testing evenodd isPointInPath');
27     ctx.beginPath();
28     ctx.rect(0, 0, 100, 100);
29     ctx.rect(25, 25, 50, 50);
30     shouldBeFalse("ctx.isPointInPath(50, 50, 'evenodd')");
31     debug('');
32
33     // reset path in context
34     ctx.beginPath();
35
36     debug('Testing default isPointInPath with Path object');
37     path = new Path2D();
38     path.rect(0, 0, 100, 100);
39     path.rect(25, 25, 50, 50);
40     shouldBeTrue("ctx.isPointInPath(path, 50, 50)");
41     shouldBeFalse("ctx.isPointInPath(path, NaN, 50)");
42     shouldBeFalse("ctx.isPointInPath(path, 50, NaN)");
43     debug('');
44
45     debug('Testing nonzero isPointInPath with Path object');
46     path = new Path2D();
47     path.rect(0, 0, 100, 100);
48     path.rect(25, 25, 50, 50);
49     shouldBeTrue("ctx.isPointInPath(path, 50, 50, 'nonzero')");
50     debug('');
51
52     debug('Testing evenodd isPointInPath with Path object');
53     path = new Path2D();
54     path.rect(0, 0, 100, 100);
55     path.rect(25, 25, 50, 50);
56     shouldBeFalse("ctx.isPointInPath(path, 50, 50, 'evenodd')");
57     debug('');
58
59     debug('Testing invalid enumeration isPointInPath (w/ and w/o Path object');
60     shouldThrow("ctx.isPointInPath(path, 50, 50, 'gazonk')");
61     shouldThrow("ctx.isPointInPath(50, 50, 'gazonk')");
62     debug('');
63
64     debug('Testing invalid type isPointInPath with Path object');
65     shouldThrow("ctx.isPointInPath(null, 50, 50)");
66     shouldThrow("ctx.isPointInPath(null, 50, 50, 'nonzero')");
67     shouldThrow("ctx.isPointInPath(null, 50, 50, 'evenodd')");
68     shouldThrow("ctx.isPointInPath(null, 50, 50, null)");
69     shouldThrow("ctx.isPointInPath(path, 50, 50, null)");
70     shouldThrow("ctx.isPointInPath(undefined, 50, 50)");
71     shouldThrow("ctx.isPointInPath(undefined, 50, 50, 'nonzero')");
72     shouldThrow("ctx.isPointInPath(undefined, 50, 50, 'evenodd')");
73     shouldThrow("ctx.isPointInPath(undefined, 50, 50, undefined)");
74     shouldThrow("ctx.isPointInPath(path, 50, 50, undefined)");
75     shouldThrow("ctx.isPointInPath([], 50, 50)");
76     shouldThrow("ctx.isPointInPath([], 50, 50, 'nonzero')");
77     shouldThrow("ctx.isPointInPath([], 50, 50, 'evenodd')");
78     shouldThrow("ctx.isPointInPath({}, 50, 50)");
79     shouldThrow("ctx.isPointInPath({}, 50, 50, 'nonzero')");
80     shouldThrow("ctx.isPointInPath({}, 50, 50, 'evenodd')");
81     debug('');
82
83     debug("Testing extremely large scale")
84     ctx.save();
85     ctx.scale(Number.MAX_VALUE, Number.MAX_VALUE);
86     ctx.beginPath();
87     ctx.rect(-10, -10, 20, 20);
88     shouldBeTrue("ctx.isPointInPath(0, 0, 'nonzero')");
89     shouldBeTrue("ctx.isPointInPath(0, 0, 'evenodd')");
90     ctx.restore();
91
92     debug("Check with non-invertible ctm.")
93     ctx.save();
94     ctx.scale(0, 0);
95     ctx.beginPath();
96     ctx.rect(-10, -10, 20, 20);
97     shouldBeFalse("ctx.isPointInPath(0, 0, 'nonzero')");
98     shouldBeFalse("ctx.isPointInPath(0, 0, 'evenodd')");
99     ctx.restore();
100 }
101
102 // Run test and allow variation of results.
103 prepareTestScenario();