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 * Waits for queued up tasks to finish before proceeding. Inspired by: | 6 * Waits for queued up tasks to finish before proceeding. Inspired by: |
7 * https://github.com/Polymer/web-component-tester/blob/master/browser/environme
nt/helpers.js#L97 | 7 * https://github.com/Polymer/web-component-tester/blob/master/browser/environme
nt/helpers.js#L97 |
8 */ | 8 */ |
9 function flush() { | 9 function flush() { |
10 Polymer.dom.flush(); | 10 Polymer.dom.flush(); |
(...skipping 19 matching lines...) Expand all Loading... |
30 body.appendChild(element); | 30 body.appendChild(element); |
31 } | 31 } |
32 | 32 |
33 /** | 33 /** |
34 * Replace the document body with a new instance of <history-app>. | 34 * Replace the document body with a new instance of <history-app>. |
35 * @return {HistoryAppElement} The app which was created. | 35 * @return {HistoryAppElement} The app which was created. |
36 */ | 36 */ |
37 function replaceApp() { | 37 function replaceApp() { |
38 var app = document.createElement('history-app'); | 38 var app = document.createElement('history-app'); |
39 app.id = 'history-app'; | 39 app.id = 'history-app'; |
| 40 // Disable querying for tests by default. |
| 41 app.queryState_.queryingDisabled = true; |
40 replaceBody(app); | 42 replaceBody(app); |
41 return app; | 43 return app; |
42 } | 44 } |
43 | 45 |
44 /** | 46 /** |
45 * Create a fake history result with the given timestamp. | 47 * Create a fake history result with the given timestamp. |
46 * @param {number|string} timestamp Timestamp of the entry, as a number in ms or | 48 * @param {number|string} timestamp Timestamp of the entry, as a number in ms or |
47 * a string which can be parsed by Date.parse(). | 49 * a string which can be parsed by Date.parse(). |
48 * @param {string} urlStr The URL to set on this entry. | 50 * @param {string} urlStr The URL to set on this entry. |
49 * @return {!HistoryEntry} An object representing a history entry. | 51 * @return {!HistoryEntry} An object representing a history entry. |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 clientX: xy.x, | 150 clientX: xy.x, |
149 clientY: xy.y, | 151 clientY: xy.y, |
150 buttons: 1, | 152 buttons: 1, |
151 shiftKey: true, | 153 shiftKey: true, |
152 }; | 154 }; |
153 | 155 |
154 element.dispatchEvent(new MouseEvent('mousedown', props)); | 156 element.dispatchEvent(new MouseEvent('mousedown', props)); |
155 element.dispatchEvent(new MouseEvent('mouseup', props)); | 157 element.dispatchEvent(new MouseEvent('mouseup', props)); |
156 element.dispatchEvent(new MouseEvent('click', props)); | 158 element.dispatchEvent(new MouseEvent('click', props)); |
157 } | 159 } |
| 160 |
| 161 function disableLinkClicks() { |
| 162 document.addEventListener('click', function(e) { |
| 163 if (e.defaultPrevented) |
| 164 return; |
| 165 |
| 166 var eventPath = e.path; |
| 167 var anchor = null; |
| 168 if (eventPath) { |
| 169 for (var i = 0; i < eventPath.length; i++) { |
| 170 var element = eventPath[i]; |
| 171 if (element.tagName === 'A' && element.href) { |
| 172 anchor = element; |
| 173 break; |
| 174 } |
| 175 } |
| 176 } |
| 177 |
| 178 if (!anchor) |
| 179 return; |
| 180 |
| 181 e.preventDefault(); |
| 182 }); |
| 183 } |
| 184 |
| 185 function createSession(name, windows) { |
| 186 return { |
| 187 collapsed: false, |
| 188 deviceType: '', |
| 189 name: name, |
| 190 modifiedTime: '2 seconds ago', |
| 191 tag: name, |
| 192 timestamp: 0, |
| 193 windows: windows |
| 194 }; |
| 195 } |
| 196 |
| 197 function createWindow(tabUrls) { |
| 198 var tabs = tabUrls.map(function(tabUrl) { |
| 199 return {sessionId: 456, timestamp: 0, title: tabUrl, url: tabUrl}; |
| 200 }); |
| 201 |
| 202 return { |
| 203 tabs: tabs, |
| 204 sessionId: '123', |
| 205 userVisibleTimestamp: "A while ago" |
| 206 }; |
| 207 } |
OLD | NEW |