Bug 1100291 - Make browser/base/content/test/general/browser_urlbarStop.js work with an async getShortcutOrURIAndPostData() and prepare it for e10s r=dao
authorTim Taubert <ttaubert@mozilla.com>
Fri, 06 Mar 2015 19:45:42 +0100
changeset 265858 51ca14f617a6e5fb575818e2e7fe066909799ab8
parent 265857 4756d973a34c53bf51b42fee3aebcd672c3dcf2b
child 265859 cd52056697d5e3538e64e4e689f0ae1df22dd58b
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1100291
milestone39.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 1100291 - Make browser/base/content/test/general/browser_urlbarStop.js work with an async getShortcutOrURIAndPostData() and prepare it for e10s r=dao
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_urlbarStop.js
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -447,17 +447,16 @@ skip-if = e10s # Bug 1093941 - Waits ind
 [browser_urlbarEnter.js]
 skip-if = e10s # Bug 1093941 - used to cause obscure non-windows child process crashes on try
 [browser_urlbarEnterAfterMouseOver.js]
 skip-if = os == "linux" || e10s # Bug 1073339 - Investigate autocomplete test unreliability on Linux/e10s
 [browser_urlbarRevert.js]
 skip-if = e10s # Bug 1093941 - ESC reverted the location bar value - Got foobar, expected example.com
 [browser_urlbarSearchSingleWordNotification.js]
 [browser_urlbarStop.js]
-skip-if = e10s # Bug 1093941 - test calls gBrowser.contentWindow.stop
 [browser_urlbarTrimURLs.js]
 [browser_urlbar_search_healthreport.js]
 [browser_utilityOverlay.js]
 [browser_visibleFindSelection.js]
 skip-if = e10s # Bug 921935 - focusmanager issues with e10s (test calls waitForFocus)
 [browser_visibleLabel.js]
 [browser_visibleTabs.js]
 [browser_visibleTabs_bookmarkAllPages.js]
--- a/browser/base/content/test/general/browser_urlbarStop.js
+++ b/browser/base/content/test/general/browser_urlbarStop.js
@@ -1,40 +1,69 @@
+"use strict";
+
 const goodURL = "http://mochi.test:8888/";
 const badURL = "http://mochi.test:8888/whatever.html";
 
-function test() {
-  waitForExplicitFinish();
-
+add_task(function* () {
   gBrowser.selectedTab = gBrowser.addTab(goodURL);
-  gBrowser.selectedBrowser.addEventListener("load", onload, true);
-}
-
-function onload() {
-  gBrowser.selectedBrowser.removeEventListener("load", onload, true);
-
+  yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
   is(gURLBar.textValue, gURLBar.trimValue(goodURL), "location bar reflects loaded page");
 
-  typeAndSubmit(badURL);
-  is(gURLBar.textValue, gURLBar.trimValue(badURL), "location bar reflects loading page");
-
-  gBrowser.contentWindow.stop();
+  yield typeAndSubmitAndStop(badURL);
   is(gURLBar.textValue, gURLBar.trimValue(goodURL), "location bar reflects loaded page after stop()");
   gBrowser.removeCurrentTab();
 
   gBrowser.selectedTab = gBrowser.addTab("about:blank");
   is(gURLBar.textValue, "", "location bar is empty");
 
-  typeAndSubmit(badURL);
-  is(gURLBar.textValue, gURLBar.trimValue(badURL), "location bar reflects loading page");
-
-  gBrowser.contentWindow.stop();
+  yield typeAndSubmitAndStop(badURL);
   is(gURLBar.textValue, gURLBar.trimValue(badURL), "location bar reflects stopped page in an empty tab");
   gBrowser.removeCurrentTab();
+});
 
-  finish();
+function typeAndSubmitAndStop(url) {
+  gBrowser.userTypedValue = url;
+  URLBarSetURI();
+  is(gURLBar.textValue, gURLBar.trimValue(url), "location bar reflects loading page");
+
+  let promise = waitForDocLoadAndStopIt();
+  gURLBar.handleCommand();
+  return promise;
 }
 
-function typeAndSubmit(value) {
-  gBrowser.userTypedValue = value;
-  URLBarSetURI();
-  gURLBar.handleCommand();
+function waitForDocLoadAndStopIt() {
+  function content_script() {
+    const {interfaces: Ci, utils: Cu} = Components;
+    Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+
+    let progressListener = {
+      onStateChange(webProgress, req, flags, status) {
+        if (flags & Ci.nsIWebProgressListener.STATE_START) {
+          wp.removeProgressListener(progressListener);
+
+          /* Hammer time. */
+          content.stop();
+
+          /* Let the parent know we're done. */
+          sendAsyncMessage("{MSG}");
+        }
+      },
+
+      QueryInterface: XPCOMUtils.generateQI(["nsISupportsWeakReference"])
+    };
+
+    let wp = docShell.QueryInterface(Ci.nsIWebProgress);
+    wp.addProgressListener(progressListener, wp.NOTIFY_ALL);
+  }
+
+  return new Promise(resolve => {
+    const MSG = "test:waitForDocLoadAndStopIt";
+    const SCRIPT = content_script.toString().replace("{MSG}", MSG);
+
+    let mm = gBrowser.selectedBrowser.messageManager;
+    mm.loadFrameScript("data:,(" + SCRIPT + ")();", true);
+    mm.addMessageListener(MSG, function onComplete() {
+      mm.removeMessageListener(MSG, onComplete);
+      resolve();
+    });
+  });
 }