toolkit/mozapps/extensions/test/xpcshell/test_bug587088.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 // Tests that trying to upgrade or uninstall an extension that has a file locked
michael@0 6 // will roll back the upgrade or uninstall and retry at the next restart
michael@0 7
michael@0 8 const profileDir = gProfD.clone();
michael@0 9 profileDir.append("extensions");
michael@0 10
michael@0 11 function run_test() {
michael@0 12 // This is only an issue on windows.
michael@0 13 if (!("nsIWindowsRegKey" in AM_Ci))
michael@0 14 return;
michael@0 15
michael@0 16 do_test_pending();
michael@0 17 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
michael@0 18
michael@0 19 startupManager();
michael@0 20 run_test_1();
michael@0 21 }
michael@0 22
michael@0 23 function check_addon(aAddon, aVersion) {
michael@0 24 do_check_neq(aAddon, null);
michael@0 25 do_check_eq(aAddon.version, aVersion);
michael@0 26 do_check_true(aAddon.isActive);
michael@0 27 do_check_true(isExtensionInAddonsList(profileDir, aAddon.id));
michael@0 28
michael@0 29 do_check_true(aAddon.hasResource("testfile"));
michael@0 30 if (aVersion == "1.0") {
michael@0 31 do_check_true(aAddon.hasResource("testfile1"));
michael@0 32 do_check_false(aAddon.hasResource("testfile2"));
michael@0 33 }
michael@0 34 else {
michael@0 35 do_check_false(aAddon.hasResource("testfile1"));
michael@0 36 do_check_true(aAddon.hasResource("testfile2"));
michael@0 37 }
michael@0 38
michael@0 39 do_check_eq(aAddon.pendingOperations, AddonManager.PENDING_NONE);
michael@0 40 }
michael@0 41
michael@0 42 function check_addon_upgrading(aAddon) {
michael@0 43 do_check_neq(aAddon, null);
michael@0 44 do_check_eq(aAddon.version, "1.0");
michael@0 45 do_check_true(aAddon.isActive);
michael@0 46 do_check_true(isExtensionInAddonsList(profileDir, aAddon.id));
michael@0 47
michael@0 48 do_check_true(aAddon.hasResource("testfile"));
michael@0 49 do_check_true(aAddon.hasResource("testfile1"));
michael@0 50 do_check_false(aAddon.hasResource("testfile2"));
michael@0 51
michael@0 52 do_check_eq(aAddon.pendingOperations, AddonManager.PENDING_UPGRADE);
michael@0 53
michael@0 54 do_check_eq(aAddon.pendingUpgrade.version, "2.0");
michael@0 55 }
michael@0 56
michael@0 57 function check_addon_uninstalling(aAddon, aAfterRestart) {
michael@0 58 do_check_neq(aAddon, null);
michael@0 59 do_check_eq(aAddon.version, "1.0");
michael@0 60
michael@0 61 if (aAfterRestart) {
michael@0 62 do_check_false(aAddon.isActive);
michael@0 63 do_check_false(isExtensionInAddonsList(profileDir, aAddon.id));
michael@0 64 }
michael@0 65 else {
michael@0 66 do_check_true(aAddon.isActive);
michael@0 67 do_check_true(isExtensionInAddonsList(profileDir, aAddon.id));
michael@0 68 }
michael@0 69
michael@0 70 do_check_true(aAddon.hasResource("testfile"));
michael@0 71 do_check_true(aAddon.hasResource("testfile1"));
michael@0 72 do_check_false(aAddon.hasResource("testfile2"));
michael@0 73
michael@0 74 do_check_eq(aAddon.pendingOperations, AddonManager.PENDING_UNINSTALL);
michael@0 75 }
michael@0 76
michael@0 77 function run_test_1() {
michael@0 78 installAllFiles([do_get_addon("test_bug587088_1")], function() {
michael@0 79 restartManager();
michael@0 80
michael@0 81 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 82 check_addon(a1, "1.0");
michael@0 83
michael@0 84 // Lock either install.rdf for unpacked add-ons or the xpi for packed add-ons.
michael@0 85 let uri = a1.getResourceURI("install.rdf");
michael@0 86 if (uri.schemeIs("jar"))
michael@0 87 uri = a1.getResourceURI();
michael@0 88
michael@0 89 let fstream = AM_Cc["@mozilla.org/network/file-input-stream;1"].
michael@0 90 createInstance(AM_Ci.nsIFileInputStream);
michael@0 91 fstream.init(uri.QueryInterface(AM_Ci.nsIFileURL).file, -1, 0, 0);
michael@0 92
michael@0 93 installAllFiles([do_get_addon("test_bug587088_2")], function() {
michael@0 94
michael@0 95 check_addon_upgrading(a1);
michael@0 96
michael@0 97 restartManager();
michael@0 98
michael@0 99 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
michael@0 100 check_addon_upgrading(a1);
michael@0 101
michael@0 102 restartManager();
michael@0 103
michael@0 104 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
michael@0 105 check_addon_upgrading(a1);
michael@0 106
michael@0 107 fstream.close();
michael@0 108
michael@0 109 restartManager();
michael@0 110
michael@0 111 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 112 check_addon(a1, "2.0");
michael@0 113
michael@0 114 a1.uninstall();
michael@0 115 do_execute_soon(run_test_2);
michael@0 116 });
michael@0 117 }));
michael@0 118 }));
michael@0 119 });
michael@0 120 });
michael@0 121 });
michael@0 122 }
michael@0 123
michael@0 124 // Test that a failed uninstall gets rolled back
michael@0 125 function run_test_2() {
michael@0 126 restartManager();
michael@0 127
michael@0 128 installAllFiles([do_get_addon("test_bug587088_1")], function() {
michael@0 129 restartManager();
michael@0 130
michael@0 131 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
michael@0 132 check_addon(a1, "1.0");
michael@0 133
michael@0 134 // Lock either install.rdf for unpacked add-ons or the xpi for packed add-ons.
michael@0 135 let uri = a1.getResourceURI("install.rdf");
michael@0 136 if (uri.schemeIs("jar"))
michael@0 137 uri = a1.getResourceURI();
michael@0 138
michael@0 139 let fstream = AM_Cc["@mozilla.org/network/file-input-stream;1"].
michael@0 140 createInstance(AM_Ci.nsIFileInputStream);
michael@0 141 fstream.init(uri.QueryInterface(AM_Ci.nsIFileURL).file, -1, 0, 0);
michael@0 142
michael@0 143 a1.uninstall();
michael@0 144
michael@0 145 check_addon_uninstalling(a1);
michael@0 146
michael@0 147 restartManager();
michael@0 148
michael@0 149 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
michael@0 150 check_addon_uninstalling(a1, true);
michael@0 151
michael@0 152 restartManager();
michael@0 153
michael@0 154 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
michael@0 155 check_addon_uninstalling(a1, true);
michael@0 156
michael@0 157 fstream.close();
michael@0 158
michael@0 159 restartManager();
michael@0 160
michael@0 161 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 162 do_check_eq(a1, null);
michael@0 163 var dir = profileDir.clone();
michael@0 164 dir.append(do_get_expected_addon_name("addon1@tests.mozilla.org"));
michael@0 165 do_check_false(dir.exists());
michael@0 166 do_check_false(isExtensionInAddonsList(profileDir, "addon1@tests.mozilla.org"));
michael@0 167
michael@0 168 do_execute_soon(do_test_finished);
michael@0 169 });
michael@0 170 }));
michael@0 171 }));
michael@0 172 }));
michael@0 173 });
michael@0 174 }

mercurial