| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <functional> | 6 #include <functional> |
| 7 | 7 |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/hash.h" | 9 #include "base/hash.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 namespace disk_cache { | 26 namespace disk_cache { |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 const base::Time kTestLastUsedTime = | 29 const base::Time kTestLastUsedTime = |
| 30 base::Time::UnixEpoch() + base::TimeDelta::FromDays(20); | 30 base::Time::UnixEpoch() + base::TimeDelta::FromDays(20); |
| 31 const int kTestEntrySize = 789; | 31 const int kTestEntrySize = 789; |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 | 35 class EntryMetadataTest : public testing::Test { |
| 36 class EntryMetadataTest : public testing::Test { | |
| 37 public: | 36 public: |
| 38 EntryMetadata NewEntryMetadataWithValues() { | 37 EntryMetadata NewEntryMetadataWithValues() { |
| 39 return EntryMetadata(kTestLastUsedTime, kTestEntrySize); | 38 return EntryMetadata(kTestLastUsedTime, kTestEntrySize); |
| 40 } | 39 } |
| 41 | 40 |
| 42 void CheckEntryMetadataValues(const EntryMetadata& entry_metadata) { | 41 void CheckEntryMetadataValues(const EntryMetadata& entry_metadata) { |
| 43 EXPECT_LT(kTestLastUsedTime - base::TimeDelta::FromSeconds(2), | 42 EXPECT_LT(kTestLastUsedTime - base::TimeDelta::FromSeconds(2), |
| 44 entry_metadata.GetLastUsedTime()); | 43 entry_metadata.GetLastUsedTime()); |
| 45 EXPECT_GT(kTestLastUsedTime + base::TimeDelta::FromSeconds(2), | 44 EXPECT_GT(kTestLastUsedTime + base::TimeDelta::FromSeconds(2), |
| 46 entry_metadata.GetLastUsedTime()); | 45 entry_metadata.GetLastUsedTime()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 int disk_writes() const { return disk_writes_; } | 83 int disk_writes() const { return disk_writes_; } |
| 85 | 84 |
| 86 private: | 85 private: |
| 87 base::Closure load_callback_; | 86 base::Closure load_callback_; |
| 88 SimpleIndexLoadResult* load_result_; | 87 SimpleIndexLoadResult* load_result_; |
| 89 int load_index_entries_calls_; | 88 int load_index_entries_calls_; |
| 90 int disk_writes_; | 89 int disk_writes_; |
| 91 SimpleIndex::EntrySet disk_write_entry_set_; | 90 SimpleIndex::EntrySet disk_write_entry_set_; |
| 92 }; | 91 }; |
| 93 | 92 |
| 94 class SimpleIndexTest : public testing::Test, public SimpleIndexDelegate { | 93 class SimpleIndexTest : public testing::Test, public SimpleIndexDelegate { |
| 95 protected: | 94 protected: |
| 96 SimpleIndexTest() | 95 SimpleIndexTest() |
| 97 : hashes_(base::Bind(&HashesInitializer)), | 96 : hashes_(base::Bind(&HashesInitializer)), doom_entries_calls_(0) {} |
| 98 doom_entries_calls_(0) {} | |
| 99 | 97 |
| 100 static uint64 HashesInitializer(size_t hash_index) { | 98 static uint64 HashesInitializer(size_t hash_index) { |
| 101 return disk_cache::simple_util::GetEntryHashKey( | 99 return disk_cache::simple_util::GetEntryHashKey( |
| 102 base::StringPrintf("key%d", static_cast<int>(hash_index))); | 100 base::StringPrintf("key%d", static_cast<int>(hash_index))); |
| 103 } | 101 } |
| 104 | 102 |
| 105 virtual void SetUp() OVERRIDE { | 103 virtual void SetUp() OVERRIDE { |
| 106 scoped_ptr<MockSimpleIndexFile> index_file(new MockSimpleIndexFile()); | 104 scoped_ptr<MockSimpleIndexFile> index_file(new MockSimpleIndexFile()); |
| 107 index_file_ = index_file->AsWeakPtr(); | 105 index_file_ = index_file->AsWeakPtr(); |
| 108 index_.reset(new SimpleIndex(NULL, this, net::DISK_CACHE, | 106 index_.reset(new SimpleIndex( |
| 109 index_file.PassAs<SimpleIndexFile>())); | 107 NULL, this, net::DISK_CACHE, index_file.PassAs<SimpleIndexFile>())); |
| 110 | 108 |
| 111 index_->Initialize(base::Time()); | 109 index_->Initialize(base::Time()); |
| 112 } | 110 } |
| 113 | 111 |
| 114 void WaitForTimeChange() { | 112 void WaitForTimeChange() { |
| 115 const base::Time initial_time = base::Time::Now(); | 113 const base::Time initial_time = base::Time::Now(); |
| 116 do { | 114 do { |
| 117 base::PlatformThread::YieldCurrentThread(); | 115 base::PlatformThread::YieldCurrentThread(); |
| 118 } while (base::Time::Now() - | 116 } while (base::Time::Now() - initial_time < |
| 119 initial_time < base::TimeDelta::FromSeconds(1)); | 117 base::TimeDelta::FromSeconds(1)); |
| 120 } | 118 } |
| 121 | 119 |
| 122 // From SimpleIndexDelegate: | 120 // From SimpleIndexDelegate: |
| 123 virtual void DoomEntries(std::vector<uint64>* entry_hashes, | 121 virtual void DoomEntries(std::vector<uint64>* entry_hashes, |
| 124 const net::CompletionCallback& callback) OVERRIDE { | 122 const net::CompletionCallback& callback) OVERRIDE { |
| 125 std::for_each(entry_hashes->begin(), entry_hashes->end(), | 123 std::for_each( |
| 126 std::bind1st(std::mem_fun(&SimpleIndex::Remove), | 124 entry_hashes->begin(), |
| 127 index_.get())); | 125 entry_hashes->end(), |
| 126 std::bind1st(std::mem_fun(&SimpleIndex::Remove), index_.get())); |
| 128 last_doom_entry_hashes_ = *entry_hashes; | 127 last_doom_entry_hashes_ = *entry_hashes; |
| 129 ++doom_entries_calls_; | 128 ++doom_entries_calls_; |
| 130 } | 129 } |
| 131 | 130 |
| 132 // Redirect to allow single "friend" declaration in base class. | 131 // Redirect to allow single "friend" declaration in base class. |
| 133 bool GetEntryForTesting(uint64 key, EntryMetadata* metadata) { | 132 bool GetEntryForTesting(uint64 key, EntryMetadata* metadata) { |
| 134 SimpleIndex::EntrySet::iterator it = index_->entries_set_.find(key); | 133 SimpleIndex::EntrySet::iterator it = index_->entries_set_.find(key); |
| 135 if (index_->entries_set_.end() == it) | 134 if (index_->entries_set_.end() == it) |
| 136 return false; | 135 return false; |
| 137 *metadata = it->second; | 136 *metadata = it->second; |
| 138 return true; | 137 return true; |
| 139 } | 138 } |
| 140 | 139 |
| 141 void InsertIntoIndexFileReturn(uint64 hash_key, | 140 void InsertIntoIndexFileReturn(uint64 hash_key, |
| 142 base::Time last_used_time, | 141 base::Time last_used_time, |
| 143 int entry_size) { | 142 int entry_size) { |
| 144 index_file_->load_result()->entries.insert(std::make_pair( | 143 index_file_->load_result()->entries.insert( |
| 145 hash_key, EntryMetadata(last_used_time, entry_size))); | 144 std::make_pair(hash_key, EntryMetadata(last_used_time, entry_size))); |
| 146 } | 145 } |
| 147 | 146 |
| 148 void ReturnIndexFile() { | 147 void ReturnIndexFile() { |
| 149 index_file_->load_result()->did_load = true; | 148 index_file_->load_result()->did_load = true; |
| 150 index_file_->load_callback().Run(); | 149 index_file_->load_callback().Run(); |
| 151 } | 150 } |
| 152 | 151 |
| 153 // Non-const for timer manipulation. | 152 // Non-const for timer manipulation. |
| 154 SimpleIndex* index() { return index_.get(); } | 153 SimpleIndex* index() { return index_.get(); } |
| 155 const MockSimpleIndexFile* index_file() const { return index_file_.get(); } | 154 const MockSimpleIndexFile* index_file() const { return index_file_.get(); } |
| 156 | 155 |
| 157 const std::vector<uint64>& last_doom_entry_hashes() const { | 156 const std::vector<uint64>& last_doom_entry_hashes() const { |
| 158 return last_doom_entry_hashes_; | 157 return last_doom_entry_hashes_; |
| 159 } | 158 } |
| 160 int doom_entries_calls() const { return doom_entries_calls_; } | 159 int doom_entries_calls() const { return doom_entries_calls_; } |
| 161 | 160 |
| 162 | |
| 163 const simple_util::ImmutableArray<uint64, 16> hashes_; | 161 const simple_util::ImmutableArray<uint64, 16> hashes_; |
| 164 scoped_ptr<SimpleIndex> index_; | 162 scoped_ptr<SimpleIndex> index_; |
| 165 base::WeakPtr<MockSimpleIndexFile> index_file_; | 163 base::WeakPtr<MockSimpleIndexFile> index_file_; |
| 166 | 164 |
| 167 std::vector<uint64> last_doom_entry_hashes_; | 165 std::vector<uint64> last_doom_entry_hashes_; |
| 168 int doom_entries_calls_; | 166 int doom_entries_calls_; |
| 169 }; | 167 }; |
| 170 | 168 |
| 171 TEST_F(EntryMetadataTest, Basics) { | 169 TEST_F(EntryMetadataTest, Basics) { |
| 172 EntryMetadata entry_metadata; | 170 EntryMetadata entry_metadata; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 index()->Remove(hashes_.at<1>()); | 357 index()->Remove(hashes_.at<1>()); |
| 360 EXPECT_EQ(1, index()->GetEntryCount()); | 358 EXPECT_EQ(1, index()->GetEntryCount()); |
| 361 index()->Remove(hashes_.at<4>()); | 359 index()->Remove(hashes_.at<4>()); |
| 362 EXPECT_EQ(0, index()->GetEntryCount()); | 360 EXPECT_EQ(0, index()->GetEntryCount()); |
| 363 } | 361 } |
| 364 | 362 |
| 365 // Confirm that we get the results we expect from a simple init. | 363 // Confirm that we get the results we expect from a simple init. |
| 366 TEST_F(SimpleIndexTest, BasicInit) { | 364 TEST_F(SimpleIndexTest, BasicInit) { |
| 367 base::Time now(base::Time::Now()); | 365 base::Time now(base::Time::Now()); |
| 368 | 366 |
| 369 InsertIntoIndexFileReturn(hashes_.at<1>(), | 367 InsertIntoIndexFileReturn( |
| 370 now - base::TimeDelta::FromDays(2), | 368 hashes_.at<1>(), now - base::TimeDelta::FromDays(2), 10u); |
| 371 10u); | 369 InsertIntoIndexFileReturn( |
| 372 InsertIntoIndexFileReturn(hashes_.at<2>(), | 370 hashes_.at<2>(), now - base::TimeDelta::FromDays(3), 100u); |
| 373 now - base::TimeDelta::FromDays(3), | |
| 374 100u); | |
| 375 | 371 |
| 376 ReturnIndexFile(); | 372 ReturnIndexFile(); |
| 377 | 373 |
| 378 EntryMetadata metadata; | 374 EntryMetadata metadata; |
| 379 EXPECT_TRUE(GetEntryForTesting(hashes_.at<1>(), &metadata)); | 375 EXPECT_TRUE(GetEntryForTesting(hashes_.at<1>(), &metadata)); |
| 380 EXPECT_LT( | 376 EXPECT_LT( |
| 381 now - base::TimeDelta::FromDays(2) - base::TimeDelta::FromSeconds(1), | 377 now - base::TimeDelta::FromDays(2) - base::TimeDelta::FromSeconds(1), |
| 382 metadata.GetLastUsedTime()); | 378 metadata.GetLastUsedTime()); |
| 383 EXPECT_GT( | 379 EXPECT_GT( |
| 384 now - base::TimeDelta::FromDays(2) + base::TimeDelta::FromSeconds(1), | 380 now - base::TimeDelta::FromDays(2) + base::TimeDelta::FromSeconds(1), |
| 385 metadata.GetLastUsedTime()); | 381 metadata.GetLastUsedTime()); |
| 386 EXPECT_EQ(10, metadata.GetEntrySize()); | 382 EXPECT_EQ(10, metadata.GetEntrySize()); |
| 387 EXPECT_TRUE(GetEntryForTesting(hashes_.at<2>(), &metadata)); | 383 EXPECT_TRUE(GetEntryForTesting(hashes_.at<2>(), &metadata)); |
| 388 EXPECT_LT( | 384 EXPECT_LT( |
| 389 now - base::TimeDelta::FromDays(3) - base::TimeDelta::FromSeconds(1), | 385 now - base::TimeDelta::FromDays(3) - base::TimeDelta::FromSeconds(1), |
| 390 metadata.GetLastUsedTime()); | 386 metadata.GetLastUsedTime()); |
| 391 EXPECT_GT( | 387 EXPECT_GT( |
| 392 now - base::TimeDelta::FromDays(3) + base::TimeDelta::FromSeconds(1), | 388 now - base::TimeDelta::FromDays(3) + base::TimeDelta::FromSeconds(1), |
| 393 metadata.GetLastUsedTime()); | 389 metadata.GetLastUsedTime()); |
| 394 EXPECT_EQ(100, metadata.GetEntrySize()); | 390 EXPECT_EQ(100, metadata.GetEntrySize()); |
| 395 } | 391 } |
| 396 | 392 |
| 397 // Remove something that's going to come in from the loaded index. | 393 // Remove something that's going to come in from the loaded index. |
| 398 TEST_F(SimpleIndexTest, RemoveBeforeInit) { | 394 TEST_F(SimpleIndexTest, RemoveBeforeInit) { |
| 399 const uint64 kHash1 = hashes_.at<1>(); | 395 const uint64 kHash1 = hashes_.at<1>(); |
| 400 index()->Remove(kHash1); | 396 index()->Remove(kHash1); |
| 401 | 397 |
| 402 InsertIntoIndexFileReturn(kHash1, | 398 InsertIntoIndexFileReturn( |
| 403 base::Time::Now() - base::TimeDelta::FromDays(2), | 399 kHash1, base::Time::Now() - base::TimeDelta::FromDays(2), 10u); |
| 404 10u); | |
| 405 ReturnIndexFile(); | 400 ReturnIndexFile(); |
| 406 | 401 |
| 407 EXPECT_FALSE(index()->Has(kHash1)); | 402 EXPECT_FALSE(index()->Has(kHash1)); |
| 408 } | 403 } |
| 409 | 404 |
| 410 // Insert something that's going to come in from the loaded index; correct | 405 // Insert something that's going to come in from the loaded index; correct |
| 411 // result? | 406 // result? |
| 412 TEST_F(SimpleIndexTest, InsertBeforeInit) { | 407 TEST_F(SimpleIndexTest, InsertBeforeInit) { |
| 413 const uint64 kHash1 = hashes_.at<1>(); | 408 const uint64 kHash1 = hashes_.at<1>(); |
| 414 index()->Insert(kHash1); | 409 index()->Insert(kHash1); |
| 415 | 410 |
| 416 InsertIntoIndexFileReturn(kHash1, | 411 InsertIntoIndexFileReturn( |
| 417 base::Time::Now() - base::TimeDelta::FromDays(2), | 412 kHash1, base::Time::Now() - base::TimeDelta::FromDays(2), 10u); |
| 418 10u); | |
| 419 ReturnIndexFile(); | 413 ReturnIndexFile(); |
| 420 | 414 |
| 421 EntryMetadata metadata; | 415 EntryMetadata metadata; |
| 422 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); | 416 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); |
| 423 base::Time now(base::Time::Now()); | 417 base::Time now(base::Time::Now()); |
| 424 EXPECT_LT(now - base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); | 418 EXPECT_LT(now - base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); |
| 425 EXPECT_GT(now + base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); | 419 EXPECT_GT(now + base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); |
| 426 EXPECT_EQ(0, metadata.GetEntrySize()); | 420 EXPECT_EQ(0, metadata.GetEntrySize()); |
| 427 } | 421 } |
| 428 | 422 |
| 429 // Insert and Remove something that's going to come in from the loaded index. | 423 // Insert and Remove something that's going to come in from the loaded index. |
| 430 TEST_F(SimpleIndexTest, InsertRemoveBeforeInit) { | 424 TEST_F(SimpleIndexTest, InsertRemoveBeforeInit) { |
| 431 const uint64 kHash1 = hashes_.at<1>(); | 425 const uint64 kHash1 = hashes_.at<1>(); |
| 432 index()->Insert(kHash1); | 426 index()->Insert(kHash1); |
| 433 index()->Remove(kHash1); | 427 index()->Remove(kHash1); |
| 434 | 428 |
| 435 InsertIntoIndexFileReturn(kHash1, | 429 InsertIntoIndexFileReturn( |
| 436 base::Time::Now() - base::TimeDelta::FromDays(2), | 430 kHash1, base::Time::Now() - base::TimeDelta::FromDays(2), 10u); |
| 437 10u); | |
| 438 ReturnIndexFile(); | 431 ReturnIndexFile(); |
| 439 | 432 |
| 440 EXPECT_FALSE(index()->Has(kHash1)); | 433 EXPECT_FALSE(index()->Has(kHash1)); |
| 441 } | 434 } |
| 442 | 435 |
| 443 // Insert and Remove something that's going to come in from the loaded index. | 436 // Insert and Remove something that's going to come in from the loaded index. |
| 444 TEST_F(SimpleIndexTest, RemoveInsertBeforeInit) { | 437 TEST_F(SimpleIndexTest, RemoveInsertBeforeInit) { |
| 445 const uint64 kHash1 = hashes_.at<1>(); | 438 const uint64 kHash1 = hashes_.at<1>(); |
| 446 index()->Remove(kHash1); | 439 index()->Remove(kHash1); |
| 447 index()->Insert(kHash1); | 440 index()->Insert(kHash1); |
| 448 | 441 |
| 449 InsertIntoIndexFileReturn(kHash1, | 442 InsertIntoIndexFileReturn( |
| 450 base::Time::Now() - base::TimeDelta::FromDays(2), | 443 kHash1, base::Time::Now() - base::TimeDelta::FromDays(2), 10u); |
| 451 10u); | |
| 452 ReturnIndexFile(); | 444 ReturnIndexFile(); |
| 453 | 445 |
| 454 EntryMetadata metadata; | 446 EntryMetadata metadata; |
| 455 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); | 447 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); |
| 456 base::Time now(base::Time::Now()); | 448 base::Time now(base::Time::Now()); |
| 457 EXPECT_LT(now - base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); | 449 EXPECT_LT(now - base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); |
| 458 EXPECT_GT(now + base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); | 450 EXPECT_GT(now + base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); |
| 459 EXPECT_EQ(0, metadata.GetEntrySize()); | 451 EXPECT_EQ(0, metadata.GetEntrySize()); |
| 460 } | 452 } |
| 461 | 453 |
| 462 // Do all above tests at once + a non-conflict to test for cross-key | 454 // Do all above tests at once + a non-conflict to test for cross-key |
| 463 // interactions. | 455 // interactions. |
| 464 TEST_F(SimpleIndexTest, AllInitConflicts) { | 456 TEST_F(SimpleIndexTest, AllInitConflicts) { |
| 465 base::Time now(base::Time::Now()); | 457 base::Time now(base::Time::Now()); |
| 466 | 458 |
| 467 index()->Remove(hashes_.at<1>()); | 459 index()->Remove(hashes_.at<1>()); |
| 468 InsertIntoIndexFileReturn(hashes_.at<1>(), | 460 InsertIntoIndexFileReturn( |
| 469 now - base::TimeDelta::FromDays(2), | 461 hashes_.at<1>(), now - base::TimeDelta::FromDays(2), 10u); |
| 470 10u); | |
| 471 index()->Insert(hashes_.at<2>()); | 462 index()->Insert(hashes_.at<2>()); |
| 472 InsertIntoIndexFileReturn(hashes_.at<2>(), | 463 InsertIntoIndexFileReturn( |
| 473 now - base::TimeDelta::FromDays(3), | 464 hashes_.at<2>(), now - base::TimeDelta::FromDays(3), 100u); |
| 474 100u); | |
| 475 index()->Insert(hashes_.at<3>()); | 465 index()->Insert(hashes_.at<3>()); |
| 476 index()->Remove(hashes_.at<3>()); | 466 index()->Remove(hashes_.at<3>()); |
| 477 InsertIntoIndexFileReturn(hashes_.at<3>(), | 467 InsertIntoIndexFileReturn( |
| 478 now - base::TimeDelta::FromDays(4), | 468 hashes_.at<3>(), now - base::TimeDelta::FromDays(4), 1000u); |
| 479 1000u); | |
| 480 index()->Remove(hashes_.at<4>()); | 469 index()->Remove(hashes_.at<4>()); |
| 481 index()->Insert(hashes_.at<4>()); | 470 index()->Insert(hashes_.at<4>()); |
| 482 InsertIntoIndexFileReturn(hashes_.at<4>(), | 471 InsertIntoIndexFileReturn( |
| 483 now - base::TimeDelta::FromDays(5), | 472 hashes_.at<4>(), now - base::TimeDelta::FromDays(5), 10000u); |
| 484 10000u); | 473 InsertIntoIndexFileReturn( |
| 485 InsertIntoIndexFileReturn(hashes_.at<5>(), | 474 hashes_.at<5>(), now - base::TimeDelta::FromDays(6), 100000u); |
| 486 now - base::TimeDelta::FromDays(6), | |
| 487 100000u); | |
| 488 | 475 |
| 489 ReturnIndexFile(); | 476 ReturnIndexFile(); |
| 490 | 477 |
| 491 EXPECT_FALSE(index()->Has(hashes_.at<1>())); | 478 EXPECT_FALSE(index()->Has(hashes_.at<1>())); |
| 492 | 479 |
| 493 EntryMetadata metadata; | 480 EntryMetadata metadata; |
| 494 EXPECT_TRUE(GetEntryForTesting(hashes_.at<2>(), &metadata)); | 481 EXPECT_TRUE(GetEntryForTesting(hashes_.at<2>(), &metadata)); |
| 495 EXPECT_LT(now - base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); | 482 EXPECT_LT(now - base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); |
| 496 EXPECT_GT(now + base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); | 483 EXPECT_GT(now + base::TimeDelta::FromMinutes(1), metadata.GetLastUsedTime()); |
| 497 EXPECT_EQ(0, metadata.GetEntrySize()); | 484 EXPECT_EQ(0, metadata.GetEntrySize()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 511 EXPECT_LT( | 498 EXPECT_LT( |
| 512 now - base::TimeDelta::FromDays(6) - base::TimeDelta::FromSeconds(1), | 499 now - base::TimeDelta::FromDays(6) - base::TimeDelta::FromSeconds(1), |
| 513 metadata.GetLastUsedTime()); | 500 metadata.GetLastUsedTime()); |
| 514 | 501 |
| 515 EXPECT_EQ(100000, metadata.GetEntrySize()); | 502 EXPECT_EQ(100000, metadata.GetEntrySize()); |
| 516 } | 503 } |
| 517 | 504 |
| 518 TEST_F(SimpleIndexTest, BasicEviction) { | 505 TEST_F(SimpleIndexTest, BasicEviction) { |
| 519 base::Time now(base::Time::Now()); | 506 base::Time now(base::Time::Now()); |
| 520 index()->SetMaxSize(1000); | 507 index()->SetMaxSize(1000); |
| 521 InsertIntoIndexFileReturn(hashes_.at<1>(), | 508 InsertIntoIndexFileReturn( |
| 522 now - base::TimeDelta::FromDays(2), | 509 hashes_.at<1>(), now - base::TimeDelta::FromDays(2), 475u); |
| 523 475u); | |
| 524 index()->Insert(hashes_.at<2>()); | 510 index()->Insert(hashes_.at<2>()); |
| 525 index()->UpdateEntrySize(hashes_.at<2>(), 475); | 511 index()->UpdateEntrySize(hashes_.at<2>(), 475); |
| 526 ReturnIndexFile(); | 512 ReturnIndexFile(); |
| 527 | 513 |
| 528 WaitForTimeChange(); | 514 WaitForTimeChange(); |
| 529 | 515 |
| 530 index()->Insert(hashes_.at<3>()); | 516 index()->Insert(hashes_.at<3>()); |
| 531 // Confirm index is as expected: No eviction, everything there. | 517 // Confirm index is as expected: No eviction, everything there. |
| 532 EXPECT_EQ(3, index()->GetEntryCount()); | 518 EXPECT_EQ(3, index()->GetEntryCount()); |
| 533 EXPECT_EQ(0, doom_entries_calls()); | 519 EXPECT_EQ(0, doom_entries_calls()); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 WaitForTimeChange(); | 605 WaitForTimeChange(); |
| 620 EXPECT_EQ(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); | 606 EXPECT_EQ(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); |
| 621 index()->Insert(hashes_.at<2>()); | 607 index()->Insert(hashes_.at<2>()); |
| 622 index()->UpdateEntrySize(hashes_.at<2>(), 40); | 608 index()->UpdateEntrySize(hashes_.at<2>(), 40); |
| 623 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning()); | 609 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning()); |
| 624 EXPECT_LT(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); | 610 EXPECT_LT(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); |
| 625 index()->write_to_disk_timer_.Stop(); | 611 index()->write_to_disk_timer_.Stop(); |
| 626 } | 612 } |
| 627 | 613 |
| 628 } // namespace disk_cache | 614 } // namespace disk_cache |
| OLD | NEW |