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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:5c95338d6b53
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 */
5
6 const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
7 const PREF_SELECTED_LOCALE = "general.useragent.locale";
8
9 const ADDON = "test_bug397778";
10 const ID = "bug397778@tests.mozilla.org";
11
12 function run_test()
13 {
14 // Setup for test
15 do_test_pending();
16 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1");
17 Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false);
18 Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR");
19
20 // Install test add-on
21 startupManager();
22 installAllFiles([do_get_addon(ADDON)], function() {
23 restartManager();
24
25 run_test_1();
26 });
27 }
28
29 function run_test_1() {
30 AddonManager.getAddonByID(ID, callback_soon(function(addon) {
31 do_check_neq(addon, null);
32 do_check_eq(addon.name, "fr Name");
33 do_check_eq(addon.description, "fr Description");
34
35 // Disable item
36 addon.userDisabled = true;
37 restartManager();
38
39 AddonManager.getAddonByID(ID, function(newAddon) {
40 do_check_neq(newAddon, null);
41 do_check_eq(newAddon.name, "fr Name");
42
43 do_execute_soon(run_test_2);
44 });
45 }));
46 }
47
48 function run_test_2() {
49 // Change locale. The more specific de-DE is the best match
50 Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de");
51 restartManager();
52
53 AddonManager.getAddonByID(ID, function(addon) {
54 do_check_neq(addon, null);
55 do_check_eq(addon.name, "de-DE Name");
56 do_check_eq(addon.description, null);
57
58 do_execute_soon(run_test_3);
59 });
60 }
61
62 function run_test_3() {
63 // Change locale. Locale case should have no effect
64 Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "DE-de");
65 restartManager();
66
67 AddonManager.getAddonByID(ID, function(addon) {
68 do_check_neq(addon, null);
69 do_check_eq(addon.name, "de-DE Name");
70 do_check_eq(addon.description, null);
71
72 do_execute_soon(run_test_4);
73 });
74 }
75
76 function run_test_4() {
77 // Change locale. es-ES should closely match
78 Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "es-AR");
79 restartManager();
80
81 AddonManager.getAddonByID(ID, function(addon) {
82 do_check_neq(addon, null);
83 do_check_eq(addon.name, "es-ES Name");
84 do_check_eq(addon.description, "es-ES Description");
85
86 do_execute_soon(run_test_5);
87 });
88 }
89
90 function run_test_5() {
91 // Change locale. Either zh-CN or zh-TW could match
92 Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "zh");
93 restartManager();
94
95 AddonManager.getAddonByID(ID, function(addon) {
96 do_check_neq(addon, null);
97 if (addon.name != "zh-TW Name" && addon.name != "zh-CN Name")
98 do_throw("zh matched to " + addon.name);
99
100 do_execute_soon(run_test_6);
101 });
102 }
103
104 function run_test_6() {
105 // Unknown locale should try to match against en-US as well. Of en,en-GB
106 // en should match as being less specific
107 Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "nl-NL");
108 restartManager();
109
110 AddonManager.getAddonByID(ID, function(addon) {
111 do_check_neq(addon, null);
112 do_check_eq(addon.name, "en Name");
113 do_check_eq(addon.description, "en Description");
114
115 do_execute_soon(do_test_finished);
116 });
117 }

mercurial