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

Unified Diff: chrome/test/data/webui/md_bookmarks/command_manager_test.js

Issue 2843903002: MD Bookmarks: Add keyboard shortcut support to bookmarks-command-manager (Closed)
Patch Set: Rebase Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/md_bookmarks/command_manager.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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']);
+ });
});
« no previous file with comments | « chrome/browser/resources/md_bookmarks/command_manager.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698