Bug 1270572 - write tests for the umprompted gUM request; r=florian
MozReview-Commit-ID: LYWTNnfli6K
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media.js
@@ -39,16 +39,53 @@ var gTests = [
yield indicator;
yield checkSharingUI({audio: true, video: true});
yield closeStream();
}
},
{
+ desc: "getUserMedia audio+video while page already has live tracks connected to the same devices",
+ run: function* checkAudioVideoWhileLiveTracksExist() {
+ let promise = promisePopupNotificationShown("webRTC-shareDevices");
+ yield promiseRequestDevice(true, true, 0, 0, false);
+ yield promise;
+ yield expectObserverCalled("getUserMedia:request");
+
+ let indicator = promiseIndicatorWindow();
+ yield promiseMessage("ok", () => {
+ PopupNotifications.panel.firstChild.button.click();
+ });
+ yield expectObserverCalled("getUserMedia:response:allow");
+ yield expectObserverCalled("recording-device-events");
+ Assert.deepEqual((yield getMediaCaptureState()), {audio: true, video: true},
+ "expected camera and microphone to be shared");
+
+ yield indicator;
+ yield checkSharingUI({audio: true, video: true});
+
+ promise = promiseMessage("ok");
+ yield promiseRequestDevice(true, true, 0, 0, true);
+ yield promise;
+
+ yield expectObserverCalled("getUserMedia:request");
+ yield promiseNoPopupNotification("webRTC-shareDevices");
+ yield expectObserverCalled("getUserMedia:response:allow");
+ yield expectObserverCalled("recording-device-events");
+ Assert.deepEqual((yield getMediaCaptureState()), {audio: true, video: true},
+ "expected camera and microphone to be shared");
+
+ yield checkSharingUI({audio: true, video: true});
+ yield closeStream(false, 0, true);
+ yield closeStream(false, 0, false);
+ }
+},
+
+{
desc: "getUserMedia audio only",
run: function* checkAudioOnly() {
let promise = promisePopupNotificationShown("webRTC-shareDevices");
yield promiseRequestDevice(true);
yield promise;
yield expectObserverCalled("getUserMedia:request");
is(PopupNotifications.getNotification("webRTC-shareDevices").anchorID,
--- a/browser/base/content/test/webrtc/get_user_media.html
+++ b/browser/base/content/test/webrtc/get_user_media.html
@@ -18,38 +18,55 @@ try {
}
function message(m) {
document.getElementById("message").innerHTML = m;
window.parent.postMessage(m, "*");
}
var gStream;
+var gSecondStream;
-function requestDevice(aAudio, aVideo, aShare) {
+function requestDevice(aAudio, aVideo, aShare, aSecondStream) {
var opts = {video: aVideo, audio: aAudio};
if (aShare) {
opts.video = {
mozMediaSource: aShare,
mediaSource: aShare
}
} else if (useFakeStreams) {
opts.fake = true;
}
- window.navigator.mediaDevices.getUserMedia(opts)
- .then(stream => {
- gStream = stream;
- message("ok");
- }, err => message("error: " + err));
+ if (!aSecondStream) {
+ window.navigator.mediaDevices.getUserMedia(opts)
+ .then(stream => {
+ gStream = stream;
+ message("ok");
+ }, err => message("error: " + err));
+ } else {
+ window.navigator.mediaDevices.getUserMedia(opts)
+ .then(stream => {
+ gSecondStream = stream;
+ message("ok");
+ }, err => message("error: " + err));
+ }
}
message("pending");
-function closeStream() {
- if (!gStream)
- return;
- gStream.getTracks().forEach(t => t.stop());
- gStream = null;
- message("closed");
+function closeStream(aSecondStream) {
+ if (!aSecondStream) {
+ if (!gStream)
+ return;
+ gStream.getTracks().forEach(t => t.stop());
+ gStream = null;
+ message("closed");
+ } else {
+ if (!gSecondStream)
+ return;
+ gSecondStream.getTracks().forEach(t => t.stop());
+ gSecondStream = null;
+ message("closed");
+ }
}
</script>
</body>
</html>
--- a/browser/base/content/test/webrtc/head.js
+++ b/browser/base/content/test/webrtc/head.js
@@ -365,49 +365,56 @@ function* stopSharing(aType = "camera",
yield expectObserverCalled("recording-window-ended");
yield expectNoObserverCalled(aExpectDoubleRecordingEvent);
if (!aShouldKeepSharing)
yield* checkNotSharing();
}
-function promiseRequestDevice(aRequestAudio, aRequestVideo, aFrameId, aType) {
+function promiseRequestDevice(aRequestAudio, aRequestVideo, aFrameId, aType, aSecondStream) {
info("requesting devices");
return ContentTask.spawn(gBrowser.selectedBrowser,
- {aRequestAudio, aRequestVideo, aFrameId, aType},
+ {aRequestAudio, aRequestVideo, aFrameId, aType, aSecondStream},
function*(args) {
let global = content.wrappedJSObject;
if (args.aFrameId)
global = global.document.getElementById(args.aFrameId).contentWindow;
- global.requestDevice(args.aRequestAudio, args.aRequestVideo, args.aType);
+ global.requestDevice(args.aRequestAudio, args.aRequestVideo, args.aType, args.aSecondStream);
});
}
-function* closeStream(aAlreadyClosed, aFrameId) {
+function* closeStream(aAlreadyClosed, aFrameId, aSecondStream) {
yield expectNoObserverCalled();
let promises;
if (!aAlreadyClosed) {
- promises = [promiseObserverCalled("recording-device-events"),
- promiseObserverCalled("recording-window-ended")];
+ if (aSecondStream) {
+ promises = [promiseObserverCalled("recording-device-events")];
+ } else {
+ promises = [promiseObserverCalled("recording-device-events"),
+ promiseObserverCalled("recording-window-ended")];
+ }
}
info("closing the stream");
- yield ContentTask.spawn(gBrowser.selectedBrowser, aFrameId, function*(contentFrameId) {
+ yield ContentTask.spawn(gBrowser.selectedBrowser,
+ {aFrameId, aSecondStream},
+ function*(args) {
let global = content.wrappedJSObject;
- if (contentFrameId)
- global = global.document.getElementById(contentFrameId).contentWindow;
- global.closeStream();
+ if (args.aFrameId)
+ global = global.document.getElementById(args.aFrameId).contentWindow;
+ global.closeStream(args.aSecondStream);
});
if (promises)
yield Promise.all(promises);
- yield* assertWebRTCIndicatorStatus(null);
+ if (!aSecondStream)
+ yield* assertWebRTCIndicatorStatus(null);
}
function* reloadAndAssertClosedStreams() {
info("reloading the web page");
let promise = promiseObserverCalled("recording-device-events");
yield ContentTask.spawn(gBrowser.selectedBrowser, null,
"() => content.location.reload()");
yield promise;