michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: /** michael@0: * Test applying an update by staging an update and launching an application to michael@0: * apply it. michael@0: */ michael@0: michael@0: function run_test() { michael@0: if (MOZ_APP_NAME == "xulrunner") { michael@0: logTestInfo("Unable to run this test on xulrunner"); michael@0: return; michael@0: } michael@0: michael@0: setupTestCommon(); michael@0: gTestFiles = gTestFilesCompleteSuccess; michael@0: gTestDirs = gTestDirsCompleteSuccess; michael@0: setupUpdaterTest(FILE_COMPLETE_MAR, false, false); michael@0: michael@0: // For Mac OS X set the last modified time for the root directory to a date in michael@0: // the past to test that the last modified time is updated on a successful michael@0: // update (bug 600098). michael@0: if (IS_MACOSX) { michael@0: let now = Date.now(); michael@0: let yesterday = now - (1000 * 60 * 60 * 24); michael@0: let applyToDir = getApplyDirFile(); michael@0: applyToDir.lastModifiedTime = yesterday; michael@0: } michael@0: michael@0: let channel = Services.prefs.getCharPref(PREF_APP_UPDATE_CHANNEL); michael@0: let patches = getLocalPatchString(null, null, null, null, null, "true", michael@0: STATE_PENDING); michael@0: let updates = getLocalUpdateString(patches, null, null, null, null, null, michael@0: null, null, null, null, null, null, michael@0: null, "true", channel); michael@0: writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); michael@0: writeVersionFile(getAppVersion()); michael@0: writeStatusFile(STATE_PENDING); michael@0: michael@0: setupAppFilesAsync(); michael@0: } michael@0: michael@0: function setupAppFilesFinished() { michael@0: do_timeout(TEST_CHECK_TIMEOUT, launchAppToApplyUpdate); michael@0: } michael@0: michael@0: /** michael@0: * Checks if the update has finished and if it has finished performs checks for michael@0: * the test. michael@0: */ michael@0: function checkUpdateFinished() { michael@0: gTimeoutRuns++; michael@0: // Don't proceed until the update's status state is the expected value. michael@0: let state = readStatusState(); michael@0: if (state != STATE_SUCCEEDED) { michael@0: if (gTimeoutRuns > MAX_TIMEOUT_RUNS) { michael@0: do_throw("Exceeded MAX_TIMEOUT_RUNS while waiting for the update " + michael@0: "status state to equal: " + STATE_SUCCEEDED + michael@0: ", current status state: " + state); michael@0: } else { michael@0: do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished); michael@0: } michael@0: return; michael@0: } michael@0: michael@0: // Don't proceed until the update log has been created. michael@0: let log = getUpdatesPatchDir(); michael@0: log.append(FILE_UPDATE_LOG); michael@0: if (!log.exists()) { michael@0: if (gTimeoutRuns > MAX_TIMEOUT_RUNS) { michael@0: do_throw("Exceeded MAX_TIMEOUT_RUNS while waiting for the update log " + michael@0: "to be created. Path: " + log.path); michael@0: } else { michael@0: do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished); michael@0: } michael@0: return; michael@0: } michael@0: michael@0: if (IS_WIN) { michael@0: // Don't proceed until the updater binary is no longer in use. michael@0: let updater = getUpdatesPatchDir(); michael@0: updater.append(FILE_UPDATER_BIN); michael@0: if (updater.exists()) { michael@0: if (gTimeoutRuns > MAX_TIMEOUT_RUNS) { michael@0: do_throw("Exceeded while waiting for updater binary to no longer be " + michael@0: "in use"); michael@0: } else { michael@0: try { michael@0: updater.remove(false); michael@0: } catch (e) { michael@0: do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished); michael@0: return; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: if (IS_MACOSX) { michael@0: logTestInfo("testing last modified time on the apply to directory has " + michael@0: "changed after a successful update (bug 600098)"); michael@0: let now = Date.now(); michael@0: let applyToDir = getApplyDirFile(); michael@0: let timeDiff = Math.abs(applyToDir.lastModifiedTime - now); michael@0: do_check_true(timeDiff < MAC_MAX_TIME_DIFFERENCE); michael@0: } michael@0: michael@0: checkFilesAfterUpdateSuccess(); michael@0: // Sorting on Linux is different so skip this check for now. michael@0: if (!IS_UNIX) { michael@0: checkUpdateLogContents(LOG_COMPLETE_SUCCESS); michael@0: } michael@0: michael@0: checkCallbackAppLog(); michael@0: michael@0: standardInit(); michael@0: michael@0: let update = gUpdateManager.getUpdateAt(0); michael@0: do_check_eq(update.state, STATE_SUCCEEDED); michael@0: michael@0: log = getUpdatesPatchDir(); michael@0: log.append(FILE_UPDATE_LOG); michael@0: logTestInfo("testing " + log.path + " shouldn't exist"); michael@0: do_check_false(log.exists()); michael@0: michael@0: log = getUpdatesDir(); michael@0: log.append(FILE_LAST_LOG); michael@0: logTestInfo("testing " + log.path + " should exist"); michael@0: do_check_true(log.exists()); michael@0: michael@0: log = getUpdatesDir(); michael@0: log.append(FILE_BACKUP_LOG); michael@0: logTestInfo("testing " + log.path + " shouldn't exist"); michael@0: do_check_false(log.exists()); michael@0: michael@0: let updatesPatchDir = getUpdatesPatchDir(); michael@0: logTestInfo("testing " + updatesPatchDir.path + " should exist"); michael@0: do_check_true(updatesPatchDir.exists()); michael@0: michael@0: waitForFilesInUse(); michael@0: }