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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 const std::string& md5) { | 174 const std::string& md5) { |
175 EXPECT_EQ(expected_error_, error); | 175 EXPECT_EQ(expected_error_, error); |
176 | 176 |
177 // Verify cache map. | 177 // Verify cache map. |
178 FileCacheEntry cache_entry; | 178 FileCacheEntry cache_entry; |
179 const bool cache_entry_found = | 179 const bool cache_entry_found = |
180 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); | 180 GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); |
181 if (cache_entry_found) | 181 if (cache_entry_found) |
182 EXPECT_TRUE(cache_entry.is_dirty()); | 182 EXPECT_TRUE(cache_entry.is_dirty()); |
183 | 183 |
184 // If entry doesn't exist, verify that: | 184 // If entry doesn't exist, verify that no files with "<resource_id>.*" |
185 // - no files with "<resource_id>.* exists in persistent and tmp dirs | 185 // exist in persistent and tmp dirs. |
186 // - no "<resource_id>" symlink exists in pinned and outgoing dirs. | |
187 std::vector<PathToVerify> paths_to_verify; | 186 std::vector<PathToVerify> paths_to_verify; |
188 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP. | 187 paths_to_verify.push_back( // Index 0: CACHE_TYPE_TMP. |
189 PathToVerify(cache_->GetCacheFilePath(resource_id, "*", | 188 PathToVerify(cache_->GetCacheFilePath(resource_id, "*", |
190 FileCache::CACHE_TYPE_TMP, | 189 FileCache::CACHE_TYPE_TMP, |
191 FileCache::CACHED_FILE_FROM_SERVER), base::FilePath())); | 190 FileCache::CACHED_FILE_FROM_SERVER), base::FilePath())); |
192 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT. | 191 paths_to_verify.push_back( // Index 1: CACHE_TYPE_PERSISTENT. |
193 PathToVerify(cache_->GetCacheFilePath(resource_id, "*", | 192 PathToVerify(cache_->GetCacheFilePath(resource_id, "*", |
194 FileCache::CACHE_TYPE_PERSISTENT, | 193 FileCache::CACHE_TYPE_PERSISTENT, |
195 FileCache::CACHED_FILE_FROM_SERVER), base::FilePath())); | 194 FileCache::CACHED_FILE_FROM_SERVER), base::FilePath())); |
196 if (!cache_entry_found) { | 195 if (!cache_entry_found) { |
197 for (size_t i = 0; i < paths_to_verify.size(); ++i) { | 196 for (size_t i = 0; i < paths_to_verify.size(); ++i) { |
198 file_util::FileEnumerator enumerator( | 197 file_util::FileEnumerator enumerator( |
199 paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/, | 198 paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/, |
200 file_util::FileEnumerator::FILES | | 199 file_util::FileEnumerator::FILES, |
201 file_util::FileEnumerator::SHOW_SYM_LINKS, | |
202 paths_to_verify[i].path_to_scan.BaseName().value()); | 200 paths_to_verify[i].path_to_scan.BaseName().value()); |
203 EXPECT_TRUE(enumerator.Next().empty()); | 201 EXPECT_TRUE(enumerator.Next().empty()); |
204 } | 202 } |
205 } else { | 203 } else { |
206 // Entry is dirty, verify that: | 204 // Entry is dirty, verify that: |
207 // - no files with "<resource_id>.*" exist in tmp dir | 205 // - no files with "<resource_id>.*" exist in tmp dir |
208 // - only 1 "<resource_id>.local" exists in persistent dir | 206 // - only 1 "<resource_id>.local" exists in persistent dir |
209 // - if entry is pinned, only 1 <resource_id> exists in pinned dir. | 207 // - if entry is pinned, only 1 <resource_id> exists in pinned dir. |
210 | 208 |
211 // Change expected_existing_path of CACHE_TYPE_PERSISTENT (index 1). | 209 // Change expected_existing_path of CACHE_TYPE_PERSISTENT (index 1). |
212 paths_to_verify[1].expected_existing_path = | 210 paths_to_verify[1].expected_existing_path = |
213 GetCacheFilePath(resource_id, | 211 GetCacheFilePath(resource_id, |
214 std::string(), | 212 std::string(), |
215 FileCache::CACHE_TYPE_PERSISTENT, | 213 FileCache::CACHE_TYPE_PERSISTENT, |
216 FileCache::CACHED_FILE_LOCALLY_MODIFIED); | 214 FileCache::CACHED_FILE_LOCALLY_MODIFIED); |
217 | 215 |
218 for (size_t i = 0; i < paths_to_verify.size(); ++i) { | 216 for (size_t i = 0; i < paths_to_verify.size(); ++i) { |
219 const struct PathToVerify& verify = paths_to_verify[i]; | 217 const struct PathToVerify& verify = paths_to_verify[i]; |
220 file_util::FileEnumerator enumerator( | 218 file_util::FileEnumerator enumerator( |
221 verify.path_to_scan.DirName(), false /* not recursive */, | 219 verify.path_to_scan.DirName(), false /* not recursive */, |
222 file_util::FileEnumerator::FILES | | 220 file_util::FileEnumerator::FILES, |
223 file_util::FileEnumerator::SHOW_SYM_LINKS, | |
224 verify.path_to_scan.BaseName().value()); | 221 verify.path_to_scan.BaseName().value()); |
225 size_t num_files_found = 0; | 222 size_t num_files_found = 0; |
226 for (base::FilePath current = enumerator.Next(); !current.empty(); | 223 for (base::FilePath current = enumerator.Next(); !current.empty(); |
227 current = enumerator.Next()) { | 224 current = enumerator.Next()) { |
228 ++num_files_found; | 225 ++num_files_found; |
229 EXPECT_EQ(verify.expected_existing_path, current); | 226 EXPECT_EQ(verify.expected_existing_path, current); |
230 } | 227 } |
231 if (verify.expected_existing_path.empty()) | 228 if (verify.expected_existing_path.empty()) |
232 EXPECT_EQ(0U, num_files_found); | 229 EXPECT_EQ(0U, num_files_found); |
233 else | 230 else |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 test_util::TEST_CACHE_STATE_PERSISTENT, | 991 test_util::TEST_CACHE_STATE_PERSISTENT, |
995 FileCache::CACHE_TYPE_PERSISTENT); | 992 FileCache::CACHE_TYPE_PERSISTENT); |
996 | 993 |
997 // Again, mark the file dirty. Nothing should change. | 994 // Again, mark the file dirty. Nothing should change. |
998 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 995 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
999 test_util::TEST_CACHE_STATE_PRESENT | | 996 test_util::TEST_CACHE_STATE_PRESENT | |
1000 test_util::TEST_CACHE_STATE_DIRTY | | 997 test_util::TEST_CACHE_STATE_DIRTY | |
1001 test_util::TEST_CACHE_STATE_PERSISTENT, | 998 test_util::TEST_CACHE_STATE_PERSISTENT, |
1002 FileCache::CACHE_TYPE_PERSISTENT); | 999 FileCache::CACHE_TYPE_PERSISTENT); |
1003 | 1000 |
1004 // Commit the file dirty. Outgoing symlink should be created. | 1001 // Commit the file dirty. |
1005 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, | 1002 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, |
1006 test_util::TEST_CACHE_STATE_PRESENT | | 1003 test_util::TEST_CACHE_STATE_PRESENT | |
1007 test_util::TEST_CACHE_STATE_DIRTY | | 1004 test_util::TEST_CACHE_STATE_DIRTY | |
1008 test_util::TEST_CACHE_STATE_PERSISTENT, | 1005 test_util::TEST_CACHE_STATE_PERSISTENT, |
1009 FileCache::CACHE_TYPE_PERSISTENT); | 1006 FileCache::CACHE_TYPE_PERSISTENT); |
1010 | 1007 |
1011 // Again, commit the file dirty. Nothing should change. | 1008 // Again, commit the file dirty. Nothing should change. |
1012 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, | 1009 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, |
1013 test_util::TEST_CACHE_STATE_PRESENT | | 1010 test_util::TEST_CACHE_STATE_PRESENT | |
1014 test_util::TEST_CACHE_STATE_DIRTY | | 1011 test_util::TEST_CACHE_STATE_DIRTY | |
1015 test_util::TEST_CACHE_STATE_PERSISTENT, | 1012 test_util::TEST_CACHE_STATE_PERSISTENT, |
1016 FileCache::CACHE_TYPE_PERSISTENT); | 1013 FileCache::CACHE_TYPE_PERSISTENT); |
1017 | 1014 |
1018 // Mark the file dirty again after it's being committed. Outgoing symlink | 1015 // Mark the file dirty again after it's being committed. |
1019 // should be deleted. | |
1020 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, | 1016 TestMarkDirty(resource_id, md5, FILE_ERROR_OK, |
1021 test_util::TEST_CACHE_STATE_PRESENT | | 1017 test_util::TEST_CACHE_STATE_PRESENT | |
1022 test_util::TEST_CACHE_STATE_DIRTY | | 1018 test_util::TEST_CACHE_STATE_DIRTY | |
1023 test_util::TEST_CACHE_STATE_PERSISTENT, | 1019 test_util::TEST_CACHE_STATE_PERSISTENT, |
1024 FileCache::CACHE_TYPE_PERSISTENT); | 1020 FileCache::CACHE_TYPE_PERSISTENT); |
1025 | 1021 |
1026 // Commit the file dirty. Outgoing symlink should be created again. | 1022 // Commit the file dirty. |
1027 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, | 1023 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, |
1028 test_util::TEST_CACHE_STATE_PRESENT | | 1024 test_util::TEST_CACHE_STATE_PRESENT | |
1029 test_util::TEST_CACHE_STATE_DIRTY | | 1025 test_util::TEST_CACHE_STATE_DIRTY | |
1030 test_util::TEST_CACHE_STATE_PERSISTENT, | 1026 test_util::TEST_CACHE_STATE_PERSISTENT, |
1031 FileCache::CACHE_TYPE_PERSISTENT); | 1027 FileCache::CACHE_TYPE_PERSISTENT); |
1032 | 1028 |
1033 // Clear dirty state of the file. | 1029 // Clear dirty state of the file. |
1034 TestClearDirty(resource_id, md5, FILE_ERROR_OK, | 1030 TestClearDirty(resource_id, md5, FILE_ERROR_OK, |
1035 test_util::TEST_CACHE_STATE_PRESENT, | 1031 test_util::TEST_CACHE_STATE_PRESENT, |
1036 FileCache::CACHE_TYPE_TMP); | 1032 FileCache::CACHE_TYPE_TMP); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 test_util::TEST_CACHE_STATE_DIRTY | | 1111 test_util::TEST_CACHE_STATE_DIRTY | |
1116 test_util::TEST_CACHE_STATE_PERSISTENT, | 1112 test_util::TEST_CACHE_STATE_PERSISTENT, |
1117 FileCache::CACHE_TYPE_PERSISTENT); | 1113 FileCache::CACHE_TYPE_PERSISTENT); |
1118 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, | 1114 TestCommitDirty(resource_id, md5, FILE_ERROR_OK, |
1119 test_util::TEST_CACHE_STATE_PRESENT | | 1115 test_util::TEST_CACHE_STATE_PRESENT | |
1120 test_util::TEST_CACHE_STATE_PINNED | | 1116 test_util::TEST_CACHE_STATE_PINNED | |
1121 test_util::TEST_CACHE_STATE_DIRTY | | 1117 test_util::TEST_CACHE_STATE_DIRTY | |
1122 test_util::TEST_CACHE_STATE_PERSISTENT, | 1118 test_util::TEST_CACHE_STATE_PERSISTENT, |
1123 FileCache::CACHE_TYPE_PERSISTENT); | 1119 FileCache::CACHE_TYPE_PERSISTENT); |
1124 | 1120 |
1125 // Try to remove the file. Since file is dirty, it and the corresponding | 1121 // Try to remove the file. Since file is dirty, it should not be removed. |
1126 // pinned and outgoing symlinks should not be removed. | |
1127 TestRemoveFromCache(resource_id, FILE_ERROR_OK); | 1122 TestRemoveFromCache(resource_id, FILE_ERROR_OK); |
1128 } | 1123 } |
1129 | 1124 |
1130 TEST_F(FileCacheTest, MountUnmount) { | 1125 TEST_F(FileCacheTest, MountUnmount) { |
1131 fake_free_disk_space_getter_->set_fake_free_disk_space( | 1126 fake_free_disk_space_getter_->set_fake_free_disk_space( |
1132 test_util::kLotsOfSpace); | 1127 test_util::kLotsOfSpace); |
1133 | 1128 |
1134 std::string resource_id("pdf:1a2b"); | 1129 std::string resource_id("pdf:1a2b"); |
1135 std::string md5("abcdef0123456789"); | 1130 std::string md5("abcdef0123456789"); |
1136 | 1131 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 google_apis::test_util::GetTestFilePath("chromeos/gdata/empty_feed.json"), | 1311 google_apis::test_util::GetTestFilePath("chromeos/gdata/empty_feed.json"), |
1317 FILE_ERROR_OK, | 1312 FILE_ERROR_OK, |
1318 test_util::TEST_CACHE_STATE_PRESENT | | 1313 test_util::TEST_CACHE_STATE_PRESENT | |
1319 test_util::TEST_CACHE_STATE_PINNED | | 1314 test_util::TEST_CACHE_STATE_PINNED | |
1320 test_util::TEST_CACHE_STATE_PERSISTENT, | 1315 test_util::TEST_CACHE_STATE_PERSISTENT, |
1321 FileCache::CACHE_TYPE_PERSISTENT); | 1316 FileCache::CACHE_TYPE_PERSISTENT); |
1322 } | 1317 } |
1323 | 1318 |
1324 } // namespace internal | 1319 } // namespace internal |
1325 } // namespace drive | 1320 } // namespace drive |
OLD | NEW |