1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
content / test / data / media / mediarecorder_test_utils.js [blame]
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
'use strict';
// This function will be used only when we need to wait for data gathering.
function waitDuration(duration) {
return new Promise(function(resolve, reject) {
console.log('Waiting for ', duration.toString(), 'msec');
setTimeout(
function() {
console.log('Done waiting');
resolve();
}, duration);
});
}
function waitFor(description, predicate) {
return new Promise(function(resolve, reject) {
var startTime = new Date();
console.log('Waiting for', description.toString());
var check = setInterval(function() {
var elapsed = new Date() - startTime;
if (predicate()) {
clearInterval(check);
resolve();
} else if (elapsed > 3000) {
startTime = new Date();
console.log('Still waiting for satisfaction of ' +
predicate.toString());
}
}, 50);
});
}