Bug 1448531 - Part 2: Make BrowserTestUtils.waitForNewWindow receive parameters object. r=enndeakin
authorTooru Fujisawa <arai_a@mac.com>
Tue, 10 Apr 2018 12:18:35 +0900
changeset 779705 0a6b2d9e232e47cbb718190056576f0bca79c2e5
parent 779704 f344c2aa32c929855c05250e1a58bde0ece1d0b0
child 779706 ab9912ab15f7daf6d0fea0fabdaed1d7b07fce88
push id105836
push userbmo:ato@sny.no
push dateTue, 10 Apr 2018 12:07:22 +0000
reviewersenndeakin
bugs1448531
milestone61.0a1
Bug 1448531 - Part 2: Make BrowserTestUtils.waitForNewWindow receive parameters object. r=enndeakin
browser/base/content/test/contextMenu/browser_contextmenu_linkopen.js
browser/base/content/test/general/browser_new_http_window_opened_from_file_tab.js
browser/base/content/test/popups/browser_popupUI.js
browser/components/extensions/test/browser/browser_ext_windows.js
browser/components/privatebrowsing/test/browser/browser_oa_private_browsing_window.js
browser/components/privatebrowsing/test/browser/browser_privatebrowsing_newtab_from_popup.js
browser/components/sessionstore/test/browser_394759_behavior.js
dom/tests/browser/browser_noopener.js
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
toolkit/components/windowwatcher/test/browser_new_content_window_from_chrome_principal.js
uriloader/exthandler/tests/mochitest/browser_auto_close_window.js
--- a/browser/base/content/test/contextMenu/browser_contextmenu_linkopen.js
+++ b/browser/base/content/test/contextMenu/browser_contextmenu_linkopen.js
@@ -13,25 +13,25 @@ async function activateContextAndWaitFor
   switch (where) {
     case "tab":
       contextMenuItem += "intab";
       openPromise = BrowserTestUtils.waitForNewTab(gBrowser, TEST_LINK, false);
       closeMethod = async (tab) => BrowserTestUtils.removeTab(tab);
       break;
     case "privatewindow":
       contextMenuItem += "private";
-      openPromise = BrowserTestUtils.waitForNewWindow(TEST_LINK).then(win => {
+      openPromise = BrowserTestUtils.waitForNewWindow({url: TEST_LINK}).then(win => {
         ok(PrivateBrowsingUtils.isWindowPrivate(win), "Should have opened a private window.");
         return win;
       });
       closeMethod = async (win) => BrowserTestUtils.closeWindow(win);
       break;
     case "window":
       // No contextMenuItem suffix for normal new windows;
-      openPromise = BrowserTestUtils.waitForNewWindow(TEST_LINK).then(win => {
+      openPromise = BrowserTestUtils.waitForNewWindow({url: TEST_LINK}).then(win => {
         ok(!PrivateBrowsingUtils.isWindowPrivate(win), "Should have opened a normal window.");
         return win;
       });
       closeMethod = async (win) => BrowserTestUtils.closeWindow(win);
       break;
   }
   let contextMenu = document.getElementById("contentAreaContextMenu");
   is(contextMenu.state, "closed", "checking if popup is closed");
--- a/browser/base/content/test/general/browser_new_http_window_opened_from_file_tab.js
+++ b/browser/base/content/test/general/browser_new_http_window_opened_from_file_tab.js
@@ -19,33 +19,33 @@ add_task(async function() {
   // Set pref to open in new window.
   Services.prefs.setIntPref("browser.link.open_newwindow", 2);
   registerCleanupFunction(function() {
     Services.prefs.clearUserPref("browser.link.open_newwindow");
   });
 
   // Open new http window from JavaScript in file:// page and check that we get
   // a new window with the correct page and features.
-  let promiseNewWindow = BrowserTestUtils.waitForNewWindow(TEST_HTTP);
+  let promiseNewWindow = BrowserTestUtils.waitForNewWindow({url: TEST_HTTP});
   await ContentTask.spawn(browser, TEST_HTTP, uri => {
     content.open(uri, "_blank");
   });
   let win = await promiseNewWindow;
   registerCleanupFunction(async function() {
     await BrowserTestUtils.closeWindow(win);
   });
   ok(win, "Check that an http window loaded when using window.open.");
   ok(win.menubar.visible,
      "Check that the menu bar on the new window is visible.");
   ok(win.toolbar.visible,
      "Check that the tool bar on the new window is visible.");
 
   // Open new http window from a link in file:// page and check that we get a
   // new window with the correct page and features.
-  promiseNewWindow = BrowserTestUtils.waitForNewWindow(TEST_HTTP);
+  promiseNewWindow = BrowserTestUtils.waitForNewWindow({url: TEST_HTTP});
   await BrowserTestUtils.synthesizeMouseAtCenter("#linkToExample", {}, browser);
   let win2 = await promiseNewWindow;
   registerCleanupFunction(async function() {
     await BrowserTestUtils.closeWindow(win2);
   });
   ok(win2, "Check that an http window loaded when using link.");
   ok(win2.menubar.visible,
      "Check that the menu bar on the new window is visible.");
--- a/browser/base/content/test/popups/browser_popupUI.js
+++ b/browser/base/content/test/popups/browser_popupUI.js
@@ -1,13 +1,13 @@
 function test() {
   waitForExplicitFinish();
   SpecialPowers.pushPrefEnv({ set: [[ "dom.disable_open_during_load", false ]] });
 
-  let popupOpened = BrowserTestUtils.waitForNewWindow("about:blank");
+  let popupOpened = BrowserTestUtils.waitForNewWindow({url: "about:blank"});
   BrowserTestUtils.openNewForegroundTab(gBrowser,
     "data:text/html,<html><script>popup=open('about:blank','','width=300,height=200')</script>"
   );
   popupOpened.then((win) => testPopupUI(win));
 }
 
 function testPopupUI(win) {
   var doc = win.document;
--- a/browser/components/extensions/test/browser/browser_ext_windows.js
+++ b/browser/components/extensions/test/browser/browser_ext_windows.js
@@ -89,17 +89,17 @@ add_task(async function testWindowTitle(
       permissions: ["tabs"],
     },
   });
 
   await extension.startup();
   let {Management: {global: {windowTracker}}} = ChromeUtils.import("resource://gre/modules/Extension.jsm", {});
 
   async function createApiWin(options) {
-    let promiseLoaded = BrowserTestUtils.waitForNewWindow(START_URL);
+    let promiseLoaded = BrowserTestUtils.waitForNewWindow({url: START_URL});
     extension.sendMessage("create", options);
     let apiWin = await extension.awaitMessage("created");
     let realWin = windowTracker.getWindow(apiWin.id);
     await promiseLoaded;
     let expectedPreface = options.titlePreface ? options.titlePreface : "";
     ok(realWin.document.title.startsWith(expectedPreface),
        "Created window has the expected title preface.");
     ok(realWin.document.title.includes(START_TITLE),
--- a/browser/components/privatebrowsing/test/browser/browser_oa_private_browsing_window.js
+++ b/browser/components/privatebrowsing/test/browser/browser_oa_private_browsing_window.js
@@ -1,17 +1,17 @@
 "use strict";
 
 const PATH = getRootDirectory(gTestPath).replace("chrome://mochitests/content", "http://example.com");
 const TEST_PAGE = PATH + "file_triggeringprincipal_oa.html";
 const DUMMY_PAGE = PATH + "empty_file.html";
 
 add_task(async function test_principal_right_click_open_link_in_new_private_win() {
   await BrowserTestUtils.withNewTab(TEST_PAGE, async function(browser) {
-    let promiseNewWindow = BrowserTestUtils.waitForNewWindow(DUMMY_PAGE);
+    let promiseNewWindow = BrowserTestUtils.waitForNewWindow({url: DUMMY_PAGE});
 
     // simulate right-click open link in new private window
     BrowserTestUtils.waitForEvent(document, "popupshown", false, event => {
       document.getElementById("context-openlinkprivate").doCommand();
       event.target.hidePopup();
       return true;
     });
     BrowserTestUtils.synthesizeMouseAtCenter("#checkPrincipalOA",
--- a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_newtab_from_popup.js
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_newtab_from_popup.js
@@ -35,17 +35,17 @@ add_task(async function test_private_pop
   // First, open a private browsing window, and load our
   // testing page.
   let privBrowser = privWin.gBrowser.selectedBrowser;
   await BrowserTestUtils.loadURI(privBrowser, WINDOW_BODY);
   await BrowserTestUtils.browserLoaded(privBrowser);
 
   // Next, click on the link in the testing page, and ensure
   // that a private popup window is opened.
-  let openedPromise = BrowserTestUtils.waitForNewWindow(POPUP_LINK);
+  let openedPromise = BrowserTestUtils.waitForNewWindow({url: POPUP_LINK});
 
   await BrowserTestUtils.synthesizeMouseAtCenter("#first", {}, privBrowser);
   let popupWin = await openedPromise;
   ok(PrivateBrowsingUtils.isWindowPrivate(popupWin),
      "Popup window was private.");
 
   // Now click on the link in the popup, and ensure that a new
   // tab is opened in the original private browsing window.
--- a/browser/components/sessionstore/test/browser_394759_behavior.js
+++ b/browser/components/sessionstore/test/browser_394759_behavior.js
@@ -21,17 +21,17 @@
  */
 function testWindows(windowsToOpen, expectedResults) {
   return (async function() {
     for (let winData of windowsToOpen) {
       let features = "chrome,dialog=no," +
                      (winData.isPopup ? "all=no" : "all");
       let url = "http://example.com/?window=" + windowsToOpen.length;
 
-      let openWindowPromise = BrowserTestUtils.waitForNewWindow(url);
+      let openWindowPromise = BrowserTestUtils.waitForNewWindow({url});
       openDialog(getBrowserURL(), "", features, url);
       let win = await openWindowPromise;
       await BrowserTestUtils.closeWindow(win);
     }
 
     let closedWindowData = JSON.parse(ss.getClosedWindowData());
     let numPopups = closedWindowData.filter(function(el, i, arr) {
       return el.isPopup;
--- a/dom/tests/browser/browser_noopener.js
+++ b/dom/tests/browser/browser_noopener.js
@@ -39,17 +39,17 @@ async function doTests(private, containe
   for (let test of TESTS) {
     const testid = `${test.id} (private=${private}, container=${container}, alwaysNewWindow=${alwaysNewWindow})`;
     let originalTab = BrowserTestUtils.addTab(window.gBrowser, TEST_URL, tabOpenOptions);
     await BrowserTestUtils.browserLoaded(originalTab.linkedBrowser);
     await BrowserTestUtils.switchTab(window.gBrowser, originalTab);
 
     let waitFor;
     if (test.newWindow || alwaysNewWindow) {
-      waitFor = BrowserTestUtils.waitForNewWindow(TARGET_URL);
+      waitFor = BrowserTestUtils.waitForNewWindow({url: TARGET_URL});
       // Confirm that this window has private browsing set if we're doing a private browsing test
     } else {
       waitFor = BrowserTestUtils.waitForNewTab(window.gBrowser, TARGET_URL, true);
     }
 
     BrowserTestUtils.synthesizeMouseAtCenter(test.id, {}, window.gBrowser.getBrowserForTab(originalTab));
 
     let tab;
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -475,48 +475,54 @@ var BrowserTestUtils = {
       };
       tabbrowser.addTabsProgressListener(progressListener);
     });
   },
 
   /**
    * Waits for the next browser window to open and be fully loaded.
    *
-   * @param {string} initialBrowserLoaded (optional)
-   *        If set, we will wait until the initial browser in the new
-   *        window has loaded a particular page. If unset, the initial
-   *        browser may or may not have finished loading its first page
-   *        when the resulting Promise resolves.
+   * @param aParams
+   *        {
+   *          url: A string (optional). If set, we will wait until the initial
+   *               browser in the new window has loaded a particular page.
+   *               If unset, the initial browser may or may not have finished
+   *               loading its first page when the resulting Promise resolves.
+   *        }
    * @return {Promise}
    *         A Promise which resolves the next time that a DOM window
    *         opens and the delayed startup observer notification fires.
    */
-  async waitForNewWindow(initialBrowserLoaded=null) {
+  async waitForNewWindow(aParams = {}) {
+    let {
+      url = null,
+    } = aParams;
+
     let win = await this.domWindowOpened();
 
     let promises = [
       TestUtils.topicObserved("browser-delayed-startup-finished",
                               subject => subject == win),
     ];
 
-    if (initialBrowserLoaded) {
+    if (url) {
       await this.waitForEvent(win, "DOMContentLoaded");
 
       let browser = win.gBrowser.selectedBrowser;
 
       // Retrieve the given browser's current process type.
       let process =
         browser.isRemoteBrowser ? Ci.nsIXULRuntime.PROCESS_TYPE_CONTENT
                                 : Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
       if (win.gMultiProcessBrowser &&
-          !E10SUtils.canLoadURIInProcess(initialBrowserLoaded, process)) {
+          !E10SUtils.canLoadURIInProcess(url, process)) {
         await this.waitForEvent(browser, "XULFrameLoaderCreated");
       }
 
-      let loadPromise = this.browserLoaded(browser, false, initialBrowserLoaded);
+      let loadPromise = this.browserLoaded(browser, false, url);
       promises.push(loadPromise);
     }
 
     await Promise.all(promises);
 
     return win;
   },
 
--- a/toolkit/components/windowwatcher/test/browser_new_content_window_from_chrome_principal.js
+++ b/toolkit/components/windowwatcher/test/browser_new_content_window_from_chrome_principal.js
@@ -8,17 +8,17 @@
 add_task(async function test_chrome_opens_window() {
   // This magic value of 2 means that by default, when content tries
   // to open a new window, it'll actually open in a new window instead
   // of a new tab.
   await SpecialPowers.pushPrefEnv({"set": [
     ["browser.link.open_newwindow", 2],
   ]});
 
-  let newWinPromise = BrowserTestUtils.waitForNewWindow("http://example.com/");
+  let newWinPromise = BrowserTestUtils.waitForNewWindow({url: "http://example.com/"});
 
   await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
     content.open("http://example.com/", "_blank");
   });
 
   let win = await newWinPromise;
   let browser = win.gBrowser.selectedBrowser;
 
--- a/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js
+++ b/uriloader/exthandler/tests/mochitest/browser_auto_close_window.js
@@ -87,17 +87,17 @@ add_task(async function target_blank() {
 
 add_task(async function new_window() {
   // Tests that a link that forces us to open a new window (by specifying a
   // width and a height in window.open) opens a new window for the load,
   // realizes that we need to close that window and returns the *original*
   // window as the window context.
   await BrowserTestUtils.withNewTab({ gBrowser, url: URL }, async function(browser) {
     let dialogAppeared = promiseHelperAppDialog();
-    let windowOpened = BrowserTestUtils.waitForNewWindow(false);
+    let windowOpened = BrowserTestUtils.waitForNewWindow();
 
     await BrowserTestUtils.synthesizeMouseAtCenter("#new_window", {}, browser);
 
     let windowContext = await dialogAppeared;
     is(windowContext.gBrowser.selectedBrowser.currentURI.spec, URL,
        "got the right windowContext");
     let win = await windowOpened;