toolkit/mozapps/extensions/test/xpcshell/test_locale.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_locale.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,149 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +// This verifies that localized properties work as expected
     1.9 +
    1.10 +const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
    1.11 +const PREF_SELECTED_LOCALE = "general.useragent.locale";
    1.12 +
    1.13 +
    1.14 +function run_test() {
    1.15 +  do_test_pending();
    1.16 +
    1.17 +  // Setup for test
    1.18 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    1.19 +  Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
    1.20 +  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
    1.21 +
    1.22 +  startupManager();
    1.23 +
    1.24 +  run_test_1();
    1.25 +}
    1.26 +
    1.27 +// Tests that the localized properties are visible before installation
    1.28 +function run_test_1() {
    1.29 +  AddonManager.getInstallForFile(do_get_addon("test_locale"), function(install) {
    1.30 +    do_check_eq(install.addon.name, "fr-FR Name");
    1.31 +    do_check_eq(install.addon.description, "fr-FR Description");
    1.32 +
    1.33 +    prepare_test({
    1.34 +      "addon1@tests.mozilla.org": [
    1.35 +        "onInstalling"
    1.36 +      ]
    1.37 +    }, [
    1.38 +      "onInstallStarted",
    1.39 +      "onInstallEnded",
    1.40 +    ], callback_soon(run_test_2));
    1.41 +    install.install();
    1.42 +  });
    1.43 +}
    1.44 +
    1.45 +// Tests that the localized properties are visible after installation
    1.46 +function run_test_2() {
    1.47 +  restartManager();
    1.48 +
    1.49 +  AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
    1.50 +    do_check_neq(addon, null);
    1.51 +
    1.52 +    do_check_eq(addon.name, "fr-FR Name");
    1.53 +    do_check_eq(addon.description, "fr-FR Description");
    1.54 +
    1.55 +    addon.userDisabled = true;
    1.56 +    do_execute_soon(run_test_3);
    1.57 +  });
    1.58 +}
    1.59 +
    1.60 +// Test that the localized properties are still there when disabled.
    1.61 +function run_test_3() {
    1.62 +  restartManager();
    1.63 +
    1.64 +  AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
    1.65 +    do_check_neq(addon, null);
    1.66 +    do_check_eq(addon.name, "fr-FR Name");
    1.67 +
    1.68 +    do_execute_soon(run_test_4);
    1.69 +  });
    1.70 +}
    1.71 +
    1.72 +// Localised preference values should be ignored when the add-on is disabled
    1.73 +function run_test_4() {
    1.74 +  Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.name", "Name from prefs");
    1.75 +  Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.contributor.1", "Contributor 1");
    1.76 +  Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.contributor.2", "Contributor 2");
    1.77 +  restartManager();
    1.78 +
    1.79 +  AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
    1.80 +    do_check_neq(addon, null);
    1.81 +    do_check_eq(addon.name, "fr-FR Name");
    1.82 +    let contributors = addon.contributors;
    1.83 +    do_check_eq(contributors.length, 3);
    1.84 +    do_check_eq(contributors[0], "Fr Contributor 1");
    1.85 +    do_check_eq(contributors[1], "Fr Contributor 2");
    1.86 +    do_check_eq(contributors[2], "Fr Contributor 3");
    1.87 +
    1.88 +    do_execute_soon(run_test_5);
    1.89 +  });
    1.90 +}
    1.91 +
    1.92 +// Test that changing locale works
    1.93 +function run_test_5() {
    1.94 +  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de-DE");
    1.95 +  restartManager();
    1.96 +
    1.97 +  AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
    1.98 +    do_check_neq(addon, null);
    1.99 +
   1.100 +    do_check_eq(addon.name, "de-DE Name");
   1.101 +    do_check_eq(addon.description, null);
   1.102 +
   1.103 +    do_execute_soon(run_test_6);
   1.104 +  });
   1.105 +}
   1.106 +
   1.107 +// Test that missing locales use the fallbacks
   1.108 +function run_test_6() {
   1.109 +  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "nl-NL");
   1.110 +  restartManager();
   1.111 +
   1.112 +  AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(addon) {
   1.113 +    do_check_neq(addon, null);
   1.114 +
   1.115 +    do_check_eq(addon.name, "Fallback Name");
   1.116 +    do_check_eq(addon.description, "Fallback Description");
   1.117 +
   1.118 +    addon.userDisabled = false;
   1.119 +    do_execute_soon(run_test_7);
   1.120 +  }));
   1.121 +}
   1.122 +
   1.123 +// Test that the prefs will override the fallbacks
   1.124 +function run_test_7() {
   1.125 +  restartManager();
   1.126 +
   1.127 +  AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
   1.128 +    do_check_neq(addon, null);
   1.129 +
   1.130 +    do_check_eq(addon.name, "Name from prefs");
   1.131 +
   1.132 +    do_execute_soon(run_test_8);
   1.133 +  });
   1.134 +}
   1.135 +
   1.136 +// Test that the prefs will override localized values from the manifest
   1.137 +function run_test_8() {
   1.138 +  Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
   1.139 +  restartManager();
   1.140 +
   1.141 +  AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
   1.142 +    do_check_neq(addon, null);
   1.143 +
   1.144 +    do_check_eq(addon.name, "Name from prefs");
   1.145 +    let contributors = addon.contributors;
   1.146 +    do_check_eq(contributors.length, 2);
   1.147 +    do_check_eq(contributors[0], "Contributor 1");
   1.148 +    do_check_eq(contributors[1], "Contributor 2");
   1.149 +
   1.150 +    do_execute_soon(do_test_finished);
   1.151 +  });
   1.152 +}

mercurial