| Index: net/http/http_cache_unittest.cc
|
| diff --git a/net/http/http_cache_unittest.cc b/net/http/http_cache_unittest.cc
|
| index 493c4e630f6fe9d37c757a0ff497d8d194077721..db9aa2eee12483d1a0ad802a8c71e6943b90aa5b 100644
|
| --- a/net/http/http_cache_unittest.cc
|
| +++ b/net/http/http_cache_unittest.cc
|
| @@ -72,13 +72,13 @@ class MockDiskEntry : public disk_cache::Entry,
|
| public base::RefCounted<MockDiskEntry> {
|
| public:
|
| MockDiskEntry()
|
| - : test_mode_(0), doomed_(false), sparse_(false), fail_requests_(false),
|
| - busy_(false), delayed_(false) {
|
| + : test_mode_(0), rank_(0), doomed_(false), sparse_(false),
|
| + fail_requests_(false), busy_(false), delayed_(false) {
|
| }
|
|
|
| explicit MockDiskEntry(const std::string& key)
|
| - : key_(key), doomed_(false), sparse_(false), fail_requests_(false),
|
| - busy_(false), delayed_(false) {
|
| + : key_(key), rank_(0), doomed_(false), sparse_(false),
|
| + fail_requests_(false), busy_(false), delayed_(false) {
|
| test_mode_ = GetTestModeForEntry(key);
|
| }
|
|
|
| @@ -279,6 +279,12 @@ class MockDiskEntry : public disk_cache::Entry,
|
| return net::ERR_IO_PENDING;
|
| }
|
|
|
| + void UpdateRankForExternalCacheHit() {
|
| + ++rank_;
|
| + }
|
| +
|
| + int rank() const { return rank_; }
|
| +
|
| // Fail most subsequent requests.
|
| void set_fail_requests() { fail_requests_ = true; }
|
|
|
| @@ -353,6 +359,7 @@ class MockDiskEntry : public disk_cache::Entry,
|
| std::string key_;
|
| std::vector<char> data_[kNumCacheEntryDataIndices];
|
| int test_mode_;
|
| + int rank_;
|
| bool doomed_;
|
| bool sparse_;
|
| bool fail_requests_;
|
| @@ -5099,3 +5106,39 @@ TEST(HttpCache, ReadMetadata) {
|
| EXPECT_EQ(4, cache.disk_cache()->open_count());
|
| EXPECT_EQ(1, cache.disk_cache()->create_count());
|
| }
|
| +
|
| +TEST(HttpCache, ExternalCacheHit_Success) {
|
| + MockHttpCache cache;
|
| +
|
| + RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction);
|
| +
|
| + disk_cache::Entry* entry;
|
| + ASSERT_TRUE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry));
|
| + MockDiskEntry* mock_entry = static_cast<MockDiskEntry*>(entry);
|
| + EXPECT_EQ(0, mock_entry->rank());
|
| +
|
| + cache.http_cache()->ReportExternalCacheHit(GURL(kSimpleGET_Transaction.url),
|
| + kSimpleGET_Transaction.method);
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + EXPECT_EQ(1, cache.network_layer()->transaction_count());
|
| + EXPECT_EQ(2, cache.disk_cache()->open_count());
|
| + EXPECT_EQ(1, cache.disk_cache()->create_count());
|
| + EXPECT_EQ(1, mock_entry->rank());
|
| +
|
| + entry->Close();
|
| +}
|
| +
|
| +TEST(HttpCache, ExternalCacheHit_NotInCache) {
|
| + MockHttpCache cache;
|
| +
|
| + cache.http_cache()->ReportExternalCacheHit(GURL(kSimpleGET_Transaction.url),
|
| + kSimpleGET_Transaction.method);
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + disk_cache::Entry* entry;
|
| + EXPECT_FALSE(cache.OpenBackendEntry(kSimpleGET_Transaction.url, &entry));
|
| + EXPECT_EQ(0, cache.network_layer()->transaction_count());
|
| + EXPECT_EQ(0, cache.disk_cache()->open_count());
|
| + EXPECT_EQ(0, cache.disk_cache()->create_count());
|
| +}
|
|
|