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

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

Issue 1340683002: Remove base's implicit_cast. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: implicitcast: numericstest Created 5 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
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/files/file.h" 5 #include "base/files/file.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/hash.h" 8 #include "base/hash.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 214 }
215 215
216 TEST_F(SimpleIndexFileTest, LoadCorruptIndex) { 216 TEST_F(SimpleIndexFileTest, LoadCorruptIndex) {
217 base::ScopedTempDir cache_dir; 217 base::ScopedTempDir cache_dir;
218 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); 218 ASSERT_TRUE(cache_dir.CreateUniqueTempDir());
219 219
220 WrappedSimpleIndexFile simple_index_file(cache_dir.path()); 220 WrappedSimpleIndexFile simple_index_file(cache_dir.path());
221 ASSERT_TRUE(simple_index_file.CreateIndexFileDirectory()); 221 ASSERT_TRUE(simple_index_file.CreateIndexFileDirectory());
222 const base::FilePath& index_path = simple_index_file.GetIndexFilePath(); 222 const base::FilePath& index_path = simple_index_file.GetIndexFilePath();
223 const std::string kDummyData = "nothing to be seen here"; 223 const std::string kDummyData = "nothing to be seen here";
224 EXPECT_EQ( 224 EXPECT_EQ(static_cast<int>(kDummyData.size()),
225 implicit_cast<int>(kDummyData.size()), 225 base::WriteFile(index_path, kDummyData.data(), kDummyData.size()));
226 base::WriteFile(index_path, kDummyData.data(), kDummyData.size()));
227 base::Time fake_cache_mtime; 226 base::Time fake_cache_mtime;
228 ASSERT_TRUE(simple_util::GetMTime(simple_index_file.GetIndexFilePath(), 227 ASSERT_TRUE(simple_util::GetMTime(simple_index_file.GetIndexFilePath(),
229 &fake_cache_mtime)); 228 &fake_cache_mtime));
230 EXPECT_FALSE(WrappedSimpleIndexFile::LegacyIsIndexFileStale(fake_cache_mtime, 229 EXPECT_FALSE(WrappedSimpleIndexFile::LegacyIsIndexFileStale(fake_cache_mtime,
231 index_path)); 230 index_path));
232 SimpleIndexLoadResult load_index_result; 231 SimpleIndexLoadResult load_index_result;
233 net::TestClosure closure; 232 net::TestClosure closure;
234 simple_index_file.LoadIndexEntries(fake_cache_mtime, closure.closure(), 233 simple_index_file.LoadIndexEntries(fake_cache_mtime, closure.closure(),
235 &load_index_result); 234 &load_index_result);
236 closure.WaitForResult(); 235 closure.WaitForResult();
(...skipping 19 matching lines...) Expand all
256 int bytes_written = file.Write(0, reinterpret_cast<char*>(&file_contents), 255 int bytes_written = file.Write(0, reinterpret_cast<char*>(&file_contents),
257 sizeof(file_contents)); 256 sizeof(file_contents));
258 ASSERT_EQ((int)sizeof(file_contents), bytes_written); 257 ASSERT_EQ((int)sizeof(file_contents), bytes_written);
259 file.Close(); 258 file.Close();
260 259
261 // Write the index file. The format is incorrect, but for transitioning from 260 // Write the index file. The format is incorrect, but for transitioning from
262 // v5 it does not matter. 261 // v5 it does not matter.
263 const std::string index_file_contents("incorrectly serialized data"); 262 const std::string index_file_contents("incorrectly serialized data");
264 const base::FilePath old_index_file = 263 const base::FilePath old_index_file =
265 cache_path.AppendASCII("the-real-index"); 264 cache_path.AppendASCII("the-real-index");
266 ASSERT_EQ(implicit_cast<int>(index_file_contents.size()), 265 ASSERT_EQ(static_cast<int>(index_file_contents.size()),
267 base::WriteFile(old_index_file, 266 base::WriteFile(old_index_file, index_file_contents.data(),
268 index_file_contents.data(),
269 index_file_contents.size())); 267 index_file_contents.size()));
270 268
271 // Upgrade the cache. 269 // Upgrade the cache.
272 ASSERT_TRUE(disk_cache::UpgradeSimpleCacheOnDisk(cache_path)); 270 ASSERT_TRUE(disk_cache::UpgradeSimpleCacheOnDisk(cache_path));
273 271
274 // Create the backend and initiate index flush by destroying the backend. 272 // Create the backend and initiate index flush by destroying the backend.
275 base::Thread cache_thread("CacheThread"); 273 base::Thread cache_thread("CacheThread");
276 ASSERT_TRUE(cache_thread.StartWithOptions( 274 ASSERT_TRUE(cache_thread.StartWithOptions(
277 base::Thread::Options(base::MessageLoop::TYPE_IO, 0))); 275 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
278 disk_cache::SimpleBackendImpl* simple_cache = 276 disk_cache::SimpleBackendImpl* simple_cache =
(...skipping 29 matching lines...) Expand all
308 WrappedSimpleIndexFile::Deserialize(contents.data(), 306 WrappedSimpleIndexFile::Deserialize(contents.data(),
309 contents.size(), 307 contents.size(),
310 &when_index_last_saw_cache, 308 &when_index_last_saw_cache,
311 &deserialize_result); 309 &deserialize_result);
312 EXPECT_TRUE(deserialize_result.did_load); 310 EXPECT_TRUE(deserialize_result.did_load);
313 } 311 }
314 312
315 #endif // defined(OS_POSIX) 313 #endif // defined(OS_POSIX)
316 314
317 } // namespace disk_cache 315 } // 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