Bug 1249332 - [e10s] Make browser_ContentSearch.js work under e10s. r=mak
authorDrew Willcoxon <adw@mozilla.com>
Mon, 22 Feb 2016 15:18:12 -0800
changeset 321672 f587e62973847f5e8305e5961bce401a4d9fa5ba
parent 321671 f184bfcbbc460851820579855b40d64ac621384c
child 321673 a951d792d9b008a7361233b6c71fbea29848ccb2
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs1249332
milestone47.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 1249332 - [e10s] Make browser_ContentSearch.js work under e10s. r=mak
browser/modules/test/browser.ini
browser/modules/test/browser_ContentSearch.js
browser/modules/test/contentSearch.js
--- a/browser/modules/test/browser.ini
+++ b/browser/modules/test/browser.ini
@@ -1,17 +1,16 @@
 [DEFAULT]
 support-files =
   head.js
 
 [browser_BrowserUITelemetry_buckets.js]
 [browser_ProcessHangNotifications.js]
 skip-if = !e10s
 [browser_ContentSearch.js]
-skip-if = e10s
 support-files =
   contentSearch.js
   contentSearchBadImage.xml
   contentSearchSuggestions.sjs
   contentSearchSuggestions.xml
 [browser_NetworkPrioritizer.js]
 skip-if = e10s # Bug 666804 - Support NetworkPrioritizer in e10s
 [browser_SelfSupportBackend.js]
--- a/browser/modules/test/browser_ContentSearch.js
+++ b/browser/modules/test/browser_ContentSearch.js
@@ -92,51 +92,55 @@ add_task(function* search() {
   yield addTab();
   let engine = Services.search.currentEngine;
   let data = {
     engineName: engine.name,
     searchString: "ContentSearchTest",
     healthReportKey: "ContentSearchTest",
     searchPurpose: "ContentSearchTest",
   };
+  let submissionURL =
+    engine.getSubmission(data.searchString, "", data.whence).uri.spec;
   gMsgMan.sendAsyncMessage(TEST_MSG, {
     type: "Search",
     data: data,
+    expectedURL: submissionURL,
   });
-  let submissionURL =
-    engine.getSubmission(data.searchString, "", data.whence).uri.spec;
-  yield waitForLoadAndStopIt(gBrowser.selectedBrowser, submissionURL);
+  let msg = yield waitForTestMsg("loadStopped");
+  Assert.equal(msg.data.url, submissionURL, "Correct search page loaded");
 });
 
 add_task(function* searchInBackgroundTab() {
   // This test is like search(), but it opens a new tab after starting a search
   // in another.  In other words, it performs a search in a background tab.  The
   // search page should be loaded in the same tab that performed the search, in
   // the background tab.
   yield addTab();
   let searchBrowser = gBrowser.selectedBrowser;
   let engine = Services.search.currentEngine;
   let data = {
     engineName: engine.name,
     searchString: "ContentSearchTest",
     healthReportKey: "ContentSearchTest",
     searchPurpose: "ContentSearchTest",
   };
+  let submissionURL =
+    engine.getSubmission(data.searchString, "", data.whence).uri.spec;
   gMsgMan.sendAsyncMessage(TEST_MSG, {
     type: "Search",
     data: data,
+    expectedURL: submissionURL,
   });
 
   let newTab = gBrowser.addTab();
   gBrowser.selectedTab = newTab;
   registerCleanupFunction(() => gBrowser.removeTab(newTab));
 
-  let submissionURL =
-    engine.getSubmission(data.searchString, "", data.whence).uri.spec;
-  yield waitForLoadAndStopIt(searchBrowser, submissionURL);
+  let msg = yield waitForTestMsg("loadStopped");
+  Assert.equal(msg.data.url, submissionURL, "Correct search page loaded");
 });
 
 add_task(function* badImage() {
   yield addTab();
   // If the bad image URI caused an exception to be thrown within ContentSearch,
   // then we'll hang waiting for the CurrentState responses triggered by the new
   // engine.  That's what we're testing, and obviously it shouldn't happen.
   let vals = yield waitForNewEngine("contentSearchBadImage.xml", 1);
@@ -326,43 +330,16 @@ function waitForNewEngine(basename, numI
       ok(false, "addEngine failed with error code " + errCode);
       addDeferred.reject();
     },
   });
 
   return Promise.all([addDeferred.promise].concat(eventPromises));
 }
 
-function waitForLoadAndStopIt(browser, expectedURL) {
-  let deferred = Promise.defer();
-  let listener = {
-    onStateChange: function (webProg, req, flags, status) {
-      if (req instanceof Ci.nsIChannel) {
-        let url = req.originalURI.spec;
-        info("onStateChange " + url);
-        let docStart = Ci.nsIWebProgressListener.STATE_IS_DOCUMENT |
-                       Ci.nsIWebProgressListener.STATE_START;
-        if ((flags & docStart) && webProg.isTopLevel && url == expectedURL) {
-          browser.removeProgressListener(listener);
-          ok(true, "Expected URL loaded");
-          req.cancel(Components.results.NS_ERROR_FAILURE);
-          deferred.resolve();
-        }
-      }
-    },
-    QueryInterface: XPCOMUtils.generateQI([
-      Ci.nsIWebProgressListener,
-      Ci.nsISupportsWeakReference,
-    ]),
-  };
-  browser.addProgressListener(listener);
-  info("Waiting for URL to load: " + expectedURL);
-  return deferred.promise;
-}
-
 function addTab() {
   let deferred = Promise.defer();
   let tab = gBrowser.addTab();
   gBrowser.selectedTab = tab;
   tab.linkedBrowser.addEventListener("load", function load() {
     tab.linkedBrowser.removeEventListener("load", load, true);
     let url = getRootDirectory(gTestPath) + TEST_CONTENT_SCRIPT_BASENAME;
     gMsgMan = tab.linkedBrowser.messageManager;
--- a/browser/modules/test/contentSearch.js
+++ b/browser/modules/test/contentSearch.js
@@ -18,9 +18,47 @@ content.addEventListener(SERVICE_EVENT_T
 
 // Forward messages from the test to the in-content service.
 addMessageListener(TEST_MSG, msg => {
   content.dispatchEvent(
     new content.CustomEvent(CLIENT_EVENT_TYPE, {
       detail: msg.data,
     })
   );
+
+  // If the message is a search, stop the page from loading and then tell the
+  // test that it loaded.
+  if (msg.data.type == "Search") {
+    waitForLoadAndStopIt(msg.data.expectedURL, url => {
+      sendAsyncMessage(TEST_MSG, {
+        type: "loadStopped",
+        url: url,
+      });
+    });
+  }
 });
+
+function waitForLoadAndStopIt(expectedURL, callback) {
+  let Ci = Components.interfaces;
+  let webProgress = docShell.QueryInterface(Ci.nsIInterfaceRequestor)
+                            .getInterface(Ci.nsIWebProgress);
+  let listener = {
+    onStateChange: function (webProg, req, flags, status) {
+      if (req instanceof Ci.nsIChannel) {
+        let url = req.originalURI.spec;
+        dump("waitForLoadAndStopIt: onStateChange " + url + "\n");
+        let docStart = Ci.nsIWebProgressListener.STATE_IS_DOCUMENT |
+                       Ci.nsIWebProgressListener.STATE_START;
+        if ((flags & docStart) && webProg.isTopLevel && url == expectedURL) {
+          webProgress.removeProgressListener(listener);
+          req.cancel(Components.results.NS_ERROR_FAILURE);
+          callback(url);
+        }
+      }
+    },
+    QueryInterface: XPCOMUtils.generateQI([
+      Ci.nsIWebProgressListener,
+      Ci.nsISupportsWeakReference,
+    ]),
+  };
+  webProgress.addProgressListener(listener, Ci.nsIWebProgress.NOTIFY_ALL);
+  dump("waitForLoadAndStopIt: Waiting for URL to load: " + expectedURL + "\n");
+}