Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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"/>
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>
19 <script type="application/javascript">
20 <![CDATA[
22 /** Test for Bug 981249 **/
24 "use strict";
26 SimpleTest.waitForExplicitFinish();
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");
33 let manifest = {
34 name: "test_desktop_hosted_launch_no_registry",
35 launch_path: "/chrome/toolkit/webapps/tests/app.sjs?appreq",
36 };
38 let app = {
39 name: "test_desktop_hosted_launch_no_registry",
40 manifestURL: "http://127.0.0.1:8888/sample_no_registry.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 };
49 let profileDir;
50 let installPath;
51 let exePath;
52 let appProcess = Cc["@mozilla.org/process/util;1"].
53 createInstance(Ci.nsIProcess);
55 let cleanup;
57 if (LINUX) {
58 installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app));
59 exePath = OS.Path.join(installPath, "webapprt-stub");
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 }
68 let desktopINI = OS.Path.join(xdg_data_home, "applications",
69 "owa-" + WebappOSUtils.getUniqueName(app) + ".desktop");
71 cleanup = function() {
72 return Task.spawn(function*() {
73 if (appProcess.isRunning) {
74 appProcess.kill();
75 }
77 if (profileDir) {
78 yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
79 }
81 yield OS.File.removeDir(installPath, { ignoreAbsent: true });
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_no_registry.exe");
90 let desktopShortcut = OS.Path.join(OS.Constants.Path.desktopDir, "test_desktop_hosted_launch_no_registry.lnk");
91 let startMenuShortcut = OS.Path.join(OS.Constants.Path.winStartMenuProgsDir, "test_desktop_hosted_launch_no_registry.lnk");
93 cleanup = function() {
94 return Task.spawn(function*() {
95 if (appProcess.isRunning) {
96 appProcess.kill();
97 }
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 }
116 if (profileDir) {
117 yield OS.File.removeDir(profileDir.parent.parent.path, { ignoreAbsent: true });
118 }
120 yield OS.File.removeDir(installPath, { ignoreAbsent: true });
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_no_registry.app");
128 exePath = OS.Path.join(installPath, "Contents", "MacOS", "webapprt");
130 let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support",
131 WebappOSUtils.getUniqueName(app));
133 cleanup = function() {
134 return Task.spawn(function*() {
135 if (appProcess.isRunning) {
136 appProcess.kill();
137 }
139 if (profileDir) {
140 yield OS.File.removeDir(profileDir.parent.path, { ignoreAbsent: true });
141 }
143 yield OS.File.removeDir(installPath, { ignoreAbsent: true });
145 yield OS.File.removeDir(appProfileDir, { ignoreAbsent: true });
146 });
147 };
148 }
150 function wasAppSJSAccessed() {
151 let deferred = Promise.defer();
153 var xhr = new XMLHttpRequest();
155 xhr.addEventListener("load", function() {
156 let ret = (xhr.responseText == "done") ? true : false;
157 deferred.resolve(ret);
158 });
160 xhr.addEventListener("error", aError => deferred.reject(aError));
161 xhr.addEventListener("abort", aError => deferred.reject(aError));
163 xhr.open('GET', 'http://test/chrome/toolkit/webapps/tests/app.sjs?testreq', true);
164 xhr.send();
166 return deferred.promise;
167 }
169 let runTest = Task.async(function*() {
170 // Get to a clean state before the test
171 yield cleanup();
173 SimpleTest.registerCleanupFunction(cleanup);
175 setDryRunPref();
177 let nativeApp = new NativeApp(app, manifest, app.categories);
178 ok(nativeApp, "NativeApp object created");
180 profileDir = nativeApp.createProfile();
181 ok(profileDir && profileDir.exists(), "Profile directory created");
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 }
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");
198 let exeFile = getFile(exePath);
200 ok(exeFile.isExecutable(), "webapprt executable is executable");
202 let appClosed = false;
204 appProcess.init(exeFile)
205 appProcess.runAsync([], 0, () => appClosed = true);
207 while (!(yield wasAppSJSAccessed()) && !appClosed) {
208 yield wait(1000);
209 }
210 ok(!appClosed, "App was launched and is still running");
212 SimpleTest.finish();
213 });
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 }
227 ]]>
228 </script>
229 </window>