Index: chrome/test/data/webui/md_bookmarks/command_manager_test.js |
diff --git a/chrome/test/data/webui/md_bookmarks/command_manager_test.js b/chrome/test/data/webui/md_bookmarks/command_manager_test.js |
index 8fb3c766f6713f3da066caa5ef784de9a7b074ed..07e414cbabcd682f5cc9384ab45a058d23e290de 100644 |
--- a/chrome/test/data/webui/md_bookmarks/command_manager_test.js |
+++ b/chrome/test/data/webui/md_bookmarks/command_manager_test.js |
@@ -5,6 +5,23 @@ |
suite('<bookmarks-command-manager>', function() { |
var commandManager; |
var store; |
+ var lastCommand; |
+ var lastCommandIds; |
+ |
+ function assertLastCommand(command, ids) { |
+ assertEquals(lastCommand, command); |
+ if (ids) |
+ assertDeepEquals(normalizeSet(lastCommandIds), ids); |
+ lastCommand = null; |
+ lastCommandIds = null; |
+ } |
+ |
+ suiteSetup(function() { |
+ // Overwrite bookmarkManagerPrivate APIs which will crash if called with |
+ // fake data. |
+ chrome.bookmarkManagerPrivate.copy = function() {}; |
+ chrome.bookmarkManagerPrivate.removeTrees = function() {}; |
+ }); |
setup(function() { |
store = new bookmarks.TestStore({ |
@@ -19,6 +36,13 @@ suite('<bookmarks-command-manager>', function() { |
bookmarks.Store.instance_ = store; |
commandManager = document.createElement('bookmarks-command-manager'); |
+ |
+ var realHandle = commandManager.handle.bind(commandManager); |
+ commandManager.handle = function(command, itemIds) { |
+ lastCommand = command; |
+ lastCommandIds = itemIds; |
+ realHandle(command, itemIds); |
+ }; |
replaceBody(commandManager); |
}); |
@@ -44,4 +68,47 @@ suite('<bookmarks-command-manager>', function() { |
assertTrue(commandHidden['copy']); |
assertFalse(commandHidden['delete']); |
}); |
+ |
+ test('keyboard shortcuts trigger when valid', function() { |
+ var modifier = cr.isMac ? 'meta' : 'ctrl'; |
+ |
+ store.data.selection.items = new Set(['13']); |
+ store.notifyObservers(); |
+ |
+ MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); |
+ assertLastCommand('copy', ['13']); |
+ |
+ // Doesn't trigger when a folder is selected. |
+ store.data.selection.items = new Set(['11']); |
+ store.notifyObservers(); |
+ |
+ MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); |
+ assertLastCommand(null); |
+ |
+ // Doesn't trigger when nothing is selected. |
+ store.data.selection.items = new Set(); |
+ store.notifyObservers(); |
+ |
+ MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c'); |
+ assertLastCommand(null); |
+ }); |
+ |
+ test('delete command triggers', function() { |
+ store.data.selection.items = new Set(['12', '13']); |
+ store.notifyObservers(); |
+ |
+ MockInteractions.pressAndReleaseKeyOn(document, 46, '', 'Delete'); |
+ assertLastCommand('delete', ['12', '13']); |
+ }); |
+ |
+ test('edit command triggers', function() { |
+ var key = cr.isMac ? 'Enter' : 'F2'; |
+ var keyCode = cr.isMac ? 13 : 113; |
+ |
+ store.data.selection.items = new Set(['11']); |
+ store.notifyObservers(); |
+ |
+ MockInteractions.pressAndReleaseKeyOn(document, keyCode, '', key); |
+ assertLastCommand('edit', ['11']); |
+ }); |
}); |