OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Tests for MD Bookmarks which are run as interactive ui tests. | 6 * @fileoverview Tests for MD Bookmarks which are run as interactive ui tests. |
7 * Should be used for tests which care about focus. | 7 * Should be used for tests which care about focus. |
8 */ | 8 */ |
9 | 9 |
10 var ROOT_PATH = '../../../../../'; | 10 var ROOT_PATH = '../../../../../'; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // Only the selected folder should be focusable. | 90 // Only the selected folder should be focusable. |
91 assertEquals('', getFolderNode('2').$.container.getAttribute('tabindex')); | 91 assertEquals('', getFolderNode('2').$.container.getAttribute('tabindex')); |
92 | 92 |
93 // Give keyboard focus to the first item. | 93 // Give keyboard focus to the first item. |
94 getFolderNode('1').$.container.focus(); | 94 getFolderNode('1').$.container.focus(); |
95 | 95 |
96 // Move down into child. | 96 // Move down into child. |
97 keydown('1', 'ArrowDown'); | 97 keydown('1', 'ArrowDown'); |
98 | 98 |
99 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); | 99 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); |
| 100 store.data.selectedFolder = '2'; |
| 101 store.notifyObservers(); |
| 102 |
| 103 assertEquals('', getFolderNode('1').$.container.getAttribute('tabindex')); |
| 104 assertEquals( |
| 105 '0', getFolderNode('2').$.container.getAttribute('tabindex')); |
100 assertFocused('1', '2'); | 106 assertFocused('1', '2'); |
101 | 107 |
102 // Move down past closed folders. | 108 // Move down past closed folders. |
103 keydown('2', 'ArrowDown'); | 109 keydown('2', 'ArrowDown'); |
104 assertDeepEquals(bookmarks.actions.selectFolder('7'), store.lastAction); | 110 assertDeepEquals(bookmarks.actions.selectFolder('7'), store.lastAction); |
105 assertFocused('2', '7'); | 111 assertFocused('2', '7'); |
106 | 112 |
107 // Move down past end of list. | 113 // Move down past end of list. |
108 store.resetLastAction(); | 114 store.resetLastAction(); |
109 keydown('7', 'ArrowDown'); | 115 keydown('7', 'ArrowDown'); |
110 assertDeepEquals(null, store.lastAction); | 116 assertDeepEquals(null, store.lastAction); |
111 | 117 |
112 // Move up past closed folders. | 118 // Move up past closed folders. |
113 keydown('7', 'ArrowUp'); | 119 keydown('7', 'ArrowUp'); |
114 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); | 120 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); |
115 assertFocused('7', '2'); | 121 assertFocused('7', '2'); |
116 | 122 |
117 // Move up into parent. | 123 // Move up into parent. |
118 keydown('2', 'ArrowUp'); | 124 keydown('2', 'ArrowUp'); |
119 assertDeepEquals(bookmarks.actions.selectFolder('1'), store.lastAction); | 125 assertDeepEquals(bookmarks.actions.selectFolder('1'), store.lastAction); |
120 assertFocused('2', '1'); | 126 assertFocused('2', '1'); |
121 | 127 |
122 // Move up past start of list. | 128 // Move up past start of list. |
123 store.resetLastAction(); | 129 store.resetLastAction(); |
124 keydown('1', 'ArrowUp'); | 130 keydown('1', 'ArrowUp'); |
125 assertDeepEquals(null, store.lastAction); | 131 assertDeepEquals(null, store.lastAction); |
126 }); | 132 }); |
| 133 |
| 134 test('keyboard left/right', function() { |
| 135 store.data.closedFolders = new Set('2'); |
| 136 store.notifyObservers(); |
| 137 |
| 138 // Give keyboard focus to the first item. |
| 139 getFolderNode('1').$.container.focus(); |
| 140 |
| 141 // Pressing right descends into first child. |
| 142 keydown('1', 'ArrowRight'); |
| 143 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); |
| 144 |
| 145 // Pressing right on a closed folder opens that folder |
| 146 keydown('2', 'ArrowRight'); |
| 147 assertDeepEquals( |
| 148 bookmarks.actions.changeFolderOpen('2', true), store.lastAction); |
| 149 |
| 150 // Pressing right again descends into first child. |
| 151 keydown('2', 'ArrowRight'); |
| 152 assertDeepEquals(bookmarks.actions.selectFolder('3'), store.lastAction); |
| 153 |
| 154 // Pressing right on a folder with no children does nothing. |
| 155 store.resetLastAction(); |
| 156 keydown('3', 'ArrowRight'); |
| 157 assertDeepEquals(null, store.lastAction); |
| 158 |
| 159 // Pressing left on a folder with no children ascends to parent. |
| 160 keydown('3', 'ArrowDown'); |
| 161 keydown('4', 'ArrowLeft'); |
| 162 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); |
| 163 |
| 164 // Pressing left again closes the parent. |
| 165 keydown('2', 'ArrowLeft'); |
| 166 assertDeepEquals( |
| 167 bookmarks.actions.changeFolderOpen('2', false), store.lastAction); |
| 168 |
| 169 // RTL flips left and right. |
| 170 document.body.style.direction = 'rtl'; |
| 171 keydown('2', 'ArrowLeft'); |
| 172 assertDeepEquals( |
| 173 bookmarks.actions.changeFolderOpen('2', true), store.lastAction); |
| 174 |
| 175 keydown('2', 'ArrowRight'); |
| 176 assertDeepEquals( |
| 177 bookmarks.actions.changeFolderOpen('2', false), store.lastAction); |
| 178 |
| 179 document.body.style.direction = 'ltr'; |
| 180 }); |
127 }); | 181 }); |
128 | 182 |
129 mocha.run(); | 183 mocha.run(); |
130 }); | 184 }); |
OLD | NEW |