Commit 24cca661 authored by lshang's avatar lshang Committed by Commit bot

MD History: Add shortcuts for 'Delete' and 'Backspace' to delete selected items

Press 'Delete' or 'Backspace' key from keyboard will delete selected history items
on MD History.

BUG=627408
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2159773003
Cr-Commit-Position: refs/heads/master@{#406715}
parent f56c5224
......@@ -159,6 +159,9 @@ Polymer({
!(this.$.toolbar.searchBar.showingSearch &&
this.$.toolbar.searchBar.isSearchFocused());
break;
case 'delete-command':
e.canExecute = this.$.toolbar.count > 0;
break;
}
},
......@@ -186,6 +189,8 @@ Polymer({
onCommand_: function(e) {
if (e.command.id == 'find-command' || e.command.id == 'slash-command')
this.$.toolbar.showSearchField();
if (e.command.id == 'delete-command')
this.deleteSelected();
},
/**
......
......@@ -75,6 +75,7 @@
<if expr="not is_macosx">
<command id="find-command" shortcut="Ctrl|f">
</if>
<command id="delete-command" shortcut="Delete Backspace">
<command id="slash-command" shortcut="/">
<link rel="import" href="chrome://resources/html/cr.html">
......
......@@ -231,6 +231,45 @@ cr.define('md_history.history_list_test', function() {
});
});
test('deleting items using shortcuts', function(done) {
var listContainer = app.$.history;
app.historyResult(createHistoryInfo(), TEST_HISTORY_RESULTS);
flush().then(function() {
items = Polymer.dom(element.root).querySelectorAll('history-item');
// Dialog should not appear when there is no item selected.
MockInteractions.pressAndReleaseKeyOn(
document.body, 46, '', 'Delete');
assertFalse(listContainer.$.dialog.opened);
MockInteractions.tap(items[1].$.checkbox);
MockInteractions.tap(items[2].$.checkbox);
assertEquals(2, toolbar.count);
registerMessageCallback('removeVisits', this, function(toRemove) {
assertEquals('https://www.example.com', toRemove[0].url);
assertEquals('https://www.google.com', toRemove[1].url);
assertEquals('2016-03-14 10:00 UTC', toRemove[0].timestamps[0]);
assertEquals('2016-03-14 9:00 UTC', toRemove[1].timestamps[0]);
done();
});
MockInteractions.pressAndReleaseKeyOn(
document.body, 46, '', 'Delete');
assertTrue(listContainer.$.dialog.opened);
MockInteractions.tap(listContainer.$$('.cancel-button'));
assertFalse(listContainer.$.dialog.opened);
MockInteractions.pressAndReleaseKeyOn(
document.body, 8, '', 'Backspace');
assertTrue(listContainer.$.dialog.opened);
MockInteractions.tap(listContainer.$$('.action-button'));
});
});
teardown(function() {
element.historyData_ = [];
registerMessageCallback('removeVisits', this, undefined);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment