Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | // Checks that we fail to migrate but still start up ok when there is a SQLITE database |
michael@0 | 6 | // with no useful data in it. |
michael@0 | 7 | |
michael@0 | 8 | const PREF_GENERAL_SKINS_SELECTEDSKIN = "general.skins.selectedSkin"; |
michael@0 | 9 | |
michael@0 | 10 | var addon1 = { |
michael@0 | 11 | id: "addon1@tests.mozilla.org", |
michael@0 | 12 | version: "1.0", |
michael@0 | 13 | name: "Test 1", |
michael@0 | 14 | targetApplications: [{ |
michael@0 | 15 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 16 | minVersion: "1", |
michael@0 | 17 | maxVersion: "1" |
michael@0 | 18 | }] |
michael@0 | 19 | }; |
michael@0 | 20 | |
michael@0 | 21 | var addon2 = { |
michael@0 | 22 | id: "addon2@tests.mozilla.org", |
michael@0 | 23 | version: "2.0", |
michael@0 | 24 | name: "Test 5", |
michael@0 | 25 | targetApplications: [{ |
michael@0 | 26 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 27 | minVersion: "0", |
michael@0 | 28 | maxVersion: "0" |
michael@0 | 29 | }] |
michael@0 | 30 | }; |
michael@0 | 31 | |
michael@0 | 32 | var defaultTheme = { |
michael@0 | 33 | id: "default@tests.mozilla.org", |
michael@0 | 34 | version: "2.0", |
michael@0 | 35 | name: "Default theme", |
michael@0 | 36 | internalName: "classic/1.0", |
michael@0 | 37 | targetApplications: [{ |
michael@0 | 38 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 39 | minVersion: "1", |
michael@0 | 40 | maxVersion: "1" |
michael@0 | 41 | }] |
michael@0 | 42 | }; |
michael@0 | 43 | |
michael@0 | 44 | var theme1 = { |
michael@0 | 45 | id: "theme1@tests.mozilla.org", |
michael@0 | 46 | version: "2.0", |
michael@0 | 47 | name: "Test theme", |
michael@0 | 48 | internalName: "theme1/1.0", |
michael@0 | 49 | targetApplications: [{ |
michael@0 | 50 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 51 | minVersion: "1", |
michael@0 | 52 | maxVersion: "1" |
michael@0 | 53 | }] |
michael@0 | 54 | }; |
michael@0 | 55 | |
michael@0 | 56 | const profileDir = gProfD.clone(); |
michael@0 | 57 | profileDir.append("extensions"); |
michael@0 | 58 | |
michael@0 | 59 | function run_test() { |
michael@0 | 60 | do_test_pending(); |
michael@0 | 61 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 62 | |
michael@0 | 63 | writeInstallRDFForExtension(addon1, profileDir); |
michael@0 | 64 | writeInstallRDFForExtension(addon2, profileDir); |
michael@0 | 65 | writeInstallRDFForExtension(defaultTheme, profileDir); |
michael@0 | 66 | writeInstallRDFForExtension(theme1, profileDir); |
michael@0 | 67 | |
michael@0 | 68 | Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0"); |
michael@0 | 69 | |
michael@0 | 70 | // Write out a broken database (no userDisabled field) |
michael@0 | 71 | let dbfile = gProfD.clone(); |
michael@0 | 72 | dbfile.append("extensions.sqlite"); |
michael@0 | 73 | let db = AM_Cc["@mozilla.org/storage/service;1"]. |
michael@0 | 74 | getService(AM_Ci.mozIStorageService). |
michael@0 | 75 | openDatabase(dbfile); |
michael@0 | 76 | db.createTable("addon", "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " + |
michael@0 | 77 | "id TEXT, location TEXT, version TEXT, active INTEGER, " + |
michael@0 | 78 | "installDate INTEGER"); |
michael@0 | 79 | db.createTable("targetApplication", "addon_internal_id INTEGER, " + |
michael@0 | 80 | "id TEXT, minVersion TEXT, maxVersion TEXT"); |
michael@0 | 81 | let stmt = db.createStatement("INSERT INTO addon VALUES (NULL, :id, :location, " + |
michael@0 | 82 | ":version, :active, :installDate)"); |
michael@0 | 83 | |
michael@0 | 84 | let internal_ids = {}; |
michael@0 | 85 | |
michael@0 | 86 | [["addon1@tests.mozilla.org", "app-profile", "1.0", "1", "0"], |
michael@0 | 87 | ["addon2@tests.mozilla.org", "app-profile", "2.0", "0", "0"], |
michael@0 | 88 | ["default@tests.mozilla.org", "app-profile", "2.0", "1", "0"], |
michael@0 | 89 | ["theme1@tests.mozilla.org", "app-profile", "2.0", "0", "0"]].forEach(function(a) { |
michael@0 | 90 | stmt.params.id = a[0]; |
michael@0 | 91 | stmt.params.location = a[1]; |
michael@0 | 92 | stmt.params.version = a[2]; |
michael@0 | 93 | stmt.params.active = a[3]; |
michael@0 | 94 | stmt.params.installDate = a[4]; |
michael@0 | 95 | stmt.execute(); |
michael@0 | 96 | internal_ids[a[0]] = db.lastInsertRowID; |
michael@0 | 97 | }); |
michael@0 | 98 | stmt.finalize(); |
michael@0 | 99 | |
michael@0 | 100 | db.schemaVersion = 100; |
michael@0 | 101 | Services.prefs.setIntPref("extensions.databaseSchema", 100); |
michael@0 | 102 | db.close(); |
michael@0 | 103 | |
michael@0 | 104 | startupManager(); |
michael@0 | 105 | check_startup_changes("installed", []); |
michael@0 | 106 | check_startup_changes("updated", []); |
michael@0 | 107 | check_startup_changes("uninstalled", []); |
michael@0 | 108 | check_startup_changes("disabled", []); |
michael@0 | 109 | check_startup_changes("enabled", []); |
michael@0 | 110 | |
michael@0 | 111 | AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
michael@0 | 112 | "addon2@tests.mozilla.org", |
michael@0 | 113 | "default@tests.mozilla.org", |
michael@0 | 114 | "theme1@tests.mozilla.org"], |
michael@0 | 115 | function([a1, a2, d, t1]) { |
michael@0 | 116 | do_check_neq(a1, null); |
michael@0 | 117 | do_check_false(a1.userDisabled); |
michael@0 | 118 | do_check_false(a1.appDisabled); |
michael@0 | 119 | do_check_true(a1.isActive); |
michael@0 | 120 | |
michael@0 | 121 | do_check_neq(a2, null); |
michael@0 | 122 | do_check_false(a2.userDisabled); |
michael@0 | 123 | do_check_true(a2.appDisabled); |
michael@0 | 124 | do_check_false(a2.isActive); |
michael@0 | 125 | |
michael@0 | 126 | // Should have enabled the selected theme |
michael@0 | 127 | do_check_neq(t1, null); |
michael@0 | 128 | do_check_false(t1.userDisabled); |
michael@0 | 129 | do_check_false(t1.appDisabled); |
michael@0 | 130 | do_check_true(t1.isActive); |
michael@0 | 131 | |
michael@0 | 132 | do_check_neq(d, null); |
michael@0 | 133 | do_check_true(d.userDisabled); |
michael@0 | 134 | do_check_false(d.appDisabled); |
michael@0 | 135 | do_check_false(d.isActive); |
michael@0 | 136 | |
michael@0 | 137 | do_execute_soon(do_test_finished); |
michael@0 | 138 | }); |
michael@0 | 139 | } |