Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: toolkit/components/search/tests/xpcshell/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
/*
* Tests covering sending submission URLs for major engines
*/
const SUBMISSION_YES = [
[
"Startpage Test",
"query={searchTerms}",
],
];
const SUBMISSION_NO = [
];
add_setup(async function () {
SearchTestUtils.setRemoteSettingsConfig([
{
identifier: "engine",
},
},
]);
});
async function addAndMakeDefault(name, search_url, search_url_get_params) {
await SearchTestUtils.installSearchExtension({
name,
search_url,
search_url_get_params,
});
let engine = Services.search.getEngineByName(name);
await Services.search.setDefault(
engine,
Ci.nsISearchService.CHANGE_REASON_UNKNOWN
);
return engine;
}
add_task(async function test_submission_url_matching() {
Assert.ok(!Services.search.isInitialized);
let engineInfo;
let engine;
for (let [name, searchURL, searchParams] of SUBMISSION_YES) {
engine = await addAndMakeDefault(name, searchURL, searchParams);
engineInfo = Services.search.getDefaultEngineInfo();
Assert.equal(
engineInfo.defaultSearchEngineData.submissionURL,
(searchURL + "?" + searchParams).replace("{searchTerms}", "")
);
await Services.search.removeEngine(engine);
}
for (let [name, searchURL, searchParams] of SUBMISSION_NO) {
engine = await addAndMakeDefault(name, searchURL, searchParams);
engineInfo = Services.search.getDefaultEngineInfo();
Assert.equal(engineInfo.defaultSearchEngineData.submissionURL, null);
await Services.search.removeEngine(engine);
}
});
add_task(async function test_submission_url_built_in() {
const engine = await Services.search.getEngineById("engine");
await Services.search.setDefault(
engine,
Ci.nsISearchService.CHANGE_REASON_UNKNOWN
);
const engineInfo = Services.search.getDefaultEngineInfo();
Assert.equal(
engineInfo.defaultSearchEngineData.submissionURL,
"Should have given the submission url for a built-in engine."
);
});