toolkit/mozapps/update/tests/unit_service_updater/marAppApplyUpdateSuccessSvc.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 /**
michael@0 6 * Test applying an update by staging an update and launching an application to
michael@0 7 * apply it.
michael@0 8 */
michael@0 9
michael@0 10 function run_test() {
michael@0 11 if (MOZ_APP_NAME == "xulrunner") {
michael@0 12 logTestInfo("Unable to run this test on xulrunner");
michael@0 13 return;
michael@0 14 }
michael@0 15
michael@0 16 if (!shouldRunServiceTest()) {
michael@0 17 return;
michael@0 18 }
michael@0 19
michael@0 20 setupTestCommon();
michael@0 21 gTestFiles = gTestFilesCompleteSuccess;
michael@0 22 gTestDirs = gTestDirsCompleteSuccess;
michael@0 23 setupUpdaterTest(FILE_COMPLETE_MAR, false, false);
michael@0 24
michael@0 25 // For Mac OS X set the last modified time for the root directory to a date in
michael@0 26 // the past to test that the last modified time is updated on a successful
michael@0 27 // update (bug 600098).
michael@0 28 if (IS_MACOSX) {
michael@0 29 let now = Date.now();
michael@0 30 let yesterday = now - (1000 * 60 * 60 * 24);
michael@0 31 let applyToDir = getApplyDirFile();
michael@0 32 applyToDir.lastModifiedTime = yesterday;
michael@0 33 }
michael@0 34
michael@0 35 let channel = Services.prefs.getCharPref(PREF_APP_UPDATE_CHANNEL);
michael@0 36 let patches = getLocalPatchString(null, null, null, null, null, "true",
michael@0 37 STATE_PENDING);
michael@0 38 let updates = getLocalUpdateString(patches, null, null, null, null, null,
michael@0 39 null, null, null, null, null, null,
michael@0 40 null, "true", channel);
michael@0 41 writeUpdatesToXMLFile(getLocalUpdatesXMLString(updates), true);
michael@0 42 writeVersionFile(getAppVersion());
michael@0 43 writeStatusFile(STATE_PENDING_SVC);
michael@0 44
michael@0 45 setupAppFilesAsync();
michael@0 46 }
michael@0 47
michael@0 48 function setupAppFilesFinished() {
michael@0 49 runUpdateUsingService(STATE_PENDING_SVC, STATE_SUCCEEDED);
michael@0 50 }
michael@0 51
michael@0 52 /**
michael@0 53 * Checks if the update has finished and if it has finished performs checks for
michael@0 54 * the test.
michael@0 55 */
michael@0 56 function checkUpdateFinished() {
michael@0 57 gTimeoutRuns++;
michael@0 58 // Don't proceed until the update's status state is the expected value.
michael@0 59 let state = readStatusState();
michael@0 60 if (state != STATE_SUCCEEDED) {
michael@0 61 if (gTimeoutRuns > MAX_TIMEOUT_RUNS) {
michael@0 62 do_throw("Exceeded MAX_TIMEOUT_RUNS while waiting for the update " +
michael@0 63 "status state to equal: " + STATE_SUCCEEDED +
michael@0 64 ", current status state: " + state);
michael@0 65 } else {
michael@0 66 do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
michael@0 67 }
michael@0 68 return;
michael@0 69 }
michael@0 70
michael@0 71 // Don't proceed until the update log has been created.
michael@0 72 let log = getUpdatesPatchDir();
michael@0 73 log.append(FILE_UPDATE_LOG);
michael@0 74 if (!log.exists()) {
michael@0 75 if (gTimeoutRuns > MAX_TIMEOUT_RUNS) {
michael@0 76 do_throw("Exceeded MAX_TIMEOUT_RUNS while waiting for the update log " +
michael@0 77 "to be created. Path: " + log.path);
michael@0 78 } else {
michael@0 79 do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
michael@0 80 }
michael@0 81 return;
michael@0 82 }
michael@0 83
michael@0 84 if (IS_WIN) {
michael@0 85 // Don't proceed until the updater binary is no longer in use.
michael@0 86 let updater = getUpdatesPatchDir();
michael@0 87 updater.append(FILE_UPDATER_BIN);
michael@0 88 if (updater.exists()) {
michael@0 89 if (gTimeoutRuns > MAX_TIMEOUT_RUNS) {
michael@0 90 do_throw("Exceeded while waiting for updater binary to no longer be " +
michael@0 91 "in use");
michael@0 92 } else {
michael@0 93 try {
michael@0 94 updater.remove(false);
michael@0 95 } catch (e) {
michael@0 96 do_timeout(TEST_CHECK_TIMEOUT, checkUpdateFinished);
michael@0 97 return;
michael@0 98 }
michael@0 99 }
michael@0 100 }
michael@0 101 }
michael@0 102
michael@0 103 if (IS_MACOSX) {
michael@0 104 logTestInfo("testing last modified time on the apply to directory has " +
michael@0 105 "changed after a successful update (bug 600098)");
michael@0 106 let now = Date.now();
michael@0 107 let applyToDir = getApplyDirFile();
michael@0 108 let timeDiff = Math.abs(applyToDir.lastModifiedTime - now);
michael@0 109 do_check_true(timeDiff < MAC_MAX_TIME_DIFFERENCE);
michael@0 110 }
michael@0 111
michael@0 112 checkFilesAfterUpdateSuccess();
michael@0 113 // Sorting on Linux is different so skip this check for now.
michael@0 114 if (!IS_UNIX) {
michael@0 115 checkUpdateLogContents(LOG_COMPLETE_SUCCESS);
michael@0 116 }
michael@0 117
michael@0 118 checkCallbackAppLog();
michael@0 119
michael@0 120 standardInit();
michael@0 121
michael@0 122 let update = gUpdateManager.getUpdateAt(0);
michael@0 123 do_check_eq(update.state, STATE_SUCCEEDED);
michael@0 124
michael@0 125 log = getUpdatesPatchDir();
michael@0 126 log.append(FILE_UPDATE_LOG);
michael@0 127 logTestInfo("testing " + log.path + " shouldn't exist");
michael@0 128 do_check_false(log.exists());
michael@0 129
michael@0 130 log = getUpdatesDir();
michael@0 131 log.append(FILE_LAST_LOG);
michael@0 132 logTestInfo("testing " + log.path + " should exist");
michael@0 133 do_check_true(log.exists());
michael@0 134
michael@0 135 log = getUpdatesDir();
michael@0 136 log.append(FILE_BACKUP_LOG);
michael@0 137 logTestInfo("testing " + log.path + " shouldn't exist");
michael@0 138 do_check_false(log.exists());
michael@0 139
michael@0 140 let updatesPatchDir = getUpdatesPatchDir();
michael@0 141 logTestInfo("testing " + updatesPatchDir.path + " should exist");
michael@0 142 do_check_true(updatesPatchDir.exists());
michael@0 143
michael@0 144 waitForFilesInUse();
michael@0 145 }

mercurial