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

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

Issue 2912893002: MD Bookmarks: Support policies for disabling bookmark editing (Closed)
Patch Set: canEdit -> globalCanEdit Created 3 years, 6 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 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 12 matching lines...) Expand all
23 [ 23 [
24 createFolder( 24 createFolder(
25 '11', 25 '11',
26 [ 26 [
27 createItem('111', {url: 'http://111/'}), 27 createItem('111', {url: 'http://111/'}),
28 ]), 28 ]),
29 createFolder( 29 createFolder(
30 '12', 30 '12',
31 [ 31 [
32 createItem('121', {url: 'http://121/'}), 32 createItem('121', {url: 'http://121/'}),
33 createFolder(
34 '122',
35 [
36 createItem('1221'),
37 ]),
33 ]), 38 ]),
34 createItem('13', {url: 'http://13/'}), 39 createItem('13', {url: 'http://13/'}),
35 ]), 40 ]),
36 createFolder( 41 createFolder(
37 '2', 42 '2',
38 [ 43 [
39 createFolder('21', []), 44 createFolder('21', []),
40 ])) 45 ]))
41 }); 46 });
42 store.replaceSingleton(); 47 store.replaceSingleton();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 document.body, '', redoModifier, redoKey); 134 document.body, '', redoModifier, redoKey);
130 commandManager.assertLastCommand('redo'); 135 commandManager.assertLastCommand('redo');
131 }); 136 });
132 137
133 test('does not delete children at same time as ancestor', function() { 138 test('does not delete children at same time as ancestor', function() {
134 var lastDelete = null; 139 var lastDelete = null;
135 chrome.bookmarkManagerPrivate.removeTrees = function(idArray) { 140 chrome.bookmarkManagerPrivate.removeTrees = function(idArray) {
136 lastDelete = idArray.sort(); 141 lastDelete = idArray.sort();
137 }; 142 };
138 143
139 var parentAndChildren = new Set(['1', '2', '12', '111']); 144 var parentAndChildren = new Set(['11', '12', '111', '1221']);
140 assertTrue(commandManager.canExecute(Command.DELETE, parentAndChildren)); 145 assertTrue(commandManager.canExecute(Command.DELETE, parentAndChildren));
141 commandManager.handle(Command.DELETE, parentAndChildren); 146 commandManager.handle(Command.DELETE, parentAndChildren);
142 147
143 assertDeepEquals(['1', '2'], lastDelete); 148 assertDeepEquals(['11', '12'], lastDelete);
144 }); 149 });
145 150
146 test('expandUrls_ expands one level of URLs', function() { 151 test('expandUrls_ expands one level of URLs', function() {
147 var urls = commandManager.expandUrls_(new Set(['1'])); 152 var urls = commandManager.expandUrls_(new Set(['1']));
148 assertDeepEquals(['http://13/'], urls); 153 assertDeepEquals(['http://13/'], urls);
149 154
150 urls = commandManager.expandUrls_(new Set(['11', '12', '13'])); 155 urls = commandManager.expandUrls_(new Set(['11', '12', '13']));
151 assertDeepEquals(['http://111/', 'http://121/', 'http://13/'], urls); 156 assertDeepEquals(['http://111/', 'http://121/', 'http://13/'], urls);
152 }); 157 });
153 158
(...skipping 26 matching lines...) Expand all
180 185
181 assertTrue(commandItem[Command.OPEN_NEW_TAB].disabled); 186 assertTrue(commandItem[Command.OPEN_NEW_TAB].disabled);
182 assertFalse(commandItem[Command.OPEN_NEW_TAB].hidden); 187 assertFalse(commandItem[Command.OPEN_NEW_TAB].hidden);
183 188
184 assertTrue(commandItem[Command.OPEN_NEW_WINDOW].disabled); 189 assertTrue(commandItem[Command.OPEN_NEW_WINDOW].disabled);
185 assertFalse(commandItem[Command.OPEN_NEW_WINDOW].hidden); 190 assertFalse(commandItem[Command.OPEN_NEW_WINDOW].hidden);
186 191
187 assertTrue(commandItem[Command.OPEN_INCOGNITO].disabled); 192 assertTrue(commandItem[Command.OPEN_INCOGNITO].disabled);
188 assertFalse(commandItem[Command.OPEN_INCOGNITO].hidden); 193 assertFalse(commandItem[Command.OPEN_INCOGNITO].hidden);
189 }); 194 });
195
196 test('cannot execute editing commands when editing is disabled', function() {
197 var items = new Set(['12']);
198
199 store.data.prefs.canEdit = false;
200 store.data.selection.items = items;
201 store.notifyObservers();
202
203 assertFalse(commandManager.canExecute(Command.EDIT, items));
204 assertFalse(commandManager.canExecute(Command.DELETE, items));
205 assertFalse(commandManager.canExecute(Command.UNDO, items));
206 assertFalse(commandManager.canExecute(Command.REDO, items));
207
208 // No divider line should be visible when only 'Open' commands are enabled.
209 commandManager.openCommandMenuAtPosition(0, 0);
210 commandManager.root.querySelectorAll('hr').forEach(element => {
211 assertTrue(element.hidden);
212 });
213 });
214
215 test('cannot edit unmodifiable nodes', function() {
216 // Cannot edit root folders.
217 var items = new Set(['1']);
218 assertFalse(commandManager.canExecute(Command.EDIT, items));
219 assertFalse(commandManager.canExecute(Command.DELETE, items));
220
221 store.data.nodes['12'].unmodifiable = 'managed';
222 store.notifyObservers();
223
224 items = new Set(['12']);
225 assertFalse(commandManager.canExecute(Command.EDIT, items));
226 assertFalse(commandManager.canExecute(Command.DELETE, items));
227 });
190 }); 228 });
191 229
192 suite('<bookmarks-item> CommandManager integration', function() { 230 suite('<bookmarks-item> CommandManager integration', function() {
193 var list; 231 var list;
194 var items; 232 var items;
195 var commandManager; 233 var commandManager;
196 var openedTabs; 234 var openedTabs;
197 235
198 setup(function() { 236 setup(function() {
199 store = new bookmarks.TestStore({ 237 store = new bookmarks.TestStore({
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 assertOpenedTabs(['http://111/', 'http://12/']); 296 assertOpenedTabs(['http://111/', 'http://12/']);
259 }); 297 });
260 298
261 test('control-double click opens full selection', function() { 299 test('control-double click opens full selection', function() {
262 customClick(items[0]); 300 customClick(items[0]);
263 simulateDoubleClick(items[2], {ctrlKey: true}); 301 simulateDoubleClick(items[2], {ctrlKey: true});
264 302
265 assertOpenedTabs(['http://111/', 'http://13/']); 303 assertOpenedTabs(['http://111/', 'http://13/']);
266 }); 304 });
267 }); 305 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698