michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS"; michael@0: const PREF_SELECTED_LOCALE = "general.useragent.locale"; michael@0: michael@0: const ADDON = "test_bug397778"; michael@0: const ID = "bug397778@tests.mozilla.org"; michael@0: michael@0: function run_test() michael@0: { michael@0: // Setup for test michael@0: do_test_pending(); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1"); michael@0: Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false); michael@0: Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR"); michael@0: michael@0: // Install test add-on michael@0: startupManager(); michael@0: installAllFiles([do_get_addon(ADDON)], function() { michael@0: restartManager(); michael@0: michael@0: run_test_1(); michael@0: }); michael@0: } michael@0: michael@0: function run_test_1() { michael@0: AddonManager.getAddonByID(ID, callback_soon(function(addon) { michael@0: do_check_neq(addon, null); michael@0: do_check_eq(addon.name, "fr Name"); michael@0: do_check_eq(addon.description, "fr Description"); michael@0: michael@0: // Disable item michael@0: addon.userDisabled = true; michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID(ID, function(newAddon) { michael@0: do_check_neq(newAddon, null); michael@0: do_check_eq(newAddon.name, "fr Name"); michael@0: michael@0: do_execute_soon(run_test_2); michael@0: }); michael@0: })); michael@0: } michael@0: michael@0: function run_test_2() { michael@0: // Change locale. The more specific de-DE is the best match michael@0: Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de"); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID(ID, function(addon) { michael@0: do_check_neq(addon, null); michael@0: do_check_eq(addon.name, "de-DE Name"); michael@0: do_check_eq(addon.description, null); michael@0: michael@0: do_execute_soon(run_test_3); michael@0: }); michael@0: } michael@0: michael@0: function run_test_3() { michael@0: // Change locale. Locale case should have no effect michael@0: Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "DE-de"); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID(ID, function(addon) { michael@0: do_check_neq(addon, null); michael@0: do_check_eq(addon.name, "de-DE Name"); michael@0: do_check_eq(addon.description, null); michael@0: michael@0: do_execute_soon(run_test_4); michael@0: }); michael@0: } michael@0: michael@0: function run_test_4() { michael@0: // Change locale. es-ES should closely match michael@0: Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "es-AR"); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID(ID, function(addon) { michael@0: do_check_neq(addon, null); michael@0: do_check_eq(addon.name, "es-ES Name"); michael@0: do_check_eq(addon.description, "es-ES Description"); michael@0: michael@0: do_execute_soon(run_test_5); michael@0: }); michael@0: } michael@0: michael@0: function run_test_5() { michael@0: // Change locale. Either zh-CN or zh-TW could match michael@0: Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "zh"); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID(ID, function(addon) { michael@0: do_check_neq(addon, null); michael@0: if (addon.name != "zh-TW Name" && addon.name != "zh-CN Name") michael@0: do_throw("zh matched to " + addon.name); michael@0: michael@0: do_execute_soon(run_test_6); michael@0: }); michael@0: } michael@0: michael@0: function run_test_6() { michael@0: // Unknown locale should try to match against en-US as well. Of en,en-GB michael@0: // en should match as being less specific michael@0: Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "nl-NL"); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID(ID, function(addon) { michael@0: do_check_neq(addon, null); michael@0: do_check_eq(addon.name, "en Name"); michael@0: do_check_eq(addon.description, "en Description"); michael@0: michael@0: do_execute_soon(do_test_finished); michael@0: }); michael@0: }