toolkit/mozapps/extensions/test/xpcshell/test_migrate4.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 migrate data from a previous version of the JSON database
michael@0 6
michael@0 7 // The test extension uses an insecure update url.
michael@0 8 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
michael@0 9
michael@0 10 Components.utils.import("resource://testing-common/httpd.js");
michael@0 11 var testserver = new HttpServer();
michael@0 12 testserver.start(-1);
michael@0 13 gPort = testserver.identity.primaryPort;
michael@0 14 mapFile("/data/test_migrate4.rdf", testserver);
michael@0 15 testserver.registerDirectory("/addons/", do_get_file("addons"));
michael@0 16
michael@0 17 var addon1 = {
michael@0 18 id: "addon1@tests.mozilla.org",
michael@0 19 version: "1.0",
michael@0 20 name: "Test 1",
michael@0 21 targetApplications: [{
michael@0 22 id: "xpcshell@tests.mozilla.org",
michael@0 23 minVersion: "1",
michael@0 24 maxVersion: "2"
michael@0 25 }]
michael@0 26 };
michael@0 27
michael@0 28 var addon2 = {
michael@0 29 id: "addon2@tests.mozilla.org",
michael@0 30 version: "2.0",
michael@0 31 name: "Test 2",
michael@0 32 targetApplications: [{
michael@0 33 id: "xpcshell@tests.mozilla.org",
michael@0 34 minVersion: "1",
michael@0 35 maxVersion: "2"
michael@0 36 }]
michael@0 37 };
michael@0 38
michael@0 39 var addon3 = {
michael@0 40 id: "addon3@tests.mozilla.org",
michael@0 41 version: "2.0",
michael@0 42 name: "Test 3",
michael@0 43 targetApplications: [{
michael@0 44 id: "xpcshell@tests.mozilla.org",
michael@0 45 minVersion: "1",
michael@0 46 maxVersion: "2"
michael@0 47 }]
michael@0 48 };
michael@0 49
michael@0 50 var addon4 = {
michael@0 51 id: "addon4@tests.mozilla.org",
michael@0 52 version: "2.0",
michael@0 53 name: "Test 4",
michael@0 54 strictCompatibility: true,
michael@0 55 targetApplications: [{
michael@0 56 id: "xpcshell@tests.mozilla.org",
michael@0 57 minVersion: "1",
michael@0 58 maxVersion: "2"
michael@0 59 }]
michael@0 60 };
michael@0 61
michael@0 62 var addon5 = {
michael@0 63 id: "addon5@tests.mozilla.org",
michael@0 64 version: "2.0",
michael@0 65 name: "Test 5",
michael@0 66 updateURL: "http://localhost:" + gPort + "/data/test_migrate4.rdf",
michael@0 67 targetApplications: [{
michael@0 68 id: "xpcshell@tests.mozilla.org",
michael@0 69 minVersion: "0",
michael@0 70 maxVersion: "1"
michael@0 71 }]
michael@0 72 };
michael@0 73
michael@0 74 var addon6 = {
michael@0 75 id: "addon6@tests.mozilla.org",
michael@0 76 version: "1.0",
michael@0 77 name: "Test 6",
michael@0 78 updateURL: "http://localhost:" + gPort + "/data/test_migrate4.rdf",
michael@0 79 targetApplications: [{
michael@0 80 id: "xpcshell@tests.mozilla.org",
michael@0 81 minVersion: "0",
michael@0 82 maxVersion: "1"
michael@0 83 }]
michael@0 84 };
michael@0 85
michael@0 86 var defaultTheme = {
michael@0 87 id: "default@tests.mozilla.org",
michael@0 88 version: "1.0",
michael@0 89 name: "Default",
michael@0 90 internalName: "classic/1.0",
michael@0 91 targetApplications: [{
michael@0 92 id: "xpcshell@tests.mozilla.org",
michael@0 93 minVersion: "1",
michael@0 94 maxVersion: "2"
michael@0 95 }]
michael@0 96 };
michael@0 97
michael@0 98 const profileDir = gProfD.clone();
michael@0 99 profileDir.append("extensions");
michael@0 100
michael@0 101 let oldSyncGUIDs = {};
michael@0 102
michael@0 103 function prepare_profile() {
michael@0 104 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
michael@0 105
michael@0 106 writeInstallRDFForExtension(addon1, profileDir);
michael@0 107 writeInstallRDFForExtension(addon2, profileDir);
michael@0 108 writeInstallRDFForExtension(addon3, profileDir);
michael@0 109 writeInstallRDFForExtension(addon4, profileDir);
michael@0 110 writeInstallRDFForExtension(addon5, profileDir);
michael@0 111 writeInstallRDFForExtension(addon6, profileDir);
michael@0 112 writeInstallRDFForExtension(defaultTheme, profileDir);
michael@0 113
michael@0 114 startupManager();
michael@0 115 installAllFiles([do_get_addon("test_migrate8"), do_get_addon("test_migrate9")],
michael@0 116 function() {
michael@0 117 restartManager();
michael@0 118
michael@0 119 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
michael@0 120 "addon2@tests.mozilla.org",
michael@0 121 "addon3@tests.mozilla.org",
michael@0 122 "addon4@tests.mozilla.org",
michael@0 123 "addon5@tests.mozilla.org",
michael@0 124 "addon6@tests.mozilla.org",
michael@0 125 "addon9@tests.mozilla.org"],
michael@0 126 function([a1, a2, a3, a4, a5, a6, a9]) {
michael@0 127 a1.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DEFAULT;
michael@0 128 a2.userDisabled = true;
michael@0 129 a2.applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE;
michael@0 130 a3.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE;
michael@0 131 a4.userDisabled = true;
michael@0 132 a6.userDisabled = true;
michael@0 133 a9.userDisabled = false;
michael@0 134
michael@0 135 for each (let addon in [a1, a2, a3, a4, a5, a6]) {
michael@0 136 oldSyncGUIDs[addon.id] = addon.syncGUID;
michael@0 137 }
michael@0 138
michael@0 139 a6.findUpdates({
michael@0 140 onUpdateAvailable: function(aAddon, aInstall6) {
michael@0 141 AddonManager.getInstallForURL("http://localhost:" + gPort + "/addons/test_migrate4_7.xpi", function(aInstall7) {
michael@0 142 completeAllInstalls([aInstall6, aInstall7], function() {
michael@0 143 restartManager();
michael@0 144
michael@0 145 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
michael@0 146 "addon2@tests.mozilla.org",
michael@0 147 "addon3@tests.mozilla.org",
michael@0 148 "addon4@tests.mozilla.org",
michael@0 149 "addon5@tests.mozilla.org",
michael@0 150 "addon6@tests.mozilla.org"],
michael@0 151 function([a1, a2, a3, a4, a5, a6]) {
michael@0 152 a3.userDisabled = true;
michael@0 153 a4.userDisabled = false;
michael@0 154
michael@0 155 a5.findUpdates({
michael@0 156 onUpdateFinished: function() {
michael@0 157 do_execute_soon(perform_migration);
michael@0 158 }
michael@0 159 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
michael@0 160 });
michael@0 161 });
michael@0 162 }, "application/x-xpinstall");
michael@0 163 }
michael@0 164 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
michael@0 165 });
michael@0 166 });
michael@0 167 }
michael@0 168
michael@0 169 function perform_migration() {
michael@0 170 shutdownManager();
michael@0 171
michael@0 172 // Turn on disabling for all scopes
michael@0 173 Services.prefs.setIntPref("extensions.autoDisableScopes", 15);
michael@0 174
michael@0 175 changeXPIDBVersion(1);
michael@0 176 Services.prefs.setIntPref("extensions.databaseSchema", 1);
michael@0 177
michael@0 178 gAppInfo.version = "2"
michael@0 179 startupManager(true);
michael@0 180 test_results();
michael@0 181 }
michael@0 182
michael@0 183 function test_results() {
michael@0 184 check_startup_changes("installed", []);
michael@0 185 check_startup_changes("updated", []);
michael@0 186 check_startup_changes("uninstalled", []);
michael@0 187 check_startup_changes("disabled", []);
michael@0 188 check_startup_changes("enabled", []);
michael@0 189
michael@0 190 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
michael@0 191 "addon2@tests.mozilla.org",
michael@0 192 "addon3@tests.mozilla.org",
michael@0 193 "addon4@tests.mozilla.org",
michael@0 194 "addon5@tests.mozilla.org",
michael@0 195 "addon6@tests.mozilla.org",
michael@0 196 "addon7@tests.mozilla.org",
michael@0 197 "addon8@tests.mozilla.org",
michael@0 198 "addon9@tests.mozilla.org"],
michael@0 199 function([a1, a2, a3, a4, a5, a6, a7, a8, a9]) {
michael@0 200 // addon1 was enabled
michael@0 201 do_check_neq(a1, null);
michael@0 202 do_check_eq(a1.syncGUID, oldSyncGUIDs[a1.id]);
michael@0 203 do_check_false(a1.userDisabled);
michael@0 204 do_check_false(a1.appDisabled);
michael@0 205 do_check_true(a1.isActive);
michael@0 206 do_check_eq(a1.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DEFAULT);
michael@0 207 do_check_true(a1.foreignInstall);
michael@0 208 do_check_false(a1.hasBinaryComponents);
michael@0 209 do_check_false(a1.strictCompatibility);
michael@0 210
michael@0 211 // addon2 was disabled
michael@0 212 do_check_neq(a2, null);
michael@0 213 do_check_eq(a2.syncGUID, oldSyncGUIDs[a2.id]);
michael@0 214 do_check_true(a2.userDisabled);
michael@0 215 do_check_false(a2.appDisabled);
michael@0 216 do_check_false(a2.isActive);
michael@0 217 do_check_eq(a2.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DISABLE);
michael@0 218 do_check_true(a2.foreignInstall);
michael@0 219 do_check_false(a2.hasBinaryComponents);
michael@0 220 do_check_false(a2.strictCompatibility);
michael@0 221
michael@0 222 // addon3 was pending-disable in the database
michael@0 223 do_check_neq(a3, null);
michael@0 224 do_check_eq(a3.syncGUID, oldSyncGUIDs[a3.id]);
michael@0 225 do_check_true(a3.userDisabled);
michael@0 226 do_check_false(a3.appDisabled);
michael@0 227 do_check_false(a3.isActive);
michael@0 228 do_check_eq(a3.applyBackgroundUpdates, AddonManager.AUTOUPDATE_ENABLE);
michael@0 229 do_check_true(a3.foreignInstall);
michael@0 230 do_check_false(a3.hasBinaryComponents);
michael@0 231 do_check_false(a3.strictCompatibility);
michael@0 232
michael@0 233 // addon4 was pending-enable in the database
michael@0 234 do_check_neq(a4, null);
michael@0 235 do_check_eq(a4.syncGUID, oldSyncGUIDs[a4.id]);
michael@0 236 do_check_false(a4.userDisabled);
michael@0 237 do_check_false(a4.appDisabled);
michael@0 238 do_check_true(a4.isActive);
michael@0 239 do_check_eq(a4.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DEFAULT);
michael@0 240 do_check_true(a4.foreignInstall);
michael@0 241 do_check_false(a4.hasBinaryComponents);
michael@0 242 do_check_true(a4.strictCompatibility);
michael@0 243
michael@0 244 // addon5 was enabled in the database but needed a compatibility update
michael@0 245 do_check_neq(a5, null);
michael@0 246 do_check_false(a5.userDisabled);
michael@0 247 do_check_false(a5.appDisabled);
michael@0 248 do_check_true(a5.isActive);
michael@0 249 do_check_eq(a4.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DEFAULT);
michael@0 250 do_check_true(a5.foreignInstall);
michael@0 251 do_check_false(a5.hasBinaryComponents);
michael@0 252 do_check_false(a5.strictCompatibility);
michael@0 253
michael@0 254 // addon6 was disabled and compatible but a new version has been installed
michael@0 255 do_check_neq(a6, null);
michael@0 256 do_check_eq(a6.syncGUID, oldSyncGUIDs[a6.id]);
michael@0 257 do_check_eq(a6.version, "2.0");
michael@0 258 do_check_true(a6.userDisabled);
michael@0 259 do_check_false(a6.appDisabled);
michael@0 260 do_check_false(a6.isActive);
michael@0 261 do_check_eq(a6.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DEFAULT);
michael@0 262 do_check_true(a6.foreignInstall);
michael@0 263 do_check_eq(a6.sourceURI.spec, "http://localhost:" + gPort + "/addons/test_migrate4_6.xpi");
michael@0 264 do_check_eq(a6.releaseNotesURI.spec, "http://example.com/updateInfo.xhtml");
michael@0 265 do_check_false(a6.hasBinaryComponents);
michael@0 266 do_check_false(a6.strictCompatibility);
michael@0 267
michael@0 268 // addon7 was installed manually
michael@0 269 do_check_neq(a7, null);
michael@0 270 do_check_eq(a7.version, "1.0");
michael@0 271 do_check_false(a7.userDisabled);
michael@0 272 do_check_false(a7.appDisabled);
michael@0 273 do_check_true(a7.isActive);
michael@0 274 do_check_eq(a7.applyBackgroundUpdates, AddonManager.AUTOUPDATE_DEFAULT);
michael@0 275 do_check_false(a7.foreignInstall);
michael@0 276 do_check_eq(a7.sourceURI.spec, "http://localhost:" + gPort + "/addons/test_migrate4_7.xpi");
michael@0 277 do_check_eq(a7.releaseNotesURI, null);
michael@0 278 do_check_false(a7.hasBinaryComponents);
michael@0 279 do_check_false(a7.strictCompatibility);
michael@0 280
michael@0 281 // addon8 was enabled and has binary components
michael@0 282 do_check_neq(a8, null);
michael@0 283 do_check_false(a8.userDisabled);
michael@0 284 do_check_false(a8.appDisabled);
michael@0 285 do_check_true(a8.isActive);
michael@0 286 do_check_false(a8.foreignInstall);
michael@0 287 do_check_true(a8.hasBinaryComponents);
michael@0 288 do_check_false(a8.strictCompatibility);
michael@0 289
michael@0 290 // addon9 is the active theme
michael@0 291 do_check_neq(a9, null);
michael@0 292 do_check_false(a9.userDisabled);
michael@0 293 do_check_false(a9.appDisabled);
michael@0 294 do_check_true(a9.isActive);
michael@0 295 do_check_false(a9.foreignInstall);
michael@0 296 do_check_false(a9.hasBinaryComponents);
michael@0 297 do_check_true(a9.strictCompatibility);
michael@0 298
michael@0 299 testserver.stop(do_test_finished);
michael@0 300 });
michael@0 301 }
michael@0 302
michael@0 303 function run_test() {
michael@0 304 do_test_pending();
michael@0 305
michael@0 306 prepare_profile();
michael@0 307 }

mercurial