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
--- 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}