file_util::Move fails on Windows if moving a directory
across volumes. This change adds a
CopyAndDeleteDirectory function, and Move falls back
to CopyAndDeleteDirectory if moving directory fails.

BUG=8505
Review URL: http://codereview.chromium.org/43069

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11460 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 2c59af7dcafb6e26fee53be61c180cfc7a310ed5
diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc
index 5a28a95..0153e9b 100644
--- a/base/file_util_unittest.cc
+++ b/base/file_util_unittest.cc
@@ -685,6 +685,36 @@
   DeleteFile(link_file.value().c_str());
   CoUninitialize();
 }
+
+TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) {
+  // Create a directory
+  FilePath dir_name_from =
+      test_dir_.Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir"));
+  file_util::CreateDirectory(dir_name_from);
+  ASSERT_TRUE(file_util::PathExists(dir_name_from));
+
+  // Create a file under the directory
+  FilePath file_name_from =
+      dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt"));
+  CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
+  ASSERT_TRUE(file_util::PathExists(file_name_from));
+
+  // Move the directory by using CopyAndDeleteDirectory
+  FilePath dir_name_to = test_dir_.Append(
+      FILE_PATH_LITERAL("CopyAndDelete_To_Subdir"));
+  FilePath file_name_to =
+      dir_name_to.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt"));
+
+  ASSERT_FALSE(file_util::PathExists(dir_name_to));
+
+  EXPECT_TRUE(file_util::CopyAndDeleteDirectory(dir_name_from, dir_name_to));
+
+  // Check everything has been moved.
+  EXPECT_FALSE(file_util::PathExists(dir_name_from));
+  EXPECT_FALSE(file_util::PathExists(file_name_from));
+  EXPECT_TRUE(file_util::PathExists(dir_name_to));
+  EXPECT_TRUE(file_util::PathExists(file_name_to));
+}
 #endif
 
 TEST_F(FileUtilTest, CreateTemporaryFileNameTest) {