Bug 1652884 - Test that mute/unmute track events fire from UA muting camera. r=padenot

Differential Revision: https://phabricator.services.mozilla.com/D84243
This commit is contained in:
Jan-Ivar Bruaroey 2020-08-19 19:30:48 +00:00
Родитель 5a903e491c
Коммит 14d93f2803
2 изменённых файлов: 48 добавлений и 11 удалений

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

@ -32,6 +32,22 @@ function setTrackEnabled(audio, video) {
);
}
async function getVideoTrackMuted() {
return SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.wrappedJSObject.gStreams[0].getVideoTracks()[0].muted
);
}
async function getVideoTrackEvents() {
return SpecialPowers.spawn(
gBrowser.selectedBrowser,
[],
() => content.wrappedJSObject.gVideoEvents
);
}
function cloneTracks(audio, video) {
return SpecialPowers.spawn(
gBrowser.selectedBrowser,
@ -370,6 +386,12 @@ var gTests = [
video: STATE_CAPTURE_ENABLED,
audio: STATE_CAPTURE_ENABLED,
});
is(await getVideoTrackMuted(), false, "video track starts unmuted");
Assert.deepEqual(
await getVideoTrackEvents(),
[],
"no video track events fired yet"
);
// Mute camera.
observerPromise = expectObserverCalled("recording-device-events");
@ -390,6 +412,8 @@ var gTests = [
video: STATE_CAPTURE_DISABLED,
audio: STATE_CAPTURE_ENABLED,
});
is(await getVideoTrackMuted(), true, "video track is muted");
Assert.deepEqual(await getVideoTrackEvents(), ["mute"], "mute fired");
// Unmute video again.
observerPromise = expectObserverCalled("recording-device-events");
@ -409,6 +433,12 @@ var gTests = [
video: STATE_CAPTURE_ENABLED,
audio: STATE_CAPTURE_ENABLED,
});
is(await getVideoTrackMuted(), false, "video track is unmuted");
Assert.deepEqual(
await getVideoTrackEvents(),
["mute", "unmute"],
"unmute fired"
);
await closeStream();
},
},

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

@ -24,14 +24,12 @@ function message(m) {
}
var gStreams = [];
var gVideoEvents = [];
function requestDevice(aAudio, aVideo, aShare, aBadDevice = false) {
var opts = {video: aVideo, audio: aAudio};
async function requestDevice(aAudio, aVideo, aShare, aBadDevice = false) {
const opts = {video: aVideo, audio: aAudio};
if (aShare) {
opts.video = {
mozMediaSource: aShare,
mediaSource: aShare,
};
opts.video = { mediaSource: aShare };
}
if (useFakeStreams) {
opts.fake = true;
@ -51,11 +49,19 @@ function requestDevice(aAudio, aVideo, aShare, aBadDevice = false) {
opts.fake = true;
}
navigator.mediaDevices.getUserMedia(opts)
.then(stream => {
gStreams.push(stream);
message("ok");
}, err => message("error: " + err));
try {
const stream = await navigator.mediaDevices.getUserMedia(opts)
gStreams.push(stream);
const track = stream.getVideoTracks()[0];
if (track) {
for (const name of ["mute", "unmute", "ended"]) {
track.addEventListener(name, () => gVideoEvents.push(name));
}
}
message("ok");
} catch (err) {
message("error: " + err);
}
}
message("pending");
@ -67,6 +73,7 @@ function closeStream() {
}
}
gStreams = [];
gVideoEvents = [];
message("closed");
}
</script>