summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/webextensions/test/xpcshell/test_migrate_max_version.js
blob: 171ac411e39b049f995b1192f1f001494b881ac4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// Checks that we don't migrate data from SQLITE if
// the "extensions.databaseSchema" preference shows we've
// already upgraded to JSON

// Enable loading extensions from the user and system scopes
Services.prefs.setIntPref("extensions.enabledScopes",
                          AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER +
                          AddonManager.SCOPE_SYSTEM);

var addon1 = {
  id: "addon1@tests.mozilla.org",
  version: "1.0",
  name: "Test 1",
  targetApplications: [{
    id: "xpcshell@tests.mozilla.org",
    minVersion: "1",
    maxVersion: "1"
  }]
};

createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
const profileDir = gProfD.clone();
profileDir.append("extensions");

function run_test() {
  writeInstallRDFForExtension(addon1, profileDir);

  // Write out a minimal database
  let dbfile = gProfD.clone();
  dbfile.append("extensions.sqlite");
  let db = AM_Cc["@mozilla.org/storage/service;1"].
           getService(AM_Ci.mozIStorageService).
           openDatabase(dbfile);
  db.createTable("addon", "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                          "id TEXT, location TEXT, version TEXT, active INTEGER, " +
                          "userDisabled INTEGER, installDate INTEGER");
  db.createTable("targetApplication", "addon_internal_id INTEGER, " +
                                      "id TEXT, minVersion TEXT, maxVersion TEXT");
  let stmt = db.createStatement("INSERT INTO addon VALUES (NULL, :id, :location, " +
                                ":version, :active, :userDisabled, :installDate)");

  let internal_ids = {};

  let a = ["addon1@tests.mozilla.org", "app-profile", "1.0", "0", "1", "0"];
  stmt.params.id = a[0];
  stmt.params.location = a[1];
  stmt.params.version = a[2];
  stmt.params.active = a[3];
  stmt.params.userDisabled = a[4];
  stmt.params.installDate = a[5];
  stmt.execute();
  internal_ids[a[0]] = db.lastInsertRowID;
  stmt.finalize();

  db.schemaVersion = 14;
  Services.prefs.setIntPref("extensions.databaseSchema", 14);
  db.close();

  startupManager();
  run_next_test();
}

add_test(function before_rebuild() {
  AddonManager.getAddonByID("addon1@tests.mozilla.org",
                            function check_before_rebuild (a1) {
    // First check that it migrated OK once
    // addon1 was disabled in the database
    do_check_neq(a1, null);
    do_check_true(a1.userDisabled);
    do_check_false(a1.appDisabled);
    do_check_false(a1.isActive);
    do_check_false(a1.strictCompatibility);
    do_check_false(a1.foreignInstall);

    run_next_test();
  });
});

// now shut down, remove the JSON database,
// start up again, and make sure the data didn't migrate this time
add_test(function rebuild_again() {
  shutdownManager();
  gExtensionsJSON.remove(true);
  startupManager();

  AddonManager.getAddonByID("addon1@tests.mozilla.org",
                            function check_after_rebuild(a1) {
    // addon1 was rebuilt from extensions directory,
    // so it appears enabled as a foreign install
    do_check_neq(a1, null);
    do_check_false(a1.userDisabled);
    do_check_false(a1.appDisabled);
    do_check_true(a1.isActive);
    do_check_false(a1.strictCompatibility);
    do_check_true(a1.foreignInstall);

    run_next_test();
  });
});