toolkit/mozapps/extensions/test/xpcshell/test_migrate5.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_migrate5.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,139 @@
     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 fail to migrate but still start up ok when there is a SQLITE database
     1.9 +// with no useful data in it.
    1.10 +
    1.11 +const PREF_GENERAL_SKINS_SELECTEDSKIN = "general.skins.selectedSkin";
    1.12 +
    1.13 +var addon1 = {
    1.14 +  id: "addon1@tests.mozilla.org",
    1.15 +  version: "1.0",
    1.16 +  name: "Test 1",
    1.17 +  targetApplications: [{
    1.18 +    id: "xpcshell@tests.mozilla.org",
    1.19 +    minVersion: "1",
    1.20 +    maxVersion: "1"
    1.21 +  }]
    1.22 +};
    1.23 +
    1.24 +var addon2 = {
    1.25 +  id: "addon2@tests.mozilla.org",
    1.26 +  version: "2.0",
    1.27 +  name: "Test 5",
    1.28 +  targetApplications: [{
    1.29 +    id: "xpcshell@tests.mozilla.org",
    1.30 +    minVersion: "0",
    1.31 +    maxVersion: "0"
    1.32 +  }]
    1.33 +};
    1.34 +
    1.35 +var defaultTheme = {
    1.36 +  id: "default@tests.mozilla.org",
    1.37 +  version: "2.0",
    1.38 +  name: "Default theme",
    1.39 +  internalName: "classic/1.0",
    1.40 +  targetApplications: [{
    1.41 +    id: "xpcshell@tests.mozilla.org",
    1.42 +    minVersion: "1",
    1.43 +    maxVersion: "1"
    1.44 +  }]
    1.45 +};
    1.46 +
    1.47 +var theme1 = {
    1.48 +  id: "theme1@tests.mozilla.org",
    1.49 +  version: "2.0",
    1.50 +  name: "Test theme",
    1.51 +  internalName: "theme1/1.0",
    1.52 +  targetApplications: [{
    1.53 +    id: "xpcshell@tests.mozilla.org",
    1.54 +    minVersion: "1",
    1.55 +    maxVersion: "1"
    1.56 +  }]
    1.57 +};
    1.58 +
    1.59 +const profileDir = gProfD.clone();
    1.60 +profileDir.append("extensions");
    1.61 +
    1.62 +function run_test() {
    1.63 +  do_test_pending();
    1.64 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    1.65 +
    1.66 +  writeInstallRDFForExtension(addon1, profileDir);
    1.67 +  writeInstallRDFForExtension(addon2, profileDir);
    1.68 +  writeInstallRDFForExtension(defaultTheme, profileDir);
    1.69 +  writeInstallRDFForExtension(theme1, profileDir);
    1.70 +
    1.71 +  Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0");
    1.72 +
    1.73 +  // Write out a broken database (no userDisabled field)
    1.74 +  let dbfile = gProfD.clone();
    1.75 +  dbfile.append("extensions.sqlite");
    1.76 +  let db = AM_Cc["@mozilla.org/storage/service;1"].
    1.77 +           getService(AM_Ci.mozIStorageService).
    1.78 +           openDatabase(dbfile);
    1.79 +  db.createTable("addon", "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
    1.80 +                          "id TEXT, location TEXT, version TEXT, active INTEGER, " +
    1.81 +                          "installDate INTEGER");
    1.82 +  db.createTable("targetApplication", "addon_internal_id INTEGER, " +
    1.83 +                                      "id TEXT, minVersion TEXT, maxVersion TEXT");
    1.84 +  let stmt = db.createStatement("INSERT INTO addon VALUES (NULL, :id, :location, " +
    1.85 +                                ":version, :active, :installDate)");
    1.86 +
    1.87 +  let internal_ids = {};
    1.88 +
    1.89 +  [["addon1@tests.mozilla.org", "app-profile", "1.0", "1", "0"],
    1.90 +   ["addon2@tests.mozilla.org", "app-profile", "2.0", "0", "0"],
    1.91 +   ["default@tests.mozilla.org", "app-profile", "2.0", "1", "0"],
    1.92 +   ["theme1@tests.mozilla.org", "app-profile", "2.0", "0", "0"]].forEach(function(a) {
    1.93 +    stmt.params.id = a[0];
    1.94 +    stmt.params.location = a[1];
    1.95 +    stmt.params.version = a[2];
    1.96 +    stmt.params.active = a[3];
    1.97 +    stmt.params.installDate = a[4];
    1.98 +    stmt.execute();
    1.99 +    internal_ids[a[0]] = db.lastInsertRowID;
   1.100 +  });
   1.101 +  stmt.finalize();
   1.102 +
   1.103 +  db.schemaVersion = 100;
   1.104 +  Services.prefs.setIntPref("extensions.databaseSchema", 100);
   1.105 +  db.close();
   1.106 +
   1.107 +  startupManager();
   1.108 +  check_startup_changes("installed", []);
   1.109 +  check_startup_changes("updated", []);
   1.110 +  check_startup_changes("uninstalled", []);
   1.111 +  check_startup_changes("disabled", []);
   1.112 +  check_startup_changes("enabled", []);
   1.113 +
   1.114 +  AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
   1.115 +                               "addon2@tests.mozilla.org",
   1.116 +                               "default@tests.mozilla.org",
   1.117 +                               "theme1@tests.mozilla.org"],
   1.118 +                               function([a1, a2, d, t1]) {
   1.119 +    do_check_neq(a1, null);
   1.120 +    do_check_false(a1.userDisabled);
   1.121 +    do_check_false(a1.appDisabled);
   1.122 +    do_check_true(a1.isActive);
   1.123 +
   1.124 +    do_check_neq(a2, null);
   1.125 +    do_check_false(a2.userDisabled);
   1.126 +    do_check_true(a2.appDisabled);
   1.127 +    do_check_false(a2.isActive);
   1.128 +
   1.129 +    // Should have enabled the selected theme
   1.130 +    do_check_neq(t1, null);
   1.131 +    do_check_false(t1.userDisabled);
   1.132 +    do_check_false(t1.appDisabled);
   1.133 +    do_check_true(t1.isActive);
   1.134 +
   1.135 +    do_check_neq(d, null);
   1.136 +    do_check_true(d.userDisabled);
   1.137 +    do_check_false(d.appDisabled);
   1.138 +    do_check_false(d.isActive);
   1.139 +
   1.140 +    do_execute_soon(do_test_finished);
   1.141 +  });
   1.142 +}

mercurial