forked from mirrors/gecko-dev
This is a rollup of all the patches that have landed on the cedar project branch:891252fdd0Bug 1492475 - Part 1: Migrate most, if not all nsSearchService consumers to use async APIs. r=florian79b2eb2367Bug 1492475 - Part 2: Move nsIBrowserSearchService.idl to toolkit/components/search/nsISearchService.idl and update references. r=floriana947d3cdf0Bug 1492475 - Part 3: The search service init() method should simply return a Promise. r=florianc1e172dfacBug 1492475 - Part 4: Remove the synchronous initialization flow. r=floriancd41189eacBug 1492475 - Part 5: Since async initialization of the search service now is implicit behavior, remove the distinctive verbiage used internally. r=florian2ae7189dfaBug 1492475 - Part 6: Update the cache build task to work with an actual Promise and re-initialize only once at the same time - all to fix race conditions here. r=florianc8ee92973fBug 1492475 - Part 7: Make the region fetch not block the init flow, to ensure it's as fast as possible. r=florianc44e674e16Bug 1492475 - Part 8: Introduce an init flag, which can only be used privately, that allows to explicitly skip waiting for the region check process to complete. r=florian6c79eaf1d3Bug 1492475 - Part 9: Update unit tests to stop using 'currentEngine', in favor of 'defaultEngine'. r=Standard821b3aa17eeBug 1492475 - Part 10: Update unit tests to be fully aware of the new, async signatures of the search service API and remove sync init flow tests. r=mkaply,floriance5ba69019Bug 1492475 - Part 11: Repair incorrect usage of the `identifier` property of nsISearchEngine instances. r=florianfd177a7994Bug 1518543 - Fix up the Android (Fennec) nsISearchService shim to work with the new asynchronous API. r=florian3653d8ee22Bug 1523708 - Change the search service interaction in the show-heartbeat action to use the new async API. r=florian Differential Revision: https://phabricator.services.mozilla.com/D18355 --HG-- rename : netwerk/base/nsIBrowserSearchService.idl => toolkit/components/search/nsISearchService.idl extra : moz-landing-system : lando
152 lines
6.9 KiB
JavaScript
152 lines
6.9 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
/**
|
|
* Tests that preferences are properly set by distribution.ini
|
|
*/
|
|
|
|
// Import common head.
|
|
var commonFile = do_get_file("../../../../toolkit/components/places/tests/head_common.js", false);
|
|
/* import-globals-from ../../../../toolkit/components/places/tests/head_common.js */
|
|
if (commonFile) {
|
|
let uri = Services.io.newFileURI(commonFile);
|
|
Services.scriptloader.loadSubScript(uri.spec, this);
|
|
}
|
|
|
|
const TOPICDATA_DISTRIBUTION_CUSTOMIZATION = "force-distribution-customization";
|
|
const TOPIC_BROWSERGLUE_TEST = "browser-glue-test";
|
|
|
|
/**
|
|
* Copy the engine-distribution.xml engine to a fake distribution
|
|
* created in the profile, and registered with the directory service.
|
|
* Create an empty en-US directory to make sure it isn't used.
|
|
*/
|
|
function installDistributionEngine() {
|
|
const XRE_APP_DISTRIBUTION_DIR = "XREAppDist";
|
|
|
|
let dir = gProfD.clone();
|
|
dir.append("distribution");
|
|
let distDir = dir.clone();
|
|
|
|
dir.append("searchplugins");
|
|
dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
|
|
|
dir.append("locale");
|
|
dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
|
let localeDir = dir.clone();
|
|
|
|
dir.append("en-US");
|
|
dir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
|
|
|
localeDir.append("de-DE");
|
|
localeDir.create(dir.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY);
|
|
|
|
do_get_file("data/engine-de-DE.xml").copyTo(localeDir, "engine-de-DE.xml");
|
|
|
|
Services.dirsvc.registerProvider({
|
|
getFile(aProp, aPersistent) {
|
|
aPersistent.value = true;
|
|
if (aProp == XRE_APP_DISTRIBUTION_DIR)
|
|
return distDir.clone();
|
|
return null;
|
|
},
|
|
});
|
|
}
|
|
|
|
registerCleanupFunction(async function() {
|
|
// Remove the distribution dir, even if the test failed, otherwise all
|
|
// next tests will use it.
|
|
let folderPath = OS.Path.join(OS.Constants.Path.profileDir, "distribution");
|
|
await OS.File.removeDir(folderPath, { ignoreAbsent: true });
|
|
Assert.ok(!(await OS.File.exists(folderPath)));
|
|
Services.prefs.clearUserPref("distribution.testing.loadFromProfile");
|
|
});
|
|
|
|
add_task(async function() {
|
|
// Set special pref to load distribution.ini from the profile folder.
|
|
Services.prefs.setBoolPref("distribution.testing.loadFromProfile", true);
|
|
|
|
// Copy distribution.ini file to the profile dir.
|
|
let distroDir = gProfD.clone();
|
|
distroDir.leafName = "distribution";
|
|
let iniFile = distroDir.clone();
|
|
iniFile.append("distribution.ini");
|
|
if (iniFile.exists()) {
|
|
iniFile.remove(false);
|
|
print("distribution.ini already exists, did some test forget to cleanup?");
|
|
}
|
|
|
|
let testDistributionFile = gTestDir.clone();
|
|
testDistributionFile.append("distribution.ini");
|
|
testDistributionFile.copyTo(distroDir, "distribution.ini");
|
|
Assert.ok(testDistributionFile.exists());
|
|
|
|
installDistributionEngine();
|
|
});
|
|
|
|
add_task(async function() {
|
|
// Force distribution.
|
|
let glue = Cc["@mozilla.org/browser/browserglue;1"].getService(Ci.nsIObserver);
|
|
glue.observe(null, TOPIC_BROWSERGLUE_TEST, TOPICDATA_DISTRIBUTION_CUSTOMIZATION);
|
|
|
|
var defaultBranch = Services.prefs.getDefaultBranch(null);
|
|
|
|
Assert.equal(defaultBranch.getCharPref("distribution.id"), "disttest");
|
|
Assert.equal(defaultBranch.getCharPref("distribution.version"), "1.0");
|
|
Assert.equal(defaultBranch.getStringPref("distribution.about"), "Tèƨƭ δïƨƭřïβúƭïôñ ƒïℓè");
|
|
|
|
Assert.equal(defaultBranch.getCharPref("distribution.test.string"), "Test String");
|
|
Assert.equal(defaultBranch.getCharPref("distribution.test.string.noquotes"), "Test String");
|
|
Assert.equal(defaultBranch.getIntPref("distribution.test.int"), 777);
|
|
Assert.equal(defaultBranch.getBoolPref("distribution.test.bool.true"), true);
|
|
Assert.equal(defaultBranch.getBoolPref("distribution.test.bool.false"), false);
|
|
|
|
Assert.throws(() => defaultBranch.getCharPref("distribution.test.empty"),
|
|
/NS_ERROR_UNEXPECTED/);
|
|
Assert.throws(() => defaultBranch.getIntPref("distribution.test.empty"),
|
|
/NS_ERROR_UNEXPECTED/);
|
|
Assert.throws(() => defaultBranch.getBoolPref("distribution.test.empty"),
|
|
/NS_ERROR_UNEXPECTED/);
|
|
|
|
Assert.equal(defaultBranch.getCharPref("distribution.test.pref.locale"), "en-US");
|
|
Assert.equal(defaultBranch.getCharPref("distribution.test.pref.language.en"), "en");
|
|
Assert.equal(defaultBranch.getCharPref("distribution.test.pref.locale.en-US"), "en-US");
|
|
Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.language.de"),
|
|
/NS_ERROR_UNEXPECTED/);
|
|
// This value was never set because of the empty language specific pref
|
|
Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.language.reset"),
|
|
/NS_ERROR_UNEXPECTED/);
|
|
// This value was never set because of the empty locale specific pref
|
|
Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.locale.reset"),
|
|
/NS_ERROR_UNEXPECTED/);
|
|
// This value was overridden by a locale specific setting
|
|
Assert.equal(defaultBranch.getCharPref("distribution.test.pref.locale.set"), "Locale Set");
|
|
// This value was overridden by a language specific setting
|
|
Assert.equal(defaultBranch.getCharPref("distribution.test.pref.language.set"), "Language Set");
|
|
// Language should not override locale
|
|
Assert.notEqual(defaultBranch.getCharPref("distribution.test.pref.locale.set"), "Language Set");
|
|
|
|
Assert.equal(defaultBranch.getComplexValue("distribution.test.locale", Ci.nsIPrefLocalizedString).data, "en-US");
|
|
Assert.equal(defaultBranch.getComplexValue("distribution.test.language.en", Ci.nsIPrefLocalizedString).data, "en");
|
|
Assert.equal(defaultBranch.getComplexValue("distribution.test.locale.en-US", Ci.nsIPrefLocalizedString).data, "en-US");
|
|
Assert.throws(() => defaultBranch.getComplexValue("distribution.test.language.de", Ci.nsIPrefLocalizedString),
|
|
/NS_ERROR_UNEXPECTED/);
|
|
// This value was never set because of the empty language specific pref
|
|
Assert.throws(() => defaultBranch.getComplexValue("distribution.test.language.reset", Ci.nsIPrefLocalizedString),
|
|
/NS_ERROR_UNEXPECTED/);
|
|
// This value was never set because of the empty locale specific pref
|
|
Assert.throws(() => defaultBranch.getComplexValue("distribution.test.locale.reset", Ci.nsIPrefLocalizedString),
|
|
/NS_ERROR_UNEXPECTED/);
|
|
// This value was overridden by a locale specific setting
|
|
Assert.equal(defaultBranch.getComplexValue("distribution.test.locale.set", Ci.nsIPrefLocalizedString).data, "Locale Set");
|
|
// This value was overridden by a language specific setting
|
|
Assert.equal(defaultBranch.getComplexValue("distribution.test.language.set", Ci.nsIPrefLocalizedString).data, "Language Set");
|
|
// Language should not override locale
|
|
Assert.notEqual(defaultBranch.getComplexValue("distribution.test.locale.set", Ci.nsIPrefLocalizedString).data, "Language Set");
|
|
|
|
Services.prefs.setCharPref("distribution.searchplugins.defaultLocale", "de-DE");
|
|
|
|
await Services.search.init();
|
|
var engine = Services.search.getEngineByName("Google");
|
|
Assert.equal(engine.description, "override-de-DE");
|
|
});
|