-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1775312 - Add simple tests for user and policy engines. r=mak
Depends on D149929 Differential Revision: https://phabricator.services.mozilla.com/D149930
- Loading branch information
Showing
3 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
toolkit/components/search/tests/xpcshell/test_policyEngine.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
toolkit/components/search/tests/xpcshell/test_userEngine.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters