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