From 13b82bd15ebf12ee21898bd1a26aa8eff1f531ff Mon Sep 17 00:00:00 2001 From: Drew Willcoxon Date: Mon, 22 Feb 2016 15:18:12 -0800 Subject: [PATCH] Bug 1249332 - [e10s] Make browser_ContentSearch.js work under e10s. r=mak --- browser/modules/test/browser.ini | 1 - browser/modules/test/browser_ContentSearch.js | 43 +++++-------------- browser/modules/test/contentSearch.js | 36 ++++++++++++++++ 3 files changed, 46 insertions(+), 34 deletions(-) diff --git a/browser/modules/test/browser.ini b/browser/modules/test/browser.ini index 18020a611f87..bc8eaf7b8799 100644 --- a/browser/modules/test/browser.ini +++ b/browser/modules/test/browser.ini @@ -6,7 +6,6 @@ support-files = [browser_ProcessHangNotifications.js] skip-if = !e10s [browser_ContentSearch.js] -skip-if = e10s support-files = contentSearch.js contentSearchBadImage.xml diff --git a/browser/modules/test/browser_ContentSearch.js b/browser/modules/test/browser_ContentSearch.js index 5a154d9aa9a3..f7c6ecca8c91 100644 --- a/browser/modules/test/browser_ContentSearch.js +++ b/browser/modules/test/browser_ContentSearch.js @@ -97,13 +97,15 @@ add_task(function* search() { 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() { @@ -120,18 +122,20 @@ add_task(function* searchInBackgroundTab() { 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() { @@ -331,33 +335,6 @@ function waitForNewEngine(basename, numImages) { 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(); diff --git a/browser/modules/test/contentSearch.js b/browser/modules/test/contentSearch.js index c6bcd17d4cc7..4f6e2c181755 100644 --- a/browser/modules/test/contentSearch.js +++ b/browser/modules/test/contentSearch.js @@ -23,4 +23,40 @@ addMessageListener(TEST_MSG, msg => { 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 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) { + docShell.removeProgressListener(listener); + req.cancel(Components.results.NS_ERROR_FAILURE); + callback(url); + } + } + }, + QueryInterface: XPCOMUtils.generateQI([ + Ci.nsIWebProgressListener, + Ci.nsISupportsWeakReference, + ]), + }; + docShell.addProgressListener(listener, Ci.nsIWebProgress.NOTIFY_ALL); + dump("waitForLoadAndStopIt: Waiting for URL to load: " + expectedURL + "\n"); +}