| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 assertTrue(commandHidden['copy']); | 69 assertTrue(commandHidden['copy']); |
| 70 assertFalse(commandHidden['delete']); | 70 assertFalse(commandHidden['delete']); |
| 71 }); | 71 }); |
| 72 | 72 |
| 73 test('keyboard shortcuts trigger when valid', function() { | 73 test('keyboard shortcuts trigger when valid', function() { |
| 74 var modifier = cr.isMac ? 'meta' : 'ctrl'; | 74 var modifier = cr.isMac ? 'meta' : 'ctrl'; |
| 75 | 75 |
| 76 store.data.selection.items = new Set(['13']); | 76 store.data.selection.items = new Set(['13']); |
| 77 store.notifyObservers(); | 77 store.notifyObservers(); |
| 78 | 78 |
| 79 MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); | 79 MockInteractions.pressAndReleaseKeyOn(document.body, 67, modifier, 'c'); |
| 80 commandManager.assertLastCommand('copy', ['13']); | 80 commandManager.assertLastCommand('copy', ['13']); |
| 81 | 81 |
| 82 // Doesn't trigger when a folder is selected. | 82 // Doesn't trigger when a folder is selected. |
| 83 store.data.selection.items = new Set(['11']); | 83 store.data.selection.items = new Set(['11']); |
| 84 store.notifyObservers(); | 84 store.notifyObservers(); |
| 85 | 85 |
| 86 MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); | 86 MockInteractions.pressAndReleaseKeyOn(document.body, 67, modifier, 'c'); |
| 87 commandManager.assertLastCommand(null); | 87 commandManager.assertLastCommand(null); |
| 88 | 88 |
| 89 // Doesn't trigger when nothing is selected. | 89 // Doesn't trigger when nothing is selected. |
| 90 store.data.selection.items = new Set(); | 90 store.data.selection.items = new Set(); |
| 91 store.notifyObservers(); | 91 store.notifyObservers(); |
| 92 | 92 |
| 93 MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); | 93 MockInteractions.pressAndReleaseKeyOn(document.body, 67, modifier, 'c'); |
| 94 commandManager.assertLastCommand(null); | 94 commandManager.assertLastCommand(null); |
| 95 }); | 95 }); |
| 96 | 96 |
| 97 test('delete command triggers', function() { | 97 test('delete command triggers', function() { |
| 98 store.data.selection.items = new Set(['12', '13']); | 98 store.data.selection.items = new Set(['12', '13']); |
| 99 store.notifyObservers(); | 99 store.notifyObservers(); |
| 100 | 100 |
| 101 MockInteractions.pressAndReleaseKeyOn(document, 46, '', 'Delete'); | 101 MockInteractions.pressAndReleaseKeyOn(document.body, 46, '', 'Delete'); |
| 102 commandManager.assertLastCommand('delete', ['12', '13']); | 102 commandManager.assertLastCommand('delete', ['12', '13']); |
| 103 }); | 103 }); |
| 104 | 104 |
| 105 test('edit command triggers', function() { | 105 test('edit command triggers', function() { |
| 106 var key = cr.isMac ? 'Enter' : 'F2'; | 106 var key = cr.isMac ? 'Enter' : 'F2'; |
| 107 var keyCode = cr.isMac ? 13 : 113; | 107 var keyCode = cr.isMac ? 13 : 113; |
| 108 | 108 |
| 109 store.data.selection.items = new Set(['11']); | 109 store.data.selection.items = new Set(['11']); |
| 110 store.notifyObservers(); | 110 store.notifyObservers(); |
| 111 | 111 |
| 112 MockInteractions.pressAndReleaseKeyOn(document, keyCode, '', key); | 112 MockInteractions.pressAndReleaseKeyOn(document.body, keyCode, '', key); |
| 113 commandManager.assertLastCommand('edit', ['11']); | 113 commandManager.assertLastCommand('edit', ['11']); |
| 114 }); | 114 }); |
| 115 | 115 |
| 116 test('undo and redo commands trigger', function() { | 116 test('undo and redo commands trigger', function() { |
| 117 var undoModifier = cr.isMac ? 'meta' : 'ctrl'; | 117 var undoModifier = cr.isMac ? 'meta' : 'ctrl'; |
| 118 var undoKey = 'z'; | 118 var undoKey = 'z'; |
| 119 var redoModifier = cr.isMac ? ['meta', 'shift'] : 'ctrl' | 119 var redoModifier = cr.isMac ? ['meta', 'shift'] : 'ctrl' |
| 120 var redoKey = cr.isMac ? 'z' : 'y'; | 120 var redoKey = cr.isMac ? 'z' : 'y'; |
| 121 | 121 |
| 122 MockInteractions.pressAndReleaseKeyOn(document, '', undoModifier, undoKey); | 122 MockInteractions.pressAndReleaseKeyOn( |
| 123 document.body, '', undoModifier, undoKey); |
| 123 commandManager.assertLastCommand('undo'); | 124 commandManager.assertLastCommand('undo'); |
| 124 | 125 |
| 125 MockInteractions.pressAndReleaseKeyOn(document, '', redoModifier, redoKey); | 126 MockInteractions.pressAndReleaseKeyOn( |
| 127 document.body, '', redoModifier, redoKey); |
| 126 commandManager.assertLastCommand('redo'); | 128 commandManager.assertLastCommand('redo'); |
| 127 }); | 129 }); |
| 128 | 130 |
| 129 test('does not delete children at same time as ancestor', function() { | 131 test('does not delete children at same time as ancestor', function() { |
| 130 var lastDelete = null; | 132 var lastDelete = null; |
| 131 chrome.bookmarkManagerPrivate.removeTrees = function(idArray) { | 133 chrome.bookmarkManagerPrivate.removeTrees = function(idArray) { |
| 132 lastDelete = idArray.sort(); | 134 lastDelete = idArray.sort(); |
| 133 }; | 135 }; |
| 134 | 136 |
| 135 var parentAndChildren = new Set(['1', '2', '12', '111']); | 137 var parentAndChildren = new Set(['1', '2', '12', '111']); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 149 | 151 |
| 150 test('shift-enter opens URLs in new window', function() { | 152 test('shift-enter opens URLs in new window', function() { |
| 151 store.data.selection.items = new Set(['12', '13']); | 153 store.data.selection.items = new Set(['12', '13']); |
| 152 store.notifyObservers(); | 154 store.notifyObservers(); |
| 153 | 155 |
| 154 var lastCreate; | 156 var lastCreate; |
| 155 chrome.windows.create = function(createConfig) { | 157 chrome.windows.create = function(createConfig) { |
| 156 lastCreate = createConfig; | 158 lastCreate = createConfig; |
| 157 }; | 159 }; |
| 158 | 160 |
| 159 MockInteractions.pressAndReleaseKeyOn(document, 13, 'shift', 'Enter'); | 161 MockInteractions.pressAndReleaseKeyOn(document.body, 13, 'shift', 'Enter'); |
| 160 commandManager.assertLastCommand(Command.OPEN_NEW_WINDOW, ['12', '13']); | 162 commandManager.assertLastCommand(Command.OPEN_NEW_WINDOW, ['12', '13']); |
| 161 assertDeepEquals(['http://121/', 'http://13/'], lastCreate.url); | 163 assertDeepEquals(['http://121/', 'http://13/'], lastCreate.url); |
| 162 assertFalse(lastCreate.incognito); | 164 assertFalse(lastCreate.incognito); |
| 163 }); | 165 }); |
| 164 | 166 |
| 165 test('cannot execute "Open in New Tab" on folders with no items', function() { | 167 test('cannot execute "Open in New Tab" on folders with no items', function() { |
| 166 var items = new Set(['2']); | 168 var items = new Set(['2']); |
| 167 assertFalse(commandManager.canExecute(Command.OPEN_NEW_TAB, items)); | 169 assertFalse(commandManager.canExecute(Command.OPEN_NEW_TAB, items)); |
| 168 | 170 |
| 169 store.data.selection.items = items; | 171 store.data.selection.items = items; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 assertOpenedTabs(['http://111/', 'http://12/']); | 256 assertOpenedTabs(['http://111/', 'http://12/']); |
| 255 }); | 257 }); |
| 256 | 258 |
| 257 test('control-double click opens full selection', function() { | 259 test('control-double click opens full selection', function() { |
| 258 customClick(items[0]); | 260 customClick(items[0]); |
| 259 simulateDoubleClick(items[2], {ctrlKey: true}); | 261 simulateDoubleClick(items[2], {ctrlKey: true}); |
| 260 | 262 |
| 261 assertOpenedTabs(['http://111/', 'http://13/']); | 263 assertOpenedTabs(['http://111/', 'http://13/']); |
| 262 }); | 264 }); |
| 263 }); | 265 }); |
| OLD | NEW |