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

mercurial