1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_migrate1.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,251 @@ 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 +// Checks that we migrate data from the old rdf style database 1.9 + 1.10 +var addon1 = { 1.11 + id: "addon1@tests.mozilla.org", 1.12 + version: "1.0", 1.13 + name: "Test 1", 1.14 + targetApplications: [{ 1.15 + id: "xpcshell@tests.mozilla.org", 1.16 + minVersion: "1", 1.17 + maxVersion: "1" 1.18 + }] 1.19 +}; 1.20 + 1.21 +var addon2 = { 1.22 + id: "addon2@tests.mozilla.org", 1.23 + version: "2.0", 1.24 + name: "Test 2", 1.25 + targetApplications: [{ 1.26 + id: "toolkit@mozilla.org", 1.27 + minVersion: "1", 1.28 + maxVersion: "1" 1.29 + }] 1.30 +}; 1.31 + 1.32 +var addon3 = { 1.33 + id: "addon3@tests.mozilla.org", 1.34 + version: "2.0", 1.35 + name: "Test 3", 1.36 + targetApplications: [{ 1.37 + id: "xpcshell@tests.mozilla.org", 1.38 + minVersion: "1", 1.39 + maxVersion: "1" 1.40 + }] 1.41 +}; 1.42 + 1.43 +var addon4 = { 1.44 + id: "addon4@tests.mozilla.org", 1.45 + version: "2.0", 1.46 + name: "Test 4", 1.47 + targetApplications: [{ 1.48 + id: "toolkit@mozilla.org", 1.49 + minVersion: "1", 1.50 + maxVersion: "1" 1.51 + }] 1.52 +}; 1.53 + 1.54 +var addon5 = { 1.55 + id: "addon5@tests.mozilla.org", 1.56 + version: "2.0", 1.57 + name: "Test 5", 1.58 + targetApplications: [{ 1.59 + id: "toolkit@mozilla.org", 1.60 + minVersion: "1", 1.61 + maxVersion: "1" 1.62 + }] 1.63 +}; 1.64 + 1.65 +var theme1 = { 1.66 + id: "theme1@tests.mozilla.org", 1.67 + version: "1.0", 1.68 + name: "Theme 1", 1.69 + type: 4, 1.70 + internalName: "theme1/1.0", 1.71 + targetApplications: [{ 1.72 + id: "xpcshell@tests.mozilla.org", 1.73 + minVersion: "1", 1.74 + maxVersion: "2" 1.75 + }] 1.76 +}; 1.77 + 1.78 +var theme2 = { 1.79 + id: "theme2@tests.mozilla.org", 1.80 + version: "1.0", 1.81 + name: "Theme 2", 1.82 + type: 4, 1.83 + internalName: "theme2/1.0", 1.84 + targetApplications: [{ 1.85 + id: "xpcshell@tests.mozilla.org", 1.86 + minVersion: "1", 1.87 + maxVersion: "2" 1.88 + }] 1.89 +}; 1.90 + 1.91 +const profileDir = gProfD.clone(); 1.92 +profileDir.append("extensions"); 1.93 + 1.94 +function run_test() { 1.95 + do_test_pending(); 1.96 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2"); 1.97 + 1.98 + writeInstallRDFForExtension(addon1, profileDir); 1.99 + writeInstallRDFForExtension(addon2, profileDir); 1.100 + writeInstallRDFForExtension(addon3, profileDir); 1.101 + writeInstallRDFForExtension(addon4, profileDir); 1.102 + writeInstallRDFForExtension(addon5, profileDir); 1.103 + writeInstallRDFForExtension(theme1, profileDir); 1.104 + writeInstallRDFForExtension(theme2, profileDir); 1.105 + 1.106 + let stagedXPIs = profileDir.clone(); 1.107 + stagedXPIs.append("staged-xpis"); 1.108 + stagedXPIs.append("addon6@tests.mozilla.org"); 1.109 + stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); 1.110 + 1.111 + let addon6 = do_get_addon("test_migrate6"); 1.112 + addon6.copyTo(stagedXPIs, "tmp.xpi"); 1.113 + stagedXPIs = stagedXPIs.parent; 1.114 + 1.115 + stagedXPIs.append("addon7@tests.mozilla.org"); 1.116 + stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); 1.117 + 1.118 + let addon7 = do_get_addon("test_migrate7"); 1.119 + addon7.copyTo(stagedXPIs, "tmp.xpi"); 1.120 + stagedXPIs = stagedXPIs.parent; 1.121 + 1.122 + stagedXPIs.append("addon8@tests.mozilla.org"); 1.123 + stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); 1.124 + 1.125 + let addon7 = do_get_addon("test_migrate8"); 1.126 + addon7.copyTo(stagedXPIs, "tmp.xpi"); 1.127 + stagedXPIs = stagedXPIs.parent; 1.128 + 1.129 + let old = do_get_file("data/test_migrate.rdf"); 1.130 + old.copyTo(gProfD, "extensions.rdf"); 1.131 + 1.132 + let oldCache = gProfD.clone(); 1.133 + oldCache.append("extensions.cache"); 1.134 + oldCache.create(AM_Ci.nsIFile.NORMAL_FILE_TYPE, FileUtils.PERMS_FILE); 1.135 + 1.136 + // Theme state is determined by the selected theme pref 1.137 + Services.prefs.setCharPref("general.skins.selectedSkin", "theme1/1.0"); 1.138 + 1.139 + Services.prefs.setCharPref("extensions.lastAppVersion", "1"); 1.140 + 1.141 + startupManager(); 1.142 + check_startup_changes("installed", []); 1.143 + check_startup_changes("updated", []); 1.144 + check_startup_changes("uninstalled", []); 1.145 + check_startup_changes("disabled", []); 1.146 + check_startup_changes("enabled", []); 1.147 + 1.148 + do_check_false(oldCache.exists()); 1.149 + 1.150 + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", 1.151 + "addon2@tests.mozilla.org", 1.152 + "addon3@tests.mozilla.org", 1.153 + "addon4@tests.mozilla.org", 1.154 + "addon5@tests.mozilla.org", 1.155 + "addon6@tests.mozilla.org", 1.156 + "addon7@tests.mozilla.org", 1.157 + "addon8@tests.mozilla.org", 1.158 + "theme1@tests.mozilla.org", 1.159 + "theme2@tests.mozilla.org"], function([a1, a2, a3, 1.160 + a4, a5, a6, 1.161 + a7, a8, t1, 1.162 + t2]) { 1.163 + // addon1 was user and app enabled in the old extensions.rdf 1.164 + do_check_neq(a1, null); 1.165 + do_check_false(a1.userDisabled); 1.166 + do_check_false(a1.appDisabled); 1.167 + do_check_true(a1.isActive); 1.168 + do_check_true(isExtensionInAddonsList(profileDir, a1.id)); 1.169 + do_check_false(a1.hasBinaryComponents); 1.170 + 1.171 + // addon2 was user disabled and app enabled in the old extensions.rdf 1.172 + do_check_neq(a2, null); 1.173 + do_check_true(a2.userDisabled); 1.174 + do_check_false(a2.appDisabled); 1.175 + do_check_false(a2.isActive); 1.176 + do_check_false(isExtensionInAddonsList(profileDir, a2.id)); 1.177 + do_check_false(a2.hasBinaryComponents); 1.178 + 1.179 + // addon3 was pending user disable and app disabled in the old extensions.rdf 1.180 + do_check_neq(a3, null); 1.181 + do_check_true(a3.userDisabled); 1.182 + do_check_true(a3.appDisabled); 1.183 + do_check_false(a3.isActive); 1.184 + do_check_false(isExtensionInAddonsList(profileDir, a3.id)); 1.185 + do_check_false(a3.hasBinaryComponents); 1.186 + 1.187 + // addon4 was pending user enable and app disabled in the old extensions.rdf 1.188 + do_check_neq(a4, null); 1.189 + do_check_false(a4.userDisabled); 1.190 + do_check_true(a4.appDisabled); 1.191 + do_check_false(a4.isActive); 1.192 + do_check_false(isExtensionInAddonsList(profileDir, a4.id)); 1.193 + do_check_false(a4.hasBinaryComponents); 1.194 + 1.195 + // addon5 was disabled and compatible but a new version has been installed 1.196 + // since, it should still be disabled but should be incompatible 1.197 + do_check_neq(a5, null); 1.198 + do_check_true(a5.userDisabled); 1.199 + do_check_true(a5.appDisabled); 1.200 + do_check_false(a5.isActive); 1.201 + do_check_false(isExtensionInAddonsList(profileDir, a5.id)); 1.202 + do_check_false(a5.hasBinaryComponents); 1.203 + 1.204 + // addon6 should be installed and compatible and packed unless unpacking is 1.205 + // forced 1.206 + do_check_neq(a6, null); 1.207 + do_check_false(a6.userDisabled); 1.208 + do_check_false(a6.appDisabled); 1.209 + do_check_true(a6.isActive); 1.210 + do_check_true(isExtensionInAddonsList(profileDir, a6.id)); 1.211 + if (Services.prefs.getBoolPref("extensions.alwaysUnpack")) 1.212 + do_check_eq(a6.getResourceURI("install.rdf").scheme, "file"); 1.213 + else 1.214 + do_check_eq(a6.getResourceURI("install.rdf").scheme, "jar"); 1.215 + do_check_false(a6.hasBinaryComponents); 1.216 + 1.217 + // addon7 should be installed and compatible and unpacked 1.218 + do_check_neq(a7, null); 1.219 + do_check_false(a7.userDisabled); 1.220 + do_check_false(a7.appDisabled); 1.221 + do_check_true(a7.isActive); 1.222 + do_check_true(isExtensionInAddonsList(profileDir, a7.id)); 1.223 + do_check_eq(a7.getResourceURI("install.rdf").scheme, "file"); 1.224 + do_check_false(a7.hasBinaryComponents); 1.225 + 1.226 + // addon8 should be installed and compatible and have binary components 1.227 + do_check_neq(a8, null); 1.228 + do_check_false(a8.userDisabled); 1.229 + do_check_false(a8.appDisabled); 1.230 + do_check_true(a8.isActive); 1.231 + do_check_true(isExtensionInAddonsList(profileDir, a8.id)); 1.232 + do_check_true(a8.hasBinaryComponents); 1.233 + 1.234 + // Theme 1 was previously enabled 1.235 + do_check_neq(t1, null); 1.236 + do_check_false(t1.userDisabled); 1.237 + do_check_false(t1.appDisabled); 1.238 + do_check_true(t1.isActive); 1.239 + do_check_true(isThemeInAddonsList(profileDir, t1.id)); 1.240 + do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE)); 1.241 + 1.242 + // Theme 2 was previously disabled 1.243 + do_check_neq(t1, null); 1.244 + do_check_true(t2.userDisabled); 1.245 + do_check_false(t2.appDisabled); 1.246 + do_check_false(t2.isActive); 1.247 + do_check_false(isThemeInAddonsList(profileDir, t2.id)); 1.248 + do_check_true(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE)); 1.249 + 1.250 + do_check_false(stagedXPIs.exists()); 1.251 + 1.252 + do_execute_soon(do_test_finished); 1.253 + }); 1.254 +}