Bug 1286810: [MSE] P3. Update mochitests to reflect new duration behavior. r=gerald.

update/updateend is no longer fired when changing the duration. Also update the test to use promises, it makes things more readable

MozReview-Commit-ID: AeuEolCR5yT
This commit is contained in:
Jean-Yves Avenard 2016-07-15 23:48:49 +10:00
Родитель 103da1bf41
Коммит ccb52aa40e
5 изменённых файлов: 79 добавлений и 72 удалений

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

@ -12,42 +12,40 @@
SimpleTest.waitForExplicitFinish();
var updateCount = 0;
var durationChangeCount = 0;
runWithMSE(function (ms, v) {
ms.addEventListener("sourceopen", function () {
var sb = ms.addSourceBuffer("video/webm");
v.addEventListener("durationchange", function () {
durationChangeCount++;
});
fetchWithXHR("seek.webm", function (arrayBuffer) {
sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 318));
sb.addEventListener("updateend", function () {
updateCount++;
if (updateCount == 1) {
v.addEventListener("loadedmetadata", function () {
v.addEventListener("durationchange", function () {
durationChangeCount++;
});
// Set mediasource duration to 0, so future appendBuffer
// will update the mediasource duration
// setting ms.duration will fire updatestart/update/updateend
// event as per w3c spec followed by a durationchange
ms.duration = 0;
});
} else if (updateCount == 2) {
// will fire updatestart/update/updateend
// and a durationchange
sb.appendBuffer(new Uint8Array(arrayBuffer, 318));
} else if (updateCount == 3) {
// Adding the first init segment will fire a durationchange.
once(v, "loadedmetadata")
.then(function() {
ok(true, "got loadedmetadata");
// Set mediasource duration to 0, so future appendBuffer
// will update the mediasource duration.
// Changing the duration will fire a durationchange.
ms.duration = 0;
sb.appendBuffer(new Uint8Array(arrayBuffer, 318));
// Adding more data will fire durationchange.
once(sb, "updateend")
.then(function() {
ok(true, "got updateend");
// this will not fire durationchange as new duration == old duration
ms.endOfStream();
}
});
});
});
});
ms.addEventListener("sourceended", function () {
is(durationChangeCount, 3, "durationchange not fired as many times as expected");
// XXX: Duration should be exactly 4.0, see bug 1065207.
is(durationChangeCount, 2, "durationchange not fired as many times as expected");
ok(Math.abs(v.duration - 4) <= 0.002, "Video has correct duration");
SimpleTest.finish();
});

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

@ -12,44 +12,40 @@
SimpleTest.waitForExplicitFinish();
var updateCount = 0;
var durationChangeCount = 0;
runWithMSE(function (ms, v) {
ms.addEventListener("sourceopen", function () {
var sb = ms.addSourceBuffer("video/mp4");
v.addEventListener("durationchange", function () {
durationChangeCount++;
});
fetchWithXHR("bipbop/bipbop2s.mp4", function (arrayBuffer) {
sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 1395));
sb.addEventListener("updateend", function () {
updateCount++;
if (updateCount == 1) {
v.addEventListener("loadedmetadata", function () {
v.addEventListener("durationchange", function () {
durationChangeCount++;
});
// Set mediasource duration to 0, so future appendBuffer
// will update the mediasource duration
// setting ms.duration will fire updatestart/update/updateend
// event as per w3c spec followed by a durationchange
ms.duration = 0;
});
} else if (updateCount == 2) {
// will fire updatestart/update/updateend
// and a durationchange
sb.appendBuffer(new Uint8Array(arrayBuffer, 1395));
} else if (updateCount == 3) {
// Adding the first init segment will fire a durationchange.
once(v, "loadedmetadata")
.then(function() {
ok(true, "got loadedmetadata");
// Set mediasource duration to 0, so future appendBuffer
// will update the mediasource duration.
// Changing the duration will fire a durationchange.
ms.duration = 0;
sb.appendBuffer(new Uint8Array(arrayBuffer, 1395));
// Adding more data will fire durationchange.
once(sb, "updateend")
.then(function() {
ok(true, "got updateend");
// this will not fire durationchange as new duration == old duration
ms.endOfStream();
}
});
});
});
});
ms.addEventListener("sourceended", function () {
is(durationChangeCount, 2, "durationchange not fired as many times as expected");
// The bipbop video doesn't start at 0. The old MSE code adjust the
// timestamps and ignore the audio track. The new one doesn't.
isfuzzy(v.duration, 1.696, 0.166, "Video has correct duration");
is(durationChangeCount, 3, "durationchange not fired as many times as expected");
is(v.duration, 1.696666, "Video has correct duration");
SimpleTest.finish();
});
});

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

@ -66,7 +66,8 @@ runWithMSE(function(ms, el) {
isfuzzy(audiosb.buffered.start(0), 3, eps, "Audio starts at 3");
// Trim the rest of the audio.
ms.duration = videosb.buffered.end(0);
audiosb.remove(videosb.buffered.end(0), Infinity);
videosb.remove(videosb.buffered.end(0), Infinity);
return Promise.all([audiosb.updating ? once(audiosb, 'updateend') : Promise.resolve(),
videosb.updating ? once(videosb, 'updateend') : Promise.resolve()]);
}).then(function() {

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

@ -34,15 +34,20 @@ function do_seeked(e) {
var v = e.target;
v.removeEventListener("seeked", do_seeked, false);
var duration = round(v.duration / 3);
v._ms.duration = duration
v._sb.abort(); // this shouldn't abort updating the duration (bug 1130826).
ok(v.seeking, "seeking is true");
// test playback position was updated (bug 1130839).
is(v.currentTime, duration, "current time was updated");
is(v.duration, duration, "element duration was updated");
is(v._sb.buffered.length, 1, "One buffered range");
// Truncated mediasource duration will cause the video element to seek.
v.addEventListener("seeking", do_seeking, false);
is(v._sb.updating, false, "sourcebuffer isn't updating");
v._sb.remove(duration, Infinity);
once(v._sb, "updateend", function() {
v._ms.duration = duration
// frames aren't truncated, so duration may be slightly more.
isfuzzy(v.duration, duration, 1/30, "element duration was updated");
v._sb.abort(); // this shouldn't abort updating the duration (bug 1130826).
ok(v.seeking, "seeking is true");
// test playback position was updated (bug 1130839).
is(v.currentTime, v.duration, "current time was updated");
is(v._sb.buffered.length, 1, "One buffered range");
// Truncated mediasource duration will cause the video element to seek.
v.addEventListener("seeking", do_seeking, false);
});
}
function do_loaded(e) {

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

@ -12,8 +12,7 @@
// This test append data to a mediasource and then seek to half the duration
// of the video.
// We then shorten the video to 1/3rd of its original size by modifying the
// mediasource.duration attribute.
// We then shorten the video to 1/3rd of its original size.
// We ensure that the buffered range immediately reflect the truncation
// and that we've seeked to the new end of the media as per W3C spec and
// video.currentTime got updated.
@ -34,27 +33,35 @@ function do_seeked(e) {
var v = e.target;
v.removeEventListener("seeked", do_seeked, false);
var duration = round(v.duration / 3);
v._ms.duration = duration
v._sb.abort(); // this shouldn't abort updating the duration (bug 1130826).
ok(v.seeking, "seeking is true");
// test playback position was updated (bug 1130839).
is(v.currentTime, duration, "current time was updated");
is(v.duration, duration, "element duration was updated");
is(v._sb.buffered.length, 1, "One buffered range");
// Truncated mediasource duration will cause the video element to seek.
v.addEventListener("seeking", do_seeking, false);
is(v._sb.updating, false, "sourcebuffer isn't updating");
v._sb.remove(duration, Infinity);
once(v._sb, "updateend", function() {
v._ms.duration = duration
// frames aren't truncated, so duration may be slightly more.
isfuzzy(v.duration, duration, 1/30, "element duration was updated");
v._sb.abort(); // this shouldn't abort updating the duration (bug 1130826).
ok(v.seeking, "seeking is true");
// test playback position was updated (bug 1130839).
is(v.currentTime, v.duration, "current time was updated");
is(v._sb.buffered.length, 1, "One buffered range");
// Truncated mediasource duration will cause the video element to seek.
v.addEventListener("seeking", do_seeking, false);
});
}
function do_loaded(e) {
var v = e.target;
v.removeEventListener("loadeddata", do_loaded, false);
// mp4 metadata states 10s when we only have 1.6s worth of video.
v._ms.duration = v._sb.buffered.end(0);
is(v.duration, v._ms.duration, "current time updated with mediasource duration");
v.currentTime = v.duration / 2;
is(v.currentTime, v.duration / 2, "current time was updated");
ok(v.seeking, "seeking is true");
v.addEventListener("seeked", do_seeked, false);
v._sb.remove(v._sb.buffered.end(0), Infinity);
once(v._sb, "updateend", function() {
v._ms.duration = v._sb.buffered.end(0);
is(v.duration, v._ms.duration, "current time updated with mediasource duration");
v.currentTime = v.duration / 2;
is(v.currentTime, v.duration / 2, "current time was updated");
ok(v.seeking, "seeking is true");
v.addEventListener("seeked", do_seeked, false);
});
}
runWithMSE(function (ms, v) {