michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* Shared code for xpcshell and mochitests-chrome */ michael@0: michael@0: // const Cc, Ci, and Cr are defined in netwerk/test/httpserver/httpd.js so we michael@0: // need to define unique ones. michael@0: const AUS_Cc = Components.classes; michael@0: const AUS_Ci = Components.interfaces; michael@0: const AUS_Cr = Components.results; michael@0: const AUS_Cu = Components.utils; michael@0: const AUS_Cm = Components.manager; michael@0: michael@0: const PREF_APP_UPDATE_AUTO = "app.update.auto"; michael@0: const PREF_APP_UPDATE_BACKGROUNDERRORS = "app.update.backgroundErrors"; michael@0: const PREF_APP_UPDATE_BACKGROUNDMAXERRORS = "app.update.backgroundMaxErrors"; michael@0: const PREF_APP_UPDATE_CERTS_BRANCH = "app.update.certs."; michael@0: const PREF_APP_UPDATE_CERT_CHECKATTRS = "app.update.cert.checkAttributes"; michael@0: const PREF_APP_UPDATE_CERT_ERRORS = "app.update.cert.errors"; michael@0: const PREF_APP_UPDATE_CERT_MAXERRORS = "app.update.cert.maxErrors"; michael@0: const PREF_APP_UPDATE_CERT_REQUIREBUILTIN = "app.update.cert.requireBuiltIn"; michael@0: const PREF_APP_UPDATE_CHANNEL = "app.update.channel"; michael@0: const PREF_APP_UPDATE_ENABLED = "app.update.enabled"; michael@0: const PREF_APP_UPDATE_METRO_ENABLED = "app.update.metro.enabled"; michael@0: const PREF_APP_UPDATE_IDLETIME = "app.update.idletime"; michael@0: const PREF_APP_UPDATE_LOG = "app.update.log"; michael@0: const PREF_APP_UPDATE_NEVER_BRANCH = "app.update.never."; michael@0: const PREF_APP_UPDATE_NOTIFIEDUNSUPPORTED = "app.update.notifiedUnsupported"; michael@0: const PREF_APP_UPDATE_PROMPTWAITTIME = "app.update.promptWaitTime"; michael@0: const PREF_APP_UPDATE_SERVICE_ENABLED = "app.update.service.enabled"; michael@0: const PREF_APP_UPDATE_SHOW_INSTALLED_UI = "app.update.showInstalledUI"; michael@0: const PREF_APP_UPDATE_SILENT = "app.update.silent"; michael@0: const PREF_APP_UPDATE_STAGING_ENABLED = "app.update.staging.enabled"; michael@0: const PREF_APP_UPDATE_URL = "app.update.url"; michael@0: const PREF_APP_UPDATE_URL_DETAILS = "app.update.url.details"; michael@0: const PREF_APP_UPDATE_URL_OVERRIDE = "app.update.url.override"; michael@0: const PREF_APP_UPDATE_SOCKET_ERRORS = "app.update.socket.maxErrors"; michael@0: const PREF_APP_UPDATE_RETRY_TIMEOUT = "app.update.socket.retryTimeout"; michael@0: michael@0: const PREF_APP_UPDATE_CERT_INVALID_ATTR_NAME = PREF_APP_UPDATE_CERTS_BRANCH + michael@0: "1.invalidName"; michael@0: michael@0: const PREF_APP_PARTNER_BRANCH = "app.partner."; michael@0: const PREF_DISTRIBUTION_ID = "distribution.id"; michael@0: const PREF_DISTRIBUTION_VERSION = "distribution.version"; michael@0: michael@0: const PREF_EXTENSIONS_UPDATE_URL = "extensions.update.url"; michael@0: const PREF_EXTENSIONS_STRICT_COMPAT = "extensions.strictCompatibility"; michael@0: michael@0: const NS_APP_PROFILE_DIR_STARTUP = "ProfDS"; michael@0: const NS_APP_USER_PROFILE_50_DIR = "ProfD"; michael@0: const NS_GRE_DIR = "GreD"; michael@0: const NS_XPCOM_CURRENT_PROCESS_DIR = "XCurProcD"; michael@0: const XRE_EXECUTABLE_FILE = "XREExeF"; michael@0: const XRE_UPDATE_ROOT_DIR = "UpdRootD"; michael@0: michael@0: const CRC_ERROR = 4; michael@0: const WRITE_ERROR = 7; michael@0: michael@0: const DIR_PATCH = "0"; michael@0: const DIR_TOBEDELETED = "tobedeleted"; michael@0: const DIR_UPDATES = "updates"; michael@0: #ifdef XP_MACOSX michael@0: const DIR_BIN_REL_PATH = "Contents/MacOS/"; michael@0: const DIR_UPDATED = "Updated.app"; michael@0: #else michael@0: const DIR_BIN_REL_PATH = ""; michael@0: const DIR_UPDATED = "updated"; michael@0: #endif michael@0: michael@0: const FILE_BACKUP_LOG = "backup-update.log"; michael@0: const FILE_LAST_LOG = "last-update.log"; michael@0: const FILE_UPDATER_INI = "updater.ini"; michael@0: const FILE_UPDATES_DB = "updates.xml"; michael@0: const FILE_UPDATE_ACTIVE = "active-update.xml"; michael@0: const FILE_UPDATE_ARCHIVE = "update.mar"; michael@0: const FILE_UPDATE_LOG = "update.log"; michael@0: const FILE_UPDATE_SETTINGS_INI = "update-settings.ini"; michael@0: const FILE_UPDATE_SETTINGS_INI_BAK = "update-settings.ini.bak"; michael@0: const FILE_UPDATE_STATUS = "update.status"; michael@0: const FILE_UPDATE_VERSION = "update.version"; michael@0: michael@0: const UPDATE_SETTINGS_CONTENTS = "[Settings]\n" + michael@0: "ACCEPTED_MAR_CHANNEL_IDS=xpcshell-test\n" michael@0: michael@0: const PR_RDWR = 0x04; michael@0: const PR_CREATE_FILE = 0x08; michael@0: const PR_APPEND = 0x10; michael@0: const PR_TRUNCATE = 0x20; michael@0: const PR_SYNC = 0x40; michael@0: const PR_EXCL = 0x80; michael@0: michael@0: const DEFAULT_UPDATE_VERSION = "999999.0"; michael@0: michael@0: var gChannel; michael@0: michael@0: #include sharedUpdateXML.js michael@0: michael@0: AUS_Cu.import("resource://gre/modules/FileUtils.jsm"); michael@0: AUS_Cu.import("resource://gre/modules/Services.jsm"); michael@0: AUS_Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: const PERMS_FILE = FileUtils.PERMS_FILE; michael@0: const PERMS_DIRECTORY = FileUtils.PERMS_DIRECTORY; michael@0: michael@0: const MODE_RDONLY = FileUtils.MODE_RDONLY; michael@0: const MODE_WRONLY = FileUtils.MODE_WRONLY; michael@0: const MODE_RDWR = FileUtils.MODE_RDWR; michael@0: const MODE_CREATE = FileUtils.MODE_CREATE; michael@0: const MODE_APPEND = FileUtils.MODE_APPEND; michael@0: const MODE_TRUNCATE = FileUtils.MODE_TRUNCATE; michael@0: michael@0: const URI_UPDATES_PROPERTIES = "chrome://mozapps/locale/update/updates.properties"; michael@0: const gUpdateBundle = Services.strings.createBundle(URI_UPDATES_PROPERTIES); michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "gAUS", function test_gAUS() { michael@0: return AUS_Cc["@mozilla.org/updates/update-service;1"]. michael@0: getService(AUS_Ci.nsIApplicationUpdateService). michael@0: QueryInterface(AUS_Ci.nsITimerCallback). michael@0: QueryInterface(AUS_Ci.nsIObserver). michael@0: QueryInterface(AUS_Ci.nsIUpdateCheckListener); michael@0: }); michael@0: michael@0: XPCOMUtils.defineLazyServiceGetter(this, "gUpdateManager", michael@0: "@mozilla.org/updates/update-manager;1", michael@0: "nsIUpdateManager"); michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "gUpdateChecker", function test_gUC() { michael@0: return AUS_Cc["@mozilla.org/updates/update-checker;1"]. michael@0: createInstance(AUS_Ci.nsIUpdateChecker); michael@0: }); michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "gUP", function test_gUP() { michael@0: return AUS_Cc["@mozilla.org/updates/update-prompt;1"]. michael@0: createInstance(AUS_Ci.nsIUpdatePrompt); michael@0: }); michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "gDefaultPrefBranch", function test_gDPB() { michael@0: return Services.prefs.getDefaultBranch(null); michael@0: }); michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "gPrefRoot", function test_gPR() { michael@0: return Services.prefs.getBranch(null); michael@0: }); michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "gZipW", function test_gZipW() { michael@0: return AUS_Cc["@mozilla.org/zipwriter;1"]. michael@0: createInstance(AUS_Ci.nsIZipWriter); michael@0: }); michael@0: michael@0: /* Initializes the update service stub */ michael@0: function initUpdateServiceStub() { michael@0: AUS_Cc["@mozilla.org/updates/update-service-stub;1"]. michael@0: createInstance(AUS_Ci.nsISupports); michael@0: } michael@0: michael@0: /* Reloads the update metadata from disk */ michael@0: function reloadUpdateManagerData() { michael@0: gUpdateManager.QueryInterface(AUS_Ci.nsIObserver). michael@0: observe(null, "um-reload-update-data", ""); michael@0: } michael@0: michael@0: /** michael@0: * Sets the app.update.channel preference. michael@0: * michael@0: * @param aChannel michael@0: * The update channel. michael@0: */ michael@0: function setUpdateChannel(aChannel) { michael@0: gChannel = aChannel; michael@0: debugDump("setting default pref " + PREF_APP_UPDATE_CHANNEL + " to " + gChannel); michael@0: gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_CHANNEL, gChannel); michael@0: gPrefRoot.addObserver(PREF_APP_UPDATE_CHANNEL, observer, false); michael@0: } michael@0: michael@0: var observer = { michael@0: observe: function(aSubject, aTopic, aData) { michael@0: if (aTopic == "nsPref:changed" && aData == PREF_APP_UPDATE_CHANNEL) { michael@0: var channel = gDefaultPrefBranch.getCharPref(PREF_APP_UPDATE_CHANNEL); michael@0: if (channel != gChannel) { michael@0: debugDump("Changing channel from " + channel + " to " + gChannel); michael@0: gDefaultPrefBranch.setCharPref(PREF_APP_UPDATE_CHANNEL, gChannel); michael@0: } michael@0: } michael@0: }, michael@0: QueryInterface: XPCOMUtils.generateQI([AUS_Ci.nsIObserver]) michael@0: }; michael@0: michael@0: /** michael@0: * Sets the app.update.url.override preference. michael@0: * michael@0: * @param aURL michael@0: * The update url. If not specified 'URL_HOST + "/update.xml"' will be michael@0: * used. michael@0: */ michael@0: function setUpdateURLOverride(aURL) { michael@0: let url = aURL ? aURL : URL_HOST + "/update.xml"; michael@0: debugDump("setting " + PREF_APP_UPDATE_URL_OVERRIDE + " to " + url); michael@0: Services.prefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url); michael@0: } michael@0: michael@0: /** michael@0: * Returns either the active or regular update database XML file. michael@0: * michael@0: * @param isActiveUpdate michael@0: * If true this will return the active-update.xml otherwise it will michael@0: * return the updates.xml file. michael@0: */ michael@0: function getUpdatesXMLFile(aIsActiveUpdate) { michael@0: var file = getUpdatesRootDir(); michael@0: file.append(aIsActiveUpdate ? FILE_UPDATE_ACTIVE : FILE_UPDATES_DB); michael@0: return file; michael@0: } michael@0: michael@0: /** michael@0: * Writes the updates specified to either the active-update.xml or the michael@0: * updates.xml. michael@0: * michael@0: * @param aContent michael@0: * The updates represented as a string to write to the XML file. michael@0: * @param isActiveUpdate michael@0: * If true this will write to the active-update.xml otherwise it will michael@0: * write to the updates.xml file. michael@0: */ michael@0: function writeUpdatesToXMLFile(aContent, aIsActiveUpdate) { michael@0: writeFile(getUpdatesXMLFile(aIsActiveUpdate), aContent); michael@0: } michael@0: michael@0: /** michael@0: * Writes the current update operation/state to a file in the patch michael@0: * directory, indicating to the patching system that operations need michael@0: * to be performed. michael@0: * michael@0: * @param aStatus michael@0: * The status value to write. michael@0: */ michael@0: function writeStatusFile(aStatus) { michael@0: let file = getUpdatesPatchDir(); michael@0: file.append(FILE_UPDATE_STATUS); michael@0: writeFile(file, aStatus + "\n"); michael@0: } michael@0: michael@0: /** michael@0: * Writes the current update version to a file in the patch directory, michael@0: * indicating to the patching system the version of the update. michael@0: * michael@0: * @param aVersion michael@0: * The version value to write. michael@0: */ michael@0: function writeVersionFile(aVersion) { michael@0: let file = getUpdatesPatchDir(); michael@0: file.append(FILE_UPDATE_VERSION); michael@0: writeFile(file, aVersion + "\n"); michael@0: } michael@0: michael@0: /** michael@0: * Gets the root directory for the updates directory. michael@0: * michael@0: * @return nsIFile for the updates root directory. michael@0: */ michael@0: function getUpdatesRootDir() { michael@0: return Services.dirsvc.get(XRE_UPDATE_ROOT_DIR, AUS_Ci.nsIFile); michael@0: } michael@0: michael@0: /** michael@0: * Gets the updates directory. michael@0: * michael@0: * @return nsIFile for the updates directory. michael@0: */ michael@0: function getUpdatesDir() { michael@0: var dir = getUpdatesRootDir(); michael@0: dir.append(DIR_UPDATES); michael@0: return dir; michael@0: } michael@0: michael@0: /** michael@0: * Gets the directory for update patches. michael@0: * michael@0: * @return nsIFile for the updates directory. michael@0: */ michael@0: function getUpdatesPatchDir() { michael@0: let dir = getUpdatesDir(); michael@0: dir.append(DIR_PATCH); michael@0: return dir; michael@0: } michael@0: michael@0: /** michael@0: * Writes text to a file. This will replace existing text if the file exists michael@0: * and create the file if it doesn't exist. michael@0: * michael@0: * @param aFile michael@0: * The file to write to. Will be created if it doesn't exist. michael@0: * @param aText michael@0: * The text to write to the file. If there is existing text it will be michael@0: * replaced. michael@0: */ michael@0: function writeFile(aFile, aText) { michael@0: var fos = AUS_Cc["@mozilla.org/network/file-output-stream;1"]. michael@0: createInstance(AUS_Ci.nsIFileOutputStream); michael@0: if (!aFile.exists()) michael@0: aFile.create(AUS_Ci.nsILocalFile.NORMAL_FILE_TYPE, PERMS_FILE); michael@0: fos.init(aFile, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, PERMS_FILE, 0); michael@0: fos.write(aText, aText.length); michael@0: fos.close(); michael@0: } michael@0: michael@0: /** michael@0: * Reads the current update operation/state in the status file in the patch michael@0: * directory including the error code if it is present. michael@0: * michael@0: * @return The status value. michael@0: */ michael@0: function readStatusFile() { michael@0: let file = getUpdatesPatchDir(); michael@0: file.append(FILE_UPDATE_STATUS); michael@0: michael@0: if (!file.exists()) { michael@0: logTestInfo("update status file does not exists! Path: " + file.path); michael@0: return STATE_NONE; michael@0: } michael@0: michael@0: return readFile(file).split("\n")[0]; michael@0: } michael@0: michael@0: /** michael@0: * Reads the current update operation/state in the status file in the patch michael@0: * directory without the error code if it is present. michael@0: * michael@0: * @return The state value. michael@0: */ michael@0: function readStatusState() { michael@0: return readStatusFile().split(": ")[0]; michael@0: } michael@0: michael@0: /** michael@0: * Reads the current update operation/state in the status file in the patch michael@0: * directory with the error code. michael@0: * michael@0: * @return The state value. michael@0: */ michael@0: function readStatusFailedCode() { michael@0: return readStatusFile().split(": ")[1]; michael@0: } michael@0: michael@0: /** michael@0: * Reads text from a file and returns the string. michael@0: * michael@0: * @param aFile michael@0: * The file to read from. michael@0: * @return The string of text read from the file. michael@0: */ michael@0: function readFile(aFile) { michael@0: var fis = AUS_Cc["@mozilla.org/network/file-input-stream;1"]. michael@0: createInstance(AUS_Ci.nsIFileInputStream); michael@0: if (!aFile.exists()) michael@0: return null; michael@0: fis.init(aFile, MODE_RDONLY, PERMS_FILE, 0); michael@0: var sis = AUS_Cc["@mozilla.org/scriptableinputstream;1"]. michael@0: createInstance(AUS_Ci.nsIScriptableInputStream); michael@0: sis.init(fis); michael@0: var text = sis.read(sis.available()); michael@0: sis.close(); michael@0: return text; michael@0: } michael@0: michael@0: /** michael@0: * Reads the binary contents of a file and returns it as a string. michael@0: * michael@0: * @param aFile michael@0: * The file to read from. michael@0: * @return The contents of the file as a string. michael@0: */ michael@0: function readFileBytes(aFile) { michael@0: var fis = AUS_Cc["@mozilla.org/network/file-input-stream;1"]. michael@0: createInstance(AUS_Ci.nsIFileInputStream); michael@0: fis.init(aFile, -1, -1, false); michael@0: var bis = AUS_Cc["@mozilla.org/binaryinputstream;1"]. michael@0: createInstance(AUS_Ci.nsIBinaryInputStream); michael@0: bis.setInputStream(fis); michael@0: var data = []; michael@0: var count = fis.available(); michael@0: while (count > 0) { michael@0: var bytes = bis.readByteArray(Math.min(65535, count)); michael@0: data.push(String.fromCharCode.apply(null, bytes)); michael@0: count -= bytes.length; michael@0: if (bytes.length == 0) michael@0: throw "Nothing read from input stream!"; michael@0: } michael@0: data.join(''); michael@0: fis.close(); michael@0: return data.toString(); michael@0: } michael@0: michael@0: /* Returns human readable status text from the updates.properties bundle */ michael@0: function getStatusText(aErrCode) { michael@0: return getString("check_error-" + aErrCode); michael@0: } michael@0: michael@0: /* Returns a string from the updates.properties bundle */ michael@0: function getString(aName) { michael@0: try { michael@0: return gUpdateBundle.GetStringFromName(aName); michael@0: } catch (e) { michael@0: } michael@0: return null; michael@0: } michael@0: michael@0: /** michael@0: * Gets the file extension for an nsIFile. michael@0: * michael@0: * @param aFile michael@0: * The file to get the file extension for. michael@0: * @return The file extension. michael@0: */ michael@0: function getFileExtension(aFile) { michael@0: return Services.io.newFileURI(aFile).QueryInterface(AUS_Ci.nsIURL). michael@0: fileExtension; michael@0: } michael@0: michael@0: /** michael@0: * Removes the updates.xml file, active-update.xml file, and all files and michael@0: * sub-directories in the updates directory except for the "0" sub-directory. michael@0: * This prevents some tests from failing due to files being left behind when the michael@0: * tests are interrupted. michael@0: */ michael@0: function removeUpdateDirsAndFiles() { michael@0: var file = getUpdatesXMLFile(true); michael@0: try { michael@0: if (file.exists()) michael@0: file.remove(false); michael@0: } catch (e) { michael@0: dump("Unable to remove file\nPath: " + file.path + michael@0: "\nException: " + e + "\n"); michael@0: } michael@0: michael@0: file = getUpdatesXMLFile(false); michael@0: try { michael@0: if (file.exists()) michael@0: file.remove(false); michael@0: } catch (e) { michael@0: dump("Unable to remove file\nPath: " + file.path + michael@0: "\nException: " + e + "\n"); michael@0: } michael@0: michael@0: // This fails sporadically on Mac OS X so wrap it in a try catch michael@0: var updatesDir = getUpdatesDir(); michael@0: try { michael@0: cleanUpdatesDir(updatesDir); michael@0: } catch (e) { michael@0: dump("Unable to remove files / directories from directory\nPath: " + michael@0: updatesDir.path + "\nException: " + e + "\n"); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Removes all files and sub-directories in the updates directory except for michael@0: * the "0" sub-directory. michael@0: * michael@0: * @param aDir michael@0: * nsIFile for the directory to be deleted. michael@0: */ michael@0: function cleanUpdatesDir(aDir) { michael@0: if (!aDir.exists()) michael@0: return; michael@0: michael@0: var dirEntries = aDir.directoryEntries; michael@0: while (dirEntries.hasMoreElements()) { michael@0: var entry = dirEntries.getNext().QueryInterface(AUS_Ci.nsIFile); michael@0: michael@0: if (entry.isDirectory()) { michael@0: if (entry.leafName == DIR_PATCH && entry.parent.leafName == DIR_UPDATES) { michael@0: cleanUpdatesDir(entry); michael@0: entry.permissions = PERMS_DIRECTORY; michael@0: } else { michael@0: try { michael@0: entry.remove(true); michael@0: return; michael@0: } catch (e) { michael@0: } michael@0: cleanUpdatesDir(entry); michael@0: entry.permissions = PERMS_DIRECTORY; michael@0: try { michael@0: entry.remove(true); michael@0: } catch (e) { michael@0: dump("cleanUpdatesDir: unable to remove directory\nPath: " + michael@0: entry.path + "\nException: " + e + "\n"); michael@0: throw(e); michael@0: } michael@0: } michael@0: } else { michael@0: entry.permissions = PERMS_FILE; michael@0: try { michael@0: entry.remove(false); michael@0: } catch (e) { michael@0: dump("cleanUpdatesDir: unable to remove file\nPath: " + entry.path + michael@0: "\nException: " + e + "\n"); michael@0: throw(e); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Deletes a directory and its children. First it tries nsIFile::Remove(true). michael@0: * If that fails it will fall back to recursing, setting the appropriate michael@0: * permissions, and deleting the current entry. michael@0: * michael@0: * @param aDir michael@0: * nsIFile for the directory to be deleted. michael@0: */ michael@0: function removeDirRecursive(aDir) { michael@0: if (!aDir.exists()) { michael@0: return; michael@0: } michael@0: michael@0: try { michael@0: logTestInfo("attempting to remove directory. Path: " + aDir.path); michael@0: aDir.remove(true); michael@0: return; michael@0: } catch (e) { michael@0: logTestInfo("non-fatal error removing directory. Exception: " + e); michael@0: } michael@0: michael@0: var dirEntries = aDir.directoryEntries; michael@0: while (dirEntries.hasMoreElements()) { michael@0: var entry = dirEntries.getNext().QueryInterface(AUS_Ci.nsIFile); michael@0: michael@0: if (entry.isDirectory()) { michael@0: removeDirRecursive(entry); michael@0: } else { michael@0: entry.permissions = PERMS_FILE; michael@0: try { michael@0: logTestInfo("attempting to remove file. Path: " + entry.path); michael@0: entry.remove(false); michael@0: } catch (e) { michael@0: logTestInfo("error removing file. Exception: " + e); michael@0: throw(e); michael@0: } michael@0: } michael@0: } michael@0: michael@0: aDir.permissions = PERMS_DIRECTORY; michael@0: try { michael@0: logTestInfo("attempting to remove directory. Path: " + aDir.path); michael@0: aDir.remove(true); michael@0: } catch (e) { michael@0: logTestInfo("error removing directory. Exception: " + e); michael@0: throw(e); michael@0: } michael@0: } michael@0: michael@0: /** michael@0: * Returns the directory for the currently running process. This is used to michael@0: * clean up after the tests and to locate the active-update.xml and updates.xml michael@0: * files. michael@0: * michael@0: * @return nsIFile for the current process directory. michael@0: */ michael@0: function getCurrentProcessDir() { michael@0: return Services.dirsvc.get(NS_XPCOM_CURRENT_PROCESS_DIR, AUS_Ci.nsIFile); michael@0: } michael@0: michael@0: /** michael@0: * Gets the application base directory. michael@0: * michael@0: * @return nsIFile object for the application base directory. michael@0: */ michael@0: function getAppBaseDir() { michael@0: return Services.dirsvc.get(XRE_EXECUTABLE_FILE, AUS_Ci.nsIFile).parent; michael@0: } michael@0: michael@0: /** michael@0: * Returns the Gecko Runtime Engine directory. This is used to locate the the michael@0: * updater binary (Windows and Linux) or updater package (Mac OS X). For michael@0: * XULRunner applications this is different than the currently running process michael@0: * directory. michael@0: * michael@0: * @return nsIFile for the Gecko Runtime Engine directory. michael@0: */ michael@0: function getGREDir() { michael@0: return Services.dirsvc.get(NS_GRE_DIR, AUS_Ci.nsIFile); michael@0: } michael@0: michael@0: /** michael@0: * Get the "updated" directory inside the directory where we apply the michael@0: * staged updates. michael@0: * @return The active updates directory inside the updated directory, as a michael@0: * nsIFile object. michael@0: */ michael@0: function getUpdatedDir() { michael@0: let dir = getAppBaseDir(); michael@0: #ifdef XP_MACOSX michael@0: dir = dir.parent.parent; // the bundle directory michael@0: #endif michael@0: dir.append(DIR_UPDATED); michael@0: logTestInfo("updated directory path: " + dir.path); michael@0: return dir; michael@0: } michael@0: michael@0: /** michael@0: * Logs TEST-INFO messages. michael@0: * michael@0: * @param aText michael@0: * The text to log. michael@0: * @param aCaller (optional) michael@0: * An optional Components.stack.caller. If not specified michael@0: * Components.stack.caller will be used. michael@0: */ michael@0: function logTestInfo(aText, aCaller) { michael@0: let caller = (aCaller ? aCaller : Components.stack.caller); michael@0: let now = new Date; michael@0: let hh = now.getHours(); michael@0: let mm = now.getMinutes(); michael@0: let ss = now.getSeconds(); michael@0: let ms = now.getMilliseconds(); michael@0: let time = (hh < 10 ? "0" + hh : hh) + ":" + michael@0: (mm < 10 ? "0" + mm : mm) + ":" + michael@0: (ss < 10 ? "0" + ss : ss) + ":" + michael@0: (ms < 10 ? "00" + ms : ms < 100 ? "0" + ms : ms); michael@0: dump(time + " | TEST-INFO | " + caller.filename + " | [" + caller.name + michael@0: " : " + caller.lineNumber + "] " + aText + "\n"); michael@0: } michael@0: michael@0: /** michael@0: * Logs TEST-INFO messages when DEBUG_AUS_TEST evaluates to true. michael@0: * michael@0: * @param aText michael@0: * The text to log. michael@0: * @param aCaller (optional) michael@0: * An optional Components.stack.caller. If not specified michael@0: * Components.stack.caller will be used. michael@0: */ michael@0: function debugDump(aText, aCaller) { michael@0: if (DEBUG_AUS_TEST) { michael@0: let caller = aCaller ? aCaller : Components.stack.caller; michael@0: logTestInfo(aText, caller); michael@0: } michael@0: }