toolkit/webapps/tests/test_hosted.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial