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 14 matching lines...) Expand all Loading... | |
25 | 25 |
26 setup(function() { | 26 setup(function() { |
27 store = new bookmarks.TestStore({ | 27 store = new bookmarks.TestStore({ |
28 nodes: testTree( | 28 nodes: testTree( |
29 createFolder( | 29 createFolder( |
30 '1', | 30 '1', |
31 [ | 31 [ |
32 createFolder( | 32 createFolder( |
33 '11', | 33 '11', |
34 [ | 34 [ |
35 createItem('111'), | 35 createItem('111', {url: 'http://111/'}), |
36 ]), | 36 ]), |
37 createFolder('12', []), | 37 createFolder( |
38 createItem('13'), | 38 '12', |
39 [ | |
40 createItem('121', {url: 'http://121/'}), | |
41 ]), | |
42 createItem('13', {url: 'http://13/'}), | |
39 ]), | 43 ]), |
40 createFolder('2', [])), | 44 createFolder( |
45 '2', | |
46 [ | |
47 createFolder('21', []), | |
48 ])) | |
41 }); | 49 }); |
42 bookmarks.Store.instance_ = store; | 50 bookmarks.Store.instance_ = store; |
43 | 51 |
44 commandManager = document.createElement('bookmarks-command-manager'); | 52 commandManager = document.createElement('bookmarks-command-manager'); |
45 | 53 |
46 var realHandle = commandManager.handle.bind(commandManager); | 54 var realHandle = commandManager.handle.bind(commandManager); |
47 commandManager.handle = function(command, itemIds) { | 55 commandManager.handle = function(command, itemIds) { |
48 lastCommand = command; | 56 lastCommand = command; |
49 lastCommandIds = itemIds; | 57 lastCommandIds = itemIds; |
50 realHandle(command, itemIds); | 58 realHandle(command, itemIds); |
51 }; | 59 }; |
52 replaceBody(commandManager); | 60 replaceBody(commandManager); |
61 | |
62 Polymer.dom.flush(); | |
53 }); | 63 }); |
54 | 64 |
55 test('can only copy single URL items', function() { | 65 test('can only copy single URL items', function() { |
56 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11']))); | 66 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11']))); |
57 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11', '13']))); | 67 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11', '13']))); |
58 assertTrue(commandManager.canExecute(Command.COPY, new Set(['13']))); | 68 assertTrue(commandManager.canExecute(Command.COPY, new Set(['13']))); |
59 }); | 69 }); |
60 | 70 |
61 test('context menu hides invalid commands', function() { | 71 test('context menu hides invalid commands', function() { |
62 store.data.selection.items = new Set(['11', '13']); | 72 store.data.selection.items = new Set(['11', '13']); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 chrome.bookmarkManagerPrivate.removeTrees = function(idArray) { | 133 chrome.bookmarkManagerPrivate.removeTrees = function(idArray) { |
124 lastDelete = idArray.sort(); | 134 lastDelete = idArray.sort(); |
125 }; | 135 }; |
126 | 136 |
127 var parentAndChildren = new Set(['1', '2', '12', '111']); | 137 var parentAndChildren = new Set(['1', '2', '12', '111']); |
128 assertTrue(commandManager.canExecute(Command.DELETE, parentAndChildren)); | 138 assertTrue(commandManager.canExecute(Command.DELETE, parentAndChildren)); |
129 commandManager.handle(Command.DELETE, parentAndChildren); | 139 commandManager.handle(Command.DELETE, parentAndChildren); |
130 | 140 |
131 assertDeepEquals(['1', '2'], lastDelete); | 141 assertDeepEquals(['1', '2'], lastDelete); |
132 }); | 142 }); |
143 | |
144 test('expandUrls_ expands one level of URLs', function() { | |
145 var urls = commandManager.expandUrls_(new Set(['1'])); | |
146 assertDeepEquals(['http://13/'], urls); | |
147 | |
148 urls = commandManager.expandUrls_(new Set(['11', '12', '13'])); | |
149 assertDeepEquals(['http://111/', 'http://121/', 'http://13/'], urls); | |
150 }); | |
151 | |
152 test('shift-enter opens URLs in new window', function() { | |
153 store.data.selection.items = new Set(['12', '13']); | |
154 store.notifyObservers(); | |
155 | |
156 var lastCreate; | |
157 chrome.windows.create = function(createConfig) { | |
158 lastCreate = createConfig; | |
159 }; | |
160 | |
161 MockInteractions.pressAndReleaseKeyOn(document, 13, 'shift', 'Enter'); | |
162 assertLastCommand(Command.OPEN_NEW_WINDOW, ['12', '13']); | |
163 assertDeepEquals(['http://121/', 'http://13/'], lastCreate.url); | |
164 assertFalse(lastCreate.incognito); | |
165 }); | |
166 | |
167 test('cannot execute "Open in New Tab" on folders with no items', function() { | |
168 var items = new Set(['2']); | |
169 assertFalse(commandManager.canExecute(Command.OPEN_NEW_TAB, items)); | |
170 | |
171 store.data.selection.items = items; | |
172 | |
173 commandManager.openCommandMenuAtPosition(0, 0); | |
174 var commandItem = {}; | |
175 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { | |
176 commandItem[element.getAttribute('command')] = element; | |
177 }); | |
178 | |
179 assertTrue(commandItem[Command.OPEN_NEW_TAB].disabled); | |
180 assertFalse(commandItem[Command.OPEN_NEW_TAB].hidden); | |
181 | |
182 assertTrue(commandItem[Command.OPEN_INCOGNITO].disabled); | |
183 assertFalse(commandItem[Command.OPEN_INCOGNITO].hidden); | |
calamity
2017/05/12 03:22:52
Why is OPEN_NEW_WINDOW not included here?
tsergeant
2017/05/12 05:15:27
Laziness, mostly. I don't really expect it to dive
| |
184 }); | |
133 }); | 185 }); |
OLD | NEW |