Bug 1643004 - Move searchform test into other tests for OpenSearch/WebExtension engines. r=daleharvey

Differential Revision: https://phabricator.services.mozilla.com/D78714
This commit is contained in:
Mark Banner 2020-06-09 11:57:41 +00:00
Родитель 4ca58150de
Коммит 2e3146fbf2
12 изменённых файлов: 19 добавлений и 86 удалений

Просмотреть файл

@ -10,6 +10,7 @@ const { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm");
let delay = () => new Promise(resolve => setTimeout(resolve, 0));
const kSearchFormURL = "https://example.com/searchform";
const kSearchEngineURL = "https://example.com/?search={searchTerms}";
const kSearchSuggestURL = "https://example.com/?suggest={searchTerms}";
const kSearchTerm = "foo";
@ -43,6 +44,7 @@ add_task(async function test_extension_adding_engine() {
search_provider: {
name: "MozSearch",
keyword: "MozSearch",
search_form: kSearchFormURL,
search_url: kSearchEngineURL,
suggest_url: kSearchSuggestURL,
},
@ -89,6 +91,7 @@ add_task(async function test_extension_adding_engine() {
"Suggest URLs should match"
);
equal(engine.searchForm, kSearchFormURL, "Search form URLs should match");
await ext1.unload();
await delay();

Просмотреть файл

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>engine-rel-searchform-post.xml</ShortName>
<Url type="text/html" method="POST" template="http://engine-rel-searchform-post.xml/POST" rel="searchform"/>
<SearchForm>http://engine-rel-searchform-post.xml/?search</SearchForm>
</SearchPlugin>

Просмотреть файл

@ -1,17 +0,0 @@
{
"name": "engine-rel-searchform-post.xml",
"manifest_version": 2,
"version": "1.0",
"applications": {
"gecko": {
"id": "engine-rel-searchform-post@search.mozilla.org"
}
},
"hidden": true,
"chrome_settings_overrides": {
"search_provider": {
"name": "engine-rel-searchform-post.xml",
"search_url": "https://engine-rel-searchform-post.xml/POST"
}
}
}

Просмотреть файл

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>engine-rel-searchform.xml</ShortName>
<Url type="text/html" method="GET" template="http://engine-rel-searchform.xml/?search" rel="searchform"/>
</SearchPlugin>

Просмотреть файл

@ -1,17 +0,0 @@
{
"name": "engine-rel-searchform.xml",
"manifest_version": 2,
"version": "1.0",
"applications": {
"gecko": {
"id": "engine-rel-searchform@search.mozilla.org"
}
},
"hidden": true,
"chrome_settings_overrides": {
"search_provider": {
"name": "engine-rel-searchform.xml",
"search_url": "https://engine-rel-searchform.xml/?search"
}
}
}

Просмотреть файл

@ -3,4 +3,6 @@
<Url type="text/html" method="POST" template="https://example.com/post">
<Param name="searchterms" value="{searchTerms}"/>
</Url>
<Url type="text/html" method="POST" template="http://engine-rel-searchform-post.xml/POST" rel="searchform"/>
<SearchForm>http://engine-rel-searchform-post.xml/?search</SearchForm>
</OpenSearchDescription>

Просмотреть файл

@ -11,6 +11,5 @@
template="https://example.com/suggest">
<Param name="suggestion" value="{searchTerms}"/>
</Url>
<SearchForm>https://example.com/</SearchForm>
<Url type="text/html" method="GET" template="http://engine-rel-searchform.xml/?search" rel="searchform"/>
</OpenSearchDescription>

Просмотреть файл

@ -17,12 +17,16 @@ const tests = [
file: "simple.xml",
name: "simple",
description: "A small test engine",
searchForm: "https://example.com/",
searchUrl: "https://example.com/search?q=foo",
},
{
file: "post.xml",
name: "Post",
description: "",
// The POST method is not supported for `rel="searchform"` so we fallback
// to the `SearchForm` url.
searchForm: "http://engine-rel-searchform-post.xml/?search",
searchUrl: "https://example.com/post",
searchPostData: "searchterms=foo",
},
@ -30,6 +34,7 @@ const tests = [
file: "suggestion.xml",
name: "suggestion",
description: "A small engine with suggestions",
searchForm: "http://engine-rel-searchform.xml/?search",
searchUrl: "https://example.com/search?q=foo",
suggestUrl: "https://example.com/suggest?suggestion=foo",
},
@ -37,6 +42,7 @@ const tests = [
file: "suggestion-alternate.xml",
name: "suggestion-alternate",
description: "A small engine with suggestions",
searchForm: "https://example.com/",
searchUrl: "https://example.com/search?q=foo",
suggestUrl: "https://example.com/suggest?suggestion=foo",
},
@ -44,6 +50,7 @@ const tests = [
file: "mozilla-ns.xml",
name: "mozilla-ns",
description: "An engine using mozilla namespace",
searchForm: "https://example.com/",
// mozilla-ns.xml also specifies a MozParam. However, they are only
// valid for app-provided engines, and hence the param should not show
// here.
@ -104,6 +111,12 @@ for (const test of tests) {
);
}
Assert.equal(
engine.searchForm,
test.searchForm,
"Should have the correct search form url"
);
submission = engine.getSubmission("foo", SearchUtils.URL_TYPE.SUGGEST_JSON);
if (test.suggestUrl) {
Assert.equal(

Просмотреть файл

@ -1,30 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/*
* Tests that <Url rel="searchform"/> is properly recognized as a searchForm.
*/
"use strict";
add_task(async function setup() {
useHttpServer();
await AddonTestUtils.promiseStartupManager();
});
add_task(async function test_rel_searchform() {
let engineNames = [
"engine-rel-searchform.xml",
"engine-rel-searchform-post.xml",
];
// The final searchForm of the engine should be a URL whose domain is the
// <ShortName> in the engine's XML and that has a ?search parameter. The
// point of the ?search parameter is to avoid accidentally matching the value
// returned as a last resort by Engine's searchForm getter, which is simply
// the prePath of the engine's first HTML <Url>.
let items = engineNames.map(e => ({ name: e, xmlFileName: e }));
for (let engine of await addTestEngines(items)) {
Assert.equal(engine.searchForm, "http://" + engine.name + "/?search");
}
});

Просмотреть файл

@ -60,7 +60,6 @@ support-files =
[test_parseSubmissionURL.js]
[test_pref.js]
[test_purpose.js]
[test_rel_searchform.js]
[test_require_engines_in_cache.js]
[test_remove_profile_engine.js]
[test_resultDomain.js]

Просмотреть файл

@ -21,10 +21,6 @@ support-files =
data/engine-reordered/manifest.json
data/engineMaker.sjs
data/engine-pref/manifest.json
data/engine-rel-searchform/manifest.json
data/engine-rel-searchform.xml
data/engine-rel-searchform-post/manifest.json
data/engine-rel-searchform-post.xml
data/engine-rel-searchform-purpose/manifest.json
data/engine-system-purpose/manifest.json
data/engineImages.xml

Просмотреть файл

@ -21,10 +21,6 @@ support-files =
data/engine-reordered/manifest.json
data/engineMaker.sjs
data/engine-pref/manifest.json
data/engine-rel-searchform/manifest.json
data/engine-rel-searchform.xml
data/engine-rel-searchform-post/manifest.json
data/engine-rel-searchform-post.xml
data/engine-rel-searchform-purpose/manifest.json
data/engine-system-purpose/manifest.json
data/engineImages.xml