| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** @fileoverview Suite of tests for cr-shared-menu. */ | 5 /** @fileoverview Suite of tests for cr-shared-menu. */ |
| 6 suite('cr-shared-menu', function() { | 6 suite('cr-shared-menu', function() { |
| 7 var menu; | 7 var menu; |
| 8 | 8 |
| 9 var button; | 9 var button; |
| 10 var button2; | 10 var button2; |
| 11 | 11 |
| 12 var item1; | 12 var item1; |
| 13 var item2; | 13 var item2; |
| 14 var item3; | 14 var item3; |
| 15 | 15 |
| 16 function afterOpen(callback) { | 16 function afterOpen(callback) { |
| 17 menu.addEventListener('iron-overlay-opened', function f() { | 17 menu.addEventListener('iron-overlay-opened', function f() { |
| 18 menu.removeEventListener('iron-overlay-opened', f); | 18 menu.removeEventListener('iron-overlay-opened', f); |
| 19 callback(); | 19 // paper-listbox applies focus after opening with microtask timing. |
| 20 // Delay until that has happened: |
| 21 setTimeout(callback, 0); |
| 20 }); | 22 }); |
| 21 } | 23 } |
| 22 | 24 |
| 23 function afterClose(callback) { | 25 function afterClose(callback) { |
| 24 menu.addEventListener('iron-overlay-closed', function f() { | 26 menu.addEventListener('iron-overlay-closed', function f() { |
| 25 menu.removeEventListener('iron-overlay-closed', f); | 27 menu.removeEventListener('iron-overlay-closed', f); |
| 26 callback(); | 28 callback(); |
| 27 }); | 29 }); |
| 28 } | 30 } |
| 29 | 31 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 input.focus(); | 141 input.focus(); |
| 140 menu.closeMenu(); | 142 menu.closeMenu(); |
| 141 | 143 |
| 142 afterClose(function() { | 144 afterClose(function() { |
| 143 assertEquals(input, document.activeElement); | 145 assertEquals(input, document.activeElement); |
| 144 done(); | 146 done(); |
| 145 }); | 147 }); |
| 146 }); | 148 }); |
| 147 }); | 149 }); |
| 148 | 150 |
| 149 test('focus is trapped inside the menu', function(done) { | 151 test('tab closes menu', function(done) { |
| 150 button.focus(); | 152 button.focus(); |
| 151 MockInteractions.tap(button); | 153 MockInteractions.tap(button); |
| 152 | 154 |
| 153 afterOpen(function() { | 155 afterOpen(function() { |
| 154 // Simulate shift-tab on first element. | 156 MockInteractions.pressAndReleaseKeyOn(item1, 9); |
| 155 assertEquals(item1, menu.shadowRoot.activeElement); | 157 afterClose(function() { |
| 156 MockInteractions.pressAndReleaseKeyOn(item1, 9, ['shift']); | 158 done(); |
| 157 assertEquals(item3, menu.shadowRoot.activeElement); | 159 }); |
| 160 }); |
| 161 }); |
| 158 | 162 |
| 159 // Simulate tab on last element. | 163 test('up and down change focus', function(done) { |
| 160 MockInteractions.pressAndReleaseKeyOn(item3, 9); | 164 button.focus(); |
| 161 assertEquals(item1, menu.shadowRoot.activeElement); | 165 MockInteractions.tap(button); |
| 162 | 166 |
| 167 afterOpen(function() { |
| 168 assertEquals(item1, document.activeElement); |
| 169 MockInteractions.pressAndReleaseKeyOn(item1, 40); |
| 170 |
| 171 assertEquals(item2, document.activeElement); |
| 172 MockInteractions.pressAndReleaseKeyOn(item2, 38); |
| 163 done(); | 173 done(); |
| 164 }); | 174 }); |
| 165 }); | 175 }); |
| 166 }); | 176 }); |
| OLD | NEW |