| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | |
| 8 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 9 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 10 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 13 #include "chrome/browser/chromeos/drive/drive.pb.h" | 12 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 14 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" | 13 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" |
| 15 #include "chrome/browser/chromeos/drive/file_system_util.h" | 14 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 16 #include "chrome/browser/chromeos/drive/remove_stale_cache_files.h" | 15 #include "chrome/browser/chromeos/drive/remove_stale_cache_files.h" |
| 17 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 16 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // Verify that the cache entry is deleted. | 81 // Verify that the cache entry is deleted. |
| 83 EXPECT_FALSE(cache_->GetCacheEntry(local_id, &cache_entry)); | 82 EXPECT_FALSE(cache_->GetCacheEntry(local_id, &cache_entry)); |
| 84 } | 83 } |
| 85 | 84 |
| 86 TEST_F(RemoveStaleCacheFilesTest, DirtyCacheFiles) { | 85 TEST_F(RemoveStaleCacheFilesTest, DirtyCacheFiles) { |
| 87 base::FilePath dummy_file; | 86 base::FilePath dummy_file; |
| 88 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_file)); | 87 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_file)); |
| 89 | 88 |
| 90 // Dirty and deleted (= absent in resource_metada) cache entry. | 89 // Dirty and deleted (= absent in resource_metada) cache entry. |
| 91 std::string local_id_1("file:1"); | 90 std::string local_id_1("file:1"); |
| 92 std::string md5_1("abcdef0123456789"); | |
| 93 EXPECT_EQ(FILE_ERROR_OK, | 91 EXPECT_EQ(FILE_ERROR_OK, |
| 94 cache_->Store(local_id_1, md5_1, dummy_file, | 92 cache_->Store(local_id_1, std::string(), dummy_file, |
| 95 FileCache::FILE_OPERATION_COPY)); | 93 FileCache::FILE_OPERATION_COPY)); |
| 96 scoped_ptr<base::ScopedClosureRunner> file_closer; | |
| 97 EXPECT_EQ(FILE_ERROR_OK, cache_->OpenForWrite(local_id_1, &file_closer)); | |
| 98 | 94 |
| 99 // Dirty and mismatching-MD5 entry. | 95 // Dirty and mismatching-MD5 entry. |
| 100 std::string md5_2_cache("0123456789abcdef"); | 96 std::string md5_2_cache("0123456789abcdef"); |
| 101 std::string md5_2_metadata("abcdef0123456789"); | 97 std::string md5_2_metadata("abcdef0123456789"); |
| 102 | 98 |
| 103 ResourceEntry entry; | 99 ResourceEntry entry; |
| 104 std::string local_id_2; | 100 std::string local_id_2; |
| 105 entry.set_resource_id("resource_id"); | 101 entry.set_resource_id("resource_id"); |
| 106 entry.mutable_file_specific_info()->set_md5(md5_2_metadata); | 102 entry.mutable_file_specific_info()->set_md5(md5_2_metadata); |
| 107 entry.set_parent_local_id(util::kDriveGrandRootLocalId); | 103 entry.set_parent_local_id(util::kDriveGrandRootLocalId); |
| 108 entry.set_title("file.txt"); | 104 entry.set_title("file.txt"); |
| 109 resource_metadata_->AddEntry(entry, &local_id_2); | 105 resource_metadata_->AddEntry(entry, &local_id_2); |
| 110 | 106 |
| 111 EXPECT_EQ(FILE_ERROR_OK, | 107 EXPECT_EQ(FILE_ERROR_OK, |
| 112 cache_->Store(local_id_2, md5_2_cache, dummy_file, | 108 cache_->Store(local_id_2, std::string(), dummy_file, |
| 113 FileCache::FILE_OPERATION_COPY)); | 109 FileCache::FILE_OPERATION_COPY)); |
| 114 EXPECT_EQ(FILE_ERROR_OK, cache_->OpenForWrite(local_id_2, &file_closer)); | |
| 115 | 110 |
| 116 // Remove stale cache files. | 111 // Remove stale cache files. |
| 117 RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get()); | 112 RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get()); |
| 118 | 113 |
| 119 // Dirty cache should be removed if and only if the entry does not exist in | 114 // Dirty cache should be removed if and only if the entry does not exist in |
| 120 // resource_metadata. | 115 // resource_metadata. |
| 121 FileCacheEntry cache_entry; | 116 FileCacheEntry cache_entry; |
| 122 EXPECT_FALSE(cache_->GetCacheEntry(local_id_1, &cache_entry)); | 117 EXPECT_FALSE(cache_->GetCacheEntry(local_id_1, &cache_entry)); |
| 123 EXPECT_TRUE(cache_->GetCacheEntry(local_id_2, &cache_entry)); | 118 EXPECT_TRUE(cache_->GetCacheEntry(local_id_2, &cache_entry)); |
| 124 } | 119 } |
| 125 | 120 |
| 126 } // namespace internal | 121 } // namespace internal |
| 127 } // namespace drive | 122 } // namespace drive |
| OLD | NEW |