OLD | NEW |
(Empty) | |
| 1 <!doctype html> |
| 2 <!-- |
| 3 @license |
| 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 |
| 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 |
| 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 |
| 10 --> |
| 11 <html> |
| 12 <head> |
| 13 <meta charset="UTF-8"> |
| 14 <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-
scale=1.0, user-scalable=yes"> |
| 15 <title>iron-a11y-keys</title> |
| 16 |
| 17 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
| 18 <script src="../../web-component-tester/browser.js"></script> |
| 19 <script src="../../test-fixture/test-fixture-mocha.js"></script> |
| 20 |
| 21 |
| 22 <link rel="import" href="../../iron-test-helpers/iron-test-helpers.html"> |
| 23 <link rel="import" href="../../test-fixture/test-fixture.html"> |
| 24 <link rel="import" href="../iron-a11y-keys.html"> |
| 25 </head> |
| 26 <body> |
| 27 |
| 28 <test-fixture id="BasicKeys"> |
| 29 <template> |
| 30 <iron-a11y-keys></iron-a11y-keys> |
| 31 </template> |
| 32 </test-fixture> |
| 33 |
| 34 <script> |
| 35 suite('<iron-a11y-keys>', function() { |
| 36 var keys; |
| 37 |
| 38 setup(function() { |
| 39 keys = fixture('BasicKeys'); |
| 40 }); |
| 41 |
| 42 test('target is parentNode by default', function() { |
| 43 expect(keys.target).to.be.equal(keys.parentNode); |
| 44 }); |
| 45 |
| 46 suite('keys attribute', function() { |
| 47 test('causes an event listener to be added', function(done) { |
| 48 keys.keys = 'space'; |
| 49 |
| 50 keys.addEventListener('keys-pressed', function() { |
| 51 done(); |
| 52 }); |
| 53 |
| 54 Polymer.Base.async(function() { |
| 55 MockInteractions.pressSpace(keys.parentNode); |
| 56 }); |
| 57 }); |
| 58 |
| 59 test('will not trigger events for non-specified keys', function() { |
| 60 var keysPressedCount = 0; |
| 61 |
| 62 keys.keys = 'space'; |
| 63 |
| 64 keys.addEventListener('keys-pressed', function() { |
| 65 keysPressedCount++; |
| 66 }); |
| 67 |
| 68 MockInteractions.pressSpace(keys.parentNode); |
| 69 MockInteractions.pressEnter(keys.parentNode); |
| 70 |
| 71 expect(keysPressedCount).to.be.equal(1); |
| 72 }); |
| 73 |
| 74 test('triggers events for space separated keys', function() { |
| 75 var keysPressed = ''; |
| 76 |
| 77 keys.keys = 'a b c'; |
| 78 |
| 79 keys.addEventListener('keys-pressed', function(event) { |
| 80 keysPressed += event.detail.key; |
| 81 }); |
| 82 |
| 83 MockInteractions.pressAndReleaseKeyOn(keys.parentNode, 65); |
| 84 MockInteractions.pressAndReleaseKeyOn(keys.parentNode, 66); |
| 85 MockInteractions.pressAndReleaseKeyOn(keys.parentNode, 67); |
| 86 |
| 87 expect(keysPressed).to.be.equal('abc'); |
| 88 }); |
| 89 }); |
| 90 |
| 91 suite('event listeners', function() { |
| 92 test('listeners are only active when element is in document', function()
{ |
| 93 var keysPressedCount = 0; |
| 94 var parent = keys.parentNode; |
| 95 |
| 96 keys.keys = 'space'; |
| 97 |
| 98 keys.addEventListener('keys-pressed', function(event) { |
| 99 keysPressedCount++; |
| 100 }); |
| 101 |
| 102 MockInteractions.pressSpace(parent); |
| 103 expect(keysPressedCount).to.be.equal(1); |
| 104 |
| 105 keys.parentNode.removeChild(keys); |
| 106 TestHelpers.flushAsynchronousOperations(); |
| 107 |
| 108 MockInteractions.pressSpace(parent); |
| 109 expect(keysPressedCount).to.be.equal(1); |
| 110 |
| 111 parent.appendChild(keys); |
| 112 TestHelpers.flushAsynchronousOperations(); |
| 113 |
| 114 MockInteractions.pressSpace(parent); |
| 115 expect(keysPressedCount).to.be.equal(2); |
| 116 }); |
| 117 }); |
| 118 }); |
| 119 </script> |
| 120 |
| 121 </body> |
| 122 </html> |
OLD | NEW |