| 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 <hr> | |
| 21 <button class="dropdown-item">Dos</button> | |
| 22 <button class="dropdown-item">Tres</button> | |
| 23 </dialog> | |
| 24 `; | |
| 25 | |
| 26 menu = document.querySelector('dialog[is=settings-action-menu]'); | |
| 27 items = menu.querySelectorAll('.dropdown-item'); | |
| 28 assertEquals(3, items.length); | |
| 29 }); | |
| 30 | |
| 31 teardown(function() { | |
| 32 if (menu.open) | |
| 33 menu.close(); | |
| 34 }); | |
| 35 | |
| 36 test('focus after showing', function() { | |
| 37 menu.showAt(document.querySelector('#dots')); | |
| 38 assertEquals(menu.root.activeElement, items[0]); | |
| 39 | |
| 40 menu.close(); | |
| 41 items[0].hidden = true; | |
| 42 menu.showAt(document.querySelector('#dots')); | |
| 43 assertEquals(menu.root.activeElement, items[1]); | |
| 44 | |
| 45 menu.close(); | |
| 46 items[1].hidden = true; | |
| 47 menu.showAt(document.querySelector('#dots')); | |
| 48 assertEquals(menu.root.activeElement, items[2]); | |
| 49 | |
| 50 menu.close(); | |
| 51 items[2].disabled = true; | |
| 52 menu.showAt(document.querySelector('#dots')); | |
| 53 assertEquals(null, menu.root.activeElement); | |
| 54 }); | |
| 55 | |
| 56 test('focus after down/up arrow', function() { | |
| 57 function down() { | |
| 58 MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown'); | |
| 59 } | |
| 60 | |
| 61 function up() { | |
| 62 MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp'); | |
| 63 } | |
| 64 | |
| 65 menu.showAt(document.querySelector('#dots')); | |
| 66 assertEquals(items[0], menu.root.activeElement); | |
| 67 | |
| 68 down(); | |
| 69 assertEquals(items[1], menu.root.activeElement); | |
| 70 down(); | |
| 71 assertEquals(items[2], menu.root.activeElement); | |
| 72 down(); | |
| 73 assertEquals(items[0], menu.root.activeElement); | |
| 74 up(); | |
| 75 assertEquals(items[2], menu.root.activeElement); | |
| 76 up(); | |
| 77 assertEquals(items[1], menu.root.activeElement); | |
| 78 up(); | |
| 79 assertEquals(items[0], menu.root.activeElement); | |
| 80 up(); | |
| 81 assertEquals(items[2], menu.root.activeElement); | |
| 82 | |
| 83 items[1].disabled = true; | |
| 84 up(); | |
| 85 assertEquals(items[0], menu.root.activeElement); | |
| 86 }); | |
| 87 | |
| 88 test('close on resize', function() { | |
| 89 menu.showAt(document.querySelector('#dots')); | |
| 90 assertTrue(menu.open); | |
| 91 | |
| 92 window.dispatchEvent(new CustomEvent('resize')); | |
| 93 assertFalse(menu.open); | |
| 94 }); | |
| 95 | |
| 96 test('close on Tab', function() { | |
| 97 menu.showAt(document.querySelector('#dots')); | |
| 98 assertTrue(menu.open); | |
| 99 | |
| 100 MockInteractions.keyDownOn(menu, 'Tab', [], 'Tab'); | |
| 101 assertFalse(menu.open); | |
| 102 }); | |
| 103 }); | |
| OLD | NEW |