Bug 1353910 - Use an options object for runTests. r=florian draft
authorBlake Kaplan <mrbkap@gmail.com>
Fri, 07 Apr 2017 12:52:23 -0400
changeset 558418 6f9b197f68af3b7f7ade953299f46dd3ece3073d
parent 557435 322d3ca8979954ea6f03a4bf5363fed821f572c4
child 558419 f292b8eee8ce4d6bc44709fae054daaa58fb818d
push id52889
push userbmo:mrbkap@mozilla.com
push dateFri, 07 Apr 2017 17:30:02 +0000
reviewersflorian
bugs1353910
milestone55.0a1
Bug 1353910 - Use an options object for runTests. r=florian MozReview-Commit-ID: BrWlgFCNdAO
browser/base/content/test/webrtc/browser_devices_get_user_media.js
browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js
browser/base/content/test/webrtc/browser_devices_get_user_media_in_frame.js
browser/base/content/test/webrtc/browser_devices_get_user_media_multi_process.js
browser/base/content/test/webrtc/browser_devices_get_user_media_screen.js
browser/base/content/test/webrtc/browser_devices_get_user_media_tear_off_tab.js
browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access.js
browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access_in_frame.js
browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access_tear_off_tab.js
browser/base/content/test/webrtc/browser_webrtc_hooks.js
browser/base/content/test/webrtc/head.js
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media.js
@@ -571,14 +571,10 @@ var gTests = [
     webrtcUI.uninit();
     webrtcUI.init();
   }
 }
 
 ];
 
 add_task(async function test() {
-  let rootDir = getRootDirectory(gTestPath);
-  rootDir = rootDir.replace("chrome://mochitests/content/",
-                            "https://example.com/");
-
-  await runTests(gTests, rootDir + "get_user_media.html");
+  await runTests(gTests);
 });
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_anim.js
@@ -68,14 +68,10 @@ var gTests = [
     yield getStreamAndCheckBackgroundAnim(false, true, "camera");
     yield getStreamAndCheckBackgroundAnim(true, false, "microphone");
   }
 }
 
 ];
 
 add_task(async function test() {
-  let rootDir = getRootDirectory(gTestPath);
-  rootDir = rootDir.replace("chrome://mochitests/content/",
-                            "https://example.com/");
-
-  await runTests(gTests, rootDir + "get_user_media.html");
+  await runTests(gTests);
 });
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_in_frame.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_in_frame.js
@@ -214,10 +214,10 @@ var gTests = [
 
 add_task(async function test() {
   let rootDir = getRootDirectory(gTestPath);
   rootDir = rootDir.replace("chrome://mochitests/content/",
                             "https://example.com/");
   let url = rootDir + "get_user_media.html";
   let testUrl = `data:text/html,<iframe id="frame1" src="${url}"></iframe><iframe id="frame2" src="${url}"></iframe>`
 
-  await runTests(gTests, testUrl, () => expectNoObserverCalled());
+  await runTests(gTests, { absoluteURI: testUrl });
 });
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_multi_process.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_multi_process.js
@@ -110,13 +110,10 @@ var gTests = [
     ok(!webrtcUI.showGlobalIndicator, "webrtcUI wants the global indicator hidden");
     is(webrtcUI.getActiveStreams(true, true, true).length, 0, "0 active streams");
   }
 },
 
 ];
 
 add_task(async function test() {
-  let rootDir = getRootDirectory(gTestPath);
-  rootDir = rootDir.replace("chrome://mochitests/content/",
-                            "https://example.com/");
-  await runTests(gTests, rootDir + "get_user_media.html");
+  await runTests(gTests);
 });
--- 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
@@ -569,13 +569,10 @@ var gTests = [
     yield expectObserverCalled("recording-window-ended");
     SitePermissions.remove(uri, "screen", browser);
   }
 }
 
 ];
 
 add_task(async function test() {
-  let rootDir = getRootDirectory(gTestPath);
-  rootDir = rootDir.replace("chrome://mochitests/content/",
-                            "https://example.com/");
-  await runTests(gTests, rootDir + "get_user_media.html", () => expectNoObserverCalled());
+  await runTests(gTests);
 });
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_tear_off_tab.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_tear_off_tab.js
@@ -60,18 +60,14 @@ var gTests = [
 
 add_task(async function test() {
   await SpecialPowers.pushPrefEnv({"set": [["dom.ipc.processCount", 1]]});
 
   // An empty tab where we can load the content script without leaving it
   // behind at the end of the test.
   let tab = gBrowser.addTab();
 
-  let rootDir = getRootDirectory(gTestPath);
-  rootDir = rootDir.replace("chrome://mochitests/content/",
-                            "https://example.com/");
-
   // NB: This causes withNewTab to warn that we already closed the tab. That
   // doesn't cause the test to fail, so that's OK.
-  await runTests(gTests, rootDir + "get_user_media.html", () => expectNoObserverCalled());
+  await runTests(gTests);
 
   await BrowserTestUtils.removeTab(tab);
 });
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access.js
@@ -243,13 +243,10 @@ var gTests = [
     // close all streams
     yield closeStream(false, 0, 2);
   }
 }
 
 ];
 
 add_task(async function test() {
-  let rootDir = getRootDirectory(gTestPath);
-  rootDir = rootDir.replace("chrome://mochitests/content/",
-                            "https://example.com/");
-  await runTests(gTests, rootDir + "get_user_media.html", () => expectNoObserverCalled());
+  await runTests(gTests);
 });
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access_in_frame.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access_in_frame.js
@@ -202,13 +202,10 @@ var gTests = [
     SitePermissions.remove(null, "camera", gBrowser.selectedBrowser);
     SitePermissions.remove(null, "microphone", gBrowser.selectedBrowser);
   }
 }
 
 ];
 
 add_task(async function test() {
-  let rootDir = getRootDirectory(gTestPath);
-  rootDir = rootDir.replace("chrome://mochitests/content/",
-                            "https://example.com/");
-  await runTests(gTests, rootDir + "get_user_media_in_frame.html", () => expectNoObserverCalled());
+  await runTests(gTests, { relativeURI: "get_user_media_in_frame.html" });
 });
--- a/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access_tear_off_tab.js
+++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_unprompted_access_tear_off_tab.js
@@ -54,18 +54,14 @@ var gTests = [
 
 add_task(async function test() {
   await SpecialPowers.pushPrefEnv({"set": [["dom.ipc.processCount", 1]]});
 
   // An empty tab where we can load the content script without leaving it
   // behind at the end of the test.
   let tab = gBrowser.addTab();
 
-  let rootDir = getRootDirectory(gTestPath);
-  rootDir = rootDir.replace("chrome://mochitests/content/",
-                            "https://example.com/");
-
   // NB: This causes withNewTab to warn that we already closed the tab. That
   // doesn't cause the test to fail, so that's OK.
-  await runTests(gTests, rootDir + "get_user_media.html", () => expectNoObserverCalled());
+  await runTests(gTests);
 
   await BrowserTestUtils.removeTab(tab);
 });
--- a/browser/base/content/test/webrtc/browser_webrtc_hooks.js
+++ b/browser/base/content/test/webrtc/browser_webrtc_hooks.js
@@ -318,17 +318,15 @@ var gTests = [
       is(details.origin, ORIGIN, "peer-request-cancel event has correct origin");
 
       webrtcUI.removePeerConnectionBlocker(blocker);
     },
   },
 ];
 
 add_task(async function test() {
-  let rootDir = getRootDirectory(gTestPath);
-  rootDir = rootDir.replace("chrome://mochitests/content",
-                            ORIGIN);
-  await runTests(gTests, rootDir + "get_user_media.html",
-                 () => {
-                   is(webrtcUI.peerConnectionBlockers.size, 0,
-                      "Peer connection blockers list is empty");
+  await runTests(gTests,
+                 { cleanup() {
+                     is(webrtcUI.peerConnectionBlockers.size, 0,
+                        "Peer connection blockers list is empty");
+                   }
                  });
 });
--- a/browser/base/content/test/webrtc/head.js
+++ b/browser/base/content/test/webrtc/head.js
@@ -516,32 +516,40 @@ function promiseReloadFrame(aFrameId) {
            .document
            .getElementById(contentFrameId)
            .contentWindow
            .location
            .reload();
   });
 }
 
-async function runTests(tests, page, testCleanup = null) {
-  await BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" },
+async function runTests(tests, options = {}) {
+  let absoluteURI, cleanup;
+  if (options.absoluteURI) {
+    absoluteURI = options.absoluteURI;
+  } else {
+    let leaf = options.relativeURI || "get_user_media.html";
+
+    let rootDir = getRootDirectory(gTestPath);
+    rootDir = rootDir.replace("chrome://mochitests/content/",
+                              "https://example.com/");
+    absoluteURI = rootDir + leaf;
+  }
+  cleanup = options.cleanup || (() => expectNoObserverCalled());
+
+  await BrowserTestUtils.withNewTab({ gBrowser, url: absoluteURI },
     function* (browser) {
       browser.messageManager.loadFrameScript(CONTENT_SCRIPT_HELPER, true);
 
-      BrowserTestUtils.loadURI(browser, page);
-      yield BrowserTestUtils.browserLoaded(browser);
-
       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");
 
       yield SpecialPowers.pushPrefEnv({"set": [[PREF_PERMISSION_FAKE, true]]});
 
       for (let testCase of tests) {
         info(testCase.desc);
         yield testCase.run(browser);
-        if (testCleanup) {
-          yield testCleanup();
-        }
+        yield cleanup();
       }
     });
 }