| 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/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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 EXPECT_TRUE(base::TouchFile(cache_path, past_time, past_time)); | 181 EXPECT_TRUE(base::TouchFile(cache_path, past_time, past_time)); |
| 182 ASSERT_TRUE(simple_util::GetMTime(cache_path, &cache_mtime)); | 182 ASSERT_TRUE(simple_util::GetMTime(cache_path, &cache_mtime)); |
| 183 EXPECT_FALSE( | 183 EXPECT_FALSE( |
| 184 WrappedSimpleIndexFile::LegacyIsIndexFileStale(cache_mtime, index_path)); | 184 WrappedSimpleIndexFile::LegacyIsIndexFileStale(cache_mtime, index_path)); |
| 185 const base::Time even_older = past_time - base::TimeDelta::FromSeconds(10); | 185 const base::Time even_older = past_time - base::TimeDelta::FromSeconds(10); |
| 186 EXPECT_TRUE(base::TouchFile(index_path, even_older, even_older)); | 186 EXPECT_TRUE(base::TouchFile(index_path, even_older, even_older)); |
| 187 EXPECT_TRUE( | 187 EXPECT_TRUE( |
| 188 WrappedSimpleIndexFile::LegacyIsIndexFileStale(cache_mtime, index_path)); | 188 WrappedSimpleIndexFile::LegacyIsIndexFileStale(cache_mtime, index_path)); |
| 189 } | 189 } |
| 190 | 190 |
| 191 // This test is flaky, see http://crbug.com/255775. | 191 TEST_F(SimpleIndexFileTest, WriteThenLoadIndex) { |
| 192 TEST_F(SimpleIndexFileTest, DISABLED_WriteThenLoadIndex) { | |
| 193 base::ScopedTempDir cache_dir; | 192 base::ScopedTempDir cache_dir; |
| 194 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); | 193 ASSERT_TRUE(cache_dir.CreateUniqueTempDir()); |
| 195 | 194 |
| 196 SimpleIndex::EntrySet entries; | 195 SimpleIndex::EntrySet entries; |
| 197 static const uint64 kHashes[] = { 11, 22, 33 }; | 196 static const uint64 kHashes[] = { 11, 22, 33 }; |
| 198 static const size_t kNumHashes = arraysize(kHashes); | 197 static const size_t kNumHashes = arraysize(kHashes); |
| 199 EntryMetadata metadata_entries[kNumHashes]; | 198 EntryMetadata metadata_entries[kNumHashes]; |
| 200 for (size_t i = 0; i < kNumHashes; ++i) { | 199 for (size_t i = 0; i < kNumHashes; ++i) { |
| 201 uint64 hash = kHashes[i]; | 200 uint64 hash = kHashes[i]; |
| 202 metadata_entries[i] = EntryMetadata(Time(), hash); | 201 metadata_entries[i] = EntryMetadata(Time(), hash); |
| 203 SimpleIndex::InsertInEntrySet(hash, metadata_entries[i], &entries); | 202 SimpleIndex::InsertInEntrySet(hash, metadata_entries[i], &entries); |
| 204 } | 203 } |
| 205 | 204 |
| 206 const uint64 kCacheSize = 456U; | 205 const uint64 kCacheSize = 456U; |
| 207 { | 206 { |
| 208 WrappedSimpleIndexFile simple_index_file(cache_dir.path()); | 207 WrappedSimpleIndexFile simple_index_file(cache_dir.path()); |
| 209 simple_index_file.WriteToDisk(entries, kCacheSize, | 208 simple_index_file.WriteToDisk(entries, kCacheSize, |
| 210 base::TimeTicks(), false); | 209 base::TimeTicks(), false); |
| 211 base::RunLoop().RunUntilIdle(); | 210 base::RunLoop().RunUntilIdle(); |
| 212 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath())); | 211 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath())); |
| 213 } | 212 } |
| 214 | 213 |
| 215 WrappedSimpleIndexFile simple_index_file(cache_dir.path()); | 214 WrappedSimpleIndexFile simple_index_file(cache_dir.path()); |
| 216 base::Time fake_cache_mtime; | 215 base::Time fake_cache_mtime; |
| 217 ASSERT_TRUE(simple_util::GetMTime(simple_index_file.GetIndexFilePath(), | 216 ASSERT_TRUE(simple_util::GetMTime(cache_dir.path(), &fake_cache_mtime)); |
| 218 &fake_cache_mtime)); | |
| 219 SimpleIndexLoadResult load_index_result; | 217 SimpleIndexLoadResult load_index_result; |
| 220 simple_index_file.LoadIndexEntries(fake_cache_mtime, | 218 simple_index_file.LoadIndexEntries(fake_cache_mtime, |
| 221 GetCallback(), | 219 GetCallback(), |
| 222 &load_index_result); | 220 &load_index_result); |
| 223 base::RunLoop().RunUntilIdle(); | 221 base::RunLoop().RunUntilIdle(); |
| 224 | 222 |
| 225 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath())); | 223 EXPECT_TRUE(base::PathExists(simple_index_file.GetIndexFilePath())); |
| 226 ASSERT_TRUE(callback_called()); | 224 ASSERT_TRUE(callback_called()); |
| 227 EXPECT_TRUE(load_index_result.did_load); | 225 EXPECT_TRUE(load_index_result.did_load); |
| 228 EXPECT_FALSE(load_index_result.flush_required); | 226 EXPECT_FALSE(load_index_result.flush_required); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 WrappedSimpleIndexFile::Deserialize(contents.data(), | 330 WrappedSimpleIndexFile::Deserialize(contents.data(), |
| 333 contents.size(), | 331 contents.size(), |
| 334 &when_index_last_saw_cache, | 332 &when_index_last_saw_cache, |
| 335 &deserialize_result); | 333 &deserialize_result); |
| 336 EXPECT_TRUE(deserialize_result.did_load); | 334 EXPECT_TRUE(deserialize_result.did_load); |
| 337 } | 335 } |
| 338 | 336 |
| 339 #endif // defined(OS_POSIX) | 337 #endif // defined(OS_POSIX) |
| 340 | 338 |
| 341 } // namespace disk_cache | 339 } // namespace disk_cache |
| OLD | NEW |