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