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 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 ]), | 43 ]), |
44 ]), | 44 ]), |
45 createItem('13', {url: 'http://13/'}), | 45 createItem('13', {url: 'http://13/'}), |
46 ]), | 46 ]), |
47 createFolder( | 47 createFolder( |
48 '2', | 48 '2', |
49 [ | 49 [ |
50 createFolder('21', []), | 50 createFolder('21', []), |
51 ]), | 51 ]), |
52 createFolder('3', bulkChildren)), | 52 createFolder('3', bulkChildren)), |
| 53 selectedFolder: '1', |
53 }); | 54 }); |
54 store.replaceSingleton(); | 55 store.replaceSingleton(); |
55 | 56 |
56 commandManager = new TestCommandManager(); | 57 commandManager = new TestCommandManager(); |
57 replaceBody(commandManager); | 58 replaceBody(commandManager); |
58 document.body.appendChild( | 59 document.body.appendChild( |
59 document.createElement('bookmarks-toast-manager')); | 60 document.createElement('bookmarks-toast-manager')); |
60 }); | 61 }); |
61 | 62 |
62 test('can only copy single URL items', function() { | 63 test('Copy URL is only active for single URL items', function() { |
63 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11']))); | 64 assertFalse(commandManager.canExecute(Command.COPY_URL, new Set(['11']))); |
64 assertFalse(commandManager.canExecute(Command.COPY, new Set(['11', '13']))); | 65 assertFalse( |
65 assertTrue(commandManager.canExecute(Command.COPY, new Set(['13']))); | 66 commandManager.canExecute(Command.COPY_URL, new Set(['11', '13']))); |
| 67 assertTrue(commandManager.canExecute(Command.COPY_URL, new Set(['13']))); |
66 }); | 68 }); |
67 | 69 |
68 test('context menu hides invalid commands', function() { | 70 test('context menu hides invalid commands', function() { |
69 store.data.selection.items = new Set(['11', '13']); | 71 store.data.selection.items = new Set(['11', '13']); |
70 store.notifyObservers(); | 72 store.notifyObservers(); |
71 | 73 |
72 commandManager.openCommandMenuAtPosition(0, 0); | 74 commandManager.openCommandMenuAtPosition(0, 0); |
73 Polymer.dom.flush(); | 75 Polymer.dom.flush(); |
74 | 76 |
75 var commandHidden = {}; | 77 var commandHidden = {}; |
76 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { | 78 commandManager.root.querySelectorAll('.dropdown-item').forEach(element => { |
77 commandHidden[element.getAttribute('command')] = element.hidden; | 79 commandHidden[element.getAttribute('command')] = element.hidden; |
78 }); | 80 }); |
79 | 81 |
80 // With a folder and an item selected, the only available context menu item | 82 // With a folder and an item selected, the only available context menu item |
81 // is 'Delete'. | 83 // is 'Delete'. |
82 assertTrue(commandHidden['edit']); | 84 assertTrue(commandHidden[Command.EDIT]); |
83 assertTrue(commandHidden['copy']); | 85 assertTrue(commandHidden[Command.COPY_URL]); |
84 assertFalse(commandHidden['delete']); | 86 assertFalse(commandHidden[Command.DELETE]); |
85 }); | 87 }); |
86 | 88 |
87 test('keyboard shortcuts trigger when valid', function() { | 89 test('edit shortcut triggers when valid', function() { |
88 var modifier = cr.isMac ? 'meta' : 'ctrl'; | 90 var key = cr.isMac ? 'Enter' : 'F2'; |
89 | 91 |
90 store.data.selection.items = new Set(['13']); | 92 store.data.selection.items = new Set(['13']); |
91 store.notifyObservers(); | 93 store.notifyObservers(); |
92 | 94 |
93 MockInteractions.pressAndReleaseKeyOn(document.body, 67, modifier, 'c'); | 95 MockInteractions.pressAndReleaseKeyOn(document.body, '', [], key); |
94 commandManager.assertLastCommand('copy', ['13']); | 96 commandManager.assertLastCommand('edit', ['13']); |
95 | 97 |
96 // Doesn't trigger when a folder is selected. | 98 // Doesn't trigger when multiple items are selected. |
97 store.data.selection.items = new Set(['11']); | 99 store.data.selection.items = new Set(['11', '13']); |
98 store.notifyObservers(); | 100 store.notifyObservers(); |
99 | 101 |
100 MockInteractions.pressAndReleaseKeyOn(document.body, 67, modifier, 'c'); | 102 MockInteractions.pressAndReleaseKeyOn(document.body, '', [], key); |
101 commandManager.assertLastCommand(null); | 103 commandManager.assertLastCommand(null); |
102 | 104 |
103 // Doesn't trigger when nothing is selected. | 105 // Doesn't trigger when nothing is selected. |
104 store.data.selection.items = new Set(); | 106 store.data.selection.items = new Set(); |
105 store.notifyObservers(); | 107 store.notifyObservers(); |
106 | 108 |
107 MockInteractions.pressAndReleaseKeyOn(document.body, 67, modifier, 'c'); | 109 MockInteractions.pressAndReleaseKeyOn(document.body, '', [], key); |
108 commandManager.assertLastCommand(null); | 110 commandManager.assertLastCommand(null); |
109 }); | 111 }); |
110 | 112 |
111 test('delete command triggers', function() { | 113 test('delete command triggers', function() { |
112 store.data.selection.items = new Set(['12', '13']); | 114 store.data.selection.items = new Set(['12', '13']); |
113 store.notifyObservers(); | 115 store.notifyObservers(); |
114 | 116 |
115 MockInteractions.pressAndReleaseKeyOn(document.body, 46, '', 'Delete'); | 117 MockInteractions.pressAndReleaseKeyOn(document.body, 46, '', 'Delete'); |
116 commandManager.assertLastCommand('delete', ['12', '13']); | 118 commandManager.assertLastCommand('delete', ['12', '13']); |
117 }); | 119 }); |
118 | 120 |
119 test('edit command triggers', function() { | 121 test('copy command triggers', function() { |
120 var key = cr.isMac ? 'Enter' : 'F2'; | 122 var modifier = cr.isMac ? 'meta' : 'ctrl'; |
121 var keyCode = cr.isMac ? 13 : 113; | |
122 | 123 |
123 store.data.selection.items = new Set(['11']); | 124 store.data.selection.items = new Set(['11', '13']); |
124 store.notifyObservers(); | 125 store.notifyObservers(); |
125 | 126 |
126 MockInteractions.pressAndReleaseKeyOn(document.body, keyCode, '', key); | 127 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'c'); |
127 commandManager.assertLastCommand('edit', ['11']); | 128 commandManager.assertLastCommand('copy', ['11', '13']); |
| 129 }); |
| 130 |
| 131 test('cut/paste commands trigger', function() { |
| 132 var lastCut; |
| 133 var lastPaste; |
| 134 chrome.bookmarkManagerPrivate.cut = function(idList) { |
| 135 lastCut = idList.sort(); |
| 136 }; |
| 137 chrome.bookmarkManagerPrivate.paste = function(selectedFolder) { |
| 138 lastPaste = selectedFolder; |
| 139 }; |
| 140 |
| 141 var modifier = cr.isMac ? 'meta' : 'ctrl'; |
| 142 |
| 143 store.data.selection.items = new Set(['11', '13']); |
| 144 store.notifyObservers(); |
| 145 |
| 146 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'x'); |
| 147 assertDeepEquals(['11', '13'], lastCut); |
| 148 MockInteractions.pressAndReleaseKeyOn(document.body, '', modifier, 'v'); |
| 149 assertEquals('1', lastPaste); |
128 }); | 150 }); |
129 | 151 |
130 test('undo and redo commands trigger', function() { | 152 test('undo and redo commands trigger', function() { |
131 var undoModifier = cr.isMac ? 'meta' : 'ctrl'; | 153 var undoModifier = cr.isMac ? 'meta' : 'ctrl'; |
132 var undoKey = 'z'; | 154 var undoKey = 'z'; |
133 var redoModifier = cr.isMac ? ['meta', 'shift'] : 'ctrl' | 155 var redoModifier = cr.isMac ? ['meta', 'shift'] : 'ctrl' |
134 var redoKey = cr.isMac ? 'Z' : 'y'; | 156 var redoKey = cr.isMac ? 'Z' : 'y'; |
135 | 157 |
136 MockInteractions.pressAndReleaseKeyOn( | 158 MockInteractions.pressAndReleaseKeyOn( |
137 document.body, '', undoModifier, undoKey); | 159 document.body, '', undoModifier, undoKey); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 assertOpenedTabs(['http://111/', 'http://12/']); | 376 assertOpenedTabs(['http://111/', 'http://12/']); |
355 }); | 377 }); |
356 | 378 |
357 test('control-double click opens full selection', function() { | 379 test('control-double click opens full selection', function() { |
358 customClick(items[0]); | 380 customClick(items[0]); |
359 simulateDoubleClick(items[2], {ctrlKey: true}); | 381 simulateDoubleClick(items[2], {ctrlKey: true}); |
360 | 382 |
361 assertOpenedTabs(['http://111/', 'http://13/']); | 383 assertOpenedTabs(['http://111/', 'http://13/']); |
362 }); | 384 }); |
363 }); | 385 }); |
OLD | NEW |