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

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 // This verifies that localized properties work as expected
     7 const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
     8 const PREF_SELECTED_LOCALE = "general.useragent.locale";
    11 function run_test() {
    12   do_test_pending();
    14   // Setup for test
    15   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    16   Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
    17   Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
    19   startupManager();
    21   run_test_1();
    22 }
    24 // Tests that the localized properties are visible before installation
    25 function run_test_1() {
    26   AddonManager.getInstallForFile(do_get_addon("test_locale"), function(install) {
    27     do_check_eq(install.addon.name, "fr-FR Name");
    28     do_check_eq(install.addon.description, "fr-FR Description");
    30     prepare_test({
    31       "addon1@tests.mozilla.org": [
    32         "onInstalling"
    33       ]
    34     }, [
    35       "onInstallStarted",
    36       "onInstallEnded",
    37     ], callback_soon(run_test_2));
    38     install.install();
    39   });
    40 }
    42 // Tests that the localized properties are visible after installation
    43 function run_test_2() {
    44   restartManager();
    46   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
    47     do_check_neq(addon, null);
    49     do_check_eq(addon.name, "fr-FR Name");
    50     do_check_eq(addon.description, "fr-FR Description");
    52     addon.userDisabled = true;
    53     do_execute_soon(run_test_3);
    54   });
    55 }
    57 // Test that the localized properties are still there when disabled.
    58 function run_test_3() {
    59   restartManager();
    61   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
    62     do_check_neq(addon, null);
    63     do_check_eq(addon.name, "fr-FR Name");
    65     do_execute_soon(run_test_4);
    66   });
    67 }
    69 // Localised preference values should be ignored when the add-on is disabled
    70 function run_test_4() {
    71   Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.name", "Name from prefs");
    72   Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.contributor.1", "Contributor 1");
    73   Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.contributor.2", "Contributor 2");
    74   restartManager();
    76   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
    77     do_check_neq(addon, null);
    78     do_check_eq(addon.name, "fr-FR Name");
    79     let contributors = addon.contributors;
    80     do_check_eq(contributors.length, 3);
    81     do_check_eq(contributors[0], "Fr Contributor 1");
    82     do_check_eq(contributors[1], "Fr Contributor 2");
    83     do_check_eq(contributors[2], "Fr Contributor 3");
    85     do_execute_soon(run_test_5);
    86   });
    87 }
    89 // Test that changing locale works
    90 function run_test_5() {
    91   Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de-DE");
    92   restartManager();
    94   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
    95     do_check_neq(addon, null);
    97     do_check_eq(addon.name, "de-DE Name");
    98     do_check_eq(addon.description, null);
   100     do_execute_soon(run_test_6);
   101   });
   102 }
   104 // Test that missing locales use the fallbacks
   105 function run_test_6() {
   106   Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "nl-NL");
   107   restartManager();
   109   AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(addon) {
   110     do_check_neq(addon, null);
   112     do_check_eq(addon.name, "Fallback Name");
   113     do_check_eq(addon.description, "Fallback Description");
   115     addon.userDisabled = false;
   116     do_execute_soon(run_test_7);
   117   }));
   118 }
   120 // Test that the prefs will override the fallbacks
   121 function run_test_7() {
   122   restartManager();
   124   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
   125     do_check_neq(addon, null);
   127     do_check_eq(addon.name, "Name from prefs");
   129     do_execute_soon(run_test_8);
   130   });
   131 }
   133 // Test that the prefs will override localized values from the manifest
   134 function run_test_8() {
   135   Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
   136   restartManager();
   138   AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
   139     do_check_neq(addon, null);
   141     do_check_eq(addon.name, "Name from prefs");
   142     let contributors = addon.contributors;
   143     do_check_eq(contributors.length, 2);
   144     do_check_eq(contributors[0], "Contributor 1");
   145     do_check_eq(contributors[1], "Contributor 2");
   147     do_execute_soon(do_test_finished);
   148   });
   149 }

mercurial