bug 1208318 modify test to avoid assuming different clocks are synchronized r=padenot

--HG--
extra : rebase_source : 31ecead7358bdb7b511d5efd802f479af46aef42
This commit is contained in:
Karl Tomlinson 2015-09-25 13:05:03 +12:00
Родитель 5c1905cbf4
Коммит 5b32edea6d
1 изменённых файлов: 28 добавлений и 24 удалений

Просмотреть файл

@ -10,31 +10,35 @@
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
SimpleTest.requestFlakyTimeout("This test needs to wait until after the AudioContext's timer has started.");
addLoadEvent(
SimpleTest.requestFlakyTimeout(
"This test needs to wait until AudioDestinationNode has started has " +
"accumulated some 'extra' time.");
var context = new AudioContext();
const delay = 0.1;
setTimeout(
function() {
const delay = 0.1;
var context = new AudioContext();
SimpleTest.executeSoon( // to ensure that AudioContext has started
function() {
setTimeout( // wait for |delay|
function() {
var sp = context.createScriptProcessor(256);
sp.connect(context.destination);
sp.onaudioprocess =
function(e) {
var minimum =
(delay + e.inputBuffer.length/context.sampleRate) *
(1.0 - 1.0/Math.pow(2.0,52.0)); // double precision
ok(e.playbackTime >= minimum,
"playbackTime " + e.playbackTime +
" beyond expected minimum " + minimum);
sp.onaudioprocess = null;
SimpleTest.finish();
};
}, 1000 * delay);
});
});
const processorBufferLength = 256;
// |currentTime| may include double precision floating point
// rounding errors, so round to nearest integer sample to ignore these.
var minimumPlaybackSample =
Math.round(context.currentTime * context.sampleRate) +
processorBufferLength;
var sp = context.createScriptProcessor(processorBufferLength);
sp.connect(context.destination);
sp.onaudioprocess =
function(e) {
is(e.inputBuffer.length, processorBufferLength,
"expected buffer length");
var playbackSample = Math.round(e.playbackTime * context.sampleRate)
ok(playbackSample >= minimumPlaybackSample,
"playbackSample " + playbackSample +
" beyond expected minimum " + minimumPlaybackSample);
sp.onaudioprocess = null;
SimpleTest.finish();
};
}, 1000 * delay);
</script>
</pre>