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

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

Issue 2379543002: installer and some misc files: Change ScopedTempDir::path() to GetPath() (Closed)
Patch Set: regroup ifs Created 4 years, 2 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 ASSERT_TRUE(base::PathExists(file_name_to)); 194 ASSERT_TRUE(base::PathExists(file_name_to));
195 195
196 // test Do() with always_overwrite being true. 196 // test Do() with always_overwrite being true.
197 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem( 197 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem(
198 file_name_from, file_name_to, temp_dir_.GetPath(), WorkItem::ALWAYS, 198 file_name_from, file_name_to, temp_dir_.GetPath(), WorkItem::ALWAYS,
199 base::FilePath())); 199 base::FilePath()));
200 200
201 EXPECT_TRUE(work_item->Do()); 201 EXPECT_TRUE(work_item->Do());
202 202
203 // Get the path of backup file 203 // Get the path of backup file
204 base::FilePath backup_file(work_item->backup_path_.path()); 204 base::FilePath backup_file(work_item->backup_path_.GetPath());
205 EXPECT_FALSE(backup_file.empty()); 205 EXPECT_FALSE(backup_file.empty());
206 backup_file = backup_file.AppendASCII("File_To.txt"); 206 backup_file = backup_file.AppendASCII("File_To.txt");
207 207
208 EXPECT_TRUE(base::PathExists(file_name_from)); 208 EXPECT_TRUE(base::PathExists(file_name_from));
209 EXPECT_TRUE(base::PathExists(file_name_to)); 209 EXPECT_TRUE(base::PathExists(file_name_to));
210 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));
211 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));
212 // 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
213 // file. 213 // file.
214 EXPECT_TRUE(base::PathExists(backup_file)); 214 EXPECT_TRUE(base::PathExists(backup_file));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 { 273 {
274 // test Do(). 274 // test Do().
275 std::unique_ptr<CopyTreeWorkItem> work_item( 275 std::unique_ptr<CopyTreeWorkItem> work_item(
276 WorkItem::CreateCopyTreeWorkItem( 276 WorkItem::CreateCopyTreeWorkItem(
277 file_name_from, file_name_to, temp_dir_.GetPath(), 277 file_name_from, file_name_to, temp_dir_.GetPath(),
278 WorkItem::IF_DIFFERENT, base::FilePath())); 278 WorkItem::IF_DIFFERENT, base::FilePath()));
279 279
280 EXPECT_TRUE(work_item->Do()); 280 EXPECT_TRUE(work_item->Do());
281 281
282 // Get the path of backup file 282 // Get the path of backup file
283 backup_file = work_item->backup_path_.path(); 283 backup_file = work_item->backup_path_.GetPath();
284 EXPECT_FALSE(backup_file.empty()); 284 EXPECT_FALSE(backup_file.empty());
285 backup_file = backup_file.AppendASCII("File_To.txt"); 285 backup_file = backup_file.AppendASCII("File_To.txt");
286 286
287 EXPECT_TRUE(base::PathExists(file_name_from)); 287 EXPECT_TRUE(base::PathExists(file_name_from));
288 EXPECT_TRUE(base::PathExists(file_name_to)); 288 EXPECT_TRUE(base::PathExists(file_name_to));
289 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));
290 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));
291 // verify the file is moved to backup place. 291 // verify the file is moved to backup place.
292 EXPECT_TRUE(base::PathExists(backup_file)); 292 EXPECT_TRUE(base::PathExists(backup_file));
293 EXPECT_EQ(0, ReadTextFile(backup_file.value()).compare(text_content_2)); 293 EXPECT_EQ(0, ReadTextFile(backup_file.value()).compare(text_content_2));
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 NULL, NULL, &si, &pi)); 334 NULL, NULL, &si, &pi));
335 335
336 // test Do(). 336 // test Do().
337 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem( 337 std::unique_ptr<CopyTreeWorkItem> work_item(WorkItem::CreateCopyTreeWorkItem(
338 file_name_from, file_name_to, temp_dir_.GetPath(), WorkItem::IF_DIFFERENT, 338 file_name_from, file_name_to, temp_dir_.GetPath(), WorkItem::IF_DIFFERENT,
339 base::FilePath())); 339 base::FilePath()));
340 340
341 EXPECT_TRUE(work_item->Do()); 341 EXPECT_TRUE(work_item->Do());
342 342
343 // Get the path of backup file 343 // Get the path of backup file
344 base::FilePath backup_file(work_item->backup_path_.path()); 344 base::FilePath backup_file(work_item->backup_path_.GetPath());
345 EXPECT_FALSE(backup_file.empty()); 345 EXPECT_FALSE(backup_file.empty());
346 backup_file = backup_file.AppendASCII("File_To"); 346 backup_file = backup_file.AppendASCII("File_To");
347 347
348 EXPECT_TRUE(base::PathExists(file_name_from)); 348 EXPECT_TRUE(base::PathExists(file_name_from));
349 EXPECT_TRUE(base::PathExists(file_name_to)); 349 EXPECT_TRUE(base::PathExists(file_name_to));
350 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 350 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
351 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 351 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
352 // verify the file in used is moved to backup place. 352 // verify the file in used is moved to backup place.
353 EXPECT_TRUE(base::PathExists(backup_file)); 353 EXPECT_TRUE(base::PathExists(backup_file));
354 EXPECT_TRUE(base::ContentsEqual(exe_full_path, backup_file)); 354 EXPECT_TRUE(base::ContentsEqual(exe_full_path, backup_file));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 file_name_from, file_name_to, temp_dir_.GetPath(), 415 file_name_from, file_name_to, temp_dir_.GetPath(),
416 WorkItem::NEW_NAME_IF_IN_USE, alternate_to)); 416 WorkItem::NEW_NAME_IF_IN_USE, alternate_to));
417 417
418 EXPECT_TRUE(work_item->Do()); 418 EXPECT_TRUE(work_item->Do());
419 419
420 EXPECT_TRUE(base::PathExists(file_name_from)); 420 EXPECT_TRUE(base::PathExists(file_name_from));
421 EXPECT_TRUE(base::PathExists(file_name_to)); 421 EXPECT_TRUE(base::PathExists(file_name_to));
422 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));
423 EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to)); 423 EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to));
424 // verify that the backup path does not exist 424 // verify that the backup path does not exist
425 EXPECT_TRUE(work_item->backup_path_.path().empty()); 425 EXPECT_FALSE(work_item->backup_path_created_);
426 EXPECT_TRUE(base::ContentsEqual(file_name_from, alternate_to)); 426 EXPECT_TRUE(base::ContentsEqual(file_name_from, alternate_to));
427 427
428 // test rollback() 428 // test rollback()
429 work_item->Rollback(); 429 work_item->Rollback();
430 430
431 EXPECT_TRUE(base::PathExists(file_name_from)); 431 EXPECT_TRUE(base::PathExists(file_name_from));
432 EXPECT_TRUE(base::PathExists(file_name_to)); 432 EXPECT_TRUE(base::PathExists(file_name_to));
433 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 433 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
434 EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to)); 434 EXPECT_TRUE(base::ContentsEqual(exe_full_path, file_name_to));
435 EXPECT_TRUE(work_item->backup_path_.path().empty()); 435 EXPECT_FALSE(work_item->backup_path_created_);
436 // the alternate file should be gone after rollback 436 // the alternate file should be gone after rollback
437 EXPECT_FALSE(base::PathExists(alternate_to)); 437 EXPECT_FALSE(base::PathExists(alternate_to));
438 438
439 TerminateProcess(pi.hProcess, 0); 439 TerminateProcess(pi.hProcess, 0);
440 // make sure the handle is closed. 440 // make sure the handle is closed.
441 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); 441 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
442 CloseHandle(pi.hProcess); 442 CloseHandle(pi.hProcess);
443 CloseHandle(pi.hThread); 443 CloseHandle(pi.hThread);
444 444
445 // Now the process has terminated, lets try overwriting the file again 445 // Now the process has terminated, lets try overwriting the file again
446 work_item.reset(WorkItem::CreateCopyTreeWorkItem( 446 work_item.reset(WorkItem::CreateCopyTreeWorkItem(
447 file_name_from, file_name_to, temp_dir_.GetPath(), 447 file_name_from, file_name_to, temp_dir_.GetPath(),
448 WorkItem::NEW_NAME_IF_IN_USE, alternate_to)); 448 WorkItem::NEW_NAME_IF_IN_USE, alternate_to));
449 if (IsFileInUse(file_name_to)) 449 if (IsFileInUse(file_name_to))
450 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(2)); 450 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(2));
451 // 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.
452 ASSERT_FALSE(IsFileInUse(file_name_to)); 452 ASSERT_FALSE(IsFileInUse(file_name_to));
453 EXPECT_TRUE(work_item->Do()); 453 EXPECT_TRUE(work_item->Do());
454 454
455 // Get the path of backup file 455 // Get the path of backup file
456 base::FilePath backup_file(work_item->backup_path_.path()); 456 base::FilePath backup_file(work_item->backup_path_.GetPath());
457 EXPECT_FALSE(backup_file.empty()); 457 EXPECT_FALSE(backup_file.empty());
458 backup_file = backup_file.AppendASCII("File_To"); 458 backup_file = backup_file.AppendASCII("File_To");
459 459
460 EXPECT_TRUE(base::PathExists(file_name_from)); 460 EXPECT_TRUE(base::PathExists(file_name_from));
461 EXPECT_TRUE(base::PathExists(file_name_to)); 461 EXPECT_TRUE(base::PathExists(file_name_to));
462 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 462 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
463 EXPECT_TRUE(base::ContentsEqual(file_name_from, file_name_to)); 463 EXPECT_TRUE(base::ContentsEqual(file_name_from, file_name_to));
464 // verify that the backup path does exist 464 // verify that the backup path does exist
465 EXPECT_TRUE(base::PathExists(backup_file)); 465 EXPECT_TRUE(base::PathExists(backup_file));
466 EXPECT_FALSE(base::PathExists(alternate_to)); 466 EXPECT_FALSE(base::PathExists(alternate_to));
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 // test Do(). 599 // test Do().
600 { 600 {
601 std::unique_ptr<CopyTreeWorkItem> work_item( 601 std::unique_ptr<CopyTreeWorkItem> work_item(
602 WorkItem::CreateCopyTreeWorkItem( 602 WorkItem::CreateCopyTreeWorkItem(
603 file_name_from, file_name_to, temp_dir_.GetPath(), 603 file_name_from, file_name_to, temp_dir_.GetPath(),
604 WorkItem::IF_DIFFERENT, base::FilePath())); 604 WorkItem::IF_DIFFERENT, base::FilePath()));
605 605
606 EXPECT_TRUE(work_item->Do()); 606 EXPECT_TRUE(work_item->Do());
607 607
608 // Get the path of backup file 608 // Get the path of backup file
609 backup_file = work_item->backup_path_.path(); 609 backup_file = work_item->backup_path_.GetPath();
610 EXPECT_FALSE(backup_file.empty()); 610 EXPECT_FALSE(backup_file.empty());
611 backup_file = backup_file.AppendASCII("File_To"); 611 backup_file = backup_file.AppendASCII("File_To");
612 612
613 EXPECT_TRUE(base::PathExists(file_name_from)); 613 EXPECT_TRUE(base::PathExists(file_name_from));
614 EXPECT_TRUE(base::PathExists(file_name_to)); 614 EXPECT_TRUE(base::PathExists(file_name_to));
615 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 615 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
616 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 616 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
617 // verify the file in used is moved to backup place. 617 // verify the file in used is moved to backup place.
618 EXPECT_TRUE(base::PathExists(backup_file)); 618 EXPECT_TRUE(base::PathExists(backup_file));
619 EXPECT_TRUE(base::ContentsEqual(exe_full_path, backup_file)); 619 EXPECT_TRUE(base::ContentsEqual(exe_full_path, backup_file));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 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));
682 682
683 base::FilePath file_name_to_2(dir_name_to); 683 base::FilePath file_name_to_2(dir_name_to);
684 file_name_to_2 = file_name_to_2.AppendASCII("2"); 684 file_name_to_2 = file_name_to_2.AppendASCII("2");
685 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");
686 EXPECT_TRUE(base::PathExists(file_name_to_2)); 686 EXPECT_TRUE(base::PathExists(file_name_to_2));
687 VLOG(1) << "compare " << file_name_from_2.value() 687 VLOG(1) << "compare " << file_name_from_2.value()
688 << " and " << file_name_to_2.value(); 688 << " and " << file_name_to_2.value();
689 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));
690 } 690 }
OLDNEW
« no previous file with comments | « chrome/installer/util/copy_tree_work_item.cc ('k') | chrome/installer/util/delete_tree_work_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698