| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
| 6 | 6 |
| 7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 //----------------------------------------------------------------------------- | 66 //----------------------------------------------------------------------------- |
| 67 // mock disk cache (a very basic memory cache implementation) | 67 // mock disk cache (a very basic memory cache implementation) |
| 68 | 68 |
| 69 static const int kNumCacheEntryDataIndices = 3; | 69 static const int kNumCacheEntryDataIndices = 3; |
| 70 | 70 |
| 71 class MockDiskEntry : public disk_cache::Entry, | 71 class MockDiskEntry : public disk_cache::Entry, |
| 72 public base::RefCounted<MockDiskEntry> { | 72 public base::RefCounted<MockDiskEntry> { |
| 73 public: | 73 public: |
| 74 MockDiskEntry() | 74 MockDiskEntry() |
| 75 : test_mode_(0), doomed_(false), sparse_(false), fail_requests_(false), | 75 : test_mode_(0), doomed_(false), sparse_(false), |
| 76 busy_(false), delayed_(false) { | 76 fail_requests_(false), busy_(false), delayed_(false) { |
| 77 } | 77 } |
| 78 | 78 |
| 79 explicit MockDiskEntry(const std::string& key) | 79 explicit MockDiskEntry(const std::string& key) |
| 80 : key_(key), doomed_(false), sparse_(false), fail_requests_(false), | 80 : key_(key), doomed_(false), sparse_(false), |
| 81 busy_(false), delayed_(false) { | 81 fail_requests_(false), busy_(false), delayed_(false) { |
| 82 test_mode_ = GetTestModeForEntry(key); | 82 test_mode_ = GetTestModeForEntry(key); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool is_doomed() const { return doomed_; } | 85 bool is_doomed() const { return doomed_; } |
| 86 | 86 |
| 87 virtual void Doom() { | 87 virtual void Doom() { |
| 88 doomed_ = true; | 88 doomed_ = true; |
| 89 } | 89 } |
| 90 | 90 |
| 91 virtual void Close() { | 91 virtual void Close() { |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 net::CompletionCallback* callback) { | 480 net::CompletionCallback* callback) { |
| 481 return net::ERR_NOT_IMPLEMENTED; | 481 return net::ERR_NOT_IMPLEMENTED; |
| 482 } | 482 } |
| 483 | 483 |
| 484 virtual void EndEnumeration(void** iter) {} | 484 virtual void EndEnumeration(void** iter) {} |
| 485 | 485 |
| 486 virtual void GetStats( | 486 virtual void GetStats( |
| 487 std::vector<std::pair<std::string, std::string> >* stats) { | 487 std::vector<std::pair<std::string, std::string> >* stats) { |
| 488 } | 488 } |
| 489 | 489 |
| 490 virtual void OnExternalCacheHit(const std::string& key) {} |
| 491 |
| 490 // returns number of times a cache entry was successfully opened | 492 // returns number of times a cache entry was successfully opened |
| 491 int open_count() const { return open_count_; } | 493 int open_count() const { return open_count_; } |
| 492 | 494 |
| 493 // returns number of times a cache entry was successfully created | 495 // returns number of times a cache entry was successfully created |
| 494 int create_count() const { return create_count_; } | 496 int create_count() const { return create_count_; } |
| 495 | 497 |
| 496 // Fail any subsequent CreateEntry and OpenEntry. | 498 // Fail any subsequent CreateEntry and OpenEntry. |
| 497 void set_fail_requests() { fail_requests_ = true; } | 499 void set_fail_requests() { fail_requests_ = true; } |
| 498 | 500 |
| 499 // Return entries that fail some of their requests. | 501 // Return entries that fail some of their requests. |
| (...skipping 4592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5092 // Now return 200 when validating the entry so the metadata will be lost. | 5094 // Now return 200 when validating the entry so the metadata will be lost. |
| 5093 MockTransaction trans2(kTypicalGET_Transaction); | 5095 MockTransaction trans2(kTypicalGET_Transaction); |
| 5094 trans2.load_flags = net::LOAD_VALIDATE_CACHE; | 5096 trans2.load_flags = net::LOAD_VALIDATE_CACHE; |
| 5095 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); | 5097 RunTransactionTestWithResponseInfo(cache.http_cache(), trans2, &response); |
| 5096 EXPECT_TRUE(response.metadata.get() == NULL); | 5098 EXPECT_TRUE(response.metadata.get() == NULL); |
| 5097 | 5099 |
| 5098 EXPECT_EQ(3, cache.network_layer()->transaction_count()); | 5100 EXPECT_EQ(3, cache.network_layer()->transaction_count()); |
| 5099 EXPECT_EQ(4, cache.disk_cache()->open_count()); | 5101 EXPECT_EQ(4, cache.disk_cache()->open_count()); |
| 5100 EXPECT_EQ(1, cache.disk_cache()->create_count()); | 5102 EXPECT_EQ(1, cache.disk_cache()->create_count()); |
| 5101 } | 5103 } |
| OLD | NEW |