summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell/test_userEngine.js
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/search/tests/xpcshell/test_userEngine.js')
-rw-r--r--toolkit/components/search/tests/xpcshell/test_userEngine.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/toolkit/components/search/tests/xpcshell/test_userEngine.js b/toolkit/components/search/tests/xpcshell/test_userEngine.js
new file mode 100644
index 0000000000..659baf10ab
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_userEngine.js
@@ -0,0 +1,56 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*
+ * Tests that User Engines can be installed correctly.
+ */
+
+"use strict";
+
+add_task(async function setup() {
+ Services.fog.initializeFOG();
+ await AddonTestUtils.promiseStartupManager();
+ await Services.search.init();
+});
+
+add_task(async function test_user_engine() {
+ let promiseEngineAdded = SearchTestUtils.promiseSearchNotification(
+ SearchUtils.MODIFIED_TYPE.ADDED,
+ SearchUtils.TOPIC_ENGINE_MODIFIED
+ );
+ await Services.search.addUserEngine(
+ "user",
+ "https://example.com/user?q={searchTerms}",
+ "u"
+ );
+ await promiseEngineAdded;
+
+ let engine = Services.search.getEngineByName("user");
+ Assert.ok(engine, "Should have installed the engine.");
+
+ Assert.equal(engine.name, "user", "Should have the correct name");
+ Assert.equal(engine.description, null, "Should not have a description");
+ Assert.deepEqual(engine.aliases, ["u"], "Should have the correct alias");
+
+ let submission = engine.getSubmission("foo");
+ Assert.equal(
+ submission.uri.spec,
+ "https://example.com/user?q=foo",
+ "Should have the correct search url"
+ );
+
+ submission = engine.getSubmission("foo", SearchUtils.URL_TYPE.SUGGEST_JSON);
+ Assert.equal(submission, null, "Should not have a suggest url");
+
+ Services.search.defaultEngine = engine;
+
+ await assertGleanDefaultEngine({
+ normal: {
+ engineId: "other-user",
+ displayName: "user",
+ loadPath: "[user]",
+ submissionUrl: "blank:",
+ verified: "verified",
+ },
+ });
+});