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