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

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: More tests Created 3 years, 8 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
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..b65435462841010072a2906d256856fa87346f72 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,39 @@ 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']);
+
+ store.data.selection.items = new Set(['11']);
+ store.notifyObservers();
+
+ MockInteractions.pressAndReleaseKeyOn(document, 67, modifier, 'c');
+ assertLastCommand(null);
calamity 2017/04/26 10:07:58 Add a case for empty selection too.
tsergeant 2017/04/27 01:42:51 Done.
+ });
+
+ test('delete command triggers', function() {
tsergeant 2017/04/26 08:10:55 I'm not totally convinced how useful this test and
+ 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']);
+ });
});

Powered by Google App Engine
This is Rietveld 408576698