diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /toolkit/components/search/tests/xpcshell/data/engineMaker.sjs | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'toolkit/components/search/tests/xpcshell/data/engineMaker.sjs')
-rw-r--r-- | toolkit/components/search/tests/xpcshell/data/engineMaker.sjs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/toolkit/components/search/tests/xpcshell/data/engineMaker.sjs b/toolkit/components/search/tests/xpcshell/data/engineMaker.sjs new file mode 100644 index 000000000..4c432e7ee --- /dev/null +++ b/toolkit/components/search/tests/xpcshell/data/engineMaker.sjs @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components; + +/** + * Dynamically create a search engine offering search suggestions via searchSuggestions.sjs. + * + * The engine is constructed by passing a JSON object with engine datails as the query string. + */ + +function handleRequest(request, response) { + let engineData = JSON.parse(unescape(request.queryString).replace("+", " ")); + + if (!engineData.baseURL) { + response.setStatusLine(request.httpVersion, 500, "baseURL required"); + return; + } + + engineData.name = engineData.name || "Generated test engine"; + engineData.description = engineData.description || "Generated test engine description"; + engineData.method = engineData.method || "GET"; + + response.setStatusLine(request.httpVersion, 200, "OK"); + createOpenSearchEngine(response, engineData); +} + +/** + * Create an OpenSearch engine for the given base URL. + */ +function createOpenSearchEngine(response, engineData) { + let params = "", queryString = ""; + if (engineData.method == "POST") { + params = "<Param name='q' value='{searchTerms}'/>"; + } else { + queryString = "?q={searchTerms}"; + } + + let result = "<?xml version='1.0' encoding='utf-8'?>\ +<OpenSearchDescription xmlns='http://a9.com/-/spec/opensearch/1.1/'>\ + <ShortName>" + engineData.name + "</ShortName>\ + <Description>" + engineData.description + "</Description>\ + <InputEncoding>UTF-8</InputEncoding>\ + <LongName>" + engineData.name + "</LongName>\ + <Url type='application/x-suggestions+json' method='" + engineData.method + "'\ + template='" + engineData.baseURL + "searchSuggestions.sjs" + queryString + "'>\ + " + params + "\ + </Url>\ + <Url type='text/html' method='" + engineData.method + "'\ + template='" + engineData.baseURL + queryString + "'/>\ +</OpenSearchDescription>\ +"; + response.write(result); +} |