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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:de9085b3295c
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
4
5 // This verifies that localized properties work as expected
6
7 const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
8 const PREF_SELECTED_LOCALE = "general.useragent.locale";
9
10
11 function run_test() {
12 do_test_pending();
13
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");
18
19 startupManager();
20
21 run_test_1();
22 }
23
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");
29
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 }
41
42 // Tests that the localized properties are visible after installation
43 function run_test_2() {
44 restartManager();
45
46 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
47 do_check_neq(addon, null);
48
49 do_check_eq(addon.name, "fr-FR Name");
50 do_check_eq(addon.description, "fr-FR Description");
51
52 addon.userDisabled = true;
53 do_execute_soon(run_test_3);
54 });
55 }
56
57 // Test that the localized properties are still there when disabled.
58 function run_test_3() {
59 restartManager();
60
61 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
62 do_check_neq(addon, null);
63 do_check_eq(addon.name, "fr-FR Name");
64
65 do_execute_soon(run_test_4);
66 });
67 }
68
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();
75
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");
84
85 do_execute_soon(run_test_5);
86 });
87 }
88
89 // Test that changing locale works
90 function run_test_5() {
91 Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de-DE");
92 restartManager();
93
94 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
95 do_check_neq(addon, null);
96
97 do_check_eq(addon.name, "de-DE Name");
98 do_check_eq(addon.description, null);
99
100 do_execute_soon(run_test_6);
101 });
102 }
103
104 // Test that missing locales use the fallbacks
105 function run_test_6() {
106 Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "nl-NL");
107 restartManager();
108
109 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(addon) {
110 do_check_neq(addon, null);
111
112 do_check_eq(addon.name, "Fallback Name");
113 do_check_eq(addon.description, "Fallback Description");
114
115 addon.userDisabled = false;
116 do_execute_soon(run_test_7);
117 }));
118 }
119
120 // Test that the prefs will override the fallbacks
121 function run_test_7() {
122 restartManager();
123
124 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
125 do_check_neq(addon, null);
126
127 do_check_eq(addon.name, "Name from prefs");
128
129 do_execute_soon(run_test_8);
130 });
131 }
132
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();
137
138 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) {
139 do_check_neq(addon, null);
140
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");
146
147 do_execute_soon(do_test_finished);
148 });
149 }

mercurial