diff --git a/toolkit/mozapps/update/test/TestAUSHelper.cpp b/toolkit/mozapps/update/test/TestAUSHelper.cpp index 9119304650af..fc992294f772 100644 --- a/toolkit/mozapps/update/test/TestAUSHelper.cpp +++ b/toolkit/mozapps/update/test/TestAUSHelper.cpp @@ -8,14 +8,23 @@ # include typedef WCHAR NS_tchar; # define NS_main wmain +# define F_OK 00 +# define W_OK 02 +# define R_OK 04 +# define stat _stat # define NS_T(str) L ## str # define NS_tsnprintf(dest, count, fmt, ...) \ + { \ int _count = count - 1; \ _snwprintf(dest, _count, fmt, ##__VA_ARGS__); \ - dest[_count] = L'\0'; + dest[_count] = L'\0'; \ + } +# define NS_taccess _waccess +# define NS_tchdir _wchdir # define NS_tfopen _wfopen # define NS_tstrcmp wcscmp # define NS_ttoi _wtoi +# define NS_tstat _wstat # define LOG_S "%S" #else # include @@ -23,15 +32,20 @@ typedef char NS_tchar; # define NS_T(str) str # define NS_tsnprintf snprintf +# define NS_taccess access +# define NS_tchdir chdir # define NS_tfopen fopen # define NS_tstrcmp strcmp # define NS_ttoi atoi +# define NS_tstat stat # define LOG_S "%s" #endif #include #include #include +#include +#include #ifndef MAXPATHLEN # ifdef PATH_MAX @@ -47,72 +61,173 @@ # endif #endif +static void +WriteMsg(const NS_tchar *path, const char *status) +{ + FILE* outFP = NS_tfopen(path, NS_T("wb")); + if (!outFP) + return; + + fprintf(outFP, "%s\n", status); + fclose(outFP); + outFP = NULL; +} + +static bool +CheckMsg(const NS_tchar *path, const char *expected) +{ + if (NS_taccess(path, F_OK)) { + return false; + } + + FILE *inFP = NS_tfopen(path, NS_T("rb")); + if (!inFP) { + return false; + } + + struct stat ms; + if (fstat(fileno(inFP), &ms)) { + return false; + } + + char *mbuf = (char *) malloc(ms.st_size + 1); + if (!mbuf) { + return false; + } + + size_t r = ms.st_size; + char *rb = mbuf; + size_t c = fread(rb, sizeof(char), 50, inFP); + r -= c; + rb += c; + if (c == 0 && r) { + return false; + } + mbuf[ms.st_size] = '\0'; + rb = mbuf; + + fclose(inFP); + inFP = NULL; + return strcmp(rb, expected) == 0; +} + int NS_main(int argc, NS_tchar **argv) { - if (argc < 2) { + if (argc < 3) { fprintf(stderr, \ "\n" \ "Application Update Service Test Helper\n" \ "\n" \ - "Usage: -s SECONDS [LOCKTYPE FILETOLOCK]\n" \ - " or: LOGFILE [ARG2 ARG3...]\n" \ + "Usage: WORKINGDIR INFILE OUTFILE -s SECONDS [FILETOLOCK]\n" \ + " or: WORKINGDIR LOGFILE [ARG2 ARG3...]\n" \ "\n" \ + " WORKINGDIR \tThe relative path to the working directory to use.\n" \ + " INFILE \tThe relative path from the working directory for the file to\n" \ + " \tread actions to perform such as finish.\n" \ + " OUTFILE \tThe relative path from the working directory for the file to\n" \ + " \twrite status information.\n" \ " SECONDS \tThe number of seconds to sleep.\n" \ - " FILETOLOCK \tThe relative path to an existing file to open exlusively.\n" \ - " \tOnly available on Windows platforms and silently ignored on" \ + " FILETOLOCK \tThe relative path from the working directory to an existing\n" \ + " \tfile to open exlusively.\n" \ + " \tOnly available on Windows platforms and silently ignored on\n" \ " \tother platforms.\n" \ - " LOGFILE \tThe file path relative to the working directory to log the\n" \ - " \targuments passed to.\n" \ - " ARG2 ARG3...\tArguments to write to the log file.\n" \ + " LOGFILE \tThe relative path from the working directory to log the\n" \ + " \tcommand line arguments.\n" \ + " ARG2 ARG3...\tArguments to write to the LOGFILE after the preceding command\n" \ + " \tline arguments.\n" \ "\n" \ - "All paths should be relative since paths in a build environment can have a\n" \ - "path length that is larger than the maximum path length on Windows.\n" \ + "Note: All paths must be relative.\n" \ "\n"); return 1; } - // File in use test helper section - if (NS_tstrcmp(argv[1], NS_T("-s")) == 0) { -#ifdef XP_WIN - int milliseconds = NS_ttoi(argv[2]) * 1000; - HANDLE hFile = INVALID_HANDLE_VALUE; - if (argc == 4) { - hFile = CreateFileW(argv[3], + int i = 0; + #ifdef WINCE + NS_tchar cwd[MAXPATHLEN]; + if (argv[1][wcslen(argv[1]) - 1] != NS_T('/') && + argv[1][wcslen(argv[1]) - 1] != NS_T('\\')) { + NS_tsnprintf(cwd, sizeof(cwd)/sizeof(cwd[0]), + NS_T("%s"), argv[1]); + } else { + NS_tsnprintf(cwd, sizeof(cwd)/sizeof(cwd[0]), + NS_T("%s/"), argv[1]); + } +#else + if (NS_tchdir(argv[1]) != 0) { + return 1; + } +#endif + + // File in use test helper section + if (!NS_tstrcmp(argv[4], NS_T("-s"))) { +#ifdef WINCE + NS_tchar inFilePath[MAXPATHLEN]; + NS_tsnprintf(inFilePath, sizeof(inFilePath)/sizeof(inFilePath[0]), + NS_T("%s%s"), cwd, argv[2]); + NS_tchar outFilePath[MAXPATHLEN]; + NS_tsnprintf(outFilePath, sizeof(outFilePath)/sizeof(outFilePath[0]), + NS_T("%s%s"), cwd, argv[3]); +#else + NS_tchar inFilePath[MAXPATHLEN]; + NS_tsnprintf(inFilePath, sizeof(inFilePath)/sizeof(inFilePath[0]), + NS_T("%s"), argv[2]); + NS_tchar outFilePath[MAXPATHLEN]; + NS_tsnprintf(outFilePath, sizeof(outFilePath)/sizeof(outFilePath[0]), + NS_T("%s"), argv[3]); +#endif + + int seconds = NS_ttoi(argv[5]); +#ifdef XP_WIN + HANDLE hFile = INVALID_HANDLE_VALUE; + if (argc == 7) { +#ifdef WINCE + NS_tchar lockfile[MAXPATHLEN]; + NS_tsnprintf(lockfile, sizeof(lockfile)/sizeof(lockfile[0]), + NS_T("%s%s"), cwd, argv[6]); + hFile = CreateFileW(lockfile, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, #else + hFile = CreateFileW(argv[6], DELETE | GENERIC_WRITE, 0, #endif NULL, OPEN_EXISTING, 0, NULL); if (hFile == INVALID_HANDLE_VALUE) { + WriteMsg(outFilePath, "error_locking"); return 1; } } - Sleep(milliseconds); + WriteMsg(outFilePath, "sleeping"); + while (!CheckMsg(inFilePath, "finish\n") && i++ <= seconds) { + Sleep(1000); + } - if (argc == 5) { + if (argc == 7) { CloseHandle(hFile); } #else - int seconds = NS_ttoi(argv[2]); - sleep(seconds); + WriteMsg(outFilePath, "sleeping"); + while (!CheckMsg(inFilePath, "finish\n") && i++ <= seconds) { + sleep(1); + } #endif + WriteMsg(outFilePath, "finished"); return 0; } // Command line argument test helper section NS_tchar logFilePath[MAXPATHLEN]; - +#ifdef WINCE NS_tsnprintf(logFilePath, sizeof(logFilePath)/sizeof(logFilePath[0]), - NS_T("%s"), argv[1]); + NS_T("%s%s"), cwd, argv[2]); +#else + NS_tsnprintf(logFilePath, sizeof(logFilePath)/sizeof(logFilePath[0]), + NS_T("%s"), argv[2]); +#endif - FILE* logFP = NS_tfopen(logFilePath, NS_T("w")); - - fprintf(logFP, "executed\n"); - - int i; + FILE* logFP = NS_tfopen(logFilePath, NS_T("wb")); for (i = 1; i < argc; ++i) { fprintf(logFP, LOG_S "\n", argv[i]); } diff --git a/toolkit/mozapps/update/test/unit/data/complete.mar b/toolkit/mozapps/update/test/unit/data/complete.mar index 2cd8c3068d26..941cc988f140 100644 Binary files a/toolkit/mozapps/update/test/unit/data/complete.mar and b/toolkit/mozapps/update/test/unit/data/complete.mar differ diff --git a/toolkit/mozapps/update/test/unit/data/partial.mar b/toolkit/mozapps/update/test/unit/data/partial.mar index 44b0766fdae6..e3957f5c8245 100644 Binary files a/toolkit/mozapps/update/test/unit/data/partial.mar and b/toolkit/mozapps/update/test/unit/data/partial.mar differ diff --git a/toolkit/mozapps/update/test/unit/data/partial_in_use_win.mar b/toolkit/mozapps/update/test/unit/data/partial_in_use_win.mar index e4d1e27d2e8e..9427ea35dfb7 100644 Binary files a/toolkit/mozapps/update/test/unit/data/partial_in_use_win.mar and b/toolkit/mozapps/update/test/unit/data/partial_in_use_win.mar differ diff --git a/toolkit/mozapps/update/test/unit/data/partial_in_use_win_after.exe b/toolkit/mozapps/update/test/unit/data/partial_in_use_win_after.exe index b8a25fab6613..3949fd2a0ec1 100644 Binary files a/toolkit/mozapps/update/test/unit/data/partial_in_use_win_after.exe and b/toolkit/mozapps/update/test/unit/data/partial_in_use_win_after.exe differ diff --git a/toolkit/mozapps/update/test/unit/data/partial_in_use_win_before.exe b/toolkit/mozapps/update/test/unit/data/partial_in_use_win_before.exe index fe74dddc81b3..13443160e221 100644 Binary files a/toolkit/mozapps/update/test/unit/data/partial_in_use_win_before.exe and b/toolkit/mozapps/update/test/unit/data/partial_in_use_win_before.exe differ diff --git a/toolkit/mozapps/update/test/unit/head_update.js.in b/toolkit/mozapps/update/test/unit/head_update.js.in index e3d3a7aff515..a59e4f1a76df 100644 --- a/toolkit/mozapps/update/test/unit/head_update.js.in +++ b/toolkit/mozapps/update/test/unit/head_update.js.in @@ -84,16 +84,19 @@ const IS_ANDROID = false; const URL_HOST = "http://localhost:4444/"; const URL_PATH = "data"; -const AFTER_APPLY_DIR = "afterApplyDir"; -const APPLY_TO_DIR_SUFFIX = "_applyToDir"; +const APPLY_TO_DIR_SUFFIX = "_applyToDir/"; const HELPER_BIN_FILE = "TestAUSHelper" + BIN_SUFFIX; const MAR_COMPLETE_FILE = "data/complete.mar"; const MAR_PARTIAL_FILE = "data/partial.mar"; const UPDATER_BIN_FILE = "updater" + BIN_SUFFIX; const UPDATES_DIR_SUFFIX = "_mar"; +const APPLY_DIR_RELPATH = "a/b/"; const CALLBACK_BIN_FILE = "callback_app" + BIN_SUFFIX; -const CALLBACK_ARGS = [AFTER_APPLY_DIR + "/output.log", "Test Arg 2", "Test Arg 3"]; +const CALLBACK_ARGS = ["./", "callback.log", "Test Arg 2", "Test Arg 3"]; + +// Time to wait for the test helper process before continuing the test +const TEST_HELPER_TIMEOUT = 100; var gTestserver; @@ -109,6 +112,161 @@ var gUpdates; var gStatusCode; var gStatusText; +/** + * The mar files used for the updater tests contain the following remove + * operations. + * + * partial and complete test mar remove operations + * ----------------------------------------------- + * remove "text1" + * remove "text0" + * rmrfdir "9/99/" + * rmdir "9/99/" + * rmrfdir "9/98/" + * rmrfdir "9/97/" + * rmrfdir "9/96/" + * rmrfdir "9/95/" + * rmrfdir "9/95/" + * rmrfdir "9/94/" + * rmdir "9/94/" + * rmdir "9/93/" + * rmdir "9/92/" + * rmdir "9/91/" + * rmdir "9/90/" + * rmdir "9/90/" + * rmrfdir "8/89/" + * rmdir "8/89/" + * rmrfdir "8/88/" + * rmrfdir "8/87/" + * rmrfdir "8/86/" + * rmrfdir "8/85/" + * rmrfdir "8/85/" + * rmrfdir "8/84/" + * rmdir "8/84/" + * rmdir "8/83/" + * rmdir "8/82/" + * rmdir "8/81/" + * rmdir "8/80/" + * rmdir "8/80/" + * rmrfdir "7/" + * rmdir "6/" + * remove "5/text1" + * remove "5/text0" + * rmrfdir "5/" + * remove "4/text1" + * remove "4/text0" + * remove "4/exe0.exe" + * rmdir "4/" + * remove "3/text1" + * remove "3/text0" + * + * partial test mar additional remove operations + * --------------------------------------------- + * remove "0/00/00text1" + * remove "1/10/10text0" + * rmdir "1/10/" + * rmdir "1/" + */ +var TEST_DIRS = [ +{ + relPathDir : "3/", + dirRemoved : false, + files : ["text0", "text1"], + filesRemoved : true +}, { + relPathDir : "4/", + dirRemoved : true, + files : ["text0", "text1"], + filesRemoved : true +}, { + relPathDir : "5/", + dirRemoved : true, + files : ["test.exe", "text0", "text1"], + filesRemoved : true +}, { + relPathDir : "6/", + dirRemoved : true +}, { + relPathDir : "7/", + dirRemoved : true, + files : ["text0", "text1"], + subDirs : ["70/", "71/"], + subDirFiles : ["test.exe", "text0", "text1"] +}, { + relPathDir : "8/", + dirRemoved : false +}, { + relPathDir : "8/80/", + dirRemoved : true +}, { + relPathDir : "8/81/", + dirRemoved : false, + files : ["text0", "text1"] +}, { + relPathDir : "8/82/", + dirRemoved : false, + subDirs : ["820/", "821/"] +}, { + relPathDir : "8/83/", + dirRemoved : true +}, { + relPathDir : "8/84/", + dirRemoved : true +}, { + relPathDir : "8/85/", + dirRemoved : true +}, { + relPathDir : "8/86/", + dirRemoved : true, + files : ["text0", "text1"] +}, { + relPathDir : "8/87/", + dirRemoved : true, + subDirs : ["870/", "871/"], + subDirFiles : ["text0", "text1"] +}, { + relPathDir : "8/88/", + dirRemoved : true +}, { + relPathDir : "8/89/", + dirRemoved : true +}, { + relPathDir : "9/90/", + dirRemoved : true +}, { + relPathDir : "9/91/", + dirRemoved : false, + files : ["text0", "text1"] +}, { + relPathDir : "9/92/", + dirRemoved : false, + subDirs : ["920/", "921/"] +}, { + relPathDir : "9/93/", + dirRemoved : true +}, { + relPathDir : "9/94/", + dirRemoved : true +}, { + relPathDir : "9/95/", + dirRemoved : true +}, { + relPathDir : "9/96/", + dirRemoved : true, + files : ["text0", "text1"] +}, { + relPathDir : "9/97/", + dirRemoved : true, + subDirs : ["970/", "971/"], + subDirFiles : ["text0", "text1"] +}, { + relPathDir : "9/98/", + dirRemoved : true +}, { + relPathDir : "9/99/", + dirRemoved : true +}]; + // Set to true to log additional information for debugging. To log additional // information for an individual test set DEBUG_AUS_TEST to true in the test's // run_test function. @@ -180,15 +338,34 @@ function pathHandler(metadata, response) { response.bodyOutputStream.write(gResponseBody, gResponseBody.length); } +/** + * Helper function for getting the relative path to the directory where the + * update will be applied. + * + * @return The relative path to the directory where the update will be applied. + */ +function getApplyDirPath() { + return TEST_ID + APPLY_TO_DIR_SUFFIX + APPLY_DIR_RELPATH; +} + +/** + * Helper function for getting the nsIFile for the directory where the update + * will be applied. + * + * @return The nsIFile for the directory where the update will be applied. + */ +function getApplyDirFile(aRelPath, allowNonexistent) { + let relpath = getApplyDirPath() + (aRelPath ? aRelPath : ""); + return do_get_file(relpath, allowNonexistent); +} + /** * Helper function for updater tests for launching the updater binary to apply * a mar file. * - * @param aTestID - * A string used to identify the name of directories for a test. * @return The exit value returned from the updater binary. */ -function runUpdate(aTestID) { +function runUpdate() { // Copy the updater binary to the updates directory. let binDir = getGREDir(); let updater = binDir.clone(); @@ -201,7 +378,7 @@ function runUpdate(aTestID) { } } - let updatesDir = do_get_file(aTestID + UPDATES_DIR_SUFFIX, true); + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX, true); updater.copyTo(updatesDir, updater.leafName); let updateBin = updatesDir.clone(); updateBin.append(updater.leafName); @@ -217,17 +394,16 @@ function runUpdate(aTestID) { if (/ /.test(updatesDirPath)) updatesDirPath = '"' + updatesDirPath + '"'; - let applyToDir = do_get_file(aTestID + APPLY_TO_DIR_SUFFIX, true); + let applyToDir = do_get_file(getApplyDirPath(), true); let applyToDirPath = applyToDir.path; if (/ /.test(applyToDirPath)) applyToDirPath = '"' + applyToDirPath + '"'; let callbackApp = applyToDir.clone(); - callbackApp.append(AFTER_APPLY_DIR); callbackApp.append(CALLBACK_BIN_FILE); callbackApp.permissions = PERMS_DIRECTORY; - let cwdPath = callbackApp.parent.parent.path; + let cwdPath = callbackApp.parent.path; if (/ /.test(cwdPath)) cwdPath = '"' + cwdPath + '"'; @@ -270,21 +446,50 @@ function getLaunchBin() { return launchBin; } +function waitForHelperSleep() { + // Give the lock file process time to lock the file before updating otherwise + // this test can fail intermittently on Windows debug builds. + let output = getApplyDirFile("output", true); + if (readFile(output) != "sleeping\n") { + do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); + return; + } + output.remove(false); + do_timeout(TEST_HELPER_TIMEOUT, doUpdate); +} + +function waitForHelperFinished() { + // Give the lock file process time to lock the file before updating otherwise + // this test can fail intermittently on Windows debug builds. + let output = getApplyDirFile("output", true); + if (readFile(output) != "finished\n") { + do_timeout(TEST_HELPER_TIMEOUT, waitForHelperFinished); + return; + } + output.remove(false); + let input = getApplyDirFile("input", true); + if (input.exists()) { + input.remove(false); + } + do_timeout(TEST_HELPER_TIMEOUT, checkUpdate); +} + +function setupHelperFinish() { + let input = getApplyDirFile("input", true); + writeFile(input, "finish\n"); + do_timeout(TEST_HELPER_TIMEOUT, waitForHelperFinished); +} + /** - * Helper function for updater tests for setting up the files and directories - * used by the updater tests. + * Helper function for updater binary tests for setting up the files and + * directories used by the test. * - * @param aTestID - * A string used to identify the name of directories for a test. * @param aMarFile - * The mar file to copy the update mar to. - * @param aTestFiles - * An array of JavaScript objects representing the test files to create - * for the test. + * The mar file for the update test. */ -function setupUpdaterTest(aTestID, aMarFile, aTestFiles) { +function setupUpdaterTest(aMarFile) { // Remove the directory where the updater, mar file, etc. will be copied to - let updatesDir = do_get_file(aTestID + UPDATES_DIR_SUFFIX, true); + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX, true); try { removeDirRecursive(updatesDir); } @@ -298,7 +503,7 @@ function setupUpdaterTest(aTestID, aMarFile, aTestFiles) { } // Remove the directory where the update will be applied if it exists. - let applyToDir = do_get_file(aTestID + APPLY_TO_DIR_SUFFIX, true); + let applyToDir = getApplyDirFile(null, true); try { removeDirRecursive(applyToDir); } @@ -313,45 +518,42 @@ function setupUpdaterTest(aTestID, aMarFile, aTestFiles) { // Add the test files that will be updated for a successful update or left in // the initial state for a failed update. - for (let i = 0; i < aTestFiles.length; i++) { - let f = aTestFiles[i]; - if (f.originalFile || f.originalContents) { - let testDir = do_get_file(f.destinationDir, true); + TEST_FILES.forEach(function SUT_TF_FE(aTestFile) { + if (aTestFile.originalFile || aTestFile.originalContents) { + let testDir = getApplyDirFile(aTestFile.relPathDir, true); if (!testDir.exists()) testDir.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY); let testFile; - if (f.originalFile) { - testFile = do_get_file(f.originalFile); - testFile.copyTo(testDir, f.fileName); - testFile = do_get_file(f.destinationDir + f.fileName); + if (aTestFile.originalFile) { + testFile = do_get_file(aTestFile.originalFile); + testFile.copyTo(testDir, aTestFile.fileName); + testFile = getApplyDirFile(aTestFile.relPathDir + aTestFile.fileName); } else { - testFile = do_get_file(f.destinationDir + f.fileName, true); - writeFile(testFile, f.originalContents); + testFile = getApplyDirFile(aTestFile.relPathDir + aTestFile.fileName, true); + writeFile(testFile, aTestFile.originalContents); } // Skip these tests on Windows (includes WinCE) and OS/2 since their // implementaions of chmod doesn't really set permissions. - if (!IS_WIN && !IS_OS2 && f.originalPerms) { - testFile.permissions = f.originalPerms; + if (!IS_WIN && !IS_OS2 && aTestFile.originalPerms) { + testFile.permissions = aTestFile.originalPerms; // Store the actual permissions on the file for reference later after // setting the permissions. - if (!f.comparePerms) - f.comparePerms = testFile.permissions; + if (!aTestFile.comparePerms) + aTestFile.comparePerms = testFile.permissions; } } - } - - let afterApplyBinDir = applyToDir.clone(); - afterApplyBinDir.append(AFTER_APPLY_DIR); + }); let helperBin = do_get_file(HELPER_BIN_FILE); + let afterApplyBinDir = applyToDir.clone(); helperBin.copyTo(afterApplyBinDir, CALLBACK_BIN_FILE); let updaterIniContents = "[Strings]\n" + "Title=Update XPCShell Test\n" + - "Info=Application Update Test - " + aTestID + "\n"; + "Info=Application Update Test - " + TEST_ID + "\n"; let updaterIni = updatesDir.clone(); updaterIni.append(FILE_UPDATER_INI); writeFile(updaterIni, updaterIniContents); @@ -360,17 +562,50 @@ function setupUpdaterTest(aTestID, aMarFile, aTestFiles) { // Copy the mar that will be applied let mar = do_get_file(aMarFile); mar.copyTo(updatesDir, FILE_UPDATE_ARCHIVE); + + // Add the test directory that will be updated for a successful update or left in + // the initial state for a failed update. + TEST_DIRS.forEach(function SUT_TD_FE(aTestDir) { + let testDir = getApplyDirFile(aTestDir.relPathDir, true); + if (!testDir.exists()) { + testDir.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY); + } + + if (aTestDir.files) { + aTestDir.files.forEach(function SUT_TD_F_FE(aTestFile) { + let testFile = getApplyDirFile(aTestDir.relPathDir + aTestFile, true); + if (!testFile.exists()) { + testFile.create(AUS_Ci.nsIFile.FILE_TYPE, PERMS_FILE); + } + }); + } + + if (aTestDir.subDirs) { + aTestDir.subDirs.forEach(function SUT_TD_SD_FE(aSubDir) { + let testSubDir = getApplyDirFile(aTestDir.relPathDir + aSubDir, true); + if (!testSubDir.exists()) { + testSubDir.create(AUS_Ci.nsIFile.DIRECTORY_TYPE, PERMS_DIRECTORY); + } + + if (aTestDir.subDirFiles) { + aTestDir.subDirFiles.forEach(function SUT_TD_SDF_FE(aTestFile) { + let testFile = getApplyDirFile(aTestDir.relPathDir + aSubDir + aTestFile, true); + if (!testFile.exists()) { + testFile.create(AUS_Ci.nsIFile.FILE_TYPE, PERMS_FILE); + } + }); + } + }); + } + }); } /** - * Helper function for updater tests for cleaning up the state after an updater - * test has finished. - * - * @param aTestID - * A string used to identify the name of directories for a test. + * Helper function for updater binary tests to clean up the state after the test + * has finished. */ -function cleanupUpdaterTest(aTestID) { - let updatesDir = do_get_file(aTestID + UPDATES_DIR_SUFFIX, true); +function cleanupUpdaterTest() { + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX, true); try { removeDirRecursive(updatesDir); } @@ -381,7 +616,7 @@ function cleanupUpdaterTest(aTestID) { } // Try to remove the updates and the apply to directories. - let applyToDir = do_get_file(aTestID + APPLY_TO_DIR_SUFFIX, true); + let applyToDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX, true); try { removeDirRecursive(applyToDir); } @@ -395,119 +630,174 @@ function cleanupUpdaterTest(aTestID) { } /** - * Helper function for updater tests for verifying the state of files and + * Helper function for updater binary tests for verifying the state of files and * directories after a successful update. - * - * @param aTestID - * A string used to identify the name of directories for a test. - * @param aTestFiles - * An array of JavaScript objects representing the test files to create - * for the test. */ -function checkFilesAfterUpdateSuccess(aTestID, aTestFiles) { +function checkFilesAfterUpdateSuccess() { logTestInfo("testing contents of files after a successful update"); - for (let i = 0; i < aTestFiles.length; i++) { - let f = aTestFiles[i]; - let testFile = do_get_file(f.destinationDir + f.fileName, true); + TEST_FILES.forEach(function CFAUS_TF_FE(aTestFile) { + let testFile = getApplyDirFile(aTestFile.relPathDir + aTestFile.fileName, true); logTestInfo("testing file: " + testFile.path); - if (f.compareFile || f.compareContents) { + if (aTestFile.compareFile || aTestFile.compareContents) { do_check_true(testFile.exists()); // Skip these tests on Windows (includes WinCE) and OS/2 since their // implementaions of chmod doesn't really set permissions. - if (!IS_WIN && !IS_OS2 && f.comparePerms) { + if (!IS_WIN && !IS_OS2 && aTestFile.comparePerms) { // Check if the permssions as set in the complete mar file are correct. let logPerms = "testing file permissions - "; - if (f.originalPerms) { - logPerms += "original permissions: " + f.originalPerms.toString(8) + ", "; + if (aTestFile.originalPerms) { + logPerms += "original permissions: " + aTestFile.originalPerms.toString(8) + ", "; } - logPerms += "compare permissions : " + f.comparePerms.toString(8) + ", "; + logPerms += "compare permissions : " + aTestFile.comparePerms.toString(8) + ", "; logPerms += "updated permissions : " + testFile.permissions.toString(8); logTestInfo(logPerms); - do_check_eq(testFile.permissions & 0xfff, f.comparePerms & 0xfff); + do_check_eq(testFile.permissions & 0xfff, aTestFile.comparePerms & 0xfff); } - if (f.compareFile) { + if (aTestFile.compareFile) { do_check_eq(readFileBytes(testFile), - readFileBytes(do_get_file(f.compareFile))); - if (f.originalFile) { + readFileBytes(do_get_file(aTestFile.compareFile))); + if (aTestFile.originalFile) { // Verify that readFileBytes returned the entire contents by checking // the contents against the original file. do_check_neq(readFileBytes(testFile), - readFileBytes(do_get_file(f.originalFile))); + readFileBytes(do_get_file(aTestFile.originalFile))); } } else { - do_check_eq(readFileBytes(testFile), f.compareContents); + do_check_eq(readFileBytes(testFile), aTestFile.compareContents); } } else { do_check_false(testFile.exists()); } - } + }); - checkFilesAfterUpdateCommon(aTestID); + logTestInfo("testing operations specified in removed-files were performed " + + "after a successful update"); + TEST_DIRS.forEach(function CFAUS_TD_FE(aTestDir) { + let testDir = getApplyDirFile(aTestDir.relPathDir, true); + logTestInfo("testing directory: " + testDir.path); + if (aTestDir.dirRemoved) { + do_check_false(testDir.exists()); + } + else { + do_check_true(testDir.exists()); + + if (aTestDir.files) { + aTestDir.files.forEach(function CFAUS_TD_F_FE(aTestFile) { + let testFile = getApplyDirFile(aTestDir.relPathDir + aTestFile, true); + logTestInfo("testing directory file: " + testFile.path); + if (aTestDir.filesRemoved) { + do_check_false(testFile.exists()); + } + else { + do_check_true(testFile.exists()); + } + }); + } + + if (aTestDir.subDirs) { + aTestDir.subDirs.forEach(function CFAUS_TD_SD_FE(aSubDir) { + let testSubDir = getApplyDirFile(aTestDir.relPathDir + aSubDir, true); + logTestInfo("testing sub-directory: " + testSubDir.path); + do_check_true(testSubDir.exists()); + if (aTestDir.subDirFiles) { + aTestDir.subDirFiles.forEach(function CFAUS_TD_SDF_FE(aTestFile) { + let testFile = getApplyDirFile(aTestDir.relPathDir + aSubDir + aTestFile, true); + logTestInfo("testing sub-directory file: " + testFile.path); + do_check_true(testFile.exists()); + }); + } + }); + } + } + }); + + checkFilesAfterUpdateCommon(); } /** - * Helper function for updater tests for verifying the state of files and + * Helper function for updater binary tests for verifying the state of files and * directories after a failed update. - * - * @param aTestID - * A string used to identify the name of directories for a test. - * @param aTestFiles - * An array of JavaScript objects representing the test files to create - * for the test. */ -function checkFilesAfterUpdateFailure(aTestID, aTestFiles) { +function checkFilesAfterUpdateFailure() { logTestInfo("testing contents of files after a failed update"); - for (let i = 0; i < aTestFiles.length; i++) { - let f = aTestFiles[i]; - let testFile = do_get_file(f.destinationDir + f.fileName, true); + TEST_FILES.forEach(function CFAUF_TF_FE(aTestFile) { + let testFile = getApplyDirFile(aTestFile.relPathDir + aTestFile.fileName, true); logTestInfo("testing file: " + testFile.path); - if (f.compareFile || f.compareContents) { + if (aTestFile.compareFile || aTestFile.compareContents) { do_check_true(testFile.exists()); // Skip these tests on Windows (includes WinCE) and OS/2 since their // implementaions of chmod doesn't really set permissions. - if (!IS_WIN && !IS_OS2 && f.comparePerms) { + if (!IS_WIN && !IS_OS2 && aTestFile.comparePerms) { // Check the original permssions are retained on the file. let logPerms = "testing file permissions - "; - if (f.originalPerms) { - logPerms += "original permissions: " + f.originalPerms.toString(8) + ", "; + if (aTestFile.originalPerms) { + logPerms += "original permissions: " + aTestFile.originalPerms.toString(8) + ", "; } - logPerms += "compare permissions : " + f.comparePerms.toString(8) + ", "; + logPerms += "compare permissions : " + aTestFile.comparePerms.toString(8) + ", "; logPerms += "updated permissions : " + testFile.permissions.toString(8); logTestInfo(logPerms); - do_check_eq(testFile.permissions & 0xfff, f.comparePerms & 0xfff); + do_check_eq(testFile.permissions & 0xfff, aTestFile.comparePerms & 0xfff); } - if (f.compareFile) { + if (aTestFile.compareFile) { do_check_eq(readFileBytes(testFile), - readFileBytes(do_get_file(f.compareFile))); + readFileBytes(do_get_file(aTestFile.compareFile))); } else { - do_check_eq(readFileBytes(testFile), f.compareContents); + do_check_eq(readFileBytes(testFile), aTestFile.compareContents); } } else { do_check_false(testFile.exists()); } - } + }); - checkFilesAfterUpdateCommon(aTestID); + logTestInfo("testing operations specified in removed-files were not " + + "performed after a failed update"); + TEST_DIRS.forEach(function CFAUF_TD_FE(aTestDir) { + let testDir = getApplyDirFile(aTestDir.relPathDir, true); + logTestInfo("testing directory file: " + testDir.path); + do_check_true(testDir.exists()); + + if (aTestDir.files) { + aTestDir.files.forEach(function CFAUS_TD_F_FE(aTestFile) { + let testFile = getApplyDirFile(aTestDir.relPathDir + aTestFile, true); + logTestInfo("testing directory file: " + testFile.path); + do_check_true(testFile.exists()); + }); + } + + if (aTestDir.subDirs) { + aTestDir.subDirs.forEach(function CFAUS_TD_SD_FE(aSubDir) { + let testSubDir = getApplyDirFile(aTestDir.relPathDir + aSubDir, true); + logTestInfo("testing sub-directory: " + testSubDir.path); + do_check_true(testSubDir.exists()); + if (aTestDir.subDirFiles) { + aTestDir.subDirFiles.forEach(function CFAUS_TD_SDF_FE(aTestFile) { + let testFile = getApplyDirFile(aTestDir.relPathDir + aSubDir + aTestFile, true); + logTestInfo("testing sub-directory file: " + testFile.path); + do_check_true(testFile.exists()); + }); + } + }); + } + }); + + checkFilesAfterUpdateCommon(); } /** - * Helper function for updater tests for verifying patch files and moz-backup - * files aren't left behind after a successful or failed update. - * - * @param aTestID - * A string used to identify the name of directories for a test. + * Helper function for updater binary tests for verifying patch files and + * moz-backup files aren't left behind after a successful or failed update. */ -function checkFilesAfterUpdateCommon(aTestID) { +function checkFilesAfterUpdateCommon() { logTestInfo("testing patch files should not be left behind"); - let updatesDir = do_get_file(aTestID + UPDATES_DIR_SUFFIX, true); + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX, true); let entries = updatesDir.QueryInterface(AUS_Ci.nsIFile).directoryEntries; while (entries.hasMoreElements()) { let entry = entries.getNext().QueryInterface(AUS_Ci.nsIFile); @@ -515,35 +805,30 @@ function checkFilesAfterUpdateCommon(aTestID) { } logTestInfo("testing backup files should not be left behind"); - let applyToDir = do_get_file(aTestID + APPLY_TO_DIR_SUFFIX, true); + let applyToDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX, true); checkFilesInDirRecursive(applyToDir, checkForBackupFiles); } /** - * Helper function for updater tests for verifying the contents of the updater - * callback application log which should contain the string executed and the - * arguments passed to the callback application. + * Helper function for updater binary tests for verifying the contents of the + * updater callback application log which should contain the arguments passed to + * the callback application. */ -function checkCallbackAppLog(aTestID) { - let appLaunchLog = do_get_file(aTestID + APPLY_TO_DIR_SUFFIX + "/" + - CALLBACK_ARGS[0], true); +function checkCallbackAppLog() { + let appLaunchLog = getApplyDirFile(CALLBACK_ARGS[1], true); if (!appLaunchLog.exists()) { - do_execute_soon(function() { - checkCallbackAppLog(aTestID); - }); + do_timeout(TEST_HELPER_TIMEOUT, checkCallbackAppLog); return; } - let expectedLogContents = "executed\n" + CALLBACK_ARGS.join("\n") + "\n"; - let logContents = readFile(appLaunchLog).replace(/\r\n/g, "\n"); + let expectedLogContents = CALLBACK_ARGS.join("\n") + "\n"; + let logContents = readFile(appLaunchLog); // It is possible for the log file contents check to occur before the log file // contents are completely written so wait until the contents are the expected // value. If the contents are never the expected value then the test will // fail by timing out. if (logContents != expectedLogContents) { - do_execute_soon(function() { - checkCallbackAppLog(aTestID); - }); + do_timeout(TEST_HELPER_TIMEOUT, checkCallbackAppLog); return; } @@ -551,12 +836,13 @@ function checkCallbackAppLog(aTestID) { "and the expected command line arguments passed to it"); do_check_eq(logContents, expectedLogContents); - do_test_finished(); + // Use a timeout to give any files that were in use additional time to close. + do_timeout(TEST_HELPER_TIMEOUT, do_test_finished); } /** - * Helper function for updater tests for verifying there are no update backup - * files left behind after an update. + * Helper function for updater binary tests for verifying there are no update + * backup files left behind after an update. * * @param aFile * An nsIFile to check if it has moz-backup for its extension. @@ -566,8 +852,9 @@ function checkForBackupFiles(aFile) { } /** - * Helper function for updater tests for recursively enumerating a directory and - * calls a callback function with the file as a parameter for each file found. + * Helper function for updater binary tests for recursively enumerating a + * directory and calling a callback function with the file as a parameter for + * each file found. * * @param aDir * A nsIFile for the directory to be deleted diff --git a/toolkit/mozapps/update/test/unit/test_0110_general.js b/toolkit/mozapps/update/test/unit/test_0110_general.js index 4c9702a8c8e0..657758312448 100644 --- a/toolkit/mozapps/update/test/unit/test_0110_general.js +++ b/toolkit/mozapps/update/test/unit/test_0110_general.js @@ -47,8 +47,8 @@ const MAX_TIME_DIFFERENCE = 60000; // The files are in the same order as they are applied from the mar const TEST_FILES = [ { - fileName : "1_1_image1.png", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00png0.png", + relPathDir : "0/00/", originalContents : null, compareContents : null, originalFile : null, @@ -56,8 +56,8 @@ const TEST_FILES = [ originalPerms : 0776, comparePerms : 0644 }, { - fileName : "1_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text0", + relPathDir : "0/00/", originalContents : "ToBeReplacedWithToBeModified\n", compareContents : "ToBeModified\n", originalFile : null, @@ -65,8 +65,8 @@ const TEST_FILES = [ originalPerms : 0775, comparePerms : 0644 }, { - fileName : "1_1_text2", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text1", + relPathDir : "0/00/", originalContents : "ToBeReplacedWithToBeDeleted\n", compareContents : "ToBeDeleted\n", originalFile : null, @@ -74,8 +74,8 @@ const TEST_FILES = [ originalPerms : 0677, comparePerms : 0644 }, { - fileName : "1_exe1.exe", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/", + fileName : "0exe0.exe", + relPathDir : "0/", originalContents : null, compareContents : null, originalFile : "data/partial.png", @@ -83,14 +83,23 @@ const TEST_FILES = [ originalPerms : 0777, comparePerms : 0755 }, { - fileName : "2_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/2/2_1/", + fileName : "10text0", + relPathDir : "1/10/", originalContents : "ToBeReplacedWithToBeDeleted\n", compareContents : "ToBeDeleted\n", originalFile : null, compareFile : null, originalPerms : 0767, comparePerms : 0644 +}, { + fileName : "exe0.exe", + relPathDir : "", + originalContents : null, + compareContents : null, + originalFile : "data/partial.png", + compareFile : "data/complete.png", + originalPerms : 0777, + comparePerms : 0755 }]; function run_test() { @@ -100,22 +109,12 @@ function run_test() { } do_test_pending(); - do_register_cleanup(end_test); + do_register_cleanup(cleanupUpdaterTest); - setupUpdaterTest(TEST_ID, MAR_COMPLETE_FILE, TEST_FILES); + setupUpdaterTest(MAR_COMPLETE_FILE); - // The testUpdate function is used for consistency with the tests that require - // a timeout before continuing the test. - testUpdate(); -} - -function end_test() { - cleanupUpdaterTest(TEST_ID); -} - -function testUpdate() { let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - let applyToDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX); + 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 @@ -127,7 +126,7 @@ function testUpdate() { } // apply the complete mar - let exitValue = runUpdate(TEST_ID); + let exitValue = runUpdate(); logTestInfo("testing updater binary process exitValue for success when " + "applying a complete mar"); do_check_eq(exitValue, 0); @@ -145,12 +144,12 @@ function testUpdate() { do_check_true(timeDiff < MAX_TIME_DIFFERENCE); } - checkFilesAfterUpdateSuccess(TEST_ID, TEST_FILES); + checkFilesAfterUpdateSuccess(); logTestInfo("testing tobedeleted directory doesn't exist"); let toBeDeletedDir = applyToDir.clone(); toBeDeletedDir.append("tobedeleted"); do_check_false(toBeDeletedDir.exists()); - checkCallbackAppLog(TEST_ID); + checkCallbackAppLog(); } diff --git a/toolkit/mozapps/update/test/unit/test_0111_general.js b/toolkit/mozapps/update/test/unit/test_0111_general.js index 04973e779153..969fb4e31cf4 100644 --- a/toolkit/mozapps/update/test/unit/test_0111_general.js +++ b/toolkit/mozapps/update/test/unit/test_0111_general.js @@ -47,8 +47,8 @@ const MAX_TIME_DIFFERENCE = 60000; // The files are in the same order as they are applied from the mar const TEST_FILES = [ { - fileName : "1_1_image1.png", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00png0.png", + relPathDir : "0/00/", originalContents : null, compareContents : null, originalFile : "data/complete.png", @@ -56,8 +56,8 @@ const TEST_FILES = [ originalPerms : 0644, comparePerms : null }, { - fileName : "1_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text0", + relPathDir : "0/00/", originalContents : "ToBeModified\n", compareContents : "Modified\n", originalFile : null, @@ -65,8 +65,8 @@ const TEST_FILES = [ originalPerms : 0644, comparePerms : null }, { - fileName : "1_1_text2", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text1", + relPathDir : "0/00/", originalContents : "ToBeDeleted\n", compareContents : null, originalFile : null, @@ -74,8 +74,8 @@ const TEST_FILES = [ originalPerms : null, comparePerms : null }, { - fileName : "1_exe1.exe", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/", + fileName : "0exe0.exe", + relPathDir : "0/", originalContents : null, compareContents : null, originalFile : "data/complete.png", @@ -83,8 +83,8 @@ const TEST_FILES = [ originalPerms : 0755, comparePerms : null }, { - fileName : "2_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/2/2_1/", + fileName : "10text0", + relPathDir : "1/10/", originalContents : "ToBeDeleted\n", compareContents : null, originalFile : null, @@ -92,8 +92,8 @@ const TEST_FILES = [ originalPerms : null, comparePerms : null }, { - fileName : "1_1_text3", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text2", + relPathDir : "0/00/", originalContents : null, compareContents : "Added\n", originalFile : null, @@ -101,14 +101,23 @@ const TEST_FILES = [ originalPerms : null, comparePerms : 0644 }, { - fileName : "3_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/3/3_1/", + fileName : "20text0", + relPathDir : "2/20/", originalContents : null, compareContents : "Added\n", originalFile : null, compareFile : null, originalPerms : null, comparePerms : 0644 +}, { + fileName : "exe0.exe", + relPathDir : "", + originalContents : null, + compareContents : null, + originalFile : "data/complete.png", + compareFile : "data/partial.png", + originalPerms : 0755, + comparePerms : null }]; function run_test() { @@ -118,22 +127,12 @@ function run_test() { } do_test_pending(); - do_register_cleanup(end_test); + do_register_cleanup(cleanupUpdaterTest); - setupUpdaterTest(TEST_ID, MAR_PARTIAL_FILE, TEST_FILES); + setupUpdaterTest(MAR_PARTIAL_FILE); - // The testUpdate function is used for consistency with the tests that require - // a timeout before continuing the test. - testUpdate(); -} - -function end_test() { - cleanupUpdaterTest(TEST_ID); -} - -function testUpdate() { let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - let applyToDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX); + 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 @@ -145,7 +144,7 @@ function testUpdate() { } // apply the partial mar - let exitValue = runUpdate(TEST_ID); + let exitValue = runUpdate(); logTestInfo("testing updater binary process exitValue for success when " + "applying a partial mar"); do_check_eq(exitValue, 0); @@ -163,18 +162,12 @@ function testUpdate() { do_check_true(timeDiff < MAX_TIME_DIFFERENCE); } - checkFilesAfterUpdateSuccess(TEST_ID, TEST_FILES); - - logTestInfo("testing directory still exists after removal of the last file " + - "in the directory (bug 386760)"); - let testDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/2/2_1/", - true); - do_check_true(testDir.exists()); + checkFilesAfterUpdateSuccess(); logTestInfo("testing tobedeleted directory doesn't exist"); let toBeDeletedDir = applyToDir.clone(); toBeDeletedDir.append("tobedeleted"); do_check_false(toBeDeletedDir.exists()); - checkCallbackAppLog(TEST_ID); + checkCallbackAppLog(); } diff --git a/toolkit/mozapps/update/test/unit/test_0112_general.js b/toolkit/mozapps/update/test/unit/test_0112_general.js index e12a847ecc70..0b11ac55216c 100644 --- a/toolkit/mozapps/update/test/unit/test_0112_general.js +++ b/toolkit/mozapps/update/test/unit/test_0112_general.js @@ -43,8 +43,8 @@ const TEST_ID = "0112"; // The files are in the same order as they are applied from the mar const TEST_FILES = [ { - fileName : "1_1_image1.png", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00png0.png", + relPathDir : "0/00/", originalContents : null, compareContents : null, originalFile : "data/complete.png", @@ -52,8 +52,8 @@ const TEST_FILES = [ originalPerms : 0644, comparePerms : null }, { - fileName : "1_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text0", + relPathDir : "0/00/", originalContents : "ShouldNotBeDeleted\n", compareContents : "ShouldNotBeDeleted\n", originalFile : null, @@ -61,8 +61,8 @@ const TEST_FILES = [ originalPerms : 0644, comparePerms : null }, { - fileName : "1_1_text2", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text1", + relPathDir : "0/00/", originalContents : "ShouldNotBeDeleted\n", compareContents : "ShouldNotBeDeleted\n", originalFile : null, @@ -70,8 +70,8 @@ const TEST_FILES = [ originalPerms : 0644, comparePerms : null }, { - fileName : "1_exe1.exe", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/", + fileName : "0exe0.exe", + relPathDir : "0/", originalContents : null, compareContents : null, originalFile : "data/partial.png", @@ -79,14 +79,23 @@ const TEST_FILES = [ originalPerms : 0755, comparePerms : null }, { - fileName : "2_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/2/2_1/", + fileName : "10text0", + relPathDir : "1/10/", originalContents : "ShouldNotBeDeleted\n", compareContents : "ShouldNotBeDeleted\n", originalFile : null, compareFile : null, originalPerms : 0644, comparePerms : null +}, { + fileName : "exe0.exe", + relPathDir : "", + originalContents : null, + compareContents : null, + originalFile : "data/partial.png", + compareFile : "data/partial.png", + originalPerms : 0755, + comparePerms : null }]; function run_test() { @@ -96,22 +105,12 @@ function run_test() { } do_test_pending(); - do_register_cleanup(end_test); + do_register_cleanup(cleanupUpdaterTest); - setupUpdaterTest(TEST_ID, MAR_PARTIAL_FILE, TEST_FILES); + setupUpdaterTest(MAR_PARTIAL_FILE); - // The testUpdate function is used for consistency with the tests that require - // a timeout before continuing the test. - testUpdate(); -} - -function end_test() { - cleanupUpdaterTest(TEST_ID); -} - -function testUpdate() { let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - let applyToDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX); + let applyToDir = getApplyDirFile(); // For Mac OS X set the last modified time for a directory to a date in the // past to test that the last modified time on the directories in not updated @@ -129,7 +128,7 @@ function testUpdate() { } // apply the partial mar - let exitValue = runUpdate(TEST_ID); + let exitValue = runUpdate(); logTestInfo("testing updater binary process exitValue for success when " + "applying a partial mar"); do_check_eq(exitValue, 0); @@ -147,12 +146,12 @@ function testUpdate() { do_check_eq(applyToDir.lastModifiedTime, lastModTime); } - checkFilesAfterUpdateFailure(TEST_ID, TEST_FILES); + checkFilesAfterUpdateFailure(); logTestInfo("testing tobedeleted directory doesn't exist"); let toBeDeletedDir = applyToDir.clone(); toBeDeletedDir.append("tobedeleted"); do_check_false(toBeDeletedDir.exists()); - checkCallbackAppLog(TEST_ID); + checkCallbackAppLog(); } diff --git a/toolkit/mozapps/update/test/unit/test_0160_appInUse_xp_unix_complete.js b/toolkit/mozapps/update/test/unit/test_0160_appInUse_xp_unix_complete.js index 5a2ac2b29c3f..30a8c498063a 100644 --- a/toolkit/mozapps/update/test/unit/test_0160_appInUse_xp_unix_complete.js +++ b/toolkit/mozapps/update/test/unit/test_0160_appInUse_xp_unix_complete.js @@ -9,14 +9,12 @@ const TEST_ID = "0160"; // 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; -// Time to wait for the test helper process to start before continuing the test -const TEST_HELPER_TIMEOUT = 1000; // The files are in the same order as they are applied from the mar const TEST_FILES = [ { - fileName : "1_1_image1.png", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00png0.png", + relPathDir : "0/00/", originalContents : null, compareContents : null, originalFile : null, @@ -24,8 +22,8 @@ const TEST_FILES = [ originalPerms : 0776, comparePerms : 0644 }, { - fileName : "1_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text0", + relPathDir : "0/00/", originalContents : "ToBeReplacedWithToBeModified\n", compareContents : "ToBeModified\n", originalFile : null, @@ -33,8 +31,8 @@ const TEST_FILES = [ originalPerms : 0775, comparePerms : 0644 }, { - fileName : "1_1_text2", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text0", + relPathDir : "0/00/", originalContents : "ToBeReplacedWithToBeDeleted\n", compareContents : "ToBeDeleted\n", originalFile : null, @@ -42,8 +40,8 @@ const TEST_FILES = [ originalPerms : 0677, comparePerms : 0644 }, { - fileName : "1_exe1.exe", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/", + fileName : "0exe0.exe", + relPathDir : "0/", originalContents : null, compareContents : null, originalFile : "data/partial.png", @@ -51,18 +49,25 @@ const TEST_FILES = [ originalPerms : 0777, comparePerms : 0755 }, { - fileName : "2_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/2/2_1/", + fileName : "10text0", + relPathDir : "1/10/", originalContents : "ToBeReplacedWithToBeDeleted\n", compareContents : "ToBeDeleted\n", originalFile : null, compareFile : null, originalPerms : 0767, comparePerms : 0644 +}, { + fileName : "exe0.exe", + relPathDir : "", + originalContents : null, + compareContents : null, + originalFile : "data/partial.png", + compareFile : "data/complete.png", + originalPerms : 0777, + comparePerms : 0755 }]; -let gCallbackAppProcess; - function run_test() { if (!IS_UNIX || IS_ANDROID) { logTestInfo("this test is only applicable to XP_UNIX platforms except " + @@ -71,33 +76,24 @@ function run_test() { } do_test_pending(); - do_register_cleanup(end_test); + do_register_cleanup(cleanupUpdaterTest); - setupUpdaterTest(TEST_ID, MAR_COMPLETE_FILE, TEST_FILES); + setupUpdaterTest(MAR_COMPLETE_FILE); // Launch the callback helper application so it is in use during the update - let callbackApp = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX); - callbackApp.append(AFTER_APPLY_DIR); - callbackApp.append(CALLBACK_BIN_FILE); + let callbackApp = getApplyDirFile(CALLBACK_BIN_FILE); callbackApp.permissions = PERMS_DIRECTORY; - let args = ["-s", "20"]; - gCallbackAppProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - gCallbackAppProcess.init(callbackApp); - gCallbackAppProcess.run(false, args, args.length); + let args = [getApplyDirPath(), "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); - // Give the lock file process time to lock the file before updating otherwise - // this test can fail intermittently on Windows debug builds. - do_timeout(TEST_HELPER_TIMEOUT, testUpdate); + do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); } -function end_test() { - cleanupUpdaterTest(TEST_ID); -} - -function testUpdate() { - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - let applyToDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX); +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 @@ -109,12 +105,18 @@ function testUpdate() { } // apply the complete mar - let exitValue = runUpdate(TEST_ID); + let exitValue = runUpdate(); logTestInfo("testing updater binary process exitValue for success when " + "applying a complete mar"); do_check_eq(exitValue, 0); - gCallbackAppProcess.kill(); + setupHelperFinish(); +} + + +function checkUpdate() { + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); + let applyToDir = getApplyDirFile(); logTestInfo("testing update.status should be " + STATE_SUCCEEDED); do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); @@ -129,7 +131,7 @@ function testUpdate() { do_check_true(timeDiff < MAX_TIME_DIFFERENCE); } - checkFilesAfterUpdateSuccess(TEST_ID, TEST_FILES); + checkFilesAfterUpdateSuccess(); - checkCallbackAppLog(TEST_ID); + checkCallbackAppLog(); } diff --git a/toolkit/mozapps/update/test/unit/test_0160_appInUse_xp_win_complete.js b/toolkit/mozapps/update/test/unit/test_0160_appInUse_xp_win_complete.js index c67c3d1ca086..5b0075c81cce 100644 --- a/toolkit/mozapps/update/test/unit/test_0160_appInUse_xp_win_complete.js +++ b/toolkit/mozapps/update/test/unit/test_0160_appInUse_xp_win_complete.js @@ -5,50 +5,53 @@ /* Application in use complete MAR file patch apply failure test */ const TEST_ID = "0160"; -// Time to wait for the test helper process to start before continuing the test -const TEST_HELPER_TIMEOUT = 1000; // The files are in the same order as they are applied from the mar const TEST_FILES = [ { - fileName : "1_1_image1.png", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00png0.png", + relPathDir : "0/00/", originalContents : null, compareContents : null, originalFile : "data/partial.png", compareFile : "data/partial.png" }, { - fileName : "1_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text0", + relPathDir : "0/00/", originalContents : "ShouldNotBeReplaced\n", compareContents : "ShouldNotBeReplaced\n", originalFile : null, compareFile : null }, { - fileName : "1_1_text2", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text1", + relPathDir : "0/00/", originalContents : "ShouldNotBeReplaced\n", compareContents : "ShouldNotBeReplaced\n", originalFile : null, compareFile : null }, { - fileName : "1_exe1.exe", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/", + fileName : "0exe0.exe", + relPathDir : "0/", originalContents : null, compareContents : null, originalFile : "data/partial.png", compareFile : "data/partial.png" }, { - fileName : "2_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/2/2_1/", + fileName : "10text0", + relPathDir : "1/10/", originalContents : "ShouldNotBeReplaced\n", compareContents : "ShouldNotBeReplaced\n", originalFile : null, compareFile : null +}, { + fileName : "exe0.exe", + relPathDir : "", + originalContents : null, + compareContents : null, + originalFile : "data/partial.png", + compareFile : "data/partial.png" }]; -let gCallbackAppProcess; - function run_test() { if (!IS_WIN || IS_WINCE) { logTestInfo("this test is only applicable to Windows... returning early"); @@ -56,52 +59,46 @@ function run_test() { } do_test_pending(); - do_register_cleanup(end_test); + do_register_cleanup(cleanupUpdaterTest); - setupUpdaterTest(TEST_ID, MAR_COMPLETE_FILE, TEST_FILES); + setupUpdaterTest(MAR_COMPLETE_FILE); // Launch the callback helper application so it is in use during the update - let callbackApp = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX); - callbackApp.append(AFTER_APPLY_DIR); - callbackApp.append(CALLBACK_BIN_FILE); - let args = ["-s", "20"]; - gCallbackAppProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - gCallbackAppProcess.init(callbackApp); - gCallbackAppProcess.run(false, args, args.length); + let callbackApp = getApplyDirFile(CALLBACK_BIN_FILE); + let args = [getApplyDirPath(), "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); - // Give the lock file process time to lock the file before updating otherwise - // this test can fail intermittently on Windows debug builds. - do_timeout(TEST_HELPER_TIMEOUT, testUpdate); + do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); } -function end_test() { - cleanupUpdaterTest(TEST_ID); -} - -function testUpdate() { - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - let applyToDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX); - +function doUpdate() { // apply the complete mar - let exitValue = runUpdate(TEST_ID); - logTestInfo("testing updater binary process exitValue for success when " + + let exitValue = runUpdate(); + logTestInfo("testing updater binary process exitValue for failure when " + "applying a complete mar"); do_check_eq(exitValue, 1); - gCallbackAppProcess.kill(); + setupHelperFinish(); +} + +function checkUpdate() { + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); + let applyToDir = getApplyDirFile(); 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(TEST_ID, TEST_FILES); + checkFilesAfterUpdateFailure(); logTestInfo("testing tobedeleted directory doesn't exist"); let toBeDeletedDir = applyToDir.clone(); toBeDeletedDir.append("tobedeleted"); do_check_false(toBeDeletedDir.exists()); - checkCallbackAppLog(TEST_ID); + checkCallbackAppLog(); } diff --git a/toolkit/mozapps/update/test/unit/test_0170_fileLocked_xp_win_complete.js b/toolkit/mozapps/update/test/unit/test_0170_fileLocked_xp_win_complete.js index 892669494385..79d58e847b73 100644 --- a/toolkit/mozapps/update/test/unit/test_0170_fileLocked_xp_win_complete.js +++ b/toolkit/mozapps/update/test/unit/test_0170_fileLocked_xp_win_complete.js @@ -5,50 +5,53 @@ /* File locked complete MAR file patch apply failure test */ const TEST_ID = "0170"; -// Time to wait for the test helper process to start before continuing the test -const TEST_HELPER_TIMEOUT = 1000; // The files are in the same order as they are applied from the mar const TEST_FILES = [ { - fileName : "1_1_image1.png", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00png0.png", + relPathDir : "0/00/", originalContents : null, compareContents : null, originalFile : "data/partial.png", compareFile : "data/partial.png" }, { - fileName : "1_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text0", + relPathDir : "0/00/", originalContents : "ShouldNotBeReplaced\n", compareContents : "ShouldNotBeReplaced\n", originalFile : null, compareFile : null }, { - fileName : "1_1_text2", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text1", + relPathDir : "0/00/", originalContents : "ShouldNotBeReplaced\n", compareContents : "ShouldNotBeReplaced\n", originalFile : null, compareFile : null }, { - fileName : "1_exe1.exe", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/", + fileName : "0exe0.exe", + relPathDir : "0/", originalContents : null, compareContents : null, originalFile : "data/partial.png", compareFile : "data/partial.png" }, { - fileName : "2_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/2/2_1/", + fileName : "10text0", + relPathDir : "1/10/", originalContents : "ShouldNotBeReplaced\n", compareContents : "ShouldNotBeReplaced\n", originalFile : null, compareFile : null +}, { + fileName : "exe0.exe", + relPathDir : "", + originalContents : null, + compareContents : null, + originalFile : "data/partial.png", + compareFile : "data/partial.png" }]; -let gLockFileProcess; - function run_test() { if (!IS_WIN || IS_WINCE) { logTestInfo("this test is only applicable to Windows... returning early"); @@ -56,51 +59,50 @@ function run_test() { } do_test_pending(); - do_register_cleanup(end_test); + do_register_cleanup(cleanupUpdaterTest); - setupUpdaterTest(TEST_ID, MAR_COMPLETE_FILE, TEST_FILES); + 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 lockFileRelPath = TEST_FILES[3].destinationDir + TEST_FILES[3].fileName; - let args = ["-s", "20", lockFileRelPath]; - gLockFileProcess = AUS_Cc["@mozilla.org/process/util;1"]. + let applyToDir = getApplyDirFile(); + helperBin.copyTo(applyToDir, HELPER_BIN_FILE); + helperBin = getApplyDirFile(HELPER_BIN_FILE); + let lockFileRelPath = TEST_FILES[3].relPathDir + TEST_FILES[3].fileName; + let args = [getApplyDirPath(), "input", "output", "-s", "20", lockFileRelPath]; + let lockFileProcess = AUS_Cc["@mozilla.org/process/util;1"]. createInstance(AUS_Ci.nsIProcess); - gLockFileProcess.init(helperBin); - gLockFileProcess.run(false, args, args.length); + lockFileProcess.init(helperBin); + lockFileProcess.run(false, args, args.length); - // Give the lock file process time to lock the file before updating otherwise - // this test can fail intermittently on Windows debug builds. - do_timeout(TEST_HELPER_TIMEOUT, testUpdate); + do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); } -function end_test() { - cleanupUpdaterTest(TEST_ID); -} - -function testUpdate() { - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - let applyToDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX); - +function doUpdate() { // apply the complete mar - let exitValue = runUpdate(TEST_ID); + let exitValue = runUpdate(); logTestInfo("testing updater binary process exitValue for success when " + "applying a complete mar"); do_check_eq(exitValue, 0); - gLockFileProcess.kill(); + setupHelperFinish(); +} + +function checkUpdate() { + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); + let applyToDir = getApplyDirFile(); 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(TEST_ID, TEST_FILES); + checkFilesAfterUpdateFailure(); logTestInfo("testing tobedeleted directory doesn't exist"); let toBeDeletedDir = applyToDir.clone(); toBeDeletedDir.append("tobedeleted"); do_check_false(toBeDeletedDir.exists()); - checkCallbackAppLog(TEST_ID); + checkCallbackAppLog(); } diff --git a/toolkit/mozapps/update/test/unit/test_0171_fileLocked_xp_win_partial.js b/toolkit/mozapps/update/test/unit/test_0171_fileLocked_xp_win_partial.js index 8dc2ba02ebf0..921207c1c05c 100644 --- a/toolkit/mozapps/update/test/unit/test_0171_fileLocked_xp_win_partial.js +++ b/toolkit/mozapps/update/test/unit/test_0171_fileLocked_xp_win_partial.js @@ -5,50 +5,55 @@ /* File locked partial MAR file patch apply failure test */ const TEST_ID = "0171"; -// Time to wait for the test helper process to start before continuing the test -const TEST_HELPER_TIMEOUT = 1000; // The files are in the same order as they are applied from the mar const TEST_FILES = [ { - fileName : "1_1_image1.png", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", - originalContents : null, - compareContents : null, - originalFile : "data/partial.png", - compareFile : "data/partial.png" -}, { - fileName : "1_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", - originalContents : "ShouldNotBeModified\n", - compareContents : "ShouldNotBeModified\n", - originalFile : null, - compareFile : null -}, { - fileName : "1_1_text2", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", - originalContents : "ShouldNotBeDeleted\n", - compareContents : "ShouldNotBeDeleted\n", - originalFile : null, - compareFile : null -}, { - fileName : "1_exe1.exe", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/", + fileName : "00png0.png", + relPathDir : "0/00/", originalContents : null, compareContents : null, originalFile : "data/complete.png", compareFile : "data/complete.png" }, { - fileName : "2_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/2/2_1/", + fileName : "00text0", + relPathDir : "0/00/", + originalContents : "ShouldNotBeModified\n", + compareContents : "ShouldNotBeModified\n", + originalFile : null, + compareFile : null +}, { + fileName : "00text1", + relPathDir : "0/00/", originalContents : "ShouldNotBeDeleted\n", compareContents : "ShouldNotBeDeleted\n", originalFile : null, compareFile : null +}, { + fileName : "0exe0.exe", + relPathDir : "0/", + originalContents : null, + compareContents : null, + originalFile : "data/complete.png", + compareFile : "data/complete.png" +}, { + fileName : "10text0", + relPathDir : "1/10/", + originalContents : "ShouldNotBeDeleted\n", + compareContents : "ShouldNotBeDeleted\n", + originalFile : null, + compareFile : null +}, { + fileName : "exe0.exe", + relPathDir : "", + originalContents : null, + compareContents : null, + originalFile : "data/complete.png", + compareFile : "data/complete.png" }]; -let gLockFileProcess; - +// XXX LoadSourceFile: destination file size 759 does not match expected size 854 +// Needs helper since it is a partial function run_test() { if (!IS_WIN || IS_WINCE) { logTestInfo("this test is only applicable to Windows... returning early"); @@ -56,51 +61,50 @@ function run_test() { } do_test_pending(); - do_register_cleanup(end_test); + do_register_cleanup(cleanupUpdaterTest); - setupUpdaterTest(TEST_ID, MAR_PARTIAL_FILE, TEST_FILES); + 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 lockFileRelPath = TEST_FILES[3].destinationDir + TEST_FILES[3].fileName; - let args = ["-s", "20", lockFileRelPath]; - gLockFileProcess = AUS_Cc["@mozilla.org/process/util;1"]. + let applyToDir = getApplyDirFile(); + helperBin.copyTo(applyToDir, HELPER_BIN_FILE); + helperBin = getApplyDirFile(HELPER_BIN_FILE); + let lockFileRelPath = TEST_FILES[3].relPathDir + TEST_FILES[3].fileName; + let args = [getApplyDirPath(), "input", "output", "-s", "20", lockFileRelPath]; + let lockFileProcess = AUS_Cc["@mozilla.org/process/util;1"]. createInstance(AUS_Ci.nsIProcess); - gLockFileProcess.init(helperBin); - gLockFileProcess.run(false, args, args.length); + lockFileProcess.init(helperBin); + lockFileProcess.run(false, args, args.length); - // Give the lock file process time to lock the file before updating otherwise - // this test can fail intermittently on Windows debug builds. - do_timeout(TEST_HELPER_TIMEOUT, testUpdate); + do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); } -function end_test() { - cleanupUpdaterTest(TEST_ID); -} - -function testUpdate() { - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - let applyToDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX); - - // apply the partial mar - let exitValue = runUpdate(TEST_ID); +function doUpdate() { + // apply the complete mar + let exitValue = runUpdate(); logTestInfo("testing updater binary process exitValue for success when " + "applying a partial mar"); do_check_eq(exitValue, 0); - gLockFileProcess.kill(); + setupHelperFinish(); +} + +function checkUpdate() { + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); + let applyToDir = getApplyDirFile(); 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(TEST_ID, TEST_FILES); + checkFilesAfterUpdateFailure(); logTestInfo("testing tobedeleted directory doesn't exist"); let toBeDeletedDir = applyToDir.clone(); toBeDeletedDir.append("tobedeleted"); do_check_false(toBeDeletedDir.exists()); - checkCallbackAppLog(TEST_ID); + checkCallbackAppLog(); } diff --git a/toolkit/mozapps/update/test/unit/test_0180_fileInUse_xp_win_complete.js b/toolkit/mozapps/update/test/unit/test_0180_fileInUse_xp_win_complete.js index 6641108a2d09..df0422ddd716 100644 --- a/toolkit/mozapps/update/test/unit/test_0180_fileInUse_xp_win_complete.js +++ b/toolkit/mozapps/update/test/unit/test_0180_fileInUse_xp_win_complete.js @@ -5,50 +5,53 @@ /* File in use complete MAR file patch apply success test */ const TEST_ID = "0180"; -// Time to wait for the test helper process to start before continuing the test -const TEST_HELPER_TIMEOUT = 1000; // The files are in the same order as they are applied from the mar const TEST_FILES = [ { - fileName : "1_1_image1.png", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00png0.png", + relPathDir : "0/00/", originalContents : null, compareContents : null, originalFile : null, compareFile : "data/complete.png" }, { - fileName : "1_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text0", + relPathDir : "0/00/", originalContents : "ToBeReplacedWithToBeModified\n", compareContents : "ToBeModified\n", originalFile : null, compareFile : null }, { - fileName : "1_1_text2", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text1", + relPathDir : "0/00/", originalContents : "ToBeReplacedWithToBeDeleted\n", compareContents : "ToBeDeleted\n", originalFile : null, compareFile : null }, { - fileName : "1_exe1.exe", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/", + fileName : "0exe0.exe", + relPathDir : "0/", originalContents : null, compareContents : null, originalFile : HELPER_BIN_FILE, compareFile : "data/complete.png" }, { - fileName : "2_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/2/2_1/", + fileName : "10text0", + relPathDir : "1/10/", originalContents : "ToBeReplacedWithToBeDeleted\n", compareContents : "ToBeDeleted\n", originalFile : null, compareFile : null +}, { + fileName : "exe0.exe", + relPathDir : "", + originalContents : null, + compareContents : null, + originalFile : HELPER_BIN_FILE, + compareFile : "data/complete.png" }]; -let gFileInUseProcess; - function run_test() { if (!IS_WIN || IS_WINCE) { logTestInfo("this test is only applicable to Windows... returning early"); @@ -56,49 +59,45 @@ function run_test() { } do_test_pending(); - do_register_cleanup(end_test); + do_register_cleanup(cleanupUpdaterTest); - setupUpdaterTest(TEST_ID, MAR_COMPLETE_FILE, TEST_FILES); + setupUpdaterTest(MAR_COMPLETE_FILE); // Launch an existing file so it is in use during the update - let fileInUseBin = do_get_file(TEST_FILES[3].destinationDir + - TEST_FILES[3].fileName); - let args = ["-s", "20"]; - gFileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - gFileInUseProcess.init(fileInUseBin); - gFileInUseProcess.run(false, args, args.length); + let fileInUseBin = getApplyDirFile(TEST_FILES[3].relPathDir + + TEST_FILES[3].fileName); + let args = [getApplyDirPath(), "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); - // Give the file in use process time to launch before updating otherwise this - // test can fail intermittently on Windows debug builds. - do_timeout(TEST_HELPER_TIMEOUT, testUpdate); + do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); } -function end_test() { - cleanupUpdaterTest(TEST_ID); -} - -function testUpdate() { - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - let applyToDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX); - +function doUpdate() { // apply the complete mar - let exitValue = runUpdate(TEST_ID); + let exitValue = runUpdate(); logTestInfo("testing updater binary process exitValue for success when " + "applying a complete mar"); do_check_eq(exitValue, 0); - gFileInUseProcess.kill(); + setupHelperFinish(); +} + +function checkUpdate() { + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); + let applyToDir = getApplyDirFile(); logTestInfo("testing update.status should be " + STATE_SUCCEEDED); do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); - checkFilesAfterUpdateSuccess(TEST_ID, TEST_FILES); + checkFilesAfterUpdateSuccess(); logTestInfo("testing tobedeleted directory exists"); let toBeDeletedDir = applyToDir.clone(); toBeDeletedDir.append("tobedeleted"); do_check_true(toBeDeletedDir.exists()); - checkCallbackAppLog(TEST_ID); + checkCallbackAppLog(); } diff --git a/toolkit/mozapps/update/test/unit/test_0181_fileInUse_xp_win_partial.js b/toolkit/mozapps/update/test/unit/test_0181_fileInUse_xp_win_partial.js index c5201f1e6ace..50fabf953d06 100644 --- a/toolkit/mozapps/update/test/unit/test_0181_fileInUse_xp_win_partial.js +++ b/toolkit/mozapps/update/test/unit/test_0181_fileInUse_xp_win_partial.js @@ -6,64 +6,67 @@ const TEST_ID = "0181"; const MAR_IN_USE_WIN_FILE = "data/partial_in_use_win.mar"; -// Time to wait for the test helper process to start before continuing the test -const TEST_HELPER_TIMEOUT = 1000; // The files are in the same order as they are applied from the mar var TEST_FILES = [ { - fileName : "1_1_image1.png", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00png0.png", + relPathDir : "0/00/", originalContents : null, compareContents : null, originalFile : "data/complete.png", compareFile : "data/partial.png" }, { - fileName : "1_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text0", + relPathDir : "0/00/", originalContents : "ToBeModified\n", compareContents : "Modified\n", originalFile : null, compareFile : null }, { - fileName : "1_1_text2", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text1", + relPathDir : "0/00/", originalContents : "ToBeDeleted\n", compareContents : null, originalFile : null, compareFile : null }, { - fileName : "1_exe1.exe", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/", + fileName : "0exe0.exe", + relPathDir : "0/", originalContents : null, compareContents : null, originalFile : "data/partial_in_use_win_before.exe", compareFile : "data/partial_in_use_win_after.exe" }, { - fileName : "2_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/2/2_1/", + fileName : "10text0", + relPathDir : "1/10/", originalContents : "ToBeDeleted\n", compareContents : null, originalFile : null, compareFile : null }, { - fileName : "1_1_text3", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/1/1_1/", + fileName : "00text2", + relPathDir : "0/00/", originalContents : null, compareContents : "Added\n", originalFile : null, compareFile : null }, { - fileName : "3_1_text1", - destinationDir : TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/3/3_1/", + fileName : "20text0", + relPathDir : "2/20/", originalContents : null, compareContents : "Added\n", originalFile : null, compareFile : null +}, { + fileName : "exe0.exe", + relPathDir : "", + originalContents : null, + compareContents : null, + originalFile : "data/partial_in_use_win_before.exe", + compareFile : "data/partial_in_use_win_after.exe" }]; -let gFileInUseProcess; - function run_test() { if (!IS_WIN || IS_WINCE) { logTestInfo("this test is only applicable to Windows... returning early"); @@ -71,51 +74,45 @@ function run_test() { } do_test_pending(); - do_register_cleanup(end_test); + do_register_cleanup(cleanupUpdaterTest); - setupUpdaterTest(TEST_ID, MAR_IN_USE_WIN_FILE, TEST_FILES); + setupUpdaterTest(MAR_IN_USE_WIN_FILE); // Launch an existing file so it is in use during the update - let fileInUseBin = do_get_file(TEST_FILES[3].destinationDir + - TEST_FILES[3].fileName); - let args = ["-s", "20"]; - gFileInUseProcess = AUS_Cc["@mozilla.org/process/util;1"]. - createInstance(AUS_Ci.nsIProcess); - gFileInUseProcess.init(fileInUseBin); - gFileInUseProcess.run(false, args, args.length); + let fileInUseBin = getApplyDirFile(TEST_FILES[3].relPathDir + + TEST_FILES[3].fileName); + let args = [getApplyDirPath(), "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); - // Give the file in use process time to launch before updating otherwise this - // test can fail intermittently on Windows debug builds. - do_timeout(TEST_HELPER_TIMEOUT, testUpdate); + do_timeout(TEST_HELPER_TIMEOUT, waitForHelperSleep); } -function end_test() { - cleanupUpdaterTest(TEST_ID); -} - -function testUpdate() { - let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); - let applyToDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX); - - // apply the partial mar - let exitValue = runUpdate(TEST_ID); +function doUpdate() { + // apply the complete mar + let exitValue = runUpdate(); logTestInfo("testing updater binary process exitValue for success when " + "applying a partial mar"); do_check_eq(exitValue, 0); - gFileInUseProcess.kill(); + setupHelperFinish(); +} - checkFilesAfterUpdateSuccess(TEST_ID, TEST_FILES); +function checkUpdate() { + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); + let applyToDir = getApplyDirFile(); - logTestInfo("testing directory still exists after removal of the last file " + - "in the directory (bug 386760)"); - let testDir = do_get_file(TEST_ID + APPLY_TO_DIR_SUFFIX + "/mar_test/2/2_1/", true); - do_check_true(testDir.exists()); + logTestInfo("testing update.status should be " + STATE_SUCCEEDED); + do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); + + checkFilesAfterUpdateSuccess(); logTestInfo("testing tobedeleted directory exists"); let toBeDeletedDir = applyToDir.clone(); toBeDeletedDir.append("tobedeleted"); do_check_true(toBeDeletedDir.exists()); - checkCallbackAppLog(TEST_ID); + checkCallbackAppLog(); } diff --git a/toolkit/mozapps/update/test/unit/test_0182_rmrfdirFileInUse_xp_win_complete.js b/toolkit/mozapps/update/test/unit/test_0182_rmrfdirFileInUse_xp_win_complete.js new file mode 100644 index 000000000000..06c83210de71 --- /dev/null +++ b/toolkit/mozapps/update/test/unit/test_0182_rmrfdirFileInUse_xp_win_complete.js @@ -0,0 +1,113 @@ +/* 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 = "0182"; + +// The files are in the same order as they are applied from the mar +const TEST_FILES = [ +{ + fileName : "00png0.png", + relPathDir : "0/00/", + originalContents : null, + compareContents : null, + originalFile : null, + compareFile : "data/complete.png" +}, { + fileName : "00text0", + relPathDir : "0/00/", + originalContents : "ToBeReplacedWithToBeModified\n", + compareContents : "ToBeModified\n", + originalFile : null, + compareFile : null +}, { + fileName : "00text1", + relPathDir : "0/00/", + originalContents : "ToBeReplacedWithToBeDeleted\n", + compareContents : "ToBeDeleted\n", + originalFile : null, + compareFile : null +}, { + fileName : "0exe0.exe", + relPathDir : "0/", + originalContents : null, + compareContents : null, + originalFile : HELPER_BIN_FILE, + compareFile : "data/complete.png" +}, { + fileName : "10text0", + relPathDir : "1/10/", + originalContents : "ToBeReplacedWithToBeDeleted\n", + compareContents : "ToBeDeleted\n", + originalFile : null, + compareFile : null +}, { + fileName : "exe0.exe", + relPathDir : "", + originalContents : null, + compareContents : null, + originalFile : HELPER_BIN_FILE, + compareFile : "data/complete.png" +}]; + +function run_test() { + if (!IS_WIN || IS_WINCE) { + logTestInfo("this test is only applicable to Windows... returning early"); + 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(), "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 + let exitValue = runUpdate(); + logTestInfo("testing updater binary process exitValue for success when " + + "applying a complete mar"); + do_check_eq(exitValue, 0); + + setupHelperFinish(); +} + +function checkUpdate() { + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); + let applyToDir = getApplyDirFile(); + + logTestInfo("testing update.status should be " + STATE_SUCCEEDED); + do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); + + checkFilesAfterUpdateSuccess(); + + logTestInfo("testing tobedeleted directory exists"); + let toBeDeletedDir = applyToDir.clone(); + toBeDeletedDir.append("tobedeleted"); + do_check_true(toBeDeletedDir.exists()); + + checkCallbackAppLog(); +} diff --git a/toolkit/mozapps/update/test/unit/test_0183_rmrfdirFileInUse_xp_win_partial.js b/toolkit/mozapps/update/test/unit/test_0183_rmrfdirFileInUse_xp_win_partial.js new file mode 100644 index 000000000000..51c8203df47a --- /dev/null +++ b/toolkit/mozapps/update/test/unit/test_0183_rmrfdirFileInUse_xp_win_partial.js @@ -0,0 +1,126 @@ +/* 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 = "0183"; +const MAR_IN_USE_WIN_FILE = "data/partial.mar"; + +// The files are in the same order as they are applied from the mar +var TEST_FILES = [ +{ + fileName : "00png0.png", + relPathDir : "0/00/", + originalContents : null, + compareContents : null, + originalFile : "data/complete.png", + compareFile : "data/partial.png" +}, { + fileName : "00text0", + relPathDir : "0/00/", + originalContents : "ToBeModified\n", + compareContents : "Modified\n", + originalFile : null, + compareFile : null +}, { + fileName : "00text1", + relPathDir : "0/00/", + originalContents : "ToBeDeleted\n", + compareContents : null, + originalFile : null, + compareFile : null +}, { + fileName : "0exe0.exe", + relPathDir : "0/", + originalContents : null, + compareContents : null, + originalFile : "data/complete.png", + compareFile : "data/partial.png" +}, { + fileName : "10text0", + relPathDir : "1/10/", + originalContents : "ToBeDeleted\n", + compareContents : null, + originalFile : null, + compareFile : null +}, { + fileName : "00text2", + relPathDir : "0/00/", + originalContents : null, + compareContents : "Added\n", + originalFile : null, + compareFile : null +}, { + fileName : "20text0", + relPathDir : "2/20/", + originalContents : null, + compareContents : "Added\n", + originalFile : null, + compareFile : null +}, { + fileName : "exe0.exe", + relPathDir : "", + originalContents : null, + compareContents : null, + originalFile : "data/complete.png", + compareFile : "data/partial.png" +}]; + +function run_test() { + if (!IS_WIN || IS_WINCE) { + logTestInfo("this test is only applicable to Windows... returning early"); + 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(), "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 + let exitValue = runUpdate(); + logTestInfo("testing updater binary process exitValue for success when " + + "applying a partial mar"); + do_check_eq(exitValue, 0); + + setupHelperFinish(); +} + +function checkUpdate() { + let updatesDir = do_get_file(TEST_ID + UPDATES_DIR_SUFFIX); + let applyToDir = getApplyDirFile(); + + logTestInfo("testing update.status should be " + STATE_SUCCEEDED); + do_check_eq(readStatusFile(updatesDir), STATE_SUCCEEDED); + + checkFilesAfterUpdateSuccess(); + + logTestInfo("testing tobedeleted directory exists"); + let toBeDeletedDir = applyToDir.clone(); + toBeDeletedDir.append("tobedeleted"); + do_check_true(toBeDeletedDir.exists()); + + checkCallbackAppLog(); +}