Skip to content

Commit

Permalink
Bug 1775312 - Add simple tests for user and policy engines. r=mak
Browse files Browse the repository at this point in the history
Depends on D149929

Differential Revision: https://phabricator.services.mozilla.com/D149930
  • Loading branch information
Standard8 committed Jun 22, 2022
1 parent c362058 commit 5526fff
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
67 changes: 67 additions & 0 deletions toolkit/components/search/tests/xpcshell/test_policyEngine.js
Original file line number Diff line number Diff line change
@@ -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",
},
});
});
56 changes: 56 additions & 0 deletions toolkit/components/search/tests/xpcshell/test_userEngine.js
Original file line number Diff line number Diff line change
@@ -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",
},
});
});
2 changes: 2 additions & 0 deletions toolkit/components/search/tests/xpcshell/xpcshell.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 5526fff

Please sign in to comment.