toolkit/mozapps/extensions/test/xpcshell/test_locked2.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 // Checks that we handle a locked database when there are extension changes
michael@0 6 // in progress
michael@0 7
michael@0 8 Components.utils.import("resource://gre/modules/osfile.jsm");
michael@0 9
michael@0 10 // Will be left alone
michael@0 11 var addon1 = {
michael@0 12 id: "addon1@tests.mozilla.org",
michael@0 13 version: "1.0",
michael@0 14 name: "Test 1",
michael@0 15 targetApplications: [{
michael@0 16 id: "xpcshell@tests.mozilla.org",
michael@0 17 minVersion: "2",
michael@0 18 maxVersion: "2"
michael@0 19 }]
michael@0 20 };
michael@0 21
michael@0 22 // Will be enabled
michael@0 23 var addon2 = {
michael@0 24 id: "addon2@tests.mozilla.org",
michael@0 25 version: "1.0",
michael@0 26 name: "Test 2",
michael@0 27 targetApplications: [{
michael@0 28 id: "xpcshell@tests.mozilla.org",
michael@0 29 minVersion: "2",
michael@0 30 maxVersion: "2"
michael@0 31 }]
michael@0 32 };
michael@0 33
michael@0 34 // Will be disabled
michael@0 35 var addon3 = {
michael@0 36 id: "addon3@tests.mozilla.org",
michael@0 37 version: "1.0",
michael@0 38 name: "Test 3",
michael@0 39 targetApplications: [{
michael@0 40 id: "xpcshell@tests.mozilla.org",
michael@0 41 minVersion: "2",
michael@0 42 maxVersion: "2"
michael@0 43 }]
michael@0 44 };
michael@0 45
michael@0 46 // Will be uninstalled
michael@0 47 var addon4 = {
michael@0 48 id: "addon4@tests.mozilla.org",
michael@0 49 version: "1.0",
michael@0 50 name: "Test 4",
michael@0 51 targetApplications: [{
michael@0 52 id: "xpcshell@tests.mozilla.org",
michael@0 53 minVersion: "2",
michael@0 54 maxVersion: "2"
michael@0 55 }]
michael@0 56 };
michael@0 57
michael@0 58
michael@0 59 // Will be updated
michael@0 60 var addon5 = {
michael@0 61 id: "addon5@tests.mozilla.org",
michael@0 62 version: "1.0",
michael@0 63 name: "Test 5",
michael@0 64 targetApplications: [{
michael@0 65 id: "xpcshell@tests.mozilla.org",
michael@0 66 minVersion: "2",
michael@0 67 maxVersion: "2"
michael@0 68 }]
michael@0 69 };
michael@0 70
michael@0 71 const profileDir = gProfD.clone();
michael@0 72 profileDir.append("extensions");
michael@0 73
michael@0 74 add_task(function() {
michael@0 75
michael@0 76 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
michael@0 77
michael@0 78 writeInstallRDFForExtension(addon1, profileDir);
michael@0 79 writeInstallRDFForExtension(addon2, profileDir);
michael@0 80 writeInstallRDFForExtension(addon3, profileDir);
michael@0 81 writeInstallRDFForExtension(addon4, profileDir);
michael@0 82 writeInstallRDFForExtension(addon5, profileDir);
michael@0 83
michael@0 84 // Make it look like add-on 5 was installed some time in the past so the update is
michael@0 85 // detected
michael@0 86 let path = getFileForAddon(profileDir, addon5.id).path;
michael@0 87 yield promiseSetExtensionModifiedTime(path, Date.now() - (60000));
michael@0 88
michael@0 89 // Startup the profile and setup the initial state
michael@0 90 startupManager();
michael@0 91
michael@0 92 check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
michael@0 93 check_startup_changes(AddonManager.STARTUP_CHANGE_UNINSTALLED, []);
michael@0 94
michael@0 95 let a1, a2, a3, a4, a5, a6;
michael@0 96
michael@0 97 [a2] = yield promiseAddonsByIDs(["addon2@tests.mozilla.org"]);
michael@0 98 a2.userDisabled = true;
michael@0 99
michael@0 100 restartManager();
michael@0 101
michael@0 102 [a1, a2, a3, a4, a5] =
michael@0 103 yield promiseAddonsByIDs(["addon1@tests.mozilla.org",
michael@0 104 "addon2@tests.mozilla.org",
michael@0 105 "addon3@tests.mozilla.org",
michael@0 106 "addon4@tests.mozilla.org",
michael@0 107 "addon5@tests.mozilla.org"]);
michael@0 108
michael@0 109 a2.userDisabled = false;
michael@0 110 a3.userDisabled = true;
michael@0 111 a4.uninstall();
michael@0 112
michael@0 113 yield promiseInstallAllFiles([do_get_addon("test_locked2_5"),
michael@0 114 do_get_addon("test_locked2_6")]);
michael@0 115 do_check_neq(a1, null);
michael@0 116 do_check_true(a1.isActive);
michael@0 117 do_check_false(a1.userDisabled);
michael@0 118 do_check_false(a1.appDisabled);
michael@0 119 do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
michael@0 120 do_check_true(isExtensionInAddonsList(profileDir, a1.id));
michael@0 121
michael@0 122 do_check_neq(a2, null);
michael@0 123 do_check_false(a2.isActive);
michael@0 124 do_check_false(a2.userDisabled);
michael@0 125 do_check_false(a2.appDisabled);
michael@0 126 do_check_eq(a2.pendingOperations, AddonManager.PENDING_ENABLE);
michael@0 127 do_check_false(isExtensionInAddonsList(profileDir, a2.id));
michael@0 128
michael@0 129 do_check_neq(a3, null);
michael@0 130 do_check_true(a3.isActive);
michael@0 131 do_check_true(a3.userDisabled);
michael@0 132 do_check_false(a3.appDisabled);
michael@0 133 do_check_eq(a3.pendingOperations, AddonManager.PENDING_DISABLE);
michael@0 134 do_check_true(isExtensionInAddonsList(profileDir, a3.id));
michael@0 135
michael@0 136 do_check_neq(a4, null);
michael@0 137 do_check_true(a4.isActive);
michael@0 138 do_check_false(a4.userDisabled);
michael@0 139 do_check_false(a4.appDisabled);
michael@0 140 do_check_eq(a4.pendingOperations, AddonManager.PENDING_UNINSTALL);
michael@0 141 do_check_true(isExtensionInAddonsList(profileDir, a4.id));
michael@0 142
michael@0 143 do_check_neq(a5, null);
michael@0 144 do_check_eq(a5.version, "1.0");
michael@0 145 do_check_true(a5.isActive);
michael@0 146 do_check_false(a5.userDisabled);
michael@0 147 do_check_false(a5.appDisabled);
michael@0 148 do_check_eq(a5.pendingOperations, AddonManager.PENDING_UPGRADE);
michael@0 149 do_check_true(isExtensionInAddonsList(profileDir, a5.id));
michael@0 150
michael@0 151 // Open another handle on the JSON DB with as much Unix and Windows locking
michael@0 152 // as we can to simulate some other process interfering with it
michael@0 153 shutdownManager();
michael@0 154 do_print("Locking " + gExtensionsJSON.path);
michael@0 155 let options = {
michael@0 156 winShare: 0
michael@0 157 };
michael@0 158 if (OS.Constants.libc.O_EXLOCK)
michael@0 159 options.unixFlags = OS.Constants.libc.O_EXLOCK;
michael@0 160
michael@0 161 let file = yield OS.File.open(gExtensionsJSON.path, {read:true, write:true, existing:true}, options);
michael@0 162
michael@0 163 let filePermissions = gExtensionsJSON.permissions;
michael@0 164 if (!OS.Constants.Win) {
michael@0 165 gExtensionsJSON.permissions = 0;
michael@0 166 }
michael@0 167 startupManager(false);
michael@0 168
michael@0 169 check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
michael@0 170 check_startup_changes(AddonManager.STARTUP_CHANGE_UNINSTALLED, []);
michael@0 171
michael@0 172 [a1, a2, a3, a4, a5, a6] =
michael@0 173 yield promiseAddonsByIDs(["addon1@tests.mozilla.org",
michael@0 174 "addon2@tests.mozilla.org",
michael@0 175 "addon3@tests.mozilla.org",
michael@0 176 "addon4@tests.mozilla.org",
michael@0 177 "addon5@tests.mozilla.org",
michael@0 178 "addon6@tests.mozilla.org"]);
michael@0 179
michael@0 180 do_check_neq(a1, null);
michael@0 181 do_check_true(a1.isActive);
michael@0 182 do_check_false(a1.userDisabled);
michael@0 183 do_check_false(a1.appDisabled);
michael@0 184 do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
michael@0 185 do_check_true(isExtensionInAddonsList(profileDir, a1.id));
michael@0 186
michael@0 187 do_check_neq(a2, null);
michael@0 188 do_check_true(a2.isActive);
michael@0 189 do_check_false(a2.userDisabled);
michael@0 190 do_check_false(a2.appDisabled);
michael@0 191 do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
michael@0 192 do_check_true(isExtensionInAddonsList(profileDir, a2.id));
michael@0 193
michael@0 194 do_check_neq(a3, null);
michael@0 195 do_check_false(a3.isActive);
michael@0 196 do_check_true(a3.userDisabled);
michael@0 197 do_check_false(a3.appDisabled);
michael@0 198 do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
michael@0 199 do_check_false(isExtensionInAddonsList(profileDir, a3.id));
michael@0 200
michael@0 201 do_check_eq(a4, null);
michael@0 202
michael@0 203 do_check_neq(a5, null);
michael@0 204 do_check_eq(a5.version, "2.0");
michael@0 205 do_check_true(a5.isActive);
michael@0 206 do_check_false(a5.userDisabled);
michael@0 207 do_check_false(a5.appDisabled);
michael@0 208 do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
michael@0 209 do_check_true(isExtensionInAddonsList(profileDir, a5.id));
michael@0 210
michael@0 211 do_check_neq(a6, null);
michael@0 212 do_check_true(a6.isActive);
michael@0 213 do_check_false(a6.userDisabled);
michael@0 214 do_check_false(a6.appDisabled);
michael@0 215 do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
michael@0 216 do_check_true(isExtensionInAddonsList(profileDir, a6.id));
michael@0 217
michael@0 218 // After allowing access to the original DB things should still be
michael@0 219 // back how they were before the lock
michael@0 220 shutdownManager();
michael@0 221 yield file.close();
michael@0 222 gExtensionsJSON.permissions = filePermissions;
michael@0 223 startupManager();
michael@0 224
michael@0 225 // On Unix, we can save the DB even when the original file wasn't
michael@0 226 // readable, so our changes were saved. On Windows,
michael@0 227 // these things happened when we had no access to the database so
michael@0 228 // they are seen as external changes when we get the database back
michael@0 229 if (gXPISaveError) {
michael@0 230 do_print("Previous XPI save failed");
michael@0 231 check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED,
michael@0 232 ["addon6@tests.mozilla.org"]);
michael@0 233 check_startup_changes(AddonManager.STARTUP_CHANGE_UNINSTALLED,
michael@0 234 ["addon4@tests.mozilla.org"]);
michael@0 235 }
michael@0 236 else {
michael@0 237 do_print("Previous XPI save succeeded");
michael@0 238 check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []);
michael@0 239 check_startup_changes(AddonManager.STARTUP_CHANGE_UNINSTALLED, []);
michael@0 240 }
michael@0 241
michael@0 242 [a1, a2, a3, a4, a5, a6] =
michael@0 243 yield promiseAddonsByIDs(["addon1@tests.mozilla.org",
michael@0 244 "addon2@tests.mozilla.org",
michael@0 245 "addon3@tests.mozilla.org",
michael@0 246 "addon4@tests.mozilla.org",
michael@0 247 "addon5@tests.mozilla.org",
michael@0 248 "addon6@tests.mozilla.org"]);
michael@0 249
michael@0 250 do_check_neq(a1, null);
michael@0 251 do_check_true(a1.isActive);
michael@0 252 do_check_false(a1.userDisabled);
michael@0 253 do_check_false(a1.appDisabled);
michael@0 254 do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE);
michael@0 255 do_check_true(isExtensionInAddonsList(profileDir, a1.id));
michael@0 256
michael@0 257 do_check_neq(a2, null);
michael@0 258 do_check_true(a2.isActive);
michael@0 259 do_check_false(a2.userDisabled);
michael@0 260 do_check_false(a2.appDisabled);
michael@0 261 do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE);
michael@0 262 do_check_true(isExtensionInAddonsList(profileDir, a2.id));
michael@0 263
michael@0 264 do_check_neq(a3, null);
michael@0 265 do_check_false(a3.isActive);
michael@0 266 do_check_true(a3.userDisabled);
michael@0 267 do_check_false(a3.appDisabled);
michael@0 268 do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE);
michael@0 269 do_check_false(isExtensionInAddonsList(profileDir, a3.id));
michael@0 270
michael@0 271 do_check_eq(a4, null);
michael@0 272
michael@0 273 do_check_neq(a5, null);
michael@0 274 do_check_eq(a5.version, "2.0");
michael@0 275 do_check_true(a5.isActive);
michael@0 276 do_check_false(a5.userDisabled);
michael@0 277 do_check_false(a5.appDisabled);
michael@0 278 do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE);
michael@0 279 do_check_true(isExtensionInAddonsList(profileDir, a5.id));
michael@0 280
michael@0 281 do_check_neq(a6, null);
michael@0 282 do_check_true(a6.isActive);
michael@0 283 do_check_false(a6.userDisabled);
michael@0 284 do_check_false(a6.appDisabled);
michael@0 285 do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE);
michael@0 286 do_check_true(isExtensionInAddonsList(profileDir, a6.id));
michael@0 287 });
michael@0 288
michael@0 289 function run_test() {
michael@0 290 run_next_test();
michael@0 291 }
michael@0 292

mercurial