Bug 1397365: Part 1 - Make BrowserTestUtils.openNewBrowserWindow load an empty document into it by default. r?mconley draft
authorZibi Braniecki <zbraniecki@mozilla.com>
Wed, 13 Sep 2017 00:52:40 -0700
changeset 664675 7a09b2447e56a5a8e270136eeb7a14cdb39f3a92
parent 664674 13411e618c40811d8679f3318be9ae1533977088
child 664676 ee0c47ed060f985a351e1777dfb08adf4a740a7a
push id79760
push userbmo:gandalf@aviary.pl
push dateThu, 14 Sep 2017 08:02:46 +0000
reviewersmconley
bugs1397365
milestone57.0a1
Bug 1397365: Part 1 - Make BrowserTestUtils.openNewBrowserWindow load an empty document into it by default. r?mconley Most mochitests have been written with an assumption that every new window has a document loaded in its first tab by default. Since we're removing that assumption, this patch adds the behavior to the test API. MozReview-Commit-ID: L9Obsx32CHv
testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
--- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
+++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm
@@ -595,23 +595,24 @@ this.BrowserTestUtils = {
    *          private: A boolean indicating if the window should be
    *                   private
    *          remote:  A boolean indicating if the window should run
    *                   remote browser tabs or not. If omitted, the window
    *                   will choose the profile default state.
    *          width: Desired width of window
    *          height: Desired height of window
    *        }
+   * @param {String} url: Default URL to be loaded
    * @return {Promise}
    *         Resolves with the new window once it is loaded.
    */
-  async openNewBrowserWindow(options={}) {
+  async openNewBrowserWindow(options={}, url="data:text/html,<html></html>") {
     let argString = Cc["@mozilla.org/supports-string;1"].
                     createInstance(Ci.nsISupportsString);
-    argString.data = "";
+    argString.data = url;
     let features = "chrome,dialog=no,all";
     let opener = null;
 
     if (options.opener) {
       opener = options.opener;
     }
 
     if (options.private) {
@@ -640,24 +641,22 @@ this.BrowserTestUtils = {
 
     let win = Services.ww.openWindow(
       opener, Services.prefs.getCharPref("browser.chromeURL"), "_blank",
       features, argString);
 
     // Wait for browser-delayed-startup-finished notification, it indicates
     // that the window has loaded completely and is ready to be used for
     // testing.
-    let startupPromise =
-      TestUtils.topicObserved("browser-delayed-startup-finished",
-                              subject => subject == win).then(() => win);
+    await  TestUtils.topicObserved("browser-delayed-startup-finished",
+                                   subject => subject == win).then(() => win);
 
-    let loadPromise = this.firstBrowserLoaded(win);
-
-    await startupPromise;
-    await loadPromise;
+    if (url) {
+      await this.firstBrowserLoaded(win);
+    }
 
     return win;
   },
 
   /**
    * Closes a window.
    *
    * @param {Window}