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