зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1687932 - Remove use of nsISearchEngine.addEngineWithDetails from other xpcshell-tests. r=harry
Differential Revision: https://phabricator.services.mozilla.com/D108462
This commit is contained in:
Родитель
b464060db9
Коммит
5e786e8b26
|
@ -6,6 +6,7 @@ const { AddonTestUtils } = ChromeUtils.import(
|
|||
|
||||
XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
ExtensionParent: "resource://gre/modules/ExtensionParent.jsm",
|
||||
SearchTestUtils: "resource://testing-common/SearchTestUtils.jsm",
|
||||
UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
|
||||
UrlbarProvidersManager: "resource:///modules/UrlbarProvidersManager.jsm",
|
||||
UrlbarQueryContext: "resource:///modules/UrlbarUtils.jsm",
|
||||
|
@ -21,6 +22,9 @@ AddonTestUtils.createAppInfo(
|
|||
"1",
|
||||
"42"
|
||||
);
|
||||
SearchTestUtils.init(this);
|
||||
SearchTestUtils.initXPCShellAddonManager(this, "system");
|
||||
|
||||
// Override ExtensionXPCShellUtils.jsm's overriding of the pref as the
|
||||
// search service needs it.
|
||||
Services.prefs.clearUserPref("services.settings.default_bucket");
|
||||
|
@ -67,11 +71,14 @@ add_task(async function startup() {
|
|||
// Add a test engine and make it default so that when we do searches below,
|
||||
// Firefox doesn't try to include search suggestions from the actual default
|
||||
// engine from over the network.
|
||||
let engine = await Services.search.addEngineWithDetails("Test engine", {
|
||||
template: "http://example.com/?s=%S",
|
||||
alias: "@testengine",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "Test engine",
|
||||
keyword: "@testengine",
|
||||
search_url_get_params: "s={searchTerms}",
|
||||
});
|
||||
Services.search.defaultEngine = engine;
|
||||
Services.search.defaultEngine = Services.search.getEngineByName(
|
||||
"Test engine"
|
||||
);
|
||||
});
|
||||
|
||||
// Extensions must specify the "urlbar" permission to use browser.urlbar.
|
||||
|
@ -221,7 +228,7 @@ add_task(async function test_onProviderResultsRequested() {
|
|||
source: "tabs",
|
||||
payload: {
|
||||
title: "Test remote_tab-tabs result",
|
||||
url: "http://example.com/remote_tab-tabs",
|
||||
url: "https://example.com/remote_tab-tabs",
|
||||
device: "device",
|
||||
},
|
||||
},
|
||||
|
@ -238,7 +245,7 @@ add_task(async function test_onProviderResultsRequested() {
|
|||
source: "tabs",
|
||||
payload: {
|
||||
title: "Test tab-tabs result",
|
||||
url: "http://example.com/tab-tabs",
|
||||
url: "https://example.com/tab-tabs",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -247,8 +254,8 @@ add_task(async function test_onProviderResultsRequested() {
|
|||
payload: {
|
||||
text: "Test tip-local result text",
|
||||
buttonText: "Test tip-local result button text",
|
||||
buttonUrl: "http://example.com/tip-button",
|
||||
helpUrl: "http://example.com/tip-help",
|
||||
buttonUrl: "https://example.com/tip-button",
|
||||
helpUrl: "https://example.com/tip-help",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -256,7 +263,7 @@ add_task(async function test_onProviderResultsRequested() {
|
|||
source: "history",
|
||||
payload: {
|
||||
title: "Test url-history result",
|
||||
url: "http://example.com/url-history",
|
||||
url: "https://example.com/url-history",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
@ -317,8 +324,8 @@ add_task(async function test_onProviderResultsRequested() {
|
|||
heuristic: false,
|
||||
payload: {
|
||||
title: "Test remote_tab-tabs result",
|
||||
url: "http://example.com/remote_tab-tabs",
|
||||
displayUrl: "http://example.com/remote_tab-tabs",
|
||||
url: "https://example.com/remote_tab-tabs",
|
||||
displayUrl: "example.com/remote_tab-tabs",
|
||||
device: "device",
|
||||
},
|
||||
},
|
||||
|
@ -329,8 +336,8 @@ add_task(async function test_onProviderResultsRequested() {
|
|||
heuristic: false,
|
||||
payload: {
|
||||
title: "Test tab-tabs result",
|
||||
url: "http://example.com/tab-tabs",
|
||||
displayUrl: "http://example.com/tab-tabs",
|
||||
url: "https://example.com/tab-tabs",
|
||||
displayUrl: "example.com/tab-tabs",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -341,8 +348,8 @@ add_task(async function test_onProviderResultsRequested() {
|
|||
payload: {
|
||||
text: "Test tip-local result text",
|
||||
buttonText: "Test tip-local result button text",
|
||||
buttonUrl: "http://example.com/tip-button",
|
||||
helpUrl: "http://example.com/tip-help",
|
||||
buttonUrl: "https://example.com/tip-button",
|
||||
helpUrl: "https://example.com/tip-help",
|
||||
type: "extension",
|
||||
},
|
||||
},
|
||||
|
@ -353,8 +360,8 @@ add_task(async function test_onProviderResultsRequested() {
|
|||
heuristic: false,
|
||||
payload: {
|
||||
title: "Test url-history result",
|
||||
url: "http://example.com/url-history",
|
||||
displayUrl: "http://example.com/url-history",
|
||||
url: "https://example.com/url-history",
|
||||
displayUrl: "example.com/url-history",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
@ -407,7 +414,7 @@ add_task(async function test_onProviderResultsRequested_searchEngines() {
|
|||
type: "search",
|
||||
source: "search",
|
||||
payload: {
|
||||
url: "http://example.com/?s",
|
||||
url: "https://example.com/?s",
|
||||
suggestion: "url specified",
|
||||
},
|
||||
},
|
||||
|
@ -417,7 +424,7 @@ add_task(async function test_onProviderResultsRequested_searchEngines() {
|
|||
payload: {
|
||||
engine: "Test engine",
|
||||
keyword: "@testengine",
|
||||
url: "http://example.com/?s",
|
||||
url: "https://example.com/?s",
|
||||
suggestion: "engine, keyword, and url specified",
|
||||
},
|
||||
},
|
||||
|
@ -426,7 +433,7 @@ add_task(async function test_onProviderResultsRequested_searchEngines() {
|
|||
source: "search",
|
||||
payload: {
|
||||
keyword: "@testengine",
|
||||
url: "http://example.com/?s",
|
||||
url: "https://example.com/?s",
|
||||
suggestion: "keyword and url specified",
|
||||
},
|
||||
},
|
||||
|
@ -573,7 +580,7 @@ add_task(async function test_activeAndInactiveProviders() {
|
|||
source: "history",
|
||||
payload: {
|
||||
title: `Test result ${behavior}`,
|
||||
url: `http://example.com/${behavior}`,
|
||||
url: `https://example.com/${behavior}`,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
@ -634,7 +641,7 @@ add_task(async function test_threeActiveProviders() {
|
|||
source: "history",
|
||||
payload: {
|
||||
title: `Test result ${i}`,
|
||||
url: `http://example.com/${i}`,
|
||||
url: `https://example.com/${i}`,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
@ -760,7 +767,7 @@ add_task(async function test_activeInactiveAndRestrictingProviders() {
|
|||
source: "history",
|
||||
payload: {
|
||||
title: `Test result ${behavior}`,
|
||||
url: `http://example.com/${behavior}`,
|
||||
url: `https://example.com/${behavior}`,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
@ -824,7 +831,7 @@ add_task(async function test_heuristicRestricting() {
|
|||
heuristic: true,
|
||||
payload: {
|
||||
title: "Test result",
|
||||
url: "http://example.com/",
|
||||
url: "https://example.com/",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
@ -876,7 +883,7 @@ add_task(async function test_heuristicNonRestricting() {
|
|||
heuristic: true,
|
||||
payload: {
|
||||
title: "Test result",
|
||||
url: "http://example.com/",
|
||||
url: "https://example.com/",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
@ -981,7 +988,7 @@ add_task(async function test_badPayload() {
|
|||
source: "history",
|
||||
payload: {
|
||||
title: "Test result",
|
||||
url: "http://example.com/",
|
||||
url: "https://example.com/",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
@ -1127,7 +1134,7 @@ add_task(async function test_onResultsRequestedTimeout() {
|
|||
source: "history",
|
||||
payload: {
|
||||
title: "Test result",
|
||||
url: "http://example.com/",
|
||||
url: "https://example.com/",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
@ -1375,7 +1382,7 @@ add_task(async function test_nonPrivateBrowsing() {
|
|||
source: "history",
|
||||
payload: {
|
||||
title: "Test result",
|
||||
url: "http://example.com/",
|
||||
url: "https://example.com/",
|
||||
},
|
||||
suggestedIndex: 1,
|
||||
},
|
||||
|
|
|
@ -12,10 +12,14 @@ http://creativecommons.org/publicdomain/zero/1.0/ */
|
|||
const { AddonTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/AddonTestUtils.jsm"
|
||||
);
|
||||
const { SearchTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/SearchTestUtils.jsm"
|
||||
);
|
||||
const { TestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/TestUtils.jsm"
|
||||
);
|
||||
|
||||
SearchTestUtils.init(this);
|
||||
AddonTestUtils.init(this);
|
||||
AddonTestUtils.createAppInfo(
|
||||
"xpcshell@tests.mozilla.org",
|
||||
|
@ -106,11 +110,14 @@ add_task(async function setup() {
|
|||
Services.prefs.setBoolPref("browser.ping-centre.telemetry", false);
|
||||
|
||||
// We need a default search engine set up for rendering the search input.
|
||||
let engine = await Services.search.addEngineWithDetails("Test engine", {
|
||||
template: "http://example.com/?s=%S",
|
||||
alias: "@testengine",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "Test engine",
|
||||
keyword: "@testengine",
|
||||
search_url_get_params: "s={searchTerms}",
|
||||
});
|
||||
Services.search.defaultEngine = engine;
|
||||
Services.search.defaultEngine = Services.search.getEngineByName(
|
||||
"Test engine"
|
||||
);
|
||||
|
||||
// Initialize Activity Stream, and pretend that a new window has been loaded
|
||||
// to kick off initializing all of the feeds.
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
|
||||
<ShortName>engine.xml</ShortName>
|
||||
<Description>A test search engine</Description>
|
||||
<InputEncoding>UTF-8</InputEncoding>
|
||||
<Url type="text/html" method="GET" template="http://www.example.com/">
|
||||
<Param name="q" value="{searchTerms}"/>
|
||||
</Url>
|
||||
<SearchForm>http://www.example.com/</SearchForm>
|
||||
</SearchPlugin>
|
|
@ -18,6 +18,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
PlacesTestUtils: "resource://testing-common/PlacesTestUtils.jsm",
|
||||
PlacesUtils: "resource://gre/modules/PlacesUtils.jsm",
|
||||
PromiseUtils: "resource://gre/modules/PromiseUtils.jsm",
|
||||
SearchTestUtils: "resource://testing-common/SearchTestUtils.jsm",
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
TestUtils: "resource://testing-common/TestUtils.jsm",
|
||||
UrlbarController: "resource:///modules/UrlbarController.jsm",
|
||||
|
@ -31,6 +32,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
});
|
||||
const { sinon } = ChromeUtils.import("resource://testing-common/Sinon.jsm");
|
||||
|
||||
SearchTestUtils.init(this);
|
||||
AddonTestUtils.init(this, false);
|
||||
AddonTestUtils.createAppInfo(
|
||||
"xpcshell@tests.mozilla.org",
|
||||
|
|
|
@ -92,12 +92,9 @@ add_task(async function test_restrictions() {
|
|||
);
|
||||
|
||||
info("search restrict with alias");
|
||||
let aliasEngine = await Services.search.addEngineWithDetails("Test", {
|
||||
alias: "match",
|
||||
template: "http://example.com/?search={searchTerms}",
|
||||
});
|
||||
registerCleanupFunction(async function() {
|
||||
await Services.search.removeEngine(aliasEngine);
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "Test",
|
||||
keyword: "match",
|
||||
});
|
||||
results = await get_results({
|
||||
sources: [UrlbarUtils.RESULT_SOURCE.SEARCH],
|
||||
|
|
|
@ -6,6 +6,8 @@ const { UrlbarSearchUtils } = ChromeUtils.import(
|
|||
"resource:///modules/UrlbarSearchUtils.jsm"
|
||||
);
|
||||
|
||||
let baconEngineExtension;
|
||||
|
||||
add_task(async function() {
|
||||
await UrlbarSearchUtils.init();
|
||||
// Tell the search service we are running in the US. This also has the
|
||||
|
@ -72,26 +74,23 @@ add_task(async function onlyEnabled_option_nomatch() {
|
|||
});
|
||||
|
||||
add_task(async function add_search_engine_match() {
|
||||
let promiseTopic = promiseSearchTopic("engine-added");
|
||||
Assert.equal(
|
||||
0,
|
||||
(await UrlbarSearchUtils.enginesForDomainPrefix("bacon")).length
|
||||
);
|
||||
await Promise.all([
|
||||
Services.search.addEngineWithDetails("bacon", {
|
||||
alias: "pork",
|
||||
description: "Search Bacon",
|
||||
method: "GET",
|
||||
template: "http://www.bacon.moz/?search={searchTerms}",
|
||||
}),
|
||||
promiseTopic,
|
||||
]);
|
||||
await promiseTopic;
|
||||
baconEngineExtension = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "bacon",
|
||||
keyword: "pork",
|
||||
search_url: "https://www.bacon.moz/",
|
||||
},
|
||||
true
|
||||
);
|
||||
let matchedEngine = (
|
||||
await UrlbarSearchUtils.enginesForDomainPrefix("bacon")
|
||||
)[0];
|
||||
Assert.ok(matchedEngine);
|
||||
Assert.equal(matchedEngine.searchForm, "http://www.bacon.moz");
|
||||
Assert.equal(matchedEngine.searchForm, "https://www.bacon.moz");
|
||||
Assert.equal(matchedEngine.name, "bacon");
|
||||
Assert.equal(matchedEngine.iconURI, null);
|
||||
info("also type part of the public suffix");
|
||||
|
@ -99,35 +98,29 @@ add_task(async function add_search_engine_match() {
|
|||
await UrlbarSearchUtils.enginesForDomainPrefix("bacon.m")
|
||||
)[0];
|
||||
Assert.ok(matchedEngine);
|
||||
Assert.equal(matchedEngine.searchForm, "http://www.bacon.moz");
|
||||
Assert.equal(matchedEngine.searchForm, "https://www.bacon.moz");
|
||||
Assert.equal(matchedEngine.name, "bacon");
|
||||
Assert.equal(matchedEngine.iconURI, null);
|
||||
});
|
||||
|
||||
add_task(async function match_multiple_search_engines() {
|
||||
let promiseTopic = promiseSearchTopic("engine-added");
|
||||
Assert.equal(
|
||||
0,
|
||||
(await UrlbarSearchUtils.enginesForDomainPrefix("baseball")).length
|
||||
);
|
||||
await Promise.all([
|
||||
Services.search.addEngineWithDetails("baseball", {
|
||||
description: "Search Baseball",
|
||||
method: "GET",
|
||||
template: "http://www.baseball.moz/?search={searchTerms}",
|
||||
}),
|
||||
promiseTopic,
|
||||
]);
|
||||
await promiseTopic;
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "baseball",
|
||||
search_url: "https://www.baseball.moz/",
|
||||
});
|
||||
let matchedEngines = await UrlbarSearchUtils.enginesForDomainPrefix("ba");
|
||||
Assert.equal(
|
||||
matchedEngines.length,
|
||||
2,
|
||||
"enginesForDomainPrefix returned two engines."
|
||||
);
|
||||
Assert.equal(matchedEngines[0].searchForm, "http://www.bacon.moz");
|
||||
Assert.equal(matchedEngines[0].searchForm, "https://www.bacon.moz");
|
||||
Assert.equal(matchedEngines[0].name, "bacon");
|
||||
Assert.equal(matchedEngines[1].searchForm, "http://www.baseball.moz");
|
||||
Assert.equal(matchedEngines[1].searchForm, "https://www.baseball.moz");
|
||||
Assert.equal(matchedEngines[1].name, "baseball");
|
||||
});
|
||||
|
||||
|
@ -154,20 +147,15 @@ add_task(async function test_aliased_search_engine_match() {
|
|||
});
|
||||
|
||||
add_task(async function test_aliased_search_engine_match_upper_case_alias() {
|
||||
let promiseTopic = promiseSearchTopic("engine-added");
|
||||
Assert.equal(
|
||||
0,
|
||||
(await UrlbarSearchUtils.enginesForDomainPrefix("patch")).length
|
||||
);
|
||||
await Promise.all([
|
||||
Services.search.addEngineWithDetails("patch", {
|
||||
alias: "PR",
|
||||
description: "Search Patch",
|
||||
method: "GET",
|
||||
template: "http://www.patch.moz/?search={searchTerms}",
|
||||
}),
|
||||
promiseTopic,
|
||||
]);
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "patch",
|
||||
keyword: "PR",
|
||||
search_url: "https://www.patch.moz/",
|
||||
});
|
||||
// lower case
|
||||
let matchedEngine = await UrlbarSearchUtils.engineForAlias("pr");
|
||||
Assert.ok(matchedEngine);
|
||||
|
@ -189,9 +177,8 @@ add_task(async function test_aliased_search_engine_match_upper_case_alias() {
|
|||
});
|
||||
|
||||
add_task(async function remove_search_engine_nomatch() {
|
||||
let engine = Services.search.getEngineByName("bacon");
|
||||
let promiseTopic = promiseSearchTopic("engine-removed");
|
||||
await Promise.all([Services.search.removeEngine(engine), promiseTopic]);
|
||||
await Promise.all([baconEngineExtension.unload(), promiseTopic]);
|
||||
Assert.equal(
|
||||
0,
|
||||
(await UrlbarSearchUtils.enginesForDomainPrefix("bacon")).length
|
||||
|
@ -245,35 +232,57 @@ add_task(async function test_serps_are_equivalent() {
|
|||
});
|
||||
|
||||
add_task(async function test_get_root_domain_from_engine() {
|
||||
let engine = await Services.search.addEngineWithDetails("TestEngine2", {
|
||||
template: "http://example.com",
|
||||
});
|
||||
let extension = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "TestEngine2",
|
||||
search_url: "https://example.com/",
|
||||
},
|
||||
true
|
||||
);
|
||||
let engine = Services.search.getEngineByName("TestEngine2");
|
||||
Assert.equal(UrlbarSearchUtils.getRootDomainFromEngine(engine), "example");
|
||||
await Services.search.removeEngine(engine);
|
||||
await extension.unload();
|
||||
|
||||
engine = await Services.search.addEngineWithDetails("TestEngine", {
|
||||
template: "http://www.subdomain.othersubdomain.example.com",
|
||||
});
|
||||
extension = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "TestEngine",
|
||||
search_url: "https://www.subdomain.othersubdomain.example.com",
|
||||
},
|
||||
true
|
||||
);
|
||||
engine = Services.search.getEngineByName("TestEngine");
|
||||
Assert.equal(UrlbarSearchUtils.getRootDomainFromEngine(engine), "example");
|
||||
await Services.search.removeEngine(engine);
|
||||
await extension.unload();
|
||||
|
||||
// We let engines with URL ending in .test through even though its not a valid
|
||||
// TLD.
|
||||
engine = await Services.search.addEngineWithDetails("TestMalformed", {
|
||||
template: `http://mochi.test/?search={searchTerms}`,
|
||||
});
|
||||
extension = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "TestMalformed",
|
||||
search_url: "https://mochi.test/",
|
||||
search_url_get_params: "search={searchTerms}",
|
||||
},
|
||||
true
|
||||
);
|
||||
engine = Services.search.getEngineByName("TestMalformed");
|
||||
Assert.equal(UrlbarSearchUtils.getRootDomainFromEngine(engine), "mochi");
|
||||
await Services.search.removeEngine(engine);
|
||||
await extension.unload();
|
||||
|
||||
// We return the domain for engines with a malformed URL.
|
||||
engine = await Services.search.addEngineWithDetails("TestMalformed", {
|
||||
template: `http://subdomain.foobar/?search={searchTerms}`,
|
||||
});
|
||||
extension = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "TestMalformed",
|
||||
search_url: "https://subdomain.foobar/",
|
||||
search_url_get_params: "search={searchTerms}",
|
||||
},
|
||||
true
|
||||
);
|
||||
engine = Services.search.getEngineByName("TestMalformed");
|
||||
Assert.equal(
|
||||
UrlbarSearchUtils.getRootDomainFromEngine(engine),
|
||||
"subdomain.foobar"
|
||||
);
|
||||
await Services.search.removeEngine(engine);
|
||||
await extension.unload();
|
||||
});
|
||||
|
||||
function promiseSearchTopic(expectedVerb) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
https://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
/**
|
||||
* These tests unit test the functionality of UrlbarController by stubbing out the
|
||||
|
@ -53,59 +53,59 @@ searchKeywordData.prototype = new keyWordData();
|
|||
|
||||
var testData = [
|
||||
[
|
||||
new bmKeywordData("bmget", "http://bmget/search=%s", null, "foo"),
|
||||
new keywordResult("http://bmget/search=foo", null),
|
||||
new bmKeywordData("bmget", "https://bmget/search=%s", null, "foo"),
|
||||
new keywordResult("https://bmget/search=foo", null),
|
||||
],
|
||||
|
||||
[
|
||||
new bmKeywordData("bmpost", "http://bmpost/", "search=%s", "foo2"),
|
||||
new keywordResult("http://bmpost/", "search=foo2"),
|
||||
new bmKeywordData("bmpost", "https://bmpost/", "search=%s", "foo2"),
|
||||
new keywordResult("https://bmpost/", "search=foo2"),
|
||||
],
|
||||
|
||||
[
|
||||
new bmKeywordData(
|
||||
"bmpostget",
|
||||
"http://bmpostget/search1=%s",
|
||||
"https://bmpostget/search1=%s",
|
||||
"search2=%s",
|
||||
"foo3"
|
||||
),
|
||||
new keywordResult("http://bmpostget/search1=foo3", "search2=foo3"),
|
||||
new keywordResult("https://bmpostget/search1=foo3", "search2=foo3"),
|
||||
],
|
||||
|
||||
[
|
||||
new bmKeywordData("bmget-nosearch", "http://bmget-nosearch/", null, ""),
|
||||
new keywordResult("http://bmget-nosearch/", null),
|
||||
new bmKeywordData("bmget-nosearch", "https://bmget-nosearch/", null, ""),
|
||||
new keywordResult("https://bmget-nosearch/", null),
|
||||
],
|
||||
|
||||
[
|
||||
new searchKeywordData(
|
||||
"searchget",
|
||||
"http://searchget/?search={searchTerms}",
|
||||
"https://searchget/?search={searchTerms}",
|
||||
null,
|
||||
"foo4"
|
||||
),
|
||||
new keywordResult("http://searchget/?search=foo4", null, true),
|
||||
new keywordResult("https://searchget/?search=foo4", null, true),
|
||||
],
|
||||
|
||||
[
|
||||
new searchKeywordData(
|
||||
"searchpost",
|
||||
"http://searchpost/",
|
||||
"https://searchpost/",
|
||||
"search={searchTerms}",
|
||||
"foo5"
|
||||
),
|
||||
new keywordResult("http://searchpost/", "search=foo5", true),
|
||||
new keywordResult("https://searchpost/", "search=foo5", true),
|
||||
],
|
||||
|
||||
[
|
||||
new searchKeywordData(
|
||||
"searchpostget",
|
||||
"http://searchpostget/?search1={searchTerms}",
|
||||
"https://searchpostget/?search1={searchTerms}",
|
||||
"search2={searchTerms}",
|
||||
"foo6"
|
||||
),
|
||||
new keywordResult(
|
||||
"http://searchpostget/?search1=foo6",
|
||||
"https://searchpostget/?search1=foo6",
|
||||
"search2=foo6",
|
||||
true
|
||||
),
|
||||
|
@ -114,13 +114,13 @@ var testData = [
|
|||
// Bookmark keywords that don't take parameters should not be activated if a
|
||||
// parameter is passed (bug 420328).
|
||||
[
|
||||
new bmKeywordData("bmget-noparam", "http://bmget-noparam/", null, "foo7"),
|
||||
new bmKeywordData("bmget-noparam", "https://bmget-noparam/", null, "foo7"),
|
||||
new keywordResult(null, null, true),
|
||||
],
|
||||
[
|
||||
new bmKeywordData(
|
||||
"bmpost-noparam",
|
||||
"http://bmpost-noparam/",
|
||||
"https://bmpost-noparam/",
|
||||
"not_a=param",
|
||||
"foo8"
|
||||
),
|
||||
|
@ -132,21 +132,21 @@ var testData = [
|
|||
[
|
||||
new bmKeywordData(
|
||||
"bmget-escaping",
|
||||
"http://bmget/?esc=%s&raw=%S",
|
||||
"https://bmget/?esc=%s&raw=%S",
|
||||
null,
|
||||
"fo\xE9"
|
||||
),
|
||||
new keywordResult("http://bmget/?esc=fo%C3%A9&raw=fo\xE9", null),
|
||||
new keywordResult("https://bmget/?esc=fo%C3%A9&raw=fo\xE9", null),
|
||||
],
|
||||
// Explicitly-defined ISO-8859-1
|
||||
[
|
||||
new bmKeywordData(
|
||||
"bmget-escaping2",
|
||||
"http://bmget/?esc=%s&raw=%S&mozcharset=ISO-8859-1",
|
||||
"https://bmget/?esc=%s&raw=%S&mozcharset=ISO-8859-1",
|
||||
null,
|
||||
"fo\xE9"
|
||||
),
|
||||
new keywordResult("http://bmget/?esc=fo%E9&raw=fo\xE9", null),
|
||||
new keywordResult("https://bmget/?esc=fo%E9&raw=fo\xE9", null),
|
||||
],
|
||||
|
||||
// Bug 359809: Test escaping +, /, and @
|
||||
|
@ -154,27 +154,27 @@ var testData = [
|
|||
[
|
||||
new bmKeywordData(
|
||||
"bmget-escaping",
|
||||
"http://bmget/?esc=%s&raw=%S",
|
||||
"https://bmget/?esc=%s&raw=%S",
|
||||
null,
|
||||
"+/@"
|
||||
),
|
||||
new keywordResult("http://bmget/?esc=%2B%2F%40&raw=+/@", null),
|
||||
new keywordResult("https://bmget/?esc=%2B%2F%40&raw=+/@", null),
|
||||
],
|
||||
// Explicitly-defined ISO-8859-1
|
||||
[
|
||||
new bmKeywordData(
|
||||
"bmget-escaping2",
|
||||
"http://bmget/?esc=%s&raw=%S&mozcharset=ISO-8859-1",
|
||||
"https://bmget/?esc=%s&raw=%S&mozcharset=ISO-8859-1",
|
||||
null,
|
||||
"+/@"
|
||||
),
|
||||
new keywordResult("http://bmget/?esc=%2B%2F%40&raw=+/@", null),
|
||||
new keywordResult("https://bmget/?esc=%2B%2F%40&raw=+/@", null),
|
||||
],
|
||||
|
||||
// Test using a non-bmKeywordData object, to test the behavior of
|
||||
// getShortcutOrURIAndPostData for non-keywords (setupKeywords only adds keywords for
|
||||
// bmKeywordData objects)
|
||||
[{ keyword: "http://gavinsharp.com" }, new keywordResult(null, null, true)],
|
||||
[{ keyword: "https://gavinsharp.com" }, new keywordResult(null, null, true)],
|
||||
];
|
||||
|
||||
add_task(async function test_getshortcutoruri() {
|
||||
|
@ -211,7 +211,6 @@ add_task(async function test_getshortcutoruri() {
|
|||
});
|
||||
|
||||
var folder = null;
|
||||
var gAddedEngines = [];
|
||||
|
||||
async function setupKeywords() {
|
||||
folder = await PlacesUtils.bookmarks.insert({
|
||||
|
@ -234,24 +233,17 @@ async function setupKeywords() {
|
|||
}
|
||||
|
||||
if (data instanceof searchKeywordData) {
|
||||
let addedEngine = await Services.search.addEngineWithDetails(
|
||||
data.keyword,
|
||||
{
|
||||
alias: data.keyword,
|
||||
method: data.method,
|
||||
template: data.uri.spec,
|
||||
searchPostParams: data.postData,
|
||||
}
|
||||
);
|
||||
gAddedEngines.push(addedEngine);
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: data.keyword,
|
||||
keyword: data.keyword,
|
||||
search_url: data.uri.spec,
|
||||
search_url_get_params: "",
|
||||
search_url_post_params: data.postData,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function cleanupKeywords() {
|
||||
await PlacesUtils.bookmarks.remove(folder);
|
||||
for (let engine of gAddedEngines) {
|
||||
await Services.search.removeEngine(engine);
|
||||
}
|
||||
gAddedEngines = [];
|
||||
}
|
||||
|
|
|
@ -11,14 +11,9 @@ const TEST_ENGINE_ALIAS = "@autofilltest";
|
|||
|
||||
add_task(async function init() {
|
||||
// Add an engine with an "@" alias.
|
||||
await Services.search.addEngineWithDetails(TEST_ENGINE_NAME, {
|
||||
alias: TEST_ENGINE_ALIAS,
|
||||
template: "http://example.com/?search={searchTerms}",
|
||||
});
|
||||
registerCleanupFunction(async () => {
|
||||
let engine = Services.search.getEngineByName(TEST_ENGINE_NAME);
|
||||
Assert.ok(engine);
|
||||
await Services.search.removeEngine(engine);
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: TEST_ENGINE_NAME,
|
||||
keyword: TEST_ENGINE_ALIAS,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const ENGINE_NAME = "TestEngine";
|
||||
const ENGINE_NAME = "engine.xml";
|
||||
|
||||
add_task(async function searchEngines() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
|
||||
|
@ -27,14 +27,23 @@ add_task(async function searchEngines() {
|
|||
);
|
||||
});
|
||||
|
||||
let schemes = ["http", "https"];
|
||||
for (let i = 0; i < schemes.length; i++) {
|
||||
let scheme = schemes[i];
|
||||
let engine = await Services.search.addEngineWithDetails(ENGINE_NAME, {
|
||||
method: "GET",
|
||||
template: scheme + "://www.example.com/",
|
||||
searchGetParams: "q={searchTerms}",
|
||||
});
|
||||
let server = makeTestServer();
|
||||
|
||||
// Bug 1149672: Once we drop support for http with OpenSearch engines,
|
||||
// we should be able to drop the http part of this.
|
||||
for (let scheme of ["https", "http"]) {
|
||||
let extension;
|
||||
if (scheme == "https") {
|
||||
extension = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: ENGINE_NAME,
|
||||
search_url: "https://www.example.com/",
|
||||
},
|
||||
true
|
||||
);
|
||||
} else {
|
||||
await addTestEngine("engine.xml", server);
|
||||
}
|
||||
|
||||
let context = createContext("ex", { isPrivate: false });
|
||||
await check_results({
|
||||
|
@ -187,7 +196,7 @@ add_task(async function searchEngines() {
|
|||
|
||||
// We should just get a normal heuristic result from HeuristicFallback for
|
||||
// these queries.
|
||||
let otherScheme = schemes[(i + 1) % schemes.length];
|
||||
let otherScheme = scheme == "http" ? "https" : "http";
|
||||
context = createContext(otherScheme + "://ex", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
|
@ -229,6 +238,6 @@ add_task(async function searchEngines() {
|
|||
],
|
||||
});
|
||||
|
||||
await Services.search.removeEngine(engine);
|
||||
await extension?.unload();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -58,12 +58,10 @@ add_task(async function test_trailing_space_noautofill() {
|
|||
|
||||
add_task(async function test_searchEngine_autofill() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
|
||||
let engine = await Services.search.addEngineWithDetails("CakeSearch", {
|
||||
method: "GET",
|
||||
template: "http://cake.search/",
|
||||
searchGetParams: "q={searchTerms}",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "CakeSearch",
|
||||
search_url: "https://cake.search",
|
||||
});
|
||||
registerCleanupFunction(async () => Services.search.removeEngine(engine));
|
||||
|
||||
info(
|
||||
"Should autoFill search engine if search string does not contains a space"
|
||||
|
@ -84,12 +82,10 @@ add_task(async function test_searchEngine_autofill() {
|
|||
|
||||
add_task(async function test_searchEngine_prefix_space_noautofill() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
|
||||
let engine = await Services.search.addEngineWithDetails("CupcakeSearch", {
|
||||
method: "GET",
|
||||
template: "http://cupcake.search/",
|
||||
searchGetParams: "q={searchTerms}",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "CupcakeSearch",
|
||||
search_url: "https://cupcake.search",
|
||||
});
|
||||
registerCleanupFunction(async () => Services.search.removeEngine(engine));
|
||||
|
||||
info(
|
||||
"Should not try to autoFill search engine if search string contains a space"
|
||||
|
@ -111,12 +107,10 @@ add_task(async function test_searchEngine_prefix_space_noautofill() {
|
|||
|
||||
add_task(async function test_searchEngine_trailing_space_noautofill() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
|
||||
let engine = await Services.search.addEngineWithDetails("BaconSearch", {
|
||||
method: "GET",
|
||||
template: "http://bacon.search/",
|
||||
searchGetParams: "q={searchTerms}",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "BaconSearch",
|
||||
search_url: "https://bacon.search",
|
||||
});
|
||||
registerCleanupFunction(async () => Services.search.removeEngine(engine));
|
||||
|
||||
info(
|
||||
"Should not try to autoFill search engine if search string contains a space"
|
||||
|
@ -138,12 +132,10 @@ add_task(async function test_searchEngine_trailing_space_noautofill() {
|
|||
|
||||
add_task(async function test_searchEngine_www_noautofill() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
|
||||
let engine = await Services.search.addEngineWithDetails("HamSearch", {
|
||||
method: "GET",
|
||||
template: "http://ham.search/",
|
||||
searchGetParams: "q={searchTerms}",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "HamSearch",
|
||||
search_url: "https://ham.search",
|
||||
});
|
||||
registerCleanupFunction(async () => Services.search.removeEngine(engine));
|
||||
|
||||
info(
|
||||
"Should not autoFill search engine if search string contains www. but engine doesn't"
|
||||
|
@ -171,12 +163,10 @@ add_task(async function test_searchEngine_www_noautofill() {
|
|||
|
||||
add_task(async function test_searchEngine_different_scheme_noautofill() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
|
||||
let engine = await Services.search.addEngineWithDetails("PieSearch", {
|
||||
method: "GET",
|
||||
template: "https://pie.search/",
|
||||
searchGetParams: "q={searchTerms}",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "PieSearch",
|
||||
search_url: "https://pie.search",
|
||||
});
|
||||
registerCleanupFunction(async () => Services.search.removeEngine(engine));
|
||||
|
||||
info(
|
||||
"Should not autoFill search engine if search string has a different scheme."
|
||||
|
@ -200,18 +190,16 @@ add_task(async function test_searchEngine_different_scheme_noautofill() {
|
|||
|
||||
add_task(async function test_searchEngine_matching_prefix_autofill() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
|
||||
let engine = await Services.search.addEngineWithDetails("BeanSearch", {
|
||||
method: "GET",
|
||||
template: "http://www.bean.search/",
|
||||
searchGetParams: "q={searchTerms}",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "BeanSearch",
|
||||
search_url: "https://www.bean.search",
|
||||
});
|
||||
registerCleanupFunction(async () => Services.search.removeEngine(engine));
|
||||
|
||||
info("Should autoFill search engine if search string has matching prefix.");
|
||||
let context = createContext("http://www.be", { isPrivate: false });
|
||||
let context = createContext("https://www.be", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
autofilled: "http://www.bean.search/",
|
||||
autofilled: "https://www.bean.search/",
|
||||
matches: [
|
||||
makePrioritySearchResult(context, {
|
||||
engineName: "BeanSearch",
|
||||
|
@ -234,10 +222,10 @@ add_task(async function test_searchEngine_matching_prefix_autofill() {
|
|||
});
|
||||
|
||||
info("Should autoFill search engine if search string has matching scheme.");
|
||||
context = createContext("http://be", { isPrivate: false });
|
||||
context = createContext("https://be", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
autofilled: "http://bean.search/",
|
||||
autofilled: "https://bean.search/",
|
||||
matches: [
|
||||
makePrioritySearchResult(context, {
|
||||
engineName: "BeanSearch",
|
||||
|
|
|
@ -490,11 +490,11 @@ add_task(async function() {
|
|||
|
||||
info("change default engine");
|
||||
let originalTestEngine = Services.search.getEngineByName(ENGINE_NAME);
|
||||
let engine2 = await Services.search.addEngineWithDetails("AliasEngine", {
|
||||
alias: "alias",
|
||||
method: "GET",
|
||||
template: "http://example.com/?q={searchTerms}",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "AliasEngine",
|
||||
keyword: "alias",
|
||||
});
|
||||
let engine2 = Services.search.getEngineByName("AliasEngine");
|
||||
Assert.notEqual(
|
||||
Services.search.defaultEngine,
|
||||
engine2,
|
||||
|
@ -595,8 +595,6 @@ add_task(async function() {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
await Services.search.removeEngine(engine2);
|
||||
});
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,12 +19,10 @@ add_task(async function init() {
|
|||
"browser.urlbar.tabToSearch.onboard.interactionsLeft",
|
||||
0
|
||||
);
|
||||
testEngine = await Services.search.addEngineWithDetails("Test", {
|
||||
template: "https://example.com/?search={searchTerms}",
|
||||
});
|
||||
await SearchTestUtils.installSearchExtension({ name: "Test" });
|
||||
testEngine = await Services.search.getEngineByName("Test");
|
||||
|
||||
registerCleanupFunction(async () => {
|
||||
await Services.search.removeEngine(testEngine);
|
||||
Services.prefs.clearUserPref(
|
||||
"browser.urlbar.tabToSearch.onboard.interactionsLeft"
|
||||
);
|
||||
|
@ -154,9 +152,14 @@ add_task(async function ignoreWww() {
|
|||
|
||||
// The engine has www., the history result does not.
|
||||
await PlacesTestUtils.addVisits(["https://foo.bar/"]);
|
||||
let wwwTestEngine = await Services.search.addEngineWithDetails("TestWww", {
|
||||
template: "https://www.foo.bar/?search={searchTerms}",
|
||||
});
|
||||
let extension = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "TestWww",
|
||||
search_url: "https://www.foo.bar/",
|
||||
},
|
||||
true
|
||||
);
|
||||
let wwwTestEngine = Services.search.getEngineByName("TestWww");
|
||||
context = createContext("foo", { isPrivate: false });
|
||||
await check_results({
|
||||
context,
|
||||
|
@ -211,7 +214,7 @@ add_task(async function ignoreWww() {
|
|||
});
|
||||
await cleanupPlaces();
|
||||
|
||||
await Services.search.removeEngine(wwwTestEngine);
|
||||
await extension.unload();
|
||||
});
|
||||
|
||||
// Tests that when a user's query causes autofill to replace one engine's domain
|
||||
|
@ -223,13 +226,22 @@ add_task(async function conflictingEngines() {
|
|||
"https://foo.com/",
|
||||
]);
|
||||
}
|
||||
let fooBarTestEngine = await Services.search.addEngineWithDetails(
|
||||
"TestFooBar",
|
||||
{ template: "https://foobar.com/?search={searchTerms}" }
|
||||
let extension1 = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "TestFooBar",
|
||||
search_url: "https://foobar.com/",
|
||||
},
|
||||
true
|
||||
);
|
||||
let fooTestEngine = await Services.search.addEngineWithDetails("TestFoo", {
|
||||
template: "https://foo.com/?search={searchTerms}",
|
||||
});
|
||||
let extension2 = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "TestFoo",
|
||||
search_url: "https://foo.com/",
|
||||
},
|
||||
true
|
||||
);
|
||||
let fooBarTestEngine = Services.search.getEngineByName("TestFooBar");
|
||||
let fooTestEngine = Services.search.getEngineByName("TestFoo");
|
||||
|
||||
// Search for "foo", autofilling foo.com. Observe that the foo.com
|
||||
// tab-to-search result is shown, even though the foobar.com engine was added
|
||||
|
@ -293,17 +305,21 @@ add_task(async function conflictingEngines() {
|
|||
});
|
||||
|
||||
await cleanupPlaces();
|
||||
await Services.search.removeEngine(fooTestEngine);
|
||||
await Services.search.removeEngine(fooBarTestEngine);
|
||||
await extension1.unload();
|
||||
await extension2.unload();
|
||||
});
|
||||
|
||||
add_task(async function multipleEnginesForHostname() {
|
||||
info(
|
||||
"In case of multiple engines only one tab-to-search result should be returned"
|
||||
);
|
||||
let mapsEngine = await Services.search.addEngineWithDetails("TestMaps", {
|
||||
template: "https://example.com/maps/?search={searchTerms}",
|
||||
});
|
||||
let extension = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "TestMaps",
|
||||
search_url: "https://example.com/maps/",
|
||||
},
|
||||
true
|
||||
);
|
||||
await PlacesTestUtils.addVisits(["https://example.com/"]);
|
||||
let context = createContext("examp", { isPrivate: false });
|
||||
await check_results({
|
||||
|
@ -330,7 +346,7 @@ add_task(async function multipleEnginesForHostname() {
|
|||
],
|
||||
});
|
||||
await cleanupPlaces();
|
||||
await Services.search.removeEngine(mapsEngine);
|
||||
await extension.unload();
|
||||
});
|
||||
|
||||
add_task(async function test_casing() {
|
||||
|
@ -365,9 +381,14 @@ add_task(async function test_casing() {
|
|||
|
||||
add_task(async function test_publicSuffix() {
|
||||
info("Tab-to-search results appear also in case of partial host match.");
|
||||
let engine = await Services.search.addEngineWithDetails("MyTest", {
|
||||
template: "https://test.mytest.it/?search={searchTerms}",
|
||||
});
|
||||
let extension = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "MyTest",
|
||||
search_url: "https://test.mytest.it/",
|
||||
},
|
||||
true
|
||||
);
|
||||
let engine = Services.search.getEngineByName("MyTest");
|
||||
await PlacesTestUtils.addVisits(["https://test.mytest.it/"]);
|
||||
let context = createContext("my", { isPrivate: false });
|
||||
await check_results({
|
||||
|
@ -396,14 +417,19 @@ add_task(async function test_publicSuffix() {
|
|||
],
|
||||
});
|
||||
await cleanupPlaces();
|
||||
await Services.search.removeEngine(engine);
|
||||
await extension.unload();
|
||||
});
|
||||
|
||||
add_task(async function test_publicSuffixIsHost() {
|
||||
info("Tab-to-search results does not appear in case we autofill a suffix.");
|
||||
let suffixEngine = await Services.search.addEngineWithDetails("SuffixTest", {
|
||||
template: "https://somesuffix.com.mx/?search={searchTerms}",
|
||||
});
|
||||
let extension = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "SuffixTest",
|
||||
search_url: "https://somesuffix.com.mx/",
|
||||
},
|
||||
true
|
||||
);
|
||||
|
||||
// The top level domain will be autofilled, not the full domain.
|
||||
await PlacesTestUtils.addVisits(["https://com.mx/"]);
|
||||
let context = createContext("co", { isPrivate: false });
|
||||
|
@ -421,14 +447,19 @@ add_task(async function test_publicSuffixIsHost() {
|
|||
],
|
||||
});
|
||||
await cleanupPlaces();
|
||||
await Services.search.removeEngine(suffixEngine);
|
||||
await extension.unload();
|
||||
});
|
||||
|
||||
add_task(async function test_disabledEngine() {
|
||||
info("Tab-to-search results does not appear for a Pref-disabled engine.");
|
||||
let engine = await Services.search.addEngineWithDetails("Disabled", {
|
||||
template: "https://disabled.com/?search={searchTerms}",
|
||||
});
|
||||
let extension = await SearchTestUtils.installSearchExtension(
|
||||
{
|
||||
name: "Disabled",
|
||||
search_url: "https://disabled.com/",
|
||||
},
|
||||
true
|
||||
);
|
||||
let engine = Services.search.getEngineByName("Disabled");
|
||||
await PlacesTestUtils.addVisits(["https://disabled.com/"]);
|
||||
let context = createContext("dis", { isPrivate: false });
|
||||
|
||||
|
@ -473,5 +504,5 @@ add_task(async function test_disabledEngine() {
|
|||
Services.prefs.clearUserPref("browser.search.hiddenOneOffs");
|
||||
|
||||
await cleanupPlaces();
|
||||
await Services.search.removeEngine(engine);
|
||||
await extension.unload();
|
||||
});
|
||||
|
|
|
@ -32,16 +32,15 @@ add_task(async function setup() {
|
|||
});
|
||||
|
||||
let url = "https://en.example.com/";
|
||||
let engine = await Services.search.addEngineWithDetails("TestEngine", {
|
||||
method: "GET",
|
||||
template: url,
|
||||
searchGetParams: "q={searchTerms}",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "TestEngine",
|
||||
search_url: url,
|
||||
});
|
||||
let engine = Services.search.getEngineByName("TestEngine");
|
||||
let defaultEngine = await Services.search.getDefault();
|
||||
await Services.search.setDefault(engine);
|
||||
registerCleanupFunction(async () => {
|
||||
await Services.search.setDefault(defaultEngine);
|
||||
await Services.search.removeEngine(engine);
|
||||
});
|
||||
// Make sure the engine domain would be autofilled.
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
|
@ -82,14 +81,12 @@ add_task(async function setup() {
|
|||
|
||||
info("Test a www engine");
|
||||
let url2 = "https://www.it.mochi.com/";
|
||||
let engine2 = await Services.search.addEngineWithDetails("TestEngine2", {
|
||||
method: "GET",
|
||||
template: url2,
|
||||
searchGetParams: "q={searchTerms}",
|
||||
});
|
||||
registerCleanupFunction(async () => {
|
||||
await Services.search.removeEngine(engine2);
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "TestEngine2",
|
||||
search_url: url2,
|
||||
});
|
||||
|
||||
let engine2 = Services.search.getEngineByName("TestEngine2");
|
||||
// Make sure the engine domain would be autofilled.
|
||||
await PlacesUtils.bookmarks.insert({
|
||||
url: url2,
|
||||
|
|
|
@ -6,15 +6,14 @@ let engine;
|
|||
add_task(async function test_searchEngine_autoFill() {
|
||||
Services.prefs.setBoolPref("browser.urlbar.autoFill.searchEngines", true);
|
||||
Services.prefs.setBoolPref("browser.urlbar.suggest.searches", false);
|
||||
await Services.search.addEngineWithDetails("MySearchEngine", {
|
||||
method: "GET",
|
||||
template: "http://my.search.com/",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "MySearchEngine",
|
||||
search_url: "https://my.search.com/",
|
||||
});
|
||||
engine = Services.search.getEngineByName("MySearchEngine");
|
||||
registerCleanupFunction(async () => {
|
||||
Services.prefs.clearUserPref("browser.urlbar.autoFill.searchEngines");
|
||||
Services.prefs.clearUserPref("browser.urlbar.suggest.searches");
|
||||
Services.search.removeEngine(engine);
|
||||
});
|
||||
|
||||
// Add an uri that matches the search string with high frecency.
|
||||
|
|
|
@ -25,9 +25,13 @@ add_task(async function setup() {
|
|||
|
||||
// Set a mock engine as the default so we don't hit the network below when we
|
||||
// do searches that return the default engine heuristic result.
|
||||
Services.search.defaultEngine = await Services.search.addEngineWithDetails(
|
||||
DEFAULT_ENGINE_NAME,
|
||||
{ template: "http://example.com/?s=%S" }
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: DEFAULT_ENGINE_NAME,
|
||||
search_url: "https://my.search.com/",
|
||||
});
|
||||
|
||||
Services.search.defaultEngine = Services.search.getEngineByName(
|
||||
DEFAULT_ENGINE_NAME
|
||||
);
|
||||
|
||||
// History matches should not appear with @aliases, so this visit should not
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
head = head.js
|
||||
firefox-appdir = browser
|
||||
support-files =
|
||||
data/engine.xml
|
||||
data/engine-suggestions.xml
|
||||
data/engine-tail-suggestions.xml
|
||||
|
||||
|
|
|
@ -53,6 +53,13 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
|||
UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
|
||||
});
|
||||
|
||||
const { SearchTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/SearchTestUtils.jsm"
|
||||
);
|
||||
|
||||
Services.prefs.setBoolPref("browser.search.log", true);
|
||||
SearchTestUtils.init(this);
|
||||
|
||||
const { AddonTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/AddonTestUtils.jsm"
|
||||
);
|
||||
|
@ -565,14 +572,12 @@ add_task(async function ensure_search_engine() {
|
|||
let geoPref = "browser.search.geoip.url";
|
||||
Services.prefs.setCharPref(geoPref, "");
|
||||
registerCleanupFunction(() => Services.prefs.clearUserPref(geoPref));
|
||||
// Remove any existing engines before adding ours.
|
||||
for (let engine of await Services.search.getEngines()) {
|
||||
await Services.search.removeEngine(engine);
|
||||
}
|
||||
await Services.search.addEngineWithDetails("MozSearch", {
|
||||
method: "GET",
|
||||
template: "http://s.example.com/search",
|
||||
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "MozSearch",
|
||||
search_url: "https://s.example.com/search",
|
||||
});
|
||||
|
||||
let engine = Services.search.getEngineByName("MozSearch");
|
||||
await Services.search.setDefault(engine);
|
||||
});
|
||||
|
|
|
@ -13,21 +13,22 @@ const SUGGESTIONS_ENGINE_NAME = "engine-suggestions.xml";
|
|||
add_task(async function basicGetAndPost() {
|
||||
// Note that head_autocomplete.js has already added a MozSearch engine.
|
||||
// Here we add another engine with a search alias.
|
||||
await Services.search.addEngineWithDetails("AliasedGETMozSearch", {
|
||||
alias: "get",
|
||||
method: "GET",
|
||||
template: "http://s.example.com/search",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "AliasedGETMozSearch",
|
||||
keyword: "get",
|
||||
search_url: "https://s.example.com/search",
|
||||
});
|
||||
await Services.search.addEngineWithDetails("AliasedPOSTMozSearch", {
|
||||
alias: "post",
|
||||
method: "POST",
|
||||
template: "http://s.example.com/search",
|
||||
await SearchTestUtils.installSearchExtension({
|
||||
name: "AliasedPOSTMozSearch",
|
||||
keyword: "post",
|
||||
search_url: "https://s.example.com/search",
|
||||
search_url_post_params: "q={searchTerms}",
|
||||
});
|
||||
|
||||
await PlacesTestUtils.addVisits("http://s.example.com/search?q=firefox");
|
||||
await PlacesTestUtils.addVisits("https://s.example.com/search?q=firefox");
|
||||
let historyMatch = {
|
||||
value: "http://s.example.com/search?q=firefox",
|
||||
comment: "test visit for http://s.example.com/search?q=firefox",
|
||||
value: "https://s.example.com/search?q=firefox",
|
||||
comment: "test visit for https://s.example.com/search?q=firefox",
|
||||
};
|
||||
|
||||
for (let alias of ["get", "post"]) {
|
||||
|
|
|
@ -4,19 +4,13 @@
|
|||
|
||||
const engineDomain = "s.example.com";
|
||||
add_task(async function setup() {
|
||||
let engine = await Services.search.addEngineWithDetails("SearchEngine", {
|
||||
method: "GET",
|
||||
template: `http://${engineDomain}/search`,
|
||||
searchGetParams: "q={searchTerms}",
|
||||
});
|
||||
Services.prefs.setBoolPref("browser.urlbar.restyleSearches", true);
|
||||
registerCleanupFunction(async () => {
|
||||
Services.prefs.clearUserPref("browser.urlbar.restyleSearches");
|
||||
Services.search.removeEngine(engine);
|
||||
});
|
||||
});
|
||||
add_task(async function test_searchEngine() {
|
||||
let uri = Services.io.newURI(`http://${engineDomain}/search?q=Terms`);
|
||||
let uri = Services.io.newURI(`https://${engineDomain}/search?q=Terms`);
|
||||
await PlacesTestUtils.addVisits({
|
||||
uri,
|
||||
title: "Terms - SearchEngine Search",
|
||||
|
@ -28,7 +22,7 @@ add_task(async function test_searchEngine() {
|
|||
search: "term",
|
||||
matches: [
|
||||
makeSearchMatch("Terms", {
|
||||
engineName: "SearchEngine",
|
||||
engineName: "MozSearch",
|
||||
searchSuggestion: "Terms",
|
||||
isSearchHistory: true,
|
||||
style: ["favicon"],
|
||||
|
@ -76,7 +70,7 @@ add_task(async function test_searchEngine() {
|
|||
add_task(async function test_extraneousParameters() {
|
||||
info("SERPs in history with extraneous parameters should not be restyled.");
|
||||
let uri = Services.io.newURI(
|
||||
`http://${engineDomain}/search?q=Terms&p=2&type=img`
|
||||
`https://${engineDomain}/search?q=Terms&p=2&type=img`
|
||||
);
|
||||
await PlacesTestUtils.addVisits({
|
||||
uri,
|
||||
|
|
|
@ -176,9 +176,13 @@ var SearchTestUtils = {
|
|||
false
|
||||
);
|
||||
// Only do this once.
|
||||
if (!this._initedTestUtils) {
|
||||
try {
|
||||
gTestScope.ExtensionTestUtils.init(scope);
|
||||
this._initedTestUtils = true;
|
||||
} catch (ex) {
|
||||
// This can happen if init is called twice.
|
||||
if (ex.result != Cr.NS_ERROR_FILE_ALREADY_EXISTS) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
AddonTestUtils.usePrivilegedSignatures = usePrivilegedSignatures;
|
||||
AddonTestUtils.overrideCertDB();
|
||||
|
@ -278,17 +282,19 @@ var SearchTestUtils = {
|
|||
* @param {string} [options.favicon_url]
|
||||
* The favicon to use for the search engine in the WebExtension.
|
||||
* @param {string} [options.keyword]
|
||||
* The keyword to use for the WebExtension.
|
||||
* The keyword to use for the search engine.
|
||||
* @param {string} [options.encoding]
|
||||
* The encoding to use for the WebExtension.
|
||||
* The encoding to use for the search engine.
|
||||
* @param {string} [options.search_url]
|
||||
* The search URL to use for the WebExtension.
|
||||
* The search URL to use for the search engine.
|
||||
* @param {string} [options.search_url_get_params]
|
||||
* The search URL parameters to use for the WebExtension.
|
||||
* The GET search URL parameters to use for the search engine
|
||||
* @param {string} [options.search_url_post_params]
|
||||
* The POST search URL parameters to use for the search engine
|
||||
* @param {string} [options.suggest_url]
|
||||
* The suggestion URL to use for the WebExtension.
|
||||
* The suggestion URL to use for the search engine.
|
||||
* @param {string} [options.suggest_url]
|
||||
* The suggestion URL parameters to use for the WebExtension.
|
||||
* The suggestion URL parameters to use for the search engine.
|
||||
* @returns {object}
|
||||
* The generated manifest.
|
||||
*/
|
||||
|
@ -310,11 +316,18 @@ var SearchTestUtils = {
|
|||
search_provider: {
|
||||
name: options.name,
|
||||
search_url: options.search_url ?? "https://example.com/",
|
||||
search_url_get_params:
|
||||
options.search_url_get_params ?? "?q={searchTerms}",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
if (options.search_url_post_params) {
|
||||
manifest.chrome_settings_overrides.search_provider.search_url_post_params =
|
||||
options.search_url_post_params;
|
||||
} else {
|
||||
manifest.chrome_settings_overrides.search_provider.search_url_get_params =
|
||||
options.search_url_get_params ?? "?q={searchTerms}";
|
||||
}
|
||||
|
||||
if (options.favicon_url) {
|
||||
manifest.chrome_settings_overrides.search_provider.favicon_url =
|
||||
options.favicon_url;
|
||||
|
|
Загрузка…
Ссылка в новой задаче