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