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

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:6e446b2b435f
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
4
5 // Tests that we rebuild the database correctly if it contains
6 // JSON data that parses correctly but doesn't contain required fields
7
8 var addon1 = {
9 id: "addon1@tests.mozilla.org",
10 version: "2.0",
11 name: "Test 1",
12 targetApplications: [{
13 id: "xpcshell@tests.mozilla.org",
14 minVersion: "1",
15 maxVersion: "1"
16 }]
17 };
18
19 const profileDir = gProfD.clone();
20 profileDir.append("extensions");
21
22 function run_test() {
23 do_test_pending("Bad JSON");
24
25 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
26
27 // This addon will be auto-installed at startup
28 writeInstallRDFForExtension(addon1, profileDir);
29
30 startupManager();
31
32 shutdownManager();
33
34 // First startup/shutdown finished
35 // Replace the JSON store with something bogus
36 saveJSON({not: "what we expect to find"}, gExtensionsJSON);
37
38 startupManager(false);
39 // Retrieve an addon to force the database to rebuild
40 AddonManager.getAddonsByIDs([addon1.id], callback_soon(after_db_rebuild));
41 }
42
43 function after_db_rebuild([a1]) {
44 do_check_eq(a1.id, addon1.id);
45
46 shutdownManager();
47
48 // Make sure our JSON database has schemaVersion and our installed extension
49 let data = loadJSON(gExtensionsJSON);
50 do_check_true("schemaVersion" in data);
51 do_check_eq(data.addons[0].id, addon1.id);
52
53 do_test_finished("Bad JSON");
54 }

mercurial