diff --git a/browser/base/content/test/general/browser.ini b/browser/base/content/test/general/browser.ini index 0164761912dc..f7f1226dfebc 100644 --- a/browser/base/content/test/general/browser.ini +++ b/browser/base/content/test/general/browser.ini @@ -69,9 +69,6 @@ support-files = file_favicon_change.html file_favicon_change_not_in_document.html file_fullscreen-window-open.html - get_user_media.html - get_user_media_content_script.js - get_user_media_helpers.js head.js healthreport_pingData.js healthreport_testRemoteCommands.html @@ -293,12 +290,6 @@ skip-if = !datareporting [browser_decoderDoctor.js] skip-if = os == "mac" # decoder doctor isn't implemented on osx [browser_devedition.js] -[browser_devices_get_user_media.js] -skip-if = buildapp == 'mulet' || (os == "linux" && debug) # linux: bug 976544 -[browser_devices_get_user_media_about_urls.js] -skip-if = e10s && debug -[browser_devices_get_user_media_anim.js] -[browser_devices_get_user_media_in_frame.js] [browser_discovery.js] [browser_double_close_tab.js] [browser_documentnavigation.js] diff --git a/browser/base/content/test/general/head.js b/browser/base/content/test/general/head.js index 40f2384d63e7..c378b8769e50 100644 --- a/browser/base/content/test/general/head.js +++ b/browser/base/content/test/general/head.js @@ -658,119 +658,6 @@ function waitForNewTabEvent(aTabBrowser) { return promiseWaitForEvent(aTabBrowser.tabContainer, "TabOpen"); } -/** - * Waits for a window with the given URL to exist. - * - * @param url - * The url of the window. - * @return {Promise} resolved when the window exists. - * @resolves to the window - */ -function promiseWindow(url) { - info("expecting a " + url + " window"); - return new Promise(resolve => { - Services.obs.addObserver(function obs(win) { - win.QueryInterface(Ci.nsIDOMWindow); - win.addEventListener("load", function loadHandler() { - win.removeEventListener("load", loadHandler); - - if (win.location.href !== url) { - info("ignoring a window with this url: " + win.location.href); - return; - } - - Services.obs.removeObserver(obs, "domwindowopened"); - resolve(win); - }); - }, "domwindowopened", false); - }); -} - -function promiseIndicatorWindow() { - // We don't show the indicator window on Mac. - if ("nsISystemStatusBar" in Ci) - return Promise.resolve(); - - return promiseWindow("chrome://browser/content/webrtcIndicator.xul"); -} - -function assertWebRTCIndicatorStatus(expected) { - let ui = Cu.import("resource:///modules/webrtcUI.jsm", {}).webrtcUI; - let expectedState = expected ? "visible" : "hidden"; - let msg = "WebRTC indicator " + expectedState; - if (!expected && ui.showGlobalIndicator) { - // It seems the global indicator is not always removed synchronously - // in some cases. - info("waiting for the global indicator to be hidden"); - yield promiseWaitForCondition(() => !ui.showGlobalIndicator); - } - is(ui.showGlobalIndicator, !!expected, msg); - - let expectVideo = false, expectAudio = false, expectScreen = false; - if (expected) { - if (expected.video) - expectVideo = true; - if (expected.audio) - expectAudio = true; - if (expected.screen) - expectScreen = true; - } - is(ui.showCameraIndicator, expectVideo, "camera global indicator as expected"); - is(ui.showMicrophoneIndicator, expectAudio, "microphone global indicator as expected"); - is(ui.showScreenSharingIndicator, expectScreen, "screen global indicator as expected"); - - let windows = Services.wm.getEnumerator("navigator:browser"); - while (windows.hasMoreElements()) { - let win = windows.getNext(); - let menu = win.document.getElementById("tabSharingMenu"); - is(menu && !menu.hidden, !!expected, "WebRTC menu should be " + expectedState); - } - - if (!("nsISystemStatusBar" in Ci)) { - if (!expected) { - let win = Services.wm.getMostRecentWindow("Browser:WebRTCGlobalIndicator"); - if (win) { - yield new Promise((resolve, reject) => { - win.addEventListener("unload", function listener(e) { - if (e.target == win.document) { - win.removeEventListener("unload", listener); - resolve(); - } - }, false); - }); - } - } - let indicator = Services.wm.getEnumerator("Browser:WebRTCGlobalIndicator"); - let hasWindow = indicator.hasMoreElements(); - is(hasWindow, !!expected, "popup " + msg); - if (hasWindow) { - let document = indicator.getNext().document; - let docElt = document.documentElement; - - if (document.readyState != "complete") { - info("Waiting for the sharing indicator's document to load"); - let deferred = Promise.defer(); - document.addEventListener("readystatechange", - function onReadyStateChange() { - if (document.readyState != "complete") - return; - document.removeEventListener("readystatechange", onReadyStateChange); - deferred.resolve(); - }); - yield deferred.promise; - } - - for (let item of ["video", "audio", "screen"]) { - let expectedValue = (expected && expected[item]) ? "true" : ""; - is(docElt.getAttribute("sharing" + item), expectedValue, - item + " global indicator attribute as expected"); - } - - ok(!indicator.hasMoreElements(), "only one global indicator window"); - } - } -} - /** * Test the state of the identity box and control center to make * sure they are correctly showing the expected mixed content states. diff --git a/browser/base/content/test/webrtc/browser.ini b/browser/base/content/test/webrtc/browser.ini new file mode 100644 index 000000000000..8745418c47a0 --- /dev/null +++ b/browser/base/content/test/webrtc/browser.ini @@ -0,0 +1,13 @@ +[DEFAULT] +support-files = + get_user_media.html + get_user_media_content_script.js + get_user_media_helpers.js + head.js + +[browser_devices_get_user_media.js] +skip-if = buildapp == 'mulet' || (os == "linux" && debug) # linux: bug 976544 +[browser_devices_get_user_media_about_urls.js] +skip-if = e10s && debug +[browser_devices_get_user_media_anim.js] +[browser_devices_get_user_media_in_frame.js] diff --git a/browser/base/content/test/general/browser_devices_get_user_media.js b/browser/base/content/test/webrtc/browser_devices_get_user_media.js similarity index 100% rename from browser/base/content/test/general/browser_devices_get_user_media.js rename to browser/base/content/test/webrtc/browser_devices_get_user_media.js diff --git a/browser/base/content/test/general/browser_devices_get_user_media_about_urls.js b/browser/base/content/test/webrtc/browser_devices_get_user_media_about_urls.js similarity index 100% rename from browser/base/content/test/general/browser_devices_get_user_media_about_urls.js rename to browser/base/content/test/webrtc/browser_devices_get_user_media_about_urls.js diff --git a/browser/base/content/test/general/browser_devices_get_user_media_anim.js b/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js similarity index 100% rename from browser/base/content/test/general/browser_devices_get_user_media_anim.js rename to browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js diff --git a/browser/base/content/test/general/browser_devices_get_user_media_in_frame.js b/browser/base/content/test/webrtc/browser_devices_get_user_media_in_frame.js similarity index 100% rename from browser/base/content/test/general/browser_devices_get_user_media_in_frame.js rename to browser/base/content/test/webrtc/browser_devices_get_user_media_in_frame.js diff --git a/browser/base/content/test/general/get_user_media.html b/browser/base/content/test/webrtc/get_user_media.html similarity index 100% rename from browser/base/content/test/general/get_user_media.html rename to browser/base/content/test/webrtc/get_user_media.html diff --git a/browser/base/content/test/general/get_user_media_content_script.js b/browser/base/content/test/webrtc/get_user_media_content_script.js similarity index 100% rename from browser/base/content/test/general/get_user_media_content_script.js rename to browser/base/content/test/webrtc/get_user_media_content_script.js diff --git a/browser/base/content/test/general/get_user_media_helpers.js b/browser/base/content/test/webrtc/get_user_media_helpers.js similarity index 100% rename from browser/base/content/test/general/get_user_media_helpers.js rename to browser/base/content/test/webrtc/get_user_media_helpers.js diff --git a/browser/base/content/test/webrtc/head.js b/browser/base/content/test/webrtc/head.js new file mode 100644 index 000000000000..d2d951520049 --- /dev/null +++ b/browser/base/content/test/webrtc/head.js @@ -0,0 +1,172 @@ +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); + +XPCOMUtils.defineLazyModuleGetter(this, "Promise", + "resource://gre/modules/Promise.jsm"); + +function waitForCondition(condition, nextTest, errorMsg, retryTimes) { + retryTimes = typeof retryTimes !== 'undefined' ? retryTimes : 30; + var tries = 0; + var interval = setInterval(function() { + if (tries >= retryTimes) { + ok(false, errorMsg); + moveOn(); + } + var conditionPassed; + try { + conditionPassed = condition(); + } catch (e) { + ok(false, e + "\n" + e.stack); + conditionPassed = false; + } + if (conditionPassed) { + moveOn(); + } + tries++; + }, 100); + var moveOn = function() { clearInterval(interval); nextTest(); }; +} + +function promiseWaitForCondition(aConditionFn) { + let deferred = Promise.defer(); + waitForCondition(aConditionFn, deferred.resolve, "Condition didn't pass."); + return deferred.promise; +} + +/** + * Waits for a window with the given URL to exist. + * + * @param url + * The url of the window. + * @return {Promise} resolved when the window exists. + * @resolves to the window + */ +function promiseWindow(url) { + info("expecting a " + url + " window"); + return new Promise(resolve => { + Services.obs.addObserver(function obs(win) { + win.QueryInterface(Ci.nsIDOMWindow); + win.addEventListener("load", function loadHandler() { + win.removeEventListener("load", loadHandler); + + if (win.location.href !== url) { + info("ignoring a window with this url: " + win.location.href); + return; + } + + Services.obs.removeObserver(obs, "domwindowopened"); + resolve(win); + }); + }, "domwindowopened", false); + }); +} + +function promiseIndicatorWindow() { + // We don't show the indicator window on Mac. + if ("nsISystemStatusBar" in Ci) + return Promise.resolve(); + + return promiseWindow("chrome://browser/content/webrtcIndicator.xul"); +} + +function assertWebRTCIndicatorStatus(expected) { + let ui = Cu.import("resource:///modules/webrtcUI.jsm", {}).webrtcUI; + let expectedState = expected ? "visible" : "hidden"; + let msg = "WebRTC indicator " + expectedState; + if (!expected && ui.showGlobalIndicator) { + // It seems the global indicator is not always removed synchronously + // in some cases. + info("waiting for the global indicator to be hidden"); + yield promiseWaitForCondition(() => !ui.showGlobalIndicator); + } + is(ui.showGlobalIndicator, !!expected, msg); + + let expectVideo = false, expectAudio = false, expectScreen = false; + if (expected) { + if (expected.video) + expectVideo = true; + if (expected.audio) + expectAudio = true; + if (expected.screen) + expectScreen = true; + } + is(ui.showCameraIndicator, expectVideo, "camera global indicator as expected"); + is(ui.showMicrophoneIndicator, expectAudio, "microphone global indicator as expected"); + is(ui.showScreenSharingIndicator, expectScreen, "screen global indicator as expected"); + + let windows = Services.wm.getEnumerator("navigator:browser"); + while (windows.hasMoreElements()) { + let win = windows.getNext(); + let menu = win.document.getElementById("tabSharingMenu"); + is(menu && !menu.hidden, !!expected, "WebRTC menu should be " + expectedState); + } + + if (!("nsISystemStatusBar" in Ci)) { + if (!expected) { + let win = Services.wm.getMostRecentWindow("Browser:WebRTCGlobalIndicator"); + if (win) { + yield new Promise((resolve, reject) => { + win.addEventListener("unload", function listener(e) { + if (e.target == win.document) { + win.removeEventListener("unload", listener); + resolve(); + } + }, false); + }); + } + } + let indicator = Services.wm.getEnumerator("Browser:WebRTCGlobalIndicator"); + let hasWindow = indicator.hasMoreElements(); + is(hasWindow, !!expected, "popup " + msg); + if (hasWindow) { + let document = indicator.getNext().document; + let docElt = document.documentElement; + + if (document.readyState != "complete") { + info("Waiting for the sharing indicator's document to load"); + let deferred = Promise.defer(); + document.addEventListener("readystatechange", + function onReadyStateChange() { + if (document.readyState != "complete") + return; + document.removeEventListener("readystatechange", onReadyStateChange); + deferred.resolve(); + }); + yield deferred.promise; + } + + for (let item of ["video", "audio", "screen"]) { + let expectedValue = (expected && expected[item]) ? "true" : ""; + is(docElt.getAttribute("sharing" + item), expectedValue, + item + " global indicator attribute as expected"); + } + + ok(!indicator.hasMoreElements(), "only one global indicator window"); + } + } +} + +function promisePopupEvent(popup, eventSuffix) { + let endState = {shown: "open", hidden: "closed"}[eventSuffix]; + + if (popup.state == endState) + return Promise.resolve(); + + let eventType = "popup" + eventSuffix; + let deferred = Promise.defer(); + popup.addEventListener(eventType, function onPopupShown(event) { + popup.removeEventListener(eventType, onPopupShown); + deferred.resolve(); + }); + + return deferred.promise; +} + +function promiseNotificationShown(notification) { + let win = notification.browser.ownerDocument.defaultView; + if (win.PopupNotifications.panel.state == "open") { + return Promise.resolve(); + } + let panelPromise = promisePopupEvent(win.PopupNotifications.panel, "shown"); + notification.reshow(); + return panelPromise; +} diff --git a/browser/base/moz.build b/browser/base/moz.build index 2ce039711756..672cac4b9043 100644 --- a/browser/base/moz.build +++ b/browser/base/moz.build @@ -25,6 +25,7 @@ BROWSER_CHROME_MANIFESTS += [ 'content/test/social/browser.ini', 'content/test/tabPrompts/browser.ini', 'content/test/urlbar/browser.ini', + 'content/test/webrtc/browser.ini', ] DEFINES['MOZ_APP_VERSION'] = CONFIG['MOZ_APP_VERSION']