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

mercurial