1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug587088.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,174 @@ 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 +// Tests that trying to upgrade or uninstall an extension that has a file locked 1.9 +// will roll back the upgrade or uninstall and retry at the next restart 1.10 + 1.11 +const profileDir = gProfD.clone(); 1.12 +profileDir.append("extensions"); 1.13 + 1.14 +function run_test() { 1.15 + // This is only an issue on windows. 1.16 + if (!("nsIWindowsRegKey" in AM_Ci)) 1.17 + return; 1.18 + 1.19 + do_test_pending(); 1.20 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); 1.21 + 1.22 + startupManager(); 1.23 + run_test_1(); 1.24 +} 1.25 + 1.26 +function check_addon(aAddon, aVersion) { 1.27 + do_check_neq(aAddon, null); 1.28 + do_check_eq(aAddon.version, aVersion); 1.29 + do_check_true(aAddon.isActive); 1.30 + do_check_true(isExtensionInAddonsList(profileDir, aAddon.id)); 1.31 + 1.32 + do_check_true(aAddon.hasResource("testfile")); 1.33 + if (aVersion == "1.0") { 1.34 + do_check_true(aAddon.hasResource("testfile1")); 1.35 + do_check_false(aAddon.hasResource("testfile2")); 1.36 + } 1.37 + else { 1.38 + do_check_false(aAddon.hasResource("testfile1")); 1.39 + do_check_true(aAddon.hasResource("testfile2")); 1.40 + } 1.41 + 1.42 + do_check_eq(aAddon.pendingOperations, AddonManager.PENDING_NONE); 1.43 +} 1.44 + 1.45 +function check_addon_upgrading(aAddon) { 1.46 + do_check_neq(aAddon, null); 1.47 + do_check_eq(aAddon.version, "1.0"); 1.48 + do_check_true(aAddon.isActive); 1.49 + do_check_true(isExtensionInAddonsList(profileDir, aAddon.id)); 1.50 + 1.51 + do_check_true(aAddon.hasResource("testfile")); 1.52 + do_check_true(aAddon.hasResource("testfile1")); 1.53 + do_check_false(aAddon.hasResource("testfile2")); 1.54 + 1.55 + do_check_eq(aAddon.pendingOperations, AddonManager.PENDING_UPGRADE); 1.56 + 1.57 + do_check_eq(aAddon.pendingUpgrade.version, "2.0"); 1.58 +} 1.59 + 1.60 +function check_addon_uninstalling(aAddon, aAfterRestart) { 1.61 + do_check_neq(aAddon, null); 1.62 + do_check_eq(aAddon.version, "1.0"); 1.63 + 1.64 + if (aAfterRestart) { 1.65 + do_check_false(aAddon.isActive); 1.66 + do_check_false(isExtensionInAddonsList(profileDir, aAddon.id)); 1.67 + } 1.68 + else { 1.69 + do_check_true(aAddon.isActive); 1.70 + do_check_true(isExtensionInAddonsList(profileDir, aAddon.id)); 1.71 + } 1.72 + 1.73 + do_check_true(aAddon.hasResource("testfile")); 1.74 + do_check_true(aAddon.hasResource("testfile1")); 1.75 + do_check_false(aAddon.hasResource("testfile2")); 1.76 + 1.77 + do_check_eq(aAddon.pendingOperations, AddonManager.PENDING_UNINSTALL); 1.78 +} 1.79 + 1.80 +function run_test_1() { 1.81 + installAllFiles([do_get_addon("test_bug587088_1")], function() { 1.82 + restartManager(); 1.83 + 1.84 + AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { 1.85 + check_addon(a1, "1.0"); 1.86 + 1.87 + // Lock either install.rdf for unpacked add-ons or the xpi for packed add-ons. 1.88 + let uri = a1.getResourceURI("install.rdf"); 1.89 + if (uri.schemeIs("jar")) 1.90 + uri = a1.getResourceURI(); 1.91 + 1.92 + let fstream = AM_Cc["@mozilla.org/network/file-input-stream;1"]. 1.93 + createInstance(AM_Ci.nsIFileInputStream); 1.94 + fstream.init(uri.QueryInterface(AM_Ci.nsIFileURL).file, -1, 0, 0); 1.95 + 1.96 + installAllFiles([do_get_addon("test_bug587088_2")], function() { 1.97 + 1.98 + check_addon_upgrading(a1); 1.99 + 1.100 + restartManager(); 1.101 + 1.102 + AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) { 1.103 + check_addon_upgrading(a1); 1.104 + 1.105 + restartManager(); 1.106 + 1.107 + AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) { 1.108 + check_addon_upgrading(a1); 1.109 + 1.110 + fstream.close(); 1.111 + 1.112 + restartManager(); 1.113 + 1.114 + AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { 1.115 + check_addon(a1, "2.0"); 1.116 + 1.117 + a1.uninstall(); 1.118 + do_execute_soon(run_test_2); 1.119 + }); 1.120 + })); 1.121 + })); 1.122 + }); 1.123 + }); 1.124 + }); 1.125 +} 1.126 + 1.127 +// Test that a failed uninstall gets rolled back 1.128 +function run_test_2() { 1.129 + restartManager(); 1.130 + 1.131 + installAllFiles([do_get_addon("test_bug587088_1")], function() { 1.132 + restartManager(); 1.133 + 1.134 + AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) { 1.135 + check_addon(a1, "1.0"); 1.136 + 1.137 + // Lock either install.rdf for unpacked add-ons or the xpi for packed add-ons. 1.138 + let uri = a1.getResourceURI("install.rdf"); 1.139 + if (uri.schemeIs("jar")) 1.140 + uri = a1.getResourceURI(); 1.141 + 1.142 + let fstream = AM_Cc["@mozilla.org/network/file-input-stream;1"]. 1.143 + createInstance(AM_Ci.nsIFileInputStream); 1.144 + fstream.init(uri.QueryInterface(AM_Ci.nsIFileURL).file, -1, 0, 0); 1.145 + 1.146 + a1.uninstall(); 1.147 + 1.148 + check_addon_uninstalling(a1); 1.149 + 1.150 + restartManager(); 1.151 + 1.152 + AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) { 1.153 + check_addon_uninstalling(a1, true); 1.154 + 1.155 + restartManager(); 1.156 + 1.157 + AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) { 1.158 + check_addon_uninstalling(a1, true); 1.159 + 1.160 + fstream.close(); 1.161 + 1.162 + restartManager(); 1.163 + 1.164 + AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { 1.165 + do_check_eq(a1, null); 1.166 + var dir = profileDir.clone(); 1.167 + dir.append(do_get_expected_addon_name("addon1@tests.mozilla.org")); 1.168 + do_check_false(dir.exists()); 1.169 + do_check_false(isExtensionInAddonsList(profileDir, "addon1@tests.mozilla.org")); 1.170 + 1.171 + do_execute_soon(do_test_finished); 1.172 + }); 1.173 + })); 1.174 + })); 1.175 + })); 1.176 + }); 1.177 +}