summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell/test_purpose.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/search/tests/xpcshell/test_purpose.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/search/tests/xpcshell/test_purpose.js')
-rw-r--r--toolkit/components/search/tests/xpcshell/test_purpose.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/toolkit/components/search/tests/xpcshell/test_purpose.js b/toolkit/components/search/tests/xpcshell/test_purpose.js
new file mode 100644
index 0000000000..7320276e4f
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_purpose.js
@@ -0,0 +1,83 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*
+ * Test that a search purpose can be specified and that query parameters for
+ * that purpose are included in the search URL.
+ */
+
+"use strict";
+
+add_task(async function setup() {
+ // The test engines used in this test need to be recognized as 'default'
+ // engines, or their MozParams used to set the purpose will be ignored.
+ await SearchTestUtils.useTestEngines();
+
+ await AddonTestUtils.promiseStartupManager();
+ await Services.search.init();
+});
+
+add_task(async function test_purpose() {
+ let engine = Services.search.getEngineByName("Test search engine");
+
+ function check_submission(aValue, aSearchTerm, aType, aPurpose) {
+ let submissionURL = engine.getSubmission(aSearchTerm, aType, aPurpose).uri
+ .spec;
+ let searchParams = new URLSearchParams(submissionURL.split("?")[1]);
+ if (aValue) {
+ Assert.equal(searchParams.get("channel"), aValue);
+ } else {
+ Assert.ok(!searchParams.has("channel"));
+ }
+ Assert.equal(searchParams.get("q"), aSearchTerm);
+ }
+
+ check_submission("", "foo");
+ check_submission("", "foo", null);
+ check_submission("", "foo", "text/html");
+ check_submission("rcs", "foo", null, "contextmenu");
+ check_submission("rcs", "foo", "text/html", "contextmenu");
+ check_submission("fflb", "foo", null, "keyword");
+ check_submission("fflb", "foo", "text/html", "keyword");
+ check_submission("", "foo", "text/html", "invalid");
+
+ // Tests for a purpose on the search form (ie. empty query).
+ engine = Services.search.getEngineByName("engine-rel-searchform-purpose");
+
+ // See bug 1485508
+ Assert.ok(!engine.searchForm.includes("?&"));
+
+ // verify that the 'system' purpose falls back to the 'searchbar' purpose.
+ check_submission("sb", "foo", "text/html", "system");
+ check_submission("sb", "foo", "text/html", "searchbar");
+});
+
+add_task(async function test_purpose() {
+ let engine = Services.search.getEngineByName(
+ "Test search engine (Reordered)"
+ );
+
+ function check_submission(aValue, aSearchTerm, aType, aPurpose) {
+ let submissionURL = engine.getSubmission(aSearchTerm, aType, aPurpose).uri
+ .spec;
+ let searchParams = new URLSearchParams(submissionURL.split("?")[1]);
+ if (aValue) {
+ Assert.equal(searchParams.get("channel"), aValue);
+ } else {
+ Assert.ok(!searchParams.has("channel"));
+ }
+ Assert.equal(searchParams.get("q"), aSearchTerm);
+ }
+
+ check_submission("", "foo");
+ check_submission("", "foo", null);
+ check_submission("", "foo", "text/html");
+ check_submission("rcs", "foo", null, "contextmenu");
+ check_submission("rcs", "foo", "text/html", "contextmenu");
+ check_submission("fflb", "foo", null, "keyword");
+ check_submission("fflb", "foo", "text/html", "keyword");
+ check_submission("", "foo", "text/html", "invalid");
+
+ // See bug 1485508
+ Assert.ok(!engine.searchForm.includes("?&"));
+});