| 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 "net/disk_cache/simple/simple_index.h" | 5 #include "net/disk_cache/simple/simple_index.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "net/disk_cache/simple/simple_test_util.h" | 30 #include "net/disk_cache/simple/simple_test_util.h" |
| 31 #include "net/disk_cache/simple/simple_util.h" | 31 #include "net/disk_cache/simple/simple_util.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 33 | 33 |
| 34 namespace disk_cache { | 34 namespace disk_cache { |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 const base::Time kTestLastUsedTime = | 37 const base::Time kTestLastUsedTime = |
| 38 base::Time::UnixEpoch() + base::TimeDelta::FromDays(20); | 38 base::Time::UnixEpoch() + base::TimeDelta::FromDays(20); |
| 39 const uint32_t kTestEntrySize = 789; | 39 const uint32_t kTestEntrySize = 789; |
| 40 const uint8_t kTestEntryMemoryData = 123; |
| 41 |
| 42 uint32_t RoundSize(uint32_t in) { |
| 43 return (in + 0xFFu) & 0xFFFFFF00u; |
| 44 } |
| 40 | 45 |
| 41 } // namespace | 46 } // namespace |
| 42 | 47 |
| 43 class EntryMetadataTest : public testing::Test { | 48 class EntryMetadataTest : public testing::Test { |
| 44 public: | 49 public: |
| 45 EntryMetadata NewEntryMetadataWithValues() { | 50 EntryMetadata NewEntryMetadataWithValues() { |
| 46 return EntryMetadata(kTestLastUsedTime, kTestEntrySize); | 51 EntryMetadata entry(kTestLastUsedTime, kTestEntrySize); |
| 52 entry.SetInMemoryData(kTestEntryMemoryData); |
| 53 return entry; |
| 47 } | 54 } |
| 48 | 55 |
| 49 void CheckEntryMetadataValues(const EntryMetadata& entry_metadata) { | 56 void CheckEntryMetadataValues(const EntryMetadata& entry_metadata) { |
| 50 EXPECT_LT(kTestLastUsedTime - base::TimeDelta::FromSeconds(2), | 57 EXPECT_LT(kTestLastUsedTime - base::TimeDelta::FromSeconds(2), |
| 51 entry_metadata.GetLastUsedTime()); | 58 entry_metadata.GetLastUsedTime()); |
| 52 EXPECT_GT(kTestLastUsedTime + base::TimeDelta::FromSeconds(2), | 59 EXPECT_GT(kTestLastUsedTime + base::TimeDelta::FromSeconds(2), |
| 53 entry_metadata.GetLastUsedTime()); | 60 entry_metadata.GetLastUsedTime()); |
| 54 EXPECT_EQ(kTestEntrySize, entry_metadata.GetEntrySize()); | 61 EXPECT_EQ(RoundSize(kTestEntrySize), entry_metadata.GetEntrySize()); |
| 62 EXPECT_EQ(kTestEntryMemoryData, entry_metadata.GetInMemoryData()); |
| 55 } | 63 } |
| 56 }; | 64 }; |
| 57 | 65 |
| 58 class MockSimpleIndexFile : public SimpleIndexFile, | 66 class MockSimpleIndexFile : public SimpleIndexFile, |
| 59 public base::SupportsWeakPtr<MockSimpleIndexFile> { | 67 public base::SupportsWeakPtr<MockSimpleIndexFile> { |
| 60 public: | 68 public: |
| 61 MockSimpleIndexFile() | 69 MockSimpleIndexFile() |
| 62 : SimpleIndexFile(NULL, NULL, net::DISK_CACHE, base::FilePath()), | 70 : SimpleIndexFile(NULL, NULL, net::DISK_CACHE, base::FilePath()), |
| 63 load_result_(NULL), | 71 load_result_(NULL), |
| 64 load_index_entries_calls_(0), | 72 load_index_entries_calls_(0), |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 206 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
| 199 base::test::ScopedFeatureList scoped_feature_list_; | 207 base::test::ScopedFeatureList scoped_feature_list_; |
| 200 | 208 |
| 201 std::vector<uint64_t> last_doom_entry_hashes_; | 209 std::vector<uint64_t> last_doom_entry_hashes_; |
| 202 int doom_entries_calls_; | 210 int doom_entries_calls_; |
| 203 }; | 211 }; |
| 204 | 212 |
| 205 TEST_F(EntryMetadataTest, Basics) { | 213 TEST_F(EntryMetadataTest, Basics) { |
| 206 EntryMetadata entry_metadata; | 214 EntryMetadata entry_metadata; |
| 207 EXPECT_EQ(base::Time(), entry_metadata.GetLastUsedTime()); | 215 EXPECT_EQ(base::Time(), entry_metadata.GetLastUsedTime()); |
| 208 EXPECT_EQ(0U, entry_metadata.GetEntrySize()); | 216 EXPECT_EQ(0u, entry_metadata.GetEntrySize()); |
| 217 EXPECT_EQ(0u, entry_metadata.GetInMemoryData()); |
| 209 | 218 |
| 210 entry_metadata = NewEntryMetadataWithValues(); | 219 entry_metadata = NewEntryMetadataWithValues(); |
| 211 CheckEntryMetadataValues(entry_metadata); | 220 CheckEntryMetadataValues(entry_metadata); |
| 212 | 221 |
| 213 const base::Time new_time = base::Time::Now(); | 222 const base::Time new_time = base::Time::Now(); |
| 214 entry_metadata.SetLastUsedTime(new_time); | 223 entry_metadata.SetLastUsedTime(new_time); |
| 215 | 224 |
| 216 EXPECT_LT(new_time - base::TimeDelta::FromSeconds(2), | 225 EXPECT_LT(new_time - base::TimeDelta::FromSeconds(2), |
| 217 entry_metadata.GetLastUsedTime()); | 226 entry_metadata.GetLastUsedTime()); |
| 218 EXPECT_GT(new_time + base::TimeDelta::FromSeconds(2), | 227 EXPECT_GT(new_time + base::TimeDelta::FromSeconds(2), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 239 } | 248 } |
| 240 | 249 |
| 241 TEST_F(EntryMetadataTest, Serialize) { | 250 TEST_F(EntryMetadataTest, Serialize) { |
| 242 EntryMetadata entry_metadata = NewEntryMetadataWithValues(); | 251 EntryMetadata entry_metadata = NewEntryMetadataWithValues(); |
| 243 | 252 |
| 244 base::Pickle pickle; | 253 base::Pickle pickle; |
| 245 entry_metadata.Serialize(&pickle); | 254 entry_metadata.Serialize(&pickle); |
| 246 | 255 |
| 247 base::PickleIterator it(pickle); | 256 base::PickleIterator it(pickle); |
| 248 EntryMetadata new_entry_metadata; | 257 EntryMetadata new_entry_metadata; |
| 249 new_entry_metadata.Deserialize(&it); | 258 new_entry_metadata.Deserialize(&it, true); |
| 250 CheckEntryMetadataValues(new_entry_metadata); | 259 CheckEntryMetadataValues(new_entry_metadata); |
| 260 |
| 261 // Test reading of old format --- the modern serialization of above entry |
| 262 // corresponds, in older format, to an entry with size = |
| 263 // RoundSize(kTestEntrySize) | kTestEntryMemoryData, which then gets |
| 264 // rounded again when stored by EntryMetadata. |
| 265 base::PickleIterator it2(pickle); |
| 266 EntryMetadata new_entry_metadata2; |
| 267 new_entry_metadata2.Deserialize(&it2, false); |
| 268 EXPECT_EQ(RoundSize(RoundSize(kTestEntrySize) | kTestEntryMemoryData), |
| 269 new_entry_metadata2.GetEntrySize()); |
| 270 EXPECT_EQ(0, new_entry_metadata2.GetInMemoryData()); |
| 251 } | 271 } |
| 252 | 272 |
| 253 TEST_F(SimpleIndexTest, IndexSizeCorrectOnMerge) { | 273 TEST_F(SimpleIndexTest, IndexSizeCorrectOnMerge) { |
| 254 index()->SetMaxSize(100); | 274 const unsigned int kSizeResolution = 256u; |
| 275 index()->SetMaxSize(100 * kSizeResolution); |
| 255 index()->Insert(hashes_.at<2>()); | 276 index()->Insert(hashes_.at<2>()); |
| 256 index()->UpdateEntrySize(hashes_.at<2>(), 2u); | 277 index()->UpdateEntrySize(hashes_.at<2>(), 2u * kSizeResolution); |
| 257 index()->Insert(hashes_.at<3>()); | 278 index()->Insert(hashes_.at<3>()); |
| 258 index()->UpdateEntrySize(hashes_.at<3>(), 3u); | 279 index()->UpdateEntrySize(hashes_.at<3>(), 3u * kSizeResolution); |
| 259 index()->Insert(hashes_.at<4>()); | 280 index()->Insert(hashes_.at<4>()); |
| 260 index()->UpdateEntrySize(hashes_.at<4>(), 4u); | 281 index()->UpdateEntrySize(hashes_.at<4>(), 4u * kSizeResolution); |
| 261 EXPECT_EQ(9U, index()->cache_size_); | 282 EXPECT_EQ(9u * kSizeResolution, index()->cache_size_); |
| 262 { | 283 { |
| 263 std::unique_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); | 284 std::unique_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); |
| 264 result->did_load = true; | 285 result->did_load = true; |
| 265 index()->MergeInitializingSet(std::move(result)); | 286 index()->MergeInitializingSet(std::move(result)); |
| 266 } | 287 } |
| 267 EXPECT_EQ(9U, index()->cache_size_); | 288 EXPECT_EQ(9u * kSizeResolution, index()->cache_size_); |
| 268 { | 289 { |
| 269 std::unique_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); | 290 std::unique_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); |
| 270 result->did_load = true; | 291 result->did_load = true; |
| 271 const uint64_t new_hash_key = hashes_.at<11>(); | 292 const uint64_t new_hash_key = hashes_.at<11>(); |
| 293 result->entries.insert(std::make_pair( |
| 294 new_hash_key, EntryMetadata(base::Time::Now(), 11u * kSizeResolution))); |
| 295 const uint64_t redundant_hash_key = hashes_.at<4>(); |
| 272 result->entries.insert( | 296 result->entries.insert( |
| 273 std::make_pair(new_hash_key, EntryMetadata(base::Time::Now(), 11u))); | 297 std::make_pair(redundant_hash_key, |
| 274 const uint64_t redundant_hash_key = hashes_.at<4>(); | 298 EntryMetadata(base::Time::Now(), 4u * kSizeResolution))); |
| 275 result->entries.insert(std::make_pair( | |
| 276 redundant_hash_key, EntryMetadata(base::Time::Now(), 4u))); | |
| 277 index()->MergeInitializingSet(std::move(result)); | 299 index()->MergeInitializingSet(std::move(result)); |
| 278 } | 300 } |
| 279 EXPECT_EQ(2U + 3U + 4U + 11U, index()->cache_size_); | 301 EXPECT_EQ((2u + 3u + 4u + 11u) * kSizeResolution, index()->cache_size_); |
| 280 } | 302 } |
| 281 | 303 |
| 282 // State of index changes as expected with an insert and a remove. | 304 // State of index changes as expected with an insert and a remove. |
| 283 TEST_F(SimpleIndexTest, BasicInsertRemove) { | 305 TEST_F(SimpleIndexTest, BasicInsertRemove) { |
| 284 // Confirm blank state. | 306 // Confirm blank state. |
| 285 EntryMetadata metadata; | 307 EntryMetadata metadata; |
| 286 EXPECT_EQ(base::Time(), metadata.GetLastUsedTime()); | 308 EXPECT_EQ(base::Time(), metadata.GetLastUsedTime()); |
| 287 EXPECT_EQ(0U, metadata.GetEntrySize()); | 309 EXPECT_EQ(0U, metadata.GetEntrySize()); |
| 288 | 310 |
| 289 // Confirm state after insert. | 311 // Confirm state after insert. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 ReturnIndexFile(); | 398 ReturnIndexFile(); |
| 377 | 399 |
| 378 EntryMetadata metadata; | 400 EntryMetadata metadata; |
| 379 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); | 401 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); |
| 380 EXPECT_LT( | 402 EXPECT_LT( |
| 381 now - base::TimeDelta::FromDays(2) - base::TimeDelta::FromSeconds(1), | 403 now - base::TimeDelta::FromDays(2) - base::TimeDelta::FromSeconds(1), |
| 382 metadata.GetLastUsedTime()); | 404 metadata.GetLastUsedTime()); |
| 383 EXPECT_GT( | 405 EXPECT_GT( |
| 384 now - base::TimeDelta::FromDays(2) + base::TimeDelta::FromSeconds(1), | 406 now - base::TimeDelta::FromDays(2) + base::TimeDelta::FromSeconds(1), |
| 385 metadata.GetLastUsedTime()); | 407 metadata.GetLastUsedTime()); |
| 386 EXPECT_EQ(475U, metadata.GetEntrySize()); | 408 EXPECT_EQ(RoundSize(475u), metadata.GetEntrySize()); |
| 387 | 409 |
| 388 index()->UpdateEntrySize(kHash1, 600u); | 410 index()->UpdateEntrySize(kHash1, 600u); |
| 389 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); | 411 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); |
| 390 EXPECT_EQ(600U, metadata.GetEntrySize()); | 412 EXPECT_EQ(RoundSize(600u), metadata.GetEntrySize()); |
| 391 EXPECT_EQ(1, index()->GetEntryCount()); | 413 EXPECT_EQ(1, index()->GetEntryCount()); |
| 392 } | 414 } |
| 393 | 415 |
| 394 TEST_F(SimpleIndexTest, GetEntryCount) { | 416 TEST_F(SimpleIndexTest, GetEntryCount) { |
| 395 EXPECT_EQ(0, index()->GetEntryCount()); | 417 EXPECT_EQ(0, index()->GetEntryCount()); |
| 396 index()->Insert(hashes_.at<1>()); | 418 index()->Insert(hashes_.at<1>()); |
| 397 EXPECT_EQ(1, index()->GetEntryCount()); | 419 EXPECT_EQ(1, index()->GetEntryCount()); |
| 398 index()->Insert(hashes_.at<2>()); | 420 index()->Insert(hashes_.at<2>()); |
| 399 EXPECT_EQ(2, index()->GetEntryCount()); | 421 EXPECT_EQ(2, index()->GetEntryCount()); |
| 400 index()->Insert(hashes_.at<3>()); | 422 index()->Insert(hashes_.at<3>()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 415 EXPECT_EQ(0, index()->GetEntryCount()); | 437 EXPECT_EQ(0, index()->GetEntryCount()); |
| 416 } | 438 } |
| 417 | 439 |
| 418 // Confirm that we get the results we expect from a simple init. | 440 // Confirm that we get the results we expect from a simple init. |
| 419 TEST_F(SimpleIndexTest, BasicInit) { | 441 TEST_F(SimpleIndexTest, BasicInit) { |
| 420 base::Time now(base::Time::Now()); | 442 base::Time now(base::Time::Now()); |
| 421 | 443 |
| 422 InsertIntoIndexFileReturn(hashes_.at<1>(), | 444 InsertIntoIndexFileReturn(hashes_.at<1>(), |
| 423 now - base::TimeDelta::FromDays(2), | 445 now - base::TimeDelta::FromDays(2), |
| 424 10u); | 446 10u); |
| 425 InsertIntoIndexFileReturn(hashes_.at<2>(), | 447 InsertIntoIndexFileReturn(hashes_.at<2>(), now - base::TimeDelta::FromDays(3), |
| 426 now - base::TimeDelta::FromDays(3), | 448 1000u); |
| 427 100u); | |
| 428 | 449 |
| 429 ReturnIndexFile(); | 450 ReturnIndexFile(); |
| 430 | 451 |
| 431 EntryMetadata metadata; | 452 EntryMetadata metadata; |
| 432 EXPECT_TRUE(GetEntryForTesting(hashes_.at<1>(), &metadata)); | 453 EXPECT_TRUE(GetEntryForTesting(hashes_.at<1>(), &metadata)); |
| 433 EXPECT_LT( | 454 EXPECT_LT( |
| 434 now - base::TimeDelta::FromDays(2) - base::TimeDelta::FromSeconds(1), | 455 now - base::TimeDelta::FromDays(2) - base::TimeDelta::FromSeconds(1), |
| 435 metadata.GetLastUsedTime()); | 456 metadata.GetLastUsedTime()); |
| 436 EXPECT_GT( | 457 EXPECT_GT( |
| 437 now - base::TimeDelta::FromDays(2) + base::TimeDelta::FromSeconds(1), | 458 now - base::TimeDelta::FromDays(2) + base::TimeDelta::FromSeconds(1), |
| 438 metadata.GetLastUsedTime()); | 459 metadata.GetLastUsedTime()); |
| 439 EXPECT_EQ(10U, metadata.GetEntrySize()); | 460 EXPECT_EQ(RoundSize(10u), metadata.GetEntrySize()); |
| 440 EXPECT_TRUE(GetEntryForTesting(hashes_.at<2>(), &metadata)); | 461 EXPECT_TRUE(GetEntryForTesting(hashes_.at<2>(), &metadata)); |
| 441 EXPECT_LT( | 462 EXPECT_LT( |
| 442 now - base::TimeDelta::FromDays(3) - base::TimeDelta::FromSeconds(1), | 463 now - base::TimeDelta::FromDays(3) - base::TimeDelta::FromSeconds(1), |
| 443 metadata.GetLastUsedTime()); | 464 metadata.GetLastUsedTime()); |
| 444 EXPECT_GT( | 465 EXPECT_GT( |
| 445 now - base::TimeDelta::FromDays(3) + base::TimeDelta::FromSeconds(1), | 466 now - base::TimeDelta::FromDays(3) + base::TimeDelta::FromSeconds(1), |
| 446 metadata.GetLastUsedTime()); | 467 metadata.GetLastUsedTime()); |
| 447 EXPECT_EQ(100U, metadata.GetEntrySize()); | 468 EXPECT_EQ(RoundSize(1000u), metadata.GetEntrySize()); |
| 448 } | 469 } |
| 449 | 470 |
| 450 // Remove something that's going to come in from the loaded index. | 471 // Remove something that's going to come in from the loaded index. |
| 451 TEST_F(SimpleIndexTest, RemoveBeforeInit) { | 472 TEST_F(SimpleIndexTest, RemoveBeforeInit) { |
| 452 const uint64_t kHash1 = hashes_.at<1>(); | 473 const uint64_t kHash1 = hashes_.at<1>(); |
| 453 index()->Remove(kHash1); | 474 index()->Remove(kHash1); |
| 454 | 475 |
| 455 InsertIntoIndexFileReturn(kHash1, | 476 InsertIntoIndexFileReturn(kHash1, |
| 456 base::Time::Now() - base::TimeDelta::FromDays(2), | 477 base::Time::Now() - base::TimeDelta::FromDays(2), |
| 457 10u); | 478 10u); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 | 579 |
| 559 EXPECT_TRUE(GetEntryForTesting(hashes_.at<5>(), &metadata)); | 580 EXPECT_TRUE(GetEntryForTesting(hashes_.at<5>(), &metadata)); |
| 560 | 581 |
| 561 EXPECT_GT( | 582 EXPECT_GT( |
| 562 now - base::TimeDelta::FromDays(6) + base::TimeDelta::FromSeconds(1), | 583 now - base::TimeDelta::FromDays(6) + base::TimeDelta::FromSeconds(1), |
| 563 metadata.GetLastUsedTime()); | 584 metadata.GetLastUsedTime()); |
| 564 EXPECT_LT( | 585 EXPECT_LT( |
| 565 now - base::TimeDelta::FromDays(6) - base::TimeDelta::FromSeconds(1), | 586 now - base::TimeDelta::FromDays(6) - base::TimeDelta::FromSeconds(1), |
| 566 metadata.GetLastUsedTime()); | 587 metadata.GetLastUsedTime()); |
| 567 | 588 |
| 568 EXPECT_EQ(100000U, metadata.GetEntrySize()); | 589 EXPECT_EQ(RoundSize(100000u), metadata.GetEntrySize()); |
| 569 } | 590 } |
| 570 | 591 |
| 571 TEST_F(SimpleIndexTest, BasicEviction) { | 592 TEST_F(SimpleIndexTest, BasicEviction) { |
| 572 base::Time now(base::Time::Now()); | 593 base::Time now(base::Time::Now()); |
| 573 index()->SetMaxSize(1000); | 594 index()->SetMaxSize(1000); |
| 574 InsertIntoIndexFileReturn(hashes_.at<1>(), | 595 InsertIntoIndexFileReturn(hashes_.at<1>(), |
| 575 now - base::TimeDelta::FromDays(2), | 596 now - base::TimeDelta::FromDays(2), |
| 576 475u); | 597 475u); |
| 577 index()->Insert(hashes_.at<2>()); | 598 index()->Insert(hashes_.at<2>()); |
| 578 index()->UpdateEntrySize(hashes_.at<2>(), 475u); | 599 index()->UpdateEntrySize(hashes_.at<2>(), 475u); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 715 SimpleIndex::EntrySet entry_set; | 736 SimpleIndex::EntrySet entry_set; |
| 716 index_file_->GetAndResetDiskWriteEntrySet(&entry_set); | 737 index_file_->GetAndResetDiskWriteEntrySet(&entry_set); |
| 717 | 738 |
| 718 uint64_t hash_key = kHash1; | 739 uint64_t hash_key = kHash1; |
| 719 base::Time now(base::Time::Now()); | 740 base::Time now(base::Time::Now()); |
| 720 ASSERT_EQ(1u, entry_set.size()); | 741 ASSERT_EQ(1u, entry_set.size()); |
| 721 EXPECT_EQ(hash_key, entry_set.begin()->first); | 742 EXPECT_EQ(hash_key, entry_set.begin()->first); |
| 722 const EntryMetadata& entry1(entry_set.begin()->second); | 743 const EntryMetadata& entry1(entry_set.begin()->second); |
| 723 EXPECT_LT(now - base::TimeDelta::FromMinutes(1), entry1.GetLastUsedTime()); | 744 EXPECT_LT(now - base::TimeDelta::FromMinutes(1), entry1.GetLastUsedTime()); |
| 724 EXPECT_GT(now + base::TimeDelta::FromMinutes(1), entry1.GetLastUsedTime()); | 745 EXPECT_GT(now + base::TimeDelta::FromMinutes(1), entry1.GetLastUsedTime()); |
| 725 EXPECT_EQ(20U, entry1.GetEntrySize()); | 746 EXPECT_EQ(RoundSize(20u), entry1.GetEntrySize()); |
| 726 } | 747 } |
| 727 | 748 |
| 728 TEST_F(SimpleIndexTest, DiskWritePostponed) { | 749 TEST_F(SimpleIndexTest, DiskWritePostponed) { |
| 729 index()->SetMaxSize(1000); | 750 index()->SetMaxSize(1000); |
| 730 ReturnIndexFile(); | 751 ReturnIndexFile(); |
| 731 | 752 |
| 732 EXPECT_FALSE(index()->write_to_disk_timer_.IsRunning()); | 753 EXPECT_FALSE(index()->write_to_disk_timer_.IsRunning()); |
| 733 | 754 |
| 734 index()->Insert(hashes_.at<1>()); | 755 index()->Insert(hashes_.at<1>()); |
| 735 index()->UpdateEntrySize(hashes_.at<1>(), 20u); | 756 index()->UpdateEntrySize(hashes_.at<1>(), 20u); |
| 736 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning()); | 757 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning()); |
| 737 base::TimeTicks expected_trigger( | 758 base::TimeTicks expected_trigger( |
| 738 index()->write_to_disk_timer_.desired_run_time()); | 759 index()->write_to_disk_timer_.desired_run_time()); |
| 739 | 760 |
| 740 WaitForTimeChange(); | 761 WaitForTimeChange(); |
| 741 EXPECT_EQ(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); | 762 EXPECT_EQ(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); |
| 742 index()->Insert(hashes_.at<2>()); | 763 index()->Insert(hashes_.at<2>()); |
| 743 index()->UpdateEntrySize(hashes_.at<2>(), 40u); | 764 index()->UpdateEntrySize(hashes_.at<2>(), 40u); |
| 744 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning()); | 765 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning()); |
| 745 EXPECT_LT(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); | 766 EXPECT_LT(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); |
| 746 index()->write_to_disk_timer_.Stop(); | 767 index()->write_to_disk_timer_.Stop(); |
| 747 } | 768 } |
| 748 | 769 |
| 749 } // namespace disk_cache | 770 } // namespace disk_cache |
| OLD | NEW |