toolkit/webapps/tests/test_packaged_launch_no_registry.xul

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:eba983e08766
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=981249
6 -->
7 <window title="Mozilla Bug 981249"
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"
12 src="chrome://mochikit/content/chrome-harness.js"></script>
13 <script type="application/javascript" src="head.js"/>
14
15 <!-- test results are displayed in the html:body -->
16 <body xmlns="http://www.w3.org/1999/xhtml">
17 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=981249"
18 target="_blank">Mozilla Bug 981249</a>
19 </body>
20
21 <script type="application/javascript">
22 <![CDATA[
23
24 /** Test for Bug 981249 **/
25
26 "use strict";
27
28 SimpleTest.waitForExplicitFinish();
29
30 Cu.import("resource://gre/modules/Services.jsm");
31 Cu.import("resource://gre/modules/NativeApp.jsm");
32 Cu.import("resource://gre/modules/WebappOSUtils.jsm");
33 Cu.import("resource://gre/modules/Promise.jsm");
34
35 const PR_RDWR = 0x04;
36 const PR_CREATE_FILE = 0x08;
37 const PR_TRUNCATE = 0x20;
38
39 let manifest = {
40 name: "test_desktop_packaged_launch_no_registry",
41 version: "0.1a",
42 size: 777,
43 package_path: "/data/app.zip",
44 launch_path: "/index.html",
45 };
46
47 let app = {
48 name: "test_desktop_packaged_launch_no_registry",
49 manifestURL: "http://127.0.0.1:8888/sample_no_registry.manifest",
50 manifest: manifest,
51 updateManifest: manifest,
52 origin: "app://test_desktop_packaged_launch_no_registry/",
53 categories: [],
54 installOrigin: "http://127.0.0.1:8888/",
55 receipts: [],
56 installTime: Date.now(),
57 };
58
59 let profileDir;
60 let installPath;
61 let exePath;
62 let appProcess = Cc["@mozilla.org/process/util;1"].
63 createInstance(Ci.nsIProcess);
64
65 let cleanup;
66
67 if (LINUX) {
68 installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app));
69 exePath = OS.Path.join(installPath, "webapprt-stub");
70
71 let xdg_data_home = Cc["@mozilla.org/process/environment;1"].
72 getService(Ci.nsIEnvironment).
73 get("XDG_DATA_HOME");
74 if (!xdg_data_home) {
75 xdg_data_home = OS.Path.join(OS.Constants.Path.homeDir, ".local", "share");
76 }
77
78 let desktopINI = OS.Path.join(xdg_data_home, "applications",
79 "owa-" + WebappOSUtils.getUniqueName(app) + ".desktop");
80
81 cleanup = function() {
82 return Task.spawn(function*() {
83 if (appProcess.isRunning) {
84 appProcess.kill();
85 }
86
87 if (profileDir) {
88 yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
89 }
90
91 yield OS.File.removeDir(installPath, { ignoreAbsent: true });
92
93 yield OS.File.remove(desktopINI, { ignoreAbsent: true });
94 });
95 };
96 } else if (WIN) {
97 installPath = OS.Path.join(OS.Constants.Path.winAppDataDir, WebappOSUtils.getUniqueName(app));
98 exePath = OS.Path.join(installPath, "test_desktop_packaged_launch_no_registry.exe");
99
100 let desktopShortcut = OS.Path.join(OS.Constants.Path.desktopDir, "test_desktop_packaged_launch_no_registry.lnk");
101 let startMenuShortcut = OS.Path.join(OS.Constants.Path.winStartMenuProgsDir, "test_desktop_packaged_launch_no_registry.lnk");
102
103 cleanup = function() {
104 return Task.spawn(function*() {
105 if (appProcess.isRunning) {
106 appProcess.kill();
107 }
108
109 let uninstallKey;
110 try {
111 uninstallKey = Cc["@mozilla.org/windows-registry-key;1"].
112 createInstance(Ci.nsIWindowsRegKey);
113 uninstallKey.open(uninstallKey.ROOT_KEY_CURRENT_USER,
114 "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
115 uninstallKey.ACCESS_WRITE);
116 if (uninstallKey.hasChild(WebappOSUtils.getUniqueName(app))) {
117 uninstallKey.removeChild(WebappOSUtils.getUniqueName(app));
118 }
119 } catch (e) {
120 } finally {
121 if (uninstallKey) {
122 uninstallKey.close();
123 }
124 }
125
126 if (profileDir) {
127 yield OS.File.removeDir(profileDir.parent.parent.path, { ignoreAbsent: true });
128 }
129
130 yield OS.File.removeDir(installPath, { ignoreAbsent: true });
131
132 yield OS.File.remove(desktopShortcut, { ignoreAbsent: true });
133 yield OS.File.remove(startMenuShortcut, { ignoreAbsent: true });
134 });
135 };
136 } else if (MAC) {
137 installPath = OS.Path.join(OS.Constants.Path.homeDir, "Applications", "test_desktop_packaged_launch_no_registry.app");
138 exePath = OS.Path.join(installPath, "Contents", "MacOS", "webapprt");
139
140 let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support",
141 WebappOSUtils.getUniqueName(app));
142
143 cleanup = function() {
144 return Task.spawn(function*() {
145 if (appProcess.isRunning) {
146 appProcess.kill();
147 }
148
149 if (profileDir) {
150 yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
151 }
152
153 yield OS.File.removeDir(installPath, { ignoreAbsent: true });
154
155 yield OS.File.removeDir(appProfileDir, { ignoreAbsent: true });
156 });
157 };
158 }
159
160 function buildAppPackage() {
161 let zipFile = getFile(OS.Constants.Path.profileDir, "sample.zip");
162
163 let zipWriter = Cc["@mozilla.org/zipwriter;1"].createInstance(Ci.nsIZipWriter);
164 zipWriter.open(zipFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
165 zipWriter.addEntryFile("index.html",
166 Ci.nsIZipWriter.COMPRESSION_NONE,
167 getFile(getTestFilePath("data/app/index.html")),
168 false);
169 zipWriter.addEntryFile("manifest.webapp",
170 Ci.nsIZipWriter.COMPRESSION_NONE,
171 getFile(getTestFilePath("data/app/manifest.webapp")),
172 false);
173 zipWriter.close();
174
175 return zipFile.path;
176 }
177
178 function wasAppSJSAccessed() {
179 let deferred = Promise.defer();
180
181 var xhr = new XMLHttpRequest();
182
183 xhr.addEventListener("load", function() {
184 let ret = (xhr.responseText == "done") ? true : false;
185 deferred.resolve(ret);
186 });
187
188 xhr.addEventListener("error", aError => deferred.reject(aError));
189 xhr.addEventListener("abort", aError => deferred.reject(aError));
190
191 xhr.open('GET', 'http://test/chrome/toolkit/webapps/tests/app.sjs?testreq', true);
192 xhr.send();
193
194 return deferred.promise;
195 }
196
197 let runTest = Task.async(function*() {
198 // Get to a clean state before the test
199 yield cleanup();
200
201 SimpleTest.registerCleanupFunction(cleanup);
202
203 setDryRunPref();
204
205 let zipPath = buildAppPackage();
206
207 let nativeApp = new NativeApp(app, manifest, app.categories);
208 ok(nativeApp, "NativeApp object created");
209
210 profileDir = nativeApp.createProfile();
211 ok(profileDir && profileDir.exists(), "Profile directory created");
212
213 // On Mac build servers, we don't have enough privileges to write to /Applications,
214 // so we install apps in a user-owned directory.
215 if (MAC) {
216 nativeApp._rootInstallDir = OS.Path.join(OS.Constants.Path.homeDir, "Applications");
217 yield OS.File.makeDir(nativeApp._rootInstallDir, { ignoreExisting: true });
218 }
219
220 // Install application
221 info("Test installation");
222 yield nativeApp.install(manifest, zipPath);
223 while (!WebappOSUtils.isLaunchable(app)) {
224 yield wait(1000);
225 }
226 ok(true, "App launchable");
227
228 let exeFile = getFile(exePath);
229
230 ok(exeFile.isExecutable(), "webapprt executable is executable");
231
232 let appClosed = false;
233
234 appProcess.init(exeFile)
235 appProcess.runAsync([], 0, () => appClosed = true);
236
237 while (!(yield wasAppSJSAccessed()) && !appClosed) {
238 yield wait(1000);
239 }
240 ok(!appClosed, "App was launched and is still running");
241
242 SimpleTest.finish();
243 });
244
245 // The test doesn't work yet on Mac OS X 10.6 machines.
246 // See bug 993690.
247 if (MAC_106) {
248 todo(false, "The test doesn't work on Mac OS X 10.6 machines");
249 SimpleTest.finish();
250 } else {
251 runTest().then(null, function(e) {
252 ok(false, "Error during test: " + e);
253 SimpleTest.finish();
254 });
255 }
256
257 ]]>
258 </script>
259 </window>

mercurial