Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chrome/test/data/webui/settings/settings_action_menu_test.js

Issue 2438423002: MD Settings: Remove usage of 'autofocus' from settings-action-menu. (Closed)
Patch Set: Nit Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/settings/settings_action_menu.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 settings-action-menu element. */ 5 /** @fileoverview Tests for settings-action-menu element. */
6 suite('SettingsActionMenu', function() { 6 suite('SettingsActionMenu', function() {
7 /** @type {?SettingsActionMenuElement} */ 7 /** @type {?SettingsActionMenuElement} */
8 var menu = null; 8 var menu = null;
9 9
10 /** @type {?NodeList<HTMLElement>} */ 10 /** @type {?NodeList<HTMLElement>} */
11 var items = null; 11 var items = null;
12 12
13 setup(function() { 13 setup(function() {
14 PolymerTest.clearBody(); 14 PolymerTest.clearBody();
15 15
16 document.body.innerHTML = ` 16 document.body.innerHTML = `
17 <button id="dots">...</button> 17 <button id="dots">...</button>
18 <dialog is="settings-action-menu"> 18 <dialog is="settings-action-menu">
19 <button class="dropdown-item">Un</button> 19 <button class="dropdown-item">Un</button>
20 <hr>
20 <button class="dropdown-item">Dos</button> 21 <button class="dropdown-item">Dos</button>
21 <button class="dropdown-item">Tres</button> 22 <button class="dropdown-item">Tres</button>
22 </dialog> 23 </dialog>
23 `; 24 `;
24 25
25 menu = document.querySelector('dialog[is=settings-action-menu]'); 26 menu = document.querySelector('dialog[is=settings-action-menu]');
26 items = menu.querySelectorAll('.dropdown-item'); 27 items = menu.querySelectorAll('.dropdown-item');
27 assertEquals(3, items.length); 28 assertEquals(3, items.length);
28 }); 29 });
29 30
30 teardown(function() { 31 teardown(function() {
31 if (menu.open) 32 if (menu.open)
32 menu.close(); 33 menu.close();
33 }); 34 });
34 35
35 test('focus after showing', function() { 36 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')); 37 menu.showAt(document.querySelector('#dots'));
45 assertFocused(items[0]); 38 assertEquals(menu.root.activeElement, items[0]);
46 39
47 menu.close(); 40 menu.close();
48 items[0].hidden = true; 41 items[0].hidden = true;
49 menu.showAt(document.querySelector('#dots')); 42 menu.showAt(document.querySelector('#dots'));
50 assertFocused(items[1]); 43 assertEquals(menu.root.activeElement, items[1]);
51 44
52 menu.close(); 45 menu.close();
53 items[1].hidden = true; 46 items[1].hidden = true;
54 menu.showAt(document.querySelector('#dots')); 47 menu.showAt(document.querySelector('#dots'));
55 assertFocused(items[2]); 48 assertEquals(menu.root.activeElement, items[2]);
56 49
57 menu.close(); 50 menu.close();
58 items[2].disabled = true; 51 items[2].disabled = true;
59 menu.showAt(document.querySelector('#dots')); 52 menu.showAt(document.querySelector('#dots'));
60 assertEquals(null, menu.root.activeElement); 53 assertEquals(null, menu.root.activeElement);
61 assertEquals(0, menu.querySelectorAll('[autofocus]').length);
62 }); 54 });
63 55
64 test('focus after down/up arrow', function() { 56 test('focus after down/up arrow', function() {
65 function down() { 57 function down() {
66 MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown'); 58 MockInteractions.keyDownOn(menu, 'ArrowDown', [], 'ArrowDown');
67 } 59 }
68 60
69 function up() { 61 function up() {
70 MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp'); 62 MockInteractions.keyDownOn(menu, 'ArrowUp', [], 'ArrowUp');
71 } 63 }
(...skipping 30 matching lines...) Expand all
102 }); 94 });
103 95
104 test('close on Tab', function() { 96 test('close on Tab', function() {
105 menu.showAt(document.querySelector('#dots')); 97 menu.showAt(document.querySelector('#dots'));
106 assertTrue(menu.open); 98 assertTrue(menu.open);
107 99
108 MockInteractions.keyDownOn(menu, 'Tab', [], 'Tab'); 100 MockInteractions.keyDownOn(menu, 'Tab', [], 'Tab');
109 assertFalse(menu.open); 101 assertFalse(menu.open);
110 }); 102 });
111 }); 103 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/settings_action_menu.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698