Bug 890690: added unit test for POST search engines in about:home, r=gavin

--HG--
extra : transplant_source : %B0%16%95/%08%1B5%A4%BC%B9U%F4x%D5%92%BED%B3%CC%AF
This commit is contained in:
Mike de Boer 2013-07-25 02:15:54 +02:00
parent bb48df9ad1
commit 8ecbcfc2a9

View File

@ -242,10 +242,12 @@ let gTests = [
promiseBrowserAttributes(gBrowser.selectedTab).then(function() {
// Test if the update propagated
checkSearchUI(unusedEngines[0]);
searchbar.currentEngine = currEngine;
deferred.resolve();
});
// The following cleanup function will set currentEngine back to the previous engine
// The following cleanup function will set currentEngine back to the previous
// engine if we fail to do so above.
registerCleanupFunction(function() {
searchbar.currentEngine = currEngine;
});
@ -254,6 +256,60 @@ let gTests = [
searchbar.select();
return deferred.promise;
}
},
{
desc: "Check POST search engine support",
setup: function() {},
run: function()
{
let deferred = Promise.defer();
let currEngine = Services.search.defaultEngine;
let searchObserver = function search_observer(aSubject, aTopic, aData) {
let engine = aSubject.QueryInterface(Ci.nsISearchEngine);
info("Observer: " + aData + " for " + engine.name);
if (aData != "engine-added")
return;
if (engine.name != "POST Search")
return;
Services.search.defaultEngine = engine;
registerCleanupFunction(function() {
Services.search.removeEngine(engine);
Services.search.defaultEngine = currEngine;
});
let needle = "Search for something awesome.";
// Ready to execute the tests!
promiseBrowserAttributes(gBrowser.selectedTab).then(function() {
let document = gBrowser.selectedTab.linkedBrowser.contentDocument;
let searchText = document.getElementById("searchText");
waitForLoad(function() {
let loadedText = gBrowser.contentDocument.body.textContent;
ok(loadedText, "search page loaded");
is(loadedText, "searchterms=" + escape(needle.replace(/\s/g, "+")),
"Search text should arrive correctly");
deferred.resolve();
});
searchText.value = needle;
searchText.focus();
EventUtils.synthesizeKey("VK_RETURN", {});
});
};
Services.obs.addObserver(searchObserver, "browser-search-engine-modified", false);
registerCleanupFunction(function () {
Services.obs.removeObserver(searchObserver, "browser-search-engine-modified");
});
Services.search.addEngine("http://test:80/browser/browser/base/content/test/POSTSearchEngine.xml",
Ci.nsISearchEngine.DATA_XML, null, false);
return deferred.promise;
}
}
];
@ -442,3 +498,15 @@ function getNumberOfSearchesByDate(aEngineName, aData, aDate) {
return 0; // No records found.
}
function waitForLoad(cb) {
let browser = gBrowser.selectedBrowser;
browser.addEventListener("load", function listener() {
if (browser.currentURI.spec == "about:blank")
return;
info("Page loaded: " + browser.currentURI.spec);
browser.removeEventListener("load", listener, true);
cb();
}, true);
}