OLD | NEW |
---|---|
(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. | |
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 setup(function() { | |
42 store = new bookmarks.TestStore({ | |
43 nodes: testTree( | |
44 createFolder( | |
45 '1', | |
46 [ | |
47 createFolder( | |
48 '2', | |
49 [ | |
50 createFolder('3', []), | |
51 createFolder('4', []), | |
52 ]), | |
53 createItem('5'), | |
54 ]), | |
55 createFolder('7', [])), | |
56 selectedFolder: '1', | |
57 }); | |
58 bookmarks.Store.instance_ = store; | |
59 | |
60 rootNode = document.createElement('bookmarks-folder-node'); | |
61 rootNode.itemId = '0'; | |
62 rootNode.depth = -1; | |
63 replaceBody(rootNode); | |
64 Polymer.dom.flush(); | |
65 }); | |
66 | |
67 test('keyboard selection', function() { | |
68 function focusAndKeydown(id, key) { | |
69 var container = getFolderNode(id).$.container; | |
70 container.focus(); | |
71 MockInteractions.keyDownOn(container, '', [], key); | |
72 } | |
73 | |
74 store.data.closedFolders = new Set('2'); | |
75 store.notifyObservers(); | |
76 | |
77 // The selected folder is focus enabled on attach. | |
78 assertEquals( | |
79 '0', getFolderNode('1').$.container.getAttribute('tabindex')); | |
80 | |
81 // Only the selected folder should be focusable. | |
82 assertEquals('', getFolderNode('2').$.container.getAttribute('tabindex')); | |
83 | |
84 // Move down into child. | |
85 focusAndKeydown('1', 'ArrowDown'); | |
tsergeant
2017/05/01 01:35:57
Two related questions:
- Why do you focus the fol
calamity
2017/05/03 03:01:47
This was just because the notifyObservers() would
| |
86 | |
87 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); | |
88 store.data.selectedFolder = '2'; | |
tsergeant
2017/05/01 01:35:57
With the recent changes to TestStore enough, are y
calamity
2017/05/03 03:01:47
Yep, that was the dream, and now the dream is real
| |
89 store.notifyObservers(); | |
90 | |
91 assertEquals('', getFolderNode('1').$.container.getAttribute('tabindex')); | |
92 assertEquals( | |
93 '0', getFolderNode('2').$.container.getAttribute('tabindex')); | |
94 | |
95 // Move down past closed folders. | |
96 focusAndKeydown('2', 'ArrowDown'); | |
97 assertDeepEquals(bookmarks.actions.selectFolder('7'), store.lastAction); | |
98 store.data.selectedFolder = '7'; | |
99 store.notifyObservers(); | |
100 | |
101 // Move down past end of list. | |
102 store.resetLastAction(); | |
103 focusAndKeydown('7', 'ArrowDown'); | |
104 assertDeepEquals(null, store.lastAction); | |
105 store.data.selectedFolder = '7'; | |
106 store.notifyObservers(); | |
107 | |
108 // Move up past closed folders. | |
109 focusAndKeydown('7', 'ArrowUp'); | |
110 assertDeepEquals(bookmarks.actions.selectFolder('2'), store.lastAction); | |
111 store.data.selectedFolder = '2'; | |
112 store.notifyObservers(); | |
113 | |
114 // Move up into parent. | |
115 focusAndKeydown('2', 'ArrowUp'); | |
116 assertDeepEquals(bookmarks.actions.selectFolder('1'), store.lastAction); | |
117 store.data.selectedFolder = '1'; | |
118 store.notifyObservers(); | |
119 | |
120 // Move up past start of list. | |
121 store.resetLastAction(); | |
122 focusAndKeydown('1', 'ArrowUp'); | |
123 assertDeepEquals(null, store.lastAction); | |
124 store.data.selectedFolder = '1'; | |
125 store.notifyObservers(); | |
126 }); | |
127 }); | |
128 | |
129 mocha.run(); | |
130 }); | |
OLD | NEW |