| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <!-- | 2 <!-- |
| 3 @license | 3 @license |
| 4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 4 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
| 5 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 5 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
| 6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 6 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
| 7 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 7 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
| 8 Code distributed by Google as part of the polymer project is also | 8 Code distributed by Google as part of the polymer project is also |
| 9 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | 9 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
| 10 --> | 10 --> |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 164 |
| 165 suite('basic keys', function() { | 165 suite('basic keys', function() { |
| 166 setup(function() { | 166 setup(function() { |
| 167 keys = fixture('BasicKeys'); | 167 keys = fixture('BasicKeys'); |
| 168 }); | 168 }); |
| 169 | 169 |
| 170 test('trigger the handler when the specified key is pressed', function() { | 170 test('trigger the handler when the specified key is pressed', function() { |
| 171 MockInteractions.pressSpace(keys); | 171 MockInteractions.pressSpace(keys); |
| 172 | 172 |
| 173 expect(keys.keyCount).to.be.equal(1); | 173 expect(keys.keyCount).to.be.equal(1); |
| 174 }); |
| 174 | 175 |
| 175 MockInteractions.pressAndReleaseKeyOn(keys, 27, [], 'Esc'); | 176 test('keyEventTarget can be null, and disables listeners', function() { |
| 176 expect(keys.keyCount).to.be.equal(2); | 177 keys.keyEventTarget = null; |
| 178 MockInteractions.pressSpace(keys); |
| 177 | 179 |
| 178 MockInteractions.pressAndReleaseKeyOn(keys, 27, [], 'Escape'); | 180 expect(keys.keyCount).to.be.equal(0); |
| 179 expect(keys.keyCount).to.be.equal(3); | |
| 180 | |
| 181 MockInteractions.pressAndReleaseKeyOn(keys, 27, []); | |
| 182 expect(keys.keyCount).to.be.equal(4); | |
| 183 }); | 181 }); |
| 184 | 182 |
| 185 test('trigger the handler when the specified key is pressed together with a
modifier', function() { | 183 test('trigger the handler when the specified key is pressed together with a
modifier', function() { |
| 186 var event = new CustomEvent('keydown'); | 184 var event = new CustomEvent('keydown'); |
| 187 event.ctrlKey = true; | 185 event.ctrlKey = true; |
| 188 event.keyCode = event.code = 32; | 186 event.keyCode = event.code = 32; |
| 189 keys.dispatchEvent(event); | 187 keys.dispatchEvent(event); |
| 190 expect(keys.keyCount).to.be.equal(1); | 188 expect(keys.keyCount).to.be.equal(1); |
| 191 }); | 189 }); |
| 192 | 190 |
| 193 test('handles special character @', function() { | 191 test('handles special character @', function() { |
| 194 var event = new CustomEvent('keydown'); | 192 MockInteractions.pressAndReleaseKeyOn(keys, undefined, [], '@'); |
| 195 event.key = '@'; | 193 |
| 196 keys.dispatchEvent(event); | |
| 197 expect(keys.keyCount).to.be.equal(1); | 194 expect(keys.keyCount).to.be.equal(1); |
| 198 }); | 195 }); |
| 199 | 196 |
| 197 test('handles variations of Esc key', function() { |
| 198 MockInteractions.pressAndReleaseKeyOn(keys, undefined, [], 'Esc'); |
| 199 expect(keys.keyCount).to.be.equal(1); |
| 200 |
| 201 MockInteractions.pressAndReleaseKeyOn(keys, undefined, [], 'Escape'); |
| 202 expect(keys.keyCount).to.be.equal(2); |
| 203 |
| 204 MockInteractions.pressAndReleaseKeyOn(keys, 27, [], ''); |
| 205 expect(keys.keyCount).to.be.equal(3); |
| 206 }); |
| 207 |
| 200 test('do not trigger the handler for non-specified keys', function() { | 208 test('do not trigger the handler for non-specified keys', function() { |
| 201 MockInteractions.pressEnter(keys); | 209 MockInteractions.pressEnter(keys); |
| 202 | 210 |
| 203 expect(keys.keyCount).to.be.equal(0); | 211 expect(keys.keyCount).to.be.equal(0); |
| 204 }); | 212 }); |
| 205 | 213 |
| 206 test('can have bindings added imperatively', function() { | 214 test('can have bindings added imperatively', function() { |
| 207 keys.addOwnKeyBinding('enter', '_keyHandler'); | 215 keys.addOwnKeyBinding('enter', '_keyHandler'); |
| 208 | 216 |
| 209 MockInteractions.pressEnter(keys); | 217 MockInteractions.pressEnter(keys); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 event.shiftKey = true; | 424 event.shiftKey = true; |
| 417 event.keyCode = event.code = 65; | 425 event.keyCode = event.code = 65; |
| 418 keys.dispatchEvent(event); | 426 keys.dispatchEvent(event); |
| 419 | 427 |
| 420 expect(keys.keyCount).to.be.equal(1); | 428 expect(keys.keyCount).to.be.equal(1); |
| 421 expect(shiftASpy.called).to.be.true; | 429 expect(shiftASpy.called).to.be.true; |
| 422 expect(aSpy.called).to.be.false; | 430 expect(aSpy.called).to.be.false; |
| 423 }); | 431 }); |
| 424 }); | 432 }); |
| 425 | 433 |
| 434 suite('remove key behavior with null target', function () { |
| 435 test('add and remove a iron-a11y-keys-behavior', function () { |
| 436 var element = document.createElement('x-a11y-basic-keys'); |
| 437 element.keyEventTarget = null; |
| 438 document.body.appendChild(element); |
| 439 document.body.removeChild(element); |
| 440 }); |
| 441 }); |
| 442 |
| 426 }); | 443 }); |
| 427 </script> | 444 </script> |
| 428 </body> | 445 </body> |
| 429 </html> | 446 </html> |
| OLD | NEW |