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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 base::FilePath dummy_file; | 87 base::FilePath dummy_file; |
88 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), | 88 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), |
89 &dummy_file)); | 89 &dummy_file)); |
90 | 90 |
91 // Dirty and deleted (= absent in resource_metada) cache entry. | 91 // Dirty and deleted (= absent in resource_metada) cache entry. |
92 std::string resource_id_1("file:1"); | 92 std::string resource_id_1("file:1"); |
93 std::string md5_1("abcdef0123456789"); | 93 std::string md5_1("abcdef0123456789"); |
94 EXPECT_EQ(FILE_ERROR_OK, | 94 EXPECT_EQ(FILE_ERROR_OK, |
95 cache_->Store(resource_id_1, md5_1, dummy_file, | 95 cache_->Store(resource_id_1, md5_1, dummy_file, |
96 FileCache::FILE_OPERATION_COPY)); | 96 FileCache::FILE_OPERATION_COPY)); |
97 EXPECT_EQ(FILE_ERROR_OK, cache_->MarkDirty(resource_id_1, md5_1)); | 97 EXPECT_EQ(FILE_ERROR_OK, cache_->MarkDirty(resource_id_1)); |
98 | 98 |
99 // Dirty and mismatching-MD5 entry. | 99 // Dirty and mismatching-MD5 entry. |
100 std::string resource_id_2("file:2"); | 100 std::string resource_id_2("file:2"); |
101 std::string md5_2_cache("0123456789abcdef"); | 101 std::string md5_2_cache("0123456789abcdef"); |
102 std::string md5_2_metadata("abcdef0123456789"); | 102 std::string md5_2_metadata("abcdef0123456789"); |
103 EXPECT_EQ(FILE_ERROR_OK, | 103 EXPECT_EQ(FILE_ERROR_OK, |
104 cache_->Store(resource_id_2, md5_2_cache, dummy_file, | 104 cache_->Store(resource_id_2, md5_2_cache, dummy_file, |
105 FileCache::FILE_OPERATION_COPY)); | 105 FileCache::FILE_OPERATION_COPY)); |
106 EXPECT_EQ(FILE_ERROR_OK, cache_->MarkDirty(resource_id_2, md5_2_cache)); | 106 EXPECT_EQ(FILE_ERROR_OK, cache_->MarkDirty(resource_id_2)); |
107 | 107 |
108 ResourceEntry entry; | 108 ResourceEntry entry; |
109 entry.set_resource_id(resource_id_2); | 109 entry.set_resource_id(resource_id_2); |
110 entry.mutable_file_specific_info()->set_md5(md5_2_metadata); | 110 entry.mutable_file_specific_info()->set_md5(md5_2_metadata); |
111 entry.set_parent_resource_id(util::kDriveGrandRootSpecialResourceId); | 111 entry.set_parent_resource_id(util::kDriveGrandRootSpecialResourceId); |
112 resource_metadata_->AddEntry(entry); | 112 resource_metadata_->AddEntry(entry); |
113 | 113 |
114 // Remove stale cache files. | 114 // Remove stale cache files. |
115 RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get()); | 115 RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get()); |
116 | 116 |
117 // Dirty cache should be removed if and only if the entry does not exist in | 117 // Dirty cache should be removed if and only if the entry does not exist in |
118 // resource_metadata. | 118 // resource_metadata. |
119 FileCacheEntry cache_entry; | 119 FileCacheEntry cache_entry; |
120 EXPECT_FALSE(cache_->GetCacheEntry(resource_id_1, md5_1, &cache_entry)); | 120 EXPECT_FALSE(cache_->GetCacheEntry(resource_id_1, md5_1, &cache_entry)); |
121 EXPECT_TRUE(cache_->GetCacheEntry(resource_id_2, md5_2_cache, &cache_entry)); | 121 EXPECT_TRUE(cache_->GetCacheEntry(resource_id_2, md5_2_cache, &cache_entry)); |
122 } | 122 } |
123 | 123 |
124 } // namespace internal | 124 } // namespace internal |
125 } // namespace drive | 125 } // namespace drive |
OLD | NEW |