Backed out 6 changesets (bug 1445134) for causing xpcshell failures. CLOSED TREE

Backed out changeset 59f902b761b5 (bug 1445134)
Backed out changeset 2ec41e23c593 (bug 1445134)
Backed out changeset b0dc583fff47 (bug 1445134)
Backed out changeset a09ccaf19501 (bug 1445134)
Backed out changeset 2d736481d13d (bug 1445134)
Backed out changeset 57ec56757493 (bug 1445134)
This commit is contained in:
Butkovits Atila 2022-10-17 17:54:39 +03:00
Родитель 708068a79f
Коммит 86c65085e5
19 изменённых файлов: 755 добавлений и 837 удалений

Просмотреть файл

@ -2007,10 +2007,6 @@ export var Policies = {
},
onAllWindowsRestored(manager, param) {
Services.search.init().then(async () => {
// Adding of engines is handled by the SearchService in the init().
// Remove can happen after those are added - no engines are allowed
// to replace the application provided engines, even if they have been
// removed.
if (param.Remove) {
// Only rerun if the list of engine names has changed.
await runOncePerModification(
@ -2030,6 +2026,46 @@ export var Policies = {
}
);
}
if (param.Add) {
// Rerun if any engine info has changed.
let engineInfoHash = md5Hash(JSON.stringify(param.Add));
await runOncePerModification(
"addSearchEngines",
engineInfoHash,
async function() {
for (let newEngine of param.Add) {
let manifest = {
description: newEngine.Description,
iconURL: newEngine.IconURL ? newEngine.IconURL.href : null,
name: newEngine.Name,
// If the encoding is not specified or is falsy, the
// search service will fall back to the default encoding.
encoding: newEngine.Encoding,
search_url: encodeURI(newEngine.URLTemplate),
keyword: newEngine.Alias,
search_url_post_params:
newEngine.Method == "POST" ? newEngine.PostData : undefined,
suggest_url: newEngine.SuggestURLTemplate,
};
let engine = Services.search.getEngineByName(newEngine.Name);
if (engine) {
try {
await Services.search.updatePolicyEngine(manifest);
} catch (ex) {
lazy.log.error("Unable to update the search engine", ex);
}
} else {
try {
await Services.search.addPolicyEngine(manifest);
} catch (ex) {
lazy.log.error("Unable to add search engine", ex);
}
}
}
}
);
}
if (param.Default) {
await runOncePerModification(
"setDefaultSearchEngine",
@ -2764,3 +2800,32 @@ function processMIMEInfo(mimeInfo, realMIMEInfo) {
}
lazy.gHandlerService.store(realMIMEInfo);
}
// Copied from PlacesUIUtils.jsm
// Keep a hasher for repeated hashings
let gCryptoHash = null;
/**
* Run some text through md5 and return the base64 result.
* @param {string} data The string to hash.
* @returns {string} md5 hash of the input string.
*/
function md5Hash(data) {
// Lazily create a reusable hasher
if (gCryptoHash === null) {
gCryptoHash = Cc["@mozilla.org/security/hash;1"].createInstance(
Ci.nsICryptoHash
);
}
gCryptoHash.init(gCryptoHash.MD5);
// Convert the data to a byte array for hashing
gCryptoHash.update(
data.split("").map(c => c.charCodeAt(0)),
data.length
);
// Request the has result as ASCII base64
return gCryptoHash.finish(true);
}

Просмотреть файл

@ -2,9 +2,15 @@
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
ChromeUtils.defineESModuleGetters(this, {
SearchTestUtils: "resource://testing-common/SearchTestUtils.sys.mjs",
SearchUtils: "resource://gre/modules/SearchUtils.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(this, {
CustomizableUITestUtils:
"resource://testing-common/CustomizableUITestUtils.jsm",
TelemetryTestUtils: "resource://testing-common/TelemetryTestUtils.jsm",
});
let gCUITestUtils = new CustomizableUITestUtils(window);
@ -59,6 +65,217 @@ async function test_opensearch(shouldWork) {
await BrowserTestUtils.removeTab(tab);
}
add_task(async function test_install_and_set_default() {
Services.telemetry.clearEvents();
Services.fog.testResetFOG();
// Make sure we are starting in an expected state to avoid false positive
// test results.
let prevEngine = await Services.search.getDefault();
isnot(
prevEngine.name,
"MozSearch",
"Default search engine should not be MozSearch when test starts"
);
is(
Services.search.getEngineByName("Foo"),
null,
'Engine "Foo" should not be present when test starts'
);
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Add: [
{
Name: "MozSearch",
URLTemplate: "http://example.com/?q={searchTerms}",
},
],
Default: "MozSearch",
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
// If this passes, it means that the new search engine was properly installed
// *and* was properly set as the default.
is(
(await Services.search.getDefault()).name,
"MozSearch",
"Specified search engine should be the default"
);
TelemetryTestUtils.assertEvents(
[
{
object: "change_default",
value: "enterprise",
extra: {
prev_id: prevEngine.telemetryId,
new_id: "other-MozSearch",
new_name: "MozSearch",
new_load_path: "[other]addEngineWithDetails:set-via-policy",
new_sub_url: "",
},
},
],
{ category: "search", method: "engine" }
);
let snapshot = await Glean.searchEngineDefault.changed.testGetValue();
delete snapshot[0].timestamp;
Assert.deepEqual(
snapshot[0],
{
category: "search.engine.default",
name: "changed",
extra: {
change_source: "enterprise",
previous_engine_id: prevEngine.telemetryId,
new_engine_id: "other-MozSearch",
new_display_name: "MozSearch",
new_load_path: "[other]addEngineWithDetails:set-via-policy",
new_submission_url: "",
},
},
"Should have received the correct event details"
);
// Clean up
await Services.search.removeEngine(await Services.search.getDefault());
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_and_set_default_private() {
Services.telemetry.clearEvents();
Services.fog.testResetFOG();
// Make sure we are starting in an expected state to avoid false positive
// test results.
let prevEngine = await Services.search.getDefaultPrivate();
isnot(
prevEngine.name,
"MozSearch",
"Default search engine should not be MozSearch when test starts"
);
is(
Services.search.getEngineByName("Foo"),
null,
'Engine "Foo" should not be present when test starts'
);
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Add: [
{
Name: "MozSearch",
URLTemplate: "http://example.com/?q={searchTerms}",
},
],
DefaultPrivate: "MozSearch",
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
// If this passes, it means that the new search engine was properly installed
// *and* was properly set as the default.
is(
(await Services.search.getDefaultPrivate()).name,
"MozSearch",
"Specified search engine should be the default private engine"
);
TelemetryTestUtils.assertEvents(
[
{
// TODO: Bug 1791658 - this should be `change_private` but this test
// is not currently properly testing setting of the default private engine.
object: "change_default",
value: "enterprise",
extra: {
prev_id: prevEngine.telemetryId,
new_id: "other-MozSearch",
new_name: "MozSearch",
new_load_path: "[other]addEngineWithDetails:set-via-policy",
new_sub_url: "",
},
},
],
{ category: "search", method: "engine" }
);
let snapshot = await Glean.searchEngineDefault.changed.testGetValue();
delete snapshot[0].timestamp;
Assert.deepEqual(
snapshot[0],
{
// TODO: Bug 1791658 - this should be `search.engine.private` but this test
// is not currently properly testing setting of the default private engine.
category: "search.engine.default",
name: "changed",
extra: {
change_source: "enterprise",
previous_engine_id: prevEngine.telemetryId,
new_engine_id: "other-MozSearch",
new_display_name: "MozSearch",
new_load_path: "[other]addEngineWithDetails:set-via-policy",
new_submission_url: "",
},
},
"Should have received the correct event details"
);
// Clean up
await Services.search.removeEngine(await Services.search.getDefaultPrivate());
EnterprisePolicyTesting.resetRunOnceState();
});
// Same as the last test, but with "PreventInstalls" set to true to make sure
// it does not prevent search engines from being installed properly
add_task(async function test_install_and_set_default_prevent_installs() {
isnot(
(await Services.search.getDefault()).name,
"MozSearch",
"Default search engine should not be MozSearch when test starts"
);
is(
Services.search.getEngineByName("Foo"),
null,
'Engine "Foo" should not be present when test starts'
);
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Add: [
{
Name: "MozSearch",
URLTemplate: "http://example.com/?q={searchTerms}",
},
],
Default: "MozSearch",
PreventInstalls: true,
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
is(
(await Services.search.getDefault()).name,
"MozSearch",
"Specified search engine should be the default"
);
// Clean up
await Services.search.removeEngine(await Services.search.getDefault());
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_opensearch_works() {
// Clear out policies so we can test with no policies applied
await setupPolicyEngineWithJson({
@ -110,3 +327,284 @@ add_task(async function test_opensearch_disabled() {
// Check that search engines cannot be added via opensearch
await test_opensearch(false);
});
add_task(async function test_install_and_remove() {
let iconURL =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=";
is(
Services.search.getEngineByName("Foo"),
null,
'Engine "Foo" should not be present when test starts'
);
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Add: [
{
Name: "Foo",
URLTemplate: "http://example.com/?q={searchTerms}",
IconURL: iconURL,
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
// If this passes, it means that the new search engine was properly installed
let engine = Services.search.getEngineByName("Foo");
isnot(engine, null, "Specified search engine should be installed");
is(engine.wrappedJSObject.iconURI.spec, iconURL, "Icon should be present");
is(engine.wrappedJSObject.queryCharset, "UTF-8", "Should default to utf-8");
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Remove: ["Foo"],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
// If this passes, it means that the specified engine was properly removed
is(
Services.search.getEngineByName("Foo"),
null,
"Specified search engine should not be installed"
);
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_post_method_engine() {
is(
Services.search.getEngineByName("Post"),
null,
'Engine "Post" should not be present when test starts'
);
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Add: [
{
Name: "Post",
Method: "POST",
PostData: "q={searchTerms}&anotherParam=yes",
URLTemplate: "http://example.com/",
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
let engine = Services.search.getEngineByName("Post");
isnot(engine, null, "Specified search engine should be installed");
is(engine.wrappedJSObject._urls[0].method, "POST", "Method should be POST");
let submission = engine.getSubmission("term", "text/html");
isnot(submission.postData, null, "Post data should not be null");
let scriptableInputStream = Cc[
"@mozilla.org/scriptableinputstream;1"
].createInstance(Ci.nsIScriptableInputStream);
scriptableInputStream.init(submission.postData);
is(
scriptableInputStream.read(scriptableInputStream.available()),
"q=term&anotherParam=yes",
"Post data should be present"
);
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Remove: ["Post"],
},
},
});
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_with_encoding() {
// Make sure we are starting in an expected state to avoid false positive
// test results.
is(
Services.search.getEngineByName("Encoding"),
null,
'Engine "Encoding" should not be present when test starts'
);
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Add: [
{
Name: "Encoding",
Encoding: "windows-1252",
URLTemplate: "http://example.com/?q={searchTerms}",
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
let engine = Services.search.getEngineByName("Encoding");
is(
engine.wrappedJSObject.queryCharset,
"windows-1252",
"Should have correct encoding"
);
// Clean up
await Services.search.removeEngine(engine);
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_and_update() {
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Add: [
{
Name: "ToUpdate",
URLTemplate: "http://initial.example.com/?q={searchTerms}",
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
let engine = Services.search.getEngineByName("ToUpdate");
isnot(engine, null, "Specified search engine should be installed");
is(
engine.getSubmission("test").uri.spec,
"http://initial.example.com/?q=test",
"Initial submission URL should be correct."
);
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Add: [
{
Name: "ToUpdate",
URLTemplate: "http://update.example.com/?q={searchTerms}",
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
is(
engine.getSubmission("test").uri.spec,
"http://update.example.com/?q=test",
"Updated Submission URL should be correct."
);
// Clean up
await Services.search.removeEngine(engine);
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_with_suggest() {
// Make sure we are starting in an expected state to avoid false positive
// test results.
is(
Services.search.getEngineByName("Suggest"),
null,
'Engine "Suggest" should not be present when test starts'
);
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Add: [
{
Name: "Suggest",
URLTemplate: "http://example.com/?q={searchTerms}",
SuggestURLTemplate: "http://suggest.example.com/?q={searchTerms}",
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
let engine = Services.search.getEngineByName("Suggest");
is(
engine.getSubmission("test", "application/x-suggestions+json").uri.spec,
"http://suggest.example.com/?q=test",
"Updated Submission URL should be correct."
);
// Clean up
await Services.search.removeEngine(engine);
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_reset_default() {
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Remove: ["DuckDuckGo"],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
let engine = Services.search.getEngineByName("DuckDuckGo");
is(engine.hidden, true, "Application specified engine should be hidden.");
await BrowserTestUtils.withNewTab(
"about:preferences#search",
async browser => {
let tree = browser.contentDocument.querySelector("#engineList");
for (let i = 0; i < tree.view.rowCount; i++) {
let cellName = tree.view.getCellText(
i,
tree.columns.getNamedColumn("engineName")
);
isnot(cellName, "DuckDuckGo", "DuckDuckGo should be invisible");
}
let restoreDefaultsButton = browser.contentDocument.getElementById(
"restoreDefaultSearchEngines"
);
let updatedPromise = SearchTestUtils.promiseSearchNotification(
SearchUtils.MODIFIED_TYPE.CHANGED,
SearchUtils.TOPIC_ENGINE_MODIFIED
);
restoreDefaultsButton.click();
await updatedPromise;
for (let i = 0; i < tree.view.rowCount; i++) {
let cellName = tree.view.getCellText(
i,
tree.columns.getNamedColumn("engineName")
);
isnot(cellName, "DuckDuckGo", "DuckDuckGo should be invisible");
}
}
);
engine.hidden = false;
EnterprisePolicyTesting.resetRunOnceState();
});

Просмотреть файл

@ -4,14 +4,9 @@
"use strict";
const lazy = {};
const { Preferences } = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm"
);
const { SearchSettings } = ChromeUtils.importESModule(
"resource://gre/modules/SearchSettings.sys.mjs"
);
const { updateAppInfo, getAppInfo } = ChromeUtils.import(
"resource://testing-common/AppInfo.jsm"
);
@ -21,9 +16,6 @@ const { FileTestUtils } = ChromeUtils.import(
const { PermissionTestUtils } = ChromeUtils.import(
"resource://testing-common/PermissionTestUtils.jsm"
);
ChromeUtils.defineESModuleGetters(lazy, {
SearchTestUtils: "resource://testing-common/SearchTestUtils.sys.mjs",
});
const { EnterprisePolicyTesting } = ChromeUtils.importESModule(
"resource://testing-common/EnterprisePolicyTesting.sys.mjs"
);
@ -41,8 +33,6 @@ let policies = Cc["@mozilla.org/enterprisepolicies;1"].getService(
);
policies.observe(null, "policies-startup", null);
SearchSettings.SETTINGS_INVALIDATION_DELAY = 100;
async function setupPolicyEngineWithJson(json, customSchema) {
if (typeof json != "object") {
let filePath = do_get_file(json ? json : "non-existing-file.json").path;
@ -54,34 +44,6 @@ async function setupPolicyEngineWithJson(json, customSchema) {
return EnterprisePolicyTesting.setupPolicyEngineWithJson(json, customSchema);
}
/**
* Loads a new enterprise policy, and re-initialise the search service
* with the new policy. Also waits for the search service to write the settings
* file to disk.
*
* @param {object} policy
* The enterprise policy to use.
* @param {object} customSchema
* A custom schema to use to validate the enterprise policy.
*/
async function setupPolicyEngineWithJsonWithSearch(json, customSchema) {
Services.search.wrappedJSObject.reset();
if (typeof json != "object") {
let filePath = do_get_file(json ? json : "non-existing-file.json").path;
await EnterprisePolicyTesting.setupPolicyEngineWithJson(
filePath,
customSchema
);
} else {
await EnterprisePolicyTesting.setupPolicyEngineWithJson(json, customSchema);
}
let settingsWritten = lazy.SearchTestUtils.promiseSearchNotification(
"write-settings-to-disk-complete"
);
await Services.search.init();
return settingsWritten;
}
function checkLockedPref(prefName, prefValue) {
equal(
Preferences.locked(prefName),

Просмотреть файл

@ -1,490 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { SearchTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/SearchTestUtils.sys.mjs"
);
const { TestUtils } = ChromeUtils.import(
"resource://testing-common/TestUtils.jsm"
);
var { AddonTestUtils } = ChromeUtils.import(
"resource://testing-common/AddonTestUtils.jsm"
);
Services.prefs.setBoolPref("browser.search.log", true);
SearchTestUtils.init(this);
AddonTestUtils.init(this, false);
AddonTestUtils.createAppInfo(
"xpcshell@tests.mozilla.org",
"XPCShell",
"48",
"48"
);
add_setup(async () => {
await AddonTestUtils.promiseStartupManager();
await Services.search.init();
console.log("done init");
});
add_task(async function test_install_and_set_default() {
// Make sure we are starting in an expected state to avoid false positive
// test results.
Assert.notEqual(
(await Services.search.getDefault()).name,
"MozSearch",
"Default search engine should not be MozSearch when test starts"
);
Assert.equal(
Services.search.getEngineByName("Foo"),
null,
'Engine "Foo" should not be present when test starts'
);
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Add: [
{
Name: "MozSearch",
URLTemplate: "http://example.com/?q={searchTerms}",
},
],
Default: "MozSearch",
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
// If this passes, it means that the new search engine was properly installed
// *and* was properly set as the default.
Assert.equal(
(await Services.search.getDefault()).name,
"MozSearch",
"Specified search engine should be the default"
);
// Clean up
await setupPolicyEngineWithJsonWithSearch({});
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_and_set_default_private() {
// Make sure we are starting in an expected state to avoid false positive
// test results.
Assert.notEqual(
(await Services.search.getDefaultPrivate()).name,
"MozSearch",
"Default search engine should not be MozSearch when test starts"
);
Assert.equal(
Services.search.getEngineByName("Foo"),
null,
'Engine "Foo" should not be present when test starts'
);
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Add: [
{
Name: "MozSearch",
URLTemplate: "http://example.com/?q={searchTerms}",
},
],
DefaultPrivate: "MozSearch",
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
// If this passes, it means that the new search engine was properly installed
// *and* was properly set as the default.
Assert.equal(
(await Services.search.getDefaultPrivate()).name,
"MozSearch",
"Specified search engine should be the default private engine"
);
// Clean up
await setupPolicyEngineWithJsonWithSearch({});
EnterprisePolicyTesting.resetRunOnceState();
});
// Same as the last test, but with "PreventInstalls" set to true to make sure
// it does not prevent search engines from being installed properly
add_task(async function test_install_and_set_default_prevent_installs() {
Assert.notEqual(
(await Services.search.getDefault()).name,
"MozSearch",
"Default search engine should not be MozSearch when test starts"
);
Assert.equal(
Services.search.getEngineByName("Foo"),
null,
'Engine "Foo" should not be present when test starts'
);
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Add: [
{
Name: "MozSearch",
URLTemplate: "http://example.com/?q={searchTerms}",
},
],
Default: "MozSearch",
PreventInstalls: true,
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
Assert.equal(
(await Services.search.getDefault()).name,
"MozSearch",
"Specified search engine should be the default"
);
// Clean up
await setupPolicyEngineWithJsonWithSearch({});
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_and_remove() {
let iconURL =
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=";
Assert.equal(
Services.search.getEngineByName("Foo"),
null,
'Engine "Foo" should not be present when test starts'
);
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Add: [
{
Name: "Foo",
URLTemplate: "http://example.com/?q={searchTerms}",
IconURL: iconURL,
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
// If this passes, it means that the new search engine was properly installed
let engine = Services.search.getEngineByName("Foo");
Assert.notEqual(engine, null, "Specified search engine should be installed");
Assert.equal(
engine.wrappedJSObject.iconURI.spec,
iconURL,
"Icon should be present"
);
Assert.equal(
engine.wrappedJSObject.queryCharset,
"UTF-8",
"Should default to utf-8"
);
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Remove: ["Foo"],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
// If this passes, it means that the specified engine was properly removed
Assert.equal(
Services.search.getEngineByName("Foo"),
null,
"Specified search engine should not be installed"
);
await setupPolicyEngineWithJsonWithSearch({});
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_post_method_engine() {
Assert.equal(
Services.search.getEngineByName("Post"),
null,
'Engine "Post" should not be present when test starts'
);
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Add: [
{
Name: "Post",
Method: "POST",
PostData: "q={searchTerms}&anotherParam=yes",
URLTemplate: "http://example.com/",
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
let engine = Services.search.getEngineByName("Post");
Assert.notEqual(engine, null, "Specified search engine should be installed");
Assert.equal(
engine.wrappedJSObject._urls[0].method,
"POST",
"Method should be POST"
);
let submission = engine.getSubmission("term", "text/html");
Assert.notEqual(submission.postData, null, "Post data should not be null");
let scriptableInputStream = Cc[
"@mozilla.org/scriptableinputstream;1"
].createInstance(Ci.nsIScriptableInputStream);
scriptableInputStream.init(submission.postData);
Assert.equal(
scriptableInputStream.read(scriptableInputStream.available()),
"q=term&anotherParam=yes",
"Post data should be present"
);
await setupPolicyEngineWithJsonWithSearch({});
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_with_encoding() {
// Make sure we are starting in an expected state to avoid false positive
// test results.
Assert.equal(
Services.search.getEngineByName("Encoding"),
null,
'Engine "Encoding" should not be present when test starts'
);
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Add: [
{
Name: "Encoding",
Encoding: "windows-1252",
URLTemplate: "http://example.com/?q={searchTerms}",
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
let engine = Services.search.getEngineByName("Encoding");
Assert.equal(
engine.wrappedJSObject.queryCharset,
"windows-1252",
"Should have correct encoding"
);
// Clean up
await setupPolicyEngineWithJsonWithSearch({});
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_and_update() {
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Add: [
{
Name: "ToUpdate",
URLTemplate: "http://initial.example.com/?q={searchTerms}",
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
let engine = Services.search.getEngineByName("ToUpdate");
Assert.notEqual(engine, null, "Specified search engine should be installed");
Assert.equal(
engine.getSubmission("test").uri.spec,
"http://initial.example.com/?q=test",
"Initial submission URL should be correct."
);
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Add: [
{
Name: "ToUpdate",
URLTemplate: "http://update.example.com/?q={searchTerms}",
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
engine = Services.search.getEngineByName("ToUpdate");
Assert.notEqual(engine, null, "Specified search engine should be installed");
Assert.equal(
engine.getSubmission("test").uri.spec,
"http://update.example.com/?q=test",
"Updated Submission URL should be correct."
);
// Clean up
await setupPolicyEngineWithJsonWithSearch({});
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_with_suggest() {
// Make sure we are starting in an expected state to avoid false positive
// test results.
Assert.equal(
Services.search.getEngineByName("Suggest"),
null,
'Engine "Suggest" should not be present when test starts'
);
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Add: [
{
Name: "Suggest",
URLTemplate: "http://example.com/?q={searchTerms}",
SuggestURLTemplate: "http://suggest.example.com/?q={searchTerms}",
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
let engine = Services.search.getEngineByName("Suggest");
Assert.equal(
engine.getSubmission("test", "application/x-suggestions+json").uri.spec,
"http://suggest.example.com/?q=test",
"Updated Submission URL should be correct."
);
// Clean up
await setupPolicyEngineWithJsonWithSearch({});
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_install_and_restart_keeps_settings() {
// Make sure we are starting in an expected state to avoid false positive
// test results.
Assert.equal(
Services.search.getEngineByName("Settings"),
null,
'Engine "Settings" should not be present when test starts'
);
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Add: [
{
Name: "Settings",
URLTemplate: "http://example.com/?q={searchTerms}",
},
],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
let settingsWritten = SearchTestUtils.promiseSearchNotification(
"write-settings-to-disk-complete"
);
let engine = Services.search.getEngineByName("Settings");
engine.hidden = true;
engine.alias = "settings";
await settingsWritten;
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Add: [
{
Name: "Settings",
URLTemplate: "http://example.com/?q={searchTerms}",
},
],
},
},
});
engine = Services.search.getEngineByName("Settings");
Assert.ok(engine.hidden, "Should have kept the engine hidden after restart");
Assert.equal(
engine.alias,
"settings",
"Should have kept the engine alias after restart"
);
// Clean up
await setupPolicyEngineWithJsonWithSearch({});
EnterprisePolicyTesting.resetRunOnceState();
});
add_task(async function test_reset_default() {
await setupPolicyEngineWithJsonWithSearch({
policies: {
SearchEngines: {
Remove: ["DuckDuckGo"],
},
},
});
// Get in line, because the Search policy callbacks are async.
await TestUtils.waitForTick();
let engine = Services.search.getEngineByName("DuckDuckGo");
Assert.equal(
engine.hidden,
true,
"Application specified engine should be hidden."
);
await Services.search.restoreDefaultEngines();
engine = Services.search.getEngineByName("DuckDuckGo");
Assert.equal(
engine.hidden,
false,
"Application specified engine should not be hidden"
);
EnterprisePolicyTesting.resetRunOnceState();
});

Просмотреть файл

@ -19,7 +19,6 @@ support-files =
[test_macosparser_unflatten.js]
skip-if = os != 'mac'
[test_permissions.js]
[test_policy_search_engine.js]
[test_popups_cookies_addons_flash.js]
support-files = config_popups_cookies_addons_flash.json
[test_preferences.js]

Просмотреть файл

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>test_urifixup_search_engine</ShortName>
<Description>test_urifixup_search_engine</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html" method="GET" template="https://www.example.org/">
<Param name="search" value="{searchTerms}"/>
</Url>
<SearchForm>https://www.example.org/</SearchForm>
</SearchPlugin>

Просмотреть файл

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>test_urifixup_search_engine_post</ShortName>
<Description>test_urifixup_search_engine_post</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html" method="POST" template="https://www.example.org/">
<Param name="q" value="{searchTerms}"/>
</Url>
<SearchForm>https://www.example.org/</SearchForm>
</SearchPlugin>

Просмотреть файл

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>test_urifixup_search_engine_private</ShortName>
<Description>test_urifixup_search_engine_private</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html" method="GET" template="https://www.example.org/">
<Param name="private" value="{searchTerms}"/>
</Url>
<SearchForm>https://www.example.org/</SearchForm>
</SearchPlugin>

Просмотреть файл

@ -13,7 +13,6 @@ ChromeUtils.defineESModuleGetters(this, {
XPCOMUtils.defineLazyModuleGetters(this, {
AddonTestUtils: "resource://testing-common/AddonTestUtils.jsm",
HttpServer: "resource://testing-common/httpd.js",
NetUtil: "resource://gre/modules/NetUtil.jsm",
TestUtils: "resource://testing-common/TestUtils.jsm",
});
@ -48,6 +47,7 @@ const SEARCH_CONFIG = [
async function setupSearchService() {
SearchTestUtils.init(this);
Services.prefs.setBoolPref("browser.search.modernConfig", true);
AddonTestUtils.init(this);
AddonTestUtils.overrideCertDB();
AddonTestUtils.createAppInfo(
@ -62,39 +62,24 @@ async function setupSearchService() {
await Services.search.init();
}
/**
* After useHttpServer() is called, this string contains the URL of the "data"
* directory, including the final slash.
*/
var gDataUrl;
/**
* Initializes the HTTP server and ensures that it is terminated when tests end.
*
* @param {string} dir
* The test sub-directory to use for the engines.
* @returns {HttpServer}
* The HttpServer object in case further customization is needed.
*/
function useHttpServer(dir = "data") {
let httpServer = new HttpServer();
httpServer.start(-1);
httpServer.registerDirectory("/", do_get_cwd());
gDataUrl = `http://localhost:${httpServer.identity.primaryPort}/${dir}/`;
registerCleanupFunction(async function cleanup_httpServer() {
await new Promise(resolve => {
httpServer.stop(resolve);
});
});
return httpServer;
}
async function addTestEngines() {
useHttpServer();
// This is a hack, ideally we should be setting up a configuration with
// built-in engines, but the `chrome_settings_overrides` section that
// WebExtensions need is only defined for browser/
await SearchTestUtils.promiseNewSearchEngine(`${gDataUrl}/engine.xml`);
await SearchTestUtils.promiseNewSearchEngine(`${gDataUrl}/enginePrivate.xml`);
await SearchTestUtils.promiseNewSearchEngine(`${gDataUrl}/enginePost.xml`);
await Services.search.addPolicyEngine({
description: "urifixup search engine",
name: kSearchEngineID,
search_url: kSearchEngineURL,
});
await Services.search.addPolicyEngine({
description: "urifixup private search engine",
name: kPrivateSearchEngineID,
search_url: kPrivateSearchEngineURL,
});
await Services.search.addPolicyEngine({
description: "urifixup POST search engine",
name: kPostSearchEngineID,
search_url: kPostSearchEngineURL,
search_url_post_params: kPostSearchEngineData,
});
}

Просмотреть файл

@ -1,9 +1,5 @@
[DEFAULT]
head = head_docshell.js
support-files =
data/engine.xml
data/enginePost.xml
data/enginePrivate.xml
[test_allowJavascript.js]
skip-if = os == 'android'

Просмотреть файл

@ -109,21 +109,6 @@ export class AddonSearchEngine extends SearchEngine {
return this.#isAppProvided;
}
/**
* Whether or not this engine is an in-memory only search engine.
* These engines are typically application provided or policy engines,
* where they are loaded every time on SearchService initialization
* using the policy JSON or the extension manifest. Minimal details of the
* in-memory engines are saved to disk, but they are never loaded
* from the user's saved settings file.
*
* @returns {boolean}
* Only returns true for application provided engines.
*/
get inMemory() {
return this.#isAppProvided;
}
/**
* Creates a JavaScript object that represents this engine.
*

Просмотреть файл

@ -39,21 +39,6 @@ export class PolicySearchEngine extends SearchEngine {
}
}
/**
* Whether or not this engine is an in-memory only search engine.
* These engines are typically application provided or policy engines,
* where they are loaded every time on SearchService initialization
* using the policy JSON or the extension manifest. Minimal details of the
* in-memory engines are saved to disk, but they are never loaded
* from the user's saved settings file.
*
* @returns {boolean}
* All policy engines are in-memory, so this always returns true.
*/
get inMemory() {
return true;
}
/**
* Returns the appropriate identifier to use for telemetry.
*
@ -78,26 +63,4 @@ export class PolicySearchEngine extends SearchEngine {
lazy.SearchUtils.notifyAction(this, lazy.SearchUtils.MODIFIED_TYPE.CHANGED);
}
/**
* Creates a JavaScript object that represents this engine.
*
* @returns {object}
* An object suitable for serialization as JSON.
*/
toJSON() {
// For policy engines, we load them at every startup and we don't want to
// store all their data in the settings file so just return the relevant
// metadata.
let json = super.toJSON();
// We only want to return a sub-set of fields, as the details for this engine
// are loaded on each startup from the enterprise policies.
return {
_name: json._name,
// Load path is included so that we know this is an enterprise engine.
_loadPath: json._loadPath,
_metaData: json._metaData,
};
}
}

Просмотреть файл

@ -1305,22 +1305,6 @@ export class SearchEngine {
return false;
}
/**
* Whether or not this engine is an in-memory only search engine.
* These engines are typically application provided or policy engines,
* where they are loaded every time on SearchService initialization
* using the policy JSON or the extension manifest. Minimal details of the
* in-memory engines are saved to disk, but they are never loaded
* from the user's saved settings file.
*
* @returns {boolean}
* This results false for most engines, but may be overridden by particular
* engine types, such as add-on engines and policy engines.
*/
get inMemory() {
return false;
}
get isGeneralPurposeEngine() {
return !!(
this._extensionID &&

Просмотреть файл

@ -521,7 +521,9 @@ export class SearchService {
* An object that simulates the manifest object from a WebExtension. See
* the idl for more details.
*/
async #addPolicyEngine(details) {
async addPolicyEngine(details) {
await this.init();
let newEngine = new lazy.PolicySearchEngine({ details });
let existingEngine = this._engines.get(newEngine.name);
if (existingEngine) {
@ -530,10 +532,24 @@ export class SearchService {
Cr.NS_ERROR_FILE_ALREADY_EXISTS
);
}
lazy.logConsole.debug("Adding Policy Engine:", newEngine.name);
lazy.logConsole.debug(`Adding ${newEngine.name}`);
this.#addEngineToStore(newEngine);
}
/**
* Updates a search engine that is specified from enterprise policies.
*
* @param {object} details
* An object that simulates the manifest object from a WebExtension. See
* the idl for more details.
*/
async updatePolicyEngine(details) {
let engine = this.getEngineByName(details.name);
if (engine && !engine.isAppProvided) {
engine.update(details);
}
}
/**
* Adds a search engine that is specified by the user.
*
@ -702,7 +718,7 @@ export class SearchService {
});
}
if (engineToRemove.inMemory) {
if (engineToRemove.isAppProvided) {
// Just hide it (the "hidden" setter will notify) and remove its alias to
// avoid future conflicts with other engines.
engineToRemove.hidden = true;
@ -1543,15 +1559,13 @@ export class SearchService {
}
this.#startupExtensions.clear();
this.#loadEnginesFromPolicies();
this.#loadEnginesFromSettings(settings.engines);
this.#loadEnginesMetadataFromSettings(settings.engines);
lazy.logConsole.debug("#loadEngines: done");
let newCurrentEngine = this._getEngineDefault(false);
let newCurrentEngine = this._getEngineDefault(false)?.name;
this._settings.setMetaDataAttribute(
"appDefaultEngine",
this.appDefaultEngine?.name
@ -1568,7 +1582,7 @@ export class SearchService {
) {
this._showRemovalOfSearchEngineNotificationBox(
prevCurrentEngine || prevAppDefaultEngine,
newCurrentEngine.name
newCurrentEngine
);
}
}
@ -1583,8 +1597,8 @@ export class SearchService {
* The user's previous search settings metadata.
* @param { object } newCurrentEngine
* The user's new current default engine.
* @param { string } prevCurrentEngine
* The name of the user's previous default engine.
* @param { object } prevCurrentEngine
* The user's previous default engine.
* @param { string } prevAppDefaultEngine
* The name of the user's previous app default engine.
* @returns { boolean }
@ -1618,37 +1632,16 @@ export class SearchService {
if (!prevCurrentEngine && this._engines.has(prevAppDefaultEngine)) {
return false;
}
// Don't show the notification if the previous engine was an enterprise
// engine - the text doesn't quite make sense.
if (prevCurrentEngine) {
let engineSettings = settings.engines.find(
e => e._name == prevCurrentEngine
);
if (engineSettings._loadPath.includes("set-via-policy")) {
return false;
}
}
// Don't show the prompt if the previous engine was an enterprise engine -
// the text doesn't quite make sense.
if (prevCurrentEngine) {
let engineSettings = settings.engines.find(
e => e._name == prevCurrentEngine
);
if (engineSettings._loadPath.includes("set-via-policy")) {
return false;
}
}
// If the user's previous engine is different than the new current engine,
// or if the user was using the app default engine and the app default
// engine is different than the new current engine, we check if the user's
// settings metadata has been upddated.
if (
(prevCurrentEngine && prevCurrentEngine !== newCurrentEngine.name) ||
(prevCurrentEngine && prevCurrentEngine !== newCurrentEngine) ||
(!prevCurrentEngine &&
prevAppDefaultEngine &&
prevAppDefaultEngine !== newCurrentEngine.name)
prevAppDefaultEngine !== newCurrentEngine)
) {
// Check settings metadata to detect an update to locale. Sometimes when
// the user changes their locale it causes a change in engines.
@ -2115,33 +2108,6 @@ export class SearchService {
}
}
#loadEnginesFromPolicies() {
if (Services.policies.status != Ci.nsIEnterprisePolicies.ACTIVE) {
return;
}
let activePolicies = Services.policies.getActivePolicies();
if (!activePolicies.SearchEngines) {
return;
}
for (let engineDetails of activePolicies.SearchEngines.Add ?? []) {
let details = {
description: engineDetails.Description,
iconURL: engineDetails.IconURL ? engineDetails.IconURL.href : null,
name: engineDetails.Name,
// If the encoding is not specified or is falsy, we will fall back to
// the default encoding.
encoding: engineDetails.Encoding,
search_url: encodeURI(engineDetails.URLTemplate),
keyword: engineDetails.Alias,
search_url_post_params:
engineDetails.Method == "POST" ? engineDetails.PostData : undefined,
suggest_url: engineDetails.SuggestURLTemplate,
};
this.#addPolicyEngine(details);
}
}
#loadEnginesFromSettings(enginesCache) {
if (!enginesCache) {
return;
@ -2188,8 +2154,7 @@ export class SearchService {
try {
let engine;
if (loadPath?.includes("set-via-policy")) {
skippedEngines++;
continue;
engine = new lazy.PolicySearchEngine({ json: engineJSON });
} else if (loadPath?.includes("set-via-user")) {
engine = new lazy.UserSearchEngine({ json: engineJSON });
} else if (engineJSON.extensionID ?? engineJSON._extensionID) {
@ -2218,7 +2183,7 @@ export class SearchService {
lazy.logConsole.debug(
"#loadEnginesFromSettings: skipped",
skippedEngines,
"built-in/policy engines."
"built-in engines."
);
}
}
@ -2633,6 +2598,8 @@ export class SearchService {
let isCurrent = false;
// Special search engines (policy and user) are skipped for migration as
// there would never have been an OpenSearch engine associated with those.
for (let engine of this._engines.values()) {
if (
!engine.extensionID &&

Просмотреть файл

@ -171,16 +171,6 @@ interface nsISearchEngine : nsISupports
*/
readonly attribute boolean isAppProvided;
/**
* Whether or not this engine is an in-memory only search engine.
* These engines are typically application provided or policy engines,
* where they are loaded every time on SearchService initialization
* using the policy JSON or the extension manifest. Minimal details of the
* in-memory engines are saved to disk, but they are never loaded
* from the user's saved settings file.
*/
readonly attribute boolean inMemory;
/**
* Whether or not this engine is a "general" search engine, e.g. is it for
* generally searching the web, or does it have a specific purpose like
@ -310,6 +300,42 @@ interface nsISearchService : nsISupports
*/
Promise addOpenSearchEngine(in AString engineURL, in AString iconURL);
/**
* Adds a new search engine for enterprises.
*
* @param details
* An object with the following details:
*
* {iconURL} Optional. The icon to use for the engine.
* {description} Optional. The description of the engine.
* {name} The name of the engine
* {encoding} Optional. The encoding of the engine.
* {search_url} The search url for the engine.
* {keyword} Optional. The keyword for the engine.
* {search_url_post_params} Optional. Post parameters for the search
* engine submission.
* {suggest_url} The suggestion url for the engine.
*/
Promise addPolicyEngine(in jsval details);
/**
* Updates an existing engine for enterprises.
*
* @param details
* An object with the following details:
*
* {iconURL} Optional. The icon to use for the engine.
* {description} Optional. The description of the engine.
* {name} The name of the engine
* {encoding} Optional. The encoding of the engine.
* {search_url} The search url for the engine.
* {keyword} Optional. The keyword for the engine.
* {search_url_post_params} Optional. Post parameters for the search
* engine submission.
* {suggest_url} The suggestion url for the engine.
*/
Promise updatePolicyEngine(in jsval details);
/**
* Adds a new search engine defined by the user.
*

Просмотреть файл

@ -45,6 +45,8 @@ var XULRuntime = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime);
Services.prefs.setBoolPref("browser.search.log", true);
Services.prefs.setBoolPref("browser.region.log", true);
Services.prefs.setBoolPref("browser.search.modernConfig", true);
AddonTestUtils.init(this, false);
AddonTestUtils.createAppInfo(
"xpcshell@tests.mozilla.org",

Просмотреть файл

@ -93,3 +93,60 @@ add_task(async function test_migrateLegacyEngineDifferentName() {
await extension.unload();
});
add_task(async function test_migrateLegacySkipsPolicyAndUser() {
const loadPath = "jar:[profile]/extensions/set-via-policy/simple.xml";
await Services.search.addOpenSearchEngine(gDataUrl + "simple.xml", null);
// Modify the loadpath so it looks like an legacy plugin loadpath
let engine = Services.search.getEngineByName("simple");
// Although this load path should never have existed, we ensure that policy/user
// engines don't upgrade existing OpenSearch engines.
engine.wrappedJSObject._loadPath = loadPath;
engine.wrappedJSObject._extensionID = null;
await Services.search.setDefault(
engine,
Ci.nsISearchService.CHANGE_REASON_UNKNOWN
);
// This should not replace the existing engine, but be rejected with a
// duplicate engine warning.
await Assert.rejects(
Services.search.addPolicyEngine({
name: "simple",
search_url: "https://example.com",
}),
/NS_ERROR_FILE_ALREADY_EXISTS/,
"Should have rejected adding the engine"
);
// This will be added is the name is different, but will also not replace
// the existing engine.
await Services.search.addPolicyEngine({
name: "simple search",
search_url: "https://example.com",
});
engine = Services.search.getEngineByName("simple");
Assert.ok(engine, "Should have kept the old engine");
Assert.equal(
engine.wrappedJSObject._loadPath,
loadPath,
"Should have kept the load path"
);
engine = Services.search.getEngineByName("simple search");
Assert.ok(engine, "Should have added the new engine");
Assert.equal(
engine.wrappedJSObject._loadPath,
"[other]addEngineWithDetails:set-via-policy",
"Should have the correct load path"
);
Assert.equal(
(await Services.search.getDefault()).name,
"simple",
"Should have kept the original engine as default"
);
});

Просмотреть файл

@ -7,60 +7,26 @@
"use strict";
const { EnterprisePolicyTesting } = ChromeUtils.importESModule(
"resource://testing-common/EnterprisePolicyTesting.sys.mjs"
);
SearchSettings.SETTINGS_INVALIDATION_DELAY = 100;
/**
* Loads a new enterprise policy, and re-initialise the search service
* with the new policy. Also waits for the search service to write the settings
* file to disk.
*
* @param {object} policy
* The enterprise policy to use.
*/
async function setupPolicyEngineWithJson(policy) {
Services.search.wrappedJSObject.reset();
await EnterprisePolicyTesting.setupPolicyEngineWithJson(policy);
let settingsWritten = SearchTestUtils.promiseSearchNotification(
"write-settings-to-disk-complete"
);
await Services.search.init();
await settingsWritten;
}
add_task(async function setup() {
// This initializes the policy engine for xpcshell tests
let policies = Cc["@mozilla.org/enterprisepolicies;1"].getService(
Ci.nsIObserver
);
policies.observe(null, "policies-startup", null);
Services.fog.initializeFOG();
await AddonTestUtils.promiseStartupManager();
await Services.search.init();
});
add_task(async function test_enterprise_policy_engine() {
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Add: [
{
Name: "policy",
Description: "Test policy engine",
IconURL: "data:image/gif;base64,R0lGODl",
Alias: "p",
URLTemplate: "https://example.com?q={searchTerms}",
SuggestURLTemplate: "https://example.com/suggest/?q={searchTerms}",
},
],
},
},
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.");
@ -99,54 +65,3 @@ add_task(async function test_enterprise_policy_engine() {
},
});
});
add_task(async function test_enterprise_policy_engine_hidden_persisted() {
// Set the engine alias, and wait for the settings to be written.
let settingsWritten = SearchTestUtils.promiseSearchNotification(
"write-settings-to-disk-complete"
);
let engine = Services.search.getEngineByName("policy");
engine.hidden = "p1";
engine.alias = "p1";
await settingsWritten;
// This will reset and re-initialise the search service.
await setupPolicyEngineWithJson({
policies: {
SearchEngines: {
Add: [
{
Name: "policy",
Description: "Test policy engine",
IconURL: "data:image/gif;base64,R0lGODl",
Alias: "p",
URLTemplate: "https://example.com?q={searchTerms}",
SuggestURLTemplate: "https://example.com/suggest/?q={searchTerms}",
},
],
},
},
});
engine = Services.search.getEngineByName("policy");
Assert.equal(engine.alias, "p1", "Should have retained the engine alias");
Assert.ok(engine.hidden, "Should have kept the engine hidden");
});
add_task(async function test_enterprise_policy_engine_remove() {
// This will reset and re-initialise the search service.
await setupPolicyEngineWithJson({
policies: {},
});
Assert.ok(
!Services.search.getEngineByName("policy"),
"Should not have the policy engine installed"
);
let settings = await promiseSettingsData();
Assert.ok(
!settings.engines.find(e => e.name == "p1"),
"Should not have the engine settings stored"
);
});

Просмотреть файл

@ -160,3 +160,37 @@ add_task(async function test_missing_extension() {
await oldRemoveEngineFunc(Services.search.getEngineByName("Example"));
});
add_task(async function test_user_engine() {
Services.telemetry.clearScalars();
await Services.search.addUserEngine("test", "https://example.com/", "fake");
await Services.search.runBackgroundChecks();
let scalars = TelemetryTestUtils.getProcessScalars("parent", true, true);
Assert.deepEqual(
scalars,
{},
"Should not have recorded any issues for a user-defined engine"
);
});
add_task(async function test_policy_engine() {
Services.telemetry.clearScalars();
await Services.search.addPolicyEngine({
description: "test policy engine",
name: "test_policy_engine",
search_url: "https://www.example.org/?search={searchTerms}",
});
await Services.search.runBackgroundChecks();
let scalars = TelemetryTestUtils.getProcessScalars("parent", true, true);
Assert.deepEqual(
scalars,
{},
"Should not have recorded any issues for a policy defined engine"
);
});