1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/update/tests/unit_base_updater/marAppApplyUpdateSuccess.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,141 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +/** 1.9 + * Test applying an update by staging an update and launching an application to 1.10 + * apply it. 1.11 + */ 1.12 + 1.13 +function run_test() { 1.14 + if (MOZ_APP_NAME == "xulrunner") { 1.15 + logTestInfo("Unable to run this test on xulrunner"); 1.16 + return; 1.17 + } 1.18 + 1.19 + setupTestCommon(); 1.20 + gTestFiles = gTestFilesCompleteSuccess; 1.21 + gTestDirs = gTestDirsCompleteSuccess; 1.22 + setupUpdaterTest(FILE_COMPLETE_MAR, false, false); 1.23 + 1.24 + // For Mac OS X set the last modified time for the root directory to a date in 1.25 + // the past to test that the last modified time is updated on a successful 1.26 + // update (bug 600098). 1.27 + if (IS_MACOSX) { 1.28 + let now = Date.now(); 1.29 + let yesterday = now - (1000 * 60 * 60 * 24); 1.30 + let applyToDir = getApplyDirFile(); 1.31 + applyToDir.lastModifiedTime = yesterday; 1.32 + } 1.33 + 1.34 + let channel = Services.prefs.getCharPref(PREF_APP_UPDATE_CHANNEL); 1.35 + let patches = getLocalPatchString(null, null, null, null, null, "true", 1.36 + STATE_PENDING); 1.37 + let updates = getLocalUpdateString(patches, null, null, null, null, null, 1.38 + null, null, null, null, null, null, 1.39 + null, "true", channel); 1.40 + writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true); 1.41 + writeVersionFile(getAppVersion()); 1.42 + writeStatusFile(STATE_PENDING); 1.43 + 1.44 + setupAppFilesAsync(); 1.45 +} 1.46 + 1.47 +function setupAppFilesFinished() { 1.48 + do_timeout(TEST_CHECK_TIMEOUT, launchAppToApplyUpdate); 1.49 +} 1.50 + 1.51 +/** 1.52 + * Checks if the update has finished and if it has finished performs checks for 1.53 + * the test. 1.54 + */ 1.55 +function checkUpdateFinished() { 1.56 + gTimeoutRuns++; 1.57 + // Don't proceed until the update's status state is the expected value. 1.58 + let state = readStatusState(); 1.59 + if (state != STATE_SUCCEEDED) { 1.60 + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) { 1.61 + do_throw("Exceeded MAX_TIMEOUT_RUNS while waiting for the update " + 1.62 + "status state to equal: " + STATE_SUCCEEDED + 1.63 + ", current status state: " + state); 1.64 + } else { 1.65 + do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished); 1.66 + } 1.67 + return; 1.68 + } 1.69 + 1.70 + // Don't proceed until the update log has been created. 1.71 + let log = getUpdatesPatchDir(); 1.72 + log.append(FILE_UPDATE_LOG); 1.73 + if (!log.exists()) { 1.74 + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) { 1.75 + do_throw("Exceeded MAX_TIMEOUT_RUNS while waiting for the update log " + 1.76 + "to be created. Path: " + log.path); 1.77 + } else { 1.78 + do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished); 1.79 + } 1.80 + return; 1.81 + } 1.82 + 1.83 + if (IS_WIN) { 1.84 + // Don't proceed until the updater binary is no longer in use. 1.85 + let updater = getUpdatesPatchDir(); 1.86 + updater.append(FILE_UPDATER_BIN); 1.87 + if (updater.exists()) { 1.88 + if (gTimeoutRuns > MAX_TIMEOUT_RUNS) { 1.89 + do_throw("Exceeded while waiting for updater binary to no longer be " + 1.90 + "in use"); 1.91 + } else { 1.92 + try { 1.93 + updater.remove(false); 1.94 + } catch (e) { 1.95 + do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished); 1.96 + return; 1.97 + } 1.98 + } 1.99 + } 1.100 + } 1.101 + 1.102 + if (IS_MACOSX) { 1.103 + logTestInfo("testing last modified time on the apply to directory has " + 1.104 + "changed after a successful update (bug 600098)"); 1.105 + let now = Date.now(); 1.106 + let applyToDir = getApplyDirFile(); 1.107 + let timeDiff = Math.abs(applyToDir.lastModifiedTime - now); 1.108 + do_check_true(timeDiff < MAC_MAX_TIME_DIFFERENCE); 1.109 + } 1.110 + 1.111 + checkFilesAfterUpdateSuccess(); 1.112 + // Sorting on Linux is different so skip this check for now. 1.113 + if (!IS_UNIX) { 1.114 + checkUpdateLogContents(LOG_COMPLETE_SUCCESS); 1.115 + } 1.116 + 1.117 + checkCallbackAppLog(); 1.118 + 1.119 + standardInit(); 1.120 + 1.121 + let update = gUpdateManager.getUpdateAt(0); 1.122 + do_check_eq(update.state, STATE_SUCCEEDED); 1.123 + 1.124 + log = getUpdatesPatchDir(); 1.125 + log.append(FILE_UPDATE_LOG); 1.126 + logTestInfo("testing " + log.path + " shouldn't exist"); 1.127 + do_check_false(log.exists()); 1.128 + 1.129 + log = getUpdatesDir(); 1.130 + log.append(FILE_LAST_LOG); 1.131 + logTestInfo("testing " + log.path + " should exist"); 1.132 + do_check_true(log.exists()); 1.133 + 1.134 + log = getUpdatesDir(); 1.135 + log.append(FILE_BACKUP_LOG); 1.136 + logTestInfo("testing " + log.path + " shouldn't exist"); 1.137 + do_check_false(log.exists()); 1.138 + 1.139 + let updatesPatchDir = getUpdatesPatchDir(); 1.140 + logTestInfo("testing " + updatesPatchDir.path + " should exist"); 1.141 + do_check_true(updatesPatchDir.exists()); 1.142 + 1.143 + waitForFilesInUse(); 1.144 +}