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 var bmpCopyFunction; |
| 11 var bmpPasteFunction; |
10 | 12 |
11 suiteSetup(function() { | 13 suiteSetup(function() { |
12 // Overwrite bookmarkManagerPrivate APIs which will crash if called with | 14 // Overwrite bookmarkManagerPrivate APIs which will crash if called with |
13 // fake data. | 15 // fake data. |
| 16 bmpCopyFunction = chrome.bookmarkManagerPrivate.copy; |
| 17 bmpPasteFunction = chrome.bookmarkManagerPrivate.paste; |
14 chrome.bookmarkManagerPrivate.copy = function() {}; | 18 chrome.bookmarkManagerPrivate.copy = function() {}; |
15 chrome.bookmarkManagerPrivate.removeTrees = function() {}; | 19 chrome.bookmarkManagerPrivate.removeTrees = function() {}; |
16 }); | 20 }); |
17 | 21 |
| 22 suiteTeardown(function() { |
| 23 chrome.bookmarkManagerPrivate.copy = bmpCopyFunction; |
| 24 chrome.bookmarkManagerPrivate.paste = bmpPasteFunction; |
| 25 }); |
| 26 |
18 setup(function() { | 27 setup(function() { |
19 var bulkChildren = []; | 28 var bulkChildren = []; |
20 for (var i = 1; i <= 20; i++) { | 29 for (var i = 1; i <= 20; i++) { |
21 var id = '3' + i; | 30 var id = '3' + i; |
22 bulkChildren.push(createItem(id, {url: `http://${id}/`})); | 31 bulkChildren.push(createItem(id, {url: `http://${id}/`})); |
23 } | 32 } |
24 | 33 |
25 store = new bookmarks.TestStore({ | 34 store = new bookmarks.TestStore({ |
26 nodes: testTree( | 35 nodes: testTree( |
27 createFolder( | 36 createFolder( |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 test('cut/paste commands trigger', function() { | 141 test('cut/paste commands trigger', function() { |
133 var lastCut; | 142 var lastCut; |
134 var lastPaste; | 143 var lastPaste; |
135 chrome.bookmarkManagerPrivate.cut = function(idList) { | 144 chrome.bookmarkManagerPrivate.cut = function(idList) { |
136 lastCut = idList.sort(); | 145 lastCut = idList.sort(); |
137 }; | 146 }; |
138 chrome.bookmarkManagerPrivate.paste = function(selectedFolder) { | 147 chrome.bookmarkManagerPrivate.paste = function(selectedFolder) { |
139 lastPaste = selectedFolder; | 148 lastPaste = selectedFolder; |
140 }; | 149 }; |
141 | 150 |
142 var modifier = cr.isMac ? 'meta' : 'ctrl'; | |
143 | |
144 store.data.selection.items = new Set(['11', '13']); | 151 store.data.selection.items = new Set(['11', '13']); |
145 store.notifyObservers(); | 152 store.notifyObservers(); |
146 | 153 |
| 154 var modifier = cr.isMac ? 'meta' : 'ctrl'; |
147 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'x'); | 155 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'x'); |
148 assertDeepEquals(['11', '13'], lastCut); | 156 assertDeepEquals(['11', '13'], lastCut); |
149 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'v'); | 157 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'v'); |
150 assertEquals('1', lastPaste); | 158 assertEquals('1', lastPaste); |
151 }); | 159 }); |
152 | 160 |
153 test('undo and redo commands trigger', function() { | 161 test('undo and redo commands trigger', function() { |
154 var undoModifier = cr.isMac ? 'meta' : 'ctrl'; | 162 var undoModifier = cr.isMac ? 'meta' : 'ctrl'; |
155 var undoKey = 'z'; | 163 var undoKey = 'z'; |
156 var redoModifier = cr.isMac ? ['meta', 'shift'] : 'ctrl' | 164 var redoModifier = cr.isMac ? ['meta', 'shift'] : 'ctrl' |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 assertOpenedTabs(['http://111/', 'http://12/']); | 439 assertOpenedTabs(['http://111/', 'http://12/']); |
432 }); | 440 }); |
433 | 441 |
434 test('control-double click opens full selection', function() { | 442 test('control-double click opens full selection', function() { |
435 customClick(items[0]); | 443 customClick(items[0]); |
436 simulateDoubleClick(items[2], {ctrlKey: true}); | 444 simulateDoubleClick(items[2], {ctrlKey: true}); |
437 | 445 |
438 assertOpenedTabs(['http://111/', 'http://13/']); | 446 assertOpenedTabs(['http://111/', 'http://13/']); |
439 }); | 447 }); |
440 }); | 448 }); |
| 449 |
| 450 suite('<bookmarks-command-manager> whole page integration', function() { |
| 451 var app; |
| 452 var store; |
| 453 var commandManager; |
| 454 |
| 455 var testFolderId; |
| 456 |
| 457 function create(bookmark) { |
| 458 return new Promise(function(resolve) { |
| 459 chrome.bookmarks.create(bookmark, resolve); |
| 460 }); |
| 461 } |
| 462 |
| 463 suiteSetup(function() { |
| 464 var testFolder = { |
| 465 parentId: '1', |
| 466 title: 'Test', |
| 467 }; |
| 468 return create(testFolder).then(function(testFolderNode) { |
| 469 testFolderId = testFolderNode.id; |
| 470 var testItem = { |
| 471 parentId: testFolderId, |
| 472 title: 'Test bookmark', |
| 473 url: 'https://www.example.com/', |
| 474 }; |
| 475 return Promise.all([ |
| 476 create(testItem), |
| 477 create(testItem), |
| 478 ]); |
| 479 }); |
| 480 }); |
| 481 |
| 482 setup(function() { |
| 483 store = new bookmarks.TestStore({}); |
| 484 store.replaceSingleton(); |
| 485 store.setReducersEnabled(true); |
| 486 var promise = store.acceptInitOnce(); |
| 487 var app = document.createElement('bookmarks-app'); |
| 488 replaceBody(app); |
| 489 |
| 490 commandManager = bookmarks.CommandManager.getInstance(); |
| 491 |
| 492 return promise.then(() => { |
| 493 store.dispatch(bookmarks.actions.selectFolder(testFolderId)); |
| 494 }); |
| 495 }); |
| 496 |
| 497 test('paste selects newly created items', function() { |
| 498 var displayedIdsBefore = bookmarks.util.getDisplayedList(store.data); |
| 499 commandManager.handle(Command.SELECT_ALL, new Set()); |
| 500 commandManager.handle(Command.COPY, new Set(displayedIdsBefore)); |
| 501 |
| 502 store.expectAction('select-items'); |
| 503 commandManager.handle(Command.PASTE, new Set()); |
| 504 |
| 505 return store.waitForAction('select-items').then(function(action) { |
| 506 var displayedIdsAfter = bookmarks.util.getDisplayedList(store.data); |
| 507 assertEquals(4, displayedIdsAfter.length); |
| 508 |
| 509 // The start of the list shouldn't change. |
| 510 assertEquals(displayedIdsBefore[0], displayedIdsAfter[0]); |
| 511 assertEquals(displayedIdsBefore[1], displayedIdsAfter[1]); |
| 512 |
| 513 // The two pasted items should be selected at the end of the list. |
| 514 assertEquals(action.items[0], displayedIdsAfter[2]); |
| 515 assertEquals(action.items[1], displayedIdsAfter[3]); |
| 516 assertEquals(2, action.items.length); |
| 517 assertEquals(action.anchor, displayedIdsAfter[2]); |
| 518 }); |
| 519 }); |
| 520 |
| 521 suiteTeardown(function(done) { |
| 522 chrome.bookmarks.removeTree(testFolderId, () => done()); |
| 523 }); |
| 524 }); |
OLD | NEW |