toolkit/mozapps/extensions/test/xpcshell/test_upgrade_strictcompat.js

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

mercurial