OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 * Replace the current body of the test with a new element. | 6 * Replace the current body of the test with a new element. |
7 * @param {Element} element | 7 * @param {Element} element |
8 */ | 8 */ |
9 function replaceBody(element) { | 9 function replaceBody(element) { |
10 PolymerTest.clearBody(); | 10 PolymerTest.clearBody(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 * @template T | 87 * @template T |
88 */ | 88 */ |
89 function normalizeSet(set) { | 89 function normalizeSet(set) { |
90 return Array.from(set).sort(); | 90 return Array.from(set).sort(); |
91 } | 91 } |
92 | 92 |
93 /** | 93 /** |
94 * Sends a custom click event to |element|. | 94 * Sends a custom click event to |element|. |
95 * @param {HTMLElement} element | 95 * @param {HTMLElement} element |
96 * @param {Object=} config | 96 * @param {Object=} config |
| 97 * @param {string=} eventname |
97 */ | 98 */ |
98 function customClick(element, config) { | 99 function customClick(element, config, eventname) { |
99 var props = { | 100 var props = { |
100 bubbles: true, | 101 bubbles: true, |
101 cancelable: true, | 102 cancelable: true, |
| 103 button: 0, |
102 buttons: 1, | 104 buttons: 1, |
103 shiftKey: false, | 105 shiftKey: false, |
104 ctrlKey: false, | 106 ctrlKey: false, |
| 107 detail: 1, |
105 }; | 108 }; |
106 | 109 |
107 if (config) { | 110 if (config) { |
108 for (var key in config) | 111 for (var key in config) |
109 props[key] = config[key]; | 112 props[key] = config[key]; |
110 } | 113 } |
111 | 114 |
| 115 eventname = eventname || 'click'; |
| 116 |
112 element.dispatchEvent(new MouseEvent('mousedown', props)); | 117 element.dispatchEvent(new MouseEvent('mousedown', props)); |
113 element.dispatchEvent(new MouseEvent('mouseup', props)); | 118 element.dispatchEvent(new MouseEvent('mouseup', props)); |
114 element.dispatchEvent(new MouseEvent('click', props)); | 119 element.dispatchEvent(new MouseEvent(eventname, props)); |
115 } | 120 } |
116 | 121 |
117 /** | 122 /** |
118 * Returns a folder node beneath |rootNode| which matches |id|. | 123 * Returns a folder node beneath |rootNode| which matches |id|. |
119 * @param {BookmarksFolderNodeElement} rootNode | 124 * @param {BookmarksFolderNodeElement} rootNode |
120 * @param {string} id | 125 * @param {string} id |
121 * @return {BookmarksFolderNodeElement} | 126 * @return {BookmarksFolderNodeElement} |
122 */ | 127 */ |
123 function findFolderNode(rootNode, id) { | 128 function findFolderNode(rootNode, id) { |
124 var nodes = [rootNode]; | 129 var nodes = [rootNode]; |
125 var node; | 130 var node; |
126 while (nodes.length) { | 131 while (nodes.length) { |
127 node = nodes.pop(); | 132 node = nodes.pop(); |
128 if (node.itemId == id) | 133 if (node.itemId == id) |
129 return node; | 134 return node; |
130 | 135 |
131 node.root.querySelectorAll('bookmarks-folder-node') | 136 node.root.querySelectorAll('bookmarks-folder-node') |
132 .forEach((x) => {nodes.unshift(x)}); | 137 .forEach((x) => {nodes.unshift(x)}); |
133 } | 138 } |
134 } | 139 } |
OLD | NEW |