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

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

Issue 2850763002: MD Bookmarks: Update Delete command to only delete the minimal set of nodes (Closed)
Patch Set: Review comments Created 3 years, 7 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
« no previous file with comments | « chrome/browser/resources/md_bookmarks/command_manager.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 function assertLastCommand(command, ids) { 11 function assertLastCommand(command, ids) {
12 assertEquals(lastCommand, command); 12 assertEquals(lastCommand, command);
13 if (ids) 13 if (ids)
14 assertDeepEquals(normalizeSet(lastCommandIds), ids); 14 assertDeepEquals(normalizeSet(lastCommandIds), ids);
15 lastCommand = null; 15 lastCommand = null;
16 lastCommandIds = null; 16 lastCommandIds = null;
17 } 17 }
18 18
19 suiteSetup(function() { 19 suiteSetup(function() {
20 // Overwrite bookmarkManagerPrivate APIs which will crash if called with 20 // Overwrite bookmarkManagerPrivate APIs which will crash if called with
21 // fake data. 21 // fake data.
22 chrome.bookmarkManagerPrivate.copy = function() {}; 22 chrome.bookmarkManagerPrivate.copy = function() {};
23 chrome.bookmarkManagerPrivate.removeTrees = function() {}; 23 chrome.bookmarkManagerPrivate.removeTrees = function() {};
24 }); 24 });
25 25
26 setup(function() { 26 setup(function() {
27 store = new bookmarks.TestStore({ 27 store = new bookmarks.TestStore({
28 nodes: testTree(createFolder( 28 nodes: testTree(
29 '1', 29 createFolder(
30 [ 30 '1',
31 createFolder('11', []), 31 [
32 createFolder('12', []), 32 createFolder(
33 createItem('13'), 33 '11',
34 ])), 34 [
35 createItem('111'),
36 ]),
37 createFolder('12', []),
38 createItem('13'),
39 ]),
40 createFolder('2', [])),
35 }); 41 });
36 bookmarks.Store.instance_ = store; 42 bookmarks.Store.instance_ = store;
37 43
38 commandManager = document.createElement('bookmarks-command-manager'); 44 commandManager = document.createElement('bookmarks-command-manager');
39 45
40 var realHandle = commandManager.handle.bind(commandManager); 46 var realHandle = commandManager.handle.bind(commandManager);
41 commandManager.handle = function(command, itemIds) { 47 commandManager.handle = function(command, itemIds) {
42 lastCommand = command; 48 lastCommand = command;
43 lastCommandIds = itemIds; 49 lastCommandIds = itemIds;
44 realHandle(command, itemIds); 50 realHandle(command, itemIds);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 test('edit command triggers', function() { 110 test('edit command triggers', function() {
105 var key = cr.isMac ? 'Enter' : 'F2'; 111 var key = cr.isMac ? 'Enter' : 'F2';
106 var keyCode = cr.isMac ? 13 : 113; 112 var keyCode = cr.isMac ? 13 : 113;
107 113
108 store.data.selection.items = new Set(['11']); 114 store.data.selection.items = new Set(['11']);
109 store.notifyObservers(); 115 store.notifyObservers();
110 116
111 MockInteractions.pressAndReleaseKeyOn(document, keyCode, '', key); 117 MockInteractions.pressAndReleaseKeyOn(document, keyCode, '', key);
112 assertLastCommand('edit', ['11']); 118 assertLastCommand('edit', ['11']);
113 }); 119 });
120
121 test('does not delete children at same time as ancestor', function() {
122 var lastDelete = null;
123 chrome.bookmarkManagerPrivate.removeTrees = function(idArray) {
124 lastDelete = idArray.sort();
125 };
126
127 var parentAndChildren = new Set(['1', '2', '12', '111']);
128 assertTrue(commandManager.canExecute(Command.DELETE, parentAndChildren));
129 commandManager.handle(Command.DELETE, parentAndChildren);
130
131 assertDeepEquals(['1', '2'], lastDelete);
132 });
114 }); 133 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/command_manager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698