[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor-browser] 21/179: Bug 1775312 - Add simple tests for user and policy engines. r=mak, a=RyanVM
This is an automated email from the git hooks/post-receive script.
pierov pushed a commit to branch tor-browser-102.2.0esr-12.0-1
in repository tor-browser.
commit 081fe3a04fba31b7758550fa958a6a3e5dbe1dfd
Author: Mark Banner <standard8@xxxxxxxxxxx>
AuthorDate: Wed Jun 22 10:51:13 2022 +0000
Bug 1775312 - Add simple tests for user and policy engines. r=mak, a=RyanVM
Depends on D149929
Differential Revision: https://phabricator.services.mozilla.com/D149930
---
.../search/tests/xpcshell/test_policyEngine.js | 67 ++++++++++++++++++++++
.../search/tests/xpcshell/test_userEngine.js | 56 ++++++++++++++++++
.../components/search/tests/xpcshell/xpcshell.ini | 2 +
3 files changed, 125 insertions(+)
diff --git a/toolkit/components/search/tests/xpcshell/test_policyEngine.js b/toolkit/components/search/tests/xpcshell/test_policyEngine.js
new file mode 100644
index 0000000000000..7fa83fe0bb66f
--- /dev/null
+++ b/toolkit/components/search/tests/xpcshell/test_policyEngine.js
@@ -0,0 +1,67 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/*
+ * Tests that Enterprise Policy 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_enterprise_policy_engine() {
+ let promiseEngineAdded = SearchTestUtils.promiseSearchNotification(
+ SearchUtils.MODIFIED_TYPE.ADDED,
+ SearchUtils.TOPIC_ENGINE_MODIFIED
+ );
+ await Services.search.addPolicyEngine({
+ name: "policy",
+ description: "Test policy engine",
+ iconURL: "data:image/gif;base64,R0lGODl",
+ keyword: "p",
+ search_url: "https://example.com?q={searchTerms}",
+ suggest_url: "https://example.com/suggest/?q={searchTerms}",
+ });
+ await promiseEngineAdded;
+
+ let engine = Services.search.getEngineByName("policy");
+ Assert.ok(engine, "Should have installed the engine.");
+
+ Assert.equal(engine.name, "policy", "Should have the correct name");
+ Assert.equal(
+ engine.description,
+ "Test policy engine",
+ "Should have a description"
+ );
+ Assert.deepEqual(engine.aliases, ["p"], "Should have the correct alias");
+
+ let submission = engine.getSubmission("foo");
+ Assert.equal(
+ submission.uri.spec,
+ "https://example.com/?q=foo",
+ "Should have the correct search url"
+ );
+
+ submission = engine.getSubmission("foo", SearchUtils.URL_TYPE.SUGGEST_JSON);
+ Assert.equal(
+ submission.uri.spec,
+ "https://example.com/suggest/?q=foo",
+ "Should have the correct suggest url"
+ );
+
+ Services.search.defaultEngine = engine;
+
+ await assertGleanDefaultEngine({
+ normal: {
+ engineId: "other-policy",
+ displayName: "policy",
+ loadPath: "[other]addEngineWithDetails:set-via-policy",
+ submissionUrl: "blank:",
+ verified: "verified",
+ },
+ });
+});
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 0000000000000..98e880747e747
--- /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: "[other]addEngineWithDetails:set-via-user",
+ submissionUrl: "blank:",
+ verified: "verified",
+ },
+ });
+});
diff --git a/toolkit/components/search/tests/xpcshell/xpcshell.ini b/toolkit/components/search/tests/xpcshell/xpcshell.ini
index bd8d062f42767..56b2fa9721624 100644
--- a/toolkit/components/search/tests/xpcshell/xpcshell.ini
+++ b/toolkit/components/search/tests/xpcshell/xpcshell.ini
@@ -170,6 +170,7 @@ skip-if =
skip-if =
debug && socketprocess_networking # Bug 1759035
(os == "mac" || os == "win") && socketprocess_networking # Bug 1759035
+[test_policyEngine.js]
[test_pref.js]
[test_purpose.js]
[test_region_params.js]
@@ -215,6 +216,7 @@ skip-if =
[test_settings.js]
[test_sort_orders-no-hints.js]
[test_sort_orders.js]
+[test_userEngine.js]
[test_validate_engines.js]
[test_validate_manifests.js]
[test_webextensions_builtin_upgrade.js]
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits