Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 #include "net/disk_cache/simple/simple_test_util.h" | 24 #include "net/disk_cache/simple/simple_test_util.h" |
| 25 #include "net/disk_cache/simple/simple_util.h" | 25 #include "net/disk_cache/simple/simple_util.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 27 |
| 28 namespace disk_cache { | 28 namespace disk_cache { |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 const base::Time kTestLastUsedTime = | 31 const base::Time kTestLastUsedTime = |
| 32 base::Time::UnixEpoch() + base::TimeDelta::FromDays(20); | 32 base::Time::UnixEpoch() + base::TimeDelta::FromDays(20); |
| 33 const uint32_t kTestEntrySize = 789; | 33 const uint32_t kTestEntrySize = 789; |
| 34 const uint8_t kTestEntryMemoryData = 123; | |
| 35 | |
| 36 uint32_t RoundSize(uint32_t in) { | |
| 37 return (in + 255u) & 0xFFFFFF00; | |
| 38 } | |
| 34 | 39 |
| 35 } // namespace | 40 } // namespace |
| 36 | 41 |
| 37 class EntryMetadataTest : public testing::Test { | 42 class EntryMetadataTest : public testing::Test { |
| 38 public: | 43 public: |
| 39 EntryMetadata NewEntryMetadataWithValues() { | 44 EntryMetadata NewEntryMetadataWithValues() { |
| 40 return EntryMetadata(kTestLastUsedTime, kTestEntrySize); | 45 EntryMetadata entry(kTestLastUsedTime, kTestEntrySize); |
| 46 entry.SetMemoryEntryData(kTestEntryMemoryData); | |
| 47 return entry; | |
| 41 } | 48 } |
| 42 | 49 |
| 43 void CheckEntryMetadataValues(const EntryMetadata& entry_metadata) { | 50 void CheckEntryMetadataValues(const EntryMetadata& entry_metadata) { |
| 44 EXPECT_LT(kTestLastUsedTime - base::TimeDelta::FromSeconds(2), | 51 EXPECT_LT(kTestLastUsedTime - base::TimeDelta::FromSeconds(2), |
| 45 entry_metadata.GetLastUsedTime()); | 52 entry_metadata.GetLastUsedTime()); |
| 46 EXPECT_GT(kTestLastUsedTime + base::TimeDelta::FromSeconds(2), | 53 EXPECT_GT(kTestLastUsedTime + base::TimeDelta::FromSeconds(2), |
| 47 entry_metadata.GetLastUsedTime()); | 54 entry_metadata.GetLastUsedTime()); |
| 48 EXPECT_EQ(kTestEntrySize, entry_metadata.GetEntrySize()); | 55 EXPECT_EQ(RoundSize(kTestEntrySize), entry_metadata.GetEntrySize()); |
| 56 EXPECT_EQ(kTestEntryMemoryData, entry_metadata.GetMemoryEntryData()); | |
| 49 } | 57 } |
| 50 }; | 58 }; |
| 51 | 59 |
| 52 class MockSimpleIndexFile : public SimpleIndexFile, | 60 class MockSimpleIndexFile : public SimpleIndexFile, |
| 53 public base::SupportsWeakPtr<MockSimpleIndexFile> { | 61 public base::SupportsWeakPtr<MockSimpleIndexFile> { |
| 54 public: | 62 public: |
| 55 MockSimpleIndexFile() | 63 MockSimpleIndexFile() |
| 56 : SimpleIndexFile(NULL, NULL, net::DISK_CACHE, base::FilePath()), | 64 : SimpleIndexFile(NULL, NULL, net::DISK_CACHE, base::FilePath()), |
| 57 load_result_(NULL), | 65 load_result_(NULL), |
| 58 load_index_entries_calls_(0), | 66 load_index_entries_calls_(0), |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 base::WeakPtr<MockSimpleIndexFile> index_file_; | 174 base::WeakPtr<MockSimpleIndexFile> index_file_; |
| 167 | 175 |
| 168 std::vector<uint64_t> last_doom_entry_hashes_; | 176 std::vector<uint64_t> last_doom_entry_hashes_; |
| 169 int doom_entries_calls_; | 177 int doom_entries_calls_; |
| 170 }; | 178 }; |
| 171 | 179 |
| 172 TEST_F(EntryMetadataTest, Basics) { | 180 TEST_F(EntryMetadataTest, Basics) { |
| 173 EntryMetadata entry_metadata; | 181 EntryMetadata entry_metadata; |
| 174 EXPECT_EQ(base::Time(), entry_metadata.GetLastUsedTime()); | 182 EXPECT_EQ(base::Time(), entry_metadata.GetLastUsedTime()); |
| 175 EXPECT_EQ(0U, entry_metadata.GetEntrySize()); | 183 EXPECT_EQ(0U, entry_metadata.GetEntrySize()); |
| 184 EXPECT_EQ(0u, entry_metadata.GetMemoryEntryData()); | |
| 176 | 185 |
| 177 entry_metadata = NewEntryMetadataWithValues(); | 186 entry_metadata = NewEntryMetadataWithValues(); |
| 178 CheckEntryMetadataValues(entry_metadata); | 187 CheckEntryMetadataValues(entry_metadata); |
| 179 | 188 |
| 180 const base::Time new_time = base::Time::Now(); | 189 const base::Time new_time = base::Time::Now(); |
| 181 entry_metadata.SetLastUsedTime(new_time); | 190 entry_metadata.SetLastUsedTime(new_time); |
| 182 | 191 |
| 183 EXPECT_LT(new_time - base::TimeDelta::FromSeconds(2), | 192 EXPECT_LT(new_time - base::TimeDelta::FromSeconds(2), |
| 184 entry_metadata.GetLastUsedTime()); | 193 entry_metadata.GetLastUsedTime()); |
| 185 EXPECT_GT(new_time + base::TimeDelta::FromSeconds(2), | 194 EXPECT_GT(new_time + base::TimeDelta::FromSeconds(2), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 206 } | 215 } |
| 207 | 216 |
| 208 TEST_F(EntryMetadataTest, Serialize) { | 217 TEST_F(EntryMetadataTest, Serialize) { |
| 209 EntryMetadata entry_metadata = NewEntryMetadataWithValues(); | 218 EntryMetadata entry_metadata = NewEntryMetadataWithValues(); |
| 210 | 219 |
| 211 base::Pickle pickle; | 220 base::Pickle pickle; |
| 212 entry_metadata.Serialize(&pickle); | 221 entry_metadata.Serialize(&pickle); |
| 213 | 222 |
| 214 base::PickleIterator it(pickle); | 223 base::PickleIterator it(pickle); |
| 215 EntryMetadata new_entry_metadata; | 224 EntryMetadata new_entry_metadata; |
| 216 new_entry_metadata.Deserialize(&it); | 225 new_entry_metadata.Deserialize(&it, true); |
| 217 CheckEntryMetadataValues(new_entry_metadata); | 226 CheckEntryMetadataValues(new_entry_metadata); |
| 227 | |
| 228 // Test reading of old format --- the modern serialization of above entry | |
| 229 // corresponds, in older format, to an entry with size = | |
| 230 // RoundSize(kTestEntrySize) | kTestEntryMemoryData, which then gets | |
| 231 // rounded again when stored by EntryMetadata. | |
| 232 base::PickleIterator it2(pickle); | |
| 233 EntryMetadata new_entry_metadata2; | |
| 234 new_entry_metadata2.Deserialize(&it2, false); | |
| 235 EXPECT_EQ(RoundSize(RoundSize(kTestEntrySize) | kTestEntryMemoryData), | |
| 236 new_entry_metadata2.GetEntrySize()); | |
| 237 EXPECT_EQ(0, new_entry_metadata2.GetMemoryEntryData()); | |
| 218 } | 238 } |
| 219 | 239 |
| 220 TEST_F(SimpleIndexTest, IndexSizeCorrectOnMerge) { | 240 TEST_F(SimpleIndexTest, IndexSizeCorrectOnMerge) { |
| 221 index()->SetMaxSize(100); | 241 const unsigned int kSizeResolution = 256U; |
| 242 index()->SetMaxSize(100 * kSizeResolution); | |
| 222 index()->Insert(hashes_.at<2>()); | 243 index()->Insert(hashes_.at<2>()); |
| 223 index()->UpdateEntrySize(hashes_.at<2>(), 2u); | 244 index()->UpdateEntrySize(hashes_.at<2>(), 2U * kSizeResolution); |
| 224 index()->Insert(hashes_.at<3>()); | 245 index()->Insert(hashes_.at<3>()); |
| 225 index()->UpdateEntrySize(hashes_.at<3>(), 3u); | 246 index()->UpdateEntrySize(hashes_.at<3>(), 3U * kSizeResolution); |
| 226 index()->Insert(hashes_.at<4>()); | 247 index()->Insert(hashes_.at<4>()); |
| 227 index()->UpdateEntrySize(hashes_.at<4>(), 4u); | 248 index()->UpdateEntrySize(hashes_.at<4>(), 4U * kSizeResolution); |
| 228 EXPECT_EQ(9U, index()->cache_size_); | 249 EXPECT_EQ(9U * kSizeResolution, index()->cache_size_); |
| 229 { | 250 { |
| 230 std::unique_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); | 251 std::unique_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); |
| 231 result->did_load = true; | 252 result->did_load = true; |
| 232 index()->MergeInitializingSet(std::move(result)); | 253 index()->MergeInitializingSet(std::move(result)); |
| 233 } | 254 } |
| 234 EXPECT_EQ(9U, index()->cache_size_); | 255 EXPECT_EQ(9U * kSizeResolution, index()->cache_size_); |
| 235 { | 256 { |
| 236 std::unique_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); | 257 std::unique_ptr<SimpleIndexLoadResult> result(new SimpleIndexLoadResult()); |
| 237 result->did_load = true; | 258 result->did_load = true; |
| 238 const uint64_t new_hash_key = hashes_.at<11>(); | 259 const uint64_t new_hash_key = hashes_.at<11>(); |
| 260 result->entries.insert(std::make_pair( | |
| 261 new_hash_key, EntryMetadata(base::Time::Now(), 11U * kSizeResolution))); | |
| 262 const uint64_t redundant_hash_key = hashes_.at<4>(); | |
| 239 result->entries.insert( | 263 result->entries.insert( |
| 240 std::make_pair(new_hash_key, EntryMetadata(base::Time::Now(), 11u))); | 264 std::make_pair(redundant_hash_key, |
| 241 const uint64_t redundant_hash_key = hashes_.at<4>(); | 265 EntryMetadata(base::Time::Now(), 4U * kSizeResolution))); |
| 242 result->entries.insert(std::make_pair( | |
| 243 redundant_hash_key, EntryMetadata(base::Time::Now(), 4u))); | |
| 244 index()->MergeInitializingSet(std::move(result)); | 266 index()->MergeInitializingSet(std::move(result)); |
| 245 } | 267 } |
| 246 EXPECT_EQ(2U + 3U + 4U + 11U, index()->cache_size_); | 268 EXPECT_EQ((2U + 3U + 4U + 11U) * kSizeResolution, index()->cache_size_); |
| 247 } | 269 } |
| 248 | 270 |
| 249 // State of index changes as expected with an insert and a remove. | 271 // State of index changes as expected with an insert and a remove. |
| 250 TEST_F(SimpleIndexTest, BasicInsertRemove) { | 272 TEST_F(SimpleIndexTest, BasicInsertRemove) { |
| 251 // Confirm blank state. | 273 // Confirm blank state. |
| 252 EntryMetadata metadata; | 274 EntryMetadata metadata; |
| 253 EXPECT_EQ(base::Time(), metadata.GetLastUsedTime()); | 275 EXPECT_EQ(base::Time(), metadata.GetLastUsedTime()); |
| 254 EXPECT_EQ(0U, metadata.GetEntrySize()); | 276 EXPECT_EQ(0U, metadata.GetEntrySize()); |
| 255 | 277 |
| 256 // Confirm state after insert. | 278 // Confirm state after insert. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 343 ReturnIndexFile(); | 365 ReturnIndexFile(); |
| 344 | 366 |
| 345 EntryMetadata metadata; | 367 EntryMetadata metadata; |
| 346 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); | 368 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); |
| 347 EXPECT_LT( | 369 EXPECT_LT( |
| 348 now - base::TimeDelta::FromDays(2) - base::TimeDelta::FromSeconds(1), | 370 now - base::TimeDelta::FromDays(2) - base::TimeDelta::FromSeconds(1), |
| 349 metadata.GetLastUsedTime()); | 371 metadata.GetLastUsedTime()); |
| 350 EXPECT_GT( | 372 EXPECT_GT( |
| 351 now - base::TimeDelta::FromDays(2) + base::TimeDelta::FromSeconds(1), | 373 now - base::TimeDelta::FromDays(2) + base::TimeDelta::FromSeconds(1), |
| 352 metadata.GetLastUsedTime()); | 374 metadata.GetLastUsedTime()); |
| 353 EXPECT_EQ(475U, metadata.GetEntrySize()); | 375 EXPECT_EQ(RoundSize(475U), metadata.GetEntrySize()); |
| 354 | 376 |
| 355 index()->UpdateEntrySize(kHash1, 600u); | 377 index()->UpdateEntrySize(kHash1, 600u); |
| 356 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); | 378 EXPECT_TRUE(GetEntryForTesting(kHash1, &metadata)); |
| 357 EXPECT_EQ(600U, metadata.GetEntrySize()); | 379 EXPECT_EQ(RoundSize(600U), metadata.GetEntrySize()); |
| 358 EXPECT_EQ(1, index()->GetEntryCount()); | 380 EXPECT_EQ(1, index()->GetEntryCount()); |
| 359 } | 381 } |
| 360 | 382 |
| 361 TEST_F(SimpleIndexTest, GetEntryCount) { | 383 TEST_F(SimpleIndexTest, GetEntryCount) { |
| 362 EXPECT_EQ(0, index()->GetEntryCount()); | 384 EXPECT_EQ(0, index()->GetEntryCount()); |
| 363 index()->Insert(hashes_.at<1>()); | 385 index()->Insert(hashes_.at<1>()); |
| 364 EXPECT_EQ(1, index()->GetEntryCount()); | 386 EXPECT_EQ(1, index()->GetEntryCount()); |
| 365 index()->Insert(hashes_.at<2>()); | 387 index()->Insert(hashes_.at<2>()); |
| 366 EXPECT_EQ(2, index()->GetEntryCount()); | 388 EXPECT_EQ(2, index()->GetEntryCount()); |
| 367 index()->Insert(hashes_.at<3>()); | 389 index()->Insert(hashes_.at<3>()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 382 EXPECT_EQ(0, index()->GetEntryCount()); | 404 EXPECT_EQ(0, index()->GetEntryCount()); |
| 383 } | 405 } |
| 384 | 406 |
| 385 // Confirm that we get the results we expect from a simple init. | 407 // Confirm that we get the results we expect from a simple init. |
| 386 TEST_F(SimpleIndexTest, BasicInit) { | 408 TEST_F(SimpleIndexTest, BasicInit) { |
| 387 base::Time now(base::Time::Now()); | 409 base::Time now(base::Time::Now()); |
| 388 | 410 |
| 389 InsertIntoIndexFileReturn(hashes_.at<1>(), | 411 InsertIntoIndexFileReturn(hashes_.at<1>(), |
| 390 now - base::TimeDelta::FromDays(2), | 412 now - base::TimeDelta::FromDays(2), |
| 391 10u); | 413 10u); |
| 392 InsertIntoIndexFileReturn(hashes_.at<2>(), | 414 InsertIntoIndexFileReturn(hashes_.at<2>(), now - base::TimeDelta::FromDays(3), |
| 393 now - base::TimeDelta::FromDays(3), | 415 1000u); |
| 394 100u); | |
| 395 | 416 |
| 396 ReturnIndexFile(); | 417 ReturnIndexFile(); |
| 397 | 418 |
| 398 EntryMetadata metadata; | 419 EntryMetadata metadata; |
| 399 EXPECT_TRUE(GetEntryForTesting(hashes_.at<1>(), &metadata)); | 420 EXPECT_TRUE(GetEntryForTesting(hashes_.at<1>(), &metadata)); |
| 400 EXPECT_LT( | 421 EXPECT_LT( |
| 401 now - base::TimeDelta::FromDays(2) - base::TimeDelta::FromSeconds(1), | 422 now - base::TimeDelta::FromDays(2) - base::TimeDelta::FromSeconds(1), |
| 402 metadata.GetLastUsedTime()); | 423 metadata.GetLastUsedTime()); |
| 403 EXPECT_GT( | 424 EXPECT_GT( |
| 404 now - base::TimeDelta::FromDays(2) + base::TimeDelta::FromSeconds(1), | 425 now - base::TimeDelta::FromDays(2) + base::TimeDelta::FromSeconds(1), |
| 405 metadata.GetLastUsedTime()); | 426 metadata.GetLastUsedTime()); |
| 406 EXPECT_EQ(10U, metadata.GetEntrySize()); | 427 EXPECT_EQ(RoundSize(10U), metadata.GetEntrySize()); |
| 407 EXPECT_TRUE(GetEntryForTesting(hashes_.at<2>(), &metadata)); | 428 EXPECT_TRUE(GetEntryForTesting(hashes_.at<2>(), &metadata)); |
| 408 EXPECT_LT( | 429 EXPECT_LT( |
| 409 now - base::TimeDelta::FromDays(3) - base::TimeDelta::FromSeconds(1), | 430 now - base::TimeDelta::FromDays(3) - base::TimeDelta::FromSeconds(1), |
| 410 metadata.GetLastUsedTime()); | 431 metadata.GetLastUsedTime()); |
| 411 EXPECT_GT( | 432 EXPECT_GT( |
| 412 now - base::TimeDelta::FromDays(3) + base::TimeDelta::FromSeconds(1), | 433 now - base::TimeDelta::FromDays(3) + base::TimeDelta::FromSeconds(1), |
| 413 metadata.GetLastUsedTime()); | 434 metadata.GetLastUsedTime()); |
| 414 EXPECT_EQ(100U, metadata.GetEntrySize()); | 435 EXPECT_EQ(RoundSize(1000U), metadata.GetEntrySize()); |
|
gavinp
2017/08/04 18:42:54
I'm unhappy about mixing U and u in this code. I p
Maks Orlovich
2017/08/23 19:29:06
Made the stuff I touched use 'u', at least.
| |
| 415 } | 436 } |
| 416 | 437 |
| 417 // Remove something that's going to come in from the loaded index. | 438 // Remove something that's going to come in from the loaded index. |
| 418 TEST_F(SimpleIndexTest, RemoveBeforeInit) { | 439 TEST_F(SimpleIndexTest, RemoveBeforeInit) { |
| 419 const uint64_t kHash1 = hashes_.at<1>(); | 440 const uint64_t kHash1 = hashes_.at<1>(); |
| 420 index()->Remove(kHash1); | 441 index()->Remove(kHash1); |
| 421 | 442 |
| 422 InsertIntoIndexFileReturn(kHash1, | 443 InsertIntoIndexFileReturn(kHash1, |
| 423 base::Time::Now() - base::TimeDelta::FromDays(2), | 444 base::Time::Now() - base::TimeDelta::FromDays(2), |
| 424 10u); | 445 10u); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 | 546 |
| 526 EXPECT_TRUE(GetEntryForTesting(hashes_.at<5>(), &metadata)); | 547 EXPECT_TRUE(GetEntryForTesting(hashes_.at<5>(), &metadata)); |
| 527 | 548 |
| 528 EXPECT_GT( | 549 EXPECT_GT( |
| 529 now - base::TimeDelta::FromDays(6) + base::TimeDelta::FromSeconds(1), | 550 now - base::TimeDelta::FromDays(6) + base::TimeDelta::FromSeconds(1), |
| 530 metadata.GetLastUsedTime()); | 551 metadata.GetLastUsedTime()); |
| 531 EXPECT_LT( | 552 EXPECT_LT( |
| 532 now - base::TimeDelta::FromDays(6) - base::TimeDelta::FromSeconds(1), | 553 now - base::TimeDelta::FromDays(6) - base::TimeDelta::FromSeconds(1), |
| 533 metadata.GetLastUsedTime()); | 554 metadata.GetLastUsedTime()); |
| 534 | 555 |
| 535 EXPECT_EQ(100000U, metadata.GetEntrySize()); | 556 EXPECT_EQ(RoundSize(100000U), metadata.GetEntrySize()); |
| 536 } | 557 } |
| 537 | 558 |
| 538 TEST_F(SimpleIndexTest, BasicEviction) { | 559 TEST_F(SimpleIndexTest, BasicEviction) { |
| 539 base::Time now(base::Time::Now()); | 560 base::Time now(base::Time::Now()); |
| 540 index()->SetMaxSize(1000); | 561 index()->SetMaxSize(1000); |
| 541 InsertIntoIndexFileReturn(hashes_.at<1>(), | 562 InsertIntoIndexFileReturn(hashes_.at<1>(), |
| 542 now - base::TimeDelta::FromDays(2), | 563 now - base::TimeDelta::FromDays(2), |
| 543 475u); | 564 475u); |
| 544 index()->Insert(hashes_.at<2>()); | 565 index()->Insert(hashes_.at<2>()); |
| 545 index()->UpdateEntrySize(hashes_.at<2>(), 475u); | 566 index()->UpdateEntrySize(hashes_.at<2>(), 475u); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 SimpleIndex::EntrySet entry_set; | 635 SimpleIndex::EntrySet entry_set; |
| 615 index_file_->GetAndResetDiskWriteEntrySet(&entry_set); | 636 index_file_->GetAndResetDiskWriteEntrySet(&entry_set); |
| 616 | 637 |
| 617 uint64_t hash_key = kHash1; | 638 uint64_t hash_key = kHash1; |
| 618 base::Time now(base::Time::Now()); | 639 base::Time now(base::Time::Now()); |
| 619 ASSERT_EQ(1u, entry_set.size()); | 640 ASSERT_EQ(1u, entry_set.size()); |
| 620 EXPECT_EQ(hash_key, entry_set.begin()->first); | 641 EXPECT_EQ(hash_key, entry_set.begin()->first); |
| 621 const EntryMetadata& entry1(entry_set.begin()->second); | 642 const EntryMetadata& entry1(entry_set.begin()->second); |
| 622 EXPECT_LT(now - base::TimeDelta::FromMinutes(1), entry1.GetLastUsedTime()); | 643 EXPECT_LT(now - base::TimeDelta::FromMinutes(1), entry1.GetLastUsedTime()); |
| 623 EXPECT_GT(now + base::TimeDelta::FromMinutes(1), entry1.GetLastUsedTime()); | 644 EXPECT_GT(now + base::TimeDelta::FromMinutes(1), entry1.GetLastUsedTime()); |
| 624 EXPECT_EQ(20U, entry1.GetEntrySize()); | 645 EXPECT_EQ(RoundSize(20U), entry1.GetEntrySize()); |
| 625 } | 646 } |
| 626 | 647 |
| 627 TEST_F(SimpleIndexTest, DiskWritePostponed) { | 648 TEST_F(SimpleIndexTest, DiskWritePostponed) { |
| 628 index()->SetMaxSize(1000); | 649 index()->SetMaxSize(1000); |
| 629 ReturnIndexFile(); | 650 ReturnIndexFile(); |
| 630 | 651 |
| 631 EXPECT_FALSE(index()->write_to_disk_timer_.IsRunning()); | 652 EXPECT_FALSE(index()->write_to_disk_timer_.IsRunning()); |
| 632 | 653 |
| 633 index()->Insert(hashes_.at<1>()); | 654 index()->Insert(hashes_.at<1>()); |
| 634 index()->UpdateEntrySize(hashes_.at<1>(), 20u); | 655 index()->UpdateEntrySize(hashes_.at<1>(), 20u); |
| 635 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning()); | 656 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning()); |
| 636 base::TimeTicks expected_trigger( | 657 base::TimeTicks expected_trigger( |
| 637 index()->write_to_disk_timer_.desired_run_time()); | 658 index()->write_to_disk_timer_.desired_run_time()); |
| 638 | 659 |
| 639 WaitForTimeChange(); | 660 WaitForTimeChange(); |
| 640 EXPECT_EQ(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); | 661 EXPECT_EQ(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); |
| 641 index()->Insert(hashes_.at<2>()); | 662 index()->Insert(hashes_.at<2>()); |
| 642 index()->UpdateEntrySize(hashes_.at<2>(), 40u); | 663 index()->UpdateEntrySize(hashes_.at<2>(), 40u); |
| 643 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning()); | 664 EXPECT_TRUE(index()->write_to_disk_timer_.IsRunning()); |
| 644 EXPECT_LT(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); | 665 EXPECT_LT(expected_trigger, index()->write_to_disk_timer_.desired_run_time()); |
| 645 index()->write_to_disk_timer_.Stop(); | 666 index()->write_to_disk_timer_.Stop(); |
| 646 } | 667 } |
| 647 | 668 |
| 648 } // namespace disk_cache | 669 } // namespace disk_cache |
| OLD | NEW |