OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/metrics/field_trial.h" | |
13 #include "base/metrics/field_trial_param_associator.h" | |
12 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
15 #include "base/test/histogram_tester.h" | 17 #include "base/test/histogram_tester.h" |
18 #include "base/test/mock_entropy_provider.h" | |
19 #include "base/test/scoped_feature_list.h" | |
16 #include "base/threading/platform_thread.h" | 20 #include "base/threading/platform_thread.h" |
17 #include "net/base/completion_callback.h" | 21 #include "net/base/completion_callback.h" |
18 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
19 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
20 #include "net/base/test_completion_callback.h" | 24 #include "net/base/test_completion_callback.h" |
21 #include "net/disk_cache/blockfile/backend_impl.h" | 25 #include "net/disk_cache/blockfile/backend_impl.h" |
22 #include "net/disk_cache/blockfile/entry_impl.h" | 26 #include "net/disk_cache/blockfile/entry_impl.h" |
23 #include "net/disk_cache/cache_util.h" | 27 #include "net/disk_cache/cache_util.h" |
24 #include "net/disk_cache/disk_cache_test_base.h" | 28 #include "net/disk_cache/disk_cache_test_base.h" |
25 #include "net/disk_cache/disk_cache_test_util.h" | 29 #include "net/disk_cache/disk_cache_test_util.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 void DoomNormalEntry(); | 71 void DoomNormalEntry(); |
68 void DoomEntryNextToOpenEntry(); | 72 void DoomEntryNextToOpenEntry(); |
69 void DoomedEntry(int stream_index); | 73 void DoomedEntry(int stream_index); |
70 void BasicSparseIO(); | 74 void BasicSparseIO(); |
71 void HugeSparseIO(); | 75 void HugeSparseIO(); |
72 void GetAvailableRange(); | 76 void GetAvailableRange(); |
73 void CouldBeSparse(); | 77 void CouldBeSparse(); |
74 void UpdateSparseEntry(); | 78 void UpdateSparseEntry(); |
75 void DoomSparseEntry(); | 79 void DoomSparseEntry(); |
76 void PartialSparseEntry(); | 80 void PartialSparseEntry(); |
77 bool SimpleCacheMakeBadChecksumEntry(const std::string& key, int* data_size); | 81 bool SimpleCacheMakeBadChecksumEntry(const std::string& key, int data_size); |
78 bool SimpleCacheThirdStreamFileExists(const char* key); | 82 bool SimpleCacheThirdStreamFileExists(const char* key); |
79 void SyncDoomEntry(const char* key); | 83 void SyncDoomEntry(const char* key); |
80 }; | 84 }; |
81 | 85 |
82 // This part of the test runs on the background thread. | 86 // This part of the test runs on the background thread. |
83 void DiskCacheEntryTest::InternalSyncIOBackground(disk_cache::Entry* entry) { | 87 void DiskCacheEntryTest::InternalSyncIOBackground(disk_cache::Entry* entry) { |
84 const int kSize1 = 10; | 88 const int kSize1 = 10; |
85 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); | 89 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize1)); |
86 CacheTestFillBuffer(buffer1->data(), kSize1, false); | 90 CacheTestFillBuffer(buffer1->data(), kSize1, false); |
87 EXPECT_EQ( | 91 EXPECT_EQ( |
(...skipping 2536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2624 // it on a doomed entry, if it was previously lazily omitted. | 2628 // it on a doomed entry, if it was previously lazily omitted. |
2625 for (int i = 0; i < disk_cache::kSimpleEntryStreamCount - 1; ++i) { | 2629 for (int i = 0; i < disk_cache::kSimpleEntryStreamCount - 1; ++i) { |
2626 EXPECT_THAT(DoomAllEntries(), IsOk()); | 2630 EXPECT_THAT(DoomAllEntries(), IsOk()); |
2627 DoomedEntry(i); | 2631 DoomedEntry(i); |
2628 } | 2632 } |
2629 } | 2633 } |
2630 | 2634 |
2631 // Creates an entry with corrupted last byte in stream 0. | 2635 // Creates an entry with corrupted last byte in stream 0. |
2632 // Requires SimpleCacheMode. | 2636 // Requires SimpleCacheMode. |
2633 bool DiskCacheEntryTest::SimpleCacheMakeBadChecksumEntry(const std::string& key, | 2637 bool DiskCacheEntryTest::SimpleCacheMakeBadChecksumEntry(const std::string& key, |
2634 int* data_size) { | 2638 int data_size) { |
2635 disk_cache::Entry* entry = NULL; | 2639 disk_cache::Entry* entry = NULL; |
2636 | 2640 |
2637 if (CreateEntry(key, &entry) != net::OK || !entry) { | 2641 if (CreateEntry(key, &entry) != net::OK || !entry) { |
2638 LOG(ERROR) << "Could not create entry"; | 2642 LOG(ERROR) << "Could not create entry"; |
2639 return false; | 2643 return false; |
2640 } | 2644 } |
2641 | 2645 |
2642 const char data[] = "this is very good data"; | 2646 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(data_size)); |
2643 const int kDataSize = arraysize(data); | 2647 memset(buffer->data(), 'A', data_size); |
2644 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kDataSize)); | |
2645 base::strlcpy(buffer->data(), data, kDataSize); | |
2646 | 2648 |
2647 EXPECT_EQ(kDataSize, WriteData(entry, 1, 0, buffer.get(), kDataSize, false)); | 2649 EXPECT_EQ(data_size, WriteData(entry, 1, 0, buffer.get(), data_size, false)); |
2648 entry->Close(); | 2650 entry->Close(); |
2649 entry = NULL; | 2651 entry = NULL; |
2650 | 2652 |
2651 // Corrupt the last byte of the data. | 2653 // Corrupt the last byte of the data. |
2652 base::FilePath entry_file0_path = cache_path_.AppendASCII( | 2654 base::FilePath entry_file0_path = cache_path_.AppendASCII( |
2653 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0)); | 2655 disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0)); |
2654 base::File entry_file0(entry_file0_path, | 2656 base::File entry_file0(entry_file0_path, |
2655 base::File::FLAG_WRITE | base::File::FLAG_OPEN); | 2657 base::File::FLAG_WRITE | base::File::FLAG_OPEN); |
2656 if (!entry_file0.IsValid()) | 2658 if (!entry_file0.IsValid()) |
2657 return false; | 2659 return false; |
2658 | 2660 |
2659 int64_t file_offset = | 2661 int64_t file_offset = |
2660 sizeof(disk_cache::SimpleFileHeader) + key.size() + kDataSize - 2; | 2662 sizeof(disk_cache::SimpleFileHeader) + key.size() + data_size - 2; |
2661 EXPECT_EQ(1, entry_file0.Write(file_offset, "X", 1)); | 2663 EXPECT_EQ(1, entry_file0.Write(file_offset, "X", 1)); |
2662 *data_size = kDataSize; | |
2663 return true; | 2664 return true; |
2664 } | 2665 } |
2665 | 2666 |
2666 // Tests that the simple cache can detect entries that have bad data. | |
2667 TEST_F(DiskCacheEntryTest, SimpleCacheBadChecksum) { | 2667 TEST_F(DiskCacheEntryTest, SimpleCacheBadChecksum) { |
2668 base::HistogramTester histogram_tester; | 2668 base::HistogramTester histogram_tester; |
2669 SetSimpleCacheMode(); | 2669 SetSimpleCacheMode(); |
2670 InitCache(); | 2670 InitCache(); |
2671 | 2671 |
2672 const char key[] = "the first key"; | 2672 const char key[] = "the first key"; |
2673 int size_unused; | 2673 const int kLargeSize = 50000; |
2674 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, &size_unused)); | 2674 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, kLargeSize)); |
2675 | 2675 |
2676 disk_cache::Entry* entry = NULL; | 2676 disk_cache::Entry* entry = NULL; |
2677 | 2677 |
2678 // Open the entry. | 2678 // Open the entry. Can't spot the checksum that quickly with it so |
2679 // huge. | |
2679 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); | 2680 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); |
2680 ScopedEntryPtr entry_closer(entry); | 2681 ScopedEntryPtr entry_closer(entry); |
2681 | 2682 |
2682 const int kReadBufferSize = 200; | 2683 EXPECT_GE(kLargeSize, entry->GetDataSize(1)); |
2683 EXPECT_GE(kReadBufferSize, entry->GetDataSize(1)); | 2684 scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kLargeSize)); |
2684 scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kReadBufferSize)); | |
2685 EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH, | 2685 EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH, |
2686 ReadData(entry, 1, 0, read_buffer.get(), kReadBufferSize)); | 2686 ReadData(entry, 1, 0, read_buffer.get(), kLargeSize)); |
2687 histogram_tester.ExpectUniqueSample( | 2687 histogram_tester.ExpectUniqueSample( |
2688 "SimpleCache.Http.ReadResult", | 2688 "SimpleCache.Http.ReadResult", |
2689 disk_cache::READ_RESULT_SYNC_CHECKSUM_FAILURE, 1); | 2689 disk_cache::READ_RESULT_SYNC_CHECKSUM_FAILURE, 1); |
2690 } | 2690 } |
2691 | 2691 |
2692 // Tests that an entry that has had an IO error occur can still be Doomed(). | 2692 // Tests that an entry that has had an IO error occur can still be Doomed(). |
2693 TEST_F(DiskCacheEntryTest, SimpleCacheErrorThenDoom) { | 2693 TEST_F(DiskCacheEntryTest, SimpleCacheErrorThenDoom) { |
2694 base::HistogramTester histogram_tester; | 2694 base::HistogramTester histogram_tester; |
2695 SetSimpleCacheMode(); | 2695 SetSimpleCacheMode(); |
2696 InitCache(); | 2696 InitCache(); |
2697 | 2697 |
2698 const char key[] = "the first key"; | 2698 const char key[] = "the first key"; |
2699 int size_unused; | 2699 const int kLargeSize = 50000; |
2700 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, &size_unused)); | 2700 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, kLargeSize)); |
2701 | 2701 |
2702 disk_cache::Entry* entry = NULL; | 2702 disk_cache::Entry* entry = NULL; |
2703 | 2703 |
2704 // Open the entry, forcing an IO error. | 2704 // Open the entry, forcing an IO error. |
2705 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); | 2705 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); |
2706 ScopedEntryPtr entry_closer(entry); | 2706 ScopedEntryPtr entry_closer(entry); |
2707 | 2707 |
2708 const int kReadBufferSize = 200; | 2708 EXPECT_GE(kLargeSize, entry->GetDataSize(1)); |
2709 EXPECT_GE(kReadBufferSize, entry->GetDataSize(1)); | 2709 scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kLargeSize)); |
2710 scoped_refptr<net::IOBuffer> read_buffer(new net::IOBuffer(kReadBufferSize)); | |
2711 EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH, | 2710 EXPECT_EQ(net::ERR_CACHE_CHECKSUM_MISMATCH, |
2712 ReadData(entry, 1, 0, read_buffer.get(), kReadBufferSize)); | 2711 ReadData(entry, 1, 0, read_buffer.get(), kLargeSize)); |
2713 histogram_tester.ExpectUniqueSample( | 2712 histogram_tester.ExpectUniqueSample( |
2714 "SimpleCache.Http.ReadResult", | 2713 "SimpleCache.Http.ReadResult", |
2715 disk_cache::READ_RESULT_SYNC_CHECKSUM_FAILURE, 1); | 2714 disk_cache::READ_RESULT_SYNC_CHECKSUM_FAILURE, 1); |
2716 entry->Doom(); // Should not crash. | 2715 entry->Doom(); // Should not crash. |
2717 } | 2716 } |
2718 | 2717 |
2719 bool TruncatePath(const base::FilePath& file_path, int64_t length) { | 2718 bool TruncatePath(const base::FilePath& file_path, int64_t length) { |
2720 base::File file(file_path, base::File::FLAG_WRITE | base::File::FLAG_OPEN); | 2719 base::File file(file_path, base::File::FLAG_WRITE | base::File::FLAG_OPEN); |
2721 if (!file.IsValid()) | 2720 if (!file.IsValid()) |
2722 return false; | 2721 return false; |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3438 | 3437 |
3439 // Tests that if a read and a following in-flight truncate are both in progress | 3438 // Tests that if a read and a following in-flight truncate are both in progress |
3440 // simultaniously that they both can occur successfully. See | 3439 // simultaniously that they both can occur successfully. See |
3441 // http://crbug.com/239223 | 3440 // http://crbug.com/239223 |
3442 TEST_F(DiskCacheEntryTest, SimpleCacheInFlightTruncate) { | 3441 TEST_F(DiskCacheEntryTest, SimpleCacheInFlightTruncate) { |
3443 SetSimpleCacheMode(); | 3442 SetSimpleCacheMode(); |
3444 InitCache(); | 3443 InitCache(); |
3445 | 3444 |
3446 const char key[] = "the first key"; | 3445 const char key[] = "the first key"; |
3447 | 3446 |
3448 const int kBufferSize = 1024; | 3447 const int kBufferSize = 50000; // to avoid quick read |
pasko
2017/08/04 01:28:34
The context is not easy to guess from this comment
Maks Orlovich
2017/08/04 18:35:43
Can't really give an exact number of that (since p
pasko
2017/08/09 12:28:21
Oh, my comment is about adding a constant and a co
| |
3449 scoped_refptr<net::IOBuffer> write_buffer(new net::IOBuffer(kBufferSize)); | 3448 scoped_refptr<net::IOBuffer> write_buffer(new net::IOBuffer(kBufferSize)); |
3450 CacheTestFillBuffer(write_buffer->data(), kBufferSize, false); | 3449 CacheTestFillBuffer(write_buffer->data(), kBufferSize, false); |
3451 | 3450 |
3452 disk_cache::Entry* entry = NULL; | 3451 disk_cache::Entry* entry = NULL; |
3453 ASSERT_THAT(CreateEntry(key, &entry), IsOk()); | 3452 ASSERT_THAT(CreateEntry(key, &entry), IsOk()); |
3454 | 3453 |
3455 EXPECT_EQ(kBufferSize, | 3454 EXPECT_EQ(kBufferSize, |
3456 WriteData(entry, 1, 0, write_buffer.get(), kBufferSize, false)); | 3455 WriteData(entry, 1, 0, write_buffer.get(), kBufferSize, false)); |
3457 entry->Close(); | 3456 entry->Close(); |
3458 entry = NULL; | 3457 entry = NULL; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3569 } | 3568 } |
3570 | 3569 |
3571 // Checking one more scenario of overlapped reading of a bad entry. | 3570 // Checking one more scenario of overlapped reading of a bad entry. |
3572 // Differs from the |SimpleCacheMultipleReadersCheckCRC| only by the order of | 3571 // Differs from the |SimpleCacheMultipleReadersCheckCRC| only by the order of |
3573 // last two reads. | 3572 // last two reads. |
3574 TEST_F(DiskCacheEntryTest, SimpleCacheMultipleReadersCheckCRC2) { | 3573 TEST_F(DiskCacheEntryTest, SimpleCacheMultipleReadersCheckCRC2) { |
3575 SetSimpleCacheMode(); | 3574 SetSimpleCacheMode(); |
3576 InitCache(); | 3575 InitCache(); |
3577 | 3576 |
3578 const char key[] = "key"; | 3577 const char key[] = "key"; |
3579 int size; | 3578 int size = 50000; |
3580 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, &size)); | 3579 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, size)); |
3581 | 3580 |
3582 scoped_refptr<net::IOBuffer> read_buffer1(new net::IOBuffer(size)); | 3581 scoped_refptr<net::IOBuffer> read_buffer1(new net::IOBuffer(size)); |
3583 scoped_refptr<net::IOBuffer> read_buffer2(new net::IOBuffer(size)); | 3582 scoped_refptr<net::IOBuffer> read_buffer2(new net::IOBuffer(size)); |
3584 | 3583 |
3585 // Advance the first reader a little. | 3584 // Advance the first reader a little. |
3586 disk_cache::Entry* entry = NULL; | 3585 disk_cache::Entry* entry = NULL; |
3587 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); | 3586 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); |
3588 ScopedEntryPtr entry_closer(entry); | 3587 ScopedEntryPtr entry_closer(entry); |
3589 EXPECT_EQ(1, ReadData(entry, 1, 0, read_buffer1.get(), 1)); | 3588 EXPECT_EQ(1, ReadData(entry, 1, 0, read_buffer1.get(), 1)); |
3590 | 3589 |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4315 // CHECK(temp_dir_.CreateUniqueTempDir()); | 4314 // CHECK(temp_dir_.CreateUniqueTempDir()); |
4316 // cache_path_ = temp_dir_.GetPath(); | 4315 // cache_path_ = temp_dir_.GetPath(); |
4317 disk_cache::DeleteCache(cache_path_, | 4316 disk_cache::DeleteCache(cache_path_, |
4318 true /* delete the dir, what we really want*/); | 4317 true /* delete the dir, what we really want*/); |
4319 | 4318 |
4320 disk_cache::Entry* entry; | 4319 disk_cache::Entry* entry; |
4321 std::string key("a key"); | 4320 std::string key("a key"); |
4322 ASSERT_THAT(CreateEntry(key, &entry), IsOk()); | 4321 ASSERT_THAT(CreateEntry(key, &entry), IsOk()); |
4323 entry->Close(); | 4322 entry->Close(); |
4324 } | 4323 } |
4324 | |
4325 class DiskCacheSimplePrefetchTest : public DiskCacheEntryTest { | |
4326 public: | |
4327 DiskCacheSimplePrefetchTest() | |
4328 : field_trial_list_(base::MakeUnique<base::FieldTrialList>( | |
4329 base::MakeUnique<base::MockEntropyProvider>())) {} | |
4330 | |
4331 enum { kEntrySize = 1024 }; | |
4332 | |
4333 void SetUp() override { | |
4334 payload_ = new net::IOBuffer(kEntrySize); | |
4335 CacheTestFillBuffer(payload_->data(), kEntrySize, false); | |
4336 DiskCacheEntryTest::SetUp(); | |
4337 } | |
4338 | |
4339 void SetupPrefetch(int size) { | |
4340 std::map<std::string, std::string> params; | |
4341 params[disk_cache::kSimplePrefetchBytesParam] = base::IntToString(size); | |
4342 scoped_feature_list_.InitAndEnableFeatureWithParameters( | |
4343 disk_cache::kSimpleCachePrefetchExperiment, params); | |
4344 } | |
4345 | |
4346 void InitCacheAndCreateEntry(const std::string& key) { | |
4347 SetSimpleCacheMode(); | |
4348 InitCache(); | |
4349 | |
4350 disk_cache::Entry* entry; | |
4351 ASSERT_EQ(net::OK, CreateEntry(key, &entry)); | |
4352 // Use stream 1 since that's what new prefetch stuff is about. | |
4353 ASSERT_EQ(kEntrySize, | |
4354 WriteData(entry, 1, 0, payload_.get(), kEntrySize, false)); | |
4355 entry->Close(); | |
4356 } | |
4357 | |
4358 void TryRead(const std::string& key) { | |
4359 disk_cache::Entry* entry = NULL; | |
4360 ASSERT_THAT(OpenEntry(key, &entry), IsOk()); | |
4361 scoped_refptr<net::IOBuffer> read_buf(new net::IOBuffer(kEntrySize)); | |
4362 EXPECT_EQ(kEntrySize, ReadData(entry, 1, 0, read_buf.get(), kEntrySize)); | |
4363 EXPECT_EQ(0, memcmp(read_buf->data(), payload_->data(), kEntrySize)); | |
4364 entry->Close(); | |
4365 } | |
4366 | |
4367 protected: | |
4368 scoped_refptr<net::IOBuffer> payload_; | |
4369 | |
4370 // Need to have the one "global" trial list before we change things. | |
4371 std::unique_ptr<base::FieldTrialList> field_trial_list_; | |
4372 base::test::ScopedFeatureList scoped_feature_list_; | |
4373 }; | |
4374 | |
4375 TEST_F(DiskCacheSimplePrefetchTest, NoPrefetch) { | |
4376 base::HistogramTester histogram_tester; | |
4377 SetupPrefetch(0); | |
4378 | |
4379 const char kKey[] = "a key"; | |
4380 InitCacheAndCreateEntry(kKey); | |
4381 TryRead(kKey); | |
4382 | |
4383 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncOpenDidPrefetch", | |
4384 false, 1); | |
4385 histogram_tester.ExpectUniqueSample( | |
4386 "SimpleCache.Http.ReadStream1FromPrefetched", false, 1); | |
4387 } | |
4388 | |
4389 TEST_F(DiskCacheSimplePrefetchTest, YesPrefetch) { | |
4390 base::HistogramTester histogram_tester; | |
4391 SetupPrefetch(2 * kEntrySize); | |
4392 | |
4393 const char kKey[] = "a key"; | |
4394 InitCacheAndCreateEntry(kKey); | |
4395 TryRead(kKey); | |
4396 | |
4397 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncOpenDidPrefetch", | |
4398 true, 1); | |
4399 histogram_tester.ExpectUniqueSample( | |
4400 "SimpleCache.Http.ReadStream1FromPrefetched", true, 1); | |
4401 } | |
4402 | |
4403 TEST_F(DiskCacheSimplePrefetchTest, YesPrefetchNoRead) { | |
4404 base::HistogramTester histogram_tester; | |
4405 SetupPrefetch(2 * kEntrySize); | |
4406 | |
4407 const char kKey[] = "a key"; | |
4408 InitCacheAndCreateEntry(kKey); | |
4409 | |
4410 disk_cache::Entry* entry = NULL; | |
4411 ASSERT_THAT(OpenEntry(kKey, &entry), IsOk()); | |
4412 entry->Close(); | |
4413 | |
4414 histogram_tester.ExpectUniqueSample("SimpleCache.Http.SyncOpenDidPrefetch", | |
4415 true, 1); | |
4416 // Have to use GetHistogramSamplesSinceCreation here since it's the only | |
4417 // API that handles the cases where the histogram hasn't even been created. | |
4418 std::unique_ptr<base::HistogramSamples> samples( | |
4419 histogram_tester.GetHistogramSamplesSinceCreation( | |
4420 "SimpleCache.Http.ReadStream1FromPrefetched")); | |
4421 EXPECT_EQ(0, samples->TotalCount()); | |
4422 } | |
4423 | |
4424 // This makes sure we detect checksum error on entry that's small enough to be | |
4425 // prefetched. This is like DiskCacheEntryTest.BadChecksum, but we make sure | |
4426 // to configure prefetch explicitly. | |
4427 TEST_F(DiskCacheSimplePrefetchTest, BadChecksumSmall) { | |
4428 SetupPrefetch(1024); // bigger than stuff below. | |
4429 SetSimpleCacheMode(); | |
4430 InitCache(); | |
4431 | |
4432 const char key[] = "the first key"; | |
4433 ASSERT_TRUE(SimpleCacheMakeBadChecksumEntry(key, 10)); | |
4434 | |
4435 disk_cache::Entry* entry = NULL; | |
4436 | |
4437 // Open the entry. Since we made a small entry, we will detect the CRC | |
4438 // problem at open. | |
4439 EXPECT_THAT(OpenEntry(key, &entry), IsError(net::ERR_FAILED)); | |
4440 } | |
OLD | NEW |