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 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | // This verifies that localized properties work as expected |
michael@0 | 6 | |
michael@0 | 7 | const PREF_MATCH_OS_LOCALE = "intl.locale.matchOS"; |
michael@0 | 8 | const PREF_SELECTED_LOCALE = "general.useragent.locale"; |
michael@0 | 9 | |
michael@0 | 10 | |
michael@0 | 11 | function run_test() { |
michael@0 | 12 | do_test_pending(); |
michael@0 | 13 | |
michael@0 | 14 | // Setup for test |
michael@0 | 15 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 16 | Services.prefs.setBoolPref(PREF_MATCH_OS_LOCALE, false); |
michael@0 | 17 | Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR"); |
michael@0 | 18 | |
michael@0 | 19 | startupManager(); |
michael@0 | 20 | |
michael@0 | 21 | run_test_1(); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | // Tests that the localized properties are visible before installation |
michael@0 | 25 | function run_test_1() { |
michael@0 | 26 | AddonManager.getInstallForFile(do_get_addon("test_locale"), function(install) { |
michael@0 | 27 | do_check_eq(install.addon.name, "fr-FR Name"); |
michael@0 | 28 | do_check_eq(install.addon.description, "fr-FR Description"); |
michael@0 | 29 | |
michael@0 | 30 | prepare_test({ |
michael@0 | 31 | "addon1@tests.mozilla.org": [ |
michael@0 | 32 | "onInstalling" |
michael@0 | 33 | ] |
michael@0 | 34 | }, [ |
michael@0 | 35 | "onInstallStarted", |
michael@0 | 36 | "onInstallEnded", |
michael@0 | 37 | ], callback_soon(run_test_2)); |
michael@0 | 38 | install.install(); |
michael@0 | 39 | }); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | // Tests that the localized properties are visible after installation |
michael@0 | 43 | function run_test_2() { |
michael@0 | 44 | restartManager(); |
michael@0 | 45 | |
michael@0 | 46 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { |
michael@0 | 47 | do_check_neq(addon, null); |
michael@0 | 48 | |
michael@0 | 49 | do_check_eq(addon.name, "fr-FR Name"); |
michael@0 | 50 | do_check_eq(addon.description, "fr-FR Description"); |
michael@0 | 51 | |
michael@0 | 52 | addon.userDisabled = true; |
michael@0 | 53 | do_execute_soon(run_test_3); |
michael@0 | 54 | }); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | // Test that the localized properties are still there when disabled. |
michael@0 | 58 | function run_test_3() { |
michael@0 | 59 | restartManager(); |
michael@0 | 60 | |
michael@0 | 61 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { |
michael@0 | 62 | do_check_neq(addon, null); |
michael@0 | 63 | do_check_eq(addon.name, "fr-FR Name"); |
michael@0 | 64 | |
michael@0 | 65 | do_execute_soon(run_test_4); |
michael@0 | 66 | }); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | // Localised preference values should be ignored when the add-on is disabled |
michael@0 | 70 | function run_test_4() { |
michael@0 | 71 | Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.name", "Name from prefs"); |
michael@0 | 72 | Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.contributor.1", "Contributor 1"); |
michael@0 | 73 | Services.prefs.setCharPref("extensions.addon1@tests.mozilla.org.contributor.2", "Contributor 2"); |
michael@0 | 74 | restartManager(); |
michael@0 | 75 | |
michael@0 | 76 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { |
michael@0 | 77 | do_check_neq(addon, null); |
michael@0 | 78 | do_check_eq(addon.name, "fr-FR Name"); |
michael@0 | 79 | let contributors = addon.contributors; |
michael@0 | 80 | do_check_eq(contributors.length, 3); |
michael@0 | 81 | do_check_eq(contributors[0], "Fr Contributor 1"); |
michael@0 | 82 | do_check_eq(contributors[1], "Fr Contributor 2"); |
michael@0 | 83 | do_check_eq(contributors[2], "Fr Contributor 3"); |
michael@0 | 84 | |
michael@0 | 85 | do_execute_soon(run_test_5); |
michael@0 | 86 | }); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | // Test that changing locale works |
michael@0 | 90 | function run_test_5() { |
michael@0 | 91 | Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "de-DE"); |
michael@0 | 92 | restartManager(); |
michael@0 | 93 | |
michael@0 | 94 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { |
michael@0 | 95 | do_check_neq(addon, null); |
michael@0 | 96 | |
michael@0 | 97 | do_check_eq(addon.name, "de-DE Name"); |
michael@0 | 98 | do_check_eq(addon.description, null); |
michael@0 | 99 | |
michael@0 | 100 | do_execute_soon(run_test_6); |
michael@0 | 101 | }); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | // Test that missing locales use the fallbacks |
michael@0 | 105 | function run_test_6() { |
michael@0 | 106 | Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "nl-NL"); |
michael@0 | 107 | restartManager(); |
michael@0 | 108 | |
michael@0 | 109 | AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(addon) { |
michael@0 | 110 | do_check_neq(addon, null); |
michael@0 | 111 | |
michael@0 | 112 | do_check_eq(addon.name, "Fallback Name"); |
michael@0 | 113 | do_check_eq(addon.description, "Fallback Description"); |
michael@0 | 114 | |
michael@0 | 115 | addon.userDisabled = false; |
michael@0 | 116 | do_execute_soon(run_test_7); |
michael@0 | 117 | })); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | // Test that the prefs will override the fallbacks |
michael@0 | 121 | function run_test_7() { |
michael@0 | 122 | restartManager(); |
michael@0 | 123 | |
michael@0 | 124 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { |
michael@0 | 125 | do_check_neq(addon, null); |
michael@0 | 126 | |
michael@0 | 127 | do_check_eq(addon.name, "Name from prefs"); |
michael@0 | 128 | |
michael@0 | 129 | do_execute_soon(run_test_8); |
michael@0 | 130 | }); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | // Test that the prefs will override localized values from the manifest |
michael@0 | 134 | function run_test_8() { |
michael@0 | 135 | Services.prefs.setCharPref(PREF_SELECTED_LOCALE, "fr-FR"); |
michael@0 | 136 | restartManager(); |
michael@0 | 137 | |
michael@0 | 138 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(addon) { |
michael@0 | 139 | do_check_neq(addon, null); |
michael@0 | 140 | |
michael@0 | 141 | do_check_eq(addon.name, "Name from prefs"); |
michael@0 | 142 | let contributors = addon.contributors; |
michael@0 | 143 | do_check_eq(contributors.length, 2); |
michael@0 | 144 | do_check_eq(contributors[0], "Contributor 1"); |
michael@0 | 145 | do_check_eq(contributors[1], "Contributor 2"); |
michael@0 | 146 | |
michael@0 | 147 | do_execute_soon(do_test_finished); |
michael@0 | 148 | }); |
michael@0 | 149 | } |