Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 // Checks that we migrate data from the old extensions.rdf database. This
6 // matches test_migrate1.js however it runs with a lightweight theme selected
7 // so the themes should appear disabled.
9 Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
11 var addon1 = {
12 id: "addon1@tests.mozilla.org",
13 version: "1.0",
14 name: "Test 1",
15 targetApplications: [{
16 id: "xpcshell@tests.mozilla.org",
17 minVersion: "1",
18 maxVersion: "1"
19 }]
20 };
22 var addon2 = {
23 id: "addon2@tests.mozilla.org",
24 version: "2.0",
25 name: "Test 2",
26 targetApplications: [{
27 id: "toolkit@mozilla.org",
28 minVersion: "1",
29 maxVersion: "1"
30 }]
31 };
33 var addon3 = {
34 id: "addon3@tests.mozilla.org",
35 version: "2.0",
36 name: "Test 3",
37 targetApplications: [{
38 id: "xpcshell@tests.mozilla.org",
39 minVersion: "1",
40 maxVersion: "1"
41 }]
42 };
44 var addon4 = {
45 id: "addon4@tests.mozilla.org",
46 version: "2.0",
47 name: "Test 4",
48 targetApplications: [{
49 id: "toolkit@mozilla.org",
50 minVersion: "1",
51 maxVersion: "1"
52 }]
53 };
55 var addon5 = {
56 id: "addon5@tests.mozilla.org",
57 version: "2.0",
58 name: "Test 5",
59 targetApplications: [{
60 id: "toolkit@mozilla.org",
61 minVersion: "1",
62 maxVersion: "1"
63 }]
64 };
66 var theme1 = {
67 id: "theme1@tests.mozilla.org",
68 version: "1.0",
69 name: "Theme 1",
70 type: 4,
71 internalName: "theme1/1.0",
72 targetApplications: [{
73 id: "xpcshell@tests.mozilla.org",
74 minVersion: "1",
75 maxVersion: "2"
76 }]
77 };
79 var theme2 = {
80 id: "theme2@tests.mozilla.org",
81 version: "1.0",
82 name: "Theme 2",
83 type: 4,
84 internalName: "theme2/1.0",
85 targetApplications: [{
86 id: "xpcshell@tests.mozilla.org",
87 minVersion: "1",
88 maxVersion: "2"
89 }]
90 };
92 const profileDir = gProfD.clone();
93 profileDir.append("extensions");
95 function run_test() {
96 do_test_pending();
97 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2");
99 writeInstallRDFForExtension(addon1, profileDir);
100 writeInstallRDFForExtension(addon2, profileDir);
101 writeInstallRDFForExtension(addon3, profileDir);
102 writeInstallRDFForExtension(addon4, profileDir);
103 writeInstallRDFForExtension(addon5, profileDir);
104 writeInstallRDFForExtension(theme1, profileDir);
105 writeInstallRDFForExtension(theme2, profileDir);
107 // Cannot use the LightweightThemeManager before AddonManager has been started
108 // so inject the correct prefs
109 Services.prefs.setCharPref("lightweightThemes.usedThemes", JSON.stringify([{
110 id: "1",
111 version: "1",
112 name: "Test LW Theme",
113 description: "A test theme",
114 author: "Mozilla",
115 homepageURL: "http://localhost/data/index.html",
116 headerURL: "http://localhost/data/header.png",
117 footerURL: "http://localhost/data/footer.png",
118 previewURL: "http://localhost/data/preview.png",
119 iconURL: "http://localhost/data/icon.png"
120 }]));
121 Services.prefs.setBoolPref("lightweightThemes.isThemeSelected", true);
123 let stagedXPIs = profileDir.clone();
124 stagedXPIs.append("staged-xpis");
125 stagedXPIs.append("addon6@tests.mozilla.org");
126 stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
128 let addon6 = do_get_addon("test_migrate6");
129 addon6.copyTo(stagedXPIs, "tmp.xpi");
130 stagedXPIs = stagedXPIs.parent;
132 stagedXPIs.append("addon7@tests.mozilla.org");
133 stagedXPIs.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
135 let addon7 = do_get_addon("test_migrate7");
136 addon7.copyTo(stagedXPIs, "tmp.xpi");
137 stagedXPIs = stagedXPIs.parent;
139 let old = do_get_file("data/test_migrate.rdf");
140 old.copyTo(gProfD, "extensions.rdf");
142 // Theme state is determined by the selected theme pref
143 Services.prefs.setCharPref("general.skins.selectedSkin", "theme1/1.0");
145 startupManager();
146 check_startup_changes("installed", []);
147 check_startup_changes("updated", []);
148 check_startup_changes("uninstalled", []);
149 check_startup_changes("disabled", []);
150 check_startup_changes("enabled", []);
152 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
153 "addon2@tests.mozilla.org",
154 "addon3@tests.mozilla.org",
155 "addon4@tests.mozilla.org",
156 "addon5@tests.mozilla.org",
157 "addon6@tests.mozilla.org",
158 "addon7@tests.mozilla.org",
159 "theme1@tests.mozilla.org",
160 "theme2@tests.mozilla.org"], function([a1, a2, a3,
161 a4, a5, a6,
162 a7, t1, t2]) {
163 // addon1 was user and app enabled in the old extensions.rdf
164 do_check_neq(a1, null);
165 do_check_false(a1.userDisabled);
166 do_check_false(a1.appDisabled);
167 do_check_true(a1.isActive);
168 do_check_true(isExtensionInAddonsList(profileDir, a1.id));
170 // addon2 was user disabled and app enabled in the old extensions.rdf
171 do_check_neq(a2, null);
172 do_check_true(a2.userDisabled);
173 do_check_false(a2.appDisabled);
174 do_check_false(a2.isActive);
175 do_check_false(isExtensionInAddonsList(profileDir, a2.id));
177 // addon3 was pending user disable and app disabled in the old extensions.rdf
178 do_check_neq(a3, null);
179 do_check_true(a3.userDisabled);
180 do_check_true(a3.appDisabled);
181 do_check_false(a3.isActive);
182 do_check_false(isExtensionInAddonsList(profileDir, a3.id));
184 // addon4 was pending user enable and app disabled in the old extensions.rdf
185 do_check_neq(a4, null);
186 do_check_false(a4.userDisabled);
187 do_check_true(a4.appDisabled);
188 do_check_false(a4.isActive);
189 do_check_false(isExtensionInAddonsList(profileDir, a4.id));
191 // addon5 was disabled and compatible but a new version has been installed
192 // since, it should still be disabled but should be incompatible
193 do_check_neq(a5, null);
194 do_check_true(a5.userDisabled);
195 do_check_true(a5.appDisabled);
196 do_check_false(a5.isActive);
197 do_check_false(isExtensionInAddonsList(profileDir, a5.id));
199 // addon6 should be installed and compatible and packed unless unpacking is
200 // forced
201 do_check_neq(a6, null);
202 do_check_false(a6.userDisabled);
203 do_check_false(a6.appDisabled);
204 do_check_true(a6.isActive);
205 do_check_true(isExtensionInAddonsList(profileDir, a6.id));
206 if (Services.prefs.getBoolPref("extensions.alwaysUnpack"))
207 do_check_eq(a6.getResourceURI("install.rdf").scheme, "file");
208 else
209 do_check_eq(a6.getResourceURI("install.rdf").scheme, "jar");
211 // addon7 should be installed and compatible and unpacked
212 do_check_neq(a7, null);
213 do_check_false(a7.userDisabled);
214 do_check_false(a7.appDisabled);
215 do_check_true(a7.isActive);
216 do_check_true(isExtensionInAddonsList(profileDir, a7.id));
217 do_check_eq(a7.getResourceURI("install.rdf").scheme, "file");
219 // Theme 1 was previously disabled
220 do_check_neq(t1, null);
221 do_check_true(t1.userDisabled);
222 do_check_false(t1.appDisabled);
223 do_check_false(t1.isActive);
224 do_check_true(isThemeInAddonsList(profileDir, t1.id));
225 do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE));
227 // Theme 2 was previously disabled
228 do_check_neq(t1, null);
229 do_check_true(t2.userDisabled);
230 do_check_false(t2.appDisabled);
231 do_check_false(t2.isActive);
232 do_check_false(isThemeInAddonsList(profileDir, t2.id));
233 do_check_true(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE));
235 do_check_false(stagedXPIs.exists());
237 do_execute_soon(do_test_finished);
238 });
239 }