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 |
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() { | 11 suiteSetup(function() { |
20 // Overwrite bookmarkManagerPrivate APIs which will crash if called with | 12 // Overwrite bookmarkManagerPrivate APIs which will crash if called with |
21 // fake data. | 13 // fake data. |
22 chrome.bookmarkManagerPrivate.copy = function() {}; | 14 chrome.bookmarkManagerPrivate.copy = function() {}; |
23 chrome.bookmarkManagerPrivate.removeTrees = function() {}; | 15 chrome.bookmarkManagerPrivate.removeTrees = function() {}; |
24 }); | 16 }); |
25 | 17 |
26 setup(function() { | 18 setup(function() { |
27 store = new bookmarks.TestStore({ | 19 store = new bookmarks.TestStore({ |
28 nodes: testTree( | 20 nodes: testTree( |
(...skipping 13 matching lines...) Expand all Loading... |
42 createItem('13', {url: 'http://13/'}), | 34 createItem('13', {url: 'http://13/'}), |
43 ]), | 35 ]), |
44 createFolder( | 36 createFolder( |
45 '2', | 37 '2', |
46 [ | 38 [ |
47 createFolder('21', []), | 39 createFolder('21', []), |
48 ])) | 40 ])) |
49 }); | 41 }); |
50 bookmarks.Store.instance_ = store; | 42 bookmarks.Store.instance_ = store; |
51 | 43 |
52 commandManager = document.createElement('bookmarks-command-manager'); | 44 commandManager = new TestCommandManager(); |
53 | |
54 var realHandle = commandManager.handle.bind(commandManager); | |
55 commandManager.handle = function(command, itemIds) { | |
56 lastCommand = command; | |
57 lastCommandIds = itemIds; | |
58 realHandle(command, itemIds); | |
59 }; | |
60 replaceBody(commandManager); | 45 replaceBody(commandManager); |
61 | 46 |
62 Polymer.dom.flush(); | 47 Polymer.dom.flush(); |
63 }); | 48 }); |
64 | 49 |
65 test('can only copy single URL items', function() { | 50 test('can only copy single URL items', function() { |
66 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11']))); | 51 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11']))); |
67 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11', '13']))); | 52 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11', '13']))); |
68 assertTrue(commandManager.canExecute(Command.COPY, new Set(['13']))); | 53 assertTrue(commandManager.canExecute(Command.COPY, new Set(['13']))); |
69 }); | 54 }); |
(...skipping 15 matching lines...) Expand all Loading... |
85 assertFalse(commandHidden['delete']); | 70 assertFalse(commandHidden['delete']); |
86 }); | 71 }); |
87 | 72 |
88 test('keyboard shortcuts trigger when valid', function() { | 73 test('keyboard shortcuts trigger when valid', function() { |
89 var modifier = cr.isMac ? 'meta' : 'ctrl'; | 74 var modifier = cr.isMac ? 'meta' : 'ctrl'; |
90 | 75 |
91 store.data.selection.items = new Set(['13']); | 76 store.data.selection.items = new Set(['13']); |
92 store.notifyObservers(); | 77 store.notifyObservers(); |
93 | 78 |
94 MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); | 79 MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); |
95 assertLastCommand('copy', ['13']); | 80 commandManager.assertLastCommand('copy', ['13']); |
96 | 81 |
97 // Doesn't trigger when a folder is selected. | 82 // Doesn't trigger when a folder is selected. |
98 store.data.selection.items = new Set(['11']); | 83 store.data.selection.items = new Set(['11']); |
99 store.notifyObservers(); | 84 store.notifyObservers(); |
100 | 85 |
101 MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); | 86 MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); |
102 assertLastCommand(null); | 87 commandManager.assertLastCommand(null); |
103 | 88 |
104 // Doesn't trigger when nothing is selected. | 89 // Doesn't trigger when nothing is selected. |
105 store.data.selection.items = new Set(); | 90 store.data.selection.items = new Set(); |
106 store.notifyObservers(); | 91 store.notifyObservers(); |
107 | 92 |
108 MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); | 93 MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); |
109 assertLastCommand(null); | 94 commandManager.assertLastCommand(null); |
110 }); | 95 }); |
111 | 96 |
112 test('delete command triggers', function() { | 97 test('delete command triggers', function() { |
113 store.data.selection.items = new Set(['12', '13']); | 98 store.data.selection.items = new Set(['12', '13']); |
114 store.notifyObservers(); | 99 store.notifyObservers(); |
115 | 100 |
116 MockInteractions.pressAndReleaseKeyOn(document, 46, '', 'Delete'); | 101 MockInteractions.pressAndReleaseKeyOn(document, 46, '', 'Delete'); |
117 assertLastCommand('delete', ['12', '13']); | 102 commandManager.assertLastCommand('delete', ['12', '13']); |
118 }); | 103 }); |
119 | 104 |
120 test('edit command triggers', function() { | 105 test('edit command triggers', function() { |
121 var key = cr.isMac ? 'Enter' : 'F2'; | 106 var key = cr.isMac ? 'Enter' : 'F2'; |
122 var keyCode = cr.isMac ? 13 : 113; | 107 var keyCode = cr.isMac ? 13 : 113; |
123 | 108 |
124 store.data.selection.items = new Set(['11']); | 109 store.data.selection.items = new Set(['11']); |
125 store.notifyObservers(); | 110 store.notifyObservers(); |
126 | 111 |
127 MockInteractions.pressAndReleaseKeyOn(document, keyCode, '', key); | 112 MockInteractions.pressAndReleaseKeyOn(document, keyCode, '', key); |
128 assertLastCommand('edit', ['11']); | 113 commandManager.assertLastCommand('edit', ['11']); |
129 }); | 114 }); |
130 | 115 |
131 test('does not delete children at same time as ancestor', function() { | 116 test('does not delete children at same time as ancestor', function() { |
132 var lastDelete = null; | 117 var lastDelete = null; |
133 chrome.bookmarkManagerPrivate.removeTrees = function(idArray) { | 118 chrome.bookmarkManagerPrivate.removeTrees = function(idArray) { |
134 lastDelete = idArray.sort(); | 119 lastDelete = idArray.sort(); |
135 }; | 120 }; |
136 | 121 |
137 var parentAndChildren = new Set(['1', '2', '12', '111']); | 122 var parentAndChildren = new Set(['1', '2', '12', '111']); |
138 assertTrue(commandManager.canExecute(Command.DELETE, parentAndChildren)); | 123 assertTrue(commandManager.canExecute(Command.DELETE, parentAndChildren)); |
(...skipping 13 matching lines...) Expand all Loading... |
152 test('shift-enter opens URLs in new window', function() { | 137 test('shift-enter opens URLs in new window', function() { |
153 store.data.selection.items = new Set(['12', '13']); | 138 store.data.selection.items = new Set(['12', '13']); |
154 store.notifyObservers(); | 139 store.notifyObservers(); |
155 | 140 |
156 var lastCreate; | 141 var lastCreate; |
157 chrome.windows.create = function(createConfig) { | 142 chrome.windows.create = function(createConfig) { |
158 lastCreate = createConfig; | 143 lastCreate = createConfig; |
159 }; | 144 }; |
160 | 145 |
161 MockInteractions.pressAndReleaseKeyOn(document, 13, 'shift', 'Enter'); | 146 MockInteractions.pressAndReleaseKeyOn(document, 13, 'shift', 'Enter'); |
162 assertLastCommand(Command.OPEN_NEW_WINDOW, ['12', '13']); | 147 commandManager.assertLastCommand(Command.OPEN_NEW_WINDOW, ['12', '13']); |
163 assertDeepEquals(['http://121/', 'http://13/'], lastCreate.url); | 148 assertDeepEquals(['http://121/', 'http://13/'], lastCreate.url); |
164 assertFalse(lastCreate.incognito); | 149 assertFalse(lastCreate.incognito); |
165 }); | 150 }); |
166 | 151 |
167 test('cannot execute "Open in New Tab" on folders with no items', function() { | 152 test('cannot execute "Open in New Tab" on folders with no items', function() { |
168 var items = new Set(['2']); | 153 var items = new Set(['2']); |
169 assertFalse(commandManager.canExecute(Command.OPEN_NEW_TAB, items)); | 154 assertFalse(commandManager.canExecute(Command.OPEN_NEW_TAB, items)); |
170 | 155 |
171 store.data.selection.items = items; | 156 store.data.selection.items = items; |
172 | 157 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 assertOpenedTabs(['http://111/', 'http://12/']); | 241 assertOpenedTabs(['http://111/', 'http://12/']); |
257 }); | 242 }); |
258 | 243 |
259 test('control-double click opens full selection', function() { | 244 test('control-double click opens full selection', function() { |
260 customClick(items[0]); | 245 customClick(items[0]); |
261 simulateDoubleClick(items[2], {ctrlKey: true}); | 246 simulateDoubleClick(items[2], {ctrlKey: true}); |
262 | 247 |
263 assertOpenedTabs(['http://111/', 'http://13/']); | 248 assertOpenedTabs(['http://111/', 'http://13/']); |
264 }); | 249 }); |
265 }); | 250 }); |
OLD | NEW |