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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 std::string local_id("pdf:1a2b3c"); | 62 std::string local_id("pdf:1a2b3c"); |
63 std::string md5("abcdef0123456789"); | 63 std::string md5("abcdef0123456789"); |
64 | 64 |
65 // Create a stale cache file. | 65 // Create a stale cache file. |
66 EXPECT_EQ(FILE_ERROR_OK, | 66 EXPECT_EQ(FILE_ERROR_OK, |
67 cache_->Store(local_id, md5, dummy_file, | 67 cache_->Store(local_id, md5, dummy_file, |
68 FileCache::FILE_OPERATION_COPY)); | 68 FileCache::FILE_OPERATION_COPY)); |
69 | 69 |
70 // Verify that the cache entry exists. | 70 // Verify that the cache entry exists. |
71 FileCacheEntry cache_entry; | 71 FileCacheEntry cache_entry; |
72 EXPECT_TRUE(cache_->GetCacheEntry(local_id, &cache_entry)); | 72 EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(local_id, &cache_entry)); |
73 | 73 |
74 ResourceEntry entry; | 74 ResourceEntry entry; |
75 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 75 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
76 resource_metadata_->GetResourceEntryById(local_id, &entry)); | 76 resource_metadata_->GetResourceEntryById(local_id, &entry)); |
77 | 77 |
78 // Remove stale cache files. | 78 // Remove stale cache files. |
79 RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get()); | 79 RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get()); |
80 | 80 |
81 // Verify that the cache entry is deleted. | 81 // Verify that the cache entry is deleted. |
82 EXPECT_FALSE(cache_->GetCacheEntry(local_id, &cache_entry)); | 82 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
| 83 cache_->GetCacheEntry(local_id, &cache_entry)); |
83 } | 84 } |
84 | 85 |
85 TEST_F(RemoveStaleCacheFilesTest, DirtyCacheFiles) { | 86 TEST_F(RemoveStaleCacheFilesTest, DirtyCacheFiles) { |
86 base::FilePath dummy_file; | 87 base::FilePath dummy_file; |
87 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_file)); | 88 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &dummy_file)); |
88 | 89 |
89 // Dirty and deleted (= absent in resource_metada) cache entry. | 90 // Dirty and deleted (= absent in resource_metada) cache entry. |
90 std::string local_id_1("file:1"); | 91 std::string local_id_1("file:1"); |
91 EXPECT_EQ(FILE_ERROR_OK, | 92 EXPECT_EQ(FILE_ERROR_OK, |
92 cache_->Store(local_id_1, std::string(), dummy_file, | 93 cache_->Store(local_id_1, std::string(), dummy_file, |
(...skipping 14 matching lines...) Expand all Loading... |
107 EXPECT_EQ(FILE_ERROR_OK, | 108 EXPECT_EQ(FILE_ERROR_OK, |
108 cache_->Store(local_id_2, std::string(), dummy_file, | 109 cache_->Store(local_id_2, std::string(), dummy_file, |
109 FileCache::FILE_OPERATION_COPY)); | 110 FileCache::FILE_OPERATION_COPY)); |
110 | 111 |
111 // Remove stale cache files. | 112 // Remove stale cache files. |
112 RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get()); | 113 RemoveStaleCacheFiles(cache_.get(), resource_metadata_.get()); |
113 | 114 |
114 // Dirty cache should be removed if and only if the entry does not exist in | 115 // Dirty cache should be removed if and only if the entry does not exist in |
115 // resource_metadata. | 116 // resource_metadata. |
116 FileCacheEntry cache_entry; | 117 FileCacheEntry cache_entry; |
117 EXPECT_FALSE(cache_->GetCacheEntry(local_id_1, &cache_entry)); | 118 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
118 EXPECT_TRUE(cache_->GetCacheEntry(local_id_2, &cache_entry)); | 119 cache_->GetCacheEntry(local_id_1, &cache_entry)); |
| 120 EXPECT_EQ(FILE_ERROR_OK, cache_->GetCacheEntry(local_id_2, &cache_entry)); |
119 } | 121 } |
120 | 122 |
121 } // namespace internal | 123 } // namespace internal |
122 } // namespace drive | 124 } // namespace drive |
OLD | NEW |