Bug 1421724 - Account for headless Firefox not exposing scary windows. r=florian
authorAndreas Pehrson <apehrson@mozilla.com>
Fri, 04 Jan 2019 13:15:46 +0000
changeset 509769 2c87990aee062f3008c9e0ab792d8b6ef9c9215e
parent 509768 2c1444bc6c19082702d5c19533e0c9586bfb2233
child 509770 a52b66841df98457965924c2810e2a6396df896d
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersflorian
bugs1421724
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1421724 - Account for headless Firefox not exposing scary windows. r=florian Differential Revision: https://phabricator.services.mozilla.com/D15712
browser/base/content/test/webrtc/browser_devices_get_user_media_screen.js
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_screen.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_screen.js
@@ -13,16 +13,20 @@ PromiseTestUtils.whitelistRejectionsGlob
 ChromeUtils.import("resource:///modules/BrowserWindowTracker.jsm", this);
 
 const permissionError = "error: NotAllowedError: The request is not allowed " +
     "by the user agent or the platform in the current context.";
 
 const notFoundError =
     "error: NotFoundError: The object can not be found here.";
 
+let env = Cc["@mozilla.org/process/environment;1"]
+            .getService(Ci.nsIEnvironment);
+const isHeadless = env.get("MOZ_HEADLESS");
+
 var gTests = [
 
 {
   desc: "getUserMedia window/screen picking screen",
   run: async function checkWindowOrScreen() {
     let promise = promisePopupNotificationShown("webRTC-shareDevices");
     await promiseRequestDevice(false, true, null, "screen");
     await promise;
@@ -171,62 +175,68 @@ var gTests = [
         ok(item.scary, "the screen item is marked as scary");
         scaryScreenIndex = i;
       } else if (item.scary) {
         scaryWindowIndexes.push(i);
       } else {
         nonScaryWindowIndex = i;
       }
     }
-    ok(scaryWindowIndexes.length, "there's at least one scary window, as Firefox is running");
-    ok(typeof scaryScreenIndex == "number", "there's at least one scary screen, as as all screens are");
+    if (isHeadless) {
+      is(scaryWindowIndexes.length, 0, "there are no scary Firefox windows in headless mode");
+    } else {
+      ok(scaryWindowIndexes.length, "there's at least one scary window, as Firefox is running");
+    }
+    ok(typeof scaryScreenIndex == "number", "there's at least one scary screen, as all screens are");
 
-    // Select one scary window, a preview with a scary warning should appear.
-    let scaryWindowIndex;
-    for (scaryWindowIndex of scaryWindowIndexes) {
+    if (!isHeadless) {
+      // Select one scary window, a preview with a scary warning should appear.
+      let scaryWindowIndex;
+      for (scaryWindowIndex of scaryWindowIndexes) {
+        menulist.getItemAtIndex(scaryWindowIndex).doCommand();
+        ok(document.getElementById("webRTC-all-windows-shared").hidden,
+           "the 'all windows will be shared' warning should still be hidden");
+        try {
+          await TestUtils.waitForCondition(() =>
+              !document.getElementById("webRTC-preview").hidden, "", 100, 100);
+          break;
+        } catch (e) {
+          // A "scary window" is Firefox. Multiple Firefox windows have been
+          // observed to come and go during try runs, so we won't know which one
+          // is ours. To avoid intermittents, we ignore preview failing due to
+          // these going away on us, provided it succeeds on one of them.
+        }
+      }
+      ok(!document.getElementById("webRTC-preview").hidden,
+         "the preview area is visible");
+      ok(!document.getElementById("webRTC-previewWarning").hidden,
+         "the scary warning is visible");
+      // Select the 'Select Window' item again, the preview should be hidden.
+      menulist.getItemAtIndex(0).doCommand();
+      ok(document.getElementById("webRTC-preview").hidden,
+         "the preview area is hidden");
+
+      // Select the first window again so that we can have a stream.
       menulist.getItemAtIndex(scaryWindowIndex).doCommand();
-      ok(document.getElementById("webRTC-all-windows-shared").hidden,
-         "the 'all windows will be shared' warning should still be hidden");
-      try {
-        await TestUtils.waitForCondition(() =>
-            !document.getElementById("webRTC-preview").hidden, "", 100, 100);
-        break;
-      } catch (e) {
-        // A "scary window" is Firefox. Multiple Firefox windows have been
-        // observed to come and go during try runs, so we won't know which one
-        // is ours. To avoid intermittents, we ignore preview failing due to
-        // these going away on us, provided it succeeds on one of them.
-      }
     }
-    ok(!document.getElementById("webRTC-preview").hidden,
-       "the preview area is visible");
-    ok(!document.getElementById("webRTC-previewWarning").hidden,
-       "the scary warning is visible");
-    // Select the 'Select Window' item again, the preview should be hidden.
-    menulist.getItemAtIndex(0).doCommand();
-    ok(document.getElementById("webRTC-preview").hidden,
-       "the preview area is hidden");
 
     // If we have a non-scary window, select it and verify the warning isn't displayed.
     // A non-scary window may not always exist on test slaves.
     if (typeof nonScaryWindowIndex == "number") {
       menulist.getItemAtIndex(nonScaryWindowIndex).doCommand();
       ok(document.getElementById("webRTC-all-windows-shared").hidden,
          "the 'all windows will be shared' warning should still be hidden");
     await TestUtils.waitForCondition(() =>
         !document.getElementById("webRTC-preview").hidden, "preview unhide", 100, 100);
       ok(!document.getElementById("webRTC-preview").hidden,
          "the preview area is visible");
       ok(document.getElementById("webRTC-previewWarning").hidden,
          "the scary warning is hidden");
     } else {
       info("no non-scary window available on this test slave");
-
-      // Select the first window again so that we can have a stream.
-      menulist.getItemAtIndex(scaryWindowIndex).doCommand();
     }
 
     let indicator = promiseIndicatorWindow();
     await promiseMessage("ok", () => {
       PopupNotifications.panel.firstElementChild.button.click();
     });
     await expectObserverCalled("getUserMedia:response:allow");
     await expectObserverCalled("recording-device-events");