OLD | NEW |
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/file.h" |
6 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
7 #include "base/hash.h" | 8 #include "base/hash.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
11 #include "base/pickle.h" | 12 #include "base/pickle.h" |
12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 EXPECT_TRUE(load_index_result.flush_required); | 263 EXPECT_TRUE(load_index_result.flush_required); |
263 } | 264 } |
264 | 265 |
265 // Tests that after an upgrade the backend has the index file put in place. | 266 // Tests that after an upgrade the backend has the index file put in place. |
266 TEST_F(SimpleIndexFileTest, SimpleCacheUpgrade) { | 267 TEST_F(SimpleIndexFileTest, SimpleCacheUpgrade) { |
267 base::ScopedTempDir cache_dir; | 268 base::ScopedTempDir cache_dir; |
268 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); | 269 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); |
269 const base::FilePath cache_path = cache_dir.path(); | 270 const base::FilePath cache_path = cache_dir.path(); |
270 | 271 |
271 // Write an old fake index file. | 272 // Write an old fake index file. |
272 base::PlatformFileError error; | 273 base::File file(cache_path.AppendASCII("index"), |
273 base::PlatformFile file = base::CreatePlatformFile( | 274 base::File::FLAG_CREATE | base::File::FLAG_WRITE); |
274 cache_path.AppendASCII("index"), | 275 ASSERT_TRUE(file.IsValid()); |
275 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, | |
276 NULL, | |
277 &error); | |
278 disk_cache::FakeIndexData file_contents; | 276 disk_cache::FakeIndexData file_contents; |
279 file_contents.initial_magic_number = disk_cache::kSimpleInitialMagicNumber; | 277 file_contents.initial_magic_number = disk_cache::kSimpleInitialMagicNumber; |
280 file_contents.version = 5; | 278 file_contents.version = 5; |
281 int bytes_written = base::WritePlatformFile( | 279 int bytes_written = file.Write(0, reinterpret_cast<char*>(&file_contents), |
282 file, 0, reinterpret_cast<char*>(&file_contents), sizeof(file_contents)); | 280 sizeof(file_contents)); |
283 ASSERT_TRUE(base::ClosePlatformFile(file)); | |
284 ASSERT_EQ((int)sizeof(file_contents), bytes_written); | 281 ASSERT_EQ((int)sizeof(file_contents), bytes_written); |
| 282 file.Close(); |
285 | 283 |
286 // Write the index file. The format is incorrect, but for transitioning from | 284 // Write the index file. The format is incorrect, but for transitioning from |
287 // v5 it does not matter. | 285 // v5 it does not matter. |
288 const std::string index_file_contents("incorrectly serialized data"); | 286 const std::string index_file_contents("incorrectly serialized data"); |
289 const base::FilePath old_index_file = | 287 const base::FilePath old_index_file = |
290 cache_path.AppendASCII("the-real-index"); | 288 cache_path.AppendASCII("the-real-index"); |
291 ASSERT_EQ(implicit_cast<int>(index_file_contents.size()), | 289 ASSERT_EQ(implicit_cast<int>(index_file_contents.size()), |
292 file_util::WriteFile(old_index_file, | 290 file_util::WriteFile(old_index_file, |
293 index_file_contents.data(), | 291 index_file_contents.data(), |
294 index_file_contents.size())); | 292 index_file_contents.size())); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 WrappedSimpleIndexFile::Deserialize(contents.data(), | 334 WrappedSimpleIndexFile::Deserialize(contents.data(), |
337 contents.size(), | 335 contents.size(), |
338 &when_index_last_saw_cache, | 336 &when_index_last_saw_cache, |
339 &deserialize_result); | 337 &deserialize_result); |
340 EXPECT_TRUE(deserialize_result.did_load); | 338 EXPECT_TRUE(deserialize_result.did_load); |
341 } | 339 } |
342 | 340 |
343 #endif // defined(OS_POSIX) | 341 #endif // defined(OS_POSIX) |
344 | 342 |
345 } // namespace disk_cache | 343 } // namespace disk_cache |
OLD | NEW |