Chromium Code Reviews| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 test('cut/paste commands trigger', function() { | 140 test('cut/paste commands trigger', function() { |
| 132 var lastCut; | 141 var lastCut; |
| 133 var lastPaste; | 142 var lastPaste; |
| 134 chrome.bookmarkManagerPrivate.cut = function(idList) { | 143 chrome.bookmarkManagerPrivate.cut = function(idList) { |
| 135 lastCut = idList.sort(); | 144 lastCut = idList.sort(); |
| 136 }; | 145 }; |
| 137 chrome.bookmarkManagerPrivate.paste = function(selectedFolder) { | 146 chrome.bookmarkManagerPrivate.paste = function(selectedFolder) { |
| 138 lastPaste = selectedFolder; | 147 lastPaste = selectedFolder; |
| 139 }; | 148 }; |
| 140 | 149 |
| 141 var modifier = cr.isMac ? 'meta' : 'ctrl'; | |
| 142 | |
| 143 store.data.selection.items = new Set(['11', '13']); | 150 store.data.selection.items = new Set(['11', '13']); |
| 144 store.notifyObservers(); | 151 store.notifyObservers(); |
| 145 | 152 |
| 153 var modifier = cr.isMac ? 'meta' : 'ctrl'; | |
| 146 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'x'); | 154 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'x'); |
| 147 assertDeepEquals(['11', '13'], lastCut); | 155 assertDeepEquals(['11', '13'], lastCut); |
| 148 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'v'); | 156 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'v'); |
| 149 assertEquals('1', lastPaste); | 157 assertEquals('1', lastPaste); |
| 150 }); | 158 }); |
| 151 | 159 |
| 152 test('undo and redo commands trigger', function() { | 160 test('undo and redo commands trigger', function() { |
| 153 var undoModifier = cr.isMac ? 'meta' : 'ctrl'; | 161 var undoModifier = cr.isMac ? 'meta' : 'ctrl'; |
| 154 var undoKey = 'z'; | 162 var undoKey = 'z'; |
| 155 var redoModifier = cr.isMac ? ['meta', 'shift'] : 'ctrl' | 163 var redoModifier = cr.isMac ? ['meta', 'shift'] : 'ctrl' |
| 156 var redoKey = cr.isMac ? 'Z' : 'y'; | 164 var redoKey = cr.isMac ? 'Z' : 'y'; |
| 157 | 165 |
| 158 MockInteractions.pressAndReleaseKeyOn( | 166 MockInteractions.pressAndReleaseKeyOn( |
| 159 document.body, '', undoModifier, undoKey); | 167 document.body, '', undoModifier, undoKey); |
| 160 commandManager.assertLastCommand('undo'); | 168 commandManager.assertLastCommand('undo'); |
| 161 | 169 |
| 162 MockInteractions.pressAndReleaseKeyOn( | 170 MockInteractions.pressAndReleaseKeyOn( |
| 163 document.body, '', redoModifier, redoKey); | 171 document.body, '', redoModifier, redoKey); |
| 164 commandManager.assertLastCommand('redo'); | 172 commandManager.assertLastCommand('redo'); |
| 165 }); | 173 }); |
| 166 | 174 |
| 167 test.only('Show In Folder is only available during search', function() { | 175 test('Show In Folder is only available during search', function() { |
|
tsergeant
2017/07/18 01:08:55
oops
| |
| 168 store.data.selection.items = new Set(['12']); | 176 store.data.selection.items = new Set(['12']); |
| 169 store.notifyObservers(); | 177 store.notifyObservers(); |
| 170 | 178 |
| 171 commandManager.openCommandMenuAtPosition(0, 0, MenuSource.LIST); | 179 commandManager.openCommandMenuAtPosition(0, 0, MenuSource.LIST); |
| 172 Polymer.dom.flush(); | 180 Polymer.dom.flush(); |
| 173 | 181 |
| 174 var showInFolderItem = | 182 var showInFolderItem = |
| 175 commandManager.root.querySelector('[command=show-in-folder]'); | 183 commandManager.root.querySelector('[command=show-in-folder]'); |
| 176 | 184 |
| 177 // Show in folder hidden when search is inactive. | 185 // Show in folder hidden when search is inactive. |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 | 432 |
| 425 test('meta-down triggers Open on Mac', function() { | 433 test('meta-down triggers Open on Mac', function() { |
| 426 if (!cr.isMac) | 434 if (!cr.isMac) |
| 427 return; | 435 return; |
| 428 | 436 |
| 429 customClick(items[0]); | 437 customClick(items[0]); |
| 430 MockInteractions.pressAndReleaseKeyOn(items[0], 0, 'meta', 'ArrowDown'); | 438 MockInteractions.pressAndReleaseKeyOn(items[0], 0, 'meta', 'ArrowDown'); |
| 431 assertEquals('11', store.data.selectedFolder); | 439 assertEquals('11', store.data.selectedFolder); |
| 432 }); | 440 }); |
| 433 }); | 441 }); |
| 442 | |
| 443 suite('<bookmarks-command-manager> whole page integration', function() { | |
| 444 var app; | |
| 445 var store; | |
| 446 var commandManager; | |
| 447 | |
| 448 var testFolderId; | |
| 449 | |
| 450 function create(bookmark) { | |
| 451 return new Promise(function(resolve) { | |
| 452 chrome.bookmarks.create(bookmark, resolve); | |
| 453 }); | |
| 454 } | |
| 455 | |
| 456 suiteSetup(function() { | |
| 457 var testFolder = { | |
| 458 parentId: '1', | |
| 459 title: 'Test', | |
| 460 }; | |
| 461 return create(testFolder).then(function(testFolderNode) { | |
| 462 testFolderId = testFolderNode.id; | |
| 463 var testItem = { | |
| 464 parentId: testFolderId, | |
| 465 title: 'Test bookmark', | |
| 466 url: 'https://www.example.com/', | |
| 467 }; | |
| 468 return Promise.all([ | |
| 469 create(testItem), | |
| 470 create(testItem), | |
| 471 ]); | |
| 472 }); | |
| 473 }); | |
| 474 | |
| 475 setup(function() { | |
| 476 store = new bookmarks.TestStore({}); | |
| 477 store.replaceSingleton(); | |
| 478 store.setReducersEnabled(true); | |
| 479 var promise = store.acceptInitOnce(); | |
| 480 var app = document.createElement('bookmarks-app'); | |
| 481 replaceBody(app); | |
| 482 | |
| 483 commandManager = bookmarks.CommandManager.getInstance(); | |
| 484 | |
| 485 return promise.then(() => { | |
| 486 store.dispatch(bookmarks.actions.selectFolder(testFolderId)); | |
| 487 }); | |
| 488 }); | |
| 489 | |
| 490 test('paste selects newly created items', function() { | |
| 491 var displayedIdsBefore = bookmarks.util.getDisplayedList(store.data); | |
| 492 commandManager.handle(Command.SELECT_ALL, new Set()); | |
| 493 commandManager.handle(Command.COPY, new Set(displayedIdsBefore)); | |
| 494 | |
| 495 store.expectAction('select-items'); | |
| 496 commandManager.handle(Command.PASTE, new Set()); | |
| 497 | |
| 498 return store.waitForAction('select-items').then(function(action) { | |
| 499 var displayedIdsAfter = bookmarks.util.getDisplayedList(store.data); | |
| 500 assertEquals(4, displayedIdsAfter.length); | |
| 501 | |
| 502 // The start of the list shouldn't change. | |
| 503 assertEquals(displayedIdsBefore[0], displayedIdsAfter[0]); | |
| 504 assertEquals(displayedIdsBefore[1], displayedIdsAfter[1]); | |
| 505 | |
| 506 // The two pasted items should be selected at the end of the list. | |
| 507 assertEquals(action.items[0], displayedIdsAfter[2]); | |
| 508 assertEquals(action.items[1], displayedIdsAfter[3]); | |
| 509 assertEquals(2, action.items.length); | |
| 510 assertEquals(action.anchor, displayedIdsAfter[2]); | |
| 511 }); | |
| 512 }); | |
| 513 | |
| 514 suiteTeardown(function(done) { | |
| 515 chrome.bookmarks.removeTree(testFolderId, () => done()); | |
| 516 }); | |
| 517 }); | |
| OLD | NEW |