1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug397778.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,117 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + */ 1.8 + 1.9 +const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS"; 1.10 +const PREF_SELECTED_LOCALE = "general.useragent.locale"; 1.11 + 1.12 +const ADDON = "test_bug397778"; 1.13 +const ID = "bug397778@tests.mozilla.org"; 1.14 + 1.15 +function run_test() 1.16 +{ 1.17 + // Setup for test 1.18 + do_test_pending(); 1.19 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1"); 1.20 + Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false); 1.21 + Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR"); 1.22 + 1.23 + // Install test add-on 1.24 + startupManager(); 1.25 + installAllFiles([do_get_addon(ADDON)], function() { 1.26 + restartManager(); 1.27 + 1.28 + run_test_1(); 1.29 + }); 1.30 +} 1.31 + 1.32 +function run_test_1() { 1.33 + AddonManager.getAddonByID(ID, callback_soon(function(addon) { 1.34 + do_check_neq(addon, null); 1.35 + do_check_eq(addon.name, "fr Name"); 1.36 + do_check_eq(addon.description, "fr Description"); 1.37 + 1.38 + // Disable item 1.39 + addon.userDisabled = true; 1.40 + restartManager(); 1.41 + 1.42 + AddonManager.getAddonByID(ID, function(newAddon) { 1.43 + do_check_neq(newAddon, null); 1.44 + do_check_eq(newAddon.name, "fr Name"); 1.45 + 1.46 + do_execute_soon(run_test_2); 1.47 + }); 1.48 + })); 1.49 +} 1.50 + 1.51 +function run_test_2() { 1.52 + // Change locale. The more specific de-DE is the best match 1.53 + Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de"); 1.54 + restartManager(); 1.55 + 1.56 + AddonManager.getAddonByID(ID, function(addon) { 1.57 + do_check_neq(addon, null); 1.58 + do_check_eq(addon.name, "de-DE Name"); 1.59 + do_check_eq(addon.description, null); 1.60 + 1.61 + do_execute_soon(run_test_3); 1.62 + }); 1.63 +} 1.64 + 1.65 +function run_test_3() { 1.66 + // Change locale. Locale case should have no effect 1.67 + Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "DE-de"); 1.68 + restartManager(); 1.69 + 1.70 + AddonManager.getAddonByID(ID, function(addon) { 1.71 + do_check_neq(addon, null); 1.72 + do_check_eq(addon.name, "de-DE Name"); 1.73 + do_check_eq(addon.description, null); 1.74 + 1.75 + do_execute_soon(run_test_4); 1.76 + }); 1.77 +} 1.78 + 1.79 +function run_test_4() { 1.80 + // Change locale. es-ES should closely match 1.81 + Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "es-AR"); 1.82 + restartManager(); 1.83 + 1.84 + AddonManager.getAddonByID(ID, function(addon) { 1.85 + do_check_neq(addon, null); 1.86 + do_check_eq(addon.name, "es-ES Name"); 1.87 + do_check_eq(addon.description, "es-ES Description"); 1.88 + 1.89 + do_execute_soon(run_test_5); 1.90 + }); 1.91 +} 1.92 + 1.93 +function run_test_5() { 1.94 + // Change locale. Either zh-CN or zh-TW could match 1.95 + Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "zh"); 1.96 + restartManager(); 1.97 + 1.98 + AddonManager.getAddonByID(ID, function(addon) { 1.99 + do_check_neq(addon, null); 1.100 + if (addon.name != "zh-TW Name" && addon.name != "zh-CN Name") 1.101 + do_throw("zh matched to " + addon.name); 1.102 + 1.103 + do_execute_soon(run_test_6); 1.104 + }); 1.105 +} 1.106 + 1.107 +function run_test_6() { 1.108 + // Unknown locale should try to match against en-US as well. Of en,en-GB 1.109 + // en should match as being less specific 1.110 + Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "nl-NL"); 1.111 + restartManager(); 1.112 + 1.113 + AddonManager.getAddonByID(ID, function(addon) { 1.114 + do_check_neq(addon, null); 1.115 + do_check_eq(addon.name, "en Name"); 1.116 + do_check_eq(addon.description, "en Description"); 1.117 + 1.118 + do_execute_soon(do_test_finished); 1.119 + }); 1.120 +}