toolkit/mozapps/extensions/test/xpcshell/test_migrate_max_version.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_migrate_max_version.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,103 @@
     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 don't migrate data from SQLITE if
     1.9 +// the "extensions.databaseSchema" preference shows we've
    1.10 +// already upgraded to JSON
    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 +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
    1.29 +const profileDir = gProfD.clone();
    1.30 +profileDir.append("extensions");
    1.31 +
    1.32 +function run_test() {
    1.33 +  writeInstallRDFForExtension(addon1, profileDir);
    1.34 +
    1.35 +  // Write out a minimal database
    1.36 +  let dbfile = gProfD.clone();
    1.37 +  dbfile.append("extensions.sqlite");
    1.38 +  let db = AM_Cc["@mozilla.org/storage/service;1"].
    1.39 +           getService(AM_Ci.mozIStorageService).
    1.40 +           openDatabase(dbfile);
    1.41 +  db.createTable("addon", "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
    1.42 +                          "id TEXT, location TEXT, version TEXT, active INTEGER, " +
    1.43 +                          "userDisabled INTEGER, installDate INTEGER");
    1.44 +  db.createTable("targetApplication", "addon_internal_id INTEGER, " +
    1.45 +                                      "id TEXT, minVersion TEXT, maxVersion TEXT");
    1.46 +  let stmt = db.createStatement("INSERT INTO addon VALUES (NULL, :id, :location, " +
    1.47 +                                ":version, :active, :userDisabled, :installDate)");
    1.48 +
    1.49 +  let internal_ids = {};
    1.50 +
    1.51 +  let a = ["addon1@tests.mozilla.org", "app-profile", "1.0", "0", "1", "0"];
    1.52 +  stmt.params.id = a[0];
    1.53 +  stmt.params.location = a[1];
    1.54 +  stmt.params.version = a[2];
    1.55 +  stmt.params.active = a[3];
    1.56 +  stmt.params.userDisabled = a[4];
    1.57 +  stmt.params.installDate = a[5];
    1.58 +  stmt.execute();
    1.59 +  internal_ids[a[0]] = db.lastInsertRowID;
    1.60 +  stmt.finalize();
    1.61 +
    1.62 +  db.schemaVersion = 14;
    1.63 +  Services.prefs.setIntPref("extensions.databaseSchema", 14);
    1.64 +  db.close();
    1.65 +
    1.66 +  startupManager();
    1.67 +  run_next_test();
    1.68 +}
    1.69 +
    1.70 +add_test(function before_rebuild() {
    1.71 +  AddonManager.getAddonByID("addon1@tests.mozilla.org",
    1.72 +                            function check_before_rebuild (a1) {
    1.73 +    // First check that it migrated OK once
    1.74 +    // addon1 was disabled in the database
    1.75 +    do_check_neq(a1, null);
    1.76 +    do_check_true(a1.userDisabled);
    1.77 +    do_check_false(a1.appDisabled);
    1.78 +    do_check_false(a1.isActive);
    1.79 +    do_check_false(a1.strictCompatibility);
    1.80 +    do_check_false(a1.foreignInstall);
    1.81 +
    1.82 +    run_next_test();
    1.83 +  });
    1.84 +});
    1.85 +
    1.86 +// now shut down, remove the JSON database, 
    1.87 +// start up again, and make sure the data didn't migrate this time
    1.88 +add_test(function rebuild_again() {
    1.89 +  shutdownManager();
    1.90 +  gExtensionsJSON.remove(true);
    1.91 +  startupManager();
    1.92 +
    1.93 +  AddonManager.getAddonByID("addon1@tests.mozilla.org",
    1.94 +                            function check_after_rebuild(a1) {
    1.95 +    // addon1 was rebuilt from extensions directory,
    1.96 +    // so it appears enabled as a foreign install
    1.97 +    do_check_neq(a1, null);
    1.98 +    do_check_false(a1.userDisabled);
    1.99 +    do_check_false(a1.appDisabled);
   1.100 +    do_check_true(a1.isActive);
   1.101 +    do_check_false(a1.strictCompatibility);
   1.102 +    do_check_true(a1.foreignInstall);
   1.103 +
   1.104 +    run_next_test();
   1.105 +  });
   1.106 +});

mercurial