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