1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bad_json.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 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 +// Tests that we rebuild the database correctly if it contains 1.9 +// JSON data that parses correctly but doesn't contain required fields 1.10 + 1.11 +var addon1 = { 1.12 + id: "addon1@tests.mozilla.org", 1.13 + version: "2.0", 1.14 + name: "Test 1", 1.15 + targetApplications: [{ 1.16 + id: "xpcshell@tests.mozilla.org", 1.17 + minVersion: "1", 1.18 + maxVersion: "1" 1.19 + }] 1.20 +}; 1.21 + 1.22 +const profileDir = gProfD.clone(); 1.23 +profileDir.append("extensions"); 1.24 + 1.25 +function run_test() { 1.26 + do_test_pending("Bad JSON"); 1.27 + 1.28 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); 1.29 + 1.30 + // This addon will be auto-installed at startup 1.31 + writeInstallRDFForExtension(addon1, profileDir); 1.32 + 1.33 + startupManager(); 1.34 + 1.35 + shutdownManager(); 1.36 + 1.37 + // First startup/shutdown finished 1.38 + // Replace the JSON store with something bogus 1.39 + saveJSON({not: "what we expect to find"}, gExtensionsJSON); 1.40 + 1.41 + startupManager(false); 1.42 + // Retrieve an addon to force the database to rebuild 1.43 + AddonManager.getAddonsByIDs([addon1.id], callback_soon(after_db_rebuild)); 1.44 +} 1.45 + 1.46 +function after_db_rebuild([a1]) { 1.47 + do_check_eq(a1.id, addon1.id); 1.48 + 1.49 + shutdownManager(); 1.50 + 1.51 + // Make sure our JSON database has schemaVersion and our installed extension 1.52 + let data = loadJSON(gExtensionsJSON); 1.53 + do_check_true("schemaVersion" in data); 1.54 + do_check_eq(data.addons[0].id, addon1.id); 1.55 + 1.56 + do_test_finished("Bad JSON"); 1.57 +}