Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Side by Side Diff: net/disk_cache/simple/simple_index_file_unittest.cc

Issue 22571011: Remove simple_util::GetMTime from simple cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/hash.h" 7 #include "base/hash.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 for (size_t i = 0; i < kNumHashes; ++i) { 129 for (size_t i = 0; i < kNumHashes; ++i) {
130 SimpleIndex::EntrySet::const_iterator it = new_entries.find(kHashes[i]); 130 SimpleIndex::EntrySet::const_iterator it = new_entries.find(kHashes[i]);
131 EXPECT_TRUE(new_entries.end() != it); 131 EXPECT_TRUE(new_entries.end() != it);
132 EXPECT_TRUE(CompareTwoEntryMetadata(it->second, metadata_entries[i])); 132 EXPECT_TRUE(CompareTwoEntryMetadata(it->second, metadata_entries[i]));
133 } 133 }
134 } 134 }
135 135
136 TEST_F(SimpleIndexFileTest, IsIndexFileStale) { 136 TEST_F(SimpleIndexFileTest, IsIndexFileStale) {
137 base::ScopedTempDir cache_dir; 137 base::ScopedTempDir cache_dir;
138 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); 138 ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
139 base::Time cache_mtime; 139 base::PlatformFileInfo file_info;
140 const base::FilePath cache_path = cache_dir.path(); 140 const base::FilePath cache_path = cache_dir.path();
141 141
142 ASSERT_TRUE(simple_util::GetMTime(cache_path, &cache_mtime)); 142 ASSERT_TRUE(file_util::GetFileInfo(cache_path, &file_info));
143 WrappedSimpleIndexFile simple_index_file(cache_path); 143 WrappedSimpleIndexFile simple_index_file(cache_path);
144 const base::FilePath& index_path = simple_index_file.GetIndexFilePath(); 144 const base::FilePath& index_path = simple_index_file.GetIndexFilePath();
145 EXPECT_TRUE(WrappedSimpleIndexFile::IsIndexFileStale(cache_mtime, 145 EXPECT_TRUE(WrappedSimpleIndexFile::IsIndexFileStale(file_info.last_modified,
146 index_path)); 146 index_path));
147 const std::string kDummyData = "nothing to be seen here"; 147 const std::string kDummyData = "nothing to be seen here";
148 EXPECT_EQ(static_cast<int>(kDummyData.size()), 148 EXPECT_EQ(static_cast<int>(kDummyData.size()),
149 file_util::WriteFile(index_path, 149 file_util::WriteFile(index_path,
150 kDummyData.data(), 150 kDummyData.data(),
151 kDummyData.size())); 151 kDummyData.size()));
152 ASSERT_TRUE(simple_util::GetMTime(cache_path, &cache_mtime)); 152 ASSERT_TRUE(file_util::GetFileInfo(cache_path, &file_info));
153 EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(cache_mtime, 153 EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(file_info.last_modified,
154 index_path)); 154 index_path));
155 155
156 const base::Time past_time = base::Time::Now() - 156 const base::Time past_time = base::Time::Now() -
157 base::TimeDelta::FromSeconds(10); 157 base::TimeDelta::FromSeconds(10);
158 EXPECT_TRUE(file_util::TouchFile(index_path, past_time, past_time)); 158 EXPECT_TRUE(file_util::TouchFile(index_path, past_time, past_time));
159 EXPECT_TRUE(file_util::TouchFile(cache_path, past_time, past_time)); 159 EXPECT_TRUE(file_util::TouchFile(cache_path, past_time, past_time));
160 ASSERT_TRUE(simple_util::GetMTime(cache_path, &cache_mtime)); 160 ASSERT_TRUE(file_util::GetFileInfo(cache_path, &file_info));
161 EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(cache_mtime, 161 EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(file_info.last_modified,
162 index_path)); 162 index_path));
163 const base::Time even_older = 163 const base::Time even_older =
164 past_time - base::TimeDelta::FromSeconds(10); 164 past_time - base::TimeDelta::FromSeconds(10);
165 EXPECT_TRUE(file_util::TouchFile(index_path, even_older, even_older)); 165 EXPECT_TRUE(file_util::TouchFile(index_path, even_older, even_older));
166 EXPECT_TRUE(WrappedSimpleIndexFile::IsIndexFileStale(cache_mtime, 166 EXPECT_TRUE(WrappedSimpleIndexFile::IsIndexFileStale(file_info.last_modified,
167 index_path)); 167 index_path));
168 168
169 } 169 }
170 170
171 TEST_F(SimpleIndexFileTest, WriteThenLoadIndex) { 171 TEST_F(SimpleIndexFileTest, WriteThenLoadIndex) {
172 base::ScopedTempDir cache_dir; 172 base::ScopedTempDir cache_dir;
173 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); 173 ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
174 174
175 SimpleIndex::EntrySet entries; 175 SimpleIndex::EntrySet entries;
176 static const uint64 kHashes[] = { 11, 22, 33 }; 176 static const uint64 kHashes[] = { 11, 22, 33 };
177 static const size_t kNumHashes = arraysize(kHashes); 177 static const size_t kNumHashes = arraysize(kHashes);
178 EntryMetadata metadata_entries[kNumHashes]; 178 EntryMetadata metadata_entries[kNumHashes];
179 for (size_t i = 0; i < kNumHashes; ++i) { 179 for (size_t i = 0; i < kNumHashes; ++i) {
180 uint64 hash = kHashes[i]; 180 uint64 hash = kHashes[i];
181 metadata_entries[i] = EntryMetadata(Time(), hash); 181 metadata_entries[i] = EntryMetadata(Time(), hash);
182 SimpleIndex::InsertInEntrySet(hash, metadata_entries[i], &entries); 182 SimpleIndex::InsertInEntrySet(hash, metadata_entries[i], &entries);
183 } 183 }
184 184
185 const uint64 kCacheSize = 456U; 185 const uint64 kCacheSize = 456U;
186 { 186 {
187 WrappedSimpleIndexFile simple_index_file(cache_dir.path()); 187 WrappedSimpleIndexFile simple_index_file(cache_dir.path());
188 simple_index_file.WriteToDisk(entries, kCacheSize, 188 simple_index_file.WriteToDisk(entries, kCacheSize,
189 base::TimeTicks(), false); 189 base::TimeTicks(), false);
190 base::RunLoop().RunUntilIdle(); 190 base::RunLoop().RunUntilIdle();
191 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath())); 191 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath()));
192 } 192 }
193 193
194 WrappedSimpleIndexFile simple_index_file(cache_dir.path()); 194 WrappedSimpleIndexFile simple_index_file(cache_dir.path());
195 base::Time fake_cache_mtime; 195 base::PlatformFileInfo file_info;
196 ASSERT_TRUE(simple_util::GetMTime(simple_index_file.GetIndexFilePath(), 196 ASSERT_TRUE(file_util::GetFileInfo(simple_index_file.GetIndexFilePath(),
197 &fake_cache_mtime)); 197 &file_info));
198 SimpleIndexLoadResult load_index_result; 198 SimpleIndexLoadResult load_index_result;
199 simple_index_file.LoadIndexEntries(fake_cache_mtime, 199 simple_index_file.LoadIndexEntries(file_info.last_modified,
200 GetCallback(), 200 GetCallback(),
201 &load_index_result); 201 &load_index_result);
202 base::RunLoop().RunUntilIdle(); 202 base::RunLoop().RunUntilIdle();
203 203
204 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath())); 204 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath()));
205 ASSERT_TRUE(callback_called()); 205 ASSERT_TRUE(callback_called());
206 EXPECT_TRUE(load_index_result.did_load); 206 EXPECT_TRUE(load_index_result.did_load);
207 EXPECT_FALSE(load_index_result.flush_required); 207 EXPECT_FALSE(load_index_result.flush_required);
208 208
209 EXPECT_EQ(kNumHashes, load_index_result.entries.size()); 209 EXPECT_EQ(kNumHashes, load_index_result.entries.size());
210 for (size_t i = 0; i < kNumHashes; ++i) 210 for (size_t i = 0; i < kNumHashes; ++i)
211 EXPECT_EQ(1U, load_index_result.entries.count(kHashes[i])); 211 EXPECT_EQ(1U, load_index_result.entries.count(kHashes[i]));
212 } 212 }
213 213
214 TEST_F(SimpleIndexFileTest, LoadCorruptIndex) { 214 TEST_F(SimpleIndexFileTest, LoadCorruptIndex) {
215 base::ScopedTempDir cache_dir; 215 base::ScopedTempDir cache_dir;
216 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); 216 ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
217 217
218 WrappedSimpleIndexFile simple_index_file(cache_dir.path()); 218 WrappedSimpleIndexFile simple_index_file(cache_dir.path());
219 const base::FilePath& index_path = simple_index_file.GetIndexFilePath(); 219 const base::FilePath& index_path = simple_index_file.GetIndexFilePath();
220 const std::string kDummyData = "nothing to be seen here"; 220 const std::string kDummyData = "nothing to be seen here";
221 EXPECT_EQ(static_cast<int>(kDummyData.size()), 221 EXPECT_EQ(static_cast<int>(kDummyData.size()),
222 file_util::WriteFile(index_path, 222 file_util::WriteFile(index_path,
223 kDummyData.data(), 223 kDummyData.data(),
224 kDummyData.size())); 224 kDummyData.size()));
225 base::Time fake_cache_mtime; 225 base::PlatformFileInfo file_info;
226 ASSERT_TRUE(simple_util::GetMTime(simple_index_file.GetIndexFilePath(), 226 ASSERT_TRUE(file_util::GetFileInfo(simple_index_file.GetIndexFilePath(),
227 &fake_cache_mtime)); 227 &file_info));
228 EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(fake_cache_mtime, 228 EXPECT_FALSE(WrappedSimpleIndexFile::IsIndexFileStale(file_info.last_modified,
229 index_path)); 229 index_path));
230 230
231 SimpleIndexLoadResult load_index_result; 231 SimpleIndexLoadResult load_index_result;
232 simple_index_file.LoadIndexEntries(fake_cache_mtime, 232 simple_index_file.LoadIndexEntries(file_info.last_modified,
233 GetCallback(), 233 GetCallback(),
234 &load_index_result); 234 &load_index_result);
235 base::RunLoop().RunUntilIdle(); 235 base::RunLoop().RunUntilIdle();
236 236
237 EXPECT_FALSE(base::PathExists(index_path)); 237 EXPECT_FALSE(base::PathExists(index_path));
238 ASSERT_TRUE(callback_called()); 238 ASSERT_TRUE(callback_called());
239 EXPECT_TRUE(load_index_result.did_load); 239 EXPECT_TRUE(load_index_result.did_load);
240 EXPECT_TRUE(load_index_result.flush_required); 240 EXPECT_TRUE(load_index_result.flush_required);
241 } 241 }
242 242
243 } // namespace disk_cache 243 } // namespace disk_cache
OLDNEW
« no previous file with comments | « net/disk_cache/simple/simple_index_file.cc ('k') | net/disk_cache/simple/simple_synchronous_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698