| OLD | NEW |
| 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/browser/chromeos/drive/file_cache.h" | 5 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 761 // Store files. This file should not be moved. | 761 // Store files. This file should not be moved. |
| 762 EXPECT_EQ(FILE_ERROR_OK, cache_->Store("id_foo", "md5", src_path, | 762 EXPECT_EQ(FILE_ERROR_OK, cache_->Store("id_foo", "md5", src_path, |
| 763 FileCache::FILE_OPERATION_COPY)); | 763 FileCache::FILE_OPERATION_COPY)); |
| 764 | 764 |
| 765 // Set up files in the cache directory. These files should be moved. | 765 // Set up files in the cache directory. These files should be moved. |
| 766 const base::FilePath file_directory = | 766 const base::FilePath file_directory = |
| 767 temp_dir_.path().AppendASCII(kCacheFileDirectory); | 767 temp_dir_.path().AppendASCII(kCacheFileDirectory); |
| 768 ASSERT_TRUE(base::CopyFile(src_path, file_directory.AppendASCII("id_bar"))); | 768 ASSERT_TRUE(base::CopyFile(src_path, file_directory.AppendASCII("id_bar"))); |
| 769 ASSERT_TRUE(base::CopyFile(src_path, file_directory.AppendASCII("id_baz"))); | 769 ASSERT_TRUE(base::CopyFile(src_path, file_directory.AppendASCII("id_baz"))); |
| 770 | 770 |
| 771 // Insert a dirty entry with "id_baz" to |recovered_cache_entries|. |
| 772 // This should not prevent the file from being recovered. |
| 773 std::map<std::string, FileCacheEntry> recovered_cache_entries; |
| 774 recovered_cache_entries["id_baz"].set_is_dirty(true); |
| 775 |
| 771 // Recover files. | 776 // Recover files. |
| 772 const base::FilePath dest_directory = temp_dir_.path().AppendASCII("dest"); | 777 const base::FilePath dest_directory = temp_dir_.path().AppendASCII("dest"); |
| 773 EXPECT_TRUE(cache_->RecoverFilesFromCacheDirectory(dest_directory)); | 778 EXPECT_TRUE(cache_->RecoverFilesFromCacheDirectory(dest_directory, |
| 779 recovered_cache_entries)); |
| 774 | 780 |
| 775 // Only two files should be recovered. | 781 // Only two files should be recovered. |
| 776 EXPECT_TRUE(base::PathExists(dest_directory)); | 782 EXPECT_TRUE(base::PathExists(dest_directory)); |
| 777 EXPECT_TRUE(base::ContentsEqual(src_path, | 783 EXPECT_TRUE(base::ContentsEqual(src_path, |
| 778 dest_directory.Append("image00000001.png"))); | 784 dest_directory.Append("image00000001.png"))); |
| 779 EXPECT_TRUE(base::ContentsEqual(src_path, | 785 EXPECT_TRUE(base::ContentsEqual(src_path, |
| 780 dest_directory.Append("image00000002.png"))); | 786 dest_directory.Append("image00000002.png"))); |
| 781 EXPECT_FALSE(base::PathExists(dest_directory.Append("image00000003.png"))); | 787 EXPECT_FALSE(base::PathExists(dest_directory.Append("image00000003.png"))); |
| 782 } | 788 } |
| 783 | 789 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 // Clear cache. | 956 // Clear cache. |
| 951 EXPECT_TRUE(cache_->ClearAll()); | 957 EXPECT_TRUE(cache_->ClearAll()); |
| 952 | 958 |
| 953 // Verify that the cache is removed. | 959 // Verify that the cache is removed. |
| 954 EXPECT_FALSE(cache_->GetCacheEntry(id, &cache_entry)); | 960 EXPECT_FALSE(cache_->GetCacheEntry(id, &cache_entry)); |
| 955 EXPECT_TRUE(file_util::IsDirectoryEmpty(cache_files_dir_)); | 961 EXPECT_TRUE(file_util::IsDirectoryEmpty(cache_files_dir_)); |
| 956 } | 962 } |
| 957 | 963 |
| 958 } // namespace internal | 964 } // namespace internal |
| 959 } // namespace drive | 965 } // namespace drive |
| OLD | NEW |