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

Side by Side Diff: chrome/test/data/webui/md_bookmarks/md_bookmarks_focus_test.js

Issue 2857893002: [MD Bookmarks] Allow left/right keys to close/open folders in sidebar. (Closed)
Patch Set: Created 3 years, 7 months 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 /** 5 /**
6 * @fileoverview Tests for MD Bookmarks which are run as interactive ui tests. 6 * @fileoverview Tests for MD Bookmarks which are run as interactive ui tests.
7 * Should be used for tests which care about focus. 7 * Should be used for tests which care about focus.
8 */ 8 */
9 9
10 var ROOT_PATH = '../../../../../'; 10 var ROOT_PATH = '../../../../../';
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // Only the selected folder should be focusable. 90 // Only the selected folder should be focusable.
91 assertEquals('', getFolderNode('2').$.container.getAttribute('tabindex')); 91 assertEquals('', getFolderNode('2').$.container.getAttribute('tabindex'));
92 92
93 // Give keyboard focus to the first item. 93 // Give keyboard focus to the first item.
94 getFolderNode('1').$.container.focus(); 94 getFolderNode('1').$.container.focus();
95 95
96 // Move down into child. 96 // Move down into child.
97 keydown('1', 'ArrowDown'); 97 keydown('1', 'ArrowDown');
98 98
99 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); 99 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
100 store.data.selectedFolder = '2';
101 store.notifyObservers();
102
103 assertEquals('', getFolderNode('1').$.container.getAttribute('tabindex'));
104 assertEquals(
105 '0', getFolderNode('2').$.container.getAttribute('tabindex'));
100 assertFocused('1', '2'); 106 assertFocused('1', '2');
101 107
102 // Move down past closed folders. 108 // Move down past closed folders.
103 keydown('2', 'ArrowDown'); 109 keydown('2', 'ArrowDown');
104 assertDeepEquals(bookmarks.actions.selectFolder('7'), store.lastAction); 110 assertDeepEquals(bookmarks.actions.selectFolder('7'), store.lastAction);
105 assertFocused('2', '7'); 111 assertFocused('2', '7');
106 112
107 // Move down past end of list. 113 // Move down past end of list.
108 store.resetLastAction(); 114 store.resetLastAction();
109 keydown('7', 'ArrowDown'); 115 keydown('7', 'ArrowDown');
110 assertDeepEquals(null, store.lastAction); 116 assertDeepEquals(null, store.lastAction);
111 117
112 // Move up past closed folders. 118 // Move up past closed folders.
113 keydown('7', 'ArrowUp'); 119 keydown('7', 'ArrowUp');
114 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); 120 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
115 assertFocused('7', '2'); 121 assertFocused('7', '2');
116 122
117 // Move up into parent. 123 // Move up into parent.
118 keydown('2', 'ArrowUp'); 124 keydown('2', 'ArrowUp');
119 assertDeepEquals(bookmarks.actions.selectFolder('1'), store.lastAction); 125 assertDeepEquals(bookmarks.actions.selectFolder('1'), store.lastAction);
120 assertFocused('2', '1'); 126 assertFocused('2', '1');
121 127
122 // Move up past start of list. 128 // Move up past start of list.
123 store.resetLastAction(); 129 store.resetLastAction();
124 keydown('1', 'ArrowUp'); 130 keydown('1', 'ArrowUp');
125 assertDeepEquals(null, store.lastAction); 131 assertDeepEquals(null, store.lastAction);
126 }); 132 });
133
134 test('keyboard left/right', function() {
135 function keydown(id, key) {
tsergeant 2017/05/05 01:31:07 There's already a keydown function above (line 41)
calamity 2017/05/09 03:45:35 Done. Forgot to clean this up after rebase.
136 var container = getFolderNode(id).$.container;
137 MockInteractions.keyDownOn(container, '', [], key);
138 }
139
140 store.data.closedFolders = new Set('2');
141 store.notifyObservers();
142
143 // The selected folder is focus enabled on attach.
tsergeant 2017/05/05 01:31:07 Is there a particular reason to repeat these two a
calamity 2017/05/09 03:45:35 Done.
144 assertEquals(
145 '0', getFolderNode('1').$.container.getAttribute('tabindex'));
146
147 // Only the selected folder should be focusable.
148 assertEquals('', getFolderNode('2').$.container.getAttribute('tabindex'));
149
150 // Give keyboard focus to the first item.
151 getFolderNode('1').$.container.focus();
152
153 // Pressing right descends into first child.
154 keydown('1', 'ArrowRight');
155 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
156
157 // Pressing right on a closed folder opens that folder
158 keydown('2', 'ArrowRight');
159 assertDeepEquals(
160 bookmarks.actions.changeFolderOpen('2', true), store.lastAction);
161
162 // Pressing right again descends into first child.
163 keydown('2', 'ArrowRight');
164 assertDeepEquals(bookmarks.actions.selectFolder('3'), store.lastAction);
165
166 // Pressing right on a folder with no children does nothing.
167 store.resetLastAction();
168 keydown('3', 'ArrowRight');
169 assertDeepEquals(null, store.lastAction);
170
171 // Pressing left on a folder with no children ascends to parent.
172 keydown('3', 'ArrowDown');
173 keydown('4', 'ArrowLeft');
174 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
175
176 // Pressing left again closes the parent.
177 keydown('2', 'ArrowLeft');
178 assertDeepEquals(
179 bookmarks.actions.changeFolderOpen('2', false), store.lastAction);
180 });
127 }); 181 });
128 182
129 mocha.run(); 183 mocha.run();
130 }); 184 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698