Bug 1208373 - Check that we don't get "ended" event for tracks after calling stop(). r=jib

MozReview-Commit-ID: K9gOZtUNQ5K

--HG--
extra : rebase_source : cfe14a021af54eb16fdded0e71e8332d0fcf1448
extra : source : 2996367191d23fd1aa4630d4a964b2577c7fbf8c
This commit is contained in:
Andreas Pehrson 2016-05-12 13:50:34 +02:00
Родитель 7d1a406c3f
Коммит 65f6569e63
2 изменённых файлов: 35 добавлений и 3 удалений

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

@ -590,6 +590,28 @@ function createOneShotEventWrapper(wrapper, obj, event) {
};
}
/**
* Returns a promise that resolves when `target` has raised an event with the
* given name. Cancel the returned promise by passing in a `cancelPromise` and
* resolve it.
*
* @param {object} target
* The target on which the event should occur.
* @param {string} name
* The name of the event that should occur.
* @param {promise} cancelPromise
* A promise that on resolving rejects the returned promise,
* so we can avoid logging results after a test has finished.
*/
function haveEvent(target, name, cancelPromise) {
var listener;
var p = Promise.race([
(cancelPromise || new Promise()).then(e => Promise.reject(e)),
new Promise(resolve => target.addEventListener(name, listener = resolve))
]);
p.then(() => target.removeEventListener(name, listener));
return p;
};
/**
* This class executes a series of functions in a continuous sequence.

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

@ -55,8 +55,17 @@ MediaStreamPlayback.prototype = {
});
});
// TODO (bug 910249) Also check that all the tracks are local.
this.mediaStream.getTracks().forEach(t => t.stop());
var noTrackEnded = Promise.all(this.mediaStream.getTracks().map(t => {
let onNextLoop = wait(0);
let p = Promise.race([
onNextLoop,
haveEvent(t, "ended", onNextLoop)
.then(() => Promise.reject("Unexpected ended event for track " + t.id),
() => Promise.resolve())
]);
t.stop();
return p;
}));
// XXX (bug 1208316) When we implement MediaStream.active, do not stop
// the stream. We just do it now so the media element will raise 'ended'.
@ -65,7 +74,8 @@ MediaStreamPlayback.prototype = {
}
this.mediaStream.stop();
return timeout(waitForEnded(), ENDED_TIMEOUT_LENGTH, "ended event never fired")
.then(() => ok(true, "ended event successfully fired"));
.then(() => ok(true, "ended event successfully fired"))
.then(() => noTrackEnded);
},
/**