| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** @fileoverview Tests for settings-action-menu element. */ |
| 6 suite('SettingsActionMenu', function() { |
| 7 /** @type {?SettingsActionMenuElement} */ |
| 8 var menu = null; |
| 9 |
| 10 /** @type {?NodeList<HTMLElement>} */ |
| 11 var items = null; |
| 12 |
| 13 setup(function() { |
| 14 PolymerTest.clearBody(); |
| 15 |
| 16 document.body.innerHTML = ` |
| 17 <button id="dots">...</button> |
| 18 <dialog is="settings-action-menu"> |
| 19 <button class="dropdown-item">Un</button> |
| 20 <button class="dropdown-item">Dos</button> |
| 21 <button class="dropdown-item">Tres</button> |
| 22 </dialog> |
| 23 `; |
| 24 |
| 25 menu = document.querySelector('dialog[is=settings-action-menu]'); |
| 26 items = menu.querySelectorAll('.dropdown-item'); |
| 27 assertEquals(3, items.length); |
| 28 }); |
| 29 |
| 30 teardown(function() { |
| 31 if (menu.open) |
| 32 menu.close(); |
| 33 }); |
| 34 |
| 35 test('focus after showing', function() { |
| 36 /** @param {!HTMLElement} element */ |
| 37 function assertFocused(element) { |
| 38 assertEquals(element, menu.root.activeElement); |
| 39 items.forEach(function(item, i) { |
| 40 assertEquals(element === item, item.hasAttribute('autofocus')); |
| 41 }); |
| 42 } |
| 43 |
| 44 menu.showAt(document.querySelector('#dots')); |
| 45 assertFocused(items[0]); |
| 46 |
| 47 menu.close(); |
| 48 items[0].hidden = true; |
| 49 menu.showAt(document.querySelector('#dots')); |
| 50 assertFocused(items[1]); |
| 51 |
| 52 menu.close(); |
| 53 items[1].hidden = true; |
| 54 menu.showAt(document.querySelector('#dots')); |
| 55 assertFocused(items[2]); |
| 56 |
| 57 menu.close(); |
| 58 items[2].disabled = true; |
| 59 menu.showAt(document.querySelector('#dots')); |
| 60 assertEquals(null, menu.root.activeElement); |
| 61 assertEquals(0, menu.querySelectorAll('[autofocus]').length); |
| 62 }); |
| 63 |
| 64 test('focus after down/up arrow', function() { |
| 65 function down() { |
| 66 MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown'); |
| 67 } |
| 68 |
| 69 function up() { |
| 70 MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp'); |
| 71 } |
| 72 |
| 73 menu.showAt(document.querySelector('#dots')); |
| 74 assertEquals(items[0], menu.root.activeElement); |
| 75 |
| 76 down(); |
| 77 assertEquals(items[1], menu.root.activeElement); |
| 78 down(); |
| 79 assertEquals(items[2], menu.root.activeElement); |
| 80 down(); |
| 81 assertEquals(items[0], menu.root.activeElement); |
| 82 up(); |
| 83 assertEquals(items[2], menu.root.activeElement); |
| 84 up(); |
| 85 assertEquals(items[1], menu.root.activeElement); |
| 86 up(); |
| 87 assertEquals(items[0], menu.root.activeElement); |
| 88 up(); |
| 89 assertEquals(items[2], menu.root.activeElement); |
| 90 |
| 91 items[1].disabled = true; |
| 92 up(); |
| 93 assertEquals(items[0], menu.root.activeElement); |
| 94 }); |
| 95 |
| 96 test('close on resize', function() { |
| 97 menu.showAt(document.querySelector('#dots')); |
| 98 assertTrue(menu.open); |
| 99 |
| 100 window.dispatchEvent(new CustomEvent('resize')); |
| 101 assertFalse(menu.open); |
| 102 }); |
| 103 |
| 104 test('close on Tab', function() { |
| 105 menu.showAt(document.querySelector('#dots')); |
| 106 assertTrue(menu.open); |
| 107 |
| 108 MockInteractions.keyDownOn(menu, 'Tab', [], 'Tab'); |
| 109 assertFalse(menu.open); |
| 110 }); |
| 111 }); |
| OLD | NEW |