Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 */
6 const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS";
7 const PREF_SELECTED_LOCALE = "general.useragent.locale";
9 const ADDON = "test_bug397778";
10 const ID = "bug397778@tests.mozilla.org";
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");
20 // Install test add-on
21 startupManager();
22 installAllFiles([do_get_addon(ADDON)], function() {
23 restartManager();
25 run_test_1();
26 });
27 }
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");
35 // Disable item
36 addon.userDisabled = true;
37 restartManager();
39 AddonManager.getAddonByID(ID, function(newAddon) {
40 do_check_neq(newAddon, null);
41 do_check_eq(newAddon.name, "fr Name");
43 do_execute_soon(run_test_2);
44 });
45 }));
46 }
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();
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);
58 do_execute_soon(run_test_3);
59 });
60 }
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();
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);
72 do_execute_soon(run_test_4);
73 });
74 }
76 function run_test_4() {
77 // Change locale. es-ES should closely match
78 Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "es-AR");
79 restartManager();
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");
86 do_execute_soon(run_test_5);
87 });
88 }
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();
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);
100 do_execute_soon(run_test_6);
101 });
102 }
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();
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");
115 do_execute_soon(do_test_finished);
116 });
117 }