mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-11 16:32:59 +00:00
Bug 1096534 - ContentSearch should load the search URL in the tab sending the search message, not the current tab. r=mak
This commit is contained in:
parent
aa4d9dead9
commit
d803d09a32
@ -205,11 +205,23 @@ this.ContentSearch = {
|
||||
"searchString",
|
||||
"whence",
|
||||
]);
|
||||
let browserWin = msg.target.ownerDocument.defaultView;
|
||||
let engine = Services.search.getEngineByName(data.engineName);
|
||||
browserWin.BrowserSearch.recordSearchInHealthReport(engine, data.whence, data.selection);
|
||||
let submission = engine.getSubmission(data.searchString, "", data.whence);
|
||||
browserWin.loadURI(submission.uri.spec, null, submission.postData);
|
||||
let browser = msg.target;
|
||||
try {
|
||||
browser.loadURIWithFlags(submission.uri.spec,
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_NONE, null, null,
|
||||
submission.postData);
|
||||
}
|
||||
catch (err) {
|
||||
// The browser may have been closed between the time its content sent the
|
||||
// message and the time we handle it. In that case, trying to call any
|
||||
// method on it will throw.
|
||||
return Promise.resolve();
|
||||
}
|
||||
let win = browser.ownerDocument.defaultView;
|
||||
win.BrowserSearch.recordSearchInHealthReport(engine, data.whence,
|
||||
data.selection || null);
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
|
@ -102,24 +102,34 @@ add_task(function* search() {
|
||||
});
|
||||
let submissionURL =
|
||||
engine.getSubmission(data.searchString, "", data.whence).uri.spec;
|
||||
let deferred = Promise.defer();
|
||||
let listener = {
|
||||
onStateChange: function (webProg, req, flags, status) {
|
||||
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 == submissionURL) {
|
||||
gBrowser.removeProgressListener(listener);
|
||||
ok(true, "Search URL loaded");
|
||||
req.cancel(Components.results.NS_ERROR_FAILURE);
|
||||
deferred.resolve();
|
||||
}
|
||||
}
|
||||
yield waitForLoadAndStopIt(gBrowser.selectedBrowser, submissionURL);
|
||||
});
|
||||
|
||||
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",
|
||||
whence: "ContentSearchTest",
|
||||
};
|
||||
gBrowser.addProgressListener(listener);
|
||||
info("Waiting for search URL to load: " + submissionURL);
|
||||
yield deferred.promise;
|
||||
gMsgMan.sendAsyncMessage(TEST_MSG, {
|
||||
type: "Search",
|
||||
data: data,
|
||||
});
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
add_task(function* badImage() {
|
||||
@ -319,6 +329,33 @@ 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();
|
||||
|
Loading…
Reference in New Issue
Block a user