This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 162
/
capture.js
145 lines (127 loc) · 4.3 KB
/
capture.js
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
define([
'../support/tdd',
'intern/chai!expect',
'../support/setup',
'pep'
], function(tdd, expect, util, pep) {
var HAS_MS = util.HAS_MS;
var fire = util.fire;
var prep = util.prep;
var setup = tdd.beforeEach;
var suite = tdd.suite;
var teardown = tdd.afterEach;
var test = tdd.test;
suite('Pointer Capture', function() {
var set = function(el, id) {
el.setPointerCapture(id || 1);
};
var release = function(el, id) {
el.releasePointerCapture(id || 1);
};
var container, host, inner;
setup(function() {
container = document.createElement('div');
container.innerHTML = '<div id="host" touch-action="none"><div id="inner"></div></div>';
host = container.firstElementChild;
inner = host.firstElementChild;
document.body.appendChild(container);
});
teardown(function() {
document.body.removeChild(container);
});
test('Element has setPointerCapture and releasePointerCapture', function() {
expect(host).to.have.property('setPointerCapture');
expect(host).to.have.property('releasePointerCapture');
});
test('setPointerCapture throw exceptions when the pointerId is not on screen', function() {
expect(function() { set(host); }).to.throw(/NotFoundError/);
});
test('releasePointerCapture throws exception when the pointerId is not on screen', function() {
expect(function() { release(host); }).to.throw(/NotFoundError/);
});
suite('pointercapture events', function() {
test('Element.setPointerCapture fires a gotpointercapture event', function() {
if (HAS_MS) {
this.skip('this test disabled for MSPointerEvents due to flakiness');
}
var dfd = this.async();
prep('gotpointercapture', host, dfd.resolve.bind(dfd));
fire('down', host);
set(host);
fire('up', host);
});
test('Element.releasePointerCapture fires a lostpointercapture event', function() {
if (HAS_MS) {
this.skip('this test disabled for MSPointerEvents due to flakiness');
}
var dfd = this.async();
prep('lostpointercapture', host, dfd.resolve.bind(dfd));
fire('down', host);
set(host);
release(host);
fire('up', host);
});
test('pointerup fires lostpointercapture for the capturing element', function() {
if (HAS_MS) {
this.skip('this test disabled for MSPointerEvents due to flakiness');
}
var dfd = this.async(30000, 2);
prep('lostpointercapture', host, dfd.resolve.bind(dfd));
host.addEventListener('lostpointercapture', dfd.resolve.bind(dfd));
fire('down', host);
set(host);
fire('up', host);
});
test('setPointerCapture will release an already captured pointer, firing events', function() {
if (HAS_MS) {
this.skip('this test disabled for MSPointerEvents due to flakiness');
}
var issued = 0;
var wait = function() {
issued++;
return function(e) {
issued--;
if (e) {
throw e;
}
if (issued === 0) {
dfd.resolve();
}
};
};
var dfd = this.async();
prep('gotpointercapture', inner, wait());
prep('lostpointercapture', host, wait());
fire('down', host);
set(host);
set(inner);
fire('up', host);
});
test('capture multiple pointers', function() {
this.skip('This test breaks "PointerEvents from mouse fire anywhere by default"');
if (HAS_MS) {
this.skip('this test disabled for MSPointerEvents due to flakiness');
}
var dfd = this.async();
var pm = pep.dispatcher.pointermap;
var ids = 0;
function wait(e) {
ids += e.pointerId;
if (ids === 3) {
pm.clear();
dfd.resolve();
}
}
host.addEventListener('gotpointercapture', wait);
var e = new pep.PointerEvent('pointerdown', { pointerId: 1 });
pm.set(1, e);
host.dispatchEvent(e);
set(host, 1);
e = new pep.PointerEvent('pointerdown', { pointerId: 2 });
pm.set(2, e);
host.dispatchEvent(e);
set(host, 2);
});
});
});
});