|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // This verifies that app upgrades produce the expected behaviours, |
|
6 // with strict compatibility checking disabled. |
|
7 |
|
8 Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false); |
|
9 |
|
10 // Enable loading extensions from the application scope |
|
11 Services.prefs.setIntPref("extensions.enabledScopes", |
|
12 AddonManager.SCOPE_PROFILE + |
|
13 AddonManager.SCOPE_APPLICATION); |
|
14 |
|
15 const profileDir = gProfD.clone(); |
|
16 profileDir.append("extensions"); |
|
17 |
|
18 const globalDir = Services.dirsvc.get("XCurProcD", AM_Ci.nsIFile); |
|
19 globalDir.append("extensions"); |
|
20 |
|
21 var gGlobalExisted = globalDir.exists(); |
|
22 var gInstallTime = Date.now(); |
|
23 |
|
24 function run_test() { |
|
25 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
26 |
|
27 // Will be compatible in the first version and incompatible in subsequent versions |
|
28 writeInstallRDFForExtension({ |
|
29 id: "addon1@tests.mozilla.org", |
|
30 version: "1.0", |
|
31 targetApplications: [{ |
|
32 id: "xpcshell@tests.mozilla.org", |
|
33 minVersion: "1", |
|
34 maxVersion: "1" |
|
35 }], |
|
36 name: "Test Addon 1", |
|
37 targetPlatforms: [ |
|
38 "XPCShell", |
|
39 "WINNT_x86", |
|
40 ] |
|
41 }, profileDir); |
|
42 |
|
43 // Works in all tested versions |
|
44 writeInstallRDFForExtension({ |
|
45 id: "addon2@tests.mozilla.org", |
|
46 version: "1.0", |
|
47 targetApplications: [{ |
|
48 id: "xpcshell@tests.mozilla.org", |
|
49 minVersion: "1", |
|
50 maxVersion: "2" |
|
51 }], |
|
52 name: "Test Addon 2", |
|
53 targetPlatforms: [ |
|
54 "XPCShell_noarch-spidermonkey" |
|
55 ] |
|
56 }, profileDir); |
|
57 |
|
58 // Will be disabled in the first version and enabled in the second. |
|
59 writeInstallRDFForExtension({ |
|
60 id: "addon3@tests.mozilla.org", |
|
61 version: "1.0", |
|
62 targetApplications: [{ |
|
63 id: "xpcshell@tests.mozilla.org", |
|
64 minVersion: "2", |
|
65 maxVersion: "2" |
|
66 }], |
|
67 name: "Test Addon 3", |
|
68 }, profileDir); |
|
69 |
|
70 // Will be compatible in both versions but will change version in between |
|
71 var dest = writeInstallRDFForExtension({ |
|
72 id: "addon4@tests.mozilla.org", |
|
73 version: "1.0", |
|
74 targetApplications: [{ |
|
75 id: "xpcshell@tests.mozilla.org", |
|
76 minVersion: "1", |
|
77 maxVersion: "1" |
|
78 }], |
|
79 name: "Test Addon 4", |
|
80 }, globalDir); |
|
81 setExtensionModifiedTime(dest, gInstallTime); |
|
82 |
|
83 do_test_pending(); |
|
84 |
|
85 run_test_1(); |
|
86 } |
|
87 |
|
88 function end_test() { |
|
89 if (!gGlobalExisted) { |
|
90 globalDir.remove(true); |
|
91 } |
|
92 else { |
|
93 globalDir.append(do_get_expected_addon_name("addon4@tests.mozilla.org")); |
|
94 globalDir.remove(true); |
|
95 } |
|
96 do_execute_soon(do_test_finished); |
|
97 } |
|
98 |
|
99 // Test that the test extensions are all installed |
|
100 function run_test_1() { |
|
101 startupManager(); |
|
102 |
|
103 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
104 "addon2@tests.mozilla.org", |
|
105 "addon3@tests.mozilla.org", |
|
106 "addon4@tests.mozilla.org"], |
|
107 function([a1, a2, a3, a4]) { |
|
108 |
|
109 do_check_neq(a1, null); |
|
110 do_check_true(isExtensionInAddonsList(profileDir, a1.id)); |
|
111 |
|
112 do_check_neq(a2, null); |
|
113 do_check_true(isExtensionInAddonsList(profileDir, a2.id)); |
|
114 |
|
115 do_check_neq(a3, null); |
|
116 do_check_false(isExtensionInAddonsList(profileDir, a3.id)); |
|
117 |
|
118 do_check_neq(a4, null); |
|
119 do_check_true(isExtensionInAddonsList(globalDir, a4.id)); |
|
120 do_check_eq(a4.version, "1.0"); |
|
121 |
|
122 do_execute_soon(run_test_2); |
|
123 }); |
|
124 } |
|
125 |
|
126 // Test that upgrading the application doesn't disable now incompatible add-ons |
|
127 function run_test_2() { |
|
128 // Upgrade the extension |
|
129 var dest = writeInstallRDFForExtension({ |
|
130 id: "addon4@tests.mozilla.org", |
|
131 version: "2.0", |
|
132 targetApplications: [{ |
|
133 id: "xpcshell@tests.mozilla.org", |
|
134 minVersion: "2", |
|
135 maxVersion: "2" |
|
136 }], |
|
137 name: "Test Addon 4", |
|
138 }, globalDir); |
|
139 setExtensionModifiedTime(dest, gInstallTime); |
|
140 |
|
141 restartManager("2"); |
|
142 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
143 "addon2@tests.mozilla.org", |
|
144 "addon3@tests.mozilla.org", |
|
145 "addon4@tests.mozilla.org"], |
|
146 function([a1, a2, a3, a4]) { |
|
147 |
|
148 do_check_neq(a1, null); |
|
149 do_check_true(isExtensionInAddonsList(profileDir, a1.id)); |
|
150 |
|
151 do_check_neq(a2, null); |
|
152 do_check_true(isExtensionInAddonsList(profileDir, a2.id)); |
|
153 |
|
154 do_check_neq(a3, null); |
|
155 do_check_true(isExtensionInAddonsList(profileDir, a3.id)); |
|
156 |
|
157 do_check_neq(a4, null); |
|
158 do_check_true(isExtensionInAddonsList(globalDir, a4.id)); |
|
159 do_check_eq(a4.version, "2.0"); |
|
160 |
|
161 do_execute_soon(run_test_3); |
|
162 }); |
|
163 } |
|
164 |
|
165 // Test that nothing changes when only the build ID changes. |
|
166 function run_test_3() { |
|
167 // Upgrade the extension |
|
168 var dest = writeInstallRDFForExtension({ |
|
169 id: "addon4@tests.mozilla.org", |
|
170 version: "3.0", |
|
171 targetApplications: [{ |
|
172 id: "xpcshell@tests.mozilla.org", |
|
173 minVersion: "3", |
|
174 maxVersion: "3" |
|
175 }], |
|
176 name: "Test Addon 4", |
|
177 }, globalDir); |
|
178 setExtensionModifiedTime(dest, gInstallTime); |
|
179 |
|
180 // Simulates a simple Build ID change, the platform deletes extensions.ini |
|
181 // whenever the application is changed. |
|
182 gExtensionsINI.remove(true); |
|
183 restartManager(); |
|
184 |
|
185 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", |
|
186 "addon2@tests.mozilla.org", |
|
187 "addon3@tests.mozilla.org", |
|
188 "addon4@tests.mozilla.org"], |
|
189 function([a1, a2, a3, a4]) { |
|
190 |
|
191 do_check_neq(a1, null); |
|
192 do_check_true(isExtensionInAddonsList(profileDir, a1.id)); |
|
193 |
|
194 do_check_neq(a2, null); |
|
195 do_check_true(isExtensionInAddonsList(profileDir, a2.id)); |
|
196 |
|
197 do_check_neq(a3, null); |
|
198 do_check_true(isExtensionInAddonsList(profileDir, a3.id)); |
|
199 |
|
200 do_check_neq(a4, null); |
|
201 do_check_true(isExtensionInAddonsList(globalDir, a4.id)); |
|
202 do_check_eq(a4.version, "2.0"); |
|
203 |
|
204 end_test(); |
|
205 }); |
|
206 } |