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