| 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 Tests for cr-action-menu element. */ | 5 /** @fileoverview Tests for cr-action-menu element. */ |
| 6 suite('CrActionMenu', function() { | 6 suite('CrActionMenu', function() { |
| 7 /** @type {?CrActionMenuElement} */ | 7 /** @type {?CrActionMenuElement} */ |
| 8 var menu = null; | 8 var menu = null; |
| 9 | 9 |
| 10 /** @type {?NodeList<HTMLElement>} */ | 10 /** @type {?NodeList<HTMLElement>} */ |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 }); | 86 }); |
| 87 | 87 |
| 88 test('close on resize', function() { | 88 test('close on resize', function() { |
| 89 menu.showAt(document.querySelector('#dots')); | 89 menu.showAt(document.querySelector('#dots')); |
| 90 assertTrue(menu.open); | 90 assertTrue(menu.open); |
| 91 | 91 |
| 92 window.dispatchEvent(new CustomEvent('resize')); | 92 window.dispatchEvent(new CustomEvent('resize')); |
| 93 assertFalse(menu.open); | 93 assertFalse(menu.open); |
| 94 }); | 94 }); |
| 95 | 95 |
| 96 test('close on Tab', function() { | 96 /** @param {string} key The key to use for closing. */ |
| 97 menu.showAt(document.querySelector('#dots')); | 97 function testFocusAfterClosing(key) { |
| 98 assertTrue(menu.open); | 98 return new Promise(function(resolve) { |
| 99 var dots = document.querySelector('#dots'); |
| 100 menu.showAt(dots); |
| 101 assertTrue(menu.open); |
| 99 | 102 |
| 100 MockInteractions.keyDownOn(menu, 'Tab', [], 'Tab'); | 103 // Check that focus returns to the anchor element. |
| 101 assertFalse(menu.open); | 104 dots.addEventListener('focus', resolve); |
| 105 MockInteractions.keyDownOn(menu, key, [], key); |
| 106 assertFalse(menu.open); |
| 107 }); |
| 108 } |
| 109 |
| 110 test('close on Tab', function() { return testFocusAfterClosing('Tab'); }); |
| 111 test('close on Escape', function() { |
| 112 return testFocusAfterClosing('Escape'); |
| 102 }); | 113 }); |
| 103 }); | 114 }); |
| OLD | NEW |