Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1196)

Side by Side Diff: chrome/test/data/webui/md_history/test_util.js

Issue 2257703002: MD History: Improve test helpers, update synced tabs tests to use them (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revulcanize Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/test/data/webui/md_history/history_synced_tabs_test.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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();
11 // Promises have microtask timing, so we use setTimeout to explicity force a 11 // Promises have microtask timing, so we use setTimeout to explicity force a
12 // new task. 12 // new task.
13 return new Promise(function(resolve, reject) { 13 return new Promise(function(resolve, reject) {
14 window.setTimeout(resolve, 0); 14 window.setTimeout(resolve, 0);
15 }); 15 });
16 } 16 }
17 17
18 /** 18 /**
19 * Replace the current primary element of the test with a new element. Useful
20 * as an alternative to PolymerTest.clearBody() which preserves styling.
21 * @param {Element} element
22 */
23 function replaceBody(element) {
24 var body = document.body;
25 var currentBody =
26 body.querySelector('history-app') || body.querySelector('.test-body');
27 body.removeChild(currentBody);
28
29 element.classList.add('test-body');
30 body.appendChild(element);
31 }
32
33 /**
34 * Replace the document body with a new instance of <history-app>.
35 * @return {HistoryAppElement} The app which was created.
36 */
37 function replaceApp() {
38 var app = document.createElement('history-app');
39 app.id = 'history-app';
40 replaceBody(app);
41 return app;
42 }
43
44 /**
19 * Create a fake history result with the given timestamp. 45 * Create a fake history result with the given timestamp.
20 * @param {number|string} timestamp Timestamp of the entry, as a number in ms or 46 * @param {number|string} timestamp Timestamp of the entry, as a number in ms or
21 * a string which can be parsed by Date.parse(). 47 * a string which can be parsed by Date.parse().
22 * @param {string} urlStr The URL to set on this entry. 48 * @param {string} urlStr The URL to set on this entry.
23 * @return {!HistoryEntry} An object representing a history entry. 49 * @return {!HistoryEntry} An object representing a history entry.
24 */ 50 */
25 function createHistoryEntry(timestamp, urlStr) { 51 function createHistoryEntry(timestamp, urlStr) {
26 if (typeof timestamp === 'string') 52 if (typeof timestamp === 'string')
27 timestamp += ' UTC'; 53 timestamp += ' UTC';
28 54
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 clientX: xy.x, 148 clientX: xy.x,
123 clientY: xy.y, 149 clientY: xy.y,
124 buttons: 1, 150 buttons: 1,
125 shiftKey: true, 151 shiftKey: true,
126 }; 152 };
127 153
128 element.dispatchEvent(new MouseEvent('mousedown', props)); 154 element.dispatchEvent(new MouseEvent('mousedown', props));
129 element.dispatchEvent(new MouseEvent('mouseup', props)); 155 element.dispatchEvent(new MouseEvent('mouseup', props));
130 element.dispatchEvent(new MouseEvent('click', props)); 156 element.dispatchEvent(new MouseEvent('click', props));
131 } 157 }
OLDNEW
« no previous file with comments | « chrome/test/data/webui/md_history/history_synced_tabs_test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698