OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <!-- | 2 <!-- |
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | 3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. |
4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | 4 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt |
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | 5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt |
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | 6 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt |
7 Code distributed by Google as part of the polymer project is also | 7 Code distributed by Google as part of the polymer project is also |
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | 8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt |
9 --> | 9 --> |
10 <html> | 10 <html> |
11 <head> | 11 <head> |
12 <title>focused-state</title> | 12 <title>focused-state</title> |
13 | 13 |
14 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> | 14 <script src="../../webcomponentsjs/webcomponents-lite.js"></script> |
15 <script src="../../web-component-tester/browser.js"></script> | 15 <script src="../../web-component-tester/browser.js"></script> |
16 <script src="../../test-fixture/test-fixture-mocha.js"></script> | |
17 <script src="../../iron-test-helpers/mock-interactions.js"></script> | 16 <script src="../../iron-test-helpers/mock-interactions.js"></script> |
18 | |
19 <link rel="import" href="../../polymer/polymer.html"> | |
20 <link rel="import" href="../../test-fixture/test-fixture.html"> | |
21 <link rel="import" href="test-elements.html"> | 17 <link rel="import" href="test-elements.html"> |
22 </head> | 18 </head> |
23 <body> | 19 <body> |
24 | 20 |
25 <test-fixture id="TrivialFocusedState"> | 21 <test-fixture id="TrivialFocusedState"> |
26 <template> | 22 <template> |
27 <test-control tabindex="-1"></test-control> | 23 <test-control tabindex="-1"></test-control> |
28 </template> | 24 </template> |
29 </test-fixture> | 25 </test-fixture> |
30 | 26 |
31 <test-fixture id="NestedFocusedState"> | 27 <test-fixture id="NestedFocusedState"> |
32 <template> | 28 <template> |
33 <nested-focusable></nested-focusable> | 29 <nested-focusable></nested-focusable> |
34 </template> | 30 </template> |
35 </test-fixture> | 31 </test-fixture> |
36 | 32 |
| 33 <test-fixture id="LightDOM"> |
| 34 <template> |
| 35 <test-light-dom> |
| 36 <input id="input"> |
| 37 </test-light-dom> |
| 38 </template> |
| 39 </test-fixture> |
| 40 |
37 <script> | 41 <script> |
38 suite('focused-state', function() { | 42 suite('focused-state', function() { |
39 var focusTarget; | 43 var focusTarget; |
40 | 44 |
41 setup(function() { | 45 setup(function() { |
42 focusTarget = fixture('TrivialFocusedState'); | 46 focusTarget = fixture('TrivialFocusedState'); |
43 }); | 47 }); |
44 | 48 |
45 suite('when is focused', function() { | 49 suite('when is focused', function() { |
46 test('receives a focused attribute', function() { | 50 test('receives a focused attribute', function() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 }); | 87 }); |
84 }); | 88 }); |
85 | 89 |
86 suite('nested focusable', function() { | 90 suite('nested focusable', function() { |
87 var focusable; | 91 var focusable; |
88 | 92 |
89 setup(function() { | 93 setup(function() { |
90 focusable = fixture('NestedFocusedState'); | 94 focusable = fixture('NestedFocusedState'); |
91 }); | 95 }); |
92 | 96 |
93 test('focus/blur events fired on host element', function(done) { | 97 test('focus/blur events fired on host element', function() { |
94 var nFocusEvents = 0; | 98 var nFocusEvents = 0; |
95 var nBlurEvents = 0; | 99 var nBlurEvents = 0; |
| 100 |
96 focusable.addEventListener('focus', function() { | 101 focusable.addEventListener('focus', function() { |
97 nFocusEvents += 1; | 102 nFocusEvents += 1; |
98 // setTimeout to wait for potentially more, erroneous events | 103 expect(focusable.focused).to.be.equal(true); |
99 setTimeout(function() { | 104 MockInteractions.blur(focusable.$.input); |
100 assert.equal(nFocusEvents, 1, 'one focus event fired'); | |
101 MockInteractions.blur(focusable.$.input); | |
102 }); | |
103 }); | 105 }); |
104 focusable.addEventListener('blur', function() { | 106 focusable.addEventListener('blur', function() { |
| 107 expect(focusable.focused).to.be.equal(false); |
105 nBlurEvents += 1; | 108 nBlurEvents += 1; |
106 // setTimeout to wait for potentially more, erroneous events | |
107 setTimeout(function() { | |
108 assert.equal(nBlurEvents, 1, 'one blur event fired'); | |
109 done(); | |
110 }); | |
111 }); | 109 }); |
| 110 |
112 MockInteractions.focus(focusable.$.input); | 111 MockInteractions.focus(focusable.$.input); |
| 112 |
| 113 expect(nBlurEvents).to.be.greaterThan(0); |
| 114 expect(nFocusEvents).to.be.greaterThan(0); |
113 }); | 115 }); |
114 | 116 |
115 }); | 117 }); |
| 118 |
| 119 |
| 120 suite('elements in the light dom', function() { |
| 121 var lightDOM, input; |
| 122 |
| 123 setup(function() { |
| 124 lightDOM = fixture('LightDOM'); |
| 125 input = document.querySelector('#input'); |
| 126 }); |
| 127 |
| 128 test('should not fire the focus event', function() { |
| 129 var nFocusEvents = 0; |
| 130 |
| 131 lightDOM.addEventListener('focus', function() { |
| 132 nFocusEvents += 1; |
| 133 }); |
| 134 |
| 135 MockInteractions.focus(input); |
| 136 |
| 137 expect(nFocusEvents).to.be.equal(0); |
| 138 }); |
| 139 |
| 140 }); |
116 | 141 |
117 </script> | 142 </script> |
118 | 143 |
119 </body> | 144 </body> |
120 </html> | 145 </html> |
OLD | NEW |