Commit 5a0b7478 authored by Mark Banner's avatar Mark Banner
Browse files

Bug 1600715 - Change the searchUrlParams in the modern config to be an ordered...

Bug 1600715 - Change the searchUrlParams in the modern config to be an ordered array of objects. r=mikedeboer

Differential Revision: https://phabricator.services.mozilla.com/D55640

--HG--
extra : moz-landing-system : lando
parent 2771a166
......@@ -2,7 +2,7 @@
"name": "百度",
"description": "百度网页搜索",
"manifest_version": 2,
"version": "1.0",
"version": "1.1",
"applications": {
"gecko": {
"id": "baidu@search.mozilla.org"
......@@ -20,9 +20,9 @@
"name": "百度",
"search_url": "https://www.baidu.com/baidu",
"search_form": "https://www.baidu.com/",
"search_url_get_params": "wd={searchTerms}&tn=monline_7_dg&ie=utf-8",
"search_url_get_params": "tn=monline_7_dg&ie=utf-8&wd={searchTerms}",
"suggest_url": "https://www.baidu.com/su",
"suggest_url_get_params": "wd={searchTerms}&tn=monline_7_dg&ie=utf-8&action=opensearch"
"suggest_url_get_params": "tn=monline_7_dg&ie=utf-8&action=opensearch&wd={searchTerms}"
}
}
}
\ No newline at end of file
}
......@@ -2,7 +2,7 @@
"name": "Bing",
"description": "Bing. Search by Microsoft.",
"manifest_version": 2,
"version": "1.0",
"version": "1.1",
"applications": {
"gecko": {
"id": "bing@search.mozilla.org"
......@@ -19,8 +19,8 @@
"search_provider": {
"name": "Bing",
"search_url": "https://www.bing.com/search",
"search_form": "https://www.bing.com/search?q={searchTerms}&pc=MOZI",
"search_url_get_params": "q={searchTerms}&pc=MOZI",
"search_form": "https://www.bing.com/search?pc=MOZI&q={searchTerms}",
"search_url_get_params": "pc=MOZI&q={searchTerms}",
"params": [
{
"name": "form",
......@@ -57,4 +57,4 @@
"suggest_url_get_params": "query={searchTerms}&form=OSDJAS&language={moz:locale}"
}
}
}
\ No newline at end of file
}
......@@ -13,22 +13,26 @@ add_task(async function test() {
let engine = Services.search.getEngineByName("Bing");
ok(engine, "Bing");
let base = "https://www.bing.com/search?q=foo&pc=MOZI";
let base = "https://www.bing.com/search?form={code}&pc=MOZI&q=foo";
let url;
function getUrl(code) {
return base.replace("{code}", code);
}
// Test search URLs (including purposes).
url = engine.getSubmission("foo").uri.spec;
is(url, base + "&form=MOZSBR", "Check search URL for 'foo'");
is(url, getUrl("MOZSBR"), "Check search URL for 'foo'");
url = engine.getSubmission("foo", null, "contextmenu").uri.spec;
is(url, base + "&form=MOZCON", "Check context menu search URL for 'foo'");
is(url, getUrl("MOZCON"), "Check context menu search URL for 'foo'");
url = engine.getSubmission("foo", null, "keyword").uri.spec;
is(url, base + "&form=MOZLBR", "Check keyword search URL for 'foo'");
is(url, getUrl("MOZLBR"), "Check keyword search URL for 'foo'");
url = engine.getSubmission("foo", null, "searchbar").uri.spec;
is(url, base + "&form=MOZSBR", "Check search bar search URL for 'foo'");
is(url, getUrl("MOZSBR"), "Check search bar search URL for 'foo'");
url = engine.getSubmission("foo", null, "homepage").uri.spec;
is(url, base + "&form=MOZSPG", "Check homepage search URL for 'foo'");
is(url, getUrl("MOZSPG"), "Check homepage search URL for 'foo'");
url = engine.getSubmission("foo", null, "newtab").uri.spec;
is(url, base + "&form=MOZTSB", "Check newtab search URL for 'foo'");
is(url, getUrl("MOZTSB"), "Check newtab search URL for 'foo'");
// Check search suggestion URL.
url = engine.getSubmission("foo", "application/x-suggestions+json").uri.spec;
......@@ -44,7 +48,7 @@ add_task(async function test() {
name: "Bing",
alias: null,
description: "Bing. Search by Microsoft.",
searchForm: "https://www.bing.com/search?q=&pc=MOZI",
searchForm: "https://www.bing.com/search?pc=MOZI&q=",
hidden: false,
wrappedJSObject: {
queryCharset: "UTF-8",
......@@ -54,16 +58,6 @@ add_task(async function test() {
method: "GET",
template: "https://www.bing.com/search",
params: [
{
name: "q",
value: "{searchTerms}",
purpose: undefined,
},
{
name: "pc",
value: "MOZI",
purpose: undefined,
},
{
name: "form",
value: "MOZCON",
......@@ -89,6 +83,16 @@ add_task(async function test() {
value: "MOZTSB",
purpose: "newtab",
},
{
name: "pc",
value: "MOZI",
purpose: undefined,
},
{
name: "q",
value: "{searchTerms}",
purpose: undefined,
},
],
},
{
......
......@@ -13,22 +13,26 @@ add_task(async function test() {
let engine = Services.search.getEngineByName("DuckDuckGo");
ok(engine, "DuckDuckGo");
let base = "https://duckduckgo.com/?q=foo";
let base = "https://duckduckgo.com/?t={code}&q=foo";
let url;
function getUrl(code) {
return base.replace("{code}", code);
}
// Test search URLs (including purposes).
url = engine.getSubmission("foo").uri.spec;
is(url, base + "&t=ffsb", "Check search URL for 'foo'");
is(url, getUrl("ffsb"), "Check search URL for 'foo'");
url = engine.getSubmission("foo", null, "contextmenu").uri.spec;
is(url, base + "&t=ffcm", "Check context menu search URL for 'foo'");
is(url, getUrl("ffcm"), "Check context menu search URL for 'foo'");
url = engine.getSubmission("foo", null, "keyword").uri.spec;
is(url, base + "&t=ffab", "Check keyword search URL for 'foo'");
is(url, getUrl("ffab"), "Check keyword search URL for 'foo'");
url = engine.getSubmission("foo", null, "searchbar").uri.spec;
is(url, base + "&t=ffsb", "Check search bar search URL for 'foo'");
is(url, getUrl("ffsb"), "Check search bar search URL for 'foo'");
url = engine.getSubmission("foo", null, "homepage").uri.spec;
is(url, base + "&t=ffhp", "Check homepage search URL for 'foo'");
is(url, getUrl("ffhp"), "Check homepage search URL for 'foo'");
url = engine.getSubmission("foo", null, "newtab").uri.spec;
is(url, base + "&t=ffnt", "Check newtab search URL for 'foo'");
is(url, getUrl("ffnt"), "Check newtab search URL for 'foo'");
// Check search suggestion URL.
url = engine.getSubmission("foo", "application/x-suggestions+json").uri.spec;
......@@ -53,11 +57,6 @@ add_task(async function test() {
method: "GET",
template: "https://duckduckgo.com/",
params: [
{
name: "q",
value: "{searchTerms}",
purpose: undefined,
},
{
name: "t",
value: "ffcm",
......@@ -83,6 +82,11 @@ add_task(async function test() {
value: "ffnt",
purpose: "newtab",
},
{
name: "q",
value: "{searchTerms}",
purpose: undefined,
},
],
},
{
......
......@@ -21,6 +21,7 @@ add_task(async function test() {
ok(engine, "Found Google search engine");
// Check search suggestion URL.
// This also checks that the query is on the end of the URL. See bug 1484232.
let url = engine.getSubmission("foo", "application/x-suggestions+json").uri
.spec;
is(
......
......@@ -22,23 +22,23 @@ const SEARCH_ENGINE_DETAILS = [
},
{
alias: "b",
baseURL: "https://www.bing.com/search?q=foo&pc=MOZI",
baseURL: "https://www.bing.com/search?{code}pc=MOZI&q=foo",
codes: {
context: "&form=MOZCON",
keyword: "&form=MOZLBR",
newTab: "&form=MOZTSB",
submission: "&form=MOZSBR",
context: "form=MOZCON&",
keyword: "form=MOZLBR&",
newTab: "form=MOZTSB&",
submission: "form=MOZSBR&",
},
name: "Bing",
},
{
alias: "d",
baseURL: "https://duckduckgo.com/?q=foo",
baseURL: "https://duckduckgo.com/?{code}q=foo",
codes: {
context: "&t=ffcm",
keyword: "&t=ffab",
newTab: "&t=ffnt",
submission: "&t=ffsb",
context: "t=ffcm&",
keyword: "t=ffab&",
newTab: "t=ffnt&",
submission: "t=ffsb&",
},
name: "DuckDuckGo",
},
......@@ -111,7 +111,7 @@ async function testSearchEngine(engineDetails) {
let url = engine.getSubmission("foo").uri.spec;
Assert.equal(
url,
base + engineDetails.codes.submission,
base.replace("{code}", engineDetails.codes.submission),
"Check search URL for 'foo'"
);
let sb = BrowserSearch.searchBar;
......@@ -119,7 +119,7 @@ async function testSearchEngine(engineDetails) {
let engineTests = [
{
name: "context menu search",
searchURL: base + engineDetails.codes.context,
searchURL: base.replace("{code}", engineDetails.codes.context),
run() {
// Simulate a contextmenu search
// FIXME: This is a bit "low-level"...
......@@ -134,7 +134,7 @@ async function testSearchEngine(engineDetails) {
},
{
name: "keyword search",
searchURL: base + engineDetails.codes.keyword,
searchURL: base.replace("{code}", engineDetails.codes.keyword),
run() {
gURLBar.value = "? foo";
gURLBar.focus();
......@@ -143,7 +143,7 @@ async function testSearchEngine(engineDetails) {
},
{
name: "keyword search with alias",
searchURL: base + engineDetails.codes.keyword,
searchURL: base.replace("{code}", engineDetails.codes.keyword),
run() {
gURLBar.value = `${engineDetails.alias} foo`;
gURLBar.focus();
......@@ -152,7 +152,7 @@ async function testSearchEngine(engineDetails) {
},
{
name: "search bar search",
searchURL: base + engineDetails.codes.submission,
searchURL: base.replace("{code}", engineDetails.codes.submission),
run() {
sb.focus();
sb.value = "foo";
......@@ -161,7 +161,7 @@ async function testSearchEngine(engineDetails) {
},
{
name: "new tab search",
searchURL: base + engineDetails.codes.newTab,
searchURL: base.replace("{code}", engineDetails.codes.newTab),
async preTest(tab) {
let browser = tab.linkedBrowser;
await BrowserTestUtils.loadURI(browser, "about:newtab");
......
......@@ -1445,6 +1445,17 @@ SearchEngine.prototype = {
_initEngineURLFromMetaData(type, params) {
let url = new EngineURL(type, params.method || "GET", params.template);
// Do the MozParams first, so that we are more likely to get the query
// on the end of the URL, rather than the MozParams (xref bug 1484232).
if (params.mozParams) {
for (let p of params.mozParams) {
if ((p.condition || p.purpose) && !this._isDefault) {
continue;
}
url._addMozParam(p);
}
}
if (params.postParams) {
let queries = new URLSearchParams(params.postParams);
for (let [name, value] of queries) {
......@@ -1459,15 +1470,6 @@ SearchEngine.prototype = {
}
}
if (params.mozParams) {
for (let p of params.mozParams) {
if ((p.condition || p.purpose) && !this._isDefault) {
continue;
}
url._addMozParam(p);
}
}
this._urls.push(url);
},
......
......@@ -2588,16 +2588,18 @@ SearchService.prototype = {
// Modern Config encodes params as objects whereas they are
// strings in webExtensions, stringify them here.
if ("params" in config) {
[
for (const key of [
"searchUrlGetParams",
"searchUrlPostParams",
"suggestUrlGetParams",
"suggestUrlPostParams",
].forEach(key => {
]) {
if (key in config.params) {
params[key] = new URLSearchParams(config.params[key]).toString();
params[key] = new URLSearchParams(
config.params[key].map(kv => [kv.name, kv.value])
).toString();
}
});
}
}
if ("telemetryId" in config) {
......
......@@ -189,11 +189,23 @@
}
},
"searchUrlCodes": {
"type": "object",
"type": "array",
"title": "Codes",
"description": "A map of parameter name to the parameter value.",
"additionalProperties": {
"type": "string"
"description": "A array of objects - map of parameter name to the parameter value.",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "Name",
"description": "Name of the parameter that will be used in the query"
},
"value": {
"type": "string",
"title": "Value",
"description": "The value of parameter (pref or purpose)"
}
}
}
},
"params": {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment