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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_migrate2.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,259 @@
     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 +// Checks that we migrate data from SQLITE databases
     1.9 +// Note that since the database doesn't contain the foreignInstall field we
    1.10 +// should just assume that no add-ons  in the user profile were foreignInstalls
    1.11 +
    1.12 +// Enable loading extensions from the user and system scopes
    1.13 +Services.prefs.setIntPref("extensions.enabledScopes",
    1.14 +                          AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER +
    1.15 +                          AddonManager.SCOPE_SYSTEM);
    1.16 +
    1.17 +var addon1 = {
    1.18 +  id: "addon1@tests.mozilla.org",
    1.19 +  version: "1.0",
    1.20 +  name: "Test 1",
    1.21 +  targetApplications: [{
    1.22 +    id: "xpcshell@tests.mozilla.org",
    1.23 +    minVersion: "1",
    1.24 +    maxVersion: "1"
    1.25 +  }]
    1.26 +};
    1.27 +
    1.28 +var addon2 = {
    1.29 +  id: "addon2@tests.mozilla.org",
    1.30 +  version: "2.0",
    1.31 +  name: "Test 2",
    1.32 +  targetApplications: [{
    1.33 +    id: "xpcshell@tests.mozilla.org",
    1.34 +    minVersion: "1",
    1.35 +    maxVersion: "1"
    1.36 +  }]
    1.37 +};
    1.38 +
    1.39 +var addon3 = {
    1.40 +  id: "addon3@tests.mozilla.org",
    1.41 +  version: "2.0",
    1.42 +  name: "Test 3",
    1.43 +  targetApplications: [{
    1.44 +    id: "xpcshell@tests.mozilla.org",
    1.45 +    minVersion: "1",
    1.46 +    maxVersion: "1"
    1.47 +  }]
    1.48 +};
    1.49 +
    1.50 +var addon4 = {
    1.51 +  id: "addon4@tests.mozilla.org",
    1.52 +  version: "2.0",
    1.53 +  name: "Test 4",
    1.54 +  strictCompatibility: true,
    1.55 +  targetApplications: [{
    1.56 +    id: "xpcshell@tests.mozilla.org",
    1.57 +    minVersion: "1",
    1.58 +    maxVersion: "1"
    1.59 +  }]
    1.60 +};
    1.61 +
    1.62 +var addon5 = {
    1.63 +  id: "addon5@tests.mozilla.org",
    1.64 +  version: "2.0",
    1.65 +  name: "Test 5",
    1.66 +  targetApplications: [{
    1.67 +    id: "xpcshell@tests.mozilla.org",
    1.68 +    minVersion: "0",
    1.69 +    maxVersion: "0"
    1.70 +  }]
    1.71 +};
    1.72 +
    1.73 +var addon6 = {
    1.74 +  id: "addon6@tests.mozilla.org",
    1.75 +  version: "2.0",
    1.76 +  name: "Test 6",
    1.77 +  targetApplications: [{
    1.78 +    id: "xpcshell@tests.mozilla.org",
    1.79 +    minVersion: "0",
    1.80 +    maxVersion: "0"
    1.81 +  }]
    1.82 +};
    1.83 +
    1.84 +var addon7 = {
    1.85 +  id: "addon7@tests.mozilla.org",
    1.86 +  version: "2.0",
    1.87 +  name: "Test 7",
    1.88 +  targetApplications: [{
    1.89 +    id: "xpcshell@tests.mozilla.org",
    1.90 +    minVersion: "1",
    1.91 +    maxVersion: "1"
    1.92 +  }]
    1.93 +};
    1.94 +
    1.95 +var addon8 = {
    1.96 +  id: "addon8@tests.mozilla.org",
    1.97 +  version: "2.0",
    1.98 +  name: "Test 8",
    1.99 +  targetApplications: [{
   1.100 +    id: "xpcshell@tests.mozilla.org",
   1.101 +    minVersion: "1",
   1.102 +    maxVersion: "1"
   1.103 +  }]
   1.104 +};
   1.105 +
   1.106 +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
   1.107 +const profileDir = gProfD.clone();
   1.108 +profileDir.append("extensions");
   1.109 +const globalDir = gProfD.clone();
   1.110 +globalDir.append("extensions2");
   1.111 +globalDir.append(gAppInfo.ID);
   1.112 +registerDirectory("XRESysSExtPD", globalDir.parent);
   1.113 +const userDir = gProfD.clone();
   1.114 +userDir.append("extensions3");
   1.115 +userDir.append(gAppInfo.ID);
   1.116 +registerDirectory("XREUSysExt", userDir.parent);
   1.117 +
   1.118 +function run_test() {
   1.119 +  do_test_pending();
   1.120 +
   1.121 +  writeInstallRDFForExtension(addon1, profileDir);
   1.122 +  writeInstallRDFForExtension(addon2, profileDir);
   1.123 +  writeInstallRDFForExtension(addon3, profileDir);
   1.124 +  writeInstallRDFForExtension(addon4, profileDir);
   1.125 +  writeInstallRDFForExtension(addon5, profileDir);
   1.126 +  writeInstallRDFForExtension(addon6, profileDir);
   1.127 +  writeInstallRDFForExtension(addon7, globalDir);
   1.128 +  writeInstallRDFForExtension(addon8, userDir);
   1.129 +
   1.130 +  // Write out a minimal database
   1.131 +  let dbfile = gProfD.clone();
   1.132 +  dbfile.append("extensions.sqlite");
   1.133 +  let db = AM_Cc["@mozilla.org/storage/service;1"].
   1.134 +           getService(AM_Ci.mozIStorageService).
   1.135 +           openDatabase(dbfile);
   1.136 +  db.createTable("addon", "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
   1.137 +                          "id TEXT, location TEXT, version TEXT, active INTEGER, " +
   1.138 +                          "userDisabled INTEGER, installDate INTEGER");
   1.139 +  db.createTable("targetApplication", "addon_internal_id INTEGER, " +
   1.140 +                                      "id TEXT, minVersion TEXT, maxVersion TEXT");
   1.141 +  let stmt = db.createStatement("INSERT INTO addon VALUES (NULL, :id, :location, " +
   1.142 +                                ":version, :active, :userDisabled, :installDate)");
   1.143 +
   1.144 +  let internal_ids = {};
   1.145 +
   1.146 +  [["addon1@tests.mozilla.org", "app-profile", "1.0", "1", "0", "0"],
   1.147 +   ["addon2@tests.mozilla.org", "app-profile", "2.0", "0", "1", "0"],
   1.148 +   ["addon3@tests.mozilla.org", "app-profile", "2.0", "1", "1", "0"],
   1.149 +   ["addon4@tests.mozilla.org", "app-profile", "2.0", "0", "0", "0"],
   1.150 +   ["addon5@tests.mozilla.org", "app-profile", "2.0", "1", "0", "0"],
   1.151 +   ["addon6@tests.mozilla.org", "app-profile", "1.0", "0", "1", "0"],
   1.152 +   ["addon7@tests.mozilla.org", "app-system-share", "1.0", "1", "0", "0"],
   1.153 +   ["addon8@tests.mozilla.org", "app-system-user", "1.0", "1", "0", "0"]].forEach(function(a) {
   1.154 +    stmt.params.id = a[0];
   1.155 +    stmt.params.location = a[1];
   1.156 +    stmt.params.version = a[2];
   1.157 +    stmt.params.active = a[3];
   1.158 +    stmt.params.userDisabled = a[4];
   1.159 +    stmt.params.installDate = a[5];
   1.160 +    stmt.execute();
   1.161 +    internal_ids[a[0]] = db.lastInsertRowID;
   1.162 +  });
   1.163 +  stmt.finalize();
   1.164 +
   1.165 +  // Add updated target application into for addon5
   1.166 +  stmt = db.createStatement("INSERT INTO targetApplication VALUES " +
   1.167 +                            "(:internal_id, :id, :minVersion, :maxVersion)");
   1.168 +  stmt.params.internal_id = internal_ids["addon5@tests.mozilla.org"];
   1.169 +  stmt.params.id = "xpcshell@tests.mozilla.org";
   1.170 +  stmt.params.minVersion = "0";
   1.171 +  stmt.params.maxVersion = "1";
   1.172 +  stmt.execute();
   1.173 +
   1.174 +  // Add updated target application into for addon6
   1.175 +  stmt.params.internal_id = internal_ids["addon6@tests.mozilla.org"];
   1.176 +  stmt.params.id = "xpcshell@tests.mozilla.org";
   1.177 +  stmt.params.minVersion = "0";
   1.178 +  stmt.params.maxVersion = "1";
   1.179 +  stmt.execute();
   1.180 +  stmt.finalize();
   1.181 +
   1.182 +  db.schemaVersion = 10000;
   1.183 +  Services.prefs.setIntPref("extensions.databaseSchema", 14);
   1.184 +  db.close();
   1.185 +
   1.186 +  startupManager();
   1.187 +  check_startup_changes("installed", []);
   1.188 +  check_startup_changes("updated", []);
   1.189 +  check_startup_changes("uninstalled", []);
   1.190 +  check_startup_changes("disabled", []);
   1.191 +  check_startup_changes("enabled", []);
   1.192 +
   1.193 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   1.194 +                               "addon2@tests.mozilla.org",
   1.195 +                               "addon3@tests.mozilla.org",
   1.196 +                               "addon4@tests.mozilla.org",
   1.197 +                               "addon5@tests.mozilla.org",
   1.198 +                               "addon6@tests.mozilla.org",
   1.199 +                               "addon7@tests.mozilla.org",
   1.200 +                               "addon8@tests.mozilla.org"],
   1.201 +                               function([a1, a2, a3, a4, a5, a6, a7, a8]) {
   1.202 +    // addon1 was enabled in the database
   1.203 +    do_check_neq(a1, null);
   1.204 +    do_check_false(a1.userDisabled);
   1.205 +    do_check_false(a1.appDisabled);
   1.206 +    do_check_true(a1.isActive);
   1.207 +    do_check_false(a1.strictCompatibility);
   1.208 +    do_check_false(a1.foreignInstall);
   1.209 +    // addon2 was disabled in the database
   1.210 +    do_check_neq(a2, null);
   1.211 +    do_check_true(a2.userDisabled);
   1.212 +    do_check_false(a2.appDisabled);
   1.213 +    do_check_false(a2.isActive);
   1.214 +    do_check_false(a2.strictCompatibility);
   1.215 +    do_check_false(a2.foreignInstall);
   1.216 +    // addon3 was pending-disable in the database
   1.217 +    do_check_neq(a3, null);
   1.218 +    do_check_true(a3.userDisabled);
   1.219 +    do_check_false(a3.appDisabled);
   1.220 +    do_check_false(a3.isActive);
   1.221 +    do_check_false(a3.strictCompatibility);
   1.222 +    do_check_false(a3.foreignInstall);
   1.223 +    // addon4 was pending-enable in the database
   1.224 +    do_check_neq(a4, null);
   1.225 +    do_check_false(a4.userDisabled);
   1.226 +    do_check_false(a4.appDisabled);
   1.227 +    do_check_true(a4.isActive);
   1.228 +    do_check_true(a4.strictCompatibility);
   1.229 +    do_check_false(a4.foreignInstall);
   1.230 +    // addon5 was enabled in the database but needed a compatibility update
   1.231 +    do_check_neq(a5, null);
   1.232 +    do_check_false(a5.userDisabled);
   1.233 +    do_check_false(a5.appDisabled);
   1.234 +    do_check_true(a5.isActive);
   1.235 +    do_check_false(a5.strictCompatibility);
   1.236 +    do_check_false(a5.foreignInstall);
   1.237 +    // addon6 was disabled and compatible but a new version has been installed
   1.238 +    // since, it should still be disabled but should be incompatible
   1.239 +    do_check_neq(a6, null);
   1.240 +    do_check_true(a6.userDisabled);
   1.241 +    do_check_true(a6.appDisabled);
   1.242 +    do_check_false(a6.isActive);
   1.243 +    do_check_false(a6.strictCompatibility);
   1.244 +    do_check_false(a6.foreignInstall);
   1.245 +    // addon7 is in the global install location so should be a foreignInstall
   1.246 +    do_check_neq(a7, null);
   1.247 +    do_check_false(a7.userDisabled);
   1.248 +    do_check_false(a7.appDisabled);
   1.249 +    do_check_true(a7.isActive);
   1.250 +    do_check_false(a7.strictCompatibility);
   1.251 +    do_check_true(a7.foreignInstall);
   1.252 +    // addon8 is in the user install location so should be a foreignInstall
   1.253 +    do_check_neq(a8, null);
   1.254 +    do_check_false(a8.userDisabled);
   1.255 +    do_check_false(a8.appDisabled);
   1.256 +    do_check_true(a8.isActive);
   1.257 +    do_check_false(a8.strictCompatibility);
   1.258 +    do_check_true(a8.foreignInstall);
   1.259 +
   1.260 +    do_execute_soon(do_test_finished);
   1.261 +  });
   1.262 +}

mercurial