toolkit/webapps/tests/test_packaged.xul

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:f6345fabf0b3
1 <?xml version="1.0"?>
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
3 <?xml-stylesheet type="text/css" href="/tests/SimpleTest/test.css"?>
4 <!--
5 https://bugzilla.mozilla.org/show_bug.cgi?id=898647
6 -->
7 <window title="Mozilla Bug 898647"
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <script type="application/javascript"
10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
11 <script type="application/javascript" src="head.js"/>
12
13 <!-- test results are displayed in the html:body -->
14 <body xmlns="http://www.w3.org/1999/xhtml">
15 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=898647"
16 target="_blank">Mozilla Bug 898647</a>
17 </body>
18
19 <script type="application/javascript">
20 <![CDATA[
21
22 /** Test for Bug 898647 **/
23
24 "use strict";
25
26 SimpleTest.waitForExplicitFinish();
27
28 Cu.import("resource://gre/modules/Services.jsm");
29 Cu.import("resource://gre/modules/NativeApp.jsm");
30 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
31
32 let zipPath = OS.Path.join(OS.Constants.Path.profileDir, "sample.zip");
33
34 let manifest = {
35 name: "Sample packaged app",
36 version: "0.1a",
37 size: 777,
38 package_path: "/sample.zip",
39 };
40
41 let app = {
42 name: "Sample packaged app",
43 manifestURL: "http://example.com/sample.manifest",
44 manifest: manifest,
45 updateManifest: manifest,
46 origin: "http://example.com/",
47 categories: [],
48 installOrigin: "http://example.com/",
49 receipts: [],
50 installTime: Date.now(),
51 };
52
53 let profileDir;
54 let profilesIni;
55 let installPath;
56
57 let installedFiles;
58 let tempUpdatedFiles;
59 let updatedFiles;
60
61 let cleanup;
62
63 if (LINUX) {
64 installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app));
65
66 let xdg_data_home = Cc["@mozilla.org/process/environment;1"].
67 getService(Ci.nsIEnvironment).
68 get("XDG_DATA_HOME");
69 if (!xdg_data_home) {
70 xdg_data_home = OS.Path.join(OS.Constants.Path.homeDir, ".local", "share");
71 }
72
73 let desktopINI = OS.Path.join(xdg_data_home, "applications",
74 "owa-" + WebappOSUtils.getUniqueName(app) + ".desktop");
75
76 installedFiles = [
77 OS.Path.join(installPath, "icon.png"),
78 OS.Path.join(installPath, "webapprt-stub"),
79 OS.Path.join(installPath, "webapp.json"),
80 OS.Path.join(installPath, "webapp.ini"),
81 OS.Path.join(installPath, "application.zip"),
82 desktopINI,
83 ];
84 tempUpdatedFiles = [
85 OS.Path.join(installPath, "update", "icon.png"),
86 OS.Path.join(installPath, "update", "webapp.json"),
87 OS.Path.join(installPath, "update", "webapp.ini"),
88 OS.Path.join(installPath, "update", "application.zip"),
89 ];
90 updatedFiles = [
91 OS.Path.join(installPath, "icon.png"),
92 OS.Path.join(installPath, "webapp.json"),
93 OS.Path.join(installPath, "webapp.ini"),
94 OS.Path.join(installPath, "application.zip"),
95 desktopINI,
96 ];
97
98 profilesIni = OS.Path.join(installPath, "profiles.ini");
99
100 cleanup = function() {
101 return Task.spawn(function*() {
102 if (profileDir) {
103 yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
104 }
105
106 yield OS.File.removeDir(installPath, { ignoreAbsent: true });
107
108 yield OS.File.remove(desktopINI, { ignoreAbsent: true });
109 });
110 };
111 } else if (WIN) {
112 installPath = OS.Path.join(OS.Constants.Path.winAppDataDir, WebappOSUtils.getUniqueName(app));
113
114 let desktopShortcut = OS.Path.join(OS.Constants.Path.desktopDir, "Sample packaged app.lnk");
115 let startMenuShortcut = OS.Path.join(OS.Constants.Path.winStartMenuProgsDir, "Sample packaged app.lnk");
116
117 installedFiles = [
118 OS.Path.join(installPath, "Sample packaged app.exe"),
119 OS.Path.join(installPath, "chrome", "icons", "default", "default.ico"),
120 OS.Path.join(installPath, "webapp.json"),
121 OS.Path.join(installPath, "webapp.ini"),
122 OS.Path.join(installPath, "application.zip"),
123 OS.Path.join(installPath, "uninstall", "shortcuts_log.ini"),
124 OS.Path.join(installPath, "uninstall", "uninstall.log"),
125 OS.Path.join(installPath, "uninstall", "webapp-uninstaller.exe"),
126 desktopShortcut,
127 startMenuShortcut,
128 ];
129 tempUpdatedFiles = [
130 OS.Path.join(installPath, "update", "chrome", "icons", "default", "default.ico"),
131 OS.Path.join(installPath, "update", "webapp.json"),
132 OS.Path.join(installPath, "update", "webapp.ini"),
133 OS.Path.join(installPath, "update", "application.zip"),
134 OS.Path.join(installPath, "update", "uninstall", "shortcuts_log.ini"),
135 OS.Path.join(installPath, "update", "uninstall", "uninstall.log"),
136 OS.Path.join(installPath, "update", "uninstall", "webapp-uninstaller.exe"),
137 ];
138 updatedFiles = [
139 OS.Path.join(installPath, "chrome", "icons", "default", "default.ico"),
140 OS.Path.join(installPath, "webapp.json"),
141 OS.Path.join(installPath, "webapp.ini"),
142 OS.Path.join(installPath, "application.zip"),
143 OS.Path.join(installPath, "uninstall", "shortcuts_log.ini"),
144 OS.Path.join(installPath, "uninstall", "uninstall.log"),
145 desktopShortcut,
146 startMenuShortcut,
147 ];
148
149 profilesIni = OS.Path.join(installPath, "profiles.ini");
150
151 cleanup = function() {
152 return Task.spawn(function*() {
153 let uninstallKey;
154 try {
155 uninstallKey = Cc["@mozilla.org/windows-registry-key;1"].
156 createInstance(Ci.nsIWindowsRegKey);
157 uninstallKey.open(uninstallKey.ROOT_KEY_CURRENT_USER,
158 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
159 uninstallKey.ACCESS_WRITE);
160 if (uninstallKey.hasChild(WebappOSUtils.getUniqueName(app))) {
161 uninstallKey.removeChild(WebappOSUtils.getUniqueName(app));
162 }
163 } catch (e) {
164 } finally {
165 if (uninstallKey) {
166 uninstallKey.close();
167 }
168 }
169
170 if (profileDir) {
171 yield OS.File.removeDir(profileDir.parent.parent.path, { ignoreAbsent: true });
172 }
173
174 yield OS.File.removeDir(installPath, { ignoreAbsent: true });
175
176 yield OS.File.remove(desktopShortcut, { ignoreAbsent: true });
177 yield OS.File.remove(startMenuShortcut, { ignoreAbsent: true });
178 });
179 };
180 } else if (MAC) {
181 installPath = OS.Path.join(OS.Constants.Path.homeDir, "Applications", "Sample packaged app.app");
182 let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support",
183 WebappOSUtils.getUniqueName(app));
184
185 installedFiles = [
186 OS.Path.join(installPath, "Contents", "Info.plist"),
187 OS.Path.join(installPath, "Contents", "MacOS", "webapprt"),
188 OS.Path.join(installPath, "Contents", "MacOS", "webapp.ini"),
189 OS.Path.join(installPath, "Contents", "Resources", "appicon.icns"),
190 OS.Path.join(installPath, "Contents", "Resources", "application.zip"),
191 OS.Path.join(appProfileDir, "webapp.json"),
192 ];
193 tempUpdatedFiles = [
194 OS.Path.join(installPath, "update", "Contents", "Info.plist"),
195 OS.Path.join(installPath, "update", "Contents", "MacOS", "webapp.ini"),
196 OS.Path.join(installPath, "update", "Contents", "Resources", "appicon.icns"),
197 OS.Path.join(installPath, "update", "Contents", "Resources", "application.zip"),
198 OS.Path.join(installPath, "update", "webapp.json"),
199 ];
200 updatedFiles = [
201 OS.Path.join(installPath, "Contents", "Info.plist"),
202 OS.Path.join(installPath, "Contents", "MacOS", "webapp.ini"),
203 OS.Path.join(installPath, "Contents", "Resources", "appicon.icns"),
204 OS.Path.join(installPath, "Contents", "Resources", "application.zip"),
205 OS.Path.join(appProfileDir, "webapp.json"),
206 ];
207
208 profilesIni = OS.Path.join(appProfileDir, "profiles.ini");
209
210 cleanup = function() {
211 return Task.spawn(function*() {
212 if (profileDir) {
213 yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
214 }
215
216 yield OS.File.removeDir(installPath, { ignoreAbsent: true });
217
218 yield OS.File.removeDir(appProfileDir, { ignoreAbsent: true });
219 });
220 };
221 }
222
223 let runTest = Task.async(function*() {
224 // Get to a clean state before the test
225 yield cleanup();
226
227 SimpleTest.registerCleanupFunction(cleanup);
228
229 setDryRunPref();
230
231 let zipFile = yield OS.File.open(zipPath, { create: true });
232 yield zipFile.close();
233
234 let nativeApp = new NativeApp(app, manifest, app.categories);
235 ok(nativeApp, "NativeApp object created");
236
237 info("Test update for an application that isn't installed");
238 try {
239 yield nativeApp.prepareUpdate(manifest, zipPath);
240 ok(false, "Didn't thrown");
241 } catch (ex) {
242 is(ex, "The application isn't installed", "Exception thrown");
243 }
244
245 profileDir = nativeApp.createProfile();
246 ok(profileDir && profileDir.exists(), "Profile directory created");
247 ok((yield OS.File.exists(profilesIni)), "profiles.ini file created");
248
249 // On Mac build servers, we don't have enough privileges to write to /Applications,
250 // so we install apps in a user-owned directory.
251 if (MAC) {
252 nativeApp._rootInstallDir = OS.Path.join(OS.Constants.Path.homeDir, "Applications");
253 yield OS.File.makeDir(nativeApp._rootInstallDir, { ignoreExisting: true });
254 }
255
256 // Install application
257 info("Test installation");
258 yield nativeApp.install(manifest, zipPath);
259 while (!WebappOSUtils.isLaunchable(app)) {
260 yield wait(1000);
261 }
262 ok(true, "App launchable");
263 ok((yield checkFiles(installedFiles)), "Files correctly written");
264 is(WebappOSUtils.getInstallPath(app), installPath, "getInstallPath == installPath");
265
266 let stat = yield OS.File.stat(installPath);
267 let installTime = stat.lastModificationDate;
268
269 // Wait one second, otherwise the last modification date is the same.
270 yield wait(1000);
271
272 // Reinstall application
273 info("Test reinstallation");
274
275 zipFile = yield OS.File.open(zipPath, { create: true });
276 yield zipFile.close();
277
278 yield nativeApp.install(manifest, zipPath);
279 while (!WebappOSUtils.isLaunchable(app)) {
280 yield wait(1000);
281 }
282 ok(true, "App launchable");
283 ok((yield checkFiles(installedFiles)), "Installation not corrupted");
284 ok((yield checkFiles(tempUpdatedFiles)), "Files correctly written in the update subdirectory");
285
286 yield nativeApp.applyUpdate();
287 while (!WebappOSUtils.isLaunchable(app)) {
288 yield wait(1000);
289 }
290 ok(true, "App launchable");
291 ok((yield checkFiles(installedFiles)), "Installation not corrupted");
292 ok(!(yield OS.File.exists(OS.Path.join(installPath, "update"))), "Update directory removed");
293 ok((yield checkDateHigherThan(updatedFiles, installTime)), "Modification date higher");
294
295 stat = yield OS.File.stat(installPath);
296 installTime = stat.lastModificationDate;
297
298 // Wait one second, otherwise the last modification date is the same.
299 yield wait(1000);
300
301 // Update application
302 info("Test update");
303
304 zipFile = yield OS.File.open(zipPath, { create: true });
305 yield zipFile.close();
306
307 yield nativeApp.prepareUpdate(manifest, zipPath);
308 while (!WebappOSUtils.isLaunchable(app)) {
309 yield wait(1000);
310 }
311 ok(true, "App launchable");
312 ok((yield checkFiles(installedFiles)), "Installation not corrupted");
313 ok((yield checkFiles(tempUpdatedFiles)), "Files correctly written in the update subdirectory");
314
315 yield nativeApp.applyUpdate();
316 while (!WebappOSUtils.isLaunchable(app)) {
317 yield wait(1000);
318 }
319 ok(true, "App launchable");
320 ok((yield checkFiles(installedFiles)), "Installation not corrupted");
321 ok(!(yield OS.File.exists(OS.Path.join(installPath, "update"))), "Update directory removed");
322 ok((yield checkDateHigherThan(updatedFiles, installTime)), "Modification date higher");
323
324 SimpleTest.finish();
325 });
326
327 // The test doesn't work yet on Mac OS X 10.6 machines.
328 // See bug 993690.
329 if (MAC_106) {
330 todo(false, "The test doesn't work on Mac OS X 10.6 machines");
331 SimpleTest.finish();
332 } else {
333 runTest().then(null, function(e) {
334 ok(false, "Error during test: " + e);
335 SimpleTest.finish();
336 });
337 }
338
339 ]]>
340 </script>
341 </window>

mercurial