2014-06-19 22:22:45 +04:00
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
2015-03-06 18:37:26 +03:00
|
|
|
"use strict";
|
2014-06-19 22:22:45 +04:00
|
|
|
|
|
|
|
const kSearchEngineID = "browser_urifixup_search_engine";
|
|
|
|
const kSearchEngineURL = "http://example.com/?search={searchTerms}";
|
|
|
|
|
2015-03-06 18:37:26 +03:00
|
|
|
add_task(function* setup() {
|
|
|
|
// Add a new fake search engine.
|
|
|
|
Services.search.addEngineWithDetails(kSearchEngineID, "", "", "", "get",
|
|
|
|
kSearchEngineURL);
|
2014-06-19 22:22:45 +04:00
|
|
|
|
2015-03-06 18:37:26 +03:00
|
|
|
let oldDefaultEngine = Services.search.defaultEngine;
|
|
|
|
Services.search.defaultEngine = Services.search.getEngineByName(kSearchEngineID);
|
2014-06-19 22:22:45 +04:00
|
|
|
|
2015-03-06 18:37:26 +03:00
|
|
|
// Remove the fake engine when done.
|
|
|
|
registerCleanupFunction(() => {
|
|
|
|
if (oldDefaultEngine) {
|
|
|
|
Services.search.defaultEngine = oldDefaultEngine;
|
|
|
|
}
|
2014-06-19 22:22:45 +04:00
|
|
|
|
2015-03-06 18:37:26 +03:00
|
|
|
let engine = Services.search.getEngineByName(kSearchEngineID);
|
|
|
|
if (engine) {
|
|
|
|
Services.search.removeEngine(engine);
|
|
|
|
}
|
2014-06-19 22:22:45 +04:00
|
|
|
});
|
2015-03-06 18:37:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
add_task(function* test() {
|
|
|
|
for (let searchParams of ["foo bar", "brokenprotocol:somethingelse"]) {
|
|
|
|
// Add a new blank tab.
|
|
|
|
gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
|
|
|
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
2014-06-19 22:22:45 +04:00
|
|
|
|
2015-03-06 18:37:26 +03:00
|
|
|
// Enter search terms and start a search.
|
|
|
|
gURLBar.value = searchParams;
|
2014-06-19 22:22:45 +04:00
|
|
|
gURLBar.focus();
|
|
|
|
EventUtils.synthesizeKey("VK_RETURN", {});
|
2015-03-06 18:37:26 +03:00
|
|
|
yield BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
|
2014-06-19 22:22:45 +04:00
|
|
|
|
2015-03-06 18:37:26 +03:00
|
|
|
// Check that we arrived at the correct URL.
|
|
|
|
let escapedParams = encodeURIComponent(searchParams).replace("%20", "+");
|
|
|
|
let expectedURL = kSearchEngineURL.replace("{searchTerms}", escapedParams);
|
|
|
|
is(gBrowser.selectedBrowser.currentURI.spec, expectedURL,
|
|
|
|
"New tab should have loaded with expected url.");
|
2014-06-19 22:22:45 +04:00
|
|
|
|
2015-03-06 18:37:26 +03:00
|
|
|
// Cleanup.
|
|
|
|
gBrowser.removeCurrentTab();
|
2014-06-19 22:22:45 +04:00
|
|
|
}
|
|
|
|
});
|