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

Side by Side Diff: content/test/data/media/mediarecorder_test_utils.js

Issue 2868933003: Make waitFor check predicate before logging slowness. (Closed)
Patch Set: Created 3 years, 7 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 | « no previous file | 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 'use strict'; 5 'use strict';
6 6
7 // This function will be used only when we need to wait for data gathering. 7 // This function will be used only when we need to wait for data gathering.
8 function waitDuration(duration) { 8 function waitDuration(duration) {
9 return new Promise(function(resolve, reject) { 9 return new Promise(function(resolve, reject) {
10 console.log('Waiting for ', duration.toString(), 'msec'); 10 console.log('Waiting for ', duration.toString(), 'msec');
11 setTimeout( 11 setTimeout(
12 function() { 12 function() {
13 console.log('Done waiting'); 13 console.log('Done waiting');
14 resolve(); 14 resolve();
15 }, duration); 15 }, duration);
16 }); 16 });
17 } 17 }
18 18
19 function waitFor(description, predicate) { 19 function waitFor(description, predicate) {
20 return new Promise(function(resolve, reject) { 20 return new Promise(function(resolve, reject) {
21 var startTime = new Date(); 21 var startTime = new Date();
22 console.log('Waiting for', description.toString()); 22 console.log('Waiting for', description.toString());
23 var check = setInterval(function() { 23 var check = setInterval(function() {
24 var elapsed = new Date() - startTime; 24 var elapsed = new Date() - startTime;
25 if (elapsed > 3000) { 25 if (predicate()) {
26 clearInterval(check);
27 resolve();
28 } else if (elapsed > 3000) {
26 startTime = new Date(); 29 startTime = new Date();
27 console.log('Still waiting for satisfaction of ' + 30 console.log('Still waiting for satisfaction of ' +
28 predicate.toString()); 31 predicate.toString());
29 } else if (predicate()) {
30 clearInterval(check);
31 resolve();
32 } 32 }
33 }, 50); 33 }, 50);
34 }); 34 });
35 } 35 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698