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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
<!DOCTYPE html>
<title>HitRegion Clip Test</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="./resources/test-helpers.js"></script>
<canvas width="400" height="400"></canvas>
<style>
body {
margin : 0px;
padding : 0px;
}
</style>
<script>
var canvas = document.querySelector('canvas');
var context = canvas.getContext('2d');
function create_simple_rect_region_with_clip() {
context.clearRect(0, 0, 400, 400);
context.save();
context.beginPath();
context.rect(0, 0, 100, 100);
context.clip();
context.beginPath();
context.rect(50, 50, 100, 100);
context.fill();
context.addHitRegion({ id : 'clip' });
context.restore();
}
function create_non_rect_region_with_clip() {
context.clearRect(0, 0, 400, 400);
context.save();
context.beginPath();
context.arc(50, 50, 50, 0, Math.PI * 2);
context.clip();
context.beginPath();
context.rect(0, 0, 100, 100);
context.fill();
context.addHitRegion({ id : 'clip' });
context.restore();
}
function create_non_rect_region_with_multiple_clips() {
context.clearRect(0, 0, 400, 400);
context.save();
context.beginPath();
context.rect(0, 0, 100, 100);
context.clip();
context.beginPath();
context.arc(100, 50, 50, 0, Math.PI * 2);
context.clip();
context.beginPath();
context.rect(0, 0, 150, 50);
context.fill();
context.addHitRegion({ id : "clip" });
context.restore();
}
function no_pixel_test1() {
context.clearRect(0, 0, 400, 400);
context.save();
context.beginPath();
context.rect(0, 0, 100, 100);
context.clip();
context.beginPath();
context.rect(100, 100, 100, 100);
context.addHitRegion({ id : 'clip' });
context.restore();
}
function no_pixel_test2() {
context.save();
context.beginPath();
context.rect(0, 0, 50, 50);
context.rect(100, 0, 50, 50);
context.clip();
context.beginPath();
context.arc(75, 75, 30, 0, Math.PI * 2);
context.addHitRegion({ id : 'clip' });
context.restore();
}
coroutine(function*() {
setup({ explicit_done : true, explicit_timeout : true });
create_simple_rect_region_with_clip();
generate_tests(assert_equals, [
[ 'null', yield clickOrTouch(10, 10), null ],
[ 'clip', yield clickOrTouch(60, 60), 'clip' ]
]);
create_non_rect_region_with_clip();
generate_tests(assert_equals, [
[ 'null', yield clickOrTouch(0, 0), null ],
[ 'null', yield clickOrTouch(100, 0), null ],
[ 'null', yield clickOrTouch(100, 100), null ],
[ 'null', yield clickOrTouch(0, 100), null ],
[ 'clip', yield clickOrTouch(50, 50), 'clip' ]
]);
create_non_rect_region_with_multiple_clips();
generate_tests(assert_equals, [
[ 'null', yield clickOrTouch(00, 0), null ],
[ 'clip', yield clickOrTouch(100, 0), 'clip' ],
[ 'null', yield clickOrTouch(100, 100), null ],
[ 'null', yield clickOrTouch(0, 100), null ],
[ 'null', yield clickOrTouch(50, 0), null ],
[ 'null', yield clickOrTouch(150, 0), null ],
[ 'null', yield clickOrTouch(150, 100), null ],
[ 'null', yield clickOrTouch(50, 100), null ],
[ 'clip', yield clickOrTouch(50, 50), 'clip' ],
[ 'clip', yield clickOrTouch(100, 50), 'clip' ],
]);
generate_tests(assert_throws, [
[ 'no pixel test1', { name : 'NotSupportedError' }, no_pixel_test1 ],
[ 'no pixel test2', { name : 'NotSupportedError' }, no_pixel_test2 ],
]);
done();
});
</script>
|