Wed, 31 Dec 2014 06:09:35 +0100
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 SQLITE databases |
michael@0 | 6 | // Note that since the database doesn't contain the foreignInstall field we |
michael@0 | 7 | // should just assume that no add-ons in the user profile were foreignInstalls |
michael@0 | 8 | |
michael@0 | 9 | // Enable loading extensions from the user and system scopes |
michael@0 | 10 | Services.prefs.setIntPref("extensions.enabledScopes", |
michael@0 | 11 | AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER + |
michael@0 | 12 | AddonManager.SCOPE_SYSTEM); |
michael@0 | 13 | |
michael@0 | 14 | var addon1 = { |
michael@0 | 15 | id: "addon1@tests.mozilla.org", |
michael@0 | 16 | version: "1.0", |
michael@0 | 17 | name: "Test 1", |
michael@0 | 18 | targetApplications: [{ |
michael@0 | 19 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 20 | minVersion: "1", |
michael@0 | 21 | maxVersion: "1" |
michael@0 | 22 | }] |
michael@0 | 23 | }; |
michael@0 | 24 | |
michael@0 | 25 | var addon2 = { |
michael@0 | 26 | id: "addon2@tests.mozilla.org", |
michael@0 | 27 | version: "2.0", |
michael@0 | 28 | name: "Test 2", |
michael@0 | 29 | targetApplications: [{ |
michael@0 | 30 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 31 | minVersion: "1", |
michael@0 | 32 | maxVersion: "1" |
michael@0 | 33 | }] |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | var addon3 = { |
michael@0 | 37 | id: "addon3@tests.mozilla.org", |
michael@0 | 38 | version: "2.0", |
michael@0 | 39 | name: "Test 3", |
michael@0 | 40 | targetApplications: [{ |
michael@0 | 41 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 42 | minVersion: "1", |
michael@0 | 43 | maxVersion: "1" |
michael@0 | 44 | }] |
michael@0 | 45 | }; |
michael@0 | 46 | |
michael@0 | 47 | var addon4 = { |
michael@0 | 48 | id: "addon4@tests.mozilla.org", |
michael@0 | 49 | version: "2.0", |
michael@0 | 50 | name: "Test 4", |
michael@0 | 51 | strictCompatibility: true, |
michael@0 | 52 | targetApplications: [{ |
michael@0 | 53 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 54 | minVersion: "1", |
michael@0 | 55 | maxVersion: "1" |
michael@0 | 56 | }] |
michael@0 | 57 | }; |
michael@0 | 58 | |
michael@0 | 59 | var addon5 = { |
michael@0 | 60 | id: "addon5@tests.mozilla.org", |
michael@0 | 61 | version: "2.0", |
michael@0 | 62 | name: "Test 5", |
michael@0 | 63 | targetApplications: [{ |
michael@0 | 64 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 65 | minVersion: "0", |
michael@0 | 66 | maxVersion: "0" |
michael@0 | 67 | }] |
michael@0 | 68 | }; |
michael@0 | 69 | |
michael@0 | 70 | var addon6 = { |
michael@0 | 71 | id: "addon6@tests.mozilla.org", |
michael@0 | 72 | version: "2.0", |
michael@0 | 73 | name: "Test 6", |
michael@0 | 74 | targetApplications: [{ |
michael@0 | 75 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 76 | minVersion: "0", |
michael@0 | 77 | maxVersion: "0" |
michael@0 | 78 | }] |
michael@0 | 79 | }; |
michael@0 | 80 | |
michael@0 | 81 | var addon7 = { |
michael@0 | 82 | id: "addon7@tests.mozilla.org", |
michael@0 | 83 | version: "2.0", |
michael@0 | 84 | name: "Test 7", |
michael@0 | 85 | targetApplications: [{ |
michael@0 | 86 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 87 | minVersion: "1", |
michael@0 | 88 | maxVersion: "1" |
michael@0 | 89 | }] |
michael@0 | 90 | }; |
michael@0 | 91 | |
michael@0 | 92 | var addon8 = { |
michael@0 | 93 | id: "addon8@tests.mozilla.org", |
michael@0 | 94 | version: "2.0", |
michael@0 | 95 | name: "Test 8", |
michael@0 | 96 | targetApplications: [{ |
michael@0 | 97 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 98 | minVersion: "1", |
michael@0 | 99 | maxVersion: "1" |
michael@0 | 100 | }] |
michael@0 | 101 | }; |
michael@0 | 102 | |
michael@0 | 103 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 104 | const profileDir = gProfD.clone(); |
michael@0 | 105 | profileDir.append("extensions"); |
michael@0 | 106 | const globalDir = gProfD.clone(); |
michael@0 | 107 | globalDir.append("extensions2"); |
michael@0 | 108 | globalDir.append(gAppInfo.ID); |
michael@0 | 109 | registerDirectory("XRESysSExtPD", globalDir.parent); |
michael@0 | 110 | const userDir = gProfD.clone(); |
michael@0 | 111 | userDir.append("extensions3"); |
michael@0 | 112 | userDir.append(gAppInfo.ID); |
michael@0 | 113 | registerDirectory("XREUSysExt", userDir.parent); |
michael@0 | 114 | |
michael@0 | 115 | function run_test() { |
michael@0 | 116 | do_test_pending(); |
michael@0 | 117 | |
michael@0 | 118 | writeInstallRDFForExtension(addon1, profileDir); |
michael@0 | 119 | writeInstallRDFForExtension(addon2, profileDir); |
michael@0 | 120 | writeInstallRDFForExtension(addon3, profileDir); |
michael@0 | 121 | writeInstallRDFForExtension(addon4, profileDir); |
michael@0 | 122 | writeInstallRDFForExtension(addon5, profileDir); |
michael@0 | 123 | writeInstallRDFForExtension(addon6, profileDir); |
michael@0 | 124 | writeInstallRDFForExtension(addon7, globalDir); |
michael@0 | 125 | writeInstallRDFForExtension(addon8, userDir); |
michael@0 | 126 | |
michael@0 | 127 | // Write out a minimal database |
michael@0 | 128 | let dbfile = gProfD.clone(); |
michael@0 | 129 | dbfile.append("extensions.sqlite"); |
michael@0 | 130 | let db = AM_Cc["@mozilla.org/storage/service;1"]. |
michael@0 | 131 | getService(AM_Ci.mozIStorageService). |
michael@0 | 132 | openDatabase(dbfile); |
michael@0 | 133 | db.createTable("addon", "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " + |
michael@0 | 134 | "id TEXT, location TEXT, version TEXT, active INTEGER, " + |
michael@0 | 135 | "userDisabled INTEGER, installDate INTEGER"); |
michael@0 | 136 | db.createTable("targetApplication", "addon_internal_id INTEGER, " + |
michael@0 | 137 | "id TEXT, minVersion TEXT, maxVersion TEXT"); |
michael@0 | 138 | let stmt = db.createStatement("INSERT INTO addon VALUES (NULL, :id, :location, " + |
michael@0 | 139 | ":version, :active, :userDisabled, :installDate)"); |
michael@0 | 140 | |
michael@0 | 141 | let internal_ids = {}; |
michael@0 | 142 | |
michael@0 | 143 | [["addon1@tests.mozilla.org", "app-profile", "1.0", "1", "0", "0"], |
michael@0 | 144 | ["addon2@tests.mozilla.org", "app-profile", "2.0", "0", "1", "0"], |
michael@0 | 145 | ["addon3@tests.mozilla.org", "app-profile", "2.0", "1", "1", "0"], |
michael@0 | 146 | ["addon4@tests.mozilla.org", "app-profile", "2.0", "0", "0", "0"], |
michael@0 | 147 | ["addon5@tests.mozilla.org", "app-profile", "2.0", "1", "0", "0"], |
michael@0 | 148 | ["addon6@tests.mozilla.org", "app-profile", "1.0", "0", "1", "0"], |
michael@0 | 149 | ["addon7@tests.mozilla.org", "app-system-share", "1.0", "1", "0", "0"], |
michael@0 | 150 | ["addon8@tests.mozilla.org", "app-system-user", "1.0", "1", "0", "0"]].forEach(function(a) { |
michael@0 | 151 | stmt.params.id = a[0]; |
michael@0 | 152 | stmt.params.location = a[1]; |
michael@0 | 153 | stmt.params.version = a[2]; |
michael@0 | 154 | stmt.params.active = a[3]; |
michael@0 | 155 | stmt.params.userDisabled = a[4]; |
michael@0 | 156 | stmt.params.installDate = a[5]; |
michael@0 | 157 | stmt.execute(); |
michael@0 | 158 | internal_ids[a[0]] = db.lastInsertRowID; |
michael@0 | 159 | }); |
michael@0 | 160 | stmt.finalize(); |
michael@0 | 161 | |
michael@0 | 162 | // Add updated target application into for addon5 |
michael@0 | 163 | stmt = db.createStatement("INSERT INTO targetApplication VALUES " + |
michael@0 | 164 | "(:internal_id, :id, :minVersion, :maxVersion)"); |
michael@0 | 165 | stmt.params.internal_id = internal_ids["addon5@tests.mozilla.org"]; |
michael@0 | 166 | stmt.params.id = "xpcshell@tests.mozilla.org"; |
michael@0 | 167 | stmt.params.minVersion = "0"; |
michael@0 | 168 | stmt.params.maxVersion = "1"; |
michael@0 | 169 | stmt.execute(); |
michael@0 | 170 | |
michael@0 | 171 | // Add updated target application into for addon6 |
michael@0 | 172 | stmt.params.internal_id = internal_ids["addon6@tests.mozilla.org"]; |
michael@0 | 173 | stmt.params.id = "xpcshell@tests.mozilla.org"; |
michael@0 | 174 | stmt.params.minVersion = "0"; |
michael@0 | 175 | stmt.params.maxVersion = "1"; |
michael@0 | 176 | stmt.execute(); |
michael@0 | 177 | stmt.finalize(); |
michael@0 | 178 | |
michael@0 | 179 | db.schemaVersion = 10000; |
michael@0 | 180 | Services.prefs.setIntPref("extensions.databaseSchema", 14); |
michael@0 | 181 | db.close(); |
michael@0 | 182 | |
michael@0 | 183 | startupManager(); |
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 | function([a1, a2, a3, a4, a5, a6, a7, a8]) { |
michael@0 | 199 | // addon1 was enabled in the database |
michael@0 | 200 | do_check_neq(a1, null); |
michael@0 | 201 | do_check_false(a1.userDisabled); |
michael@0 | 202 | do_check_false(a1.appDisabled); |
michael@0 | 203 | do_check_true(a1.isActive); |
michael@0 | 204 | do_check_false(a1.strictCompatibility); |
michael@0 | 205 | do_check_false(a1.foreignInstall); |
michael@0 | 206 | // addon2 was disabled in the database |
michael@0 | 207 | do_check_neq(a2, null); |
michael@0 | 208 | do_check_true(a2.userDisabled); |
michael@0 | 209 | do_check_false(a2.appDisabled); |
michael@0 | 210 | do_check_false(a2.isActive); |
michael@0 | 211 | do_check_false(a2.strictCompatibility); |
michael@0 | 212 | do_check_false(a2.foreignInstall); |
michael@0 | 213 | // addon3 was pending-disable in the database |
michael@0 | 214 | do_check_neq(a3, null); |
michael@0 | 215 | do_check_true(a3.userDisabled); |
michael@0 | 216 | do_check_false(a3.appDisabled); |
michael@0 | 217 | do_check_false(a3.isActive); |
michael@0 | 218 | do_check_false(a3.strictCompatibility); |
michael@0 | 219 | do_check_false(a3.foreignInstall); |
michael@0 | 220 | // addon4 was pending-enable in the database |
michael@0 | 221 | do_check_neq(a4, null); |
michael@0 | 222 | do_check_false(a4.userDisabled); |
michael@0 | 223 | do_check_false(a4.appDisabled); |
michael@0 | 224 | do_check_true(a4.isActive); |
michael@0 | 225 | do_check_true(a4.strictCompatibility); |
michael@0 | 226 | do_check_false(a4.foreignInstall); |
michael@0 | 227 | // addon5 was enabled in the database but needed a compatibility update |
michael@0 | 228 | do_check_neq(a5, null); |
michael@0 | 229 | do_check_false(a5.userDisabled); |
michael@0 | 230 | do_check_false(a5.appDisabled); |
michael@0 | 231 | do_check_true(a5.isActive); |
michael@0 | 232 | do_check_false(a5.strictCompatibility); |
michael@0 | 233 | do_check_false(a5.foreignInstall); |
michael@0 | 234 | // addon6 was disabled and compatible but a new version has been installed |
michael@0 | 235 | // since, it should still be disabled but should be incompatible |
michael@0 | 236 | do_check_neq(a6, null); |
michael@0 | 237 | do_check_true(a6.userDisabled); |
michael@0 | 238 | do_check_true(a6.appDisabled); |
michael@0 | 239 | do_check_false(a6.isActive); |
michael@0 | 240 | do_check_false(a6.strictCompatibility); |
michael@0 | 241 | do_check_false(a6.foreignInstall); |
michael@0 | 242 | // addon7 is in the global install location so should be a foreignInstall |
michael@0 | 243 | do_check_neq(a7, null); |
michael@0 | 244 | do_check_false(a7.userDisabled); |
michael@0 | 245 | do_check_false(a7.appDisabled); |
michael@0 | 246 | do_check_true(a7.isActive); |
michael@0 | 247 | do_check_false(a7.strictCompatibility); |
michael@0 | 248 | do_check_true(a7.foreignInstall); |
michael@0 | 249 | // addon8 is in the user install location so should be a foreignInstall |
michael@0 | 250 | do_check_neq(a8, null); |
michael@0 | 251 | do_check_false(a8.userDisabled); |
michael@0 | 252 | do_check_false(a8.appDisabled); |
michael@0 | 253 | do_check_true(a8.isActive); |
michael@0 | 254 | do_check_false(a8.strictCompatibility); |
michael@0 | 255 | do_check_true(a8.foreignInstall); |
michael@0 | 256 | |
michael@0 | 257 | do_execute_soon(do_test_finished); |
michael@0 | 258 | }); |
michael@0 | 259 | } |