Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: browser/components/urlbar/tests/unit/xpcshell.toml
/*
* This test checks we can determine the type of search page and whether the
* page is a default search page.
*/
ChromeUtils.defineESModuleGetters(this, {
UrlbarSearchTermsPersistence:
"resource:///modules/UrlbarSearchTermsPersistence.sys.mjs",
});
const PROVIDERS = [
{
id: "example",
queryParamNames: ["q"],
includeParams: [
{
key: "page",
values: ["web"],
canBeMissing: true,
},
],
excludeParams: [
{
key: "excludeKey",
values: ["hello"],
},
],
},
{
id: "example2",
queryParamNames: ["q"],
includeParams: [
{
key: "page",
values: ["web"],
canBeMissing: false,
},
],
excludeParams: [
{
key: "excludeKey",
},
],
},
];
const TESTS = [
{
title: "Tracked provider",
name: "Example",
cases: [
{
title: "Non-existent URI",
originalURI: null,
expected: "",
},
{
title: "Empty URI",
originalURI: "",
expected: "",
},
{
title: "Non-url",
originalURI: "about:blank",
expected: "",
},
{
title: "Non-url 1",
originalURI: "about:home",
expected: "",
},
{
title: "Non-url 2",
originalURI: "about:newtab",
expected: "",
},
{
title: "Non-url 3",
expected: "",
},
{
title: "Non-url 4",
expected: "",
},
{
title: "No search parameters",
expected: "",
},
{
title: "No search query param value",
expected: "",
},
{
title: "With search query param value",
expected: "foo",
},
{
title: "With search query param value and a fake value key-value pair",
expected: "",
},
{
title: "With search query param value and valid key-value pair",
expected: "foo",
},
{
title: "With search query param value and unknown key-value pair",
expected: "foo",
},
{
title:
"With search query param value and valid excludeParams key-value pair",
expected: "",
},
{
title:
"With search query param value and invalid excludeParams key-value pair",
expected: "foo",
},
],
},
{
title: "Untracked provider",
name: "Example1",
cases: [
{
title: "With search query param",
expected: "",
},
{
title: "No search parameters",
expected: "",
},
{
title: "No search query param value",
expected: "",
},
{
title: "With search query param value and unknown key-value pair",
expected: "",
},
{
title: "with search query param value and default key-value pair",
expected: "foo",
},
],
},
{
title: "Tracked provider with mandatory key-value pair",
name: "Example2",
cases: [
{
title: "With search query param value",
expected: "",
},
{
title: "With search query param value",
expected: "foo",
},
{
title: "With search query param value and excludeParams key-value pair",
expected: "",
},
{
title:
"With search query param value and presence of excludeParams key",
expected: "",
},
],
},
];
add_setup(async function () {
await UrlbarSearchTermsPersistence.overrideSearchTermsPersistenceForTests(
PROVIDERS
);
const CONFIG_V2 = [
{
recordType: "engine",
identifier: "Example",
base: {
name: "Example",
},
},
},
{
recordType: "engine",
identifier: "Example1",
base: {
name: "Example1",
urls: {
search: {
searchTermParamName: "q",
params: [
{
name: "default",
value: "all",
},
],
},
},
},
},
{
recordType: "engine",
identifier: "Example2",
base: {
name: "Example2",
},
},
},
{
recordType: "defaultEngines",
globalDefault: "Example",
specificDefaults: [],
},
];
SearchTestUtils.updateRemoteSettingsConfig(CONFIG_V2);
await Services.search.init();
});
add_task(async function test_parsing_extracted_urls() {
for (let test of TESTS) {
for (let { title, originalURI, expected } of test.cases) {
info(`${test.name} - ${title}`);
if (originalURI) {
originalURI = Services.io.newURI(originalURI);
}
Assert.equal(
UrlbarSearchTermsPersistence.getSearchTerm(originalURI),
expected
);
}
}
});