From cd222b8d9222f7b9fabd7b3e9ae99eb168e95f25 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Mon, 21 Apr 2014 10:16:02 -0400 Subject: [PATCH] Bug 993690 - Enable toolkit/webapps tests on Mac by installing apps in a directory that doesn't require admin privileges. r=myk --- toolkit/webapps/MacNativeApp.js | 15 ++++-- toolkit/webapps/tests/chrome.ini | 10 ++-- toolkit/webapps/tests/head.js | 22 ++++++++ toolkit/webapps/tests/test_hosted.xul | 53 ++++++++++--------- toolkit/webapps/tests/test_hosted_launch.xul | 53 ++++++++++--------- .../tests/test_hosted_launch_no_registry.xul | 53 ++++++++++--------- toolkit/webapps/tests/test_packaged.xul | 53 ++++++++++--------- .../webapps/tests/test_packaged_launch.xul | 53 ++++++++++--------- .../test_packaged_launch_no_registry.xul | 53 ++++++++++--------- 9 files changed, 205 insertions(+), 160 deletions(-) diff --git a/toolkit/webapps/MacNativeApp.js b/toolkit/webapps/MacNativeApp.js index dfb74005066..d6dde3423c6 100644 --- a/toolkit/webapps/MacNativeApp.js +++ b/toolkit/webapps/MacNativeApp.js @@ -30,6 +30,13 @@ function NativeApp(aApp, aManifest, aCategories, aRegistryDir) { NativeApp.prototype = { __proto__: CommonNativeApp.prototype, + /* + * The _rootInstallDir property is the path of the directory where we install + * apps. In production code, it's "/Applications". In tests, it's + * "~/Applications" because on build machines we don't have enough privileges + * to write to the global "/Applications" directory. + */ + _rootInstallDir: LOCAL_APP_DIR, /** * Creates a native installation of the web app in the OS @@ -50,16 +57,16 @@ NativeApp.prototype = { this._setData(aManifest); - let localAppDir = getFile(LOCAL_APP_DIR); + let localAppDir = getFile(this._rootInstallDir); if (!localAppDir.isWritable()) { throw("Not enough privileges to install apps"); } - - let destinationName = yield getAvailableFileName([ LOCAL_APP_DIR ], + + let destinationName = yield getAvailableFileName([ this._rootInstallDir ], this.appNameAsFilename, ".app"); - let installDir = OS.Path.join(LOCAL_APP_DIR, destinationName); + let installDir = OS.Path.join(this._rootInstallDir, destinationName); let dir = getFile(TMP_DIR, this.appNameAsFilename + ".app"); dir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY); diff --git a/toolkit/webapps/tests/chrome.ini b/toolkit/webapps/tests/chrome.ini index d90039870c1..e5547e96103 100644 --- a/toolkit/webapps/tests/chrome.ini +++ b/toolkit/webapps/tests/chrome.ini @@ -6,14 +6,12 @@ support-files = data/app/manifest.webapp [test_hosted.xul] -skip-if = os == "mac" [test_packaged.xul] -skip-if = os == "mac" [test_hosted_launch.xul] -skip-if = os == "mac" || asan +skip-if = asan [test_hosted_launch_no_registry.xul] -skip-if = os == "mac" || asan +skip-if = asan [test_packaged_launch.xul] -skip-if = os == "mac" || asan +skip-if = asan [test_packaged_launch_no_registry.xul] -skip-if = os == "mac" || asan +skip-if = asan diff --git a/toolkit/webapps/tests/head.js b/toolkit/webapps/tests/head.js index 5ff308f47a6..2ca323f546d 100644 --- a/toolkit/webapps/tests/head.js +++ b/toolkit/webapps/tests/head.js @@ -7,6 +7,11 @@ Cu.import("resource://gre/modules/osfile.jsm"); Cu.import("resource://gre/modules/Task.jsm"); Cu.import("resource://gre/modules/Promise.jsm"); +const LINUX = navigator.platform.startsWith("Linux"); +const MAC = navigator.platform.startsWith("Mac"); +const WIN = navigator.platform.startsWith("Win"); +const MAC_106 = navigator.userAgent.contains("Mac OS X 10.6"); + function checkFiles(files) { return Task.spawn(function*() { for (let file of files) { @@ -55,3 +60,20 @@ function getFile() { file.initWithPath(OS.Path.join.apply(OS.Path, arguments)); return file; } + +function setDryRunPref() { + let old_dry_run; + try { + old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run"); + } catch (ex) {} + + Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false); + + SimpleTest.registerCleanupFunction(function() { + if (old_dry_run === undefined) { + Services.prefs.clearUserPref("browser.mozApps.installer.dry_run"); + } else { + Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run); + } + }); +} diff --git a/toolkit/webapps/tests/test_hosted.xul b/toolkit/webapps/tests/test_hosted.xul index 1382e46a0ac..562bc83b398 100644 --- a/toolkit/webapps/tests/test_hosted.xul +++ b/toolkit/webapps/tests/test_hosted.xul @@ -54,7 +54,7 @@ let updatedFiles; let cleanup; -if (navigator.platform.startsWith("Linux")) { +if (LINUX) { installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app)); let xdg_data_home = Cc["@mozilla.org/process/environment;1"]. @@ -99,7 +99,7 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(desktopINI, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Win")) { +} else if (WIN) { installPath = OS.Path.join(OS.Constants.Path.winAppDataDir, WebappOSUtils.getUniqueName(app)); let desktopShortcut = OS.Path.join(OS.Constants.Path.desktopDir, "Sample hosted app.lnk"); @@ -165,8 +165,8 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(startMenuShortcut, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Mac")) { - installPath = OS.Path.join(OS.Constants.Path.macLocalApplicationsDir, "Sample hosted app.app"); +} else if (MAC) { + installPath = OS.Path.join(OS.Constants.Path.homeDir, "Applications", "Sample hosted app.app"); let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support", WebappOSUtils.getUniqueName(app)); @@ -205,27 +205,14 @@ if (navigator.platform.startsWith("Linux")) { }; } -let old_dry_run; -try { - old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run"); -} catch (ex) {} - -Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false); - -SimpleTest.registerCleanupFunction(function() { - if (old_dry_run === undefined) { - Services.prefs.clearUserPref("browser.mozApps.installer.dry_run"); - } else { - Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run); - } - - cleanup(); -}); - -Task.spawn(function() { +let runTest = Task.async(function*() { // Get to a clean state before the test yield cleanup(); + SimpleTest.registerCleanupFunction(cleanup); + + setDryRunPref(); + let nativeApp = new NativeApp(app, manifest, app.categories); ok(nativeApp, "NativeApp object created"); @@ -241,6 +228,13 @@ Task.spawn(function() { ok(profileDir && profileDir.exists(), "Profile directory created"); ok((yield OS.File.exists(profilesIni)), "profiles.ini file created"); + // On Mac build servers, we don't have enough privileges to write to /Applications, + // so we install apps in a user-owned directory. + if (MAC) { + nativeApp._rootInstallDir = OS.Path.join(OS.Constants.Path.homeDir, "Applications"); + yield OS.File.makeDir(nativeApp._rootInstallDir, { ignoreExisting: true }); + } + // Install application info("Test installation"); yield nativeApp.install(manifest); @@ -301,12 +295,21 @@ Task.spawn(function() { ok(!(yield OS.File.exists(OS.Path.join(installPath, "update"))), "Update directory removed"); ok((yield checkDateHigherThan(updatedFiles, installTime)), "Modification date higher"); - SimpleTest.finish(); -}).then(null, function(e) { - ok(false, "Error during test: " + e); SimpleTest.finish(); }); +// The test doesn't work yet on Mac OS X 10.6 machines. +// See bug 993690. +if (MAC_106) { + todo(false, "The test doesn't work on Mac OS X 10.6 machines"); + SimpleTest.finish(); +} else { + runTest().then(null, function(e) { + ok(false, "Error during test: " + e); + SimpleTest.finish(); + }); +} + ]]> diff --git a/toolkit/webapps/tests/test_hosted_launch.xul b/toolkit/webapps/tests/test_hosted_launch.xul index 65bb0cde895..3bd9ce08c0e 100644 --- a/toolkit/webapps/tests/test_hosted_launch.xul +++ b/toolkit/webapps/tests/test_hosted_launch.xul @@ -54,7 +54,7 @@ let appProcess = Cc["@mozilla.org/process/util;1"]. let cleanup; -if (navigator.platform.startsWith("Linux")) { +if (LINUX) { installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app)); exePath = OS.Path.join(installPath, "webapprt-stub"); @@ -83,7 +83,7 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(desktopINI, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Win")) { +} else if (WIN) { installPath = OS.Path.join(OS.Constants.Path.winAppDataDir, WebappOSUtils.getUniqueName(app)); exePath = OS.Path.join(installPath, "test_desktop_hosted_launch.exe"); @@ -123,8 +123,8 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(startMenuShortcut, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Mac")) { - installPath = OS.Path.join(OS.Constants.Path.macLocalApplicationsDir, "test_desktop_hosted_launch.app"); +} else if (MAC) { + installPath = OS.Path.join(OS.Constants.Path.homeDir, "Applications", "test_desktop_hosted_launch.app"); exePath = OS.Path.join(installPath, "Contents", "MacOS", "webapprt"); let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support", @@ -147,23 +147,6 @@ if (navigator.platform.startsWith("Linux")) { }; } -let old_dry_run; -try { - old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run"); -} catch (ex) {} - -Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false); - -SimpleTest.registerCleanupFunction(function() { - if (old_dry_run === undefined) { - Services.prefs.clearUserPref("browser.mozApps.installer.dry_run"); - } else { - Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run); - } - - cleanup(); -}); - function wasAppSJSAccessed() { let deferred = Promise.defer(); @@ -183,16 +166,27 @@ function wasAppSJSAccessed() { return deferred.promise; } -Task.spawn(function*() { +let runTest = Task.async(function*() { // Get to a clean state before the test yield cleanup(); + SimpleTest.registerCleanupFunction(cleanup); + + setDryRunPref(); + let nativeApp = new NativeApp(app, manifest, app.categories); ok(nativeApp, "NativeApp object created"); profileDir = nativeApp.createProfile(); ok(profileDir && profileDir.exists(), "Profile directory created"); + // On Mac build servers, we don't have enough privileges to write to /Applications, + // so we install apps in a user-owned directory. + if (MAC) { + nativeApp._rootInstallDir = OS.Path.join(OS.Constants.Path.homeDir, "Applications"); + yield OS.File.makeDir(nativeApp._rootInstallDir, { ignoreExisting: true }); + } + // Install application info("Test installation"); yield nativeApp.install(manifest); @@ -215,12 +209,21 @@ Task.spawn(function*() { } ok(!appClosed, "App was launched and is still running"); - SimpleTest.finish(); -}).then(null, function(e) { - ok(false, "Error during test: " + e); SimpleTest.finish(); }); +// The test doesn't work yet on Mac OS X 10.6 machines. +// See bug 993690. +if (MAC_106) { + todo(false, "The test doesn't work on Mac OS X 10.6 machines"); + SimpleTest.finish(); +} else { + runTest().then(null, function(e) { + ok(false, "Error during test: " + e); + SimpleTest.finish(); + }); +} + ]]> diff --git a/toolkit/webapps/tests/test_hosted_launch_no_registry.xul b/toolkit/webapps/tests/test_hosted_launch_no_registry.xul index c35dbd0aed3..0f55a5d0e48 100644 --- a/toolkit/webapps/tests/test_hosted_launch_no_registry.xul +++ b/toolkit/webapps/tests/test_hosted_launch_no_registry.xul @@ -54,7 +54,7 @@ let appProcess = Cc["@mozilla.org/process/util;1"]. let cleanup; -if (navigator.platform.startsWith("Linux")) { +if (LINUX) { installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app)); exePath = OS.Path.join(installPath, "webapprt-stub"); @@ -83,7 +83,7 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(desktopINI, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Win")) { +} else if (WIN) { installPath = OS.Path.join(OS.Constants.Path.winAppDataDir, WebappOSUtils.getUniqueName(app)); exePath = OS.Path.join(installPath, "test_desktop_hosted_launch_no_registry.exe"); @@ -123,8 +123,8 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(startMenuShortcut, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Mac")) { - installPath = OS.Path.join(OS.Constants.Path.macLocalApplicationsDir, "test_desktop_hosted_launch_no_registry.app"); +} else if (MAC) { + installPath = OS.Path.join(OS.Constants.Path.homeDir, "Applications", "test_desktop_hosted_launch_no_registry.app"); exePath = OS.Path.join(installPath, "Contents", "MacOS", "webapprt"); let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support", @@ -147,23 +147,6 @@ if (navigator.platform.startsWith("Linux")) { }; } -let old_dry_run; -try { - old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run"); -} catch (ex) {} - -Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false); - -SimpleTest.registerCleanupFunction(function() { - if (old_dry_run === undefined) { - Services.prefs.clearUserPref("browser.mozApps.installer.dry_run"); - } else { - Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run); - } - - cleanup(); -}); - function wasAppSJSAccessed() { let deferred = Promise.defer(); @@ -183,16 +166,27 @@ function wasAppSJSAccessed() { return deferred.promise; } -Task.spawn(function*() { +let runTest = Task.async(function*() { // Get to a clean state before the test yield cleanup(); + SimpleTest.registerCleanupFunction(cleanup); + + setDryRunPref(); + let nativeApp = new NativeApp(app, manifest, app.categories); ok(nativeApp, "NativeApp object created"); profileDir = nativeApp.createProfile(); ok(profileDir && profileDir.exists(), "Profile directory created"); + // On Mac build servers, we don't have enough privileges to write to /Applications, + // so we install apps in a user-owned directory. + if (MAC) { + nativeApp._rootInstallDir = OS.Path.join(OS.Constants.Path.homeDir, "Applications"); + yield OS.File.makeDir(nativeApp._rootInstallDir, { ignoreExisting: true }); + } + // Install application info("Test installation"); yield nativeApp.install(manifest); @@ -215,12 +209,21 @@ Task.spawn(function*() { } ok(!appClosed, "App was launched and is still running"); - SimpleTest.finish(); -}).then(null, function(e) { - ok(false, "Error during test: " + e); SimpleTest.finish(); }); +// The test doesn't work yet on Mac OS X 10.6 machines. +// See bug 993690. +if (MAC_106) { + todo(false, "The test doesn't work on Mac OS X 10.6 machines"); + SimpleTest.finish(); +} else { + runTest().then(null, function(e) { + ok(false, "Error during test: " + e); + SimpleTest.finish(); + }); +} + ]]> diff --git a/toolkit/webapps/tests/test_packaged.xul b/toolkit/webapps/tests/test_packaged.xul index bfa2cc72e20..189230a4ba9 100644 --- a/toolkit/webapps/tests/test_packaged.xul +++ b/toolkit/webapps/tests/test_packaged.xul @@ -60,7 +60,7 @@ let updatedFiles; let cleanup; -if (navigator.platform.startsWith("Linux")) { +if (LINUX) { installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app)); let xdg_data_home = Cc["@mozilla.org/process/environment;1"]. @@ -108,7 +108,7 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(desktopINI, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Win")) { +} else if (WIN) { installPath = OS.Path.join(OS.Constants.Path.winAppDataDir, WebappOSUtils.getUniqueName(app)); let desktopShortcut = OS.Path.join(OS.Constants.Path.desktopDir, "Sample packaged app.lnk"); @@ -177,8 +177,8 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(startMenuShortcut, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Mac")) { - installPath = OS.Path.join(OS.Constants.Path.macLocalApplicationsDir, "Sample packaged app.app"); +} else if (MAC) { + installPath = OS.Path.join(OS.Constants.Path.homeDir, "Applications", "Sample packaged app.app"); let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support", WebappOSUtils.getUniqueName(app)); @@ -220,27 +220,14 @@ if (navigator.platform.startsWith("Linux")) { }; } -let old_dry_run; -try { - old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run"); -} catch (ex) {} - -Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false); - -SimpleTest.registerCleanupFunction(function() { - if (old_dry_run === undefined) { - Services.prefs.clearUserPref("browser.mozApps.installer.dry_run"); - } else { - Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run); - } - - cleanup(); -}); - -Task.spawn(function() { +let runTest = Task.async(function*() { // Get to a clean state before the test yield cleanup(); + SimpleTest.registerCleanupFunction(cleanup); + + setDryRunPref(); + let zipFile = yield OS.File.open(zipPath, { create: true }); yield zipFile.close(); @@ -259,6 +246,13 @@ Task.spawn(function() { ok(profileDir && profileDir.exists(), "Profile directory created"); ok((yield OS.File.exists(profilesIni)), "profiles.ini file created"); + // On Mac build servers, we don't have enough privileges to write to /Applications, + // so we install apps in a user-owned directory. + if (MAC) { + nativeApp._rootInstallDir = OS.Path.join(OS.Constants.Path.homeDir, "Applications"); + yield OS.File.makeDir(nativeApp._rootInstallDir, { ignoreExisting: true }); + } + // Install application info("Test installation"); yield nativeApp.install(manifest, zipPath); @@ -327,12 +321,21 @@ Task.spawn(function() { ok(!(yield OS.File.exists(OS.Path.join(installPath, "update"))), "Update directory removed"); ok((yield checkDateHigherThan(updatedFiles, installTime)), "Modification date higher"); - SimpleTest.finish(); -}).then(null, function(e) { - ok(false, "Error during test: " + e); SimpleTest.finish(); }); +// The test doesn't work yet on Mac OS X 10.6 machines. +// See bug 993690. +if (MAC_106) { + todo(false, "The test doesn't work on Mac OS X 10.6 machines"); + SimpleTest.finish(); +} else { + runTest().then(null, function(e) { + ok(false, "Error during test: " + e); + SimpleTest.finish(); + }); +} + ]]> diff --git a/toolkit/webapps/tests/test_packaged_launch.xul b/toolkit/webapps/tests/test_packaged_launch.xul index bfa1fe956ef..3f06aa61f70 100644 --- a/toolkit/webapps/tests/test_packaged_launch.xul +++ b/toolkit/webapps/tests/test_packaged_launch.xul @@ -64,7 +64,7 @@ let appProcess = Cc["@mozilla.org/process/util;1"]. let cleanup; -if (navigator.platform.startsWith("Linux")) { +if (LINUX) { installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app)); exePath = OS.Path.join(installPath, "webapprt-stub"); @@ -93,7 +93,7 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(desktopINI, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Win")) { +} else if (WIN) { installPath = OS.Path.join(OS.Constants.Path.winAppDataDir, WebappOSUtils.getUniqueName(app)); exePath = OS.Path.join(installPath, "test_desktop_packaged_launch.exe"); @@ -133,8 +133,8 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(startMenuShortcut, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Mac")) { - installPath = OS.Path.join(OS.Constants.Path.macLocalApplicationsDir, "test_desktop_packaged_launch.app"); +} else if (MAC) { + installPath = OS.Path.join(OS.Constants.Path.homeDir, "Applications", "test_desktop_packaged_launch.app"); exePath = OS.Path.join(installPath, "Contents", "MacOS", "webapprt"); let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support", @@ -157,23 +157,6 @@ if (navigator.platform.startsWith("Linux")) { }; } -let old_dry_run; -try { - old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run"); -} catch (ex) {} - -Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false); - -SimpleTest.registerCleanupFunction(function() { - if (old_dry_run === undefined) { - Services.prefs.clearUserPref("browser.mozApps.installer.dry_run"); - } else { - Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run); - } - - cleanup(); -}); - function buildAppPackage() { let zipFile = getFile(OS.Constants.Path.profileDir, "sample.zip"); @@ -211,10 +194,14 @@ function wasAppSJSAccessed() { return deferred.promise; } -Task.spawn(function() { +let runTest = Task.async(function*() { // Get to a clean state before the test yield cleanup(); + SimpleTest.registerCleanupFunction(cleanup); + + setDryRunPref(); + let zipPath = buildAppPackage(); let nativeApp = new NativeApp(app, manifest, app.categories); @@ -223,6 +210,13 @@ Task.spawn(function() { profileDir = nativeApp.createProfile(); ok(profileDir && profileDir.exists(), "Profile directory created"); + // On Mac build servers, we don't have enough privileges to write to /Applications, + // so we install apps in a user-owned directory. + if (MAC) { + nativeApp._rootInstallDir = OS.Path.join(OS.Constants.Path.homeDir, "Applications"); + yield OS.File.makeDir(nativeApp._rootInstallDir, { ignoreExisting: true }); + } + // Install application info("Test installation"); yield nativeApp.install(manifest, zipPath); @@ -245,12 +239,21 @@ Task.spawn(function() { } ok(!appClosed, "App was launched and is still running"); - SimpleTest.finish(); -}).then(null, function(e) { - ok(false, "Error during test: " + e); SimpleTest.finish(); }); +// The test doesn't work yet on Mac OS X 10.6 machines. +// See bug 993690. +if (MAC_106) { + todo(false, "The test doesn't work on Mac OS X 10.6 machines"); + SimpleTest.finish(); +} else { + runTest().then(null, function(e) { + ok(false, "Error during test: " + e); + SimpleTest.finish(); + }); +} + ]]> diff --git a/toolkit/webapps/tests/test_packaged_launch_no_registry.xul b/toolkit/webapps/tests/test_packaged_launch_no_registry.xul index 7eaec638b48..04c7bc695fa 100644 --- a/toolkit/webapps/tests/test_packaged_launch_no_registry.xul +++ b/toolkit/webapps/tests/test_packaged_launch_no_registry.xul @@ -64,7 +64,7 @@ let appProcess = Cc["@mozilla.org/process/util;1"]. let cleanup; -if (navigator.platform.startsWith("Linux")) { +if (LINUX) { installPath = OS.Path.join(OS.Constants.Path.homeDir, "." + WebappOSUtils.getUniqueName(app)); exePath = OS.Path.join(installPath, "webapprt-stub"); @@ -93,7 +93,7 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(desktopINI, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Win")) { +} else if (WIN) { installPath = OS.Path.join(OS.Constants.Path.winAppDataDir, WebappOSUtils.getUniqueName(app)); exePath = OS.Path.join(installPath, "test_desktop_packaged_launch_no_registry.exe"); @@ -133,8 +133,8 @@ if (navigator.platform.startsWith("Linux")) { yield OS.File.remove(startMenuShortcut, { ignoreAbsent: true }); }); }; -} else if (navigator.platform.startsWith("Mac")) { - installPath = OS.Path.join(OS.Constants.Path.macLocalApplicationsDir, "test_desktop_packaged_launch_no_registry.app"); +} else if (MAC) { + installPath = OS.Path.join(OS.Constants.Path.homeDir, "Applications", "test_desktop_packaged_launch_no_registry.app"); exePath = OS.Path.join(installPath, "Contents", "MacOS", "webapprt"); let appProfileDir = OS.Path.join(OS.Constants.Path.macUserLibDir, "Application Support", @@ -157,23 +157,6 @@ if (navigator.platform.startsWith("Linux")) { }; } -let old_dry_run; -try { - old_dry_run = Services.prefs.getBoolPref("browser.mozApps.installer.dry_run"); -} catch (ex) {} - -Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", false); - -SimpleTest.registerCleanupFunction(function() { - if (old_dry_run === undefined) { - Services.prefs.clearUserPref("browser.mozApps.installer.dry_run"); - } else { - Services.prefs.setBoolPref("browser.mozApps.installer.dry_run", old_dry_run); - } - - cleanup(); -}); - function buildAppPackage() { let zipFile = getFile(OS.Constants.Path.profileDir, "sample.zip"); @@ -211,10 +194,14 @@ function wasAppSJSAccessed() { return deferred.promise; } -Task.spawn(function() { +let runTest = Task.async(function*() { // Get to a clean state before the test yield cleanup(); + SimpleTest.registerCleanupFunction(cleanup); + + setDryRunPref(); + let zipPath = buildAppPackage(); let nativeApp = new NativeApp(app, manifest, app.categories); @@ -223,6 +210,13 @@ Task.spawn(function() { profileDir = nativeApp.createProfile(); ok(profileDir && profileDir.exists(), "Profile directory created"); + // On Mac build servers, we don't have enough privileges to write to /Applications, + // so we install apps in a user-owned directory. + if (MAC) { + nativeApp._rootInstallDir = OS.Path.join(OS.Constants.Path.homeDir, "Applications"); + yield OS.File.makeDir(nativeApp._rootInstallDir, { ignoreExisting: true }); + } + // Install application info("Test installation"); yield nativeApp.install(manifest, zipPath); @@ -245,12 +239,21 @@ Task.spawn(function() { } ok(!appClosed, "App was launched and is still running"); - SimpleTest.finish(); -}).then(null, function(e) { - ok(false, "Error during test: " + e); SimpleTest.finish(); }); +// The test doesn't work yet on Mac OS X 10.6 machines. +// See bug 993690. +if (MAC_106) { + todo(false, "The test doesn't work on Mac OS X 10.6 machines"); + SimpleTest.finish(); +} else { + runTest().then(null, function(e) { + ok(false, "Error during test: " + e); + SimpleTest.finish(); + }); +} + ]]>