Bug 1206233 - Update webrtc browser-chrome tests to pass without the webRTC-sharingDevices doorhanger, r=johannh.

This commit is contained in:
Florian Quèze 2016-08-09 22:52:27 +02:00
parent 77c40e0e1c
commit d067f073d1
3 changed files with 93 additions and 85 deletions

View File

@ -139,21 +139,7 @@ var gTests = [
yield indicator;
yield checkSharingUI({video: true, audio: true});
yield promiseNotificationShown(PopupNotifications.getNotification("webRTC-sharingDevices"));
activateSecondaryAction(kActionDeny);
yield promiseObserverCalled("recording-device-events");
yield expectObserverCalled("getUserMedia:revoke");
yield promiseNoPopupNotification("webRTC-sharingDevices");
yield expectObserverCalled("recording-window-ended");
if ((yield promiseTodoObserverNotCalled("recording-device-events")) == 1) {
todo(false, "Got the 'recording-device-events' notification twice, likely because of bug 962719");
}
yield expectNoObserverCalled();
yield checkNotSharing();
yield stopSharing();
// the stream is already closed, but this will do some cleanup anyway
yield closeStream(true);
@ -181,14 +167,11 @@ var gTests = [
yield indicator;
yield checkSharingUI({video: true, audio: true});
yield promiseNotificationShown(PopupNotifications.getNotification("webRTC-sharingDevices"));
info("reloading the web page");
promise = promiseObserverCalled("recording-device-events");
content.location.reload();
yield promise;
yield promiseNoPopupNotification("webRTC-sharingDevices");
if ((yield promiseTodoObserverNotCalled("recording-device-events")) == 1) {
todo(false, "Got the 'recording-device-events' notification twice, likely because of bug 962719");
}
@ -419,27 +402,7 @@ var gTests = [
yield indicator;
yield checkSharingUI({video: aRequestVideo, audio: aRequestAudio});
yield promiseNotificationShown(PopupNotifications.getNotification("webRTC-sharingDevices"));
let expectedIcon = "webRTC-sharingDevices";
if (aRequestAudio && !aRequestVideo)
expectedIcon = "webRTC-sharingMicrophone";
is(PopupNotifications.getNotification("webRTC-sharingDevices").anchorID,
expectedIcon + "-notification-icon", "anchored to correct icon");
is(PopupNotifications.panel.firstChild.getAttribute("popupid"), expectedIcon,
"panel using correct icon");
// Stop sharing.
activateSecondaryAction(kActionDeny);
yield promiseObserverCalled("recording-device-events");
yield expectObserverCalled("getUserMedia:revoke");
yield promiseNoPopupNotification("webRTC-sharingDevices");
yield expectObserverCalled("recording-window-ended");
if ((yield promiseTodoObserverNotCalled("recording-device-events")) == 1) {
todo(false, "Got the 'recording-device-events' notification twice, likely because of bug 962719");
}
yield stopSharing(aRequestVideo ? "camera" : "microphone");
// Check that permissions have been removed as expected.
let audioPerm = Perms.testExactPermission(uri, "microphone");
@ -471,8 +434,8 @@ var gTests = [
},
{
desc: "test showSharingDoorhanger",
run: function checkShowSharingDoorhanger() {
desc: "test showControlCenter",
run: function checkShowControlCenter() {
let promise = promisePopupNotificationShown("webRTC-shareDevices");
yield promiseRequestDevice(false, true);
yield promise;
@ -490,21 +453,21 @@ var gTests = [
yield indicator;
yield checkSharingUI({video: true});
yield promisePopupNotificationShown("webRTC-sharingDevices", () => {
if ("nsISystemStatusBar" in Ci) {
let activeStreams = webrtcUI.getActiveStreams(true, false, false);
webrtcUI.showSharingDoorhanger(activeStreams[0], "Devices");
}
else {
let win =
Services.wm.getMostRecentWindow("Browser:WebRTCGlobalIndicator");
let elt = win.document.getElementById("audioVideoButton");
EventUtils.synthesizeMouseAtCenter(elt, {}, win);
}
});
ok(gIdentityHandler._identityPopup.hidden, "control center should be hidden");
if ("nsISystemStatusBar" in Ci) {
let activeStreams = webrtcUI.getActiveStreams(true, false, false);
webrtcUI.showSharingDoorhanger(activeStreams[0], "Devices");
}
else {
let win =
Services.wm.getMostRecentWindow("Browser:WebRTCGlobalIndicator");
let elt = win.document.getElementById("audioVideoButton");
EventUtils.synthesizeMouseAtCenter(elt, {}, win);
yield promiseWaitForCondition(() => !gIdentityHandler._identityPopup.hidden);
}
ok(!gIdentityHandler._identityPopup.hidden, "control center should be open");
PopupNotifications.panel.firstChild.button.click();
ok(!PopupNotifications.isPanelOpen, "notification panel closed");
gIdentityHandler._identityPopup.hidden = true;
yield expectNoObserverCalled();
yield closeStream();
@ -566,6 +529,8 @@ function test() {
is(PopupNotifications._currentNotifications.length, 0,
"should start the test without any prior popup notification");
ok(gIdentityHandler._identityPopup.hidden,
"should start the test with the control center hidden");
Task.spawn(function () {
yield SpecialPowers.pushPrefEnv({"set": [[PREF_PERMISSION_FAKE, true]]});

View File

@ -71,21 +71,7 @@ var gTests = [
is(Perms.testExactPermission(uri, "camera"), Perms.ALLOW_ACTION,
"camera persistently allowed");
yield promiseNotificationShown(PopupNotifications.getNotification("webRTC-sharingDevices"));
activateSecondaryAction(kActionDeny);
yield promiseObserverCalled("recording-device-events");
yield expectObserverCalled("getUserMedia:revoke");
yield promiseNoPopupNotification("webRTC-sharingDevices");
yield expectObserverCalled("recording-window-ended");
if ((yield promiseTodoObserverNotCalled("recording-device-events")) == 1) {
todo(false, "Got the 'recording-device-events' notification twice, likely because of bug 962719");
}
yield expectNoObserverCalled();
yield checkNotSharing();
yield stopSharing();
// The persistent permissions for the frame should have been removed.
is(Perms.testExactPermission(uri, "microphone"), Perms.UNKNOWN_ACTION,
@ -124,7 +110,6 @@ var gTests = [
yield promiseReloadFrame("frame1");
yield promise;
yield promiseNoPopupNotification("webRTC-sharingDevices");
if ((yield promiseTodoObserverNotCalled("recording-device-events")) == 1) {
todo(false, "Got the 'recording-device-events' notification twice, likely because of bug 962719");
}
@ -201,15 +186,14 @@ var gTests = [
yield promiseReloadFrame("frame2");
yield promise;
yield checkSharingUI({video: false, audio: true});
yield expectObserverCalled("recording-window-ended");
yield checkSharingUI({video: false, audio: true});
if ((yield promiseTodoObserverNotCalled("recording-device-events")) == 1) {
todo(false, "Got the 'recording-device-events' notification twice, likely because of bug 962719");
}
yield expectNoObserverCalled();
yield closeStream(false, "frame1");
yield promiseNoPopupNotification("webRTC-sharingDevices");
yield expectNoObserverCalled();
yield checkNotSharing();
}

View File

@ -331,6 +331,27 @@ function getMediaCaptureState() {
});
}
function* stopSharing(aType = "camera") {
let promiseRecordingEvent = promiseObserverCalled("recording-device-events");
gIdentityHandler._identityBox.click();
let permissions = document.getElementById("identity-popup-permission-list");
let cancelButton =
permissions.querySelector(".identity-popup-permission-icon." + aType + "-icon ~ " +
".identity-popup-permission-remove-button");
cancelButton.click();
gIdentityHandler._identityPopup.hidden = true;
yield promiseRecordingEvent;
yield expectObserverCalled("getUserMedia:revoke");
yield expectObserverCalled("recording-window-ended");
if ((yield promiseTodoObserverNotCalled("recording-device-events")) == 1) {
todo(false, "Got the 'recording-device-events' notification twice, likely because of bug 962719");
}
yield expectNoObserverCalled();
yield* checkNotSharing();
}
function promiseRequestDevice(aRequestAudio, aRequestVideo, aFrameId, aType) {
info("requesting devices");
return ContentTask.spawn(gBrowser.selectedBrowser,
@ -346,9 +367,11 @@ function promiseRequestDevice(aRequestAudio, aRequestVideo, aFrameId, aType) {
function* closeStream(aAlreadyClosed, aFrameId) {
yield expectNoObserverCalled();
let promise;
if (!aAlreadyClosed)
promise = promiseObserverCalled("recording-device-events");
let promises;
if (!aAlreadyClosed) {
promises = [promiseObserverCalled("recording-device-events"),
promiseObserverCalled("recording-window-ended")];
}
info("closing the stream");
yield ContentTask.spawn(gBrowser.selectedBrowser, aFrameId, function*(aFrameId) {
@ -358,12 +381,8 @@ function* closeStream(aAlreadyClosed, aFrameId) {
global.closeStream();
});
if (!aAlreadyClosed)
yield promise;
yield promiseNoPopupNotification("webRTC-sharingDevices");
if (!aAlreadyClosed)
yield expectObserverCalled("recording-window-ended");
if (promises)
yield Promise.all(promises);
yield* assertWebRTCIndicatorStatus(null);
}
@ -383,16 +402,56 @@ function checkDeviceSelectors(aAudio, aVideo) {
}
function* checkSharingUI(aExpected) {
yield promisePopupNotification("webRTC-sharingDevices");
// First check the icon above the control center (i) icon.
let identityBox = document.getElementById("identity-box");
ok(identityBox.hasAttribute("sharing"), "sharing attribute is set");
let sharing = identityBox.getAttribute("sharing");
if (aExpected.video)
is(sharing, "camera", "showing camera icon on the control center icon");
else if (aExpected.audio)
is(sharing, "microphone", "showing mic icon on the control center icon");
// Then check the sharing indicators inside the control center panel.
identityBox.click();
let permissions = document.getElementById("identity-popup-permission-list");
for (let id of ["microphone", "camera", "screen"]) {
let convertId = id => {
if (id == "camera")
return "video";
if (id == "microphone")
return "audio";
return id;
};
let expected = aExpected[convertId(id)];
is(!!gIdentityHandler._sharingState[id], !!expected,
"sharing state for " + id + " as expected");
let icon = permissions.querySelectorAll(
".identity-popup-permission-icon." + id + "-icon");
if (expected) {
is(icon.length, 1, "should show " + id + " icon in control center panel");
ok(icon[0].classList.contains("in-use"), "icon should have the in-use class");
} else {
if (!icon.length) {
ok(true, "should not show " + id + " icon in the control center panel");
} else {
// This will happen if there are persistent permissions set.
ok(!icon[0].classList.contains("in-use"),
"if shown, the " + id + " icon should not have the in-use class");
is(icon.length, 1, "should not show more than 1 " + id + " icon");
}
}
}
gIdentityHandler._identityPopup.hidden = true;
// Check the global indicators.
yield* assertWebRTCIndicatorStatus(aExpected);
}
function* checkNotSharing() {
is((yield getMediaCaptureState()), "none", "expected nothing to be shared");
ok(!PopupNotifications.getNotification("webRTC-sharingDevices"),
"no webRTC-sharingDevices popup notification");
ok(!document.getElementById("identity-box").hasAttribute("sharing"),
"no sharing indicator on the control center icon");
yield* assertWebRTCIndicatorStatus(null);
}