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

Side by Side Diff: chrome/test/data/webui/md_bookmarks/md_bookmarks_focus_test.js

Issue 2820153003: [MD Bookmarks] Add keyboard navigation to sidebar. (Closed)
Patch Set: fix test 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview Tests for MD History which are run as interactive ui tests.
tsergeant 2017/05/03 03:56:38 Not "MD History" anymore...
calamity 2017/05/03 05:13:56 Done.
7 * Should be used for tests which care about focus.
8 */
9
10 var ROOT_PATH = '../../../../../';
11
12 GEN_INCLUDE(
13 [ROOT_PATH + 'chrome/test/data/webui/polymer_interactive_ui_test.js']);
14 GEN('#include "base/command_line.h"');
15
16 function MaterialBookmarksFocusTest() {}
17
18 MaterialBookmarksFocusTest.prototype = {
19 __proto__: PolymerInteractiveUITest.prototype,
20
21 browsePreload: 'chrome://bookmarks',
22
23 commandLineSwitches:
24 [{switchName: 'enable-features', switchValue: 'MaterialDesignBookmarks'}],
25
26 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([
27 'test_store.js',
28 'test_util.js',
29 ]),
30 };
31
32 TEST_F('MaterialBookmarksFocusTest', 'All', function() {
33 suite('<bookmarks-folder-node>', function() {
34 var rootNode;
35 var store;
36
37 function getFolderNode(id) {
38 return findFolderNode(rootNode, id);
39 }
40
41 function keydown(id, key) {
42 MockInteractions.keyDownOn(getFolderNode(id).$.container, '', [], key);
43 }
44
45 setup(function() {
46 store = new bookmarks.TestStore({
47 nodes: testTree(
48 createFolder(
49 '1',
50 [
51 createFolder(
52 '2',
53 [
54 createFolder('3', []),
55 createFolder('4', []),
56 ]),
57 createItem('5'),
58 ]),
59 createFolder('7', [])),
60 selectedFolder: '1',
61 });
62 store.setReducersEnabled(true);
63 bookmarks.Store.instance_ = store;
64
65 rootNode = document.createElement('bookmarks-folder-node');
66 rootNode.itemId = '0';
67 rootNode.depth = -1;
68 replaceBody(rootNode);
69 Polymer.dom.flush();
70 });
71
72 test('keyboard selection', function() {
73 function assertFocused(oldFocus, newFocus) {
74 assertEquals(
75 '', getFolderNode(oldFocus).$.container.getAttribute('tabindex'));
76 assertEquals(
77 '0', getFolderNode(newFocus).$.container.getAttribute('tabindex'));
78 assertEquals(
79 getFolderNode(newFocus).$.container,
80 getFolderNode(newFocus).root.activeElement);
81 }
82
83 store.data.closedFolders = new Set('2');
84 store.notifyObservers();
85
86 // The selected folder is focus enabled on attach.
87 assertEquals(
88 '0', getFolderNode('1').$.container.getAttribute('tabindex'));
89
90 // Only the selected folder should be focusable.
91 assertEquals('', getFolderNode('2').$.container.getAttribute('tabindex'));
92
93 // Give keyboard focus to the first item.
94 getFolderNode('1').$.container.focus();
95
96 // Move down into child.
97 keydown('1', 'ArrowDown');
98
99 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
100 assertFocused('1', '2');
101
102 // Move down past closed folders.
103 keydown('2', 'ArrowDown');
104 assertDeepEquals(bookmarks.actions.selectFolder('7'), store.lastAction);
105 assertFocused('2', '7');
106
107 // Move down past end of list.
108 store.resetLastAction();
109 keydown('7', 'ArrowDown');
110 assertDeepEquals(null, store.lastAction);
111
112 // Move up past closed folders.
113 keydown('7', 'ArrowUp');
114 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction);
115 assertFocused('7', '2');
116
117 // Move up into parent.
118 keydown('2', 'ArrowUp');
119 assertDeepEquals(bookmarks.actions.selectFolder('1'), store.lastAction);
120 assertFocused('2', '1');
121
122 // Move up past start of list.
123 store.resetLastAction();
124 keydown('1', 'ArrowUp');
125 assertDeepEquals(null, store.lastAction);
126 });
127 });
128
129 mocha.run();
130 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698