Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: chrome/installer/util/delete_after_reboot_helper_unittest.cc

Issue 5354006: Fix a problem with the delete-after-reboot code. Removing pending renames of ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/installer/util/delete_after_reboot_helper.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <windows.h> 5 #include <windows.h>
6 #include <shlobj.h> 6 #include <shlobj.h>
7 7
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/scoped_ptr.h" 9 #include "base/scoped_ptr.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 for (int i = 0; i < arraysize(failures); i++) { 131 for (int i = 0; i < arraysize(failures); i++) {
132 std::vector<PendingMove> string_list; 132 std::vector<PendingMove> string_list;
133 EXPECT_FALSE(SUCCEEDED( 133 EXPECT_FALSE(SUCCEEDED(
134 MultiSZBytesToStringArray(reinterpret_cast<char*>(failures[i].str), 134 MultiSZBytesToStringArray(reinterpret_cast<char*>(failures[i].str),
135 failures[i].length, &string_list))) 135 failures[i].length, &string_list)))
136 << failures[i].test_name; 136 << failures[i].test_name;
137 } 137 }
138 } 138 }
139 139
140 140
141 TEST_F(DeleteAfterRebootHelperTest, TestFileDeletes) { 141 TEST_F(DeleteAfterRebootHelperTest, TestFileDeleteScheduleAndUnschedule) {
142 if (!IsUserAnAdmin()) { 142 if (!IsUserAnAdmin()) {
143 return; 143 return;
144 } 144 }
145 145
146 EXPECT_TRUE(ScheduleDirectoryForDeletion(temp_dir_.value().c_str())); 146 EXPECT_TRUE(ScheduleDirectoryForDeletion(temp_dir_.value().c_str()));
147 147
148 std::vector<PendingMove> pending_moves; 148 std::vector<PendingMove> pending_moves;
149 EXPECT_TRUE(SUCCEEDED(GetPendingMovesValue(&pending_moves))); 149 EXPECT_TRUE(SUCCEEDED(GetPendingMovesValue(&pending_moves)));
150 150
151 // We should see, somewhere in this key, deletion writs for 151 // We should see, somewhere in this key, deletion writs for
152 // temp_file_, temp_subdir_file_, temp_subdir_ and temp_dir_ in that order. 152 // temp_file_, temp_subdir_file_, temp_subdir_ and temp_dir_ in that order.
153 EXPECT_TRUE(pending_moves.size() > 3); 153 EXPECT_TRUE(pending_moves.size() > 3);
154 154
155 // Get the short form of temp_file_ and use that to match. 155 // Get the short form of temp_file_ and use that to match.
156 std::wstring short_temp_file(GetShortPathName(temp_file_.value().c_str())); 156 std::wstring short_temp_file(GetShortPathName(temp_file_.value().c_str()));
157 157
158 // Scan for the first expected delete. 158 // Scan for the first expected delete.
159 std::vector<PendingMove>::const_iterator iter(pending_moves.begin()); 159 std::vector<PendingMove>::const_iterator iter(pending_moves.begin());
160 for (; iter != pending_moves.end(); iter++) { 160 for (; iter != pending_moves.end(); iter++) {
161 if (MatchPendingDeletePath(short_temp_file, iter->first)) 161 if (MatchPendingDeletePath(short_temp_file, iter->first))
162 break; 162 break;
163 } 163 }
164 164
165 // Check that each of the deletes we expect are there in order. 165 // Check that each of the deletes we expect are there in order.
166 FilePath expected_paths[] = 166 FilePath expected_paths[] =
167 { temp_file_, temp_subdir_file_, temp_subdir_, temp_dir_ }; 167 { temp_file_, temp_subdir_file_, temp_subdir_, temp_dir_ };
168 for (int i = 0; i < arraysize(expected_paths); i++) { 168 for (int i = 0; i < arraysize(expected_paths); ++i) {
169 EXPECT_FALSE(iter == pending_moves.end()); 169 EXPECT_FALSE(iter == pending_moves.end());
170 if (iter != pending_moves.end()) { 170 if (iter != pending_moves.end()) {
171 std::wstring short_path_name( 171 std::wstring short_path_name(
172 GetShortPathName(expected_paths[i].value().c_str())); 172 GetShortPathName(expected_paths[i].value().c_str()));
173 EXPECT_TRUE(MatchPendingDeletePath(short_path_name, iter->first)); 173 EXPECT_TRUE(MatchPendingDeletePath(short_path_name, iter->first));
174 iter++; 174 ++iter;
175 } 175 }
176 } 176 }
177 177
178 // Test that we can remove the pending deletes. 178 // Test that we can remove the pending deletes.
179 EXPECT_TRUE(RemoveFromMovesPendingReboot(temp_dir_.value().c_str())); 179 EXPECT_TRUE(RemoveFromMovesPendingReboot(temp_dir_.value().c_str()));
180 HRESULT hr = GetPendingMovesValue(&pending_moves); 180 HRESULT hr = GetPendingMovesValue(&pending_moves);
181 EXPECT_TRUE(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)); 181 EXPECT_TRUE(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND));
182 182
183 std::vector<PendingMove>::const_iterator check_iter(pending_moves.begin()); 183 std::vector<PendingMove>::const_iterator check_iter(pending_moves.begin());
184 for (; check_iter != pending_moves.end(); ++check_iter) { 184 for (; check_iter != pending_moves.end(); ++check_iter) {
185 EXPECT_FALSE(MatchPendingDeletePath(short_temp_file, check_iter->first)); 185 EXPECT_FALSE(MatchPendingDeletePath(short_temp_file, check_iter->first));
186 } 186 }
187 } 187 }
188
189 TEST_F(DeleteAfterRebootHelperTest, TestFileDeleteSchedulingWithActualDeletes) {
190 if (!IsUserAnAdmin()) {
191 return;
192 }
193
194 std::vector<PendingMove> initial_pending_moves;
195 GetPendingMovesValue(&initial_pending_moves);
196 size_t initial_pending_moves_size = initial_pending_moves.size();
197
198 EXPECT_TRUE(ScheduleDirectoryForDeletion(temp_dir_.value().c_str()));
199
200 std::vector<PendingMove> pending_moves;
201 EXPECT_TRUE(SUCCEEDED(GetPendingMovesValue(&pending_moves)));
202
203 // We should see, somewhere in this key, deletion writs for
204 // temp_file_, temp_subdir_file_, temp_subdir_ and temp_dir_ in that order.
205 EXPECT_TRUE(pending_moves.size() > 3);
206
207 // Get the short form of temp_file_ and use that to match.
208 std::wstring short_temp_file(GetShortPathName(temp_file_.value().c_str()));
209
210 // Scan for the first expected delete.
211 std::vector<PendingMove>::const_iterator iter(pending_moves.begin());
212 for (; iter != pending_moves.end(); iter++) {
213 if (MatchPendingDeletePath(short_temp_file, iter->first))
214 break;
215 }
216
217 // Check that each of the deletes we expect are there in order.
218 FilePath expected_paths[] =
219 { temp_file_, temp_subdir_file_, temp_subdir_, temp_dir_ };
220 for (int i = 0; i < arraysize(expected_paths); ++i) {
221 EXPECT_FALSE(iter == pending_moves.end());
222 if (iter != pending_moves.end()) {
223 std::wstring short_path_name(
224 GetShortPathName(expected_paths[i].value().c_str()));
225 EXPECT_TRUE(MatchPendingDeletePath(short_path_name, iter->first));
226 ++iter;
227 }
228 }
229
230 // Delete the temporary directory.
231 file_util::Delete(temp_dir_, true);
232
233 // Test that we can remove the pending deletes.
234 EXPECT_TRUE(RemoveFromMovesPendingReboot(temp_dir_.value().c_str()));
235 HRESULT hr = GetPendingMovesValue(&pending_moves);
236 EXPECT_TRUE(hr == S_OK || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND));
237
238 EXPECT_EQ(initial_pending_moves_size, pending_moves.size());
239
240 std::vector<PendingMove>::const_iterator check_iter(pending_moves.begin());
241 for (; check_iter != pending_moves.end(); ++check_iter) {
242 EXPECT_FALSE(MatchPendingDeletePath(short_temp_file, check_iter->first));
243 }
244 }
245
OLDNEW
« no previous file with comments | « chrome/installer/util/delete_after_reboot_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698