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

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

Issue 2820153003: [MD Bookmarks] Add keyboard navigation to sidebar. (Closed)
Patch Set: select_on_move Created 3 years, 8 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 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 suite('<bookmarks-folder-node>', function() { 5 suite('<bookmarks-folder-node>', function() {
6 var rootNode; 6 var rootNode;
7 var store; 7 var store;
8 8
9 function getFolderNode(id) {
10 return findFolderNode(rootNode, id);
11 }
12
9 setup(function() { 13 setup(function() {
10 store = new bookmarks.TestStore({ 14 store = new bookmarks.TestStore({
11 nodes: testTree( 15 nodes: testTree(
12 createFolder( 16 createFolder(
13 '1', 17 '1',
14 [ 18 [
15 createFolder( 19 createFolder(
16 '2', 20 '2',
17 [ 21 [
18 createFolder('3', []), 22 createFolder('3', []),
19 createFolder('4', []), 23 createFolder('4', []),
20 ]), 24 ]),
21 createItem('5'), 25 createItem('5'),
22 ]), 26 ]),
23 createFolder('7', [])), 27 createFolder('7', [])),
28 selectedFolder: '1',
24 }); 29 });
25 bookmarks.Store.instance_ = store; 30 bookmarks.Store.instance_ = store;
26 31
27 rootNode = document.createElement('bookmarks-folder-node'); 32 rootNode = document.createElement('bookmarks-folder-node');
28 rootNode.itemId = '0'; 33 rootNode.itemId = '0';
29 rootNode.depth = -1; 34 rootNode.depth = -1;
30 replaceBody(rootNode); 35 replaceBody(rootNode);
31 Polymer.dom.flush(); 36 Polymer.dom.flush();
32 }); 37 });
33 38
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 }); 73 });
69 Array.prototype.forEach.call(secondGen, function(f) { 74 Array.prototype.forEach.call(secondGen, function(f) {
70 assertEquals(2, f.depth); 75 assertEquals(2, f.depth);
71 assertEquals('2', f.style.getPropertyValue('--node-depth')); 76 assertEquals('2', f.style.getPropertyValue('--node-depth'));
72 }); 77 });
73 }); 78 });
74 79
75 test('doesn\'t highlight selected folder while searching', function() { 80 test('doesn\'t highlight selected folder while searching', function() {
76 var rootFolders = rootNode.root.querySelectorAll('bookmarks-folder-node'); 81 var rootFolders = rootNode.root.querySelectorAll('bookmarks-folder-node');
77 82
78 store.data.selectedFolder = '1';
79 store.notifyObservers();
80
81 assertEquals('1', rootFolders['0'].itemId); 83 assertEquals('1', rootFolders['0'].itemId);
82 assertTrue(rootFolders['0'].isSelectedFolder_); 84 assertTrue(rootFolders['0'].isSelectedFolder_);
83 85
84 store.data.search = { 86 store.data.search = {
85 term: 'test', 87 term: 'test',
86 inProgress: false, 88 inProgress: false,
87 results: ['3'], 89 results: ['3'],
88 }; 90 };
89 store.notifyObservers(); 91 store.notifyObservers();
90 92
91 assertFalse(rootFolders['0'].isSelectedFolder_); 93 assertFalse(rootFolders['0'].isSelectedFolder_);
92 }); 94 });
95
96 test('last visible descendant', function() {
97 assertEquals('7', rootNode.getLastVisibleDescendant_().itemId);
98 assertEquals('4', getFolderNode('1').getLastVisibleDescendant_().itemId);
99
100 store.data.closedFolders = new Set('2');
101 store.notifyObservers();
102
103 assertEquals('2', getFolderNode('1').getLastVisibleDescendant_().itemId);
104 });
105
106 test('next/previous folder nodes', function() {
107 function getNextVisibleFolderNode(parentId, targetId, reverse) {
108 return getFolderNode(parentId).getNextVisibleFolderNode_(
109 reverse, getFolderNode(targetId));
110 }
111
112 // Forwards.
113 assertEquals('2', getNextVisibleFolderNode('1', '1', false).itemId);
114 assertEquals('4', getNextVisibleFolderNode('2', '3', false).itemId);
115 assertEquals(null, getNextVisibleFolderNode('2', '4', false));
116
117 // Backwards.
118 assertEquals('1', getNextVisibleFolderNode('1', '2', true).itemId);
119 assertEquals('3', getNextVisibleFolderNode('2', '4', true).itemId);
120 assertEquals('4', getNextVisibleFolderNode('0', '7', true).itemId);
121
122 // Skips closed folders.
123 store.data.closedFolders = new Set('2');
124 store.notifyObservers();
125
126 assertEquals(null, getNextVisibleFolderNode('1', '2', false));
127 assertEquals(null, getNextVisibleFolderNode('2', '2', false));
128 assertEquals('2', getNextVisibleFolderNode('0', '7', true).itemId);
129 });
130
131 test('keyboard selection', function() {
tsergeant 2017/04/19 07:32:18 I think it would make a lot of sense to use an int
calamity 2017/04/28 06:15:47 Yeah, ok.
132 function changeKeyboardFocus(direction, targetId, activeElementId) {
133 return getFolderNode(targetId).changeKeyboardSelection_(
134 direction, getFolderNode(activeElementId));
135 }
136
137 store.data.closedFolders = new Set('2');
138 store.notifyObservers();
139
140 // The selected folder is focus enabled on attach.
141 assertEquals('0', getFolderNode('1').$.container.getAttribute('tabindex'));
142
143 // Only the selected folder should be focusable.
144 assertEquals('-1', getFolderNode('2').$.container.getAttribute('tabindex'));
145
146 // Move down into child.
147 assertTrue(changeKeyboardFocus(1, '1', '1'));
148 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
149 store.data.selectedFolder = '2';
150 store.notifyObservers();
151
152 assertEquals('-1', getFolderNode('1').$.container.getAttribute('tabindex'));
153 assertEquals('0', getFolderNode('2').$.container.getAttribute('tabindex'));
154
155 // Move down past closed folders.
156 assertFalse(changeKeyboardFocus(1, '2', '2'));
tsergeant 2017/04/19 07:32:18 I think this is testing slightly the wrong thing?
calamity 2017/04/28 06:15:47 Yeah, you're right. Fixed.
157 assertFalse(changeKeyboardFocus(1, '1', '2'));
158 assertTrue(changeKeyboardFocus(1, '0', '1'));
159 assertDeepEquals(bookmarks.actions.selectFolder('7'), store.lastAction);
160 store.data.selectedFolder = '7';
161 store.notifyObservers();
162
163 // Move down past end of list.
164 assertFalse(changeKeyboardFocus(1, '7', '7'));
165 assertFalse(changeKeyboardFocus(1, '0', '7'));
166 assertDeepEquals(bookmarks.actions.selectFolder('7'), store.lastAction);
167 store.data.selectedFolder = '7';
168 store.notifyObservers();
169
170 // Move up past closed folders.
171 assertFalse(changeKeyboardFocus(-1, '7', '7'));
172 assertTrue(changeKeyboardFocus(-1, '0', '7'));
173 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
174 store.data.selectedFolder = '2';
175 store.notifyObservers();
176
177 // Move up into parent.
178 assertFalse(changeKeyboardFocus(-1, '2', '2'));
179 assertTrue(changeKeyboardFocus(-1, '1', '2'));
180 assertDeepEquals(bookmarks.actions.selectFolder('1'), store.lastAction);
181 store.data.selectedFolder = '1';
182 store.notifyObservers();
183
184 // Move up past start of list.
185 assertFalse(changeKeyboardFocus(-1, '1', '1'));
186 assertTrue(changeKeyboardFocus(-1, '0', '1'));
187 assertDeepEquals(bookmarks.actions.selectFolder('1'), store.lastAction);
188 store.data.selectedFolder = '1';
189 store.notifyObservers();
190 });
93 }); 191 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698