summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/canvas/script-tests/canvas-isPointInPath-winding.js
blob: 7ed85ecfe0782537222c13252e003101b5a02539 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
description("Series of tests to ensure correct results of the winding rule in isPointInPath.");

var tmpimg = document.createElement('canvas');
tmpimg.width = 200;
tmpimg.height = 200;
ctx = tmpimg.getContext('2d');

// Execute test.
function prepareTestScenario() {
    debug('Testing default isPointInPath');
    ctx.beginPath();
    ctx.rect(0, 0, 100, 100);
    ctx.rect(25, 25, 50, 50);
    shouldBeTrue("ctx.isPointInPath(50, 50)");
    shouldBeFalse("ctx.isPointInPath(NaN, 50)");
    shouldBeFalse("ctx.isPointInPath(50, NaN)");
    debug('');

    debug('Testing nonzero isPointInPath');
    ctx.beginPath();
    ctx.rect(0, 0, 100, 100);
    ctx.rect(25, 25, 50, 50);
    shouldBeTrue("ctx.isPointInPath(50, 50, 'nonzero')");
    debug('');
	
    debug('Testing evenodd isPointInPath');
    ctx.beginPath();
    ctx.rect(0, 0, 100, 100);
    ctx.rect(25, 25, 50, 50);
    shouldBeFalse("ctx.isPointInPath(50, 50, 'evenodd')");
    debug('');

    // reset path in context
    ctx.beginPath();

    debug('Testing default isPointInPath with Path object');
    path = new Path2D();
    path.rect(0, 0, 100, 100);
    path.rect(25, 25, 50, 50);
    shouldBeTrue("ctx.isPointInPath(path, 50, 50)");
    shouldBeFalse("ctx.isPointInPath(path, NaN, 50)");
    shouldBeFalse("ctx.isPointInPath(path, 50, NaN)");
    debug('');

    debug('Testing nonzero isPointInPath with Path object');
    path = new Path2D();
    path.rect(0, 0, 100, 100);
    path.rect(25, 25, 50, 50);
    shouldBeTrue("ctx.isPointInPath(path, 50, 50, 'nonzero')");
    debug('');

    debug('Testing evenodd isPointInPath with Path object');
    path = new Path2D();
    path.rect(0, 0, 100, 100);
    path.rect(25, 25, 50, 50);
    shouldBeFalse("ctx.isPointInPath(path, 50, 50, 'evenodd')");
    debug('');

    debug('Testing invalid enumeration isPointInPath (w/ and w/o Path object');
    shouldThrow("ctx.isPointInPath(path, 50, 50, 'gazonk')");
    shouldThrow("ctx.isPointInPath(50, 50, 'gazonk')");
    debug('');

    debug('Testing null isPointInPath with Path object');
    path = null;
    shouldThrow("ctx.isPointInPath(null, 50, 50)");
    shouldThrow("ctx.isPointInPath(null, 50, 50, 'nonzero')");
    shouldThrow("ctx.isPointInPath(null, 50, 50, 'evenodd')");
    shouldThrow("ctx.isPointInPath(path, 50, 50)");
    shouldThrow("ctx.isPointInPath(path, 50, 50, 'nonzero')");
    shouldThrow("ctx.isPointInPath(path, 50, 50, 'evenodd')");
    debug('');

    debug('Testing invalid type isPointInPath with Path object');
    shouldThrow("ctx.isPointInPath([], 50, 50)");
    shouldThrow("ctx.isPointInPath([], 50, 50, 'nonzero')");
    shouldThrow("ctx.isPointInPath([], 50, 50, 'evenodd')");
    shouldThrow("ctx.isPointInPath({}, 50, 50)");
    shouldThrow("ctx.isPointInPath({}, 50, 50, 'nonzero')");
    shouldThrow("ctx.isPointInPath({}, 50, 50, 'evenodd')");
    debug('');
}

// Run test and allow variation of results.
prepareTestScenario();