diff options
author | Matt A. Tobin <email@mattatobin.com> | 2015-11-27 17:37:36 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2015-11-27 17:37:36 -0500 |
commit | e31519c43c049b43545c9dfeb23dd5d0d7b335b0 (patch) | |
tree | 3d9f7ba7989a203d3eeb0940a8738b05a3033606 /toolkit | |
parent | 239ea997ffa1b514ab8448243679f7dc4d8c9547 (diff) | |
download | palemoon-gre-e31519c43c049b43545c9dfeb23dd5d0d7b335b0.tar.gz |
[Issue #178] Part 1 - Kill the maintenance service with fire! - Quick Burn
Diffstat (limited to 'toolkit')
62 files changed, 0 insertions, 12545 deletions
diff --git a/toolkit/components/maintenanceservice/Makefile.in b/toolkit/components/maintenanceservice/Makefile.in deleted file mode 100644 index ecf833171..000000000 --- a/toolkit/components/maintenanceservice/Makefile.in +++ /dev/null @@ -1,57 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -# For debugging purposes only -#DEFINES += -DDISABLE_UPDATER_AUTHENTICODE_CHECK - -DIST_PROGRAM = maintenanceservice$(BIN_SUFFIX) - -# Don't link the maintenanceservice against mozglue.dll. See bug 687139 and -# bug 725876 -MOZ_GLUE_LDFLAGS = -MOZ_GLUE_PROGRAM_LDFLAGS = - -LIBS += \ - ../../mozapps/update/common/$(LIB_PREFIX)updatecommon.$(LIB_SUFFIX) \ - $(NULL) - -USE_STATIC_LIBS = 1 -HAVE_PROGRESSUI = 1 -RCINCLUDE = maintenanceservice.rc - -OS_LIBS += $(call EXPAND_LIBNAME,comctl32 ws2_32 shell32) -DEFINES += -DUNICODE -D_UNICODE -ifndef GNU_CC -RCFLAGS += -I$(srcdir) -else -RCFLAGS += --include-dir $(srcdir) -endif - -ifndef MOZ_WINCONSOLE -ifdef MOZ_DEBUG -MOZ_WINCONSOLE = 1 -else -MOZ_WINCONSOLE = 0 -endif -endif - -include $(topsrcdir)/config/rules.mk - -DEFINES += -DNS_NO_XPCOM - -ifdef _MSC_VER -WIN32_EXE_LDFLAGS += -ENTRY:wmainCRTStartup -endif - -# Pick up nsWindowsRestart.cpp -LOCAL_INCLUDES += -I$(topsrcdir)/toolkit/xre \ - -I$(topsrcdir)/toolkit/mozapps/update/common \ - $(NULL) diff --git a/toolkit/components/maintenanceservice/bootstrapinstaller/maintenanceservice_installer.nsi b/toolkit/components/maintenanceservice/bootstrapinstaller/maintenanceservice_installer.nsi deleted file mode 100644 index 6371b1b69..000000000 --- a/toolkit/components/maintenanceservice/bootstrapinstaller/maintenanceservice_installer.nsi +++ /dev/null @@ -1,258 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -; Set verbosity to 3 (e.g. no script) to lessen the noise in the build logs -!verbose 3 - -; 7-Zip provides better compression than the lzma from NSIS so we add the files -; uncompressed and use 7-Zip to create a SFX archive of it -SetDatablockOptimize on -SetCompress off -CRCCheck on - -RequestExecutionLevel admin -!addplugindir ./ - -; Variables -Var TempMaintServiceName -Var BrandFullNameDA -Var BrandFullName - -; Other included files may depend upon these includes! -; The following includes are provided by NSIS. -!include FileFunc.nsh -!include LogicLib.nsh -!include MUI.nsh -!include WinMessages.nsh -!include WinVer.nsh -!include WordFunc.nsh - -!insertmacro GetOptions -!insertmacro GetParameters -!insertmacro GetSize - -; The test slaves use this fallback key to run tests. -; And anyone that wants to run tests themselves should already have -; this installed. -!define FallbackKey \ - "SOFTWARE\Mozilla\MaintenanceService\3932ecacee736d366d6436db0f55bce4" - -!define CompanyName "Mozilla Corporation" -!define BrandFullNameInternal "" - -; The following includes are custom. -!include defines.nsi -; We keep defines.nsi defined so that we get other things like -; the version number, but we redefine BrandFullName -!define MaintFullName "Mozilla Maintenance Service" -!undef BrandFullName -!define BrandFullName "${MaintFullName}" - -!include common.nsh -!include locales.nsi - -VIAddVersionKey "FileDescription" "${MaintFullName} Installer" -VIAddVersionKey "OriginalFilename" "maintenanceservice_installer.exe" - -Name "${MaintFullName}" -OutFile "maintenanceservice_installer.exe" - -; Get installation folder from registry if available -InstallDirRegKey HKLM "Software\Mozilla\MaintenanceService" "" - -SetOverwrite on - -!define MaintUninstallKey \ - "Software\Microsoft\Windows\CurrentVersion\Uninstall\MozillaMaintenanceService" - -; The HAVE_64BIT_OS define also means that we have an x64 build, -; not just an x64 OS. -!ifdef HAVE_64BIT_OS - ; See below, we actually abort the install for x64 builds currently. - InstallDir "$PROGRAMFILES64\${MaintFullName}\" -!else - InstallDir "$PROGRAMFILES32\${MaintFullName}\" -!endif -ShowUnInstDetails nevershow - -################################################################################ -# Modern User Interface - MUI - -!define MUI_ICON setup.ico -!define MUI_UNICON setup.ico -!define MUI_WELCOMEPAGE_TITLE_3LINES -!define MUI_UNWELCOMEFINISHPAGE_BITMAP wizWatermark.bmp - -;Interface Settings -!define MUI_ABORTWARNING - -; Uninstaller Pages -!insertmacro MUI_UNPAGE_CONFIRM -!insertmacro MUI_UNPAGE_INSTFILES - -################################################################################ -# Language - -!insertmacro MOZ_MUI_LANGUAGE 'baseLocale' -!verbose push -!verbose 3 -!include "overrideLocale.nsh" -!include "customLocale.nsh" -!verbose pop - -; Set this after the locale files to override it if it is in the locale -; using " " for BrandingText will hide the "Nullsoft Install System..." branding -BrandingText " " - -Function .onInit - SetSilent silent -!ifdef HAVE_64BIT_OS - ; We plan to eventually enable 64bit native builds to use the maintenance - ; service, but for the initial release, to reduce testing and development, - ; 64-bit builds will not install the maintenanceservice. - Abort -!endif - - ; On Windows 2000 we do not install the maintenance service. - ; We won't run this installer from the parent installer, but just in case - ; someone tries to execute it on Windows 2000... - ${Unless} ${AtLeastWinXP} - Abort - ${EndUnless} -FunctionEnd - -Function un.onInit - StrCpy $BrandFullNameDA "${MaintFullName}" - StrCpy $BrandFullName "${MaintFullName}" -FunctionEnd - -Section "MaintenanceService" - AllowSkipFiles off - - CreateDirectory $INSTDIR - SetOutPath $INSTDIR - - ; If the service already exists, then it will be stopped when upgrading it - ; via the maintenanceservice_tmp.exe command executed below. - ; The maintenanceservice_tmp.exe command will rename the file to - ; maintenanceservice.exe if maintenanceservice_tmp.exe is newer. - ; If the service does not exist yet, we install it and drop the file on - ; disk as maintenanceservice.exe directly. - StrCpy $TempMaintServiceName "maintenanceservice.exe" - IfFileExists "$INSTDIR\maintenanceservice.exe" 0 skipAlreadyExists - StrCpy $TempMaintServiceName "maintenanceservice_tmp.exe" - skipAlreadyExists: - - ; We always write out a copy and then decide whether to install it or - ; not via calling its 'install' cmdline which works by version comparison. - CopyFiles "$EXEDIR\maintenanceservice.exe" "$INSTDIR\$TempMaintServiceName" - - ; The updater.ini file is only used when performing an install or upgrade, - ; and only if that install or upgrade is successful. If an old updater.ini - ; happened to be copied into the maintenance service installation directory - ; but the service was not newer, the updater.ini file would be unused. - ; It is used to fill the description of the service on success. - CopyFiles "$EXEDIR\updater.ini" "$INSTDIR\updater.ini" - - ; Install the application maintenance service. - ; If a service already exists, the command line parameter will stop the - ; service and only install itself if it is newer than the already installed - ; service. If successful it will remove the old maintenanceservice.exe - ; and replace it with maintenanceservice_tmp.exe. - ClearErrors - ;${GetParameters} $0 - ;${GetOptions} "$0" "/Upgrade" $0 - ;${If} ${Errors} - nsExec::Exec '"$INSTDIR\$TempMaintServiceName" forceinstall' - ;${Else} - ; The upgrade cmdline is the same as install except - ; It will fail if the service isn't already installed. - ; nsExec::Exec '"$INSTDIR\$TempMaintServiceName" upgrade' - ;${EndIf} - - WriteUninstaller "$INSTDIR\Uninstall.exe" - WriteRegStr HKLM "${MaintUninstallKey}" "DisplayName" "${MaintFullName}" - WriteRegStr HKLM "${MaintUninstallKey}" "UninstallString" \ - '"$INSTDIR\uninstall.exe"' - WriteRegStr HKLM "${MaintUninstallKey}" "DisplayIcon" \ - "$INSTDIR\Uninstall.exe,0" - WriteRegStr HKLM "${MaintUninstallKey}" "DisplayVersion" "${AppVersion}" - WriteRegStr HKLM "${MaintUninstallKey}" "Publisher" "Mozilla" - WriteRegStr HKLM "${MaintUninstallKey}" "Comments" \ - "${BrandFullName} ${AppVersion} (${ARCH} ${AB_CD})" - WriteRegDWORD HKLM "${MaintUninstallKey}" "NoModify" 1 - ${GetSize} "$INSTDIR" "/S=0K" $R2 $R3 $R4 - WriteRegDWORD HKLM "${MaintUninstallKey}" "EstimatedSize" $R2 - - ; Write out that a maintenance service was attempted. - ; We do this because on upgrades we will check this value and we only - ; want to install once on the first upgrade to maintenance service. - ; Also write out that we are currently installed, preferences will check - ; this value to determine if we should show the service update pref. - ; Since the Maintenance service can be installed either x86 or x64, - ; always use the 64-bit registry for checking if an attempt was made. - ${If} ${RunningX64} - SetRegView 64 - ${EndIf} - WriteRegDWORD HKLM "Software\Mozilla\MaintenanceService" "Attempted" 1 - WriteRegDWORD HKLM "Software\Mozilla\MaintenanceService" "Installed" 1 - - ; Included here for debug purposes only. - ; These keys are used to bypass the installation dir is a valid installation - ; check from the service so that tests can be run. - WriteRegStr HKLM "${FallbackKey}\0" "name" "Mozilla Corporation" - WriteRegStr HKLM "${FallbackKey}\0" "issuer" "DigiCert Assured ID Code Signing CA-1" - WriteRegStr HKLM "${FallbackKey}\1" "name" "Mozilla Fake SPC" - WriteRegStr HKLM "${FallbackKey}\1" "issuer" "Mozilla Fake CA" - ${If} ${RunningX64} - SetRegView lastused - ${EndIf} -SectionEnd - -; By renaming before deleting we improve things slightly in case -; there is a file in use error. In this case a new install can happen. -Function un.RenameDelete - Pop $9 - ; If the .moz-delete file already exists previously, delete it - ; If it doesn't exist, the call is ignored. - ; We don't need to pass /REBOOTOK here since it was already marked that way - ; if it exists. - Delete "$9.moz-delete" - Rename "$9" "$9.moz-delete" - ${If} ${Errors} - Delete /REBOOTOK "$9" - ${Else} - Delete /REBOOTOK "$9.moz-delete" - ${EndIf} - ClearErrors -FunctionEnd - -Section "Uninstall" - ; Delete the service so that no updates will be attempted - nsExec::Exec '"$INSTDIR\maintenanceservice.exe" uninstall' - - Push "$INSTDIR\updater.ini" - Call un.RenameDelete - Push "$INSTDIR\maintenanceservice.exe" - Call un.RenameDelete - Push "$INSTDIR\maintenanceservice_tmp.exe" - Call un.RenameDelete - Push "$INSTDIR\maintenanceservice.old" - Call un.RenameDelete - Push "$INSTDIR\Uninstall.exe" - Call un.RenameDelete - RMDir /REBOOTOK "$INSTDIR" - - DeleteRegKey HKLM "${MaintUninstallKey}" - - ${If} ${RunningX64} - SetRegView 64 - ${EndIf} - DeleteRegValue HKLM "Software\Mozilla\MaintenanceService" "Installed" - DeleteRegKey HKLM "${FallbackKey}\" - ${If} ${RunningX64} - SetRegView lastused - ${EndIf} -SectionEnd - diff --git a/toolkit/components/maintenanceservice/certificatecheck.cpp b/toolkit/components/maintenanceservice/certificatecheck.cpp deleted file mode 100644 index 1d9f5e4d7..000000000 --- a/toolkit/components/maintenanceservice/certificatecheck.cpp +++ /dev/null @@ -1,270 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include <stdio.h> -#include <stdlib.h> -#include <windows.h> -#include <softpub.h> -#include <wintrust.h> - -#include "certificatecheck.h" -#include "servicebase.h" - -#pragma comment(lib, "wintrust.lib") -#pragma comment(lib, "crypt32.lib") - -static const int ENCODING = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING; - -/** - * Checks to see if a file stored at filePath matches the specified info. - * - * @param filePath The PE file path to check - * @param infoToMatch The acceptable information to match - * @return ERROR_SUCCESS if successful, ERROR_NOT_FOUND if the info - * does not match, or the last error otherwise. - */ -DWORD -CheckCertificateForPEFile(LPCWSTR filePath, - CertificateCheckInfo &infoToMatch) -{ - HCERTSTORE certStore = NULL; - HCRYPTMSG cryptMsg = NULL; - PCCERT_CONTEXT certContext = NULL; - PCMSG_SIGNER_INFO signerInfo = NULL; - DWORD lastError = ERROR_SUCCESS; - - // Get the HCERTSTORE and HCRYPTMSG from the signed file. - DWORD encoding, contentType, formatType; - BOOL result = CryptQueryObject(CERT_QUERY_OBJECT_FILE, - filePath, - CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED, - CERT_QUERY_CONTENT_FLAG_ALL, - 0, &encoding, &contentType, - &formatType, &certStore, &cryptMsg, NULL); - if (!result) { - lastError = GetLastError(); - LOG_WARN(("CryptQueryObject failed. (%d)", lastError)); - goto cleanup; - } - - // Pass in NULL to get the needed signer information size. - DWORD signerInfoSize; - result = CryptMsgGetParam(cryptMsg, CMSG_SIGNER_INFO_PARAM, 0, - NULL, &signerInfoSize); - if (!result) { - lastError = GetLastError(); - LOG_WARN(("CryptMsgGetParam failed. (%d)", lastError)); - goto cleanup; - } - - // Allocate the needed size for the signer information. - signerInfo = (PCMSG_SIGNER_INFO)LocalAlloc(LPTR, signerInfoSize); - if (!signerInfo) { - lastError = GetLastError(); - LOG_WARN(("Unable to allocate memory for Signer Info. (%d)", lastError)); - goto cleanup; - } - - // Get the signer information (PCMSG_SIGNER_INFO). - // In particular we want the issuer and serial number. - result = CryptMsgGetParam(cryptMsg, CMSG_SIGNER_INFO_PARAM, 0, - (PVOID)signerInfo, &signerInfoSize); - if (!result) { - lastError = GetLastError(); - LOG_WARN(("CryptMsgGetParam failed. (%d)", lastError)); - goto cleanup; - } - - // Search for the signer certificate in the certificate store. - CERT_INFO certInfo; - certInfo.Issuer = signerInfo->Issuer; - certInfo.SerialNumber = signerInfo->SerialNumber; - certContext = CertFindCertificateInStore(certStore, ENCODING, 0, - CERT_FIND_SUBJECT_CERT, - (PVOID)&certInfo, NULL); - if (!certContext) { - lastError = GetLastError(); - LOG_WARN(("CertFindCertificateInStore failed. (%d)", lastError)); - goto cleanup; - } - - if (!DoCertificateAttributesMatch(certContext, infoToMatch)) { - lastError = ERROR_NOT_FOUND; - LOG_WARN(("Certificate did not match issuer or name. (%d)", lastError)); - goto cleanup; - } - -cleanup: - if (signerInfo) { - LocalFree(signerInfo); - } - if (certContext) { - CertFreeCertificateContext(certContext); - } - if (certStore) { - CertCloseStore(certStore, 0); - } - if (cryptMsg) { - CryptMsgClose(cryptMsg); - } - return lastError; -} - -/** - * Checks to see if a file stored at filePath matches the specified info. - * - * @param certContext The certificate context of the file - * @param infoToMatch The acceptable information to match - * @return FALSE if the info does not match or if any error occurs in the check - */ -BOOL -DoCertificateAttributesMatch(PCCERT_CONTEXT certContext, - CertificateCheckInfo &infoToMatch) -{ - DWORD dwData; - LPTSTR szName = NULL; - - if (infoToMatch.issuer) { - // Pass in NULL to get the needed size of the issuer buffer. - dwData = CertGetNameString(certContext, - CERT_NAME_SIMPLE_DISPLAY_TYPE, - CERT_NAME_ISSUER_FLAG, NULL, - NULL, 0); - - if (!dwData) { - LOG_WARN(("CertGetNameString failed. (%d)", GetLastError())); - return FALSE; - } - - // Allocate memory for Issuer name buffer. - LPTSTR szName = (LPTSTR)LocalAlloc(LPTR, dwData * sizeof(WCHAR)); - if (!szName) { - LOG_WARN(("Unable to allocate memory for issuer name. (%d)", - GetLastError())); - return FALSE; - } - - // Get Issuer name. - if (!CertGetNameString(certContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, - CERT_NAME_ISSUER_FLAG, NULL, szName, dwData)) { - LOG_WARN(("CertGetNameString failed. (%d)", GetLastError())); - LocalFree(szName); - return FALSE; - } - - // If the issuer does not match, return a failure. - if (!infoToMatch.issuer || - wcscmp(szName, infoToMatch.issuer)) { - LocalFree(szName); - return FALSE; - } - - LocalFree(szName); - szName = NULL; - } - - if (infoToMatch.name) { - // Pass in NULL to get the needed size of the name buffer. - dwData = CertGetNameString(certContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, - 0, NULL, NULL, 0); - if (!dwData) { - LOG_WARN(("CertGetNameString failed. (%d)", GetLastError())); - return FALSE; - } - - // Allocate memory for the name buffer. - szName = (LPTSTR)LocalAlloc(LPTR, dwData * sizeof(WCHAR)); - if (!szName) { - LOG_WARN(("Unable to allocate memory for subject name. (%d)", - GetLastError())); - return FALSE; - } - - // Obtain the name. - if (!(CertGetNameString(certContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, - NULL, szName, dwData))) { - LOG_WARN(("CertGetNameString failed. (%d)", GetLastError())); - LocalFree(szName); - return FALSE; - } - - // If the issuer does not match, return a failure. - if (!infoToMatch.name || - wcscmp(szName, infoToMatch.name)) { - LocalFree(szName); - return FALSE; - } - - // We have a match! - LocalFree(szName); - } - - // If there were any errors we would have aborted by now. - return TRUE; -} - -/** - * Duplicates the specified string - * - * @param inputString The string to duplicate - * @return The duplicated string which should be freed by the caller. - */ -LPWSTR -AllocateAndCopyWideString(LPCWSTR inputString) -{ - LPWSTR outputString = - (LPWSTR)LocalAlloc(LPTR, (wcslen(inputString) + 1) * sizeof(WCHAR)); - if (outputString) { - lstrcpyW(outputString, inputString); - } - return outputString; -} - -/** - * Verifies the trust of the specified file path. - * - * @param filePath The file path to check. - * @return ERROR_SUCCESS if successful, or the last error code otherwise. - */ -DWORD -VerifyCertificateTrustForFile(LPCWSTR filePath) -{ - // Setup the file to check. - WINTRUST_FILE_INFO fileToCheck; - ZeroMemory(&fileToCheck, sizeof(fileToCheck)); - fileToCheck.cbStruct = sizeof(WINTRUST_FILE_INFO); - fileToCheck.pcwszFilePath = filePath; - - // Setup what to check, we want to check it is signed and trusted. - WINTRUST_DATA trustData; - ZeroMemory(&trustData, sizeof(trustData)); - trustData.cbStruct = sizeof(trustData); - trustData.pPolicyCallbackData = NULL; - trustData.pSIPClientData = NULL; - trustData.dwUIChoice = WTD_UI_NONE; - trustData.fdwRevocationChecks = WTD_REVOKE_NONE; - trustData.dwUnionChoice = WTD_CHOICE_FILE; - trustData.dwStateAction = 0; - trustData.hWVTStateData = NULL; - trustData.pwszURLReference = NULL; - // no UI - trustData.dwUIContext = 0; - trustData.pFile = &fileToCheck; - - GUID policyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2; - // Check if the file is signed by something that is trusted. - LONG ret = WinVerifyTrust(NULL, &policyGUID, &trustData); - if (ERROR_SUCCESS == ret) { - // The hash that represents the subject is trusted and there were no - // verification errors. No publisher nor time stamp chain errors. - LOG(("The file \"%ls\" is signed and the signature was verified.", - filePath)); - return ERROR_SUCCESS; - } - - DWORD lastError = GetLastError(); - LOG_WARN(("There was an error validating trust of the certificate for file" - " \"%ls\". Returned: %d. (%d)", filePath, ret, lastError)); - return ret; -} diff --git a/toolkit/components/maintenanceservice/certificatecheck.h b/toolkit/components/maintenanceservice/certificatecheck.h deleted file mode 100644 index 43a7c85b6..000000000 --- a/toolkit/components/maintenanceservice/certificatecheck.h +++ /dev/null @@ -1,22 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef _CERTIFICATECHECK_H_ -#define _CERTIFICATECHECK_H_ - -#include <wincrypt.h> - -struct CertificateCheckInfo -{ - LPCWSTR name; - LPCWSTR issuer; -}; - -BOOL DoCertificateAttributesMatch(PCCERT_CONTEXT pCertContext, - CertificateCheckInfo &infoToMatch); -DWORD VerifyCertificateTrustForFile(LPCWSTR filePath); -DWORD CheckCertificateForPEFile(LPCWSTR filePath, - CertificateCheckInfo &infoToMatch); - -#endif diff --git a/toolkit/components/maintenanceservice/maintenanceservice.cpp b/toolkit/components/maintenanceservice/maintenanceservice.cpp deleted file mode 100644 index f929e11ee..000000000 --- a/toolkit/components/maintenanceservice/maintenanceservice.cpp +++ /dev/null @@ -1,386 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include <windows.h> -#include <shlwapi.h> -#include <stdio.h> -#include <wchar.h> -#include <shlobj.h> - -#include "serviceinstall.h" -#include "maintenanceservice.h" -#include "servicebase.h" -#include "workmonitor.h" -#include "uachelper.h" -#include "updatehelper.h" - -SERVICE_STATUS gSvcStatus = { 0 }; -SERVICE_STATUS_HANDLE gSvcStatusHandle = NULL; -HANDLE gWorkDoneEvent = NULL; -HANDLE gThread = NULL; -bool gServiceControlStopping = false; - -// logs are pretty small, about 20 lines, so 10 seems reasonable. -#define LOGS_TO_KEEP 10 - -BOOL GetLogDirectoryPath(WCHAR *path); - -int -wmain(int argc, WCHAR **argv) -{ - // If command-line parameter is "install", install the service - // or upgrade if already installed - // If command line parameter is "forceinstall", install the service - // even if it is older than what is already installed. - // If command-line parameter is "upgrade", upgrade the service - // but do not install it if it is not already installed. - // If command line parameter is "uninstall", uninstall the service. - // Otherwise, the service is probably being started by the SCM. - bool forceInstall = !lstrcmpi(argv[1], L"forceinstall"); - if (!lstrcmpi(argv[1], L"install") || forceInstall) { - WCHAR updatePath[MAX_PATH + 1]; - if (GetLogDirectoryPath(updatePath)) { - LogInit(updatePath, L"maintenanceservice-install.log"); - } - - SvcInstallAction action = InstallSvc; - if (forceInstall) { - action = ForceInstallSvc; - LOG(("Installing service with force specified...")); - } else { - LOG(("Installing service...")); - } - - bool ret = SvcInstall(action); - if (!ret) { - LOG_WARN(("Could not install service. (%d)", GetLastError())); - LogFinish(); - return 1; - } - - LOG(("The service was installed successfully")); - LogFinish(); - return 0; - } - - if (!lstrcmpi(argv[1], L"upgrade")) { - WCHAR updatePath[MAX_PATH + 1]; - if (GetLogDirectoryPath(updatePath)) { - LogInit(updatePath, L"maintenanceservice-install.log"); - } - - LOG(("Upgrading service if installed...")); - if (!SvcInstall(UpgradeSvc)) { - LOG_WARN(("Could not upgrade service. (%d)", GetLastError())); - LogFinish(); - return 1; - } - - LOG(("The service was upgraded successfully")); - LogFinish(); - return 0; - } - - if (!lstrcmpi(argv[1], L"uninstall")) { - WCHAR updatePath[MAX_PATH + 1]; - if (GetLogDirectoryPath(updatePath)) { - LogInit(updatePath, L"maintenanceservice-uninstall.log"); - } - LOG(("Uninstalling service...")); - if (!SvcUninstall()) { - LOG_WARN(("Could not uninstall service. (%d)", GetLastError())); - LogFinish(); - return 1; - } - LOG(("The service was uninstalled successfully")); - LogFinish(); - return 0; - } - - SERVICE_TABLE_ENTRYW DispatchTable[] = { - { SVC_NAME, (LPSERVICE_MAIN_FUNCTIONW) SvcMain }, - { NULL, NULL } - }; - - // This call returns when the service has stopped. - // The process should simply terminate when the call returns. - if (!StartServiceCtrlDispatcherW(DispatchTable)) { - LOG_WARN(("StartServiceCtrlDispatcher failed. (%d)", GetLastError())); - } - - return 0; -} - -/** - * Obtains the base path where logs should be stored - * - * @param path The out buffer for the backup log path of size MAX_PATH + 1 - * @return TRUE if successful. - */ -BOOL -GetLogDirectoryPath(WCHAR *path) -{ - HRESULT hr = SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, - SHGFP_TYPE_CURRENT, path); - if (FAILED(hr)) { - return FALSE; - } - - if (!PathAppendSafe(path, L"Mozilla")) { - return FALSE; - } - // The directory should already be created from the installer, but - // just to be safe in case someone deletes. - CreateDirectoryW(path, NULL); - - if (!PathAppendSafe(path, L"logs")) { - return FALSE; - } - CreateDirectoryW(path, NULL); - return TRUE; -} - -/** - * Calculated a backup path based on the log number. - * - * @param path The out buffer to store the log path of size MAX_PATH + 1 - * @param basePath The base directory where the calculated path should go - * @param logNumber The log number, 0 == updater.log - * @return TRUE if successful. - */ -BOOL -GetBackupLogPath(LPWSTR path, LPCWSTR basePath, int logNumber) -{ - WCHAR logName[64] = { L'\0' }; - wcsncpy(path, basePath, sizeof(logName) / sizeof(logName[0]) - 1); - if (logNumber <= 0) { - swprintf(logName, sizeof(logName) / sizeof(logName[0]), - L"maintenanceservice.log"); - } else { - swprintf(logName, sizeof(logName) / sizeof(logName[0]), - L"maintenanceservice-%d.log", logNumber); - } - return PathAppendSafe(path, logName); -} - -/** - * Moves the old log files out of the way before a new one is written. - * If you for example keep 3 logs, then this function will do: - * updater2.log -> updater3.log - * updater1.log -> updater2.log - * updater.log -> updater1.log - * Which clears room for a new updater.log in the basePath directory - * - * @param basePath The base directory path where log files are stored - * @param numLogsToKeep The number of logs to keep - */ -void -BackupOldLogs(LPCWSTR basePath, int numLogsToKeep) -{ - WCHAR oldPath[MAX_PATH + 1]; - WCHAR newPath[MAX_PATH + 1]; - for (int i = numLogsToKeep; i >= 1; i--) { - if (!GetBackupLogPath(oldPath, basePath, i -1)) { - continue; - } - - if (!GetBackupLogPath(newPath, basePath, i)) { - continue; - } - - if (!MoveFileExW(oldPath, newPath, MOVEFILE_REPLACE_EXISTING)) { - continue; - } - } -} - -/** - * Ensures the service is shutdown once all work is complete. - * There is an issue on XP SP2 and below where the service can hang - * in a stop pending state even though the SCM is notified of a stopped - * state. Control *should* be returned to StartServiceCtrlDispatcher from the - * call to SetServiceStatus on a stopped state in the wmain thread. - * Sometimes this is not the case though. This thread will terminate the process - * if it has been 5 seconds after all work is done and the process is still not - * terminated. This thread is only started once a stopped state was sent to the - * SCM. The stop pending hang can be reproduced intermittently even if you set - * a stopped state dirctly and never set a stop pending state. It is safe to - * forcefully terminate the process ourselves since all work is done once we - * start this thread. -*/ -DWORD WINAPI -EnsureProcessTerminatedThread(LPVOID) -{ - Sleep(5000); - exit(0); - return 0; -} - -void -StartTerminationThread() -{ - // If the process does not self terminate like it should, this thread - // will terminate the process after 5 seconds. - HANDLE thread = CreateThread(NULL, 0, EnsureProcessTerminatedThread, - NULL, 0, NULL); - if (thread) { - CloseHandle(thread); - } -} - -/** - * Main entry point when running as a service. - */ -void WINAPI -SvcMain(DWORD argc, LPWSTR *argv) -{ - // Setup logging, and backup the old logs - WCHAR updatePath[MAX_PATH + 1]; - if (GetLogDirectoryPath(updatePath)) { - BackupOldLogs(updatePath, LOGS_TO_KEEP); - LogInit(updatePath, L"maintenanceservice.log"); - } - - // Disable every privilege we don't need. Processes started using - // CreateProcess will use the same token as this process. - UACHelper::DisablePrivileges(NULL); - - // Register the handler function for the service - gSvcStatusHandle = RegisterServiceCtrlHandlerW(SVC_NAME, SvcCtrlHandler); - if (!gSvcStatusHandle) { - LOG_WARN(("RegisterServiceCtrlHandler failed. (%d)", GetLastError())); - ExecuteServiceCommand(argc, argv); - LogFinish(); - exit(1); - } - - // These values will be re-used later in calls involving gSvcStatus - gSvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; - gSvcStatus.dwServiceSpecificExitCode = 0; - - // Report initial status to the SCM - ReportSvcStatus(SERVICE_START_PENDING, NO_ERROR, 3000); - - // This event will be used to tell the SvcCtrlHandler when the work is - // done for when a stop comamnd is manually issued. - gWorkDoneEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - if (!gWorkDoneEvent) { - ReportSvcStatus(SERVICE_STOPPED, 1, 0); - StartTerminationThread(); - return; - } - - // Initialization complete and we're about to start working on - // the actual command. Report the service state as running to the SCM. - ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0); - - // The service command was executed, stop logging and set an event - // to indicate the work is done in case someone is waiting on a - // service stop operation. - ExecuteServiceCommand(argc, argv); - LogFinish(); - - SetEvent(gWorkDoneEvent); - - // If we aren't already in a stopping state then tell the SCM we're stopped - // now. If we are already in a stopping state then the SERVICE_STOPPED state - // will be set by the SvcCtrlHandler. - if (!gServiceControlStopping) { - ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0); - StartTerminationThread(); - } -} - -/** - * Sets the current service status and reports it to the SCM. - * - * @param currentState The current state (see SERVICE_STATUS) - * @param exitCode The system error code - * @param waitHint Estimated time for pending operation in milliseconds - */ -void -ReportSvcStatus(DWORD currentState, - DWORD exitCode, - DWORD waitHint) -{ - static DWORD dwCheckPoint = 1; - - gSvcStatus.dwCurrentState = currentState; - gSvcStatus.dwWin32ExitCode = exitCode; - gSvcStatus.dwWaitHint = waitHint; - - if (SERVICE_START_PENDING == currentState || - SERVICE_STOP_PENDING == currentState) { - gSvcStatus.dwControlsAccepted = 0; - } else { - gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | - SERVICE_ACCEPT_SHUTDOWN; - } - - if ((SERVICE_RUNNING == currentState) || - (SERVICE_STOPPED == currentState)) { - gSvcStatus.dwCheckPoint = 0; - } else { - gSvcStatus.dwCheckPoint = dwCheckPoint++; - } - - // Report the status of the service to the SCM. - SetServiceStatus(gSvcStatusHandle, &gSvcStatus); -} - -/** - * Since the SvcCtrlHandler should only spend at most 30 seconds before - * returning, this function does the service stop work for the SvcCtrlHandler. -*/ -DWORD WINAPI -StopServiceAndWaitForCommandThread(LPVOID) -{ - do { - ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 1000); - } while(WaitForSingleObject(gWorkDoneEvent, 100) == WAIT_TIMEOUT); - CloseHandle(gWorkDoneEvent); - gWorkDoneEvent = NULL; - ReportSvcStatus(SERVICE_STOPPED, NO_ERROR, 0); - StartTerminationThread(); - return 0; -} - -/** - * Called by SCM whenever a control code is sent to the service - * using the ControlService function. - */ -void WINAPI -SvcCtrlHandler(DWORD dwCtrl) -{ - // After a SERVICE_CONTROL_STOP there should be no more commands sent to - // the SvcCtrlHandler. - if (gServiceControlStopping) { - return; - } - - // Handle the requested control code. - switch(dwCtrl) { - case SERVICE_CONTROL_SHUTDOWN: - case SERVICE_CONTROL_STOP: { - gServiceControlStopping = true; - ReportSvcStatus(SERVICE_STOP_PENDING, NO_ERROR, 1000); - - // The SvcCtrlHandler thread should not spend more than 30 seconds in - // shutdown so we spawn a new thread for stopping the service - HANDLE thread = CreateThread(NULL, 0, StopServiceAndWaitForCommandThread, - NULL, 0, NULL); - if (thread) { - CloseHandle(thread); - } else { - // Couldn't start the thread so just call the stop ourselves. - // If it happens to take longer than 30 seconds the caller will - // get an error. - StopServiceAndWaitForCommandThread(NULL); - } - } - break; - default: - break; - } -} diff --git a/toolkit/components/maintenanceservice/maintenanceservice.exe.manifest b/toolkit/components/maintenanceservice/maintenanceservice.exe.manifest deleted file mode 100644 index dae842b76..000000000 --- a/toolkit/components/maintenanceservice/maintenanceservice.exe.manifest +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes"?> -<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> -<assemblyIdentity - version="1.0.0.0" - processorArchitecture="*" - name="MaintenanceService" - type="win32" -/> -<description>MaintenanceService</description> -<ms_asmv3:trustInfo xmlns:ms_asmv3="urn:schemas-microsoft-com:asm.v3"> - <ms_asmv3:security> - <ms_asmv3:requestedPrivileges> - <ms_asmv3:requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> - </ms_asmv3:requestedPrivileges> - </ms_asmv3:security> -</ms_asmv3:trustInfo> - <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> - <application> - <!-- Windows 10 --> - <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/> - <!-- Windows 8.1 --> - <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/> - <!-- Windows 8 --> - <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/> - <!-- Windows 7 --> - <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> - <!-- Windows Vista --> - <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> - </application> - </compatibility> -</assembly> diff --git a/toolkit/components/maintenanceservice/maintenanceservice.h b/toolkit/components/maintenanceservice/maintenanceservice.h deleted file mode 100644 index 9e02914a0..000000000 --- a/toolkit/components/maintenanceservice/maintenanceservice.h +++ /dev/null @@ -1,10 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -void WINAPI SvcMain(DWORD dwArgc, LPWSTR *lpszArgv); -void SvcInit(DWORD dwArgc, LPWSTR *lpszArgv); -void WINAPI SvcCtrlHandler(DWORD dwCtrl); -void ReportSvcStatus(DWORD dwCurrentState, - DWORD dwWin32ExitCode, - DWORD dwWaitHint); diff --git a/toolkit/components/maintenanceservice/maintenanceservice.rc b/toolkit/components/maintenanceservice/maintenanceservice.rc deleted file mode 100644 index ddd3e942b..000000000 --- a/toolkit/components/maintenanceservice/maintenanceservice.rc +++ /dev/null @@ -1,86 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "winresrc.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// RT_MANIFEST -// - -1 RT_MANIFEST "maintenanceservice.exe.manifest" - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN -END -#endif // APSTUDIO_INVOKED - - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""winresrc.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/toolkit/components/maintenanceservice/moz.build b/toolkit/components/maintenanceservice/moz.build deleted file mode 100644 index 3ad1fd8a6..000000000 --- a/toolkit/components/maintenanceservice/moz.build +++ /dev/null @@ -1,16 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -PROGRAM = 'maintenanceservice' - -CPP_SOURCES += [ - 'certificatecheck.cpp', - 'maintenanceservice.cpp', - 'registrycertificates.cpp', - 'servicebase.cpp', - 'serviceinstall.cpp', - 'workmonitor.cpp', -] diff --git a/toolkit/components/maintenanceservice/registrycertificates.cpp b/toolkit/components/maintenanceservice/registrycertificates.cpp deleted file mode 100644 index 006b3ae71..000000000 --- a/toolkit/components/maintenanceservice/registrycertificates.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include <stdio.h> -#include <stdlib.h> -#include <windows.h> - -#include "registrycertificates.h" -#include "pathhash.h" -#include "nsWindowsHelpers.h" -#include "servicebase.h" -#include "updatehelper.h" -#define MAX_KEY_LENGTH 255 - -/** - * Verifies if the file path matches any certificate stored in the registry. - * - * @param filePath The file path of the application to check if allowed. - * @return TRUE if the binary matches any of the allowed certificates. - */ -BOOL -DoesBinaryMatchAllowedCertificates(LPCWSTR basePathForUpdate, LPCWSTR filePath) -{ - WCHAR maintenanceServiceKey[MAX_PATH + 1]; - if (!CalculateRegistryPathFromFilePath(basePathForUpdate, - maintenanceServiceKey)) { - return FALSE; - } - - // We use KEY_WOW64_64KEY to always force 64-bit view. - // The user may have both x86 and x64 applications installed - // which each register information. We need a consistent place - // to put those certificate attributes in and hence why we always - // force the non redirected registry under Wow6432Node. - // This flag is ignored on 32bit systems. - HKEY baseKeyRaw; - LONG retCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE, - maintenanceServiceKey, 0, - KEY_READ | KEY_WOW64_64KEY, &baseKeyRaw); - if (retCode != ERROR_SUCCESS) { - LOG_WARN(("Could not open key. (%d)", retCode)); - // Our tests run with a different apply directory for each test. - // We use this registry key on our test slaves to store the - // allowed name/issuers. - retCode = RegOpenKeyExW(HKEY_LOCAL_MACHINE, - TEST_ONLY_FALLBACK_KEY_PATH, 0, - KEY_READ | KEY_WOW64_64KEY, &baseKeyRaw); - if (retCode != ERROR_SUCCESS) { - LOG_WARN(("Could not open fallback key. (%d)", retCode)); - return FALSE; - } - } - nsAutoRegKey baseKey(baseKeyRaw); - - // Get the number of subkeys. - DWORD subkeyCount = 0; - retCode = RegQueryInfoKeyW(baseKey, NULL, NULL, NULL, &subkeyCount, NULL, - NULL, NULL, NULL, NULL, NULL, NULL); - if (retCode != ERROR_SUCCESS) { - LOG_WARN(("Could not query info key. (%d)", retCode)); - return FALSE; - } - - // Enumerate the subkeys, each subkey represents an allowed certificate. - for (DWORD i = 0; i < subkeyCount; i++) { - WCHAR subkeyBuffer[MAX_KEY_LENGTH]; - DWORD subkeyBufferCount = MAX_KEY_LENGTH; - retCode = RegEnumKeyExW(baseKey, i, subkeyBuffer, - &subkeyBufferCount, NULL, - NULL, NULL, NULL); - if (retCode != ERROR_SUCCESS) { - LOG_WARN(("Could not enum certs. (%d)", retCode)); - return FALSE; - } - - // Open the subkey for the current certificate - HKEY subKeyRaw; - retCode = RegOpenKeyExW(baseKey, - subkeyBuffer, - 0, - KEY_READ | KEY_WOW64_64KEY, - &subKeyRaw); - nsAutoRegKey subKey(subKeyRaw); - if (retCode != ERROR_SUCCESS) { - LOG_WARN(("Could not open subkey. (%d)", retCode)); - continue; // Try the next subkey - } - - const int MAX_CHAR_COUNT = 256; - DWORD valueBufSize = MAX_CHAR_COUNT * sizeof(WCHAR); - WCHAR name[MAX_CHAR_COUNT] = { L'\0' }; - WCHAR issuer[MAX_CHAR_COUNT] = { L'\0' }; - - // Get the name from the registry - retCode = RegQueryValueExW(subKey, L"name", 0, NULL, - (LPBYTE)name, &valueBufSize); - if (retCode != ERROR_SUCCESS) { - LOG_WARN(("Could not obtain name from registry. (%d)", retCode)); - continue; // Try the next subkey - } - - // Get the issuer from the registry - valueBufSize = MAX_CHAR_COUNT * sizeof(WCHAR); - retCode = RegQueryValueExW(subKey, L"issuer", 0, NULL, - (LPBYTE)issuer, &valueBufSize); - if (retCode != ERROR_SUCCESS) { - LOG_WARN(("Could not obtain issuer from registry. (%d)", retCode)); - continue; // Try the next subkey - } - - CertificateCheckInfo allowedCertificate = { - name, - issuer, - }; - - retCode = CheckCertificateForPEFile(filePath, allowedCertificate); - if (retCode != ERROR_SUCCESS) { - LOG_WARN(("Error on certificate check. (%d)", retCode)); - continue; // Try the next subkey - } - - retCode = VerifyCertificateTrustForFile(filePath); - if (retCode != ERROR_SUCCESS) { - LOG_WARN(("Error on certificate trust check. (%d)", retCode)); - continue; // Try the next subkey - } - - // Raise the roof, we found a match! - return TRUE; - } - - // No certificates match, :'( - return FALSE; -} diff --git a/toolkit/components/maintenanceservice/registrycertificates.h b/toolkit/components/maintenanceservice/registrycertificates.h deleted file mode 100644 index 29213e843..000000000 --- a/toolkit/components/maintenanceservice/registrycertificates.h +++ /dev/null @@ -1,13 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef _REGISTRYCERTIFICATES_H_ -#define _REGISTRYCERTIFICATES_H_ - -#include "certificatecheck.h" - -BOOL DoesBinaryMatchAllowedCertificates(LPCWSTR basePathForUpdate, - LPCWSTR filePath); - -#endif diff --git a/toolkit/components/maintenanceservice/resource.h b/toolkit/components/maintenanceservice/resource.h deleted file mode 100644 index 45619457c..000000000 --- a/toolkit/components/maintenanceservice/resource.h +++ /dev/null @@ -1,20 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by updater.rc -// -#define IDI_DIALOG 1003 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 102 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1003 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/toolkit/components/maintenanceservice/servicebase.cpp b/toolkit/components/maintenanceservice/servicebase.cpp deleted file mode 100644 index 34164ab8e..000000000 --- a/toolkit/components/maintenanceservice/servicebase.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "servicebase.h" -#include "nsWindowsHelpers.h" - -// Shared code between applications and updater.exe -#include "nsWindowsRestart.cpp" - -/** - * Verifies if 2 files are byte for byte equivalent. - * - * @param file1Path The first file to verify. - * @param file2Path The second file to verify. - * @param sameContent Out parameter, TRUE if the files are equal - * @return TRUE If there was no error checking the files. - */ -BOOL -VerifySameFiles(LPCWSTR file1Path, LPCWSTR file2Path, BOOL &sameContent) -{ - sameContent = FALSE; - nsAutoHandle file1(CreateFileW(file1Path, GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_EXISTING, 0, NULL)); - if (INVALID_HANDLE_VALUE == file1) { - return FALSE; - } - nsAutoHandle file2(CreateFileW(file2Path, GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_EXISTING, 0, NULL)); - if (INVALID_HANDLE_VALUE == file2) { - return FALSE; - } - - DWORD fileSize1 = GetFileSize(file1, NULL); - DWORD fileSize2 = GetFileSize(file2, NULL); - if (INVALID_FILE_SIZE == fileSize1 || INVALID_FILE_SIZE == fileSize2) { - return FALSE; - } - - if (fileSize1 != fileSize2) { - // sameContent is already set to FALSE - return TRUE; - } - - char buf1[COMPARE_BLOCKSIZE]; - char buf2[COMPARE_BLOCKSIZE]; - DWORD numBlocks = fileSize1 / COMPARE_BLOCKSIZE; - DWORD leftOver = fileSize1 % COMPARE_BLOCKSIZE; - DWORD readAmount; - for (DWORD i = 0; i < numBlocks; i++) { - if (!ReadFile(file1, buf1, COMPARE_BLOCKSIZE, &readAmount, NULL) || - readAmount != COMPARE_BLOCKSIZE) { - return FALSE; - } - - if (!ReadFile(file2, buf2, COMPARE_BLOCKSIZE, &readAmount, NULL) || - readAmount != COMPARE_BLOCKSIZE) { - return FALSE; - } - - if (memcmp(buf1, buf2, COMPARE_BLOCKSIZE)) { - // sameContent is already set to FALSE - return TRUE; - } - } - - if (leftOver) { - if (!ReadFile(file1, buf1, leftOver, &readAmount, NULL) || - readAmount != leftOver) { - return FALSE; - } - - if (!ReadFile(file2, buf2, leftOver, &readAmount, NULL) || - readAmount != leftOver) { - return FALSE; - } - - if (memcmp(buf1, buf2, leftOver)) { - // sameContent is already set to FALSE - return TRUE; - } - } - - sameContent = TRUE; - return TRUE; -} diff --git a/toolkit/components/maintenanceservice/servicebase.h b/toolkit/components/maintenanceservice/servicebase.h deleted file mode 100644 index dfe04ed29..000000000 --- a/toolkit/components/maintenanceservice/servicebase.h +++ /dev/null @@ -1,22 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include <windows.h> -#include "updatelogging.h" - -BOOL PathAppendSafe(LPWSTR base, LPCWSTR extra); -BOOL VerifySameFiles(LPCWSTR file1Path, LPCWSTR file2Path, BOOL &sameContent); - -// 32KiB for comparing files at a time seems reasonable. -// The bigger the better for speed, but this will be used -// on the stack so I don't want it to be too big. -#define COMPARE_BLOCKSIZE 32768 - -// The following string resource value is used to uniquely identify the signed -// Mozilla application as an updater. Before the maintenance service will -// execute the updater it must have this updater identity string in its string -// table. No other signed Mozilla product will have this string table value. -#define UPDATER_IDENTITY_STRING \ - "moz-updater.exe-4cdccec4-5ee0-4a06-9817-4cd899a9db49" -#define IDS_UPDATER_IDENTITY 1006 diff --git a/toolkit/components/maintenanceservice/serviceinstall.cpp b/toolkit/components/maintenanceservice/serviceinstall.cpp deleted file mode 100644 index 4342bab11..000000000 --- a/toolkit/components/maintenanceservice/serviceinstall.cpp +++ /dev/null @@ -1,733 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include <windows.h> -#include <aclapi.h> -#include <stdlib.h> -#include <shlwapi.h> - -// Used for DNLEN and UNLEN -#include <lm.h> - -#include <nsAutoPtr.h> -#include <nsWindowsHelpers.h> -#include <nsMemory.h> - -#include "serviceinstall.h" -#include "servicebase.h" -#include "updatehelper.h" -#include "shellapi.h" -#include "readstrings.h" -#include "errors.h" - -#pragma comment(lib, "version.lib") - -/** - * A wrapper function to read strings for the maintenance service. - * - * @param path The path of the ini file to read from - * @param results The maintenance service strings that were read - * @return OK on success -*/ -static int -ReadMaintenanceServiceStrings(LPCWSTR path, - MaintenanceServiceStringTable *results) -{ - // Read in the maintenance service description string if specified. - const unsigned int kNumStrings = 1; - const char *kServiceKeys = "MozillaMaintenanceDescription\0"; - char serviceStrings[kNumStrings][MAX_TEXT_LEN]; - int result = ReadStrings(path, kServiceKeys, - kNumStrings, serviceStrings); - if (result != OK) { - serviceStrings[0][0] = '\0'; - } - strncpy(results->serviceDescription, - serviceStrings[0], MAX_TEXT_LEN - 1); - results->serviceDescription[MAX_TEXT_LEN - 1] = '\0'; - return result; -} - -/** - * Obtains the version number from the specified PE file's version information - * Version Format: A.B.C.D (Example 10.0.0.300) - * - * @param path The path of the file to check the version on - * @param A The first part of the version number - * @param B The second part of the version number - * @param C The third part of the version number - * @param D The fourth part of the version number - * @return TRUE if successful - */ -static BOOL -GetVersionNumberFromPath(LPWSTR path, DWORD &A, DWORD &B, - DWORD &C, DWORD &D) -{ - DWORD fileVersionInfoSize = GetFileVersionInfoSizeW(path, 0); - nsAutoArrayPtr<char> fileVersionInfo = new char[fileVersionInfoSize]; - if (!GetFileVersionInfoW(path, 0, fileVersionInfoSize, - fileVersionInfo.get())) { - LOG_WARN(("Could not obtain file info of old service. (%d)", - GetLastError())); - return FALSE; - } - - VS_FIXEDFILEINFO *fixedFileInfo = - reinterpret_cast<VS_FIXEDFILEINFO *>(fileVersionInfo.get()); - UINT size; - if (!VerQueryValueW(fileVersionInfo.get(), L"\\", - reinterpret_cast<LPVOID*>(&fixedFileInfo), &size)) { - LOG_WARN(("Could not query file version info of old service. (%d)", - GetLastError())); - return FALSE; - } - - A = HIWORD(fixedFileInfo->dwFileVersionMS); - B = LOWORD(fixedFileInfo->dwFileVersionMS); - C = HIWORD(fixedFileInfo->dwFileVersionLS); - D = LOWORD(fixedFileInfo->dwFileVersionLS); - return TRUE; -} - -/** - * Updates the service description with what is stored in updater.ini - * at the same path as the currently executing module binary. - * - * @param serviceHandle A handle to an opened service with - * SERVICE_CHANGE_CONFIG access right - * @param TRUE on succcess. -*/ -BOOL -UpdateServiceDescription(SC_HANDLE serviceHandle) -{ - WCHAR updaterINIPath[MAX_PATH + 1]; - if (!GetModuleFileNameW(NULL, updaterINIPath, - sizeof(updaterINIPath) / - sizeof(updaterINIPath[0]))) { - LOG_WARN(("Could not obtain module filename when attempting to " - "modify service description. (%d)", GetLastError())); - return FALSE; - } - - if (!PathRemoveFileSpecW(updaterINIPath)) { - LOG_WARN(("Could not remove file spec when attempting to " - "modify service description. (%d)", GetLastError())); - return FALSE; - } - - if (!PathAppendSafe(updaterINIPath, L"updater.ini")) { - LOG_WARN(("Could not append updater.ini filename when attempting to " - "modify service description. (%d)", GetLastError())); - return FALSE; - } - - if (GetFileAttributesW(updaterINIPath) == INVALID_FILE_ATTRIBUTES) { - LOG_WARN(("updater.ini file does not exist, will not modify " - "service description. (%d)", GetLastError())); - return FALSE; - } - - MaintenanceServiceStringTable serviceStrings; - int rv = ReadMaintenanceServiceStrings(updaterINIPath, &serviceStrings); - if (rv != OK || !strlen(serviceStrings.serviceDescription)) { - LOG_WARN(("updater.ini file does not contain a maintenance " - "service description.")); - return FALSE; - } - - WCHAR serviceDescription[MAX_TEXT_LEN]; - if (!MultiByteToWideChar(CP_UTF8, 0, - serviceStrings.serviceDescription, -1, - serviceDescription, - sizeof(serviceDescription) / - sizeof(serviceDescription[0]))) { - LOG_WARN(("Could not convert description to wide string format. (%d)", - GetLastError())); - return FALSE; - } - - SERVICE_DESCRIPTIONW descriptionConfig; - descriptionConfig.lpDescription = serviceDescription; - if (!ChangeServiceConfig2W(serviceHandle, - SERVICE_CONFIG_DESCRIPTION, - &descriptionConfig)) { - LOG_WARN(("Could not change service config. (%d)", GetLastError())); - return FALSE; - } - - LOG(("The service description was updated successfully.")); - return TRUE; -} - -/** - * Determines if the MozillaMaintenance service path needs to be updated - * and fixes it if it is wrong. - * - * @param service A handle to the service to fix. - * @param currentServicePath The current (possibly wrong) path that is used. - * @param servicePathWasWrong Out parameter set to TRUE if a fix was needed. - * @return TRUE if the service path is now correct. -*/ -BOOL -FixServicePath(SC_HANDLE service, - LPCWSTR currentServicePath, - BOOL &servicePathWasWrong) -{ - // When we originally upgraded the MozillaMaintenance service we - // would uninstall the service on each upgrade. This had an - // intermittent error which could cause the service to use the file - // maintenanceservice_tmp.exe as the install path. Only a small number - // of Nightly users would be affected by this, but we check for this - // state here and fix the user if they are affected. - // - // We also fix the path in the case of the path not being quoted. - size_t currentServicePathLen = wcslen(currentServicePath); - bool doesServiceHaveCorrectPath = - currentServicePathLen > 2 && - !wcsstr(currentServicePath, L"maintenanceservice_tmp.exe") && - currentServicePath[0] == L'\"' && - currentServicePath[currentServicePathLen - 1] == L'\"'; - - if (doesServiceHaveCorrectPath) { - LOG(("The MozillaMaintenance service path is correct.")); - servicePathWasWrong = FALSE; - return TRUE; - } - // This is a recoverable situation so not logging as a warning - LOG(("The MozillaMaintenance path is NOT correct. It was: %ls", - currentServicePath)); - - servicePathWasWrong = TRUE; - WCHAR fixedPath[MAX_PATH + 1] = { L'\0' }; - wcsncpy(fixedPath, currentServicePath, MAX_PATH); - PathUnquoteSpacesW(fixedPath); - if (!PathRemoveFileSpecW(fixedPath)) { - LOG_WARN(("Couldn't remove file spec. (%d)", GetLastError())); - return FALSE; - } - if (!PathAppendSafe(fixedPath, L"maintenanceservice.exe")) { - LOG_WARN(("Couldn't append file spec. (%d)", GetLastError())); - return FALSE; - } - PathQuoteSpacesW(fixedPath); - - - if (!ChangeServiceConfigW(service, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, - SERVICE_NO_CHANGE, fixedPath, NULL, NULL, NULL, - NULL, NULL, NULL)) { - LOG_WARN(("Could not fix service path. (%d)", GetLastError())); - return FALSE; - } - - LOG(("Fixed service path to: %ls.", fixedPath)); - return TRUE; -} - -/** - * Installs or upgrades the SVC_NAME service. - * If an existing service is already installed, we replace it with the - * currently running process. - * - * @param action The action to perform. - * @return TRUE if the service was installed/upgraded - */ -BOOL -SvcInstall(SvcInstallAction action) -{ - // Get a handle to the local computer SCM database with full access rights. - nsAutoServiceHandle schSCManager(OpenSCManager(NULL, NULL, - SC_MANAGER_ALL_ACCESS)); - if (!schSCManager) { - LOG_WARN(("Could not open service manager. (%d)", GetLastError())); - return FALSE; - } - - WCHAR newServiceBinaryPath[MAX_PATH + 1]; - if (!GetModuleFileNameW(NULL, newServiceBinaryPath, - sizeof(newServiceBinaryPath) / - sizeof(newServiceBinaryPath[0]))) { - LOG_WARN(("Could not obtain module filename when attempting to " - "install service. (%d)", - GetLastError())); - return FALSE; - } - - // Check if we already have the service installed. - nsAutoServiceHandle schService(OpenServiceW(schSCManager, - SVC_NAME, - SERVICE_ALL_ACCESS)); - DWORD lastError = GetLastError(); - if (!schService && ERROR_SERVICE_DOES_NOT_EXIST != lastError) { - // The service exists but we couldn't open it - LOG_WARN(("Could not open service. (%d)", GetLastError())); - return FALSE; - } - - if (schService) { - // The service exists but it may not have the correct permissions. - // This could happen if the permissions were not set correctly originally - // or have been changed after the installation. This will reset the - // permissions back to allow limited user accounts. - if (!SetUserAccessServiceDACL(schService)) { - LOG_WARN(("Could not reset security ACE on service handle. It might not be " - "possible to start the service. This error should never " - "happen. (%d)", GetLastError())); - } - - // The service exists and we opened it - DWORD bytesNeeded; - if (!QueryServiceConfigW(schService, NULL, 0, &bytesNeeded) && - GetLastError() != ERROR_INSUFFICIENT_BUFFER) { - LOG_WARN(("Could not determine buffer size for query service config. (%d)", - GetLastError())); - return FALSE; - } - - // Get the service config information, in particular we want the binary - // path of the service. - nsAutoArrayPtr<char> serviceConfigBuffer = new char[bytesNeeded]; - if (!QueryServiceConfigW(schService, - reinterpret_cast<QUERY_SERVICE_CONFIGW*>(serviceConfigBuffer.get()), - bytesNeeded, &bytesNeeded)) { - LOG_WARN(("Could open service but could not query service config. (%d)", - GetLastError())); - return FALSE; - } - QUERY_SERVICE_CONFIGW &serviceConfig = - *reinterpret_cast<QUERY_SERVICE_CONFIGW*>(serviceConfigBuffer.get()); - - // Check if we need to fix the service path - BOOL servicePathWasWrong; - static BOOL alreadyCheckedFixServicePath = FALSE; - if (!alreadyCheckedFixServicePath) { - if (!FixServicePath(schService, serviceConfig.lpBinaryPathName, - servicePathWasWrong)) { - LOG_WARN(("Could not fix service path. This should never happen. (%d)", - GetLastError())); - // True is returned because the service is pointing to - // maintenanceservice_tmp.exe so it actually was upgraded to the - // newest installed service. - return TRUE; - } else if (servicePathWasWrong) { - // Now that the path is fixed we should re-attempt the install. - // This current process' image path is maintenanceservice_tmp.exe. - // The service used to point to maintenanceservice_tmp.exe. - // The service was just fixed to point to maintenanceservice.exe. - // Re-attempting an install from scratch will work as normal. - alreadyCheckedFixServicePath = TRUE; - LOG(("Restarting install action: %d", action)); - return SvcInstall(action); - } - } - - // Ensure the service path is not quoted. We own this memory and know it to - // be large enough for the quoted path, so it is large enough for the - // unquoted path. This function cannot fail. - PathUnquoteSpacesW(serviceConfig.lpBinaryPathName); - - // Obtain the existing maintenanceservice file's version number and - // the new file's version number. Versions are in the format of - // A.B.C.D. - DWORD existingA, existingB, existingC, existingD; - DWORD newA, newB, newC, newD; - BOOL obtainedExistingVersionInfo = - GetVersionNumberFromPath(serviceConfig.lpBinaryPathName, - existingA, existingB, - existingC, existingD); - if (!GetVersionNumberFromPath(newServiceBinaryPath, newA, - newB, newC, newD)) { - LOG_WARN(("Could not obtain version number from new path")); - return FALSE; - } - - // Check if we need to replace the old binary with the new one - // If we couldn't get the old version info then we assume we should - // replace it. - if (ForceInstallSvc == action || - !obtainedExistingVersionInfo || - (existingA < newA) || - (existingA == newA && existingB < newB) || - (existingA == newA && existingB == newB && - existingC < newC) || - (existingA == newA && existingB == newB && - existingC == newC && existingD < newD)) { - - // We have a newer updater, so update the description from the INI file. - UpdateServiceDescription(schService); - - schService.reset(); - if (!StopService()) { - return FALSE; - } - - if (!wcscmp(newServiceBinaryPath, serviceConfig.lpBinaryPathName)) { - LOG(("File is already in the correct location, no action needed for " - "upgrade. The path is: \"%ls\"", newServiceBinaryPath)); - return TRUE; - } - - BOOL result = TRUE; - - // Attempt to copy the new binary over top the existing binary. - // If there is an error we try to move it out of the way and then - // copy it in. First try the safest / easiest way to overwrite the file. - if (!CopyFileW(newServiceBinaryPath, - serviceConfig.lpBinaryPathName, FALSE)) { - LOG_WARN(("Could not overwrite old service binary file. " - "This should never happen, but if it does the next " - "upgrade will fix it, the service is not a critical " - "component that needs to be installed for upgrades " - "to work. (%d)", GetLastError())); - - // We rename the last 3 filename chars in an unsafe way. Manually - // verify there are more than 3 chars for safe failure in MoveFileExW. - const size_t len = wcslen(serviceConfig.lpBinaryPathName); - if (len > 3) { - // Calculate the temp file path that we're moving the file to. This - // is the same as the proper service path but with a .old extension. - LPWSTR oldServiceBinaryTempPath = - new WCHAR[len + 1]; - memset(oldServiceBinaryTempPath, 0, (len + 1) * sizeof (WCHAR)); - wcsncpy(oldServiceBinaryTempPath, serviceConfig.lpBinaryPathName, len); - // Rename the last 3 chars to 'old' - wcsncpy(oldServiceBinaryTempPath + len - 3, L"old", 3); - - // Move the current (old) service file to the temp path. - if (MoveFileExW(serviceConfig.lpBinaryPathName, - oldServiceBinaryTempPath, - MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)) { - // The old binary is moved out of the way, copy in the new one. - if (!CopyFileW(newServiceBinaryPath, - serviceConfig.lpBinaryPathName, FALSE)) { - // It is best to leave the old service binary in this condition. - LOG_WARN(("The new service binary could not be copied in." - " The service will not be upgraded.")); - result = FALSE; - } else { - LOG(("The new service binary was copied in by first moving the" - " old one out of the way.")); - } - - // Attempt to get rid of the old service temp path. - if (DeleteFileW(oldServiceBinaryTempPath)) { - LOG(("The old temp service path was deleted: %ls.", - oldServiceBinaryTempPath)); - } else { - // The old temp path could not be removed. It will be removed - // the next time the user can't copy the binary in or on uninstall. - LOG_WARN(("The old temp service path was not deleted.")); - } - } else { - // It is best to leave the old service binary in this condition. - LOG_WARN(("Could not move old service file out of the way from:" - " \"%ls\" to \"%ls\". Service will not be upgraded. (%d)", - serviceConfig.lpBinaryPathName, - oldServiceBinaryTempPath, GetLastError())); - result = FALSE; - } - delete[] oldServiceBinaryTempPath; - } else { - // It is best to leave the old service binary in this condition. - LOG_WARN(("Service binary path was less than 3, service will" - " not be updated. This should never happen.")); - result = FALSE; - } - } else { - LOG(("The new service binary was copied in.")); - } - - // We made a copy of ourselves to the existing location. - // The tmp file (the process of which we are executing right now) will be - // left over. Attempt to delete the file on the next reboot. - if (MoveFileExW(newServiceBinaryPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT)) { - LOG(("Deleting the old file path on the next reboot: %ls.", - newServiceBinaryPath)); - } else { - LOG_WARN(("Call to delete the old file path failed: %ls.", - newServiceBinaryPath)); - } - - return result; - } - - // We don't need to copy ourselves to the existing location. - // The tmp file (the process of which we are executing right now) will be - // left over. Attempt to delete the file on the next reboot. - MoveFileExW(newServiceBinaryPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT); - - // nothing to do, we already have a newer service installed - return TRUE; - } - - // If the service does not exist and we are upgrading, don't install it. - if (UpgradeSvc == action) { - // The service does not exist and we are upgrading, so don't install it - return TRUE; - } - - // Quote the path only if it contains spaces. - PathQuoteSpacesW(newServiceBinaryPath); - // The service does not already exist so create the service as on demand - schService.own(CreateServiceW(schSCManager, SVC_NAME, SVC_DISPLAY_NAME, - SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, - SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, - newServiceBinaryPath, NULL, NULL, NULL, - NULL, NULL)); - if (!schService) { - LOG_WARN(("Could not create Windows service. " - "This error should never happen since a service install " - "should only be called when elevated. (%d)", GetLastError())); - return FALSE; - } - - if (!SetUserAccessServiceDACL(schService)) { - LOG_WARN(("Could not set security ACE on service handle, the service will not " - "be able to be started from unelevated processes. " - "This error should never happen. (%d)", - GetLastError())); - } - - UpdateServiceDescription(schService); - - return TRUE; -} - -/** - * Stops the Maintenance service. - * - * @return TRUE if successful. - */ -BOOL -StopService() -{ - // Get a handle to the local computer SCM database with full access rights. - nsAutoServiceHandle schSCManager(OpenSCManager(NULL, NULL, - SC_MANAGER_ALL_ACCESS)); - if (!schSCManager) { - LOG_WARN(("Could not open service manager. (%d)", GetLastError())); - return FALSE; - } - - // Open the service - nsAutoServiceHandle schService(OpenServiceW(schSCManager, SVC_NAME, - SERVICE_ALL_ACCESS)); - if (!schService) { - LOG_WARN(("Could not open service. (%d)", GetLastError())); - return FALSE; - } - - LOG(("Sending stop request...")); - SERVICE_STATUS status; - SetLastError(ERROR_SUCCESS); - if (!ControlService(schService, SERVICE_CONTROL_STOP, &status) && - GetLastError() != ERROR_SERVICE_NOT_ACTIVE) { - LOG_WARN(("Error sending stop request. (%d)", GetLastError())); - } - - schSCManager.reset(); - schService.reset(); - - LOG(("Waiting for service stop...")); - DWORD lastState = WaitForServiceStop(SVC_NAME, 30); - - // The service can be in a stopped state but the exe still in use - // so make sure the process is really gone before proceeding - WaitForProcessExit(L"maintenanceservice.exe", 30); - LOG(("Done waiting for service stop, last service state: %d", lastState)); - - return lastState == SERVICE_STOPPED; -} - -/** - * Uninstalls the Maintenance service. - * - * @return TRUE if successful. - */ -BOOL -SvcUninstall() -{ - // Get a handle to the local computer SCM database with full access rights. - nsAutoServiceHandle schSCManager(OpenSCManager(NULL, NULL, - SC_MANAGER_ALL_ACCESS)); - if (!schSCManager) { - LOG_WARN(("Could not open service manager. (%d)", GetLastError())); - return FALSE; - } - - // Open the service - nsAutoServiceHandle schService(OpenServiceW(schSCManager, SVC_NAME, - SERVICE_ALL_ACCESS)); - if (!schService) { - LOG_WARN(("Could not open service. (%d)", GetLastError())); - return FALSE; - } - - //Stop the service so it deletes faster and so the uninstaller - // can actually delete its EXE. - DWORD totalWaitTime = 0; - SERVICE_STATUS status; - static const int maxWaitTime = 1000 * 60; // Never wait more than a minute - if (ControlService(schService, SERVICE_CONTROL_STOP, &status)) { - do { - Sleep(status.dwWaitHint); - totalWaitTime += (status.dwWaitHint + 10); - if (status.dwCurrentState == SERVICE_STOPPED) { - break; - } else if (totalWaitTime > maxWaitTime) { - break; - } - } while (QueryServiceStatus(schService, &status)); - } - - // Delete the service or mark it for deletion - BOOL deleted = DeleteService(schService); - if (!deleted) { - deleted = (GetLastError() == ERROR_SERVICE_MARKED_FOR_DELETE); - } - - return deleted; -} - -/** - * Sets the access control list for user access for the specified service. - * - * @param hService The service to set the access control list on - * @return TRUE if successful - */ -BOOL -SetUserAccessServiceDACL(SC_HANDLE hService) -{ - PACL pNewAcl = NULL; - PSECURITY_DESCRIPTOR psd = NULL; - DWORD lastError = SetUserAccessServiceDACL(hService, pNewAcl, psd); - if (pNewAcl) { - LocalFree((HLOCAL)pNewAcl); - } - if (psd) { - LocalFree((LPVOID)psd); - } - return ERROR_SUCCESS == lastError; -} - -/** - * Sets the access control list for user access for the specified service. - * - * @param hService The service to set the access control list on - * @param pNewAcl The out param ACL which should be freed by caller - * @param psd out param security descriptor, should be freed by caller - * @return ERROR_SUCCESS if successful - */ -DWORD -SetUserAccessServiceDACL(SC_HANDLE hService, PACL &pNewAcl, - PSECURITY_DESCRIPTOR psd) -{ - // Get the current security descriptor needed size - DWORD needed = 0; - if (!QueryServiceObjectSecurity(hService, DACL_SECURITY_INFORMATION, - &psd, 0, &needed)) { - if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { - LOG_WARN(("Could not query service object security size. (%d)", - GetLastError())); - return GetLastError(); - } - - DWORD size = needed; - psd = (PSECURITY_DESCRIPTOR)LocalAlloc(LPTR, size); - if (!psd) { - LOG_WARN(("Could not allocate security descriptor. (%d)", - GetLastError())); - return ERROR_INSUFFICIENT_BUFFER; - } - - // Get the actual security descriptor now - if (!QueryServiceObjectSecurity(hService, DACL_SECURITY_INFORMATION, - psd, size, &needed)) { - LOG_WARN(("Could not allocate security descriptor. (%d)", - GetLastError())); - return GetLastError(); - } - } - - // Get the current DACL from the security descriptor. - PACL pacl = NULL; - BOOL bDaclPresent = FALSE; - BOOL bDaclDefaulted = FALSE; - if ( !GetSecurityDescriptorDacl(psd, &bDaclPresent, &pacl, - &bDaclDefaulted)) { - LOG_WARN(("Could not obtain DACL. (%d)", GetLastError())); - return GetLastError(); - } - - PSID sid; - DWORD SIDSize = SECURITY_MAX_SID_SIZE; - sid = LocalAlloc(LMEM_FIXED, SIDSize); - if (!sid) { - LOG_WARN(("Could not allocate SID memory. (%d)", GetLastError())); - return GetLastError(); - } - - if (!CreateWellKnownSid(WinBuiltinUsersSid, NULL, sid, &SIDSize)) { - DWORD lastError = GetLastError(); - LOG_WARN(("Could not create well known SID. (%d)", lastError)); - LocalFree(sid); - return lastError; - } - - // Lookup the account name, the function fails if you don't pass in - // a buffer for the domain name but it's not used since we're using - // the built in account Sid. - SID_NAME_USE accountType; - WCHAR accountName[UNLEN + 1] = { L'\0' }; - WCHAR domainName[DNLEN + 1] = { L'\0' }; - DWORD accountNameSize = UNLEN + 1; - DWORD domainNameSize = DNLEN + 1; - if (!LookupAccountSidW(NULL, sid, accountName, - &accountNameSize, - domainName, &domainNameSize, &accountType)) { - LOG_WARN(("Could not lookup account Sid, will try Users. (%d)", - GetLastError())); - wcsncpy(accountName, L"Users", UNLEN); - } - - // We already have the group name so we can get rid of the SID - FreeSid(sid); - sid = NULL; - - // Build the ACE, BuildExplicitAccessWithName cannot fail so it is not logged. - EXPLICIT_ACCESS ea; - BuildExplicitAccessWithNameW(&ea, accountName, - SERVICE_START | SERVICE_STOP | GENERIC_READ, - SET_ACCESS, NO_INHERITANCE); - DWORD lastError = SetEntriesInAclW(1, (PEXPLICIT_ACCESS)&ea, pacl, &pNewAcl); - if (ERROR_SUCCESS != lastError) { - LOG_WARN(("Could not set entries in ACL. (%d)", lastError)); - return lastError; - } - - // Initialize a new security descriptor. - SECURITY_DESCRIPTOR sd; - if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) { - LOG_WARN(("Could not initialize security descriptor. (%d)", - GetLastError())); - return GetLastError(); - } - - // Set the new DACL in the security descriptor. - if (!SetSecurityDescriptorDacl(&sd, TRUE, pNewAcl, FALSE)) { - LOG_WARN(("Could not set security descriptor DACL. (%d)", - GetLastError())); - return GetLastError(); - } - - // Set the new security descriptor for the service object. - if (!SetServiceObjectSecurity(hService, DACL_SECURITY_INFORMATION, &sd)) { - LOG_WARN(("Could not set object security. (%d)", - GetLastError())); - return GetLastError(); - } - - // Woohoo, raise the roof - LOG(("User access was set successfully on the service.")); - return ERROR_SUCCESS; -} diff --git a/toolkit/components/maintenanceservice/serviceinstall.h b/toolkit/components/maintenanceservice/serviceinstall.h deleted file mode 100644 index d8532a968..000000000 --- a/toolkit/components/maintenanceservice/serviceinstall.h +++ /dev/null @@ -1,21 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "readstrings.h" - -#define SVC_DISPLAY_NAME L"Mozilla Maintenance Service" - -enum SvcInstallAction { UpgradeSvc, InstallSvc, ForceInstallSvc }; -BOOL SvcInstall(SvcInstallAction action); -BOOL SvcUninstall(); -BOOL StopService(); -BOOL SetUserAccessServiceDACL(SC_HANDLE hService); -DWORD SetUserAccessServiceDACL(SC_HANDLE hService, PACL &pNewAcl, - PSECURITY_DESCRIPTOR psd); - -struct MaintenanceServiceStringTable -{ - char serviceDescription[MAX_TEXT_LEN]; -}; - diff --git a/toolkit/components/maintenanceservice/workmonitor.cpp b/toolkit/components/maintenanceservice/workmonitor.cpp deleted file mode 100644 index c3046b21e..000000000 --- a/toolkit/components/maintenanceservice/workmonitor.cpp +++ /dev/null @@ -1,634 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include <shlobj.h> -#include <shlwapi.h> -#include <wtsapi32.h> -#include <userenv.h> -#include <shellapi.h> - -#pragma comment(lib, "wtsapi32.lib") -#pragma comment(lib, "userenv.lib") -#pragma comment(lib, "shlwapi.lib") -#pragma comment(lib, "ole32.lib") -#pragma comment(lib, "rpcrt4.lib") - -#include "nsWindowsHelpers.h" -#include "nsAutoPtr.h" - -#include "workmonitor.h" -#include "serviceinstall.h" -#include "servicebase.h" -#include "registrycertificates.h" -#include "uachelper.h" -#include "updatehelper.h" -#include "errors.h" - -// Wait 15 minutes for an update operation to run at most. -// Updates usually take less than a minute so this seems like a -// significantly large and safe amount of time to wait. -static const int TIME_TO_WAIT_ON_UPDATER = 15 * 60 * 1000; -PRUnichar* MakeCommandLine(int argc, PRUnichar **argv); -BOOL WriteStatusFailure(LPCWSTR updateDirPath, int errorCode); -BOOL PathGetSiblingFilePath(LPWSTR destinationBuffer, LPCWSTR siblingFilePath, - LPCWSTR newFileName); - -/* - * Read the update.status file and sets isApplying to true if - * the status is set to applying - * - * @param updateDirPath The directory where update.status is stored - * @param isApplying Out parameter for specifying if the status - * is set to applying or not. - * @return TRUE if the information was filled. -*/ -static BOOL -IsStatusApplying(LPCWSTR updateDirPath, BOOL &isApplying) -{ - isApplying = FALSE; - WCHAR updateStatusFilePath[MAX_PATH + 1] = {L'\0'}; - wcsncpy(updateStatusFilePath, updateDirPath, MAX_PATH); - if (!PathAppendSafe(updateStatusFilePath, L"update.status")) { - LOG_WARN(("Could not append path for update.status file")); - return FALSE; - } - - nsAutoHandle statusFile(CreateFileW(updateStatusFilePath, GENERIC_READ, - FILE_SHARE_READ | - FILE_SHARE_WRITE | - FILE_SHARE_DELETE, - NULL, OPEN_EXISTING, 0, NULL)); - - if (INVALID_HANDLE_VALUE == statusFile) { - LOG_WARN(("Could not open update.status file")); - return FALSE; - } - - char buf[32] = { 0 }; - DWORD read; - if (!ReadFile(statusFile, buf, sizeof(buf), &read, NULL)) { - LOG_WARN(("Could not read from update.status file")); - return FALSE; - } - - LOG(("updater.exe returned status: %s", buf)); - - const char kApplying[] = "applying"; - isApplying = strncmp(buf, kApplying, - sizeof(kApplying) - 1) == 0; - return TRUE; -} - -/** - * Determines whether we're staging an update. - * - * @param argc The argc value normally sent to updater.exe - * @param argv The argv value normally sent to updater.exe - * @param boolean True if we're staging an update - */ -static bool -IsUpdateBeingStaged(int argc, LPWSTR *argv) -{ - // PID will be set to -1 if we're supposed to stage an update. - return argc == 4 && !wcscmp(argv[3], L"-1"); -} - -/** - * Gets the installation directory from the arguments passed to updater.exe. - * - * @param argcTmp The argc value normally sent to updater.exe - * @param argvTmp The argv value normally sent to updater.exe - * @param aResultDir Buffer to hold the installation directory. - */ -static BOOL -GetInstallationDir(int argcTmp, LPWSTR *argvTmp, WCHAR aResultDir[MAX_PATH + 1]) -{ - if (argcTmp < 2) { - return FALSE; - } - wcsncpy(aResultDir, argvTmp[2], MAX_PATH); - WCHAR* backSlash = wcsrchr(aResultDir, L'\\'); - // Make sure that the path does not include trailing backslashes - if (backSlash && (backSlash[1] == L'\0')) { - *backSlash = L'\0'; - } - bool backgroundUpdate = IsUpdateBeingStaged(argcTmp, argvTmp); - bool replaceRequest = (argcTmp >= 4 && wcsstr(argvTmp[3], L"/replace")); - if (backgroundUpdate || replaceRequest) { - return PathRemoveFileSpecW(aResultDir); - } - return TRUE; -} - -/** - * Runs an update process as the service using the SYSTEM account. - * - * @param argc The number of arguments in argv - * @param argv The arguments normally passed to updater.exe - * argv[0] must be the path to updater.exe - * @param processStarted Set to TRUE if the process was started. - * @return TRUE if the update process was run had a return code of 0. - */ -BOOL -StartUpdateProcess(int argc, - LPWSTR *argv, - LPCWSTR installDir, - BOOL &processStarted) -{ - LOG(("Starting update process as the service in session 0.")); - STARTUPINFO si = {0}; - si.cb = sizeof(STARTUPINFO); - si.lpDesktop = L"winsta0\\Default"; - PROCESS_INFORMATION pi = {0}; - - // The updater command line is of the form: - // updater.exe update-dir apply [wait-pid [callback-dir callback-path args]] - LPWSTR cmdLine = MakeCommandLine(argc, argv); - - // If we're about to start the update process from session 0, - // then we should not show a GUI. This only really needs to be done - // on Vista and higher, but it's better to keep everything consistent - // across all OS if it's of no harm. - if (argc >= 2 ) { - // Setting the desktop to blank will ensure no GUI is displayed - si.lpDesktop = L""; - si.dwFlags |= STARTF_USESHOWWINDOW; - si.wShowWindow = SW_HIDE; - } - - // We move the updater.ini file out of the way because we will handle - // executing PostUpdate through the service. We handle PostUpdate from - // the service because there are some per user things that happen that - // can't run in session 0 which we run updater.exe in. - // Once we are done running updater.exe we rename updater.ini back so - // that if there were any errors the next updater.exe will run correctly. - WCHAR updaterINI[MAX_PATH + 1]; - WCHAR updaterINITemp[MAX_PATH + 1]; - BOOL selfHandlePostUpdate = FALSE; - // We use the updater.ini from the same directory as the updater.exe - // because of background updates. - if (PathGetSiblingFilePath(updaterINI, argv[0], L"updater.ini") && - PathGetSiblingFilePath(updaterINITemp, argv[0], L"updater.tmp")) { - selfHandlePostUpdate = MoveFileExW(updaterINI, updaterINITemp, - MOVEFILE_REPLACE_EXISTING); - } - - // Add an env var for MOZ_USING_SERVICE so the updater.exe can - // do anything special that it needs to do for service updates. - // Search in updater.cpp for more info on MOZ_USING_SERVICE. - putenv(const_cast<char*>("MOZ_USING_SERVICE=1")); - LOG(("Starting service with cmdline: %ls", cmdLine)); - processStarted = CreateProcessW(argv[0], cmdLine, - NULL, NULL, FALSE, - CREATE_DEFAULT_ERROR_MODE, - NULL, - NULL, &si, &pi); - // Empty value on putenv is how you remove an env variable in Windows - putenv(const_cast<char*>("MOZ_USING_SERVICE=")); - - BOOL updateWasSuccessful = FALSE; - if (processStarted) { - // Wait for the updater process to finish - LOG(("Process was started... waiting on result.")); - DWORD waitRes = WaitForSingleObject(pi.hProcess, TIME_TO_WAIT_ON_UPDATER); - if (WAIT_TIMEOUT == waitRes) { - // We waited a long period of time for updater.exe and it never finished - // so kill it. - TerminateProcess(pi.hProcess, 1); - } else { - // Check the return code of updater.exe to make sure we get 0 - DWORD returnCode; - if (GetExitCodeProcess(pi.hProcess, &returnCode)) { - LOG(("Process finished with return code %d.", returnCode)); - // updater returns 0 if successful. - updateWasSuccessful = (returnCode == 0); - } else { - LOG_WARN(("Process finished but could not obtain return code.")); - } - } - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - - // Check just in case updater.exe didn't change the status from - // applying. If this is the case we report an error. - BOOL isApplying = FALSE; - if (IsStatusApplying(argv[1], isApplying) && isApplying) { - if (updateWasSuccessful) { - LOG(("update.status is still applying even know update " - " was successful.")); - if (!WriteStatusFailure(argv[1], - SERVICE_STILL_APPLYING_ON_SUCCESS)) { - LOG_WARN(("Could not write update.status still applying on" - " success error.")); - } - // Since we still had applying we know updater.exe didn't do its - // job correctly. - updateWasSuccessful = FALSE; - } else { - LOG_WARN(("update.status is still applying and update was not successful.")); - if (!WriteStatusFailure(argv[1], - SERVICE_STILL_APPLYING_ON_FAILURE)) { - LOG_WARN(("Could not write update.status still applying on" - " success error.")); - } - } - } - } else { - DWORD lastError = GetLastError(); - LOG_WARN(("Could not create process as current user, " - "updaterPath: %ls; cmdLine: %ls. (%d)", - argv[0], cmdLine, lastError)); - } - - // Now that we're done with the update, restore back the updater.ini file - // We use it ourselves, and also we want it back in case we had any type - // of error so that the normal update process can use it. - if (selfHandlePostUpdate) { - MoveFileExW(updaterINITemp, updaterINI, MOVEFILE_REPLACE_EXISTING); - - // Only run the PostUpdate if the update was successful - if (updateWasSuccessful && argc > 2) { - LPCWSTR updateInfoDir = argv[1]; - bool backgroundUpdate = IsUpdateBeingStaged(argc, argv); - - // Launch the PostProcess with admin access in session 0. This is - // actually launching the post update process but it takes in the - // callback app path to figure out where to apply to. - // The PostUpdate process with user only access will be done inside - // the unelevated updater.exe after the update process is complete - // from the service. We don't know here which session to start - // the user PostUpdate process from. - // Note that we don't need to do this if we're just staging the - // update in the background, as the PostUpdate step runs when - // performing the replacing in that case. - if (!backgroundUpdate) { - LOG(("Launching post update process as the service in session 0.")); - if (!LaunchWinPostProcess(installDir, updateInfoDir, true, NULL)) { - LOG_WARN(("The post update process could not be launched." - " installDir: %ls, updateInfoDir: %ls", - installDir, updateInfoDir)); - } - } - } - } - - free(cmdLine); - return updateWasSuccessful; -} - -/** - * Processes a software update command - * - * @param argc The number of arguments in argv - * @param argv The arguments normally passed to updater.exe - * argv[0] must be the path to updater.exe - * @return TRUE if the update was successful. - */ -BOOL -ProcessSoftwareUpdateCommand(DWORD argc, LPWSTR *argv) -{ - BOOL result = TRUE; - if (argc < 3) { - LOG_WARN(("Not enough command line parameters specified. " - "Updating update.status.")); - - // We can only update update.status if argv[1] exists. argv[1] is - // the directory where the update.status file exists. - if (argc < 2 || - !WriteStatusFailure(argv[1], - SERVICE_NOT_ENOUGH_COMMAND_LINE_ARGS)) { - LOG_WARN(("Could not write update.status service update failure. (%d)", - GetLastError())); - } - return FALSE; - } - - WCHAR installDir[MAX_PATH + 1] = {L'\0'}; - if (!GetInstallationDir(argc, argv, installDir)) { - LOG_WARN(("Could not get the installation directory")); - if (!WriteStatusFailure(argv[1], - SERVICE_INSTALLDIR_ERROR)) { - LOG_WARN(("Could not write update.status for GetInstallationDir failure.")); - } - return FALSE; - } - - // Make sure the path to the updater to use for the update is local. - // We do this check to make sure that file locking is available for - // race condition security checks. - BOOL isLocal = FALSE; - if (!IsLocalFile(argv[0], isLocal) || !isLocal) { - LOG_WARN(("Filesystem in path %ls is not supported (%d)", - argv[0], GetLastError())); - if (!WriteStatusFailure(argv[1], - SERVICE_UPDATER_NOT_FIXED_DRIVE)) { - LOG_WARN(("Could not write update.status service update failure. (%d)", - GetLastError())); - } - return FALSE; - } - - nsAutoHandle noWriteLock(CreateFileW(argv[0], GENERIC_READ, FILE_SHARE_READ, - NULL, OPEN_EXISTING, 0, NULL)); - if (INVALID_HANDLE_VALUE == noWriteLock) { - LOG_WARN(("Could not set no write sharing access on file. (%d)", - GetLastError())); - if (!WriteStatusFailure(argv[1], - SERVICE_COULD_NOT_LOCK_UPDATER)) { - LOG_WARN(("Could not write update.status service update failure. (%d)", - GetLastError())); - } - return FALSE; - } - - // Verify that the updater.exe that we are executing is the same - // as the one in the installation directory which we are updating. - // The installation dir that we are installing to is installDir. - WCHAR installDirUpdater[MAX_PATH + 1] = { L'\0' }; - wcsncpy(installDirUpdater, installDir, MAX_PATH); - if (!PathAppendSafe(installDirUpdater, L"updater.exe")) { - LOG_WARN(("Install directory updater could not be determined.")); - result = FALSE; - } - - BOOL updaterIsCorrect; - if (result && !VerifySameFiles(argv[0], installDirUpdater, - updaterIsCorrect)) { - LOG_WARN(("Error checking if the updaters are the same.\n" - "Path 1: %ls\nPath 2: %ls", argv[0], installDirUpdater)); - result = FALSE; - } - - if (result && !updaterIsCorrect) { - LOG_WARN(("The updaters do not match, updater will not run.")); - result = FALSE; - } - - if (result) { - LOG(("updater.exe was compared successfully to the installation directory" - " updater.exe.")); - } else { - if (!WriteStatusFailure(argv[1], - SERVICE_UPDATER_COMPARE_ERROR)) { - LOG_WARN(("Could not write update.status updater compare failure.")); - } - return FALSE; - } - - // Check to make sure the updater.exe module has the unique updater identity. - // This is a security measure to make sure that the signed executable that - // we will run is actually an updater. - HMODULE updaterModule = LoadLibraryEx(argv[0], NULL, - LOAD_LIBRARY_AS_DATAFILE); - if (!updaterModule) { - LOG_WARN(("updater.exe module could not be loaded. (%d)", GetLastError())); - result = FALSE; - } else { - char updaterIdentity[64]; - if (!LoadStringA(updaterModule, IDS_UPDATER_IDENTITY, - updaterIdentity, sizeof(updaterIdentity))) { - LOG_WARN(("The updater.exe application does not contain the Mozilla" - " updater identity.")); - result = FALSE; - } - - if (strcmp(updaterIdentity, UPDATER_IDENTITY_STRING)) { - LOG_WARN(("The updater.exe identity string is not valid.")); - result = FALSE; - } - FreeLibrary(updaterModule); - } - - if (result) { - LOG(("The updater.exe application contains the Mozilla" - " updater identity.")); - } else { - if (!WriteStatusFailure(argv[1], - SERVICE_UPDATER_IDENTITY_ERROR)) { - LOG_WARN(("Could not write update.status no updater identity.")); - } - return TRUE; - } - - // Check for updater.exe sign problems - BOOL updaterSignProblem = FALSE; -#ifndef DISABLE_UPDATER_AUTHENTICODE_CHECK - updaterSignProblem = !DoesBinaryMatchAllowedCertificates(installDir, - argv[0]); -#endif - - // Only proceed with the update if we have no signing problems - if (!updaterSignProblem) { - BOOL updateProcessWasStarted = FALSE; - if (StartUpdateProcess(argc, argv, installDir, - updateProcessWasStarted)) { - LOG(("updater.exe was launched and run successfully!")); - LogFlush(); - - // Don't attempt to update the service when the update is being staged. - if (!IsUpdateBeingStaged(argc, argv)) { - // We might not execute code after StartServiceUpdate because - // the service installer will stop the service if it is running. - StartServiceUpdate(installDir); - } - } else { - result = FALSE; - LOG_WARN(("Error running update process. Updating update.status (%d)", - GetLastError())); - LogFlush(); - - // If the update process was started, then updater.exe is responsible for - // setting the failure code. If it could not be started then we do the - // work. We set an error instead of directly setting status pending - // so that the app.update.service.errors pref can be updated when - // the callback app restarts. - if (!updateProcessWasStarted) { - if (!WriteStatusFailure(argv[1], - SERVICE_UPDATER_COULD_NOT_BE_STARTED)) { - LOG_WARN(("Could not write update.status service update failure. (%d)", - GetLastError())); - } - } - } - } else { - result = FALSE; - LOG_WARN(("Could not start process due to certificate check error on " - "updater.exe. Updating update.status. (%d)", GetLastError())); - - // When there is a certificate check error on the updater.exe application, - // we want to write out the error. - if (!WriteStatusFailure(argv[1], - SERVICE_UPDATER_SIGN_ERROR)) { - LOG_WARN(("Could not write pending state to update.status. (%d)", - GetLastError())); - } - } - - return result; -} - -/** - * Obtains the updater path alongside a subdir of the service binary. - * The purpose of this function is to return a path that is likely high - * integrity and therefore more safe to execute code from. - * - * @param serviceUpdaterPath Out parameter for the path where the updater - * should be copied to. - * @return TRUE if a file path was obtained. - */ -BOOL -GetSecureUpdaterPath(WCHAR serviceUpdaterPath[MAX_PATH + 1]) -{ - if (!GetModuleFileNameW(NULL, serviceUpdaterPath, MAX_PATH)) { - LOG_WARN(("Could not obtain module filename when attempting to " - "use a secure updater path. (%d)", GetLastError())); - return FALSE; - } - - if (!PathRemoveFileSpecW(serviceUpdaterPath)) { - LOG_WARN(("Couldn't remove file spec when attempting to use a secure " - "updater path. (%d)", GetLastError())); - return FALSE; - } - - if (!PathAppendSafe(serviceUpdaterPath, L"update")) { - LOG_WARN(("Couldn't append file spec when attempting to use a secure " - "updater path. (%d)", GetLastError())); - return FALSE; - } - - CreateDirectoryW(serviceUpdaterPath, NULL); - - if (!PathAppendSafe(serviceUpdaterPath, L"updater.exe")) { - LOG_WARN(("Couldn't append file spec when attempting to use a secure " - "updater path. (%d)", GetLastError())); - return FALSE; - } - - return TRUE; -} - -/** - * Deletes the passed in updater path and the associated updater.ini file. - * - * @param serviceUpdaterPath The path to delete. - * @return TRUE if a file was deleted. - */ -BOOL -DeleteSecureUpdater(WCHAR serviceUpdaterPath[MAX_PATH + 1]) -{ - BOOL result = FALSE; - if (serviceUpdaterPath[0]) { - result = DeleteFileW(serviceUpdaterPath); - if (!result && GetLastError() != ERROR_PATH_NOT_FOUND && - GetLastError() != ERROR_FILE_NOT_FOUND) { - LOG_WARN(("Could not delete service updater path: '%ls'.", - serviceUpdaterPath)); - } - - WCHAR updaterINIPath[MAX_PATH + 1] = { L'\0' }; - if (PathGetSiblingFilePath(updaterINIPath, serviceUpdaterPath, - L"updater.ini")) { - result = DeleteFileW(updaterINIPath); - if (!result && GetLastError() != ERROR_PATH_NOT_FOUND && - GetLastError() != ERROR_FILE_NOT_FOUND) { - LOG_WARN(("Could not delete service updater INI path: '%ls'.", - updaterINIPath)); - } - } - } - return result; -} - -/** - * Executes a service command. - * - * @param argc The number of arguments in argv - * @param argv The service command line arguments, argv[0] and argv[1] - * and automatically included by Windows. argv[2] is the - * service command. - * - * @return FALSE if there was an error executing the service command. - */ -BOOL -ExecuteServiceCommand(int argc, LPWSTR *argv) -{ - if (argc < 3) { - LOG_WARN(("Not enough command line arguments to execute a service command")); - return FALSE; - } - - // The tests work by making sure the log has changed, so we put a - // unique ID in the log. - RPC_WSTR guidString = RPC_WSTR(L""); - GUID guid; - HRESULT hr = CoCreateGuid(&guid); - if (SUCCEEDED(hr)) { - UuidToString(&guid, &guidString); - } - LOG(("Executing service command %ls, ID: %ls", - argv[2], reinterpret_cast<LPCWSTR>(guidString))); - RpcStringFree(&guidString); - - BOOL result = FALSE; - if (!lstrcmpi(argv[2], L"software-update")) { - - // Use the passed in command line arguments for the update, except for the - // path to updater.exe. We copy updater.exe to a the directory of the - // MozillaMaintenance service so that a low integrity process cannot - // replace the updater.exe at any point and use that for the update. - // It also makes DLL injection attacks harder. - LPWSTR oldUpdaterPath = argv[3]; - WCHAR secureUpdaterPath[MAX_PATH + 1] = { L'\0' }; - result = GetSecureUpdaterPath(secureUpdaterPath); // Does its own logging - if (result) { - LOG(("Passed in path: '%ls'; Using this path for updating: '%ls'.", - oldUpdaterPath, secureUpdaterPath)); - DeleteSecureUpdater(secureUpdaterPath); - result = CopyFileW(oldUpdaterPath, secureUpdaterPath, FALSE); - } - - if (!result) { - LOG_WARN(("Could not copy path to secure location. (%d)", - GetLastError())); - if (argc > 4 && !WriteStatusFailure(argv[4], - SERVICE_COULD_NOT_COPY_UPDATER)) { - LOG_WARN(("Could not write update.status could not copy updater error")); - } - } else { - - // We obtained the path and copied it successfully, update the path to - // use for the service update. - argv[3] = secureUpdaterPath; - - WCHAR oldUpdaterINIPath[MAX_PATH + 1] = { L'\0' }; - WCHAR secureUpdaterINIPath[MAX_PATH + 1] = { L'\0' }; - if (PathGetSiblingFilePath(secureUpdaterINIPath, secureUpdaterPath, - L"updater.ini") && - PathGetSiblingFilePath(oldUpdaterINIPath, oldUpdaterPath, - L"updater.ini")) { - // This is non fatal if it fails there is no real harm - if (!CopyFileW(oldUpdaterINIPath, secureUpdaterINIPath, FALSE)) { - LOG_WARN(("Could not copy updater.ini from: '%ls' to '%ls'. (%d)", - oldUpdaterINIPath, secureUpdaterINIPath, GetLastError())); - } - } - - result = ProcessSoftwareUpdateCommand(argc - 3, argv + 3); - DeleteSecureUpdater(secureUpdaterPath); - } - - // We might not reach here if the service install succeeded - // because the service self updates itself and the service - // installer will stop the service. - LOG(("Service command %ls complete.", argv[2])); - } else { - LOG_WARN(("Service command not recognized: %ls.", argv[2])); - // result is already set to FALSE - } - - LOG(("service command %ls complete with result: %ls.", - argv[1], (result ? L"Success" : L"Failure"))); - return TRUE; -} diff --git a/toolkit/components/maintenanceservice/workmonitor.h b/toolkit/components/maintenanceservice/workmonitor.h deleted file mode 100644 index ac4cd679b..000000000 --- a/toolkit/components/maintenanceservice/workmonitor.h +++ /dev/null @@ -1,5 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -BOOL ExecuteServiceCommand(int argc, LPWSTR *argv); diff --git a/toolkit/moz.build b/toolkit/moz.build index baa9c652e..7fba20cd2 100644 --- a/toolkit/moz.build +++ b/toolkit/moz.build @@ -25,9 +25,6 @@ PARALLEL_DIRS += [ DIRS += ['mozapps/update'] -if CONFIG['MOZ_MAINTENANCE_SERVICE']: - DIRS += ['components/maintenanceservice'] - DIRS += ['xre'] if CONFIG['MOZ_WIDGET_TOOLKIT'] in ('gtk2', 'gtk3', 'qt'): diff --git a/toolkit/mozapps/installer/windows/nsis/makensis.mk b/toolkit/mozapps/installer/windows/nsis/makensis.mk index 9266c2909..2246ec846 100644 --- a/toolkit/mozapps/installer/windows/nsis/makensis.mk +++ b/toolkit/mozapps/installer/windows/nsis/makensis.mk @@ -94,13 +94,6 @@ uninstaller:: $(NSINSTALL) -D $(DIST)/bin/uninstall cp $(CONFIG_DIR)/helper.exe $(DIST)/bin/uninstall -ifdef MOZ_MAINTENANCE_SERVICE -maintenanceservice_installer:: - cd $(CONFIG_DIR) && $(MAKENSISU) maintenanceservice_installer.nsi - $(NSINSTALL) -D $(DIST)/bin/ - cp $(CONFIG_DIR)/maintenanceservice_installer.exe $(DIST)/bin -endif - ifdef MOZ_WEBAPP_RUNTIME webapp_uninstaller:: $(INSTALL) $(addprefix $(MOZILLA_DIR)/toolkit/mozapps/installer/windows/nsis/,$(TOOLKIT_NSIS_FILES)) $(CONFIG_DIR) diff --git a/toolkit/mozapps/update/moz.build b/toolkit/mozapps/update/moz.build index d0242c4c3..0f7ce27e0 100644 --- a/toolkit/mozapps/update/moz.build +++ b/toolkit/mozapps/update/moz.build @@ -7,12 +7,6 @@ if CONFIG['MOZ_WIDGET_TOOLKIT'] != 'android': if CONFIG['MOZ_UPDATER']: DIRS += ['common', 'updater'] - elif CONFIG['MOZ_MAINTENANCE_SERVICE']: - # If only the maintenance service is installed and not - # the updater, then the maintenance service may still be - # used for other things. We need to build update/common - # which the maintenance service uses. - DIRS += ['common'] TEST_DIRS += ['test_timermanager'] @@ -24,9 +18,6 @@ XPIDL_SOURCES += [ if CONFIG['MOZ_UPDATER']: TEST_DIRS += ['test'] - if CONFIG['MOZ_MAINTENANCE_SERVICE']: - TEST_DIRS += ['test_svc'] - XPIDL_SOURCES += [ 'nsIUpdateService.idl', ] diff --git a/toolkit/mozapps/update/test/Makefile.in b/toolkit/mozapps/update/test/Makefile.in index b01aac72a..15ef9e552 100644 --- a/toolkit/mozapps/update/test/Makefile.in +++ b/toolkit/mozapps/update/test/Makefile.in @@ -21,10 +21,6 @@ DEFINES += \ -DMOZ_DEBUG=$(MOZ_DEBUG) \ $(NULL) -ifdef MOZ_MAINTENANCE_SERVICE -DEFINES += -DMOZ_MAINTENANCE_SERVICE=$(MOZ_MAINTENANCE_SERVICE) -endif - ifneq (android,$(MOZ_WIDGET_TOOLKIT)) # TODO: Remove when SIMPLE_PROGRAMS is in moz.build cppsrcs = \ diff --git a/toolkit/mozapps/update/test/unit/head_update.js.in b/toolkit/mozapps/update/test/unit/head_update.js.in index ae354e9b0..353d88091 100644 --- a/toolkit/mozapps/update/test/unit/head_update.js.in +++ b/toolkit/mozapps/update/test/unit/head_update.js.in @@ -291,11 +291,7 @@ var DEBUG_AUS_TEST = true; #include ../shared.js -#ifdef MOZ_MAINTENANCE_SERVICE -const STATE_APPLIED_PLATFORM = STATE_APPLIED_SVC; -#else const STATE_APPLIED_PLATFORM = STATE_APPLIED; -#endif // This makes it possible to run most tests on xulrunner where the update // channel default preference is not set. diff --git a/toolkit/mozapps/update/test_svc/Makefile.in b/toolkit/mozapps/update/test_svc/Makefile.in deleted file mode 100644 index 80b32f15d..000000000 --- a/toolkit/mozapps/update/test_svc/Makefile.in +++ /dev/null @@ -1,39 +0,0 @@ -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -DEPTH = @DEPTH@ -topsrcdir = @top_srcdir@ -srcdir = @srcdir@ -VPATH = @srcdir@ -relativesrcdir = @relativesrcdir@ - -include $(DEPTH)/config/autoconf.mk - -TESTROOT = $(call core_abspath,$(DEPTH))/_tests/xpcshell/$(relativesrcdir) - -DEFINES += \ - -DAB_CD=$(AB_CD) \ - -DMOZ_APP_NAME=$(MOZ_APP_NAME) \ - -DMOZ_APP_DISPLAYNAME="$(MOZ_APP_DISPLAYNAME)" \ - -DBIN_SUFFIX=$(BIN_SUFFIX) \ - -DNS_NO_XPCOM \ - -DMOZ_DEBUG=$(MOZ_DEBUG) \ - $(NULL) - -# For debugging purposes only -#DEFINES += -DDISABLE_UPDATER_AUTHENTICODE_CHECK - -include $(topsrcdir)/config/rules.mk - -libs:: ../test/unit/head_update.js.in - $(PYTHON) $(MOZILLA_DIR)/config/Preprocessor.py -Fsubstitution $(DEFINES) $(ACDEFINES) $^ > $(TESTROOT)/unit/head_update.js - -ifneq ($(OS_TARGET),Android) -ifndef MOZ_PROFILE_GENERATE -libs:: - $(INSTALL) ../test/TestAUSHelper$(BIN_SUFFIX) $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit - $(INSTALL) -D $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit/data - $(INSTALL) $(topsrcdir)/$(relativesrcdir)/../test/unit/data/* $(DEPTH)/_tests/xpcshell/$(relativesrcdir)/unit/data -endif -endif # Not Android diff --git a/toolkit/mozapps/update/test_svc/moz.build b/toolkit/mozapps/update/test_svc/moz.build deleted file mode 100644 index 191c90f0b..000000000 --- a/toolkit/mozapps/update/test_svc/moz.build +++ /dev/null @@ -1,7 +0,0 @@ -# -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- -# vim: set filetype=python: -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini'] diff --git a/toolkit/mozapps/update/test_svc/unit/test_0000_bootstrap_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0000_bootstrap_svc.js deleted file mode 100644 index a1cac2c5f..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0000_bootstrap_svc.js +++ /dev/null @@ -1,44 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* Bootstrap the tests using the service by installing our own version of the service */ - -const TEST_ID = "0000_svc"; - -const TEST_FILES = [ -{ - description : "the dummy file to make sure that the update worked", - fileName : "dummy", - relPathDir : "/", - originalContents : null, - compareContents : "", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -} -]; - -function run_test() { - if (!shouldRunServiceTest(true)) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_COMPLETE_FILE); - - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED, checkUpdateApplied, null, false); -} - -function checkUpdateApplied() { - checkFilesAfterUpdateSuccess(); - - // We need to check the service log even though this is a bootstrap - // because the app bin could be in use by this test by the time the next - // test runs. - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0110_general_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0110_general_svc.js deleted file mode 100644 index 0846bbd9c..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0110_general_svc.js +++ /dev/null @@ -1,264 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -/* General Complete MAR File Patch Apply Test */ - -const TEST_ID = "0110_svc"; -// All we care about is that the last modified time has changed so that Mac OS -// X Launch Services invalidates its cache so the test allows up to one minute -// difference in the last modified time. -const MAX_TIME_DIFFERENCE = 60000; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0767, - comparePerms : 0767 -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/complete_precomplete", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/complete_removed-files", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0777, - comparePerms : 0755 -}, { - description : "Added by update.manifest (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0767, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0777, - comparePerms : 0755 -}, { - description : "Added by update.manifest (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0677, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : 0776, - comparePerms : 0644 -}, { - description : "Removed by precomplete (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : true -}, { - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_COMPLETE_FILE); - - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - checkUpdateLogContents(LOG_COMPLETE_SUCCESS); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0111_general_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0111_general_svc.js deleted file mode 100644 index 7b589aa1a..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0111_general_svc.js +++ /dev/null @@ -1,268 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -/* General Partial MAR File Patch Apply Test */ - -const TEST_ID = "0111_svc"; -// All we care about is that the last modified time has changed so that Mac OS -// X Launch Services invalidates its cache so the test allows up to one minute -// difference in the last modified time. -const MAX_TIME_DIFFERENCE = 60000; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/partial_precomplete", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Patched by update.manifest (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Patched by update.manifest (patch)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Patched by update.manifest (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/partial.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Removed by update.manifest (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : true -}, { - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_PARTIAL_FILE); - - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - - // apply the partial mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED, checkUpdateApplied); -} - -function checkUpdateApplied() { - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - checkUpdateLogContents(LOG_PARTIAL_SUCCESS); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0112_general_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0112_general_svc.js deleted file mode 100644 index fa80292d3..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0112_general_svc.js +++ /dev/null @@ -1,263 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -/* General Partial MAR File Patch Apply Failure Test */ - -const TEST_ID = "0112_svc"; -// All we care about is that the last modified time has changed so that Mac OS -// X Launch Services invalidates its cache so the test allows up to one minute -// difference in the last modified time. -const MAX_TIME_DIFFERENCE = 60000; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0767, - comparePerms : null -}, { - description : "Not added for failed update (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/complete_precomplete", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0775 -}, { - description : "Not patched for failed update (patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not patched for failed update (patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Not patched for failed update (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Not patched for failed update (patch) and causes " + - "LoadSourceFile failed", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Not added for failed update (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Not patched for failed update (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not added for failed update (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Not added for failed update (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Not added for failed update (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Not removed for failed update (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null, - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not removed for failed update (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null, - originalPerms : 0666, - comparePerms : 0666 -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : false -}, { - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : false -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_PARTIAL_FILE); - - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - - // apply the partial mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_FAILED, checkUpdateApplied); -} - -function checkUpdateApplied() { - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - logTestInfo("testing update.status should be " + STATE_FAILED); - // The update status format for a failure is failed: # where # is the error - // code for the failure. - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - checkFilesAfterUpdateFailure(); - checkUpdateLogContents(LOG_PARTIAL_FAILURE); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0113_general_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0113_general_svc.js deleted file mode 100644 index 221c6d154..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0113_general_svc.js +++ /dev/null @@ -1,293 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -/* General Complete MAR File Background Patch Apply Test */ - -const TEST_ID = "0113_svc"; -// All we care about is that the last modified time has changed so that Mac OS -// X Launch Services invalidates its cache so the test allows up to one minute -// difference in the last modified time. -const MAX_TIME_DIFFERENCE = 60000; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0767, - comparePerms : 0767 -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/complete_precomplete", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/complete_removed-files", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0777, - comparePerms : 0755 -}, { - description : "Added by update.manifest (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0767, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0777, - comparePerms : 0755 -}, { - description : "Added by update.manifest (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0677, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : 0776, - comparePerms : 0644 -}, { - description : "Removed by precomplete (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : true -}, { - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_COMPLETE_FILE); - - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - checkFilesAfterUpdateSuccess(); - checkUpdateLogContents(LOG_COMPLETE_SUCCESS); - - // This shouldn't exist anyways in background updates, but let's make sure - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - toBeDeletedDir = getTargetDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for success when " + - "switching to the updated application"); - do_check_eq(exitValue, 0); - - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - checkUpdateLogContents(LOG_COMPLETE_SWITCH_SUCCESS); - - // This shouldn't exist anyways in background updates, but let's make sure - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - // Make sure that the intermediate directory has been removed - let applyToDir = getApplyDirFile(); - let updatedDir = applyToDir.clone(); - updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", "")); - do_check_false(updatedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0114_general_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0114_general_svc.js deleted file mode 100644 index a0c2858e4..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0114_general_svc.js +++ /dev/null @@ -1,297 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -/* General Partial MAR File Background Patch Apply Test */ - -const TEST_ID = "0114_svc"; -// All we care about is that the last modified time has changed so that Mac OS -// X Launch Services invalidates its cache so the test allows up to one minute -// difference in the last modified time. -const MAX_TIME_DIFFERENCE = 60000; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/partial_precomplete", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Patched by update.manifest (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Patched by update.manifest (patch)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Patched by update.manifest (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/partial.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Removed by update.manifest (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : true -}, { - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_PARTIAL_FILE); - - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - - // apply the partial mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - logTestInfo("testing update.status should be " + STATE_APPLIED); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - checkFilesAfterUpdateSuccess(); - checkUpdateLogContents(LOG_PARTIAL_SUCCESS); - - // This shouldn't exist anyways in background updates, but let's make sure - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - toBeDeletedDir = getTargetDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for success when " + - "switching to the updated application"); - do_check_eq(exitValue, 0); - - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - checkUpdateLogContents(LOG_PARTIAL_SWITCH_SUCCESS); - - // This shouldn't exist anyways in background updates, but let's make sure - logTestInfo("testing tobedeleted directory doesn't exist"); - toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - // Make sure that the intermediate directory has been removed - let applyToDir = getApplyDirFile(); - let updatedDir = applyToDir.clone(); - updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", "")); - do_check_false(updatedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0115_general_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0115_general_svc.js deleted file mode 100644 index 52802b210..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0115_general_svc.js +++ /dev/null @@ -1,267 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -/* General Partial MAR File Background Patch Apply Failure Test */ - -const TEST_ID = "0115_svc"; -// All we care about is that the last modified time has changed so that Mac OS -// X Launch Services invalidates its cache so the test allows up to one minute -// difference in the last modified time. -const MAX_TIME_DIFFERENCE = 60000; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0767, - comparePerms : null -}, { - description : "Not added for failed update (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/complete_precomplete", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0775 -}, { - description : "Not patched for failed update (patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not patched for failed update (patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Not patched for failed update (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Not patched for failed update (patch) and causes " + - "LoadSourceFile failed", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Not added for failed update (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Not patched for failed update (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not added for failed update (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Not added for failed update (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Not added for failed update (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Not removed for failed update (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null, - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Not removed for failed update (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null, - originalPerms : 0666, - comparePerms : 0666 -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : false -}, { - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : false -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_PARTIAL_FILE); - - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - - // apply the partial mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_FAILED, checkUpdateApplied); -} - -function checkUpdateApplied() { - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - logTestInfo("testing update.status should be " + STATE_FAILED); - // The update status format for a failure is failed: # where # is the error - // code for the failure. - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - checkFilesAfterUpdateFailure(); - checkUpdateLogContents(LOG_PARTIAL_FAILURE); - - // This shouldn't exist anyways in background updates, but let's make sure - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - toBeDeletedDir = getTargetDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - removeCallbackCopy(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0150_appBinReplaced_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0150_appBinReplaced_xp_win_complete_svc.js deleted file mode 100644 index 3a88d61e9..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0150_appBinReplaced_xp_win_complete_svc.js +++ /dev/null @@ -1,221 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* Replace app binary complete MAR file patch apply success test */ - -const TEST_ID = "0150_svc"; -const MAR_COMPLETE_WIN_FILE = "data/complete_win.mar"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/complete_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/complete_removed-files" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_after.exe", - compareFile : "data/partial_in_use_win_before.exe" -}, { - description : "Added by update.manifest (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_after.exe", - compareFile : "data/partial_in_use_win_before.exe" -}, { - description : "Added by update.manifest (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Removed by precomplete (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : true -}, { - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_COMPLETE_WIN_FILE); - - gCallbackBinFile = "exe0.exe"; - - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0151_appBinPatched_xp_win_partial_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0151_appBinPatched_xp_win_partial_svc.js deleted file mode 100644 index c5a4ca315..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0151_appBinPatched_xp_win_partial_svc.js +++ /dev/null @@ -1,223 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* Patch app binary partial MAR file patch apply success test */ - -const TEST_ID = "0151_svc"; -const MAR_IN_USE_WIN_FILE = "data/partial_win.mar"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_before.exe", - compareFile : "data/partial_in_use_win_after.exe" -}, { - description : "Patched by update.manifest (patch) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_before.exe", - compareFile : "data/partial_in_use_win_after.exe" -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : true -}, { - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_IN_USE_WIN_FILE); - - gCallbackBinFile = "exe0.exe"; - - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0152_appBinReplaced_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0152_appBinReplaced_xp_win_complete_svc.js deleted file mode 100644 index 785778598..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0152_appBinReplaced_xp_win_complete_svc.js +++ /dev/null @@ -1,233 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* Replace app binary complete MAR file background patch apply success test */ - -const TEST_ID = "0152_svc"; -const MAR_COMPLETE_WIN_FILE = "data/complete_win.mar"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/complete_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/complete_removed-files" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_after.exe", - compareFile : "data/partial_in_use_win_before.exe" -}, { - description : "Added by update.manifest (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_after.exe", - compareFile : "data/partial_in_use_win_before.exe" -}, { - description : "Added by update.manifest (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Removed by precomplete (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : true -}, { - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_COMPLETE_WIN_FILE); - - gCallbackBinFile = "exe0.exe"; - - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for success when " + - "switching to the updated application"); - do_check_eq(exitValue, 0); - - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0153_appBinPatched_xp_win_partial_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0153_appBinPatched_xp_win_partial_svc.js deleted file mode 100644 index c34b6a820..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0153_appBinPatched_xp_win_partial_svc.js +++ /dev/null @@ -1,235 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* Patch app binary partial MAR file background patch apply success test */ - -const TEST_ID = "0153_svc"; -const MAR_IN_USE_WIN_FILE = "data/partial_win.mar"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_before.exe", - compareFile : "data/partial_in_use_win_after.exe" -}, { - description : "Patched by update.manifest (patch) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_before.exe", - compareFile : "data/partial_in_use_win_after.exe" -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : true -}, { - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_IN_USE_WIN_FILE); - - gCallbackBinFile = "exe0.exe"; - - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for success when " + - "switching to the updated application"); - do_check_eq(exitValue, 0); - - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0160_appInUse_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0160_appInUse_complete_svc.js deleted file mode 100644 index 449ca08fe..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0160_appInUse_complete_svc.js +++ /dev/null @@ -1,310 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* This test mirrors ../../test/unit/test_0160_appInUse_complete.js but does the - * update using the service. This test only runs on Windows but the blocks like - * IS_MACOSX are preserved to make it easy to spot differences between the 2 - * mirrored tests. */ - -/* Application in use complete MAR file patch apply success test */ - -const TEST_ID = "0160_svc"; -// All we care about is that the last modified time has changed so that Mac OS -// X Launch Services invalidates its cache so the test allows up to one minute -// difference in the last modified time. -const MAX_TIME_DIFFERENCE = 60000; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0767, - comparePerms : 0767 -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/complete_precomplete", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/complete_removed-files", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0777, - comparePerms : 0755 -}, { - description : "Added by update.manifest (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0767, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png", - originalPerms : 0777, - comparePerms : 0755 -}, { - description : "Added by update.manifest (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0677, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png", - originalPerms : 0776, - comparePerms : 0644 -}, { - description : "Removed by precomplete (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : true -}, { - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_COMPLETE_FILE); - - // Launch the callback helper application so it is in use during the update - let callbackApp = getApplyDirFile("a/b/" + gCallbackBinFile); - callbackApp.permissions = PERMS_DIRECTORY; - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "20"]; - let callbackAppProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - callbackAppProcess.init(callbackApp); - callbackAppProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - let applyToDir = getApplyDirFile(); - - // For Mac OS X set the last modified time for the root directory to a date in - // the past to test that the last modified time is updated on a successful - // update (bug 600098). - if (IS_MACOSX) { - let now = Date.now(); - let yesterday = now - (1000 * 60 * 60 * 24); - applyToDir.lastModifiedTime = yesterday; - } - - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED, checkUpdateApplied); -} - -function checkUpdateApplied() { - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - // For Mac OS X check that the last modified time for a directory has been - // updated after a successful update (bug 600098). - if (IS_MACOSX) { - logTestInfo("testing last modified time on the apply to directory has " + - "changed after a successful update (bug 600098)"); - let now = Date.now(); - let applyToDir = getApplyDirFile(); - let timeDiff = Math.abs(applyToDir.lastModifiedTime - now); - do_check_true(timeDiff < MAX_TIME_DIFFERENCE); - } - - checkFilesAfterUpdateSuccess(); - checkUpdateLogContents(LOG_COMPLETE_SUCCESS); - - if (IS_WIN) { - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - } - - checkCallbackServiceLog(); -} - diff --git a/toolkit/mozapps/update/test_svc/unit/test_0161_appInUse_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0161_appInUse_xp_win_complete_svc.js deleted file mode 100644 index a04d54561..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0161_appInUse_xp_win_complete_svc.js +++ /dev/null @@ -1,245 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* Application in use complete MAR file background patch apply failure test */ - -const TEST_ID = "0161_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/partial_removed-files" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not removed for failed update (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Not removed for failed update (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : false -}, { - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : false -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_COMPLETE_FILE); - - // Launch the callback helper application so it is in use during the update - let callbackApp = getApplyDirFile("a/b/" + gCallbackBinFile); - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40"]; - let callbackAppProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - callbackAppProcess.init(callbackApp); - callbackAppProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - gDisableReplaceFallback = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - // The update status format for a failure is failed: # where # is the error - // code for the failure. - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0162_appInUse_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0162_appInUse_xp_win_complete_svc.js deleted file mode 100644 index 19cc5a738..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0162_appInUse_xp_win_complete_svc.js +++ /dev/null @@ -1,242 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* Application in use complete MAR file background patch apply failure fallback test */ - -const TEST_ID = "0162_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/partial_removed-files" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not removed for failed update (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Not removed for failed update (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : false -}, { - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : false -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_COMPLETE_FILE); - - // Launch the callback helper application so it is in use during the update - let callbackApp = getApplyDirFile("a/b/" + gCallbackBinFile); - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40"]; - let callbackAppProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - callbackAppProcess.init(callbackApp); - callbackAppProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_PENDING); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_PENDING); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0170_fileLocked_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0170_fileLocked_xp_win_complete_svc.js deleted file mode 100644 index b7c4dfb59..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0170_fileLocked_xp_win_complete_svc.js +++ /dev/null @@ -1,239 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File locked complete MAR file patch apply failure test */ - -const TEST_ID = "0170_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/partial_removed-files" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not removed for failed update (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Not removed for failed update (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : false -}, { - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : false -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_COMPLETE_FILE); - - // Exclusively lock an existing file so it is in use during the update - let helperBin = do_get_file(HELPER_BIN_FILE); - let helperDestDir = getApplyDirFile("a/b/"); - helperBin.copyTo(helperDestDir, HELPER_BIN_FILE); - helperBin = getApplyDirFile("a/b/" + HELPER_BIN_FILE); - // Strip off the first two directories so the path has to be from the helper's - // working directory. - let lockFileRelPath = TEST_FILES[3].relPathDir.split("/"); - lockFileRelPath = lockFileRelPath.slice(2); - lockFileRelPath = lockFileRelPath.join("/") + "/" + TEST_FILES[3].fileName; - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "20", lockFileRelPath]; - let lockFileProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - lockFileProcess.init(helperBin); - lockFileProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_FAILED, checkUpdateApplied); -} - -function checkUpdateApplied() { - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - // The update status format for a failure is failed: # where # is the error - // code for the failure. - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - checkFilesAfterUpdateFailure(); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0171_fileLocked_xp_win_partial_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0171_fileLocked_xp_win_partial_svc.js deleted file mode 100644 index 29beb73c6..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0171_fileLocked_xp_win_partial_svc.js +++ /dev/null @@ -1,240 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File locked partial MAR file patch apply failure test */ - -const TEST_ID = "0171_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/complete_precomplete" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch) and causes " + - "LoadSourceFile failed", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not added for failed update (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not removed for failed update (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Not removed for failed update (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : false -}, { - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : false -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_PARTIAL_FILE); - - // Exclusively lock an existing file so it is in use during the update - let helperBin = do_get_file(HELPER_BIN_FILE); - let helperDestDir = getApplyDirFile("a/b/"); - helperBin.copyTo(helperDestDir, HELPER_BIN_FILE); - helperBin = getApplyDirFile("a/b/" + HELPER_BIN_FILE); - // Strip off the first two directories so the path has to be from the helper's - // working directory. - let lockFileRelPath = TEST_FILES[3].relPathDir.split("/"); - lockFileRelPath = lockFileRelPath.slice(2); - lockFileRelPath = lockFileRelPath.join("/") + "/" + TEST_FILES[3].fileName; - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "20", lockFileRelPath]; - let lockFileProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - lockFileProcess.init(helperBin); - lockFileProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_FAILED, checkUpdateApplied); -} - -function checkUpdateApplied() { - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - // The update status format for a failure is failed: # where # is the error - // code for the failure. - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - checkFilesAfterUpdateFailure(); - checkUpdateLogContains(ERR_UNABLE_OPEN_DEST); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0172_fileLocked_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0172_fileLocked_xp_win_complete_svc.js deleted file mode 100644 index af8b68693..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0172_fileLocked_xp_win_complete_svc.js +++ /dev/null @@ -1,253 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File locked complete MAR file background patch apply failure test */ - -const TEST_ID = "0172_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/partial_removed-files" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not removed for failed update (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Not removed for failed update (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : false -}, { - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : false -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_COMPLETE_FILE); - - // Exclusively lock an existing file so it is in use during the update - let helperBin = do_get_file(HELPER_BIN_FILE); - let helperDestDir = getApplyDirFile("a/b/"); - helperBin.copyTo(helperDestDir, HELPER_BIN_FILE); - helperBin = getApplyDirFile("a/b/" + HELPER_BIN_FILE); - // Strip off the first two directories so the path has to be from the helper's - // working directory. - let lockFileRelPath = TEST_FILES[3].relPathDir.split("/"); - lockFileRelPath = lockFileRelPath.slice(2); - lockFileRelPath = lockFileRelPath.join("/") + "/" + TEST_FILES[3].fileName; - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40", lockFileRelPath]; - let lockFileProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - lockFileProcess.init(helperBin); - lockFileProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_FAILED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - gDisableReplaceFallback = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - // The update status format for a failure is failed: # where # is the error - // code for the failure. - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0173_fileLocked_xp_win_partial_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0173_fileLocked_xp_win_partial_svc.js deleted file mode 100644 index dabcb801e..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0173_fileLocked_xp_win_partial_svc.js +++ /dev/null @@ -1,254 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File locked partial MAR file background patch apply failure test */ - -const TEST_ID = "0173_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/complete_precomplete" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch) and causes " + - "LoadSourceFile failed", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not added for failed update (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not removed for failed update (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Not removed for failed update (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : false -}, { - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : false -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_PARTIAL_FILE); - - // Exclusively lock an existing file so it is in use during the update - let helperBin = do_get_file(HELPER_BIN_FILE); - let helperDestDir = getApplyDirFile("a/b/"); - helperBin.copyTo(helperDestDir, HELPER_BIN_FILE); - helperBin = getApplyDirFile("a/b/" + HELPER_BIN_FILE); - // Strip off the first two directories so the path has to be from the helper's - // working directory. - let lockFileRelPath = TEST_FILES[3].relPathDir.split("/"); - lockFileRelPath = lockFileRelPath.slice(2); - lockFileRelPath = lockFileRelPath.join("/") + "/" + TEST_FILES[3].fileName; - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40", lockFileRelPath]; - let lockFileProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - lockFileProcess.init(helperBin); - lockFileProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_FAILED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - gDisableReplaceFallback = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - // The update status format for a failure is failed: # where # is the error - // code for the failure. - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0174_fileLocked_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0174_fileLocked_xp_win_complete_svc.js deleted file mode 100644 index 6ca0ff7e6..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0174_fileLocked_xp_win_complete_svc.js +++ /dev/null @@ -1,250 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File locked complete MAR file background patch apply failure fallback test */ - -const TEST_ID = "0174_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/partial_removed-files" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not removed for failed update (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Not removed for failed update (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : false -}, { - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : false -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_COMPLETE_FILE); - - // Exclusively lock an existing file so it is in use during the update - let helperBin = do_get_file(HELPER_BIN_FILE); - let helperDestDir = getApplyDirFile("a/b/"); - helperBin.copyTo(helperDestDir, HELPER_BIN_FILE); - helperBin = getApplyDirFile("a/b/" + HELPER_BIN_FILE); - // Strip off the first two directories so the path has to be from the helper's - // working directory. - let lockFileRelPath = TEST_FILES[3].relPathDir.split("/"); - lockFileRelPath = lockFileRelPath.slice(2); - lockFileRelPath = lockFileRelPath.join("/") + "/" + TEST_FILES[3].fileName; - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40", lockFileRelPath]; - let lockFileProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - lockFileProcess.init(helperBin); - lockFileProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_FAILED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_PENDING); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_PENDING); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0175_fileLocked_xp_win_partial_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0175_fileLocked_xp_win_partial_svc.js deleted file mode 100644 index 3aa2a0de9..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0175_fileLocked_xp_win_partial_svc.js +++ /dev/null @@ -1,251 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File locked partial MAR file background patch apply failure fallback test */ - -const TEST_ID = "0175_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/complete_precomplete" -}, { - description : "Not added for failed update (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not added for failed update (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not patched for failed update (patch) and causes " + - "LoadSourceFile failed", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Not added for failed update (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Not patched for failed update (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Not added for failed update (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not added for failed update (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Not removed for failed update (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Not removed for failed update (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : false -}, { - description : "Not removed for failed update (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : false -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_PARTIAL_FILE); - - // Exclusively lock an existing file so it is in use during the update - let helperBin = do_get_file(HELPER_BIN_FILE); - let helperDestDir = getApplyDirFile("a/b/"); - helperBin.copyTo(helperDestDir, HELPER_BIN_FILE); - helperBin = getApplyDirFile("a/b/" + HELPER_BIN_FILE); - // Strip off the first two directories so the path has to be from the helper's - // working directory. - let lockFileRelPath = TEST_FILES[3].relPathDir.split("/"); - lockFileRelPath = lockFileRelPath.slice(2); - lockFileRelPath = lockFileRelPath.join("/") + "/" + TEST_FILES[3].fileName; - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40", lockFileRelPath]; - let lockFileProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - lockFileProcess.init(helperBin); - lockFileProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_FAILED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_PENDING); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_PENDING); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory doesn't exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0180_fileInUse_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0180_fileInUse_xp_win_complete_svc.js deleted file mode 100644 index e5ad35d0f..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0180_fileInUse_xp_win_complete_svc.js +++ /dev/null @@ -1,236 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use complete MAR file patch apply success test */ - -const TEST_ID = "0180_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/complete_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/complete_removed-files" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Removed by precomplete (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : true -}, { - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_COMPLETE_FILE); - - // Launch an existing file so it is in use during the update - let fileInUseBin = getApplyDirFile(TEST_FILES[14].relPathDir + - TEST_FILES[14].fileName); - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "20"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED, checkUpdateApplied); -} - -function checkUpdateApplied() { - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - checkUpdateLogContains(ERR_BACKUP_DISCARD); - - logTestInfo("testing tobedeleted directory exists"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_true(toBeDeletedDir.exists()); - - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0181_fileInUse_xp_win_partial_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0181_fileInUse_xp_win_partial_svc.js deleted file mode 100644 index b61f10996..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0181_fileInUse_xp_win_partial_svc.js +++ /dev/null @@ -1,239 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use partial MAR file patch apply success test */ - -const TEST_ID = "0181_svc"; -const MAR_IN_USE_WIN_FILE = "data/partial_win.mar"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Patched by update.manifest (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_before.exe", - compareFile : "data/partial_in_use_win_after.exe" -}, { - description : "Patched by update.manifest (patch) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_before.exe", - compareFile : "data/partial_in_use_win_after.exe" -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : true -}, { - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_IN_USE_WIN_FILE); - - // Launch an existing file so it is in use during the update - let fileInUseBin = getApplyDirFile(TEST_FILES[12].relPathDir + - TEST_FILES[12].fileName); - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "20"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED, checkUpdateApplied); -} - -function checkUpdateApplied() { - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - checkUpdateLogContains(ERR_BACKUP_DISCARD); - - logTestInfo("testing tobedeleted directory exists"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_true(toBeDeletedDir.exists()); - - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0182_rmrfdirFileInUse_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0182_rmrfdirFileInUse_xp_win_complete_svc.js deleted file mode 100644 index e4fa4cc75..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0182_rmrfdirFileInUse_xp_win_complete_svc.js +++ /dev/null @@ -1,246 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use inside removed dir complete MAR file patch apply success test */ - -const TEST_ID = "0182_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/complete_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/complete_removed-files" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "FromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/complete.png" -}, { - description : "Removed by precomplete (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : true -}, { - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_COMPLETE_FILE); - - let fileInUseBin = getApplyDirFile(TEST_DIRS[4].relPathDir + - TEST_DIRS[4].subDirs[0] + - TEST_DIRS[4].subDirFiles[0]); - // Remove the empty file created for the test so the helper application can - // replace it. - fileInUseBin.remove(false); - - let helperBin = do_get_file(HELPER_BIN_FILE); - let fileInUseDir = getApplyDirFile(TEST_DIRS[4].relPathDir + - TEST_DIRS[4].subDirs[0]); - helperBin.copyTo(fileInUseDir, TEST_DIRS[4].subDirFiles[0]); - - // Launch an existing file so it is in use during the update - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "20"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED, checkUpdateApplied); -} - -function checkUpdateApplied() { - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - checkUpdateLogContains(ERR_BACKUP_DISCARD); - - logTestInfo("testing tobedeleted directory exists"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_true(toBeDeletedDir.exists()); - - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0183_rmrfdirFileInUse_xp_win_partial_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0183_rmrfdirFileInUse_xp_win_partial_svc.js deleted file mode 100644 index 20736b70f..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0183_rmrfdirFileInUse_xp_win_partial_svc.js +++ /dev/null @@ -1,287 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use inside removed dir partial MAR file patch apply success test */ - -const TEST_ID = "0183_svc"; -const MAR_IN_USE_WIN_FILE = "data/partial.mar"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/partial_precomplete", - originalPerms : 0666, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Patched by update.manifest (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0755, - comparePerms : null -}, { - description : "Patched by update.manifest (patch)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0755, - comparePerms : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : null -}, { - description : "Patched by update.manifest (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/partial.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : "data/partial.png", - originalPerms : null, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : "FromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : 0644 -}, { - description : "Removed by update.manifest (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeDeleted\n", - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : true -}, { - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - setupUpdaterTest(MAR_IN_USE_WIN_FILE); - - let fileInUseBin = getApplyDirFile(TEST_DIRS[2].relPathDir + - TEST_DIRS[2].files[0]); - // Remove the empty file created for the test so the helper application can - // replace it. - fileInUseBin.remove(false); - - let helperBin = do_get_file(HELPER_BIN_FILE); - let fileInUseDir = getApplyDirFile(TEST_DIRS[2].relPathDir); - helperBin.copyTo(fileInUseDir, TEST_DIRS[2].files[0]); - - // Launch an existing file so it is in use during the update - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "20"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED, checkUpdateApplied); -} - -function checkUpdateApplied() { - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_SUCCEEDED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - - checkFilesAfterUpdateSuccess(); - checkUpdateLogContains(ERR_BACKUP_DISCARD); - - logTestInfo("testing tobedeleted directory exists"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_true(toBeDeletedDir.exists()); - - checkCallbackServiceLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0184_fileInUse_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0184_fileInUse_xp_win_complete_svc.js deleted file mode 100644 index 5392866f1..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0184_fileInUse_xp_win_complete_svc.js +++ /dev/null @@ -1,250 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use complete MAR file background patch apply success test */ - -const TEST_ID = "0184_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/partial_removed-files" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : HELPER_BIN_FILE -}, { - description : "Added by update.manifest (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : HELPER_BIN_FILE -}, { - description : "Added by update.manifest (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : true -}, { - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_COMPLETE_FILE); - - // Launch an existing file so it is in use during the update - let fileInUseBin = getApplyDirFile(TEST_FILES[14].relPathDir + - TEST_FILES[14].fileName); - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - gDisableReplaceFallback = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory does not exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0185_fileInUse_xp_win_partial_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0185_fileInUse_xp_win_partial_svc.js deleted file mode 100644 index e42bc774f..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0185_fileInUse_xp_win_partial_svc.js +++ /dev/null @@ -1,253 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use partial MAR file background patch apply success test */ - -const TEST_ID = "0185_svc"; -const MAR_IN_USE_WIN_FILE = "data/partial_win.mar"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/complete_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Patched by update.manifest (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_before.exe", - compareFile : "data/partial_in_use_win_before.exe" -}, { - description : "Patched by update.manifest (patch) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_before.exe", - compareFile : "data/partial_in_use_win_before.exe" -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : true -}, { - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_IN_USE_WIN_FILE); - - // Launch an existing file so it is in use during the update - let fileInUseBin = getApplyDirFile(TEST_FILES[12].relPathDir + - TEST_FILES[12].fileName); - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - gDisableReplaceFallback = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory does not exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0186_rmrfdirFileInUse_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0186_rmrfdirFileInUse_xp_win_complete_svc.js deleted file mode 100644 index 78962d9e7..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0186_rmrfdirFileInUse_xp_win_complete_svc.js +++ /dev/null @@ -1,259 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use inside removed dir complete MAR file background patch apply success test */ - -const TEST_ID = "0186_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/partial_removed-files" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : HELPER_BIN_FILE -}, { - description : "Added by update.manifest (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : HELPER_BIN_FILE -}, { - description : "Added by update.manifest (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : true -}, { - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_COMPLETE_FILE); - - let fileInUseBin = getApplyDirFile(TEST_DIRS[4].relPathDir + - TEST_DIRS[4].subDirs[0] + - TEST_DIRS[4].subDirFiles[0]); - // Remove the empty file created for the test so the helper application can - // replace it. - fileInUseBin.remove(false); - - let helperBin = do_get_file(HELPER_BIN_FILE); - let fileInUseDir = getApplyDirFile(TEST_DIRS[4].relPathDir + - TEST_DIRS[4].subDirs[0]); - helperBin.copyTo(fileInUseDir, TEST_DIRS[4].subDirFiles[0]); - - // Launch an existing file so it is in use during the update - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - gDisableReplaceFallback = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory does not exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0187_rmrfdirFileInUse_xp_win_partial_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0187_rmrfdirFileInUse_xp_win_partial_svc.js deleted file mode 100644 index 9b05af0f0..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0187_rmrfdirFileInUse_xp_win_partial_svc.js +++ /dev/null @@ -1,300 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use inside removed dir partial MAR file background patch apply success test */ - -const TEST_ID = "0187_svc"; -const MAR_IN_USE_WIN_FILE = "data/partial.mar"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/complete_precomplete", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0775 -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : null -}, { - description : "Patched by update.manifest (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Patched by update.manifest (patch)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Patched by update.manifest (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Added by update.manifest (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : true -}, { - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_IN_USE_WIN_FILE); - - let fileInUseBin = getApplyDirFile(TEST_DIRS[2].relPathDir + - TEST_DIRS[2].files[0]); - // Remove the empty file created for the test so the helper application can - // replace it. - fileInUseBin.remove(false); - - let helperBin = do_get_file(HELPER_BIN_FILE); - let fileInUseDir = getApplyDirFile(TEST_DIRS[2].relPathDir); - helperBin.copyTo(fileInUseDir, TEST_DIRS[2].files[0]); - - // Launch an existing file so it is in use during the update - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - gDisableReplaceFallback = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_FAILED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir).split(": ")[0], STATE_FAILED); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory does not exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0188_fileInUse_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0188_fileInUse_xp_win_complete_svc.js deleted file mode 100644 index 5dbe420be..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0188_fileInUse_xp_win_complete_svc.js +++ /dev/null @@ -1,249 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use complete MAR file background patch apply failure fallback test */ - -const TEST_ID = "0188_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/partial_removed-files" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : HELPER_BIN_FILE -}, { - description : "Added by update.manifest (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : HELPER_BIN_FILE -}, { - description : "Added by update.manifest (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : true -}, { - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_COMPLETE_FILE); - - // Launch an existing file so it is in use during the update - let fileInUseBin = getApplyDirFile(TEST_FILES[14].relPathDir + - TEST_FILES[14].fileName); - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_PENDING); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_PENDING); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory does not exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0189_fileInUse_xp_win_partial_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0189_fileInUse_xp_win_partial_svc.js deleted file mode 100644 index d55ec0389..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0189_fileInUse_xp_win_partial_svc.js +++ /dev/null @@ -1,252 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use partial MAR file background patch apply failure fallback test */ - -const TEST_ID = "0189_svc"; -const MAR_IN_USE_WIN_FILE = "data/partial_win.mar"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/complete_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Patched by update.manifest (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_before.exe", - compareFile : "data/partial_in_use_win_before.exe" -}, { - description : "Patched by update.manifest (patch) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_in_use_win_before.exe", - compareFile : "data/partial_in_use_win_before.exe" -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null -}, { - description : "Patched by update.manifest (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png" -}, { - description : "Added by update.manifest (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : true -}, { - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_IN_USE_WIN_FILE); - - // Launch an existing file so it is in use during the update - let fileInUseBin = getApplyDirFile(TEST_FILES[12].relPathDir + - TEST_FILES[12].fileName); - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - // apply the complete mar - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_PENDING); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_PENDING); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory does not exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0190_rmrfdirFileInUse_xp_win_complete_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0190_rmrfdirFileInUse_xp_win_complete_svc.js deleted file mode 100644 index f26be5b61..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0190_rmrfdirFileInUse_xp_win_complete_svc.js +++ /dev/null @@ -1,258 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use inside removed dir complete MAR file background patch apply failure fallback test */ - -const TEST_ID = "0190_svc"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/partial_precomplete", - compareFile : "data/partial_precomplete" -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest (add)", - fileName : "removed-files", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/partial_removed-files", - compareFile : "data/partial_removed-files" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : HELPER_BIN_FILE -}, { - description : "Added by update.manifest (add)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add) file in use", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : HELPER_BIN_FILE, - compareFile : HELPER_BIN_FILE -}, { - description : "Added by update.manifest (add)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromComplete\n", - compareContents : "ToBeReplacedWithFromComplete\n", - originalFile : null, - compareFile : null -}, { - description : "Added by update.manifest (add)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}, { - description : "Removed by precomplete (remove)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/20/", - dirRemoved : true -}, { - description : "Removed by precomplete (rmdir)", - relPathDir : "a/b/2/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_COMPLETE_FILE); - - let fileInUseBin = getApplyDirFile(TEST_DIRS[4].relPathDir + - TEST_DIRS[4].subDirs[0] + - TEST_DIRS[4].subDirFiles[0]); - // Remove the empty file created for the test so the helper application can - // replace it. - fileInUseBin.remove(false); - - let helperBin = do_get_file(HELPER_BIN_FILE); - let fileInUseDir = getApplyDirFile(TEST_DIRS[4].relPathDir + - TEST_DIRS[4].subDirs[0]); - helperBin.copyTo(fileInUseDir, TEST_DIRS[4].subDirFiles[0]); - - // Launch an existing file so it is in use during the update - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_PENDING); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_PENDING); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory does not exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0191_rmrfdirFileInUse_xp_win_partial_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0191_rmrfdirFileInUse_xp_win_partial_svc.js deleted file mode 100644 index 093316579..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0191_rmrfdirFileInUse_xp_win_partial_svc.js +++ /dev/null @@ -1,299 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* File in use inside removed dir partial MAR file background patch apply failure fallback test */ - -const TEST_ID = "0191_svc"; -const MAR_IN_USE_WIN_FILE = "data/partial.mar"; - -// The files are listed in the same order as they are applied from the mar's -// update.manifest. Complete updates have remove file and rmdir directory -// operations located in the precomplete file performed first. -const TEST_FILES = [ -{ - description : "Should never change", - fileName : "channel-prefs.js", - relPathDir : "a/b/defaults/pref/", - originalContents : "ShouldNotBeReplaced\n", - compareContents : "ShouldNotBeReplaced\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Added by update.manifest (add)", - fileName : "precomplete", - relPathDir : "", - originalContents : null, - compareContents : null, - originalFile : "data/complete_precomplete", - compareFile : "data/complete_precomplete", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest (add)", - fileName : "searchpluginstext0", - relPathDir : "a/b/searchplugins/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0775, - comparePerms : 0775 -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng1.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Patched by update.manifest if the file exists " + - "(patch-if)", - fileName : "searchpluginspng0.png", - relPathDir : "a/b/searchplugins/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions1text0", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png1.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions1png0.png", - relPathDir : "a/b/extensions/extensions1/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest if the parent directory " + - "exists (add-if)", - fileName : "extensions0text0", - relPathDir : "a/b/extensions/extensions0/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png1.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : null -}, { - description : "Patched by update.manifest if the parent directory " + - "exists (patch-if)", - fileName : "extensions0png0.png", - relPathDir : "a/b/extensions/extensions0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : null, - comparePerms : null -}, { - description : "Patched by update.manifest (patch)", - fileName : "exe0.exe", - relPathDir : "a/b/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Patched by update.manifest (patch)", - fileName : "0exe0.exe", - relPathDir : "a/b/0/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0755, - comparePerms : 0755 -}, { - description : "Added by update.manifest (add)", - fileName : "00text0", - relPathDir : "a/b/0/00/", - originalContents : "ToBeReplacedWithFromPartial\n", - compareContents : "ToBeReplacedWithFromPartial\n", - originalFile : null, - compareFile : null, - originalPerms : 0644, - comparePerms : 0644 -}, { - description : "Patched by update.manifest (patch)", - fileName : "00png0.png", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : "data/complete.png", - compareFile : "data/complete.png", - originalPerms : 0666, - comparePerms : 0666 -}, { - description : "Added by update.manifest (add)", - fileName : "20text0", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Added by update.manifest (add)", - fileName : "20png0.png", - relPathDir : "a/b/2/20/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Added by update.manifest (add)", - fileName : "00text2", - relPathDir : "a/b/0/00/", - originalContents : null, - compareContents : null, - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "10text0", - relPathDir : "a/b/1/10/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}, { - description : "Removed by update.manifest (remove)", - fileName : "00text1", - relPathDir : "a/b/0/00/", - originalContents : "ToBeDeleted\n", - compareContents : "ToBeDeleted\n", - originalFile : null, - compareFile : null, - originalPerms : null, - comparePerms : null -}]; - -ADDITIONAL_TEST_DIRS = [ -{ - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/10/", - dirRemoved : true -}, { - description : "Removed by update.manifest (rmdir)", - relPathDir : "a/b/1/", - dirRemoved : true -}]; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(cleanupUpdaterTest); - - gBackgroundUpdate = true; - setupUpdaterTest(MAR_IN_USE_WIN_FILE); - - let fileInUseBin = getApplyDirFile(TEST_DIRS[2].relPathDir + - TEST_DIRS[2].files[0]); - // Remove the empty file created for the test so the helper application can - // replace it. - fileInUseBin.remove(false); - - let helperBin = do_get_file(HELPER_BIN_FILE); - let fileInUseDir = getApplyDirFile(TEST_DIRS[2].relPathDir); - helperBin.copyTo(fileInUseDir, TEST_DIRS[2].files[0]); - - // Launch an existing file so it is in use during the update - let args = [getApplyDirPath() + "a/b/", "input", "output", "-s", "40"]; - let fileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - fileInUseProcess.init(fileInUseBin); - fileInUseProcess.run(false, args, args.length); - - do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); -} - -function doUpdate() { - runUpdateUsingService(STATE_PENDING_SVC, STATE_APPLIED, checkUpdateApplied); -} - -function checkUpdateApplied() { - logTestInfo("testing update.status should be " + STATE_APPLIED); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_APPLIED); - - // Now switch the application and its updated version - gBackgroundUpdate = false; - gSwitchApp = true; - exitValue = runUpdate(); - logTestInfo("testing updater binary process exitValue for failure when " + - "switching to the updated application"); - do_check_eq(exitValue, 1); - - setupHelperFinish(); -} - -function checkUpdate() { - logTestInfo("testing update.status should be " + STATE_PENDING); - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - do_check_eq(readStatusFile(updatesDir), STATE_PENDING); - - checkFilesAfterUpdateFailure(getApplyDirFile); - checkUpdateLogContains(ERR_RENAME_FILE); - - logTestInfo("testing tobedeleted directory does not exist"); - let toBeDeletedDir = getApplyDirFile("tobedeleted", true); - do_check_false(toBeDeletedDir.exists()); - - checkCallbackAppLog(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0200_app_launch_apply_update_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0200_app_launch_apply_update_svc.js deleted file mode 100644 index 167c738ee..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0200_app_launch_apply_update_svc.js +++ /dev/null @@ -1,272 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/* Test applying an update by staging an update and launching an application */ - -/** - * The MAR file used for this test should not contain a version 2 update - * manifest file (e.g. updatev2.manifest). - */ - -const TEST_ID = "0200_svc"; - -// Backup the updater.ini and use a custom one to prevent the updater from -// launching a post update executable. -const FILE_UPDATER_INI_BAK = "updater.ini.bak"; - -// Number of milliseconds for each do_timeout call. -const CHECK_TIMEOUT_MILLI = 1000; - -// How many of CHECK_TIMEOUT_MILLI to wait before we abort the test. -const MAX_TIMEOUT_RUNS = 300; - -let gTimeoutRuns = 0; - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(end_test); - - removeUpdateDirsAndFiles(); - - if (!gAppBinPath) { - do_throw("Main application binary not found... expected: " + - APP_BIN_NAME + APP_BIN_SUFFIX); - return; - } - - gEnvSKipUpdateDirHashing = true; - let channel = Services.prefs.getCharPref(PREF_APP_UPDATE_CHANNEL); - let patches = getLocalPatchString(null, null, null, null, null, "true", - STATE_PENDING); - let updates = getLocalUpdateString(patches, null, null, null, null, null, - null, null, null, null, null, null, - null, "true", channel); - writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); - - // Read the application.ini and use its application version - let processDir = getCurrentProcessDir(); - let file = processDir.clone(); - file.append("application.ini"); - let ini = AUS_Cc["@mozilla.org/xpcom/ini-parser-factory;1"]. - getService(AUS_Ci.nsIINIParserFactory). - createINIParser(file); - let version = ini.getString("App", "Version"); - writeVersionFile(version); - - // This is the directory where the update files will be located - let updateTestDir = getUpdateTestDir(); - try { - removeDirRecursive(updateTestDir); - } - catch (e) { - logTestInfo("unable to remove directory - path: " + updateTestDir.path + - ", exception: " + e); - } - - // Add the directory where the update files will be added and add files that - // will be removed. - if (!updateTestDir.exists()) { - updateTestDir.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY); - } - logTestInfo("update test directory path: " + updateTestDir.path); - - file = updateTestDir.clone(); - file.append("UpdateTestRemoveFile"); - writeFile(file, "ToBeRemoved"); - - file = updateTestDir.clone(); - file.append("UpdateTestAddFile"); - writeFile(file, "ToBeReplaced"); - - file = updateTestDir.clone(); - file.append("removed-files"); - writeFile(file, "ToBeReplaced"); - - let updatesRootDir = processDir.clone(); - updatesRootDir.append("updates"); - updatesRootDir.append("0"); - let mar = do_get_file("data/simple.mar"); - mar.copyTo(updatesRootDir, FILE_UPDATE_ARCHIVE); - - // Backup the updater.ini file if it exists by moving it. This prevents the - // post update executable from being launched if it is specified. - let updaterIni = processDir.clone(); - updaterIni.append(FILE_UPDATER_INI); - if (updaterIni.exists()) { - updaterIni.moveTo(processDir, FILE_UPDATER_INI_BAK); - } - - getUpdatesDir = function() { - var updatesDir = processDir.clone(); - updatesDir.append("updates"); - return updatesDir; - } - getApplyDirPath = function() { - return processDir.path; - } - getApplyDirFile = function (aRelPath, allowNonexistent) { - let base = AUS_Cc["@mozilla.org/file/local;1"]. - createInstance(AUS_Ci.nsILocalFile); - base.initWithPath(getApplyDirPath()); - let path = (aRelPath ? aRelPath : ""); - let bits = path.split("/"); - for (let i = 0; i < bits.length; i++) { - if (bits[i]) { - if (bits[i] == "..") - base = base.parent; - else - base.append(bits[i]); - } - } - - if (!allowNonexistent && !base.exists()) { - _passed = false; - var stack = Components.stack.caller; - _dump("TEST-UNEXPECTED-FAIL | " + stack.filename + " | [" + - stack.name + " : " + stack.lineNumber + "] " + base.path + - " does not exist\n"); - } - - return base; - } - runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED, checkUpdateFinished, updatesRootDir); -} - -function end_test() { - resetEnvironment(); - - let processDir = getCurrentProcessDir(); - // Restore the backup of the updater.ini if it exists. - let updaterIni = processDir.clone(); - updaterIni.append(FILE_UPDATER_INI_BAK); - if (updaterIni.exists()) { - updaterIni.moveTo(processDir, FILE_UPDATER_INI); - } - - // Remove the files added by the update. - let updateTestDir = getUpdateTestDir(); - try { - logTestInfo("removing update test directory " + updateTestDir.path); - removeDirRecursive(updateTestDir); - } - catch (e) { - logTestInfo("unable to remove directory - path: " + updateTestDir.path + - ", exception: " + e); - } - - // This will delete the app console log file if it exists. - getAppConsoleLogPath(); - - cleanUp(); -} - -/** - * Gets the directory where the update adds / removes the files contained in the - * update. - * - * @return nsIFile for the directory where the update adds / removes the files - * contained in the update mar. - */ -function getUpdateTestDir() { - let updateTestDir = getCurrentProcessDir(); - updateTestDir.append("update_test"); - return updateTestDir; -} - -/** - * Checks if the update has finished and if it has finished performs checks for - * the test. - */ -function checkUpdateFinished() { - // Don't proceed until the update.log has been created. - let log = getUpdatesDir(); - log.append("0"); - log.append(FILE_UPDATE_LOG); - if (!log.exists()) { - if (++gTimeoutRuns > MAX_TIMEOUT_RUNS) - do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for updates log to be created at " + log.path); - else - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); - return; - } - - // Log the contents of the update.log so it is simpler to diagnose a test - // failure. For example, on Windows if the application binary is in use the - // updater will not apply the update. - let contents = readFile(log); - logTestInfo("contents of " + log.path + ":\n" + - contents.replace(/\r\n/g, "\n")); - - if (contents.indexOf("NS_main: file in use") != -1) { - do_throw("the application can't be in use when running this test"); - } - - standardInit(); - - let update = gUpdateManager.getUpdateAt(0); - do_check_eq(update.state, STATE_SUCCEEDED); - - let updateTestDir = getUpdateTestDir(); - - let file = updateTestDir.clone(); - file.append("UpdateTestRemoveFile"); - do_check_false(file.exists()); - - file = updateTestDir.clone(); - file.append("UpdateTestAddFile"); - do_check_true(file.exists()); - do_check_eq(readFileBytes(file), "UpdateTestAddFile\n"); - - file = updateTestDir.clone(); - file.append("removed-files"); - do_check_true(file.exists()); - do_check_eq(readFileBytes(file), "update_test/UpdateTestRemoveFile\n"); - - let updatesDir = getUpdatesDir(); - log = updatesDir.clone(); - log.append("0"); - log.append(FILE_UPDATE_LOG); - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - - log = updatesDir.clone(); - log.append(FILE_LAST_LOG); - logTestInfo("testing " + log.path + " should exist"); - do_check_true(log.exists()); - - log = updatesDir.clone(); - log.append(FILE_BACKUP_LOG); - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - - updatesDir.append("0"); - logTestInfo("testing " + updatesDir.path + " should exist"); - do_check_true(updatesDir.exists()); - - Services.dirsvc.unregisterProvider(gDirProvider); - removeCallbackCopy(); -} - -// On Vista XRE_UPDATE_ROOT_DIR can be a directory other than the one in the -// application directory. This will reroute it back to the one in the -// application directory. -var gDirProvider = { - getFile: function DP_getFile(prop, persistent) { - persistent.value = true; - if (prop == XRE_UPDATE_ROOT_DIR) - return getCurrentProcessDir(); - return null; - }, - QueryInterface: function(iid) { - if (iid.equals(AUS_Ci.nsIDirectoryServiceProvider) || - iid.equals(AUS_Ci.nsISupports)) - return this; - throw AUS_Cr.NS_ERROR_NO_INTERFACE; - } -}; -Services.dirsvc.QueryInterface(AUS_Ci.nsIDirectoryService).registerProvider(gDirProvider); diff --git a/toolkit/mozapps/update/test_svc/unit/test_0201_app_launch_apply_update_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0201_app_launch_apply_update_svc.js deleted file mode 100644 index 3837c8a09..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0201_app_launch_apply_update_svc.js +++ /dev/null @@ -1,507 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/** - * Test applying an update by applying an update in the background and - * launching an application - */ - -/** - * The MAR file used for this test should not contain a version 2 update - * manifest file (e.g. updatev2.manifest). - */ - -const TEST_ID = "0201_svc"; - -// Backup the updater.ini and use a custom one to prevent the updater from -// launching a post update executable. -const FILE_UPDATER_INI_BAK = "updater.ini.bak"; - -// Number of milliseconds for each do_timeout call. -const CHECK_TIMEOUT_MILLI = 1000; - -// How many of CHECK_TIMEOUT_MILLI to wait before we abort the test. -const MAX_TIMEOUT_RUNS = 300; - -// Maximum number of milliseconds the process that is launched can run before -// the test will try to kill it. -const APP_TIMER_TIMEOUT = 120000; - -let gAppTimer; -let gProcess; -let gActiveUpdate; -let gTimeoutRuns = 0; - -// Override getUpdatesRootDir on Mac because we need to apply the update -// inside the bundle directory. -function symlinkUpdateFilesIntoBundleDirectory() { - if (!shouldAdjustPathsOnMac()) { - return; - } - // Symlink active-update.xml and updates/ inside the dist/bin directory - // to point to the bundle directory. - // This is necessary because in order to test the code which actually ships - // with Firefox, we need to perform the update inside the bundle directory, - // whereas xpcshell runs from dist/bin/, and the updater service code looks - // at the current process directory to find things like these two files. - - Components.utils.import("resource://gre/modules/ctypes.jsm"); - let libc = ctypes.open("/usr/lib/libc.dylib"); - // We need these two low level APIs because their functionality is not - // provided in nsIFile APIs. - let symlink = libc.declare("symlink", ctypes.default_abi, ctypes.int, - ctypes.char.ptr, ctypes.char.ptr); - let unlink = libc.declare("unlink", ctypes.default_abi, ctypes.int, - ctypes.char.ptr); - - // Symlink active-update.xml - let dest = getAppDir(); - dest.append("active-update.xml"); - if (!dest.exists()) { - dest.create(dest.NORMAL_FILE_TYPE, 0644); - } - do_check_true(dest.exists()); - let source = getUpdatesRootDir(); - source.append("active-update.xml"); - unlink(source.path); - let ret = symlink(dest.path, source.path); - do_check_eq(ret, 0); - do_check_true(source.exists()); - - // Symlink updates/ - let dest2 = getAppDir(); - dest2.append("updates"); - if (dest2.exists()) { - dest2.remove(true); - } - dest2.create(dest.DIRECTORY_TYPE, 0755); - do_check_true(dest2.exists()); - let source2 = getUpdatesRootDir(); - source2.append("updates"); - if (source2.exists()) { - source2.remove(true); - } - ret = symlink(dest2.path, source2.path); - do_check_eq(ret, 0); - do_check_true(source2.exists()); - - // Cleanup the symlinks when the test is finished. - do_register_cleanup(function() { - let ret = unlink(source.path); - do_check_false(source.exists()); - let ret = unlink(source2.path); - do_check_false(source2.exists()); - }); - - // Now, make sure that getUpdatesRootDir returns the application bundle - // directory, to make the various stuff in the test framework to work - // correctly. - getUpdatesRootDir = getAppDir; -} - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(end_test); - - if (IS_WIN) { - Services.prefs.setBoolPref(PREF_APP_UPDATE_SERVICE_ENABLED, true); - } - - removeUpdateDirsAndFiles(); - - symlinkUpdateFilesIntoBundleDirectory(); - if (IS_WIN) { - adjustPathsOnWindows(); - } - - if (!gAppBinPath) { - do_throw("Main application binary not found... expected: " + - APP_BIN_NAME + APP_BIN_SUFFIX); - return; - } - - // Don't attempt to show a prompt when the update is finished. - Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, true); - - gEnvSKipUpdateDirHashing = true; - let channel = Services.prefs.getCharPref(PREF_APP_UPDATE_CHANNEL); - let patches = getLocalPatchString(null, null, null, null, null, "true", - STATE_PENDING_SVC); - let updates = getLocalUpdateString(patches, null, null, null, null, null, - null, null, null, null, null, null, - null, "true", channel); - writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); - - // Read the application.ini and use its application version - let processDir = getAppDir(); - let file = processDir.clone(); - file.append("application.ini"); - let ini = AUS_Cc["@mozilla.org/xpcom/ini-parser-factory;1"]. - getService(AUS_Ci.nsIINIParserFactory). - createINIParser(file); - let version = ini.getString("App", "Version"); - writeVersionFile(version); - writeStatusFile(STATE_PENDING_SVC); - - // This is the directory where the update files will be located - let updateTestDir = getUpdateTestDir(); - try { - removeDirRecursive(updateTestDir); - } - catch (e) { - logTestInfo("unable to remove directory - path: " + updateTestDir.path + - ", exception: " + e); - } - - let updatesPatchDir = getUpdatesDir(); - updatesPatchDir.append("0"); - let mar = do_get_file("data/simple.mar"); - mar.copyTo(updatesPatchDir, FILE_UPDATE_ARCHIVE); - - reloadUpdateManagerData(); - gActiveUpdate = gUpdateManager.activeUpdate; - do_check_true(!!gActiveUpdate); - - setEnvironment(); - - // Backup the updater.ini file if it exists by moving it. This prevents the - // post update executable from being launched if it is specified. -//XXX disabled until bug 820933 and bug 820934 are fixed -if (0) { - let updaterIni = processDir.clone(); - updaterIni.append(FILE_UPDATER_INI); - if (updaterIni.exists()) { - updaterIni.moveTo(processDir, FILE_UPDATER_INI_BAK); - } -} - - // Backup the updater-settings.ini file if it exists by moving it. - let updateSettingsIni = processDir.clone(); - updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI); - if (updateSettingsIni.exists()) { - updateSettingsIni.moveTo(processDir, FILE_UPDATE_SETTINGS_INI_BAK); - } - updateSettingsIni = processDir.clone(); - updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI); - writeFile(updateSettingsIni, UPDATE_SETTINGS_CONTENTS); - - // Initiate a background update. - AUS_Cc["@mozilla.org/updates/update-processor;1"]. - createInstance(AUS_Ci.nsIUpdateProcessor). - processUpdate(gActiveUpdate); - - resetEnvironment(); - - checkUpdateApplied(); -} - -function switchApp() { - let launchBin = getLaunchBin(); - let args = getProcessArgs(); - logTestInfo("launching " + launchBin.path + " " + args.join(" ")); - - gProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - gProcess.init(launchBin); - - gAppTimer = AUS_Cc["@mozilla.org/timer;1"].createInstance(AUS_Ci.nsITimer); - gAppTimer.initWithCallback(gTimerCallback, APP_TIMER_TIMEOUT, - AUS_Ci.nsITimer.TYPE_ONE_SHOT); - - setEnvironment(); - - gProcess.runAsync(args, args.length, gProcessObserver); - - resetEnvironment(); -} - -function end_test() { - if (gProcess.isRunning) { - logTestInfo("attempt to kill process"); - gProcess.kill(); - } - - if (gAppTimer) { - logTestInfo("cancelling timer"); - gAppTimer.cancel(); - gAppTimer = null; - } - - resetEnvironment(); - - let processDir = getAppDir(); - // Restore the backup of the updater.ini if it exists. - let updaterIni = processDir.clone(); - updaterIni.append(FILE_UPDATER_INI_BAK); - if (updaterIni.exists()) { - updaterIni.moveTo(processDir, FILE_UPDATER_INI); - } - - // Restore the backed up updater-settings.ini if it exists. - let updateSettingsIni = processDir.clone(); - updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI_BAK); - if (updateSettingsIni.exists()) { - updateSettingsIni.moveTo(processDir, FILE_UPDATE_SETTINGS_INI); - } - - // Remove the files added by the update. - let updateTestDir = getUpdateTestDir(); - try { - logTestInfo("removing update test directory " + updateTestDir.path); - removeDirRecursive(updateTestDir); - } - catch (e) { - logTestInfo("unable to remove directory - path: " + updateTestDir.path + - ", exception: " + e); - } - - if (IS_UNIX) { - // This will delete the launch script if it exists. - getLaunchScript(); - if (IS_MACOSX) { - // This will delete the version script and version file if they exist. - getVersionScriptAndFile(); - } - } - - cleanUp(); -} - -function shouldAdjustPathsOnMac() { - // When running xpcshell tests locally, xpcshell and firefox-bin do not live - // in the same directory. - let dir = getCurrentProcessDir(); - return (IS_MACOSX && dir.leafName != "MacOS"); -} - -/** - * Gets the directory where the update adds / removes the files contained in the - * update. - * - * @return nsIFile for the directory where the update adds / removes the files - * contained in the update mar. - */ -function getUpdateTestDir() { - let updateTestDir = getAppDir(); - if (IS_MACOSX) { - updateTestDir = updateTestDir.parent.parent; - } - updateTestDir.append("update_test"); - return updateTestDir; -} - -/** - * Checks if the update has finished being applied in the background. - */ -function checkUpdateApplied() { - gTimeoutRuns++; - // Don't proceed until the update has been applied. - if (gUpdateManager.activeUpdate.state != STATE_APPLIED_PLATFORM) { - if (gTimeoutRuns > MAX_TIMEOUT_RUNS) - do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for update to be " + - "applied, current state is: " + - gUpdateManager.activeUpdate.state); - else - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); - return; - } - - let updatedDir = getAppDir(); - if (IS_MACOSX) { - updatedDir = updatedDir.parent.parent; - } - updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", "")); - logTestInfo("testing " + updatedDir.path + " should exist"); - do_check_true(updatedDir.exists()); - - let log = getUpdatesDir(); - log.append(FILE_LAST_LOG); - if (!log.exists()) { - if (gTimeoutRuns > MAX_TIMEOUT_RUNS) - do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for update log to " + - "be created"); - else - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); - return; - } - - // Don't proceed until the update status is no longer pending or applying. - let status = readStatusFile(); - do_check_eq(status, STATE_APPLIED_PLATFORM); - - // On Windows, make sure not to use the maintenance service for switching - // the app. - if (IS_WIN) { - writeStatusFile(STATE_APPLIED); - status = readStatusFile(); - do_check_eq(status, STATE_APPLIED); - } - - // Log the contents of the update.log so it is simpler to diagnose a test - // failure. - let contents = readFile(log); - logTestInfo("contents of " + log.path + ":\n" + - contents.replace(/\r\n/g, "\n")); - - let updateTestDir = getUpdateTestDir(); - logTestInfo("testing " + updateTestDir.path + " shouldn't exist"); - do_check_false(updateTestDir.exists()); - - updateTestDir = updatedDir.clone(); - updateTestDir.append("update_test"); - let file = updateTestDir.clone(); - file.append("UpdateTestRemoveFile"); - logTestInfo("testing " + file.path + " shouldn't exist"); - do_check_false(file.exists()); - - file = updateTestDir.clone(); - file.append("UpdateTestAddFile"); - logTestInfo("testing " + file.path + " should exist"); - do_check_true(file.exists()); - do_check_eq(readFileBytes(file), "UpdateTestAddFile\n"); - - file = updateTestDir.clone(); - file.append("removed-files"); - logTestInfo("testing " + file.path + " should exist"); - do_check_true(file.exists()); - do_check_eq(readFileBytes(file), "update_test/UpdateTestRemoveFile\n"); - - let updatesDir = getUpdatesDir(); - log = updatesDir.clone(); - log.append("0"); - log.append(FILE_UPDATE_LOG); - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - - log = updatesDir.clone(); - log.append(FILE_LAST_LOG); - logTestInfo("testing " + log.path + " should exist"); - do_check_true(log.exists()); - - log = updatesDir.clone(); - log.append(FILE_BACKUP_LOG); - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - - updatesDir = updatedDir.clone(); - if (IS_MACOSX) { - updatesDir.append("Contents"); - updatesDir.append("MacOS"); - } - updatesDir.append("updates"); - log = updatesDir.clone(); - log.append("0"); - log.append(FILE_UPDATE_LOG); - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - - updatesDir.append("0"); - logTestInfo("testing " + updatesDir.path + " shouldn't exist"); - do_check_false(updatesDir.exists()); - - // Now, switch the updated version of the app - do_timeout(CHECK_TIMEOUT_MILLI, switchApp); -} - -/** - * Checks if the update has finished and if it has finished performs checks for - * the test. - */ -function checkUpdateFinished() { - gTimeoutRuns++; - // Don't proceed until the update status is no longer applied. - try { - let status = readStatusFile(); - if (status != STATE_SUCCEEDED) { - if (gTimeoutRuns > MAX_TIMEOUT_RUNS) - do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for state to " + - "change to succeeded, current status: " + status); - else - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); - return; - } - } catch (e) { - // Ignore exceptions if the status file is not found - } - - try { - // This will delete the app console log file if it exists. - getAppConsoleLogPath(); - } catch (e) { - if (e.result == Components.results.NS_ERROR_FILE_IS_LOCKED) { - // This might happen on Windows in case the callback application has not - // finished its job yet. So, we'll wait some more. - if (gTimeoutRuns > MAX_TIMEOUT_RUNS) - do_throw("Exceeded whilst waiting for file to be unlocked"); - else - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); - return; - } else { - do_throw("getAppConsoleLogPath threw: " + e); - } - } - - // At this point we need to see if the application was switched successfully. - - let updatedDir = getAppDir(); - if (IS_MACOSX) { - updatedDir = updatedDir.parent.parent; - } - updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", "")); - logTestInfo("testing " + updatedDir.path + " shouldn't exist"); - do_check_false(updatedDir.exists()); - - let updateTestDir = getUpdateTestDir(); - - let file = updateTestDir.clone(); - file.append("UpdateTestRemoveFile"); - logTestInfo("testing " + file.path + " shouldn't exist"); - do_check_false(file.exists()); - - file = updateTestDir.clone(); - file.append("UpdateTestAddFile"); - logTestInfo("testing " + file.path + " should exist"); - do_check_true(file.exists()); - do_check_eq(readFileBytes(file), "UpdateTestAddFile\n"); - - file = updateTestDir.clone(); - file.append("removed-files"); - logTestInfo("testing " + file.path + " should exist"); - do_check_true(file.exists()); - do_check_eq(readFileBytes(file), "update_test/UpdateTestRemoveFile\n"); - - let updatesDir = getUpdatesDir(); - log = updatesDir.clone(); - log.append("0"); - log.append(FILE_UPDATE_LOG); - if (IS_WIN) { - // On Windows, this log file is written to the AppData directory, and will - // therefore exist. - logTestInfo("testing " + log.path + " should exist"); - do_check_true(log.exists()); - } else { - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - } - - log = updatesDir.clone(); - log.append(FILE_LAST_LOG); - logTestInfo("testing " + log.path + " should exist"); - do_check_true(log.exists()); - - log = updatesDir.clone(); - log.append(FILE_BACKUP_LOG); - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - - updatesDir.append("0"); - logTestInfo("testing " + updatesDir.path + " should exist"); - do_check_true(updatesDir.exists()); - - waitForFilesInUse(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0202_app_launch_apply_update_dirlocked_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0202_app_launch_apply_update_dirlocked_svc.js deleted file mode 100644 index 9274856d6..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0202_app_launch_apply_update_dirlocked_svc.js +++ /dev/null @@ -1,291 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/** - * Test applying an update by applying an update in the background and - * launching an application - */ - -/** - * This test is identical to test_0201_app_launch_apply_update_svc.js, except - * that it locks the application directory when the test is launched to - * check if the alternate updated directory logic works correctly. - */ - -/** - * The MAR file used for this test should not contain a version 2 update - * manifest file (e.g. updatev2.manifest). - */ - -const TEST_ID = "0202_svc"; - -// Backup the updater.ini and use a custom one to prevent the updater from -// launching a post update executable. -const FILE_UPDATER_INI_BAK = "updater.ini.bak"; - -// Number of milliseconds for each do_timeout call. -const CHECK_TIMEOUT_MILLI = 1000; - -// How many of CHECK_TIMEOUT_MILLI to wait before we abort the test. -const MAX_TIMEOUT_RUNS = 300; - -let gActiveUpdate; -let gTimeoutRuns = 0; - -// Override getUpdatesRootDir on Mac because we need to apply the update -// inside the bundle directory. -function symlinkUpdateFilesIntoBundleDirectory() { - if (!shouldAdjustPathsOnMac()) { - return; - } - // Symlink active-update.xml and updates/ inside the dist/bin directory - // to point to the bundle directory. - // This is necessary because in order to test the code which actually ships - // with Firefox, we need to perform the update inside the bundle directory, - // whereas xpcshell runs from dist/bin/, and the updater service code looks - // at the current process directory to find things like these two files. - - Components.utils.import("resource://gre/modules/ctypes.jsm"); - let libc = ctypes.open("/usr/lib/libc.dylib"); - // We need these two low level APIs because their functionality is not - // provided in nsIFile APIs. - let symlink = libc.declare("symlink", ctypes.default_abi, ctypes.int, - ctypes.char.ptr, ctypes.char.ptr); - let unlink = libc.declare("unlink", ctypes.default_abi, ctypes.int, - ctypes.char.ptr); - - // Symlink active-update.xml - let dest = getAppDir(); - dest.append("active-update.xml"); - if (!dest.exists()) { - dest.create(dest.NORMAL_FILE_TYPE, 0644); - } - do_check_true(dest.exists()); - let source = getUpdatesRootDir(); - source.append("active-update.xml"); - unlink(source.path); - let ret = symlink(dest.path, source.path); - do_check_eq(ret, 0); - do_check_true(source.exists()); - - // Symlink updates/ - let dest2 = getAppDir(); - dest2.append("updates"); - if (dest2.exists()) { - dest2.remove(true); - } - dest2.create(dest.DIRECTORY_TYPE, 0755); - do_check_true(dest2.exists()); - let source2 = getUpdatesRootDir(); - source2.append("updates"); - if (source2.exists()) { - source2.remove(true); - } - ret = symlink(dest2.path, source2.path); - do_check_eq(ret, 0); - do_check_true(source2.exists()); - - // Cleanup the symlinks when the test is finished. - do_register_cleanup(function() { - let ret = unlink(source.path); - do_check_false(source.exists()); - let ret = unlink(source2.path); - do_check_false(source2.exists()); - }); - - // Now, make sure that getUpdatesRootDir returns the application bundle - // directory, to make the various stuff in the test framework to work - // correctly. - getUpdatesRootDir = getAppDir; -} - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(end_test); - - removeUpdateDirsAndFiles(); - - symlinkUpdateFilesIntoBundleDirectory(); - if (IS_WIN) { - adjustPathsOnWindows(); - } - - if (!gAppBinPath) { - do_throw("Main application binary not found... expected: " + - APP_BIN_NAME + APP_BIN_SUFFIX); - return; - } - - // Don't attempt to show a prompt when the update is finished. - Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, true); - - let channel = Services.prefs.getCharPref(PREF_APP_UPDATE_CHANNEL); - let patches = getLocalPatchString(null, null, null, null, null, "true", - STATE_PENDING_SVC); - let updates = getLocalUpdateString(patches, null, null, null, null, null, - null, null, null, null, null, null, - null, "true", channel); - writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); - - // Read the application.ini and use its application version - let processDir = getAppDir(); - lockDirectory(processDir); - let file = processDir.clone(); - file.append("application.ini"); - let ini = AUS_Cc["@mozilla.org/xpcom/ini-parser-factory;1"]. - getService(AUS_Ci.nsIINIParserFactory). - createINIParser(file); - let version = ini.getString("App", "Version"); - writeVersionFile(version); - writeStatusFile(STATE_PENDING_SVC); - - // Remove the old updated directory which might be left over from previous tests. - let oldUpdatedDir = processDir.clone(); - oldUpdatedDir.append(UPDATED_DIR_SUFFIX.replace("/", "")); - if (oldUpdatedDir.exists()) { - oldUpdatedDir.remove(true); - } - - // This is the directory where the update files will be located - let updateTestDir = getUpdateTestDir(); - try { - removeDirRecursive(updateTestDir); - } - catch (e) { - logTestInfo("unable to remove directory - path: " + updateTestDir.path + - ", exception: " + e); - } - - let updatesPatchDir = getUpdatesDir(); - updatesPatchDir.append("0"); - let mar = do_get_file("data/simple.mar"); - mar.copyTo(updatesPatchDir, FILE_UPDATE_ARCHIVE); - - // Backup the updater.ini file if it exists by moving it. This prevents the - // post update executable from being launched if it is specified. - let updaterIni = processDir.clone(); - updaterIni.append(FILE_UPDATER_INI); - if (updaterIni.exists()) { - updaterIni.moveTo(processDir, FILE_UPDATER_INI_BAK); - } - - // Backup the updater-settings.ini file if it exists by moving it. - let updateSettingsIni = processDir.clone(); - updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI); - if (updateSettingsIni.exists()) { - updateSettingsIni.moveTo(processDir, FILE_UPDATE_SETTINGS_INI_BAK); - } - updateSettingsIni = processDir.clone(); - updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI); - writeFile(updateSettingsIni, UPDATE_SETTINGS_CONTENTS); - - reloadUpdateManagerData(); - gActiveUpdate = gUpdateManager.activeUpdate; - do_check_true(!!gActiveUpdate); - - setEnvironment(); - - // Initiate a background update. - AUS_Cc["@mozilla.org/updates/update-processor;1"]. - createInstance(AUS_Ci.nsIUpdateProcessor). - processUpdate(gActiveUpdate); - - resetEnvironment(); - - checkUpdateApplied(); -} - -function end_test() { - resetEnvironment(); - - let processDir = getAppDir(); - // Restore the backup of the updater.ini if it exists. - let updaterIni = processDir.clone(); - updaterIni.append(FILE_UPDATER_INI_BAK); - if (updaterIni.exists()) { - updaterIni.moveTo(processDir, FILE_UPDATER_INI); - } - - // Restore the backed up updater-settings.ini if it exists. - let updateSettingsIni = processDir.clone(); - updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI_BAK); - if (updateSettingsIni.exists()) { - updateSettingsIni.moveTo(processDir, FILE_UPDATE_SETTINGS_INI); - } - - // Remove the files added by the update. - let updateTestDir = getUpdateTestDir(); - try { - logTestInfo("removing update test directory " + updateTestDir.path); - removeDirRecursive(updateTestDir); - } - catch (e) { - logTestInfo("unable to remove directory - path: " + updateTestDir.path + - ", exception: " + e); - } - - if (IS_UNIX) { - // This will delete the launch script if it exists. - getLaunchScript(); - if (IS_MACOSX) { - // This will delete the version script and version file if they exist. - getVersionScriptAndFile(); - } - } - - cleanUp(); -} - -function shouldAdjustPathsOnMac() { - // When running xpcshell tests locally, xpcshell and firefox-bin do not live - // in the same directory. - let dir = getCurrentProcessDir(); - return (IS_MACOSX && dir.leafName != "MacOS"); -} - -/** - * Gets the directory where the update adds / removes the files contained in the - * update. - * - * @return nsIFile for the directory where the update adds / removes the files - * contained in the update mar. - */ -function getUpdateTestDir() { - let updateTestDir = getAppDir(); - if (IS_MACOSX) { - updateTestDir = updateTestDir.parent.parent; - } - updateTestDir.append("update_test"); - return updateTestDir; -} - -/** - * Checks if the update has failed being applied in the background. - */ -function checkUpdateApplied() { - // Don't proceed until the update has failed, and reset to pending. - if (gUpdateManager.activeUpdate.state != STATE_PENDING) { - if (++gTimeoutRuns > MAX_TIMEOUT_RUNS) - do_throw("Exceeded MAX_TIMEOUT_RUNS whist waiting for pending state to finish"); - else - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); - return; - } - - do_timeout(CHECK_TIMEOUT_MILLI, finishTest); -} - -function finishTest() { - // Don't proceed until the update status is pending. - let status = readStatusFile(); - do_check_eq(status, STATE_PENDING); - - unlockDirectory(getAppDir()); - - removeCallbackCopy(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/test_0203_app_launch_apply_update_svc.js b/toolkit/mozapps/update/test_svc/unit/test_0203_app_launch_apply_update_svc.js deleted file mode 100644 index b8f7a4f97..000000000 --- a/toolkit/mozapps/update/test_svc/unit/test_0203_app_launch_apply_update_svc.js +++ /dev/null @@ -1,533 +0,0 @@ -/* Any copyright is dedicated to the Public Domain. - * http://creativecommons.org/publicdomain/zero/1.0/ - */ - -/** - * Test applying an update by applying an update in the background and - * launching an application - */ - -/** - * This test is identical to test_0201_app_launch_apply_update_svc.js, except - * that it locks the application directory when the test is launched to - * make the updater fall back to apply the update regularly. - */ - -/** - * The MAR file used for this test should not contain a version 2 update - * manifest file (e.g. updatev2.manifest). - */ - -const TEST_ID = "0203_svc"; - -// Backup the updater.ini and use a custom one to prevent the updater from -// launching a post update executable. -const FILE_UPDATER_INI_BAK = "updater.ini.bak"; - -// Number of milliseconds for each do_timeout call. -const CHECK_TIMEOUT_MILLI = 1000; - -// How many of CHECK_TIMEOUT_MILLI to wait before we abort the test. -const MAX_TIMEOUT_RUNS = 300; - -// Maximum number of milliseconds the process that is launched can run before -// the test will try to kill it. -const APP_TIMER_TIMEOUT = 120000; - -Components.utils.import("resource://gre/modules/ctypes.jsm"); - -let gAppTimer; -let gProcess; -let gActiveUpdate; -let gTimeoutRuns = 0; - -// Override getUpdatesRootDir on Mac because we need to apply the update -// inside the bundle directory. -function symlinkUpdateFilesIntoBundleDirectory() { - if (!shouldAdjustPathsOnMac()) { - return; - } - // Symlink active-update.xml and updates/ inside the dist/bin directory - // to point to the bundle directory. - // This is necessary because in order to test the code which actually ships - // with Firefox, we need to perform the update inside the bundle directory, - // whereas xpcshell runs from dist/bin/, and the updater service code looks - // at the current process directory to find things like these two files. - - Components.utils.import("resource://gre/modules/ctypes.jsm"); - let libc = ctypes.open("/usr/lib/libc.dylib"); - // We need these two low level APIs because their functionality is not - // provided in nsIFile APIs. - let symlink = libc.declare("symlink", ctypes.default_abi, ctypes.int, - ctypes.char.ptr, ctypes.char.ptr); - let unlink = libc.declare("unlink", ctypes.default_abi, ctypes.int, - ctypes.char.ptr); - - // Symlink active-update.xml - let dest = getAppDir(); - dest.append("active-update.xml"); - if (!dest.exists()) { - dest.create(dest.NORMAL_FILE_TYPE, 0644); - } - do_check_true(dest.exists()); - let source = getUpdatesRootDir(); - source.append("active-update.xml"); - unlink(source.path); - let ret = symlink(dest.path, source.path); - do_check_eq(ret, 0); - do_check_true(source.exists()); - - // Symlink updates/ - let dest2 = getAppDir(); - dest2.append("updates"); - if (dest2.exists()) { - dest2.remove(true); - } - dest2.create(dest.DIRECTORY_TYPE, 0755); - do_check_true(dest2.exists()); - let source2 = getUpdatesRootDir(); - source2.append("updates"); - if (source2.exists()) { - source2.remove(true); - } - ret = symlink(dest2.path, source2.path); - do_check_eq(ret, 0); - do_check_true(source2.exists()); - - // Cleanup the symlinks when the test is finished. - do_register_cleanup(function() { - let ret = unlink(source.path); - do_check_false(source.exists()); - let ret = unlink(source2.path); - do_check_false(source2.exists()); - }); - - // Now, make sure that getUpdatesRootDir returns the application bundle - // directory, to make the various stuff in the test framework to work - // correctly. - getUpdatesRootDir = getAppDir; -} - -function run_test() { - if (!shouldRunServiceTest()) { - return; - } - - do_test_pending(); - do_register_cleanup(end_test); - - if (IS_WIN) { - Services.prefs.setBoolPref(PREF_APP_UPDATE_SERVICE_ENABLED, true); - } - - removeUpdateDirsAndFiles(); - - symlinkUpdateFilesIntoBundleDirectory(); - if (IS_WIN) { - adjustPathsOnWindows(); - } - - if (!gAppBinPath) { - do_throw("Main application binary not found... expected: " + - APP_BIN_NAME + APP_BIN_SUFFIX); - return; - } - - // Don't attempt to show a prompt when the update is finished. - Services.prefs.setBoolPref(PREF_APP_UPDATE_SILENT, true); - - gEnvSKipUpdateDirHashing = true; - let channel = Services.prefs.getCharPref(PREF_APP_UPDATE_CHANNEL); - let patches = getLocalPatchString(null, null, null, null, null, "true", - STATE_PENDING_SVC); - let updates = getLocalUpdateString(patches, null, null, null, null, null, - null, null, null, null, null, null, - null, "true", channel); - writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); - - // Read the application.ini and use its application version - let processDir = getAppDir(); - let file = processDir.clone(); - file.append("application.ini"); - let ini = AUS_Cc["@mozilla.org/xpcom/ini-parser-factory;1"]. - getService(AUS_Ci.nsIINIParserFactory). - createINIParser(file); - let version = ini.getString("App", "Version"); - writeVersionFile(version); - writeStatusFile(STATE_PENDING_SVC); - - // This is the directory where the update files will be located - let updateTestDir = getUpdateTestDir(); - try { - removeDirRecursive(updateTestDir); - } - catch (e) { - logTestInfo("unable to remove directory - path: " + updateTestDir.path + - ", exception: " + e); - } - - let updatesPatchDir = getUpdatesDir(); - updatesPatchDir.append("0"); - let mar = do_get_file("data/simple.mar"); - mar.copyTo(updatesPatchDir, FILE_UPDATE_ARCHIVE); - - reloadUpdateManagerData(); - gActiveUpdate = gUpdateManager.activeUpdate; - do_check_true(!!gActiveUpdate); - - setEnvironment(); - - // Backup the updater.ini file if it exists by moving it. This prevents the - // post update executable from being launched if it is specified. - let updaterIni = processDir.clone(); - updaterIni.append(FILE_UPDATER_INI); - if (updaterIni.exists()) { - updaterIni.moveTo(processDir, FILE_UPDATER_INI_BAK); - } - - // Backup the updater-settings.ini file if it exists by moving it. - let updateSettingsIni = processDir.clone(); - updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI); - if (updateSettingsIni.exists()) { - updateSettingsIni.moveTo(processDir, FILE_UPDATE_SETTINGS_INI_BAK); - } - updateSettingsIni = processDir.clone(); - updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI); - writeFile(updateSettingsIni, UPDATE_SETTINGS_CONTENTS); - - // Initiate a background update. - AUS_Cc["@mozilla.org/updates/update-processor;1"]. - createInstance(AUS_Ci.nsIUpdateProcessor). - processUpdate(gActiveUpdate); - - resetEnvironment(); - - checkUpdateApplied(); -} - -function switchApp() { - let launchBin = getLaunchBin(); - let args = getProcessArgs(); - logTestInfo("launching " + launchBin.path + " " + args.join(" ")); - - // Lock the installation directory - const LPCWSTR = ctypes.jschar.ptr; - const DWORD = ctypes.uint32_t; - const LPVOID = ctypes.voidptr_t; - const GENERIC_READ = 0x80000000; - const FILE_SHARE_READ = 1; - const FILE_SHARE_WRITE = 2; - const OPEN_EXISTING = 3; - const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; - const INVALID_HANDLE_VALUE = LPVOID(0xffffffff); - let kernel32 = ctypes.open("kernel32"); - let CreateFile = kernel32.declare("CreateFileW", ctypes.default_abi, - LPVOID, LPCWSTR, DWORD, DWORD, - LPVOID, DWORD, DWORD, LPVOID); - logTestInfo(gWindowsBinDir.path); - let handle = CreateFile(gWindowsBinDir.path, GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE, LPVOID(0), - OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, LPVOID(0)); - do_check_neq(handle.toString(), INVALID_HANDLE_VALUE.toString()); - kernel32.close(); - - gProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - gProcess.init(launchBin); - - gAppTimer = AUS_Cc["@mozilla.org/timer;1"].createInstance(AUS_Ci.nsITimer); - gAppTimer.initWithCallback(gTimerCallback, APP_TIMER_TIMEOUT, - AUS_Ci.nsITimer.TYPE_ONE_SHOT); - - setEnvironment(); - - gProcess.runAsync(args, args.length, gProcessObserver); - - resetEnvironment(); -} - -function end_test() { - if (gProcess.isRunning) { - logTestInfo("attempt to kill process"); - gProcess.kill(); - } - - if (gAppTimer) { - logTestInfo("cancelling timer"); - gAppTimer.cancel(); - gAppTimer = null; - } - - resetEnvironment(); - - let processDir = getAppDir(); - // Restore the backup of the updater.ini if it exists. - let updaterIni = processDir.clone(); - updaterIni.append(FILE_UPDATER_INI_BAK); - if (updaterIni.exists()) { - updaterIni.moveTo(processDir, FILE_UPDATER_INI); - } - - // Restore the backed up updater-settings.ini if it exists. - let updateSettingsIni = processDir.clone(); - updateSettingsIni.append(FILE_UPDATE_SETTINGS_INI_BAK); - if (updateSettingsIni.exists()) { - updateSettingsIni.moveTo(processDir, FILE_UPDATE_SETTINGS_INI); - } - - // Remove the files added by the update. - let updateTestDir = getUpdateTestDir(); - try { - logTestInfo("removing update test directory " + updateTestDir.path); - removeDirRecursive(updateTestDir); - } - catch (e) { - logTestInfo("unable to remove directory - path: " + updateTestDir.path + - ", exception: " + e); - } - - if (IS_UNIX) { - // This will delete the launch script if it exists. - getLaunchScript(); - if (IS_MACOSX) { - // This will delete the version script and version file if they exist. - getVersionScriptAndFile(); - } - } - - cleanUp(); -} - -function shouldAdjustPathsOnMac() { - // When running xpcshell tests locally, xpcshell and firefox-bin do not live - // in the same directory. - let dir = getCurrentProcessDir(); - return (IS_MACOSX && dir.leafName != "MacOS"); -} - -/** - * Gets the directory where the update adds / removes the files contained in the - * update. - * - * @return nsIFile for the directory where the update adds / removes the files - * contained in the update mar. - */ -function getUpdateTestDir() { - let updateTestDir = getAppDir(); - if (IS_MACOSX) { - updateTestDir = updateTestDir.parent.parent; - } - updateTestDir.append("update_test"); - return updateTestDir; -} - -/** - * Checks if the update has finished being applied in the background. - */ -function checkUpdateApplied() { - gTimeoutRuns++; - // Don't proceed until the update has been applied. - if (gUpdateManager.activeUpdate.state != STATE_APPLIED_PLATFORM) { - if (gTimeoutRuns > MAX_TIMEOUT_RUNS) - do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for update to be " + - "applied, current state is: " + gUpdateManager.activeUpdate.state); - else - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); - return; - } - - let updatedDir = getAppDir(); - if (IS_MACOSX) { - updatedDir = updatedDir.parent.parent; - } - updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", "")); - logTestInfo("testing " + updatedDir.path + " should exist"); - do_check_true(updatedDir.exists()); - - let log = getUpdatesDir(); - log.append(FILE_LAST_LOG); - if (!log.exists()) { - if (gTimeoutRuns > MAX_TIMEOUT_RUNS) - do_throw("Exceeded MAX_TIMEOUT_RUNS whist waiting for update log to be " + - "created"); - else - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateApplied); - return; - } - - // Don't proceed until the update status is no longer pending or applying. - let status = readStatusFile(); - do_check_eq(status, STATE_APPLIED_PLATFORM); - - // On Windows, make sure not to use the maintenance service for switching - // the app. - if (IS_WIN) { - writeStatusFile(STATE_APPLIED); - status = readStatusFile(); - do_check_eq(status, STATE_APPLIED); - } - - // Log the contents of the update.log so it is simpler to diagnose a test - // failure. - let contents = readFile(log); - logTestInfo("contents of " + log.path + ":\n" + - contents.replace(/\r\n/g, "\n")); - - let updateTestDir = getUpdateTestDir(); - logTestInfo("testing " + updateTestDir.path + " shouldn't exist"); - do_check_false(updateTestDir.exists()); - - updateTestDir = updatedDir.clone(); - updateTestDir.append("update_test"); - let file = updateTestDir.clone(); - file.append("UpdateTestRemoveFile"); - logTestInfo("testing " + file.path + " shouldn't exist"); - do_check_false(file.exists()); - - file = updateTestDir.clone(); - file.append("UpdateTestAddFile"); - logTestInfo("testing " + file.path + " should exist"); - do_check_true(file.exists()); - do_check_eq(readFileBytes(file), "UpdateTestAddFile\n"); - - file = updateTestDir.clone(); - file.append("removed-files"); - logTestInfo("testing " + file.path + " should exist"); - do_check_true(file.exists()); - do_check_eq(readFileBytes(file), "update_test/UpdateTestRemoveFile\n"); - - let updatesDir = getUpdatesDir(); - log = updatesDir.clone(); - log.append("0"); - log.append(FILE_UPDATE_LOG); - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - - log = updatesDir.clone(); - log.append(FILE_LAST_LOG); - logTestInfo("testing " + log.path + " should exist"); - do_check_true(log.exists()); - - log = updatesDir.clone(); - log.append(FILE_BACKUP_LOG); - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - - updatesDir = updatedDir.clone(); - if (IS_MACOSX) { - updatesDir.append("Contents"); - updatesDir.append("MacOS"); - } - updatesDir.append("updates"); - log = updatesDir.clone(); - log.append("0"); - log.append(FILE_UPDATE_LOG); - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - - updatesDir.append("0"); - logTestInfo("testing " + updatesDir.path + " shouldn't exist"); - do_check_false(updatesDir.exists()); - - // Now, switch the updated version of the app - do_timeout(CHECK_TIMEOUT_MILLI, switchApp); -} - -/** - * Checks if the update has finished and if it has finished performs checks for - * the test. - */ -function checkUpdateFinished() { - gTimeoutRuns++; - // Don't proceed until the update status is no longer applied. - try { - let status = readStatusFile(); - if (status != STATE_SUCCEEDED) { - if (gTimeoutRuns > MAX_TIMEOUT_RUNS) - do_throw("Exceeded MAX_TIMEOUT_RUNS whilst waiting for state to " + - "change to succeeded, current status: " + status); - else - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); - return; - } - } catch (e) { - // Ignore exceptions if the status file is not found - } - - try { - // This will delete the app console log file if it exists. - getAppConsoleLogPath(); - } catch (e) { - if (e.result == Components.results.NS_ERROR_FILE_IS_LOCKED) { - if (gTimeoutRuns > MAX_TIMEOUT_RUNS) - do_throw("Exceeded MAX_TIMEOUT_RUNS whist waiting for file to be " + - "unlocked"); - else - // This might happen on Windows in case the callback application has not - // finished its job yet. So, we'll wait some more. - do_timeout(CHECK_TIMEOUT_MILLI, checkUpdateFinished); - return; - } else { - do_throw("getAppConsoleLogPath threw: " + e); - } - } - - // At this point we need to see if the application was switched successfully. - - let updatedDir = getAppDir(); - if (IS_MACOSX) { - updatedDir = updatedDir.parent.parent; - } - updatedDir.append(UPDATED_DIR_SUFFIX.replace("/", "")); - logTestInfo("testing " + updatedDir.path + " shouldn't exist"); - do_check_false(updatedDir.exists()); - - let updateTestDir = getUpdateTestDir(); - - let file = updateTestDir.clone(); - file.append("UpdateTestRemoveFile"); - logTestInfo("testing " + file.path + " shouldn't exist"); - do_check_false(file.exists()); - - file = updateTestDir.clone(); - file.append("UpdateTestAddFile"); - logTestInfo("testing " + file.path + " should exist"); - do_check_true(file.exists()); - do_check_eq(readFileBytes(file), "UpdateTestAddFile\n"); - - file = updateTestDir.clone(); - file.append("removed-files"); - logTestInfo("testing " + file.path + " should exist"); - do_check_true(file.exists()); - do_check_eq(readFileBytes(file), "update_test/UpdateTestRemoveFile\n"); - - let updatesDir = getUpdatesDir(); - log = updatesDir.clone(); - log.append("0"); - log.append(FILE_UPDATE_LOG); - if (IS_WIN) { - // On Windows, this log file is written to the AppData directory, and will - // therefore exist. - logTestInfo("testing " + log.path + " should exist"); - do_check_true(log.exists()); - } else { - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - } - - log = updatesDir.clone(); - log.append(FILE_LAST_LOG); - logTestInfo("testing " + log.path + " should exist"); - do_check_true(log.exists()); - - log = updatesDir.clone(); - log.append(FILE_BACKUP_LOG); - logTestInfo("testing " + log.path + " shouldn't exist"); - do_check_false(log.exists()); - - updatesDir.append("0"); - logTestInfo("testing " + updatesDir.path + " should exist"); - do_check_true(updatesDir.exists()); - - waitForFilesInUse(); -} diff --git a/toolkit/mozapps/update/test_svc/unit/xpcshell.ini b/toolkit/mozapps/update/test_svc/unit/xpcshell.ini deleted file mode 100644 index 155fbd2f9..000000000 --- a/toolkit/mozapps/update/test_svc/unit/xpcshell.ini +++ /dev/null @@ -1,44 +0,0 @@ -; This Source Code Form is subject to the terms of the Mozilla Public -; License, v. 2.0. If a copy of the MPL was not distributed with this -; file, You can obtain one at http://mozilla.org/MPL/2.0/. - -[DEFAULT] -head = head_update.js -tail = - -[test_0000_bootstrap_svc.js] -[test_0110_general_svc.js] -[test_0111_general_svc.js] -[test_0112_general_svc.js] -[test_0113_general_svc.js] -[test_0114_general_svc.js] -[test_0115_general_svc.js] -[test_0150_appBinReplaced_xp_win_complete_svc.js] -[test_0151_appBinPatched_xp_win_partial_svc.js] -[test_0152_appBinReplaced_xp_win_complete_svc.js] -[test_0153_appBinPatched_xp_win_partial_svc.js] -[test_0160_appInUse_complete_svc.js] -[test_0161_appInUse_xp_win_complete_svc.js] -[test_0162_appInUse_xp_win_complete_svc.js] -[test_0170_fileLocked_xp_win_complete_svc.js] -[test_0171_fileLocked_xp_win_partial_svc.js] -[test_0172_fileLocked_xp_win_complete_svc.js] -[test_0173_fileLocked_xp_win_partial_svc.js] -[test_0174_fileLocked_xp_win_complete_svc.js] -[test_0175_fileLocked_xp_win_partial_svc.js] -[test_0180_fileInUse_xp_win_complete_svc.js] -[test_0181_fileInUse_xp_win_partial_svc.js] -[test_0182_rmrfdirFileInUse_xp_win_complete_svc.js] -[test_0183_rmrfdirFileInUse_xp_win_partial_svc.js] -[test_0184_fileInUse_xp_win_complete_svc.js] -[test_0185_fileInUse_xp_win_partial_svc.js] -[test_0186_rmrfdirFileInUse_xp_win_complete_svc.js] -[test_0187_rmrfdirFileInUse_xp_win_partial_svc.js] -[test_0188_fileInUse_xp_win_complete_svc.js] -[test_0189_fileInUse_xp_win_partial_svc.js] -[test_0190_rmrfdirFileInUse_xp_win_complete_svc.js] -[test_0191_rmrfdirFileInUse_xp_win_partial_svc.js] -[test_0200_app_launch_apply_update_svc.js] -[test_0201_app_launch_apply_update_svc.js] -[test_0202_app_launch_apply_update_dirlocked_svc.js] -[test_0203_app_launch_apply_update_svc.js] |