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

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

Issue 2977523002: MD Bookmarks: Scroll and select items that are added to the main list (Closed)
Patch Set: Fix test Created 3 years, 5 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 var bmpCopyFunction;
10 11
11 suiteSetup(function() { 12 suiteSetup(function() {
12 // Overwrite bookmarkManagerPrivate APIs which will crash if called with 13 // Overwrite bookmarkManagerPrivate APIs which will crash if called with
13 // fake data. 14 // fake data.
15 bmpCopyFunction = chrome.bookmarkManagerPrivate.copy;
14 chrome.bookmarkManagerPrivate.copy = function() {}; 16 chrome.bookmarkManagerPrivate.copy = function() {};
15 chrome.bookmarkManagerPrivate.removeTrees = function() {}; 17 chrome.bookmarkManagerPrivate.removeTrees = function() {};
16 }); 18 });
17 19
20 suiteTeardown(function() {
21 chrome.bookmarkManagerPrivate.copy = bmpCopyFunction;
22 });
23
18 setup(function() { 24 setup(function() {
19 var bulkChildren = []; 25 var bulkChildren = [];
20 for (var i = 1; i <= 20; i++) { 26 for (var i = 1; i <= 20; i++) {
21 var id = '3' + i; 27 var id = '3' + i;
22 bulkChildren.push(createItem(id, {url: `http://${id}/`})); 28 bulkChildren.push(createItem(id, {url: `http://${id}/`}));
23 } 29 }
24 30
25 store = new bookmarks.TestStore({ 31 store = new bookmarks.TestStore({
26 nodes: testTree( 32 nodes: testTree(
27 createFolder( 33 createFolder(
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'c'); 133 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'c');
128 commandManager.assertLastCommand('copy', ['11', '13']); 134 commandManager.assertLastCommand('copy', ['11', '13']);
129 }); 135 });
130 136
131 test('cut/paste commands trigger', function() { 137 test('cut/paste commands trigger', function() {
132 var lastCut; 138 var lastCut;
133 var lastPaste; 139 var lastPaste;
134 chrome.bookmarkManagerPrivate.cut = function(idList) { 140 chrome.bookmarkManagerPrivate.cut = function(idList) {
135 lastCut = idList.sort(); 141 lastCut = idList.sort();
136 }; 142 };
143 var bmpPasteFunction = chrome.bookmarkManagerPrivate.paste;
calamity 2017/07/14 04:14:40 Can we just do this in the setup/teardown like for
tsergeant 2017/07/14 06:39:20 Done.
137 chrome.bookmarkManagerPrivate.paste = function(selectedFolder) { 144 chrome.bookmarkManagerPrivate.paste = function(selectedFolder) {
138 lastPaste = selectedFolder; 145 lastPaste = selectedFolder;
139 }; 146 };
140 147
141 var modifier = cr.isMac ? 'meta' : 'ctrl'; 148 var modifier = cr.isMac ? 'meta' : 'ctrl';
142 149
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
146 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'x'); 153 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'x');
147 assertDeepEquals(['11', '13'], lastCut); 154 assertDeepEquals(['11', '13'], lastCut);
148 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'v'); 155 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'v');
149 assertEquals('1', lastPaste); 156 assertEquals('1', lastPaste);
157
158 chrome.bookmarkManagerPrivate.paste = bmpPasteFunction;
150 }); 159 });
151 160
152 test('undo and redo commands trigger', function() { 161 test('undo and redo commands trigger', function() {
153 var undoModifier = cr.isMac ? 'meta' : 'ctrl'; 162 var undoModifier = cr.isMac ? 'meta' : 'ctrl';
154 var undoKey = 'z'; 163 var undoKey = 'z';
155 var redoModifier = cr.isMac ? ['meta', 'shift'] : 'ctrl' 164 var redoModifier = cr.isMac ? ['meta', 'shift'] : 'ctrl'
156 var redoKey = cr.isMac ? 'Z' : 'y'; 165 var redoKey = cr.isMac ? 'Z' : 'y';
157 166
158 MockInteractions.pressAndReleaseKeyOn( 167 MockInteractions.pressAndReleaseKeyOn(
159 document.body, '', undoModifier, undoKey); 168 document.body, '', undoModifier, undoKey);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 433
425 test('meta-down triggers Open on Mac', function() { 434 test('meta-down triggers Open on Mac', function() {
426 if (!cr.isMac) 435 if (!cr.isMac)
427 return; 436 return;
428 437
429 customClick(items[0]); 438 customClick(items[0]);
430 MockInteractions.pressAndReleaseKeyOn(items[0], 0, 'meta', 'ArrowDown'); 439 MockInteractions.pressAndReleaseKeyOn(items[0], 0, 'meta', 'ArrowDown');
431 assertEquals('11', store.data.selectedFolder); 440 assertEquals('11', store.data.selectedFolder);
432 }); 441 });
433 }); 442 });
443
444 suite('<bookmarks-command-manager> whole page integration', function() {
445 var app;
446 var store;
447 var commandManager;
448
449 var testFolderId;
450
451 function create(bookmark) {
452 return new Promise(function(resolve) {
453 chrome.bookmarks.create(bookmark, resolve);
454 });
455 }
456
457 suiteSetup(function() {
458 var testFolder = {
459 parentId: '1',
460 title: 'Test',
461 };
462 return create(testFolder).then(function(testFolderNode) {
463 testFolderId = testFolderNode.id;
464 var testItem = {
465 parentId: testFolderId,
466 title: 'Test bookmark',
467 url: 'https://www.example.com/',
468 };
469 return Promise.all([
470 create(testItem),
471 create(testItem),
472 ]);
473 });
474 });
475
476 setup(function() {
477 store = new bookmarks.TestStore({});
478 store.replaceSingleton();
479 store.setReducersEnabled(true);
480 var promise = store.acceptInitOnce();
481 var app = document.createElement('bookmarks-app');
482 replaceBody(app);
483
484 commandManager = bookmarks.CommandManager.getInstance();
485
486 return promise.then(() => {
487 store.dispatch(bookmarks.actions.selectFolder(testFolderId));
488 });
489 });
490
491 test('paste selects newly created items', function() {
492 var displayedIdsBefore = bookmarks.util.getDisplayedList(store.data);
493 commandManager.handle(Command.SELECT_ALL, new Set());
494 commandManager.handle(Command.COPY, new Set(displayedIdsBefore));
495
496 store.expectAction('select-items');
497 commandManager.handle(Command.PASTE, new Set());
498
499 return store.waitForAction('select-items').then(function(action) {
500 var displayedIdsAfter = bookmarks.util.getDisplayedList(store.data);
501 assertEquals(4, displayedIdsAfter.length);
502
503 // The start of the list shouldn't change.
504 assertEquals(displayedIdsBefore[0], displayedIdsAfter[0]);
505 assertEquals(displayedIdsBefore[1], displayedIdsAfter[1]);
506
507 // The two pasted items should be selected at the end of the list.
508 assertEquals(action.items[0], displayedIdsAfter[2]);
509 assertEquals(action.items[1], displayedIdsAfter[3]);
510 assertEquals(2, action.items.length);
511 assertEquals(action.anchor, displayedIdsAfter[2]);
512 });
513 });
514
515 suiteTeardown(function(done) {
516 chrome.bookmarks.removeTree(testFolderId, () => done());
517 });
518 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698