| 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 = '../../../../../'; |
| 11 | 11 |
| 12 GEN_INCLUDE( | 12 GEN_INCLUDE( |
| 13 [ROOT_PATH + 'chrome/test/data/webui/polymer_interactive_ui_test.js']); | 13 [ROOT_PATH + 'chrome/test/data/webui/polymer_interactive_ui_test.js']); |
| 14 GEN('#include "base/command_line.h"'); | 14 GEN('#include "base/command_line.h"'); |
| 15 | 15 |
| 16 function MaterialBookmarksFocusTest() {} | 16 function MaterialBookmarksFocusTest() {} |
| 17 | 17 |
| 18 MaterialBookmarksFocusTest.prototype = { | 18 MaterialBookmarksFocusTest.prototype = { |
| 19 __proto__: PolymerInteractiveUITest.prototype, | 19 __proto__: PolymerInteractiveUITest.prototype, |
| 20 | 20 |
| 21 browsePreload: 'chrome://bookmarks', | 21 browsePreload: 'chrome://bookmarks', |
| 22 | 22 |
| 23 commandLineSwitches: | 23 commandLineSwitches: |
| 24 [{switchName: 'enable-features', switchValue: 'MaterialDesignBookmarks'}], | 24 [{switchName: 'enable-features', switchValue: 'MaterialDesignBookmarks'}], |
| 25 | 25 |
| 26 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([ | 26 extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([ |
| 27 'test_command_manager.js', |
| 27 'test_store.js', | 28 'test_store.js', |
| 28 'test_util.js', | 29 'test_util.js', |
| 29 ]), | 30 ]), |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 TEST_F('MaterialBookmarksFocusTest', 'All', function() { | 33 TEST_F('MaterialBookmarksFocusTest', 'All', function() { |
| 33 suite('<bookmarks-folder-node>', function() { | 34 suite('<bookmarks-folder-node>', function() { |
| 34 var rootNode; | 35 var rootNode; |
| 35 var store; | 36 var store; |
| 36 | 37 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 keydown('2', 'ArrowLeft'); | 172 keydown('2', 'ArrowLeft'); |
| 172 assertDeepEquals( | 173 assertDeepEquals( |
| 173 bookmarks.actions.changeFolderOpen('2', true), store.lastAction); | 174 bookmarks.actions.changeFolderOpen('2', true), store.lastAction); |
| 174 | 175 |
| 175 keydown('2', 'ArrowRight'); | 176 keydown('2', 'ArrowRight'); |
| 176 assertDeepEquals( | 177 assertDeepEquals( |
| 177 bookmarks.actions.changeFolderOpen('2', false), store.lastAction); | 178 bookmarks.actions.changeFolderOpen('2', false), store.lastAction); |
| 178 | 179 |
| 179 document.body.style.direction = 'ltr'; | 180 document.body.style.direction = 'ltr'; |
| 180 }); | 181 }); |
| 182 |
| 183 test('keyboard commands are passed to command manager', function() { |
| 184 var commandManager = new TestCommandManager(); |
| 185 document.body.appendChild(commandManager); |
| 186 chrome.bookmarkManagerPrivate.removeTrees = function() {} |
| 187 |
| 188 store.data.selection.items = new Set(['3', '4']); |
| 189 store.notifyObservers(); |
| 190 |
| 191 getFolderNode('1').$.container.focus(); |
| 192 keydown('1', 'delete'); |
| 193 |
| 194 commandManager.assertLastCommand(Command.DELETE, ['1']); |
| 195 }); |
| 181 }); | 196 }); |
| 182 | 197 |
| 183 suite('<bookmarks-list>', function() { | 198 suite('<bookmarks-list>', function() { |
| 184 var list; | 199 var list; |
| 185 var store; | 200 var store; |
| 186 var items; | 201 var items; |
| 187 var multiKey = cr.isMac ? 'meta' : 'ctrl'; | 202 var multiKey = cr.isMac ? 'meta' : 'ctrl'; |
| 188 | 203 |
| 189 function keydown(item, key, modifiers) { | 204 function keydown(item, key, modifiers) { |
| 190 MockInteractions.keyDownOn(item, '', modifiers, key); | 205 MockInteractions.keyDownOn(item, '', modifiers, key); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 keydown(focusedItem, 'ArrowDown', ['ctrl', 'shift']); | 352 keydown(focusedItem, 'ArrowDown', ['ctrl', 'shift']); |
| 338 focusedItem = items[3]; | 353 focusedItem = items[3]; |
| 339 assertDeepEquals( | 354 assertDeepEquals( |
| 340 ['2', '4', '5'], normalizeSet(store.data.selection.items)); | 355 ['2', '4', '5'], normalizeSet(store.data.selection.items)); |
| 341 | 356 |
| 342 keydown(focusedItem, 'ArrowDown', ['ctrl', 'shift']); | 357 keydown(focusedItem, 'ArrowDown', ['ctrl', 'shift']); |
| 343 focusedItem = items[3]; | 358 focusedItem = items[3]; |
| 344 assertDeepEquals( | 359 assertDeepEquals( |
| 345 ['2', '4', '5', '6'], normalizeSet(store.data.selection.items)); | 360 ['2', '4', '5', '6'], normalizeSet(store.data.selection.items)); |
| 346 }); | 361 }); |
| 362 |
| 363 test('keyboard commands are passed to command manager', function() { |
| 364 var commandManager = new TestCommandManager(); |
| 365 document.body.appendChild(commandManager); |
| 366 chrome.bookmarkManagerPrivate.removeTrees = function() {} |
| 367 |
| 368 store.data.selection.items = new Set(['2', '3']); |
| 369 store.notifyObservers(); |
| 370 |
| 371 var focusedItem = items[4]; |
| 372 focusedItem.focus(); |
| 373 |
| 374 keydown(focusedItem, 'Delete'); |
| 375 // Commands should take affect on the selection, even if something else is |
| 376 // focused. |
| 377 commandManager.assertLastCommand(Command.DELETE, ['2', '3']); |
| 378 }); |
| 379 |
| 380 test('iron-list does not steal focus on enter', function() { |
| 381 // Iron-list attempts to focus the whole <bookmarks-item> when pressing |
| 382 // enter on the menu button. This checks that we block this behavior |
| 383 // during keydown on <bookmarks-list>. |
| 384 var commandManager = new TestCommandManager(); |
| 385 document.body.appendChild(commandManager); |
| 386 |
| 387 var button = items[0].$$('.more-vert-button'); |
| 388 button.focus(); |
| 389 keydown(button, 'Enter'); |
| 390 |
| 391 assertEquals(button, items[0].root.activeElement); |
| 392 }); |
| 347 }); | 393 }); |
| 348 | 394 |
| 349 mocha.run(); | 395 mocha.run(); |
| 350 }); | 396 }); |
| OLD | NEW |