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; | |
9 var lastCommandIds; | |
10 | |
11 function assertLastCommand(command, ids) { | |
12 assertEquals(lastCommand, command); | |
13 if (ids) | |
14 assertDeepEquals(normalizeSet(lastCommandIds), ids); | |
15 lastCommand = null; | |
16 lastCommandIds = null; | |
17 } | |
18 | |
19 suiteSetup(function() { | |
20 // Overwrite bookmarkManagerPrivate APIs which will crash if called with | |
21 // fake data. | |
22 chrome.bookmarkManagerPrivate.copy = function() {}; | |
23 chrome.bookmarkManagerPrivate.removeTrees = function() {}; | |
24 }); | |
8 | 25 |
9 setup(function() { | 26 setup(function() { |
10 store = new bookmarks.TestStore({ | 27 store = new bookmarks.TestStore({ |
11 nodes: testTree(createFolder( | 28 nodes: testTree(createFolder( |
12 '1', | 29 '1', |
13 [ | 30 [ |
14 createFolder('11', []), | 31 createFolder('11', []), |
15 createFolder('12', []), | 32 createFolder('12', []), |
16 createItem('13'), | 33 createItem('13'), |
17 ])), | 34 ])), |
18 }); | 35 }); |
19 bookmarks.Store.instance_ = store; | 36 bookmarks.Store.instance_ = store; |
20 | 37 |
21 commandManager = document.createElement('bookmarks-command-manager'); | 38 commandManager = document.createElement('bookmarks-command-manager'); |
39 | |
40 var realHandle = commandManager.handle.bind(commandManager); | |
41 commandManager.handle = function(command, itemIds) { | |
42 lastCommand = command; | |
43 lastCommandIds = itemIds; | |
44 realHandle(command, itemIds); | |
45 }; | |
22 replaceBody(commandManager); | 46 replaceBody(commandManager); |
23 }); | 47 }); |
24 | 48 |
25 test('can only copy single URL items', function() { | 49 test('can only copy single URL items', function() { |
26 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11']))); | 50 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11']))); |
27 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11', '13']))); | 51 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11', '13']))); |
28 assertTrue(commandManager.canExecute(Command.COPY, new Set(['13']))); | 52 assertTrue(commandManager.canExecute(Command.COPY, new Set(['13']))); |
29 }); | 53 }); |
30 | 54 |
31 test('context menu hides invalid commands', function() { | 55 test('context menu hides invalid commands', function() { |
32 store.data.selection.items = new Set(['11', '13']); | 56 store.data.selection.items = new Set(['11', '13']); |
33 store.notifyObservers(); | 57 store.notifyObservers(); |
34 | 58 |
35 commandManager.openCommandMenuAtPosition(0, 0); | 59 commandManager.openCommandMenuAtPosition(0, 0); |
36 var commandHidden = {}; | 60 var commandHidden = {}; |
37 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { | 61 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { |
38 commandHidden[element.getAttribute('command')] = element.hidden; | 62 commandHidden[element.getAttribute('command')] = element.hidden; |
39 }); | 63 }); |
40 | 64 |
41 // With a folder and an item selected, the only available context menu item | 65 // With a folder and an item selected, the only available context menu item |
42 // is 'Delete'. | 66 // is 'Delete'. |
43 assertTrue(commandHidden['edit']); | 67 assertTrue(commandHidden['edit']); |
44 assertTrue(commandHidden['copy']); | 68 assertTrue(commandHidden['copy']); |
45 assertFalse(commandHidden['delete']); | 69 assertFalse(commandHidden['delete']); |
46 }); | 70 }); |
71 | |
72 test('keyboard shortcuts trigger when valid', function() { | |
73 var modifier = cr.isMac ? 'meta' : 'ctrl'; | |
74 | |
75 store.data.selection.items = new Set(['13']); | |
76 store.notifyObservers(); | |
77 | |
78 MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); | |
79 assertLastCommand('copy', ['13']); | |
80 | |
81 store.data.selection.items = new Set(['11']); | |
82 store.notifyObservers(); | |
83 | |
84 MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); | |
85 assertLastCommand(null); | |
calamity
2017/04/26 10:07:58
Add a case for empty selection too.
tsergeant
2017/04/27 01:42:51
Done.
| |
86 }); | |
87 | |
88 test('delete command triggers', function() { | |
tsergeant
2017/04/26 08:10:55
I'm not totally convinced how useful this test and
| |
89 store.data.selection.items = new Set(['12', '13']); | |
90 store.notifyObservers(); | |
91 | |
92 MockInteractions.pressAndReleaseKeyOn(document, 46, '', 'Delete'); | |
93 assertLastCommand('delete', ['12', '13']); | |
94 }); | |
95 | |
96 test('edit command triggers', function() { | |
97 var key = cr.isMac ? 'Enter' : 'F2'; | |
98 var keyCode = cr.isMac ? 13 : 113; | |
99 | |
100 store.data.selection.items = new Set(['11']); | |
101 store.notifyObservers(); | |
102 | |
103 MockInteractions.pressAndReleaseKeyOn(document, keyCode, '', key); | |
104 assertLastCommand('edit', ['11']); | |
105 }); | |
47 }); | 106 }); |
OLD | NEW |