Commit 08dbb44e authored by Esmael El-Moslimany's avatar Esmael El-Moslimany Committed by Commit Bot

Bookmarks WebUI: arrows change which folder has focus, space/enter selects

Pressing enter on Mac will open a rename folder dialog (F2 on other
platforms).

Bug: 854673
Change-Id: I659cfcedc42aec04c47f696df9c71edc7201ce0c
Reviewed-on: https://chromium-review.googlesource.com/c/1341082
Commit-Queue: Esmael El-Moslimany <aee@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609473}
parent 37502857
...@@ -162,7 +162,6 @@ Polymer({ ...@@ -162,7 +162,6 @@ Polymer({
} else { } else {
const parentFolderNode = this.getParentFolderNode_(); const parentFolderNode = this.getParentFolderNode_();
if (parentFolderNode.itemId != ROOT_NODE_ID) { if (parentFolderNode.itemId != ROOT_NODE_ID) {
parentFolderNode.selectFolder_();
parentFolderNode.getFocusTarget().focus(); parentFolderNode.getFocusTarget().focus();
} }
} }
...@@ -202,7 +201,6 @@ Polymer({ ...@@ -202,7 +201,6 @@ Polymer({
// The root node is not navigable. // The root node is not navigable.
if (newFocusFolderNode.itemId != ROOT_NODE_ID) { if (newFocusFolderNode.itemId != ROOT_NODE_ID) {
newFocusFolderNode.selectFolder_();
newFocusFolderNode.getFocusTarget().focus(); newFocusFolderNode.getFocusTarget().focus();
} }
}, },
......
...@@ -20,6 +20,7 @@ MaterialBookmarksFocusTest.prototype = { ...@@ -20,6 +20,7 @@ MaterialBookmarksFocusTest.prototype = {
browsePreload: 'chrome://bookmarks', browsePreload: 'chrome://bookmarks',
extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([ extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([
ROOT_PATH + 'ui/webui/resources/js/util.js',
'../settings/test_util.js', '../settings/test_util.js',
'test_command_manager.js', 'test_command_manager.js',
'test_store.js', 'test_store.js',
...@@ -36,6 +37,17 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() { ...@@ -36,6 +37,17 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() {
return findFolderNode(rootNode, id); return findFolderNode(rootNode, id);
} }
function assertHasFocusAndNotSelected(id) {
const node = getFolderNode(id);
const activeElement = node.shadowRoot.activeElement;
assertTrue(
activeElement != null && activeElement == getDeepActiveElement());
const badAction = bookmarks.actions.selectFolder(id);
if (store.lastAction != null && badAction.name == store.lastAction.name) {
assertNotEquals(badAction.id, store.lastAction.id);
}
}
function keydown(id, key) { function keydown(id, key) {
MockInteractions.keyDownOn(getFolderNode(id).$.container, '', [], key); MockInteractions.keyDownOn(getFolderNode(id).$.container, '', [], key);
} }
...@@ -104,6 +116,8 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() { ...@@ -104,6 +116,8 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() {
// Move down into child. // Move down into child.
keydown('1', 'ArrowDown'); keydown('1', 'ArrowDown');
assertHasFocusAndNotSelected('2');
keydown('2', ' ');
assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
store.data.selectedFolder = '2'; store.data.selectedFolder = '2';
...@@ -117,6 +131,9 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() { ...@@ -117,6 +131,9 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() {
// Move down past closed folders. // Move down past closed folders.
keydown('2', 'ArrowDown'); keydown('2', 'ArrowDown');
assertHasFocusAndNotSelected('7');
keydown('7', ' ');
assertDeepEquals(bookmarks.actions.selectFolder('7'), store.lastAction); assertDeepEquals(bookmarks.actions.selectFolder('7'), store.lastAction);
assertFocused('2', '7'); assertFocused('2', '7');
...@@ -127,11 +144,16 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() { ...@@ -127,11 +144,16 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() {
// Move up past closed folders. // Move up past closed folders.
keydown('7', 'ArrowUp'); keydown('7', 'ArrowUp');
assertHasFocusAndNotSelected('2');
keydown('2', ' ');
assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
assertFocused('7', '2'); assertFocused('7', '2');
// Move up into parent. // Move up into parent.
keydown('2', 'ArrowUp'); keydown('2', 'ArrowUp');
assertHasFocusAndNotSelected('1');
keydown('1', ' ');
assertDeepEquals(bookmarks.actions.selectFolder('1'), store.lastAction); assertDeepEquals(bookmarks.actions.selectFolder('1'), store.lastAction);
assertFocused('2', '1'); assertFocused('2', '1');
...@@ -150,6 +172,9 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() { ...@@ -150,6 +172,9 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() {
// Pressing right descends into first child. // Pressing right descends into first child.
keydown('1', 'ArrowRight'); keydown('1', 'ArrowRight');
assertHasFocusAndNotSelected('2');
keydown('2', ' ');
assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
// Pressing right on a closed folder opens that folder // Pressing right on a closed folder opens that folder
...@@ -159,16 +184,21 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() { ...@@ -159,16 +184,21 @@ TEST_F('MaterialBookmarksFocusTest', 'All', function() {
// Pressing right again descends into first child. // Pressing right again descends into first child.
keydown('2', 'ArrowRight'); keydown('2', 'ArrowRight');
assertHasFocusAndNotSelected('3');
keydown('3', ' ');
assertDeepEquals(bookmarks.actions.selectFolder('3'), store.lastAction); assertDeepEquals(bookmarks.actions.selectFolder('3'), store.lastAction);
// Pressing right on a folder with no children does nothing. // Pressing right on a folder with no children does nothing.
store.resetLastAction(); store.resetLastAction();
keydown('3', 'ArrowRight'); keydown('3', 'ArrowRight');
assertHasFocusAndNotSelected('3');
assertDeepEquals(null, store.lastAction); assertDeepEquals(null, store.lastAction);
// Pressing left on a folder with no children ascends to parent. // Pressing left on a folder with no children ascends to parent.
keydown('3', 'ArrowDown'); keydown('3', 'ArrowDown');
keydown('4', 'ArrowLeft'); keydown('4', 'ArrowLeft');
assertHasFocusAndNotSelected('2');
keydown('2', ' ');
assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
// Pressing left again closes the parent. // Pressing left again closes the parent.
......
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