Bug 1298594: P5. Fix mochitest. r?gerald
The assumption was that the waiting event would be fired once the last frame prior the gap had been played. This is however incorrect, as per spec, the waiting event is to be fired once readyState is <= HAVE_CURRENT_DATA. So the waiting event is actually fired anytime between the start of the last frame and its end.
MozReview-Commit-ID: AA4Qhn7okhB
--- a/dom/media/mediasource/test/test_Threshold_mp4.html
+++ b/dom/media/mediasource/test/test_Threshold_mp4.html
@@ -10,23 +10,22 @@
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
runWithMSE(function(ms, el) {
var threshold = 0.5; // gap threshold in seconds.
-// duration of a frame. The FFmpeg decoder can't calculate properly calculate the duration of the last frame.
-var fuzz = 33322 / 1000000;
+var fuzz = 0.000001; // fuzz when comparing double.
once(ms, 'sourceopen').then(function() {
ok(true, "Receive a sourceopen event");
var videosb = ms.addSourceBuffer("video/mp4");
- var vchunks = [ {start: 0, end: 3.2033}, { start: 3.2033, end: 6.4066}];
+ var vchunks = [ {start: 0, end: 3.203333}, { start: 3.203333, end: 6.406666}];
fetchAndLoad(videosb, 'bipbop/bipbop_video', ['init'], '.mp4')
.then(fetchAndLoad.bind(null, videosb, 'bipbop/bipbop_video', range(1, 5), '.m4s'))
.then(function() {
// We will insert a gap of threshold
videosb.timestampOffset = threshold;
return fetchAndLoad(videosb, 'bipbop/bipbop_video', range(5, 9), '.m4s');
}).then(function() {
@@ -35,18 +34,20 @@ var fuzz = 33322 / 1000000;
// we starting waiting for 'waiting'.
info("Invoking play()");
var p = once(el, 'playing');
el.play();
return p;
}).then(function() {
return once(el, 'waiting');
}).then(function() {
- // We're waiting for data at the end of the last segment.
- isfuzzy(el.currentTime, vchunks[1].end + threshold, fuzz, "skipped the gap properly");
+ // We're waiting for data after the start of the last frame.
+ // 0.033333 is the duration of the last frame.
+ ok(el.currentTime >= vchunks[1].end - 0.033333 + threshold - fuzz
+ && el.currentTime <= vchunks[1].end + threshold + fuzz, "skipped the gap properly: " + el.currentTime + " " + (vchunks[1].end + threshold));
is(el.buffered.length, 2, "buffered range has right length");
// Now we test that seeking will succeed despite the gap.
el.currentTime = el.buffered.end(0) + (threshold / 2);
return once(el, 'seeked');
}).then(function() {
// Now we test that we don't pass the gap.
// Clean up our sourcebuffer by removing all data.
videosb.timestampOffset = 0;
@@ -63,18 +64,20 @@ var fuzz = 33322 / 1000000;
}).then(function() {
info("Invoking play()");
var p = once(el, 'playing');
el.play();
return p;
}).then(function() {
return once(el, 'waiting');
}).then(function() {
- // We're waiting for data at the end of the first segment as the gap is too big.
- isfuzzy(el.currentTime, vchunks[0].end, fuzz, "stopped at the gap properly");
+ // We're waiting for data after the start of the last frame.
+ // 0.033333 is the duration of the last frame.
+ ok(el.currentTime >= vchunks[0].end - 0.033333 - fuzz
+ && el.currentTime <= vchunks[0].end + fuzz, "stopped at the gap properly: " + el.currentTime + " " + vchunks[0].end);
SimpleTest.finish();
});
});
});
</script>
</pre>
</body>