OLD | NEW |
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 suite('<bookmarks-command-manager>', function() { | 5 suite('<bookmarks-command-manager>', function() { |
6 var commandManager; | 6 var commandManager; |
7 var store; | 7 var store; |
8 var lastCommand; | 8 var lastCommand; |
9 var lastCommandIds; | 9 var lastCommandIds; |
10 | 10 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 assertFalse(commandManager.canExecute(Command.COPY_URL, new Set(['11']))); | 64 assertFalse(commandManager.canExecute(Command.COPY_URL, new Set(['11']))); |
65 assertFalse( | 65 assertFalse( |
66 commandManager.canExecute(Command.COPY_URL, new Set(['11', '13']))); | 66 commandManager.canExecute(Command.COPY_URL, new Set(['11', '13']))); |
67 assertTrue(commandManager.canExecute(Command.COPY_URL, new Set(['13']))); | 67 assertTrue(commandManager.canExecute(Command.COPY_URL, new Set(['13']))); |
68 }); | 68 }); |
69 | 69 |
70 test('context menu hides invalid commands', function() { | 70 test('context menu hides invalid commands', function() { |
71 store.data.selection.items = new Set(['11', '13']); | 71 store.data.selection.items = new Set(['11', '13']); |
72 store.notifyObservers(); | 72 store.notifyObservers(); |
73 | 73 |
74 commandManager.openCommandMenuAtPosition(0, 0); | 74 commandManager.openCommandMenuAtPosition(0, 0, MenuSource.LIST); |
75 Polymer.dom.flush(); | 75 Polymer.dom.flush(); |
76 | 76 |
77 var commandHidden = {}; | 77 var commandHidden = {}; |
78 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { | 78 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { |
79 commandHidden[element.getAttribute('command')] = element.hidden; | 79 commandHidden[element.getAttribute('command')] = element.hidden; |
80 }); | 80 }); |
81 | 81 |
82 // With a folder and an item selected, the only available context menu item | 82 // With a folder and an item selected, the only available context menu item |
83 // is 'Delete'. | 83 // is 'Delete'. |
84 assertTrue(commandHidden[Command.EDIT]); | 84 assertTrue(commandHidden[Command.EDIT]); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 MockInteractions.pressAndReleaseKeyOn( | 158 MockInteractions.pressAndReleaseKeyOn( |
159 document.body, '', undoModifier, undoKey); | 159 document.body, '', undoModifier, undoKey); |
160 commandManager.assertLastCommand('undo'); | 160 commandManager.assertLastCommand('undo'); |
161 | 161 |
162 MockInteractions.pressAndReleaseKeyOn( | 162 MockInteractions.pressAndReleaseKeyOn( |
163 document.body, '', redoModifier, redoKey); | 163 document.body, '', redoModifier, redoKey); |
164 commandManager.assertLastCommand('redo'); | 164 commandManager.assertLastCommand('redo'); |
165 }); | 165 }); |
166 | 166 |
| 167 test.only('Show In Folder is only available during search', function() { |
| 168 store.data.selection.items = new Set(['12']); |
| 169 store.notifyObservers(); |
| 170 |
| 171 commandManager.openCommandMenuAtPosition(0, 0, MenuSource.LIST); |
| 172 Polymer.dom.flush(); |
| 173 |
| 174 var showInFolderItem = |
| 175 commandManager.root.querySelector('[command=show-in-folder]'); |
| 176 |
| 177 // Show in folder hidden when search is inactive. |
| 178 assertTrue(showInFolderItem.hidden); |
| 179 |
| 180 // Show in Folder visible when search is active. |
| 181 store.data.search.term = 'test'; |
| 182 store.data.search.results = ['12', '13']; |
| 183 store.notifyObservers(); |
| 184 commandManager.closeCommandMenu(); |
| 185 commandManager.openCommandMenuAtPosition(0, 0, MenuSource.LIST); |
| 186 assertFalse(showInFolderItem.hidden); |
| 187 |
| 188 // Show in Folder hidden when menu is opened from the sidebar. |
| 189 commandManager.closeCommandMenu(); |
| 190 commandManager.openCommandMenuAtPosition(0, 0, MenuSource.TREE); |
| 191 assertTrue(showInFolderItem.hidden); |
| 192 |
| 193 // Show in Folder hidden when multiple items are selected. |
| 194 store.data.selection.items = new Set(['12', '13']); |
| 195 store.notifyObservers(); |
| 196 commandManager.closeCommandMenu(); |
| 197 commandManager.openCommandMenuAtPosition(0, 0, MenuSource.LIST); |
| 198 assertTrue(showInFolderItem.hidden); |
| 199 |
| 200 // Executing the command selects the parent folder. |
| 201 commandManager.handle(Command.SHOW_IN_FOLDER, new Set(['12'])); |
| 202 assertEquals('select-folder', store.lastAction.name); |
| 203 assertEquals('1', store.lastAction.id); |
| 204 }); |
| 205 |
167 test('does not delete children at same time as ancestor', function() { | 206 test('does not delete children at same time as ancestor', function() { |
168 var lastDelete = null; | 207 var lastDelete = null; |
169 chrome.bookmarkManagerPrivate.removeTrees = function(idArray) { | 208 chrome.bookmarkManagerPrivate.removeTrees = function(idArray) { |
170 lastDelete = idArray.sort(); | 209 lastDelete = idArray.sort(); |
171 }; | 210 }; |
172 | 211 |
173 var parentAndChildren = new Set(['11', '12', '111', '1221']); | 212 var parentAndChildren = new Set(['11', '12', '111', '1221']); |
174 assertTrue(commandManager.canExecute(Command.DELETE, parentAndChildren)); | 213 assertTrue(commandManager.canExecute(Command.DELETE, parentAndChildren)); |
175 commandManager.handle(Command.DELETE, parentAndChildren); | 214 commandManager.handle(Command.DELETE, parentAndChildren); |
176 | 215 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 assertFalse(dialog.open); | 278 assertFalse(dialog.open); |
240 assertEquals(20, lastCreate.url.length); | 279 assertEquals(20, lastCreate.url.length); |
241 }); | 280 }); |
242 | 281 |
243 test('cannot execute "Open in New Tab" on folders with no items', function() { | 282 test('cannot execute "Open in New Tab" on folders with no items', function() { |
244 var items = new Set(['2']); | 283 var items = new Set(['2']); |
245 assertFalse(commandManager.canExecute(Command.OPEN_NEW_TAB, items)); | 284 assertFalse(commandManager.canExecute(Command.OPEN_NEW_TAB, items)); |
246 | 285 |
247 store.data.selection.items = items; | 286 store.data.selection.items = items; |
248 | 287 |
249 commandManager.openCommandMenuAtPosition(0, 0); | 288 commandManager.openCommandMenuAtPosition(0, 0, MenuSource.LIST); |
250 Polymer.dom.flush(); | 289 Polymer.dom.flush(); |
251 | 290 |
252 var commandItem = {}; | 291 var commandItem = {}; |
253 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { | 292 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { |
254 commandItem[element.getAttribute('command')] = element; | 293 commandItem[element.getAttribute('command')] = element; |
255 }); | 294 }); |
256 | 295 |
257 assertTrue(commandItem[Command.OPEN_NEW_TAB].disabled); | 296 assertTrue(commandItem[Command.OPEN_NEW_TAB].disabled); |
258 assertFalse(commandItem[Command.OPEN_NEW_TAB].hidden); | 297 assertFalse(commandItem[Command.OPEN_NEW_TAB].hidden); |
259 | 298 |
(...skipping 10 matching lines...) Expand all Loading... |
270 store.data.prefs.canEdit = false; | 309 store.data.prefs.canEdit = false; |
271 store.data.selection.items = items; | 310 store.data.selection.items = items; |
272 store.notifyObservers(); | 311 store.notifyObservers(); |
273 | 312 |
274 assertFalse(commandManager.canExecute(Command.EDIT, items)); | 313 assertFalse(commandManager.canExecute(Command.EDIT, items)); |
275 assertFalse(commandManager.canExecute(Command.DELETE, items)); | 314 assertFalse(commandManager.canExecute(Command.DELETE, items)); |
276 assertFalse(commandManager.canExecute(Command.UNDO, items)); | 315 assertFalse(commandManager.canExecute(Command.UNDO, items)); |
277 assertFalse(commandManager.canExecute(Command.REDO, items)); | 316 assertFalse(commandManager.canExecute(Command.REDO, items)); |
278 | 317 |
279 // No divider line should be visible when only 'Open' commands are enabled. | 318 // No divider line should be visible when only 'Open' commands are enabled. |
280 commandManager.openCommandMenuAtPosition(0, 0); | 319 commandManager.openCommandMenuAtPosition(0, 0, MenuSource.LIST); |
281 commandManager.root.querySelectorAll('hr').forEach(element => { | 320 commandManager.root.querySelectorAll('hr').forEach(element => { |
282 assertTrue(element.hidden); | 321 assertTrue(element.hidden); |
283 }); | 322 }); |
284 }); | 323 }); |
285 | 324 |
286 test('cannot edit unmodifiable nodes', function() { | 325 test('cannot edit unmodifiable nodes', function() { |
287 // Cannot edit root folders. | 326 // Cannot edit root folders. |
288 var items = new Set(['1']); | 327 var items = new Set(['1']); |
289 store.data.selection.items = items; | 328 store.data.selection.items = items; |
290 assertFalse(commandManager.canExecute(Command.EDIT, items)); | 329 assertFalse(commandManager.canExecute(Command.EDIT, items)); |
291 assertFalse(commandManager.canExecute(Command.DELETE, items)); | 330 assertFalse(commandManager.canExecute(Command.DELETE, items)); |
292 | 331 |
293 store.data.nodes['12'].unmodifiable = 'managed'; | 332 store.data.nodes['12'].unmodifiable = 'managed'; |
294 store.notifyObservers(); | 333 store.notifyObservers(); |
295 | 334 |
296 items = new Set(['12']); | 335 items = new Set(['12']); |
297 assertFalse(commandManager.canExecute(Command.EDIT, items)); | 336 assertFalse(commandManager.canExecute(Command.EDIT, items)); |
298 assertFalse(commandManager.canExecute(Command.DELETE, items)); | 337 assertFalse(commandManager.canExecute(Command.DELETE, items)); |
299 | 338 |
300 commandManager.openCommandMenuAtPosition(0, 0); | 339 commandManager.openCommandMenuAtPosition(0, 0, MenuSource.LIST); |
301 var commandItem = {}; | 340 var commandItem = {}; |
302 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { | 341 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { |
303 commandItem[element.getAttribute('command')] = element; | 342 commandItem[element.getAttribute('command')] = element; |
304 }); | 343 }); |
305 MockInteractions.tap(commandItem[Command.EDIT]); | 344 MockInteractions.tap(commandItem[Command.EDIT]); |
306 commandManager.assertLastCommand(null); | 345 commandManager.assertLastCommand(null); |
307 }); | 346 }); |
308 }); | 347 }); |
309 | 348 |
310 suite('<bookmarks-item> CommandManager integration', function() { | 349 suite('<bookmarks-item> CommandManager integration', function() { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 424 |
386 test('meta-down triggers Open on Mac', function() { | 425 test('meta-down triggers Open on Mac', function() { |
387 if (!cr.isMac) | 426 if (!cr.isMac) |
388 return; | 427 return; |
389 | 428 |
390 customClick(items[0]); | 429 customClick(items[0]); |
391 MockInteractions.pressAndReleaseKeyOn(items[0], 0, 'meta', 'ArrowDown'); | 430 MockInteractions.pressAndReleaseKeyOn(items[0], 0, 'meta', 'ArrowDown'); |
392 assertEquals('11', store.data.selectedFolder); | 431 assertEquals('11', store.data.selectedFolder); |
393 }); | 432 }); |
394 }); | 433 }); |
OLD | NEW |