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

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

mercurial