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