michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // This verifies that localized properties work as expected 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: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: // Setup for test michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); michael@0: Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false); michael@0: Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR"); michael@0: michael@0: startupManager(); michael@0: michael@0: run_test_1(); michael@0: } michael@0: michael@0: // Tests that the localized properties are visible before installation michael@0: function run_test_1() { michael@0: AddonManager.getInstallForFile(do_get_addon("test_locale"), function(install) { michael@0: do_check_eq(install.addon.name, "fr-FR Name"); michael@0: do_check_eq(install.addon.description, "fr-FR Description"); michael@0: michael@0: prepare_test({ michael@0: "addon1@tests.mozilla.org": [ michael@0: "onInstalling" michael@0: ] michael@0: }, [ michael@0: "onInstallStarted", michael@0: "onInstallEnded", michael@0: ], callback_soon(run_test_2)); michael@0: install.install(); michael@0: }); michael@0: } michael@0: michael@0: // Tests that the localized properties are visible after installation michael@0: function run_test_2() { michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { michael@0: do_check_neq(addon, null); michael@0: michael@0: do_check_eq(addon.name, "fr-FR Name"); michael@0: do_check_eq(addon.description, "fr-FR Description"); michael@0: michael@0: addon.userDisabled = true; michael@0: do_execute_soon(run_test_3); michael@0: }); michael@0: } michael@0: michael@0: // Test that the localized properties are still there when disabled. michael@0: function run_test_3() { michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { michael@0: do_check_neq(addon, null); michael@0: do_check_eq(addon.name, "fr-FR Name"); michael@0: michael@0: do_execute_soon(run_test_4); michael@0: }); michael@0: } michael@0: michael@0: // Localised preference values should be ignored when the add-on is disabled michael@0: function run_test_4() { michael@0: Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.name", "Name from prefs"); michael@0: Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.contributor.1", "Contributor 1"); michael@0: Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.contributor.2", "Contributor 2"); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { michael@0: do_check_neq(addon, null); michael@0: do_check_eq(addon.name, "fr-FR Name"); michael@0: let contributors = addon.contributors; michael@0: do_check_eq(contributors.length, 3); michael@0: do_check_eq(contributors[0], "Fr Contributor 1"); michael@0: do_check_eq(contributors[1], "Fr Contributor 2"); michael@0: do_check_eq(contributors[2], "Fr Contributor 3"); michael@0: michael@0: do_execute_soon(run_test_5); michael@0: }); michael@0: } michael@0: michael@0: // Test that changing locale works michael@0: function run_test_5() { michael@0: Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de-DE"); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { michael@0: do_check_neq(addon, null); michael@0: 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_6); michael@0: }); michael@0: } michael@0: michael@0: // Test that missing locales use the fallbacks michael@0: function run_test_6() { michael@0: Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "nl-NL"); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(addon) { michael@0: do_check_neq(addon, null); michael@0: michael@0: do_check_eq(addon.name, "Fallback Name"); michael@0: do_check_eq(addon.description, "Fallback Description"); michael@0: michael@0: addon.userDisabled = false; michael@0: do_execute_soon(run_test_7); michael@0: })); michael@0: } michael@0: michael@0: // Test that the prefs will override the fallbacks michael@0: function run_test_7() { michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { michael@0: do_check_neq(addon, null); michael@0: michael@0: do_check_eq(addon.name, "Name from prefs"); michael@0: michael@0: do_execute_soon(run_test_8); michael@0: }); michael@0: } michael@0: michael@0: // Test that the prefs will override localized values from the manifest michael@0: function run_test_8() { michael@0: Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR"); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { michael@0: do_check_neq(addon, null); michael@0: michael@0: do_check_eq(addon.name, "Name from prefs"); michael@0: let contributors = addon.contributors; michael@0: do_check_eq(contributors.length, 2); michael@0: do_check_eq(contributors[0], "Contributor 1"); michael@0: do_check_eq(contributors[1], "Contributor 2"); michael@0: michael@0: do_execute_soon(do_test_finished); michael@0: }); michael@0: }