diff options
author | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-05 18:21:00 +0000 |
---|---|---|
committer | gab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-05 18:21:00 +0000 |
commit | a7db59a612909895bc4cfefb38da59eb16afd630 (patch) | |
tree | 05e2e29fed798e7a8b83444af7d9817b168da063 /chrome/installer/util | |
parent | cfc888a562b3b6d3e613f008d5997fe0345e7181 (diff) | |
download | chromium_src-a7db59a612909895bc4cfefb38da59eb16afd630.zip chromium_src-a7db59a612909895bc4cfefb38da59eb16afd630.tar.gz chromium_src-a7db59a612909895bc4cfefb38da59eb16afd630.tar.bz2 |
Move CopyFileHierarchy to a common test namespace and also use it in MoveTreeWorkItemTest.MoveDirectoryDestExistsCheckForDuplicatesFull.
Unflakes that test.
TBR=thakis@chromium.org (for chrome\chrome_installer.gypi).
BUG=156374
TEST=installer_util_unittests.exe (ran all of them to make sure no other test was affected)
Review URL: https://chromiumcodereview.appspot.com/11340049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165962 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/util')
4 files changed, 69 insertions, 42 deletions
diff --git a/chrome/installer/util/duplicate_tree_detector_unittest.cc b/chrome/installer/util/duplicate_tree_detector_unittest.cc index 163c91b..d1445dc 100644 --- a/chrome/installer/util/duplicate_tree_detector_unittest.cc +++ b/chrome/installer/util/duplicate_tree_detector_unittest.cc @@ -3,7 +3,6 @@ // found in the LICENSE file. #include <windows.h> -#include <shellapi.h> #include <fstream> @@ -12,6 +11,7 @@ #include "base/string16.h" #include "base/string_util.h" #include "chrome/installer/util/duplicate_tree_detector.h" +#include "chrome/installer/util/installer_util_test_common.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -57,27 +57,7 @@ class DuplicateTreeDetectorTest : public testing::Test { CreateTextFile(f2.MaybeAsASCII(), text_content_2_); ASSERT_TRUE(file_util::PathExists(f2)); - CopyFileHierarchy(d1, second_root); - } - - // Copies the hierarcy in |from| to |to|. - void CopyFileHierarchy(const FilePath& from, const FilePath& to) { - // In SHFILEOPSTRUCT below, |pFrom| and |pTo| have to be double-null - // terminated: http://msdn.microsoft.com/library/bb759795.aspx - string16 double_null_from(from.value()); - double_null_from.push_back(L'\0'); - string16 double_null_to(to.value()); - double_null_to.push_back(L'\0'); - - SHFILEOPSTRUCT file_op = {}; - file_op.wFunc = FO_COPY; - file_op.pFrom = double_null_from.c_str(); - file_op.pTo = double_null_to.c_str(); - file_op.fFlags = FOF_NO_UI; - - ASSERT_EQ(0, SHFileOperation(&file_op)); - - ASSERT_FALSE(file_op.fAnyOperationsAborted); + ASSERT_TRUE(installer::test::CopyFileHierarchy(d1, second_root)); } ScopedTempDir temp_source_dir_; @@ -164,7 +144,7 @@ TEST_F(DuplicateTreeDetectorTest, TestSingleFiles) { // This file should be the same. FilePath dest_file(temp_dest_dir_.path()); dest_file = dest_file.AppendASCII("F1"); - CopyFileHierarchy(source_file, dest_file); + ASSERT_TRUE(installer::test::CopyFileHierarchy(source_file, dest_file)); // This file should be different. FilePath other_file(temp_dest_dir_.path()); diff --git a/chrome/installer/util/installer_util_test_common.cc b/chrome/installer/util/installer_util_test_common.cc new file mode 100644 index 0000000..708d6c3 --- /dev/null +++ b/chrome/installer/util/installer_util_test_common.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/installer/util/installer_util_test_common.h" + +#include <windows.h> +#include <shellapi.h> + +#include "base/file_path.h" +#include "base/string16.h" + +namespace installer { + +namespace test { + +bool CopyFileHierarchy(const FilePath& from, const FilePath& to) { + // In SHFILEOPSTRUCT below, |pFrom| and |pTo| have to be double-null + // terminated: http://msdn.microsoft.com/library/bb759795.aspx + string16 double_null_from(from.value()); + double_null_from.push_back(L'\0'); + string16 double_null_to(to.value()); + double_null_to.push_back(L'\0'); + + SHFILEOPSTRUCT file_op = {}; + file_op.wFunc = FO_COPY; + file_op.pFrom = double_null_from.c_str(); + file_op.pTo = double_null_to.c_str(); + file_op.fFlags = FOF_NO_UI; + + return (SHFileOperation(&file_op) == 0 && !file_op.fAnyOperationsAborted); +} + +} // namespace test + +} // namespace installer diff --git a/chrome/installer/util/installer_util_test_common.h b/chrome/installer/util/installer_util_test_common.h new file mode 100644 index 0000000..8839f6d --- /dev/null +++ b/chrome/installer/util/installer_util_test_common.h @@ -0,0 +1,22 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_INSTALLER_UTIL_INSTALLER_UTIL_TEST_COMMON_H_ +#define CHROME_INSTALLER_UTIL_INSTALLER_UTIL_TEST_COMMON_H_ + +class FilePath; + +namespace installer { + +namespace test { + +// Copies the hierarcy in |from| to |to|. +// Keeps all file properties identical (creation time, etc.). +bool CopyFileHierarchy(const FilePath& from, const FilePath& to); + +} // namespace test + +} // namespace installer + +#endif // CHROME_INSTALLER_UTIL_INSTALLER_UTIL_TEST_COMMON_H_ diff --git a/chrome/installer/util/move_tree_work_item_unittest.cc b/chrome/installer/util/move_tree_work_item_unittest.cc index 5d5018d..ebe47d2 100644 --- a/chrome/installer/util/move_tree_work_item_unittest.cc +++ b/chrome/installer/util/move_tree_work_item_unittest.cc @@ -12,8 +12,9 @@ #include "base/path_service.h" #include "base/process_util.h" #include "base/string_util.h" -#include "chrome/installer/util/work_item.h" +#include "chrome/installer/util/installer_util_test_common.h" #include "chrome/installer/util/move_tree_work_item.h" +#include "chrome/installer/util/work_item.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -386,8 +387,7 @@ TEST_F(MoveTreeWorkItemTest, MoveFileInUse) { // Move one directory from source to destination when destination already // exists. -TEST_F(MoveTreeWorkItemTest, - FLAKY_MoveDirectoryDestExistsCheckForDuplicatesFull) { +TEST_F(MoveTreeWorkItemTest, MoveDirectoryDestExistsCheckForDuplicatesFull) { // Create two level deep source dir FilePath from_dir1(temp_from_dir_.path()); from_dir1 = from_dir1.AppendASCII("From_Dir1"); @@ -404,25 +404,14 @@ TEST_F(MoveTreeWorkItemTest, CreateTextFile(from_file.value(), kTextContent1); ASSERT_TRUE(file_util::PathExists(from_file)); - // Create destination path + // // Create a file hierarchy identical to the one in the source directory. FilePath to_dir(temp_from_dir_.path()); to_dir = to_dir.AppendASCII("To_Dir"); - file_util::CreateDirectory(to_dir); - ASSERT_TRUE(file_util::PathExists(to_dir)); - - // Create a sub-directory of the same name as in the source directory. - FilePath to_dir2(to_dir); - to_dir2 = to_dir2.AppendASCII("From_Dir2"); - file_util::CreateDirectory(to_dir2); - ASSERT_TRUE(file_util::PathExists(to_dir2)); - - // Create an identical file in the to sub-directory. - FilePath orig_to_file(to_dir2); - orig_to_file = orig_to_file.AppendASCII("From_File"); - CreateTextFile(orig_to_file.value(), kTextContent1); - ASSERT_TRUE(file_util::PathExists(orig_to_file)); + ASSERT_TRUE(installer::test::CopyFileHierarchy(from_dir1, to_dir)); - // Lock one of the files in the to sub-directory to prevent moves. + // Lock one of the files in the to destination directory to prevent moves. + FilePath orig_to_file( + to_dir.AppendASCII("From_Dir2").AppendASCII("From_File")); file_util::MemoryMappedFile mapped_file; EXPECT_TRUE(mapped_file.Initialize(orig_to_file)); |