1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_upgrade.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,206 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// This verifies that app upgrades produce the expected behaviours, 1.9 +// with strict compatibility checking disabled. 1.10 + 1.11 +Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false); 1.12 + 1.13 +// Enable loading extensions from the application scope 1.14 +Services.prefs.setIntPref("extensions.enabledScopes", 1.15 + AddonManager.SCOPE_PROFILE + 1.16 + AddonManager.SCOPE_APPLICATION); 1.17 + 1.18 +const profileDir = gProfD.clone(); 1.19 +profileDir.append("extensions"); 1.20 + 1.21 +const globalDir = Services.dirsvc.get("XCurProcD", AM_Ci.nsIFile); 1.22 +globalDir.append("extensions"); 1.23 + 1.24 +var gGlobalExisted = globalDir.exists(); 1.25 +var gInstallTime = Date.now(); 1.26 + 1.27 +function run_test() { 1.28 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); 1.29 + 1.30 + // Will be compatible in the first version and incompatible in subsequent versions 1.31 + writeInstallRDFForExtension({ 1.32 + id: "addon1@tests.mozilla.org", 1.33 + version: "1.0", 1.34 + targetApplications: [{ 1.35 + id: "xpcshell@tests.mozilla.org", 1.36 + minVersion: "1", 1.37 + maxVersion: "1" 1.38 + }], 1.39 + name: "Test Addon 1", 1.40 + targetPlatforms: [ 1.41 + "XPCShell", 1.42 + "WINNT_x86", 1.43 + ] 1.44 + }, profileDir); 1.45 + 1.46 + // Works in all tested versions 1.47 + writeInstallRDFForExtension({ 1.48 + id: "addon2@tests.mozilla.org", 1.49 + version: "1.0", 1.50 + targetApplications: [{ 1.51 + id: "xpcshell@tests.mozilla.org", 1.52 + minVersion: "1", 1.53 + maxVersion: "2" 1.54 + }], 1.55 + name: "Test Addon 2", 1.56 + targetPlatforms: [ 1.57 + "XPCShell_noarch-spidermonkey" 1.58 + ] 1.59 + }, profileDir); 1.60 + 1.61 + // Will be disabled in the first version and enabled in the second. 1.62 + writeInstallRDFForExtension({ 1.63 + id: "addon3@tests.mozilla.org", 1.64 + version: "1.0", 1.65 + targetApplications: [{ 1.66 + id: "xpcshell@tests.mozilla.org", 1.67 + minVersion: "2", 1.68 + maxVersion: "2" 1.69 + }], 1.70 + name: "Test Addon 3", 1.71 + }, profileDir); 1.72 + 1.73 + // Will be compatible in both versions but will change version in between 1.74 + var dest = writeInstallRDFForExtension({ 1.75 + id: "addon4@tests.mozilla.org", 1.76 + version: "1.0", 1.77 + targetApplications: [{ 1.78 + id: "xpcshell@tests.mozilla.org", 1.79 + minVersion: "1", 1.80 + maxVersion: "1" 1.81 + }], 1.82 + name: "Test Addon 4", 1.83 + }, globalDir); 1.84 + setExtensionModifiedTime(dest, gInstallTime); 1.85 + 1.86 + do_test_pending(); 1.87 + 1.88 + run_test_1(); 1.89 +} 1.90 + 1.91 +function end_test() { 1.92 + if (!gGlobalExisted) { 1.93 + globalDir.remove(true); 1.94 + } 1.95 + else { 1.96 + globalDir.append(do_get_expected_addon_name("addon4@tests.mozilla.org")); 1.97 + globalDir.remove(true); 1.98 + } 1.99 + do_execute_soon(do_test_finished); 1.100 +} 1.101 + 1.102 +// Test that the test extensions are all installed 1.103 +function run_test_1() { 1.104 + startupManager(); 1.105 + 1.106 + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", 1.107 + "addon2@tests.mozilla.org", 1.108 + "addon3@tests.mozilla.org", 1.109 + "addon4@tests.mozilla.org"], 1.110 + function([a1, a2, a3, a4]) { 1.111 + 1.112 + do_check_neq(a1, null); 1.113 + do_check_true(isExtensionInAddonsList(profileDir, a1.id)); 1.114 + 1.115 + do_check_neq(a2, null); 1.116 + do_check_true(isExtensionInAddonsList(profileDir, a2.id)); 1.117 + 1.118 + do_check_neq(a3, null); 1.119 + do_check_false(isExtensionInAddonsList(profileDir, a3.id)); 1.120 + 1.121 + do_check_neq(a4, null); 1.122 + do_check_true(isExtensionInAddonsList(globalDir, a4.id)); 1.123 + do_check_eq(a4.version, "1.0"); 1.124 + 1.125 + do_execute_soon(run_test_2); 1.126 + }); 1.127 +} 1.128 + 1.129 +// Test that upgrading the application doesn't disable now incompatible add-ons 1.130 +function run_test_2() { 1.131 + // Upgrade the extension 1.132 + var dest = writeInstallRDFForExtension({ 1.133 + id: "addon4@tests.mozilla.org", 1.134 + version: "2.0", 1.135 + targetApplications: [{ 1.136 + id: "xpcshell@tests.mozilla.org", 1.137 + minVersion: "2", 1.138 + maxVersion: "2" 1.139 + }], 1.140 + name: "Test Addon 4", 1.141 + }, globalDir); 1.142 + setExtensionModifiedTime(dest, gInstallTime); 1.143 + 1.144 + restartManager("2"); 1.145 + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", 1.146 + "addon2@tests.mozilla.org", 1.147 + "addon3@tests.mozilla.org", 1.148 + "addon4@tests.mozilla.org"], 1.149 + function([a1, a2, a3, a4]) { 1.150 + 1.151 + do_check_neq(a1, null); 1.152 + do_check_true(isExtensionInAddonsList(profileDir, a1.id)); 1.153 + 1.154 + do_check_neq(a2, null); 1.155 + do_check_true(isExtensionInAddonsList(profileDir, a2.id)); 1.156 + 1.157 + do_check_neq(a3, null); 1.158 + do_check_true(isExtensionInAddonsList(profileDir, a3.id)); 1.159 + 1.160 + do_check_neq(a4, null); 1.161 + do_check_true(isExtensionInAddonsList(globalDir, a4.id)); 1.162 + do_check_eq(a4.version, "2.0"); 1.163 + 1.164 + do_execute_soon(run_test_3); 1.165 + }); 1.166 +} 1.167 + 1.168 +// Test that nothing changes when only the build ID changes. 1.169 +function run_test_3() { 1.170 + // Upgrade the extension 1.171 + var dest = writeInstallRDFForExtension({ 1.172 + id: "addon4@tests.mozilla.org", 1.173 + version: "3.0", 1.174 + targetApplications: [{ 1.175 + id: "xpcshell@tests.mozilla.org", 1.176 + minVersion: "3", 1.177 + maxVersion: "3" 1.178 + }], 1.179 + name: "Test Addon 4", 1.180 + }, globalDir); 1.181 + setExtensionModifiedTime(dest, gInstallTime); 1.182 + 1.183 + // Simulates a simple Build ID change, the platform deletes extensions.ini 1.184 + // whenever the application is changed. 1.185 + gExtensionsINI.remove(true); 1.186 + restartManager(); 1.187 + 1.188 + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", 1.189 + "addon2@tests.mozilla.org", 1.190 + "addon3@tests.mozilla.org", 1.191 + "addon4@tests.mozilla.org"], 1.192 + function([a1, a2, a3, a4]) { 1.193 + 1.194 + do_check_neq(a1, null); 1.195 + do_check_true(isExtensionInAddonsList(profileDir, a1.id)); 1.196 + 1.197 + do_check_neq(a2, null); 1.198 + do_check_true(isExtensionInAddonsList(profileDir, a2.id)); 1.199 + 1.200 + do_check_neq(a3, null); 1.201 + do_check_true(isExtensionInAddonsList(profileDir, a3.id)); 1.202 + 1.203 + do_check_neq(a4, null); 1.204 + do_check_true(isExtensionInAddonsList(globalDir, a4.id)); 1.205 + do_check_eq(a4.version, "2.0"); 1.206 + 1.207 + end_test(); 1.208 + }); 1.209 +}