73bcce88
luigser
COMPONENTS
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>iron-a11y-keys</title>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
|
c5169e0e
Renato De Donato
a new hope
|
19
|
<script src="../../test-fixture/test-fixture-mocha.js"></script>
|
73bcce88
luigser
COMPONENTS
|
20
21
22
|
<script src="../../iron-test-helpers/mock-interactions.js"></script>
<link rel="import" href="../../polymer/polymer.html">
|
c5169e0e
Renato De Donato
a new hope
|
23
|
<link rel="import" href="../../test-fixture/test-fixture.html">
|
73bcce88
luigser
COMPONENTS
|
24
25
26
27
28
29
30
31
32
|
<link rel="import" href="../iron-a11y-keys-behavior.html">
</head>
<body>
<test-fixture id="BasicKeys">
<template>
<x-a11y-basic-keys></x-a11y-basic-keys>
</template>
</test-fixture>
|
eb240478
Luigi Serra
public room cards...
|
33
34
35
36
37
38
|
<test-fixture id="NonPropagatingKeys">
<template>
<x-a11y-basic-keys stop-keyboard-event-propagation></x-a11y-basic-keys>
</template>
</test-fixture>
|
73bcce88
luigser
COMPONENTS
|
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
<test-fixture id="ComboKeys">
<template>
<x-a11y-combo-keys></x-a11y-combo-keys>
</template>
</test-fixture>
<test-fixture id="AlternativeEventKeys">
<template>
<x-a11y-alternate-event-keys></x-a11y-alternate-event-keys>
</template>
</test-fixture>
<test-fixture id="BehaviorKeys">
<template>
<x-a11y-behavior-keys></x-a11y-behavior-keys>
</template>
</test-fixture>
|
73bcce88
luigser
COMPONENTS
|
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
<script>
suite('Polymer.IronA11yKeysBehavior', function() {
var keys;
suiteSetup(function() {
var KeysTestBehavior = [Polymer.IronA11yKeysBehavior, {
properties: {
keyCount: {
type: Number,
value: 0
}
},
_keyHandler: function(event) {
this.keyCount++;
this.lastEvent = event;
|
f748e9cf
Luigi Serra
new controllet an...
|
73
|
},
|
f748e9cf
Luigi Serra
new controllet an...
|
74
75
|
_preventDefaultHandler: function(event) {
event.preventDefault();
|
73bcce88
luigser
COMPONENTS
|
76
77
78
79
80
81
82
83
84
85
86
|
}
}];
Polymer({
is: 'x-a11y-basic-keys',
behaviors: [
KeysTestBehavior
],
keyBindings: {
|
c5169e0e
Renato De Donato
a new hope
|
87
|
'space': '_keyHandler'
|
73bcce88
luigser
COMPONENTS
|
88
89
90
91
92
93
94
95
96
97
98
|
}
});
Polymer({
is: 'x-a11y-combo-keys',
behaviors: [
KeysTestBehavior
],
keyBindings: {
|
c5169e0e
Renato De Donato
a new hope
|
99
|
'ctrl+shift+a': '_keyHandler'
|
73bcce88
luigser
COMPONENTS
|
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
|
}
});
Polymer({
is: 'x-a11y-alternate-event-keys',
behaviors: [
KeysTestBehavior
],
keyBindings: {
'space:keyup': '_keyHandler'
}
});
var XA11yBehavior = {
keyBindings: {
'enter': '_keyHandler'
}
};
Polymer({
is: 'x-a11y-behavior-keys',
behaviors: [
KeysTestBehavior,
XA11yBehavior
],
keyBindings: {
|
c5169e0e
Renato De Donato
a new hope
|
130
131
|
'space': '_keyHandler',
'enter': '_preventDefaultHandler'
|
73bcce88
luigser
COMPONENTS
|
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
}
});
});
suite('basic keys', function() {
setup(function() {
keys = fixture('BasicKeys');
});
test('trigger the handler when the specified key is pressed', function() {
MockInteractions.pressSpace(keys);
expect(keys.keyCount).to.be.equal(1);
});
|
73bcce88
luigser
COMPONENTS
|
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
test('do not trigger the handler for non-specified keys', function() {
MockInteractions.pressEnter(keys);
expect(keys.keyCount).to.be.equal(0);
});
test('can have bindings added imperatively', function() {
keys.addOwnKeyBinding('enter', '_keyHandler');
MockInteractions.pressEnter(keys);
expect(keys.keyCount).to.be.equal(1);
MockInteractions.pressSpace(keys);
expect(keys.keyCount).to.be.equal(2);
});
test('can remove imperatively added bindings', function() {
keys.addOwnKeyBinding('enter', '_keyHandler');
keys.removeOwnKeyBindings();
MockInteractions.pressEnter(keys);
expect(keys.keyCount).to.be.equal(0);
MockInteractions.pressSpace(keys);
expect(keys.keyCount).to.be.equal(1);
});
|
eb240478
Luigi Serra
public room cards...
|
174
175
176
177
178
179
180
181
182
|
test('allows propagation beyond the key combo handler', function() {
var keySpy = sinon.spy();
document.addEventListener('keydown', keySpy);
MockInteractions.pressEnter(keys);
expect(keySpy.callCount).to.be.equal(1);
});
|
73bcce88
luigser
COMPONENTS
|
183
184
185
186
187
188
|
suite('edge cases', function() {
test('knows that `spacebar` is the same as `space`', function() {
var event = new CustomEvent('keydown');
event.key = 'spacebar';
expect(keys.keyboardEventMatchesKeys(event, 'space')).to.be.equal(true);
});
|
73bcce88
luigser
COMPONENTS
|
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
});
suite('matching keyboard events to keys', function() {
test('can be done imperatively', function() {
var event = new CustomEvent('keydown');
event.keyCode = 65;
expect(keys.keyboardEventMatchesKeys(event, 'a')).to.be.equal(true);
});
test('can be done with a provided keyboardEvent', function() {
var event;
MockInteractions.pressSpace(keys);
event = keys.lastEvent;
expect(event.detail.keyboardEvent).to.be.okay;
expect(keys.keyboardEventMatchesKeys(event, 'space')).to.be.equal(true);
});
test('can handle variations in arrow key names', function() {
var event = new CustomEvent('keydown');
event.key = 'up';
expect(keys.keyboardEventMatchesKeys(event, 'up')).to.be.equal(true);
event.key = 'ArrowUp';
expect(keys.keyboardEventMatchesKeys(event, 'up')).to.be.equal(true);
});
});
});
suite('combo keys', function() {
setup(function() {
keys = fixture('ComboKeys');
});
test('trigger the handler when the combo is pressed', function() {
var event = new CustomEvent('keydown');
event.ctrlKey = true;
event.shiftKey = true;
event.keyCode = event.code = 65;
keys.dispatchEvent(event);
expect(keys.keyCount).to.be.equal(1);
});
|
73bcce88
luigser
COMPONENTS
|
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
});
suite('alternative event keys', function() {
setup(function() {
keys = fixture('AlternativeEventKeys');
});
test('trigger on the specified alternative keyboard event', function() {
MockInteractions.keyDownOn(keys, 32);
expect(keys.keyCount).to.be.equal(0);
MockInteractions.keyUpOn(keys, 32);
expect(keys.keyCount).to.be.equal(1);
});
});
suite('behavior keys', function() {
setup(function() {
keys = fixture('BehaviorKeys');
});
test('bindings in other behaviors are transitive', function() {
MockInteractions.pressEnter(keys);
|
c5169e0e
Renato De Donato
a new hope
|
258
259
|
MockInteractions.pressSpace(keys);
|
73bcce88
luigser
COMPONENTS
|
260
261
262
263
|
expect(keys.keyCount).to.be.equal(2);
});
});
|
eb240478
Luigi Serra
public room cards...
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
|
suite('stopping propagation automatically', function() {
setup(function() {
keys = fixture('NonPropagatingKeys');
});
test('does not propagate key events beyond the combo handler', function() {
var keySpy = sinon.spy();
document.addEventListener('keydown', keySpy);
MockInteractions.pressEnter(keys);
expect(keySpy.callCount).to.be.equal(0);
});
});
|
f748e9cf
Luigi Serra
new controllet an...
|
280
281
|
suite('prevent default behavior of event', function() {
setup(function() {
|
c5169e0e
Renato De Donato
a new hope
|
282
|
keys = fixture('BehaviorKeys');
|
f748e9cf
Luigi Serra
new controllet an...
|
283
|
});
|
c5169e0e
Renato De Donato
a new hope
|
284
285
|
test('defaultPrevented is correctly set', function() {
var keySpy = sinon.spy();
|
f748e9cf
Luigi Serra
new controllet an...
|
286
|
|
c5169e0e
Renato De Donato
a new hope
|
287
|
document.addEventListener('keydown', keySpy);
|
a1a3bc73
Luigi Serra
graphs updates
|
288
|
|
c5169e0e
Renato De Donato
a new hope
|
289
|
MockInteractions.pressEnter(keys);
|
f748e9cf
Luigi Serra
new controllet an...
|
290
|
|
c5169e0e
Renato De Donato
a new hope
|
291
|
expect(keySpy.getCall(0).args[0].defaultPrevented).to.be.equal(true);
|
f748e9cf
Luigi Serra
new controllet an...
|
292
293
294
|
});
});
|
73bcce88
luigser
COMPONENTS
|
295
296
297
298
|
});
</script>
</body>
</html>
|