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 a file hierarchy identical to the one in the source directory. |
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 ASSERT_TRUE(installer::test::CopyFileHierarchy(from_dir1, to_dir)); |
411 ASSERT_TRUE(file_util::PathExists(to_dir)); | |
412 | 411 |
413 // Create a sub-directory of the same name as in the source directory. | 412 // Lock one of the files in the to destination directory to prevent moves. |
414 FilePath to_dir2(to_dir); | 413 FilePath orig_to_file( |
415 to_dir2 = to_dir2.AppendASCII("From_Dir2"); | 414 to_dir.AppendASCII("From_Dir2").AppendASCII("From_File")); |
416 file_util::CreateDirectory(to_dir2); | |
417 ASSERT_TRUE(file_util::PathExists(to_dir2)); | |
418 | |
419 // Create an identical file in the to sub-directory. | |
420 FilePath orig_to_file(to_dir2); | |
421 orig_to_file = orig_to_file.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; | 415 file_util::MemoryMappedFile mapped_file; |
427 EXPECT_TRUE(mapped_file.Initialize(orig_to_file)); | 416 EXPECT_TRUE(mapped_file.Initialize(orig_to_file)); |
428 | 417 |
429 // First check that we can't do the regular Move(). | 418 // First check that we can't do the regular Move(). |
430 scoped_ptr<MoveTreeWorkItem> work_item( | 419 scoped_ptr<MoveTreeWorkItem> work_item( |
431 WorkItem::CreateMoveTreeWorkItem(from_dir1, | 420 WorkItem::CreateMoveTreeWorkItem(from_dir1, |
432 to_dir, | 421 to_dir, |
433 temp_to_dir_.path(), | 422 temp_to_dir_.path(), |
434 WorkItem::ALWAYS_MOVE)); | 423 WorkItem::ALWAYS_MOVE)); |
435 EXPECT_FALSE(work_item->Do()); | 424 EXPECT_FALSE(work_item->Do()); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 // the source files. | 533 // the source files. |
545 EXPECT_TRUE(file_util::PathExists(from_dir1)); | 534 EXPECT_TRUE(file_util::PathExists(from_dir1)); |
546 EXPECT_TRUE(file_util::PathExists(to_dir)); | 535 EXPECT_TRUE(file_util::PathExists(to_dir)); |
547 EXPECT_TRUE(file_util::PathExists(orig_to_file)); | 536 EXPECT_TRUE(file_util::PathExists(orig_to_file)); |
548 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1)); | 537 EXPECT_EQ(0, ReadTextFile(orig_to_file).compare(kTextContent1)); |
549 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); | 538 EXPECT_EQ(0, ReadTextFile(from_file).compare(kTextContent1)); |
550 | 539 |
551 // Also, after rollback the new "to" file should be gone. | 540 // Also, after rollback the new "to" file should be gone. |
552 EXPECT_FALSE(file_util::PathExists(new_to_file2)); | 541 EXPECT_FALSE(file_util::PathExists(new_to_file2)); |
553 } | 542 } |
OLD | NEW |