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

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

Issue 2321573002: //chrome misc: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: Fix Win compilation Created 4 years, 3 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/installer/util/copy_tree_work_item.h" 5 #include "chrome/installer/util/copy_tree_work_item.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <fstream> 9 #include <fstream>
10 #include <memory> 10 #include <memory>
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 69 }
70 70
71 const wchar_t text_content_1[] = L"Gooooooooooooooooooooogle"; 71 const wchar_t text_content_1[] = L"Gooooooooooooooooooooogle";
72 const wchar_t text_content_2[] = L"Overwrite Me"; 72 const wchar_t text_content_2[] = L"Overwrite Me";
73 73
74 } // namespace 74 } // namespace
75 75
76 // Copy one file from source to destination. 76 // Copy one file from source to destination.
77 TEST_F(CopyTreeWorkItemTest, CopyFile) { 77 TEST_F(CopyTreeWorkItemTest, CopyFile) {
78 // Create source file 78 // Create source file
79 base::FilePath file_name_from(test_dir_.path()); 79 base::FilePath file_name_from(test_dir_.GetPath());
80 file_name_from = file_name_from.AppendASCII("File_From.txt"); 80 file_name_from = file_name_from.AppendASCII("File_From.txt");
81 CreateTextFile(file_name_from.value(), text_content_1); 81 CreateTextFile(file_name_from.value(), text_content_1);
82 ASSERT_TRUE(base::PathExists(file_name_from)); 82 ASSERT_TRUE(base::PathExists(file_name_from));
83 83
84 // Create destination path 84 // Create destination path
85 base::FilePath dir_name_to(test_dir_.path()); 85 base::FilePath dir_name_to(test_dir_.GetPath());
86 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 86 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
87 base::CreateDirectory(dir_name_to); 87 base::CreateDirectory(dir_name_to);
88 ASSERT_TRUE(base::PathExists(dir_name_to)); 88 ASSERT_TRUE(base::PathExists(dir_name_to));
89 89
90 base::FilePath file_name_to(dir_name_to); 90 base::FilePath file_name_to(dir_name_to);
91 file_name_to = file_name_to.AppendASCII("File_To.txt"); 91 file_name_to = file_name_to.AppendASCII("File_To.txt");
92 92
93 // test Do() 93 // test Do()
94 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem( 94 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem(
95 file_name_from, file_name_to, temp_dir_.path(), WorkItem::ALWAYS, 95 file_name_from, file_name_to, temp_dir_.GetPath(), WorkItem::ALWAYS,
96 base::FilePath())); 96 base::FilePath()));
97 97
98 EXPECT_TRUE(work_item->Do()); 98 EXPECT_TRUE(work_item->Do());
99 99
100 EXPECT_TRUE(base::PathExists(file_name_from)); 100 EXPECT_TRUE(base::PathExists(file_name_from));
101 EXPECT_TRUE(base::PathExists(file_name_to)); 101 EXPECT_TRUE(base::PathExists(file_name_to));
102 EXPECT_TRUE(base::ContentsEqual(file_name_from, file_name_to)); 102 EXPECT_TRUE(base::ContentsEqual(file_name_from, file_name_to));
103 103
104 // test rollback() 104 // test rollback()
105 work_item->Rollback(); 105 work_item->Rollback();
106 106
107 EXPECT_FALSE(base::PathExists(file_name_to)); 107 EXPECT_FALSE(base::PathExists(file_name_to));
108 EXPECT_TRUE(base::PathExists(file_name_from)); 108 EXPECT_TRUE(base::PathExists(file_name_from));
109 } 109 }
110 110
111 // Copy one file, overwriting the existing one in destination. 111 // Copy one file, overwriting the existing one in destination.
112 // Test with always_overwrite being true or false. The file is overwritten 112 // Test with always_overwrite being true or false. The file is overwritten
113 // regardless since the content at destination file is different from source. 113 // regardless since the content at destination file is different from source.
114 TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) { 114 TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) {
115 // Create source file 115 // Create source file
116 base::FilePath file_name_from(test_dir_.path()); 116 base::FilePath file_name_from(test_dir_.GetPath());
117 file_name_from = file_name_from.AppendASCII("File_From.txt"); 117 file_name_from = file_name_from.AppendASCII("File_From.txt");
118 CreateTextFile(file_name_from.value(), text_content_1); 118 CreateTextFile(file_name_from.value(), text_content_1);
119 ASSERT_TRUE(base::PathExists(file_name_from)); 119 ASSERT_TRUE(base::PathExists(file_name_from));
120 120
121 // Create destination file 121 // Create destination file
122 base::FilePath dir_name_to(test_dir_.path()); 122 base::FilePath dir_name_to(test_dir_.GetPath());
123 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 123 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
124 base::CreateDirectory(dir_name_to); 124 base::CreateDirectory(dir_name_to);
125 ASSERT_TRUE(base::PathExists(dir_name_to)); 125 ASSERT_TRUE(base::PathExists(dir_name_to));
126 126
127 base::FilePath file_name_to(dir_name_to); 127 base::FilePath file_name_to(dir_name_to);
128 file_name_to = file_name_to.AppendASCII("File_To.txt"); 128 file_name_to = file_name_to.AppendASCII("File_To.txt");
129 CreateTextFile(file_name_to.value(), text_content_2); 129 CreateTextFile(file_name_to.value(), text_content_2);
130 ASSERT_TRUE(base::PathExists(file_name_to)); 130 ASSERT_TRUE(base::PathExists(file_name_to));
131 131
132 // test Do() with always_overwrite being true. 132 // test Do() with always_overwrite being true.
133 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem( 133 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem(
134 file_name_from, file_name_to, temp_dir_.path(), WorkItem::ALWAYS, 134 file_name_from, file_name_to, temp_dir_.GetPath(), WorkItem::ALWAYS,
135 base::FilePath())); 135 base::FilePath()));
136 136
137 EXPECT_TRUE(work_item->Do()); 137 EXPECT_TRUE(work_item->Do());
138 138
139 EXPECT_TRUE(base::PathExists(file_name_from)); 139 EXPECT_TRUE(base::PathExists(file_name_from));
140 EXPECT_TRUE(base::PathExists(file_name_to)); 140 EXPECT_TRUE(base::PathExists(file_name_to));
141 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 141 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
142 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 142 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
143 143
144 // test rollback() 144 // test rollback()
145 work_item->Rollback(); 145 work_item->Rollback();
146 146
147 EXPECT_TRUE(base::PathExists(file_name_from)); 147 EXPECT_TRUE(base::PathExists(file_name_from));
148 EXPECT_TRUE(base::PathExists(file_name_to)); 148 EXPECT_TRUE(base::PathExists(file_name_to));
149 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 149 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
150 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_2)); 150 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_2));
151 151
152 // test Do() with always_overwrite being false. 152 // test Do() with always_overwrite being false.
153 // the file is still overwritten since the content is different. 153 // the file is still overwritten since the content is different.
154 work_item.reset( 154 work_item.reset(WorkItem::CreateCopyTreeWorkItem(
155 WorkItem::CreateCopyTreeWorkItem(file_name_from, 155 file_name_from, file_name_to, temp_dir_.GetPath(), WorkItem::IF_DIFFERENT,
156 file_name_to, 156 base::FilePath()));
157 temp_dir_.path(),
158 WorkItem::IF_DIFFERENT,
159 base::FilePath()));
160 157
161 EXPECT_TRUE(work_item->Do()); 158 EXPECT_TRUE(work_item->Do());
162 159
163 EXPECT_TRUE(base::PathExists(file_name_from)); 160 EXPECT_TRUE(base::PathExists(file_name_from));
164 EXPECT_TRUE(base::PathExists(file_name_to)); 161 EXPECT_TRUE(base::PathExists(file_name_to));
165 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 162 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
166 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 163 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
167 164
168 // test rollback() 165 // test rollback()
169 work_item->Rollback(); 166 work_item->Rollback();
170 167
171 EXPECT_TRUE(base::PathExists(file_name_from)); 168 EXPECT_TRUE(base::PathExists(file_name_from));
172 EXPECT_TRUE(base::PathExists(file_name_to)); 169 EXPECT_TRUE(base::PathExists(file_name_to));
173 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 170 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
174 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_2)); 171 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_2));
175 } 172 }
176 173
177 // Copy one file, with the existing one in destination having the same 174 // Copy one file, with the existing one in destination having the same
178 // content. 175 // content.
179 // If always_overwrite being true, the file is overwritten. 176 // If always_overwrite being true, the file is overwritten.
180 // If always_overwrite being false, the file is unchanged. 177 // If always_overwrite being false, the file is unchanged.
181 TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) { 178 TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) {
182 // Create source file 179 // Create source file
183 base::FilePath file_name_from(test_dir_.path()); 180 base::FilePath file_name_from(test_dir_.GetPath());
184 file_name_from = file_name_from.AppendASCII("File_From.txt"); 181 file_name_from = file_name_from.AppendASCII("File_From.txt");
185 CreateTextFile(file_name_from.value(), text_content_1); 182 CreateTextFile(file_name_from.value(), text_content_1);
186 ASSERT_TRUE(base::PathExists(file_name_from)); 183 ASSERT_TRUE(base::PathExists(file_name_from));
187 184
188 // Create destination file 185 // Create destination file
189 base::FilePath dir_name_to(test_dir_.path()); 186 base::FilePath dir_name_to(test_dir_.GetPath());
190 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 187 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
191 base::CreateDirectory(dir_name_to); 188 base::CreateDirectory(dir_name_to);
192 ASSERT_TRUE(base::PathExists(dir_name_to)); 189 ASSERT_TRUE(base::PathExists(dir_name_to));
193 190
194 base::FilePath file_name_to(dir_name_to); 191 base::FilePath file_name_to(dir_name_to);
195 file_name_to = file_name_to.AppendASCII("File_To.txt"); 192 file_name_to = file_name_to.AppendASCII("File_To.txt");
196 CreateTextFile(file_name_to.value(), text_content_1); 193 CreateTextFile(file_name_to.value(), text_content_1);
197 ASSERT_TRUE(base::PathExists(file_name_to)); 194 ASSERT_TRUE(base::PathExists(file_name_to));
198 195
199 // test Do() with always_overwrite being true. 196 // test Do() with always_overwrite being true.
200 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem( 197 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem(
201 file_name_from, file_name_to, temp_dir_.path(), WorkItem::ALWAYS, 198 file_name_from, file_name_to, temp_dir_.GetPath(), WorkItem::ALWAYS,
202 base::FilePath())); 199 base::FilePath()));
203 200
204 EXPECT_TRUE(work_item->Do()); 201 EXPECT_TRUE(work_item->Do());
205 202
206 // Get the path of backup file 203 // Get the path of backup file
207 base::FilePath backup_file(work_item->backup_path_.path()); 204 base::FilePath backup_file(work_item->backup_path_.path());
208 EXPECT_FALSE(backup_file.empty()); 205 EXPECT_FALSE(backup_file.empty());
209 backup_file = backup_file.AppendASCII("File_To.txt"); 206 backup_file = backup_file.AppendASCII("File_To.txt");
210 207
211 EXPECT_TRUE(base::PathExists(file_name_from)); 208 EXPECT_TRUE(base::PathExists(file_name_from));
212 EXPECT_TRUE(base::PathExists(file_name_to)); 209 EXPECT_TRUE(base::PathExists(file_name_to));
213 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 210 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
214 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 211 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
215 // we verify the file is overwritten by checking the existence of backup 212 // we verify the file is overwritten by checking the existence of backup
216 // file. 213 // file.
217 EXPECT_TRUE(base::PathExists(backup_file)); 214 EXPECT_TRUE(base::PathExists(backup_file));
218 EXPECT_EQ(0, ReadTextFile(backup_file.value()).compare(text_content_1)); 215 EXPECT_EQ(0, ReadTextFile(backup_file.value()).compare(text_content_1));
219 216
220 // test rollback() 217 // test rollback()
221 work_item->Rollback(); 218 work_item->Rollback();
222 219
223 EXPECT_TRUE(base::PathExists(file_name_from)); 220 EXPECT_TRUE(base::PathExists(file_name_from));
224 EXPECT_TRUE(base::PathExists(file_name_to)); 221 EXPECT_TRUE(base::PathExists(file_name_to));
225 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 222 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
226 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 223 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
227 // the backup file should be gone after rollback 224 // the backup file should be gone after rollback
228 EXPECT_FALSE(base::PathExists(backup_file)); 225 EXPECT_FALSE(base::PathExists(backup_file));
229 226
230 // test Do() with always_overwrite being false. nothing should change. 227 // test Do() with always_overwrite being false. nothing should change.
231 work_item.reset( 228 work_item.reset(WorkItem::CreateCopyTreeWorkItem(
232 WorkItem::CreateCopyTreeWorkItem(file_name_from, 229 file_name_from, file_name_to, temp_dir_.GetPath(), WorkItem::IF_DIFFERENT,
233 file_name_to, 230 base::FilePath()));
234 temp_dir_.path(),
235 WorkItem::IF_DIFFERENT,
236 base::FilePath()));
237 231
238 EXPECT_TRUE(work_item->Do()); 232 EXPECT_TRUE(work_item->Do());
239 233
240 EXPECT_TRUE(base::PathExists(file_name_from)); 234 EXPECT_TRUE(base::PathExists(file_name_from));
241 EXPECT_TRUE(base::PathExists(file_name_to)); 235 EXPECT_TRUE(base::PathExists(file_name_to));
242 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 236 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
243 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 237 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
244 // we verify the file is not overwritten by checking that the backup 238 // we verify the file is not overwritten by checking that the backup
245 // file does not exist. 239 // file does not exist.
246 EXPECT_FALSE(base::PathExists(backup_file)); 240 EXPECT_FALSE(base::PathExists(backup_file));
247 241
248 // test rollback(). nothing should happen here. 242 // test rollback(). nothing should happen here.
249 work_item->Rollback(); 243 work_item->Rollback();
250 244
251 EXPECT_TRUE(base::PathExists(file_name_from)); 245 EXPECT_TRUE(base::PathExists(file_name_from));
252 EXPECT_TRUE(base::PathExists(file_name_to)); 246 EXPECT_TRUE(base::PathExists(file_name_to));
253 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 247 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
254 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 248 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
255 EXPECT_FALSE(base::PathExists(backup_file)); 249 EXPECT_FALSE(base::PathExists(backup_file));
256 } 250 }
257 251
258 // Copy one file and without rollback. Verify all temporary files are deleted. 252 // Copy one file and without rollback. Verify all temporary files are deleted.
259 TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) { 253 TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) {
260 // Create source file 254 // Create source file
261 base::FilePath file_name_from(test_dir_.path()); 255 base::FilePath file_name_from(test_dir_.GetPath());
262 file_name_from = file_name_from.AppendASCII("File_From.txt"); 256 file_name_from = file_name_from.AppendASCII("File_From.txt");
263 CreateTextFile(file_name_from.value(), text_content_1); 257 CreateTextFile(file_name_from.value(), text_content_1);
264 ASSERT_TRUE(base::PathExists(file_name_from)); 258 ASSERT_TRUE(base::PathExists(file_name_from));
265 259
266 // Create destination file 260 // Create destination file
267 base::FilePath dir_name_to(test_dir_.path()); 261 base::FilePath dir_name_to(test_dir_.GetPath());
268 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 262 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
269 base::CreateDirectory(dir_name_to); 263 base::CreateDirectory(dir_name_to);
270 ASSERT_TRUE(base::PathExists(dir_name_to)); 264 ASSERT_TRUE(base::PathExists(dir_name_to));
271 265
272 base::FilePath file_name_to(dir_name_to); 266 base::FilePath file_name_to(dir_name_to);
273 file_name_to = file_name_to.AppendASCII("File_To.txt"); 267 file_name_to = file_name_to.AppendASCII("File_To.txt");
274 CreateTextFile(file_name_to.value(), text_content_2); 268 CreateTextFile(file_name_to.value(), text_content_2);
275 ASSERT_TRUE(base::PathExists(file_name_to)); 269 ASSERT_TRUE(base::PathExists(file_name_to));
276 270
277 base::FilePath backup_file; 271 base::FilePath backup_file;
278 272
279 { 273 {
280 // test Do(). 274 // test Do().
281 std::unique_ptr<CopyTreeWorkItem> work_item( 275 std::unique_ptr<CopyTreeWorkItem> work_item(
282 WorkItem::CreateCopyTreeWorkItem( 276 WorkItem::CreateCopyTreeWorkItem(
283 file_name_from, file_name_to, temp_dir_.path(), 277 file_name_from, file_name_to, temp_dir_.GetPath(),
284 WorkItem::IF_DIFFERENT, base::FilePath())); 278 WorkItem::IF_DIFFERENT, base::FilePath()));
285 279
286 EXPECT_TRUE(work_item->Do()); 280 EXPECT_TRUE(work_item->Do());
287 281
288 // Get the path of backup file 282 // Get the path of backup file
289 backup_file = work_item->backup_path_.path(); 283 backup_file = work_item->backup_path_.path();
290 EXPECT_FALSE(backup_file.empty()); 284 EXPECT_FALSE(backup_file.empty());
291 backup_file = backup_file.AppendASCII("File_To.txt"); 285 backup_file = backup_file.AppendASCII("File_To.txt");
292 286
293 EXPECT_TRUE(base::PathExists(file_name_from)); 287 EXPECT_TRUE(base::PathExists(file_name_from));
294 EXPECT_TRUE(base::PathExists(file_name_to)); 288 EXPECT_TRUE(base::PathExists(file_name_to));
295 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 289 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
296 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 290 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
297 // verify the file is moved to backup place. 291 // verify the file is moved to backup place.
298 EXPECT_TRUE(base::PathExists(backup_file)); 292 EXPECT_TRUE(base::PathExists(backup_file));
299 EXPECT_EQ(0, ReadTextFile(backup_file.value()).compare(text_content_2)); 293 EXPECT_EQ(0, ReadTextFile(backup_file.value()).compare(text_content_2));
300 } 294 }
301 295
302 // verify the backup file is cleaned up as well. 296 // verify the backup file is cleaned up as well.
303 EXPECT_FALSE(base::PathExists(backup_file)); 297 EXPECT_FALSE(base::PathExists(backup_file));
304 } 298 }
305 299
306 // Copy one file, with the existing one in destination being used with 300 // Copy one file, with the existing one in destination being used with
307 // overwrite option as IF_DIFFERENT. This destination-file-in-use should 301 // overwrite option as IF_DIFFERENT. This destination-file-in-use should
308 // be moved to backup location after Do() and moved back after Rollback(). 302 // be moved to backup location after Do() and moved back after Rollback().
309 TEST_F(CopyTreeWorkItemTest, CopyFileInUse) { 303 TEST_F(CopyTreeWorkItemTest, CopyFileInUse) {
310 // Create source file 304 // Create source file
311 base::FilePath file_name_from(test_dir_.path()); 305 base::FilePath file_name_from(test_dir_.GetPath());
312 file_name_from = file_name_from.AppendASCII("File_From"); 306 file_name_from = file_name_from.AppendASCII("File_From");
313 CreateTextFile(file_name_from.value(), text_content_1); 307 CreateTextFile(file_name_from.value(), text_content_1);
314 ASSERT_TRUE(base::PathExists(file_name_from)); 308 ASSERT_TRUE(base::PathExists(file_name_from));
315 309
316 // Create an executable in destination path by copying ourself to it. 310 // Create an executable in destination path by copying ourself to it.
317 wchar_t exe_full_path_str[MAX_PATH]; 311 wchar_t exe_full_path_str[MAX_PATH];
318 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 312 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
319 base::FilePath exe_full_path(exe_full_path_str); 313 base::FilePath exe_full_path(exe_full_path_str);
320 314
321 base::FilePath dir_name_to(test_dir_.path()); 315 base::FilePath dir_name_to(test_dir_.GetPath());
322 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 316 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
323 base::CreateDirectory(dir_name_to); 317 base::CreateDirectory(dir_name_to);
324 ASSERT_TRUE(base::PathExists(dir_name_to)); 318 ASSERT_TRUE(base::PathExists(dir_name_to));
325 319
326 base::FilePath file_name_to(dir_name_to); 320 base::FilePath file_name_to(dir_name_to);
327 file_name_to = file_name_to.AppendASCII("File_To"); 321 file_name_to = file_name_to.AppendASCII("File_To");
328 base::CopyFile(exe_full_path, file_name_to); 322 base::CopyFile(exe_full_path, file_name_to);
329 ASSERT_TRUE(base::PathExists(file_name_to)); 323 ASSERT_TRUE(base::PathExists(file_name_to));
330 324
331 VLOG(1) << "copy ourself from " << exe_full_path.value() 325 VLOG(1) << "copy ourself from " << exe_full_path.value()
332 << " to " << file_name_to.value(); 326 << " to " << file_name_to.value();
333 327
334 // Run the executable in destination path 328 // Run the executable in destination path
335 STARTUPINFOW si = {sizeof(si)}; 329 STARTUPINFOW si = {sizeof(si)};
336 PROCESS_INFORMATION pi = {0}; 330 PROCESS_INFORMATION pi = {0};
337 ASSERT_TRUE( 331 ASSERT_TRUE(
338 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()), 332 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()),
339 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED, 333 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
340 NULL, NULL, &si, &pi)); 334 NULL, NULL, &si, &pi));
341 335
342 // test Do(). 336 // test Do().
343 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem( 337 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem(
344 file_name_from, file_name_to, temp_dir_.path(), WorkItem::IF_DIFFERENT, 338 file_name_from, file_name_to, temp_dir_.GetPath(), WorkItem::IF_DIFFERENT,
345 base::FilePath())); 339 base::FilePath()));
346 340
347 EXPECT_TRUE(work_item->Do()); 341 EXPECT_TRUE(work_item->Do());
348 342
349 // Get the path of backup file 343 // Get the path of backup file
350 base::FilePath backup_file(work_item->backup_path_.path()); 344 base::FilePath backup_file(work_item->backup_path_.path());
351 EXPECT_FALSE(backup_file.empty()); 345 EXPECT_FALSE(backup_file.empty());
352 backup_file = backup_file.AppendASCII("File_To"); 346 backup_file = backup_file.AppendASCII("File_To");
353 347
354 EXPECT_TRUE(base::PathExists(file_name_from)); 348 EXPECT_TRUE(base::PathExists(file_name_from));
(...skipping 22 matching lines...) Expand all
377 } 371 }
378 372
379 // Test overwrite option NEW_NAME_IF_IN_USE: 373 // Test overwrite option NEW_NAME_IF_IN_USE:
380 // 1. If destination file is in use, the source should be copied with the 374 // 1. If destination file is in use, the source should be copied with the
381 // new name after Do() and this new name file should be deleted 375 // new name after Do() and this new name file should be deleted
382 // after rollback. 376 // after rollback.
383 // 2. If destination file is not in use, the source should be copied in the 377 // 2. If destination file is not in use, the source should be copied in the
384 // destination folder after Do() and should be rolled back after Rollback(). 378 // destination folder after Do() and should be rolled back after Rollback().
385 TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) { 379 TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
386 // Create source file 380 // Create source file
387 base::FilePath file_name_from(test_dir_.path()); 381 base::FilePath file_name_from(test_dir_.GetPath());
388 file_name_from = file_name_from.AppendASCII("File_From"); 382 file_name_from = file_name_from.AppendASCII("File_From");
389 CreateTextFile(file_name_from.value(), text_content_1); 383 CreateTextFile(file_name_from.value(), text_content_1);
390 ASSERT_TRUE(base::PathExists(file_name_from)); 384 ASSERT_TRUE(base::PathExists(file_name_from));
391 385
392 // Create an executable in destination path by copying ourself to it. 386 // Create an executable in destination path by copying ourself to it.
393 wchar_t exe_full_path_str[MAX_PATH]; 387 wchar_t exe_full_path_str[MAX_PATH];
394 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 388 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
395 base::FilePath exe_full_path(exe_full_path_str); 389 base::FilePath exe_full_path(exe_full_path_str);
396 390
397 base::FilePath dir_name_to(test_dir_.path()); 391 base::FilePath dir_name_to(test_dir_.GetPath());
398 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 392 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
399 base::CreateDirectory(dir_name_to); 393 base::CreateDirectory(dir_name_to);
400 ASSERT_TRUE(base::PathExists(dir_name_to)); 394 ASSERT_TRUE(base::PathExists(dir_name_to));
401 395
402 base::FilePath file_name_to(dir_name_to), alternate_to(dir_name_to); 396 base::FilePath file_name_to(dir_name_to), alternate_to(dir_name_to);
403 file_name_to = file_name_to.AppendASCII("File_To"); 397 file_name_to = file_name_to.AppendASCII("File_To");
404 alternate_to = alternate_to.AppendASCII("Alternate_To"); 398 alternate_to = alternate_to.AppendASCII("Alternate_To");
405 base::CopyFile(exe_full_path, file_name_to); 399 base::CopyFile(exe_full_path, file_name_to);
406 ASSERT_TRUE(base::PathExists(file_name_to)); 400 ASSERT_TRUE(base::PathExists(file_name_to));
407 401
408 VLOG(1) << "copy ourself from " << exe_full_path.value() 402 VLOG(1) << "copy ourself from " << exe_full_path.value()
409 << " to " << file_name_to.value(); 403 << " to " << file_name_to.value();
410 404
411 // Run the executable in destination path 405 // Run the executable in destination path
412 STARTUPINFOW si = {sizeof(si)}; 406 STARTUPINFOW si = {sizeof(si)};
413 PROCESS_INFORMATION pi = {0}; 407 PROCESS_INFORMATION pi = {0};
414 ASSERT_TRUE( 408 ASSERT_TRUE(
415 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()), 409 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()),
416 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED, 410 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
417 NULL, NULL, &si, &pi)); 411 NULL, NULL, &si, &pi));
418 412
419 // test Do(). 413 // test Do().
420 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem( 414 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem(
421 file_name_from, file_name_to, temp_dir_.path(), 415 file_name_from, file_name_to, temp_dir_.GetPath(),
422 WorkItem::NEW_NAME_IF_IN_USE, alternate_to)); 416 WorkItem::NEW_NAME_IF_IN_USE, alternate_to));
423 417
424 EXPECT_TRUE(work_item->Do()); 418 EXPECT_TRUE(work_item->Do());
425 419
426 EXPECT_TRUE(base::PathExists(file_name_from)); 420 EXPECT_TRUE(base::PathExists(file_name_from));
427 EXPECT_TRUE(base::PathExists(file_name_to)); 421 EXPECT_TRUE(base::PathExists(file_name_to));
428 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 422 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
429 EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to)); 423 EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to));
430 // verify that the backup path does not exist 424 // verify that the backup path does not exist
431 EXPECT_TRUE(work_item->backup_path_.path().empty()); 425 EXPECT_TRUE(work_item->backup_path_.path().empty());
(...skipping 11 matching lines...) Expand all
443 EXPECT_FALSE(base::PathExists(alternate_to)); 437 EXPECT_FALSE(base::PathExists(alternate_to));
444 438
445 TerminateProcess(pi.hProcess, 0); 439 TerminateProcess(pi.hProcess, 0);
446 // make sure the handle is closed. 440 // make sure the handle is closed.
447 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); 441 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
448 CloseHandle(pi.hProcess); 442 CloseHandle(pi.hProcess);
449 CloseHandle(pi.hThread); 443 CloseHandle(pi.hThread);
450 444
451 // Now the process has terminated, lets try overwriting the file again 445 // Now the process has terminated, lets try overwriting the file again
452 work_item.reset(WorkItem::CreateCopyTreeWorkItem( 446 work_item.reset(WorkItem::CreateCopyTreeWorkItem(
453 file_name_from, file_name_to, 447 file_name_from, file_name_to, temp_dir_.GetPath(),
454 temp_dir_.path(), WorkItem::NEW_NAME_IF_IN_USE, 448 WorkItem::NEW_NAME_IF_IN_USE, alternate_to));
455 alternate_to));
456 if (IsFileInUse(file_name_to)) 449 if (IsFileInUse(file_name_to))
457 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(2)); 450 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(2));
458 // If file is still in use, the rest of the test will fail. 451 // If file is still in use, the rest of the test will fail.
459 ASSERT_FALSE(IsFileInUse(file_name_to)); 452 ASSERT_FALSE(IsFileInUse(file_name_to));
460 EXPECT_TRUE(work_item->Do()); 453 EXPECT_TRUE(work_item->Do());
461 454
462 // Get the path of backup file 455 // Get the path of backup file
463 base::FilePath backup_file(work_item->backup_path_.path()); 456 base::FilePath backup_file(work_item->backup_path_.path());
464 EXPECT_FALSE(backup_file.empty()); 457 EXPECT_FALSE(backup_file.empty());
465 backup_file = backup_file.AppendASCII("File_To"); 458 backup_file = backup_file.AppendASCII("File_To");
(...skipping 19 matching lines...) Expand all
485 } 478 }
486 479
487 // Test overwrite option IF_NOT_PRESENT: 480 // Test overwrite option IF_NOT_PRESENT:
488 // 1. If destination file/directory exist, the source should not be copied 481 // 1. If destination file/directory exist, the source should not be copied
489 // 2. If destination file/directory do not exist, the source should be copied 482 // 2. If destination file/directory do not exist, the source should be copied
490 // in the destination folder after Do() and should be rolled back after 483 // in the destination folder after Do() and should be rolled back after
491 // Rollback(). 484 // Rollback().
492 // Flaky, http://crbug.com/59785. 485 // Flaky, http://crbug.com/59785.
493 TEST_F(CopyTreeWorkItemTest, DISABLED_IfNotPresentTest) { 486 TEST_F(CopyTreeWorkItemTest, DISABLED_IfNotPresentTest) {
494 // Create source file 487 // Create source file
495 base::FilePath file_name_from(test_dir_.path()); 488 base::FilePath file_name_from(test_dir_.GetPath());
496 file_name_from = file_name_from.AppendASCII("File_From"); 489 file_name_from = file_name_from.AppendASCII("File_From");
497 CreateTextFile(file_name_from.value(), text_content_1); 490 CreateTextFile(file_name_from.value(), text_content_1);
498 ASSERT_TRUE(base::PathExists(file_name_from)); 491 ASSERT_TRUE(base::PathExists(file_name_from));
499 492
500 // Create an executable in destination path by copying ourself to it. 493 // Create an executable in destination path by copying ourself to it.
501 wchar_t exe_full_path_str[MAX_PATH]; 494 wchar_t exe_full_path_str[MAX_PATH];
502 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 495 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
503 base::FilePath exe_full_path(exe_full_path_str); 496 base::FilePath exe_full_path(exe_full_path_str);
504 497
505 base::FilePath dir_name_to(test_dir_.path()); 498 base::FilePath dir_name_to(test_dir_.GetPath());
506 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 499 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
507 base::CreateDirectory(dir_name_to); 500 base::CreateDirectory(dir_name_to);
508 ASSERT_TRUE(base::PathExists(dir_name_to)); 501 ASSERT_TRUE(base::PathExists(dir_name_to));
509 base::FilePath file_name_to(dir_name_to); 502 base::FilePath file_name_to(dir_name_to);
510 file_name_to = file_name_to.AppendASCII("File_To"); 503 file_name_to = file_name_to.AppendASCII("File_To");
511 base::CopyFile(exe_full_path, file_name_to); 504 base::CopyFile(exe_full_path, file_name_to);
512 ASSERT_TRUE(base::PathExists(file_name_to)); 505 ASSERT_TRUE(base::PathExists(file_name_to));
513 506
514 // Get the path of backup file 507 // Get the path of backup file
515 base::FilePath backup_file(temp_dir_.path()); 508 base::FilePath backup_file(temp_dir_.GetPath());
516 backup_file = backup_file.AppendASCII("File_To"); 509 backup_file = backup_file.AppendASCII("File_To");
517 510
518 // test Do(). 511 // test Do().
519 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem( 512 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem(
520 file_name_from, file_name_to, temp_dir_.path(), WorkItem::IF_NOT_PRESENT, 513 file_name_from, file_name_to, temp_dir_.GetPath(),
521 base::FilePath())); 514 WorkItem::IF_NOT_PRESENT, base::FilePath()));
522 EXPECT_TRUE(work_item->Do()); 515 EXPECT_TRUE(work_item->Do());
523 516
524 // verify that the source, destination have not changed and backup path 517 // verify that the source, destination have not changed and backup path
525 // does not exist 518 // does not exist
526 EXPECT_TRUE(base::PathExists(file_name_from)); 519 EXPECT_TRUE(base::PathExists(file_name_from));
527 EXPECT_TRUE(base::PathExists(file_name_to)); 520 EXPECT_TRUE(base::PathExists(file_name_to));
528 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 521 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
529 EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to)); 522 EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to));
530 EXPECT_FALSE(base::PathExists(backup_file)); 523 EXPECT_FALSE(base::PathExists(backup_file));
531 524
532 // test rollback() 525 // test rollback()
533 work_item->Rollback(); 526 work_item->Rollback();
534 527
535 // verify that the source, destination have not changed and backup path 528 // verify that the source, destination have not changed and backup path
536 // does not exist after rollback also 529 // does not exist after rollback also
537 EXPECT_TRUE(base::PathExists(file_name_from)); 530 EXPECT_TRUE(base::PathExists(file_name_from));
538 EXPECT_TRUE(base::PathExists(file_name_to)); 531 EXPECT_TRUE(base::PathExists(file_name_to));
539 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 532 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
540 EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to)); 533 EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to));
541 EXPECT_FALSE(base::PathExists(backup_file)); 534 EXPECT_FALSE(base::PathExists(backup_file));
542 535
543 // Now delete the destination and try copying the file again. 536 // Now delete the destination and try copying the file again.
544 base::DeleteFile(file_name_to, false); 537 base::DeleteFile(file_name_to, false);
545 work_item.reset(WorkItem::CreateCopyTreeWorkItem( 538 work_item.reset(WorkItem::CreateCopyTreeWorkItem(
546 file_name_from, file_name_to, 539 file_name_from, file_name_to, temp_dir_.GetPath(),
547 temp_dir_.path(), WorkItem::IF_NOT_PRESENT, 540 WorkItem::IF_NOT_PRESENT, base::FilePath()));
548 base::FilePath()));
549 EXPECT_TRUE(work_item->Do()); 541 EXPECT_TRUE(work_item->Do());
550 542
551 // verify that the source, destination are the same and backup path 543 // verify that the source, destination are the same and backup path
552 // does not exist 544 // does not exist
553 EXPECT_TRUE(base::PathExists(file_name_from)); 545 EXPECT_TRUE(base::PathExists(file_name_from));
554 EXPECT_TRUE(base::PathExists(file_name_to)); 546 EXPECT_TRUE(base::PathExists(file_name_to));
555 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 547 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
556 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 548 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
557 EXPECT_FALSE(base::PathExists(backup_file)); 549 EXPECT_FALSE(base::PathExists(backup_file));
558 550
559 // test rollback() 551 // test rollback()
560 work_item->Rollback(); 552 work_item->Rollback();
561 553
562 // verify that the destination does not exist anymore 554 // verify that the destination does not exist anymore
563 EXPECT_TRUE(base::PathExists(file_name_from)); 555 EXPECT_TRUE(base::PathExists(file_name_from));
564 EXPECT_FALSE(base::PathExists(file_name_to)); 556 EXPECT_FALSE(base::PathExists(file_name_to));
565 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 557 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
566 EXPECT_FALSE(base::PathExists(backup_file)); 558 EXPECT_FALSE(base::PathExists(backup_file));
567 } 559 }
568 560
569 // Copy one file without rollback. The existing one in destination is in use. 561 // Copy one file without rollback. The existing one in destination is in use.
570 // Verify it is moved to backup location and stays there. 562 // Verify it is moved to backup location and stays there.
571 // Flaky, http://crbug.com/59783. 563 // Flaky, http://crbug.com/59783.
572 TEST_F(CopyTreeWorkItemTest, DISABLED_CopyFileInUseAndCleanup) { 564 TEST_F(CopyTreeWorkItemTest, DISABLED_CopyFileInUseAndCleanup) {
573 // Create source file 565 // Create source file
574 base::FilePath file_name_from(test_dir_.path()); 566 base::FilePath file_name_from(test_dir_.GetPath());
575 file_name_from = file_name_from.AppendASCII("File_From"); 567 file_name_from = file_name_from.AppendASCII("File_From");
576 CreateTextFile(file_name_from.value(), text_content_1); 568 CreateTextFile(file_name_from.value(), text_content_1);
577 ASSERT_TRUE(base::PathExists(file_name_from)); 569 ASSERT_TRUE(base::PathExists(file_name_from));
578 570
579 // Create an executable in destination path by copying ourself to it. 571 // Create an executable in destination path by copying ourself to it.
580 wchar_t exe_full_path_str[MAX_PATH]; 572 wchar_t exe_full_path_str[MAX_PATH];
581 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 573 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
582 base::FilePath exe_full_path(exe_full_path_str); 574 base::FilePath exe_full_path(exe_full_path_str);
583 575
584 base::FilePath dir_name_to(test_dir_.path()); 576 base::FilePath dir_name_to(test_dir_.GetPath());
585 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 577 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
586 base::CreateDirectory(dir_name_to); 578 base::CreateDirectory(dir_name_to);
587 ASSERT_TRUE(base::PathExists(dir_name_to)); 579 ASSERT_TRUE(base::PathExists(dir_name_to));
588 580
589 base::FilePath file_name_to(dir_name_to); 581 base::FilePath file_name_to(dir_name_to);
590 file_name_to = file_name_to.AppendASCII("File_To"); 582 file_name_to = file_name_to.AppendASCII("File_To");
591 base::CopyFile(exe_full_path, file_name_to); 583 base::CopyFile(exe_full_path, file_name_to);
592 ASSERT_TRUE(base::PathExists(file_name_to)); 584 ASSERT_TRUE(base::PathExists(file_name_to));
593 585
594 VLOG(1) << "copy ourself from " << exe_full_path.value() 586 VLOG(1) << "copy ourself from " << exe_full_path.value()
595 << " to " << file_name_to.value(); 587 << " to " << file_name_to.value();
596 588
597 // Run the executable in destination path 589 // Run the executable in destination path
598 STARTUPINFOW si = {sizeof(si)}; 590 STARTUPINFOW si = {sizeof(si)};
599 PROCESS_INFORMATION pi = {0}; 591 PROCESS_INFORMATION pi = {0};
600 ASSERT_TRUE( 592 ASSERT_TRUE(
601 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()), 593 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()),
602 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED, 594 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
603 NULL, NULL, &si, &pi)); 595 NULL, NULL, &si, &pi));
604 596
605 base::FilePath backup_file; 597 base::FilePath backup_file;
606 598
607 // test Do(). 599 // test Do().
608 { 600 {
609 std::unique_ptr<CopyTreeWorkItem> work_item( 601 std::unique_ptr<CopyTreeWorkItem> work_item(
610 WorkItem::CreateCopyTreeWorkItem( 602 WorkItem::CreateCopyTreeWorkItem(
611 file_name_from, file_name_to, temp_dir_.path(), 603 file_name_from, file_name_to, temp_dir_.GetPath(),
612 WorkItem::IF_DIFFERENT, base::FilePath())); 604 WorkItem::IF_DIFFERENT, base::FilePath()));
613 605
614 EXPECT_TRUE(work_item->Do()); 606 EXPECT_TRUE(work_item->Do());
615 607
616 // Get the path of backup file 608 // Get the path of backup file
617 backup_file = work_item->backup_path_.path(); 609 backup_file = work_item->backup_path_.path();
618 EXPECT_FALSE(backup_file.empty()); 610 EXPECT_FALSE(backup_file.empty());
619 backup_file = backup_file.AppendASCII("File_To"); 611 backup_file = backup_file.AppendASCII("File_To");
620 612
621 EXPECT_TRUE(base::PathExists(file_name_from)); 613 EXPECT_TRUE(base::PathExists(file_name_from));
(...skipping 13 matching lines...) Expand all
635 // make sure the handle is closed. 627 // make sure the handle is closed.
636 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); 628 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
637 CloseHandle(pi.hProcess); 629 CloseHandle(pi.hProcess);
638 CloseHandle(pi.hThread); 630 CloseHandle(pi.hThread);
639 } 631 }
640 632
641 // Copy a tree from source to destination. 633 // Copy a tree from source to destination.
642 // Flaky, http://crbug.com/59784. 634 // Flaky, http://crbug.com/59784.
643 TEST_F(CopyTreeWorkItemTest, DISABLED_CopyTree) { 635 TEST_F(CopyTreeWorkItemTest, DISABLED_CopyTree) {
644 // Create source tree 636 // Create source tree
645 base::FilePath dir_name_from(test_dir_.path()); 637 base::FilePath dir_name_from(test_dir_.GetPath());
646 dir_name_from = dir_name_from.AppendASCII("from"); 638 dir_name_from = dir_name_from.AppendASCII("from");
647 base::CreateDirectory(dir_name_from); 639 base::CreateDirectory(dir_name_from);
648 ASSERT_TRUE(base::PathExists(dir_name_from)); 640 ASSERT_TRUE(base::PathExists(dir_name_from));
649 641
650 base::FilePath dir_name_from_1(dir_name_from); 642 base::FilePath dir_name_from_1(dir_name_from);
651 dir_name_from_1 = dir_name_from_1.AppendASCII("1"); 643 dir_name_from_1 = dir_name_from_1.AppendASCII("1");
652 base::CreateDirectory(dir_name_from_1); 644 base::CreateDirectory(dir_name_from_1);
653 ASSERT_TRUE(base::PathExists(dir_name_from_1)); 645 ASSERT_TRUE(base::PathExists(dir_name_from_1));
654 646
655 base::FilePath dir_name_from_2(dir_name_from); 647 base::FilePath dir_name_from_2(dir_name_from);
656 dir_name_from_2 = dir_name_from_2.AppendASCII("2"); 648 dir_name_from_2 = dir_name_from_2.AppendASCII("2");
657 base::CreateDirectory(dir_name_from_2); 649 base::CreateDirectory(dir_name_from_2);
658 ASSERT_TRUE(base::PathExists(dir_name_from_2)); 650 ASSERT_TRUE(base::PathExists(dir_name_from_2));
659 651
660 base::FilePath file_name_from_1(dir_name_from_1); 652 base::FilePath file_name_from_1(dir_name_from_1);
661 file_name_from_1 = file_name_from_1.AppendASCII("File_1.txt"); 653 file_name_from_1 = file_name_from_1.AppendASCII("File_1.txt");
662 CreateTextFile(file_name_from_1.value(), text_content_1); 654 CreateTextFile(file_name_from_1.value(), text_content_1);
663 ASSERT_TRUE(base::PathExists(file_name_from_1)); 655 ASSERT_TRUE(base::PathExists(file_name_from_1));
664 656
665 base::FilePath file_name_from_2(dir_name_from_2); 657 base::FilePath file_name_from_2(dir_name_from_2);
666 file_name_from_2 = file_name_from_2.AppendASCII("File_2.txt"); 658 file_name_from_2 = file_name_from_2.AppendASCII("File_2.txt");
667 CreateTextFile(file_name_from_2.value(), text_content_1); 659 CreateTextFile(file_name_from_2.value(), text_content_1);
668 ASSERT_TRUE(base::PathExists(file_name_from_2)); 660 ASSERT_TRUE(base::PathExists(file_name_from_2));
669 661
670 base::FilePath dir_name_to(test_dir_.path()); 662 base::FilePath dir_name_to(test_dir_.GetPath());
671 dir_name_to = dir_name_to.AppendASCII("to"); 663 dir_name_to = dir_name_to.AppendASCII("to");
672 664
673 // test Do() 665 // test Do()
674 { 666 {
675 std::unique_ptr<CopyTreeWorkItem> work_item( 667 std::unique_ptr<CopyTreeWorkItem> work_item(
676 WorkItem::CreateCopyTreeWorkItem(dir_name_from, dir_name_to, 668 WorkItem::CreateCopyTreeWorkItem(dir_name_from, dir_name_to,
677 temp_dir_.path(), WorkItem::ALWAYS, 669 temp_dir_.GetPath(), WorkItem::ALWAYS,
678 base::FilePath())); 670 base::FilePath()));
679 671
680 EXPECT_TRUE(work_item->Do()); 672 EXPECT_TRUE(work_item->Do());
681 } 673 }
682 674
683 base::FilePath file_name_to_1(dir_name_to); 675 base::FilePath file_name_to_1(dir_name_to);
684 file_name_to_1 = file_name_to_1.AppendASCII("1"); 676 file_name_to_1 = file_name_to_1.AppendASCII("1");
685 file_name_to_1 = file_name_to_1.AppendASCII("File_1.txt"); 677 file_name_to_1 = file_name_to_1.AppendASCII("File_1.txt");
686 EXPECT_TRUE(base::PathExists(file_name_to_1)); 678 EXPECT_TRUE(base::PathExists(file_name_to_1));
687 VLOG(1) << "compare " << file_name_from_1.value() 679 VLOG(1) << "compare " << file_name_from_1.value()
688 << " and " << file_name_to_1.value(); 680 << " and " << file_name_to_1.value();
689 EXPECT_TRUE(base::ContentsEqual(file_name_from_1, file_name_to_1)); 681 EXPECT_TRUE(base::ContentsEqual(file_name_from_1, file_name_to_1));
690 682
691 base::FilePath file_name_to_2(dir_name_to); 683 base::FilePath file_name_to_2(dir_name_to);
692 file_name_to_2 = file_name_to_2.AppendASCII("2"); 684 file_name_to_2 = file_name_to_2.AppendASCII("2");
693 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt"); 685 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt");
694 EXPECT_TRUE(base::PathExists(file_name_to_2)); 686 EXPECT_TRUE(base::PathExists(file_name_to_2));
695 VLOG(1) << "compare " << file_name_from_2.value() 687 VLOG(1) << "compare " << file_name_from_2.value()
696 << " and " << file_name_to_2.value(); 688 << " and " << file_name_to_2.value();
697 EXPECT_TRUE(base::ContentsEqual(file_name_from_2, file_name_to_2)); 689 EXPECT_TRUE(base::ContentsEqual(file_name_from_2, file_name_to_2));
698 } 690 }
OLDNEW
« no previous file with comments | « chrome/installer/util/conditional_work_item_list_unittest.cc ('k') | chrome/installer/util/create_dir_work_item_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698