 Chromium Code Reviews
 Chromium Code Reviews Issue 11340049:
  Move CopyFileHierarchy to a common test namespace and also use it in MoveTreeWorkItemTest.MoveDirec…  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 11340049:
  Move CopyFileHierarchy to a common test namespace and also use it in MoveTreeWorkItemTest.MoveDirec…  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 6 | 
| 7 #include <fstream> | 7 #include <fstream> | 
| 8 | 8 | 
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" | 
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" | 
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" | 
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" | 
| 13 #include "base/process_util.h" | 13 #include "base/process_util.h" | 
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" | 
| 15 #include "chrome/installer/util/installer_util_test_common.h" | |
| 16 #include "chrome/installer/util/move_tree_work_item.h" | |
| 15 #include "chrome/installer/util/work_item.h" | 17 #include "chrome/installer/util/work_item.h" | 
| 16 #include "chrome/installer/util/move_tree_work_item.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" | 
| 18 | 19 | 
| 19 namespace { | 20 namespace { | 
| 20 class MoveTreeWorkItemTest : public testing::Test { | 21 class MoveTreeWorkItemTest : public testing::Test { | 
| 21 protected: | 22 protected: | 
| 22 virtual void SetUp() { | 23 virtual void SetUp() { | 
| 23 ASSERT_TRUE(temp_from_dir_.CreateUniqueTempDir()); | 24 ASSERT_TRUE(temp_from_dir_.CreateUniqueTempDir()); | 
| 24 ASSERT_TRUE(temp_to_dir_.CreateUniqueTempDir()); | 25 ASSERT_TRUE(temp_to_dir_.CreateUniqueTempDir()); | 
| 25 } | 26 } | 
| 26 | 27 | 
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 work_item->Rollback(); | 380 work_item->Rollback(); | 
| 380 | 381 | 
| 381 EXPECT_TRUE(file_util::PathExists(from_dir)); | 382 EXPECT_TRUE(file_util::PathExists(from_dir)); | 
| 382 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, from_file)); | 383 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, from_file)); | 
| 383 EXPECT_TRUE(file_util::PathExists(to_dir)); | 384 EXPECT_TRUE(file_util::PathExists(to_dir)); | 
| 384 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); | 385 EXPECT_EQ(0, ReadTextFile(to_file).compare(kTextContent1)); | 
| 385 } | 386 } | 
| 386 | 387 | 
| 387 // Move one directory from source to destination when destination already | 388 // Move one directory from source to destination when destination already | 
| 388 // exists. | 389 // exists. | 
| 389 TEST_F(MoveTreeWorkItemTest, | 390 TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExistsCheckForDuplicatesFull) { | 
| 390 FLAKY_MoveDirectoryDestExistsCheckForDuplicatesFull) { | |
| 391 // Create two level deep source dir | 391 // Create two level deep source dir | 
| 392 FilePath from_dir1(temp_from_dir_.path()); | 392 FilePath from_dir1(temp_from_dir_.path()); | 
| 393 from_dir1 = from_dir1.AppendASCII("From_Dir1"); | 393 from_dir1 = from_dir1.AppendASCII("From_Dir1"); | 
| 394 file_util::CreateDirectory(from_dir1); | 394 file_util::CreateDirectory(from_dir1); | 
| 395 ASSERT_TRUE(file_util::PathExists(from_dir1)); | 395 ASSERT_TRUE(file_util::PathExists(from_dir1)); | 
| 396 | 396 | 
| 397 FilePath from_dir2(from_dir1); | 397 FilePath from_dir2(from_dir1); | 
| 398 from_dir2 = from_dir2.AppendASCII("From_Dir2"); | 398 from_dir2 = from_dir2.AppendASCII("From_Dir2"); | 
| 399 file_util::CreateDirectory(from_dir2); | 399 file_util::CreateDirectory(from_dir2); | 
| 400 ASSERT_TRUE(file_util::PathExists(from_dir2)); | 400 ASSERT_TRUE(file_util::PathExists(from_dir2)); | 
| 401 | 401 | 
| 402 FilePath from_file(from_dir2); | 402 FilePath from_file(from_dir2); | 
| 403 from_file = from_file.AppendASCII("From_File"); | 403 from_file = from_file.AppendASCII("From_File"); | 
| 404 CreateTextFile(from_file.value(), kTextContent1); | 404 CreateTextFile(from_file.value(), kTextContent1); | 
| 405 ASSERT_TRUE(file_util::PathExists(from_file)); | 405 ASSERT_TRUE(file_util::PathExists(from_file)); | 
| 406 | 406 | 
| 407 // Create destination path | 407 // Create destination path | 
| 408 FilePath to_dir(temp_from_dir_.path()); | 408 FilePath to_dir(temp_from_dir_.path()); | 
| 409 to_dir = to_dir.AppendASCII("To_Dir"); | 409 to_dir = to_dir.AppendASCII("To_Dir"); | 
| 410 file_util::CreateDirectory(to_dir); | 410 file_util::CreateDirectory(to_dir); | 
| 
grt (UTC plus 2)
2012/10/31 17:33:06
is it equivalent to replace 410-414 with:
  // Cre
 
gab
2012/11/01 15:52:05
Yep, done.
 | |
| 411 ASSERT_TRUE(file_util::PathExists(to_dir)); | 411 ASSERT_TRUE(file_util::PathExists(to_dir)); | 
| 412 | 412 | 
| 413 // Create a sub-directory of the same name as in the source directory. | 413 // Create a sub-directory identical to the one in the source directory. | 
| 414 FilePath to_dir2(to_dir); | 414 installer::test::CopyFileHierarchy(from_dir2, to_dir); | 
| 415 to_dir2 = to_dir2.AppendASCII("From_Dir2"); | |
| 416 file_util::CreateDirectory(to_dir2); | |
| 417 ASSERT_TRUE(file_util::PathExists(to_dir2)); | |
| 418 | 415 | 
| 419 // Create an identical file in the to sub-directory. | 416 // Lock one of the files in the to destination directory to prevent moves. | 
| 420 FilePath orig_to_file(to_dir2); | 417 FilePath orig_to_file( | 
| 421 orig_to_file = orig_to_file.AppendASCII("From_File"); | 418 to_dir.AppendASCII("From_Dir2").AppendASCII("From_File")); | 
| 422 CreateTextFile(orig_to_file.value(), kTextContent1); | |
| 423 ASSERT_TRUE(file_util::PathExists(orig_to_file)); | |
| 424 | |
| 425 // Lock one of the files in the to sub-directory to prevent moves. | |
| 426 file_util::MemoryMappedFile mapped_file; | 419 file_util::MemoryMappedFile mapped_file; | 
| 427 EXPECT_TRUE(mapped_file.Initialize(orig_to_file)); | 420 EXPECT_TRUE(mapped_file.Initialize(orig_to_file)); | 
| 428 | 421 | 
| 429 // First check that we can't do the regular Move(). | 422 // First check that we can't do the regular Move(). | 
| 430 scoped_ptr<MoveTreeWorkItem> work_item( | 423 scoped_ptr<MoveTreeWorkItem> work_item( | 
| 431 WorkItem::CreateMoveTreeWorkItem(from_dir1, | 424 WorkItem::CreateMoveTreeWorkItem(from_dir1, | 
| 432 to_dir, | 425 to_dir, | 
| 433 temp_to_dir_.path(), | 426 temp_to_dir_.path(), | 
| 434 WorkItem::ALWAYS_MOVE)); | 427 WorkItem::ALWAYS_MOVE)); | 
| 435 EXPECT_FALSE(work_item->Do()); | 428 EXPECT_FALSE(work_item->Do()); | 
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 544 // the source files. | 537 // the source files. | 
| 545 EXPECT_TRUE(file_util::PathExists(from_dir1)); | 538 EXPECT_TRUE(file_util::PathExists(from_dir1)); | 
| 546 EXPECT_TRUE(file_util::PathExists(to_dir)); | 539 EXPECT_TRUE(file_util::PathExists(to_dir)); | 
| 547 EXPECT_TRUE(file_util::PathExists(orig_to_file)); | 540 EXPECT_TRUE(file_util::PathExists(orig_to_file)); | 
| 548 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1)); | 541 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1)); | 
| 549 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); | 542 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); | 
| 550 | 543 | 
| 551 // Also, after rollback the new "to" file should be gone. | 544 // Also, after rollback the new "to" file should be gone. | 
| 552 EXPECT_FALSE(file_util::PathExists(new_to_file2)); | 545 EXPECT_FALSE(file_util::PathExists(new_to_file2)); | 
| 553 } | 546 } | 
| OLD | NEW |