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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 bookmarks.actions.changeFolderOpen('2', true), store.lastAction); | 173 bookmarks.actions.changeFolderOpen('2', true), store.lastAction); |
174 | 174 |
175 keydown('2', 'ArrowRight'); | 175 keydown('2', 'ArrowRight'); |
176 assertDeepEquals( | 176 assertDeepEquals( |
177 bookmarks.actions.changeFolderOpen('2', false), store.lastAction); | 177 bookmarks.actions.changeFolderOpen('2', false), store.lastAction); |
178 | 178 |
179 document.body.style.direction = 'ltr'; | 179 document.body.style.direction = 'ltr'; |
180 }); | 180 }); |
181 }); | 181 }); |
182 | 182 |
| 183 suite('<bookmarks-list>', function() { |
| 184 var list; |
| 185 var store; |
| 186 var items; |
| 187 var multiKey = cr.isMac ? 'meta' : 'ctrl'; |
| 188 |
| 189 function keydown(item, key, modifiers) { |
| 190 MockInteractions.keyDownOn(item, '', modifiers, key); |
| 191 } |
| 192 |
| 193 setup(function() { |
| 194 store = new bookmarks.TestStore({ |
| 195 nodes: testTree(createFolder( |
| 196 '1', |
| 197 [ |
| 198 createItem('2'), |
| 199 createItem('3'), |
| 200 createItem('4'), |
| 201 createItem('5'), |
| 202 createItem('6'), |
| 203 createFolder('7', []), |
| 204 ])), |
| 205 selectedFolder: '1', |
| 206 }); |
| 207 store.setReducersEnabled(true); |
| 208 bookmarks.Store.instance_ = store; |
| 209 |
| 210 list = document.createElement('bookmarks-list'); |
| 211 list.style.height = '100%'; |
| 212 list.style.width = '100%'; |
| 213 list.style.position = 'absolute'; |
| 214 replaceBody(list); |
| 215 Polymer.dom.flush(); |
| 216 items = list.root.querySelectorAll('bookmarks-item'); |
| 217 }); |
| 218 |
| 219 test('simple keyboard selection', function() { |
| 220 var focusedItem = items[0]; |
| 221 assertEquals('0', focusedItem.getAttribute('tabindex')); |
| 222 assertEquals( |
| 223 '0', focusedItem.$$('.more-vert-button').getAttribute('tabindex')); |
| 224 focusedItem.focus(); |
| 225 |
| 226 keydown(focusedItem, 'ArrowDown'); |
| 227 focusedItem = items[1]; |
| 228 assertEquals('0', focusedItem.getAttribute('tabindex')); |
| 229 assertEquals( |
| 230 '0', focusedItem.$$('.more-vert-button').getAttribute('tabindex')); |
| 231 assertDeepEquals(['3'], normalizeSet(store.data.selection.items)); |
| 232 |
| 233 keydown(focusedItem, 'ArrowUp'); |
| 234 focusedItem = items[0]; |
| 235 assertEquals('0', focusedItem.getAttribute('tabindex')); |
| 236 assertDeepEquals(['2'], normalizeSet(store.data.selection.items)); |
| 237 |
| 238 keydown(focusedItem, 'End'); |
| 239 focusedItem = items[5]; |
| 240 assertEquals('0', focusedItem.getAttribute('tabindex')); |
| 241 assertDeepEquals(['7'], normalizeSet(store.data.selection.items)); |
| 242 |
| 243 // Moving past the end of the list is a no-op. |
| 244 keydown(focusedItem, 'ArrowDown'); |
| 245 assertEquals('0', focusedItem.getAttribute('tabindex')); |
| 246 assertDeepEquals(['7'], normalizeSet(store.data.selection.items)); |
| 247 |
| 248 keydown(focusedItem, 'Home'); |
| 249 focusedItem = items[0]; |
| 250 assertEquals('0', focusedItem.getAttribute('tabindex')); |
| 251 assertDeepEquals(['2'], normalizeSet(store.data.selection.items)); |
| 252 |
| 253 // Moving past the start of the list is a no-op. |
| 254 keydown(focusedItem, 'ArrowUp'); |
| 255 assertEquals('0', focusedItem.getAttribute('tabindex')); |
| 256 assertDeepEquals(['2'], normalizeSet(store.data.selection.items)); |
| 257 |
| 258 keydown(focusedItem, 'Escape'); |
| 259 assertDeepEquals([], normalizeSet(store.data.selection.items)); |
| 260 |
| 261 keydown(focusedItem, 'a', 'ctrl'); |
| 262 assertDeepEquals( |
| 263 ['2', '3', '4', '5', '6', '7'], |
| 264 normalizeSet(store.data.selection.items)); |
| 265 }); |
| 266 |
| 267 test('shift selection', function() { |
| 268 // TODO(calamity): Make the first item the anchor index when a new folder |
| 269 // is selected. |
| 270 var focusedItem = items[0]; |
| 271 focusedItem.focus(); |
| 272 |
| 273 keydown(focusedItem, 'ArrowDown'); |
| 274 focusedItem = items[1]; |
| 275 assertDeepEquals(['3'], normalizeSet(store.data.selection.items)); |
| 276 |
| 277 keydown(focusedItem, 'ArrowUp', 'shift'); |
| 278 focusedItem = items[0]; |
| 279 assertDeepEquals(['2', '3'], normalizeSet(store.data.selection.items)); |
| 280 |
| 281 keydown(focusedItem, 'ArrowDown', 'shift'); |
| 282 focusedItem = items[1]; |
| 283 assertDeepEquals(['3'], normalizeSet(store.data.selection.items)); |
| 284 |
| 285 keydown(focusedItem, 'ArrowDown', 'shift'); |
| 286 focusedItem = items[2]; |
| 287 assertDeepEquals(['3', '4'], normalizeSet(store.data.selection.items)); |
| 288 |
| 289 keydown(focusedItem, 'End', 'shift'); |
| 290 focusedItem = items[2]; |
| 291 assertDeepEquals( |
| 292 ['3', '4', '5', '6', '7'], normalizeSet(store.data.selection.items)); |
| 293 |
| 294 keydown(focusedItem, 'Home', 'shift'); |
| 295 focusedItem = items[2]; |
| 296 assertDeepEquals(['2', '3'], normalizeSet(store.data.selection.items)); |
| 297 }); |
| 298 |
| 299 test('ctrl selection', function() { |
| 300 var focusedItem = items[0]; |
| 301 focusedItem.focus(); |
| 302 |
| 303 keydown(focusedItem, ' ', 'ctrl'); |
| 304 assertDeepEquals(['2'], normalizeSet(store.data.selection.items)); |
| 305 |
| 306 keydown(focusedItem, 'ArrowDown', 'ctrl'); |
| 307 focusedItem = items[1]; |
| 308 assertDeepEquals(['2'], normalizeSet(store.data.selection.items)); |
| 309 assertEquals('3', store.data.selection.anchor); |
| 310 |
| 311 keydown(focusedItem, 'ArrowDown', 'ctrl'); |
| 312 focusedItem = items[2]; |
| 313 assertDeepEquals(['2'], normalizeSet(store.data.selection.items)); |
| 314 |
| 315 keydown(focusedItem, ' ', 'ctrl'); |
| 316 assertDeepEquals(['2', '4'], normalizeSet(store.data.selection.items)); |
| 317 |
| 318 keydown(focusedItem, ' ', 'ctrl'); |
| 319 assertDeepEquals(['2'], normalizeSet(store.data.selection.items)); |
| 320 }); |
| 321 |
| 322 test('ctrl+shift selection', function() { |
| 323 var focusedItem = items[0]; |
| 324 focusedItem.focus(); |
| 325 |
| 326 keydown(focusedItem, ' ', 'ctrl'); |
| 327 assertDeepEquals(['2'], normalizeSet(store.data.selection.items)); |
| 328 |
| 329 keydown(focusedItem, 'ArrowDown', 'ctrl'); |
| 330 focusedItem = items[1]; |
| 331 assertDeepEquals(['2'], normalizeSet(store.data.selection.items)); |
| 332 |
| 333 keydown(focusedItem, 'ArrowDown', 'ctrl'); |
| 334 focusedItem = items[2]; |
| 335 assertDeepEquals(['2'], normalizeSet(store.data.selection.items)); |
| 336 |
| 337 keydown(focusedItem, 'ArrowDown', ['ctrl', 'shift']); |
| 338 focusedItem = items[3]; |
| 339 assertDeepEquals( |
| 340 ['2', '4', '5'], normalizeSet(store.data.selection.items)); |
| 341 |
| 342 keydown(focusedItem, 'ArrowDown', ['ctrl', 'shift']); |
| 343 focusedItem = items[3]; |
| 344 assertDeepEquals( |
| 345 ['2', '4', '5', '6'], normalizeSet(store.data.selection.items)); |
| 346 }); |
| 347 }); |
| 348 |
183 mocha.run(); | 349 mocha.run(); |
184 }); | 350 }); |
OLD | NEW |