toolkit/webapps/tests/test_packaged.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial