| 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 suiteSetup(function() { | 11 suiteSetup(function() { |
| 12 // Overwrite bookmarkManagerPrivate APIs which will crash if called with | 12 // Overwrite bookmarkManagerPrivate APIs which will crash if called with |
| 13 // fake data. | 13 // fake data. |
| 14 chrome.bookmarkManagerPrivate.copy = function() {}; | 14 chrome.bookmarkManagerPrivate.copy = function() {}; |
| 15 chrome.bookmarkManagerPrivate.removeTrees = function() {}; | 15 chrome.bookmarkManagerPrivate.removeTrees = function() {}; |
| 16 }); | 16 }); |
| 17 | 17 |
| 18 setup(function() { | 18 setup(function() { |
| 19 var bulkChildren = []; |
| 20 for (var i = 1; i <= 20; i++) { |
| 21 var id = '3' + i; |
| 22 bulkChildren.push(createItem(id, {url: `http://${id}/`})); |
| 23 } |
| 24 |
| 19 store = new bookmarks.TestStore({ | 25 store = new bookmarks.TestStore({ |
| 20 nodes: testTree( | 26 nodes: testTree( |
| 21 createFolder( | 27 createFolder( |
| 22 '1', | 28 '1', |
| 23 [ | 29 [ |
| 24 createFolder( | 30 createFolder( |
| 25 '11', | 31 '11', |
| 26 [ | 32 [ |
| 27 createItem('111', {url: 'http://111/'}), | 33 createItem('111', {url: 'http://111/'}), |
| 28 ]), | 34 ]), |
| 29 createFolder( | 35 createFolder( |
| 30 '12', | 36 '12', |
| 31 [ | 37 [ |
| 32 createItem('121', {url: 'http://121/'}), | 38 createItem('121', {url: 'http://121/'}), |
| 33 createFolder( | 39 createFolder( |
| 34 '122', | 40 '122', |
| 35 [ | 41 [ |
| 36 createItem('1221'), | 42 createItem('1221'), |
| 37 ]), | 43 ]), |
| 38 ]), | 44 ]), |
| 39 createItem('13', {url: 'http://13/'}), | 45 createItem('13', {url: 'http://13/'}), |
| 40 ]), | 46 ]), |
| 41 createFolder( | 47 createFolder( |
| 42 '2', | 48 '2', |
| 43 [ | 49 [ |
| 44 createFolder('21', []), | 50 createFolder('21', []), |
| 45 ])) | 51 ]), |
| 52 createFolder('3', bulkChildren)), |
| 46 }); | 53 }); |
| 47 store.replaceSingleton(); | 54 store.replaceSingleton(); |
| 48 | 55 |
| 49 commandManager = new TestCommandManager(); | 56 commandManager = new TestCommandManager(); |
| 50 replaceBody(commandManager); | 57 replaceBody(commandManager); |
| 51 document.body.appendChild( | 58 document.body.appendChild( |
| 52 document.createElement('bookmarks-toast-manager')); | 59 document.createElement('bookmarks-toast-manager')); |
| 53 | 60 |
| 54 Polymer.dom.flush(); | 61 Polymer.dom.flush(); |
| 55 }); | 62 }); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 test('shift-enter does not trigger enter commands', function() { | 181 test('shift-enter does not trigger enter commands', function() { |
| 175 // Enter by itself performs an edit (Mac) or open (non-Mac). Ensure that | 182 // Enter by itself performs an edit (Mac) or open (non-Mac). Ensure that |
| 176 // shift-enter doesn't trigger those commands. | 183 // shift-enter doesn't trigger those commands. |
| 177 store.data.selection.items = new Set(['13']); | 184 store.data.selection.items = new Set(['13']); |
| 178 store.notifyObservers(); | 185 store.notifyObservers(); |
| 179 | 186 |
| 180 MockInteractions.pressAndReleaseKeyOn(document.body, 13, 'shift', 'Enter'); | 187 MockInteractions.pressAndReleaseKeyOn(document.body, 13, 'shift', 'Enter'); |
| 181 commandManager.assertLastCommand(Command.OPEN_NEW_WINDOW); | 188 commandManager.assertLastCommand(Command.OPEN_NEW_WINDOW); |
| 182 }); | 189 }); |
| 183 | 190 |
| 191 test('opening many items causes a confirmation dialog', function() { |
| 192 var lastCreate = null; |
| 193 chrome.windows.create = function(createConfig) { |
| 194 lastCreate = createConfig; |
| 195 }; |
| 196 |
| 197 var items = new Set(['3']); |
| 198 assertTrue(commandManager.canExecute(Command.OPEN_NEW_WINDOW, items)); |
| 199 |
| 200 commandManager.handle(Command.OPEN_NEW_WINDOW, items); |
| 201 // No window should be created right away. |
| 202 assertEquals(null, lastCreate); |
| 203 |
| 204 var dialog = commandManager.$.openDialog.getIfExists(); |
| 205 assertTrue(dialog.open); |
| 206 |
| 207 // Pressing 'cancel' should not open the window. |
| 208 MockInteractions.tap(dialog.querySelector('.cancel-button')); |
| 209 assertFalse(dialog.open); |
| 210 assertEquals(null, lastCreate); |
| 211 |
| 212 commandManager.handle(Command.OPEN_NEW_WINDOW, items); |
| 213 assertTrue(dialog.open); |
| 214 |
| 215 // Pressing 'yes' will open all the URLs. |
| 216 MockInteractions.tap(dialog.querySelector('.action-button')); |
| 217 assertFalse(dialog.open); |
| 218 assertEquals(20, lastCreate.url.length); |
| 219 }); |
| 220 |
| 184 test('cannot execute "Open in New Tab" on folders with no items', function() { | 221 test('cannot execute "Open in New Tab" on folders with no items', function() { |
| 185 var items = new Set(['2']); | 222 var items = new Set(['2']); |
| 186 assertFalse(commandManager.canExecute(Command.OPEN_NEW_TAB, items)); | 223 assertFalse(commandManager.canExecute(Command.OPEN_NEW_TAB, items)); |
| 187 | 224 |
| 188 store.data.selection.items = items; | 225 store.data.selection.items = items; |
| 189 | 226 |
| 190 commandManager.openCommandMenuAtPosition(0, 0); | 227 commandManager.openCommandMenuAtPosition(0, 0); |
| 191 var commandItem = {}; | 228 var commandItem = {}; |
| 192 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { | 229 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { |
| 193 commandItem[element.getAttribute('command')] = element; | 230 commandItem[element.getAttribute('command')] = element; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 assertOpenedTabs(['http://111/', 'http://12/']); | 343 assertOpenedTabs(['http://111/', 'http://12/']); |
| 307 }); | 344 }); |
| 308 | 345 |
| 309 test('control-double click opens full selection', function() { | 346 test('control-double click opens full selection', function() { |
| 310 customClick(items[0]); | 347 customClick(items[0]); |
| 311 simulateDoubleClick(items[2], {ctrlKey: true}); | 348 simulateDoubleClick(items[2], {ctrlKey: true}); |
| 312 | 349 |
| 313 assertOpenedTabs(['http://111/', 'http://13/']); | 350 assertOpenedTabs(['http://111/', 'http://13/']); |
| 314 }); | 351 }); |
| 315 }); | 352 }); |
| OLD | NEW |