| 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 "net/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 6752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6763 // Skipping cache validation should still return a response. | 6763 // Skipping cache validation should still return a response. |
| 6764 transaction.load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION; | 6764 transaction.load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION; |
| 6765 RunTransactionTest(cache.http_cache(), transaction); | 6765 RunTransactionTest(cache.http_cache(), transaction); |
| 6766 | 6766 |
| 6767 // If the cache entry is checked for validitiy, it should fail. | 6767 // If the cache entry is checked for validitiy, it should fail. |
| 6768 transaction.load_flags = LOAD_ONLY_FROM_CACHE; | 6768 transaction.load_flags = LOAD_ONLY_FROM_CACHE; |
| 6769 transaction.return_code = ERR_CACHE_MISS; | 6769 transaction.return_code = ERR_CACHE_MISS; |
| 6770 RunTransactionTest(cache.http_cache(), transaction); | 6770 RunTransactionTest(cache.http_cache(), transaction); |
| 6771 } | 6771 } |
| 6772 | 6772 |
| 6773 TEST(HttpCache, InvalidLoadFlagCombination) { |
| 6774 MockHttpCache cache; |
| 6775 |
| 6776 // Put the resource in the cache. |
| 6777 RunTransactionTest(cache.http_cache(), kSimpleGET_Transaction); |
| 6778 |
| 6779 // Now try to fetch it again, but with a flag combination disallowing both |
| 6780 // cache and network access. |
| 6781 ScopedMockTransaction transaction(kSimpleGET_Transaction); |
| 6782 // DevTools relies on this combination of flags for "disable cache" mode |
| 6783 // when a resource is only supposed to be loaded from cache. |
| 6784 transaction.load_flags = LOAD_ONLY_FROM_CACHE | LOAD_BYPASS_CACHE; |
| 6785 transaction.return_code = ERR_CACHE_MISS; |
| 6786 RunTransactionTest(cache.http_cache(), transaction); |
| 6787 } |
| 6788 |
| 6773 // Tests that we can read metadata after validating the entry and with READ mode | 6789 // Tests that we can read metadata after validating the entry and with READ mode |
| 6774 // transactions. | 6790 // transactions. |
| 6775 TEST(HttpCache, ReadMetadata) { | 6791 TEST(HttpCache, ReadMetadata) { |
| 6776 MockHttpCache cache; | 6792 MockHttpCache cache; |
| 6777 | 6793 |
| 6778 // Write to the cache | 6794 // Write to the cache |
| 6779 HttpResponseInfo response; | 6795 HttpResponseInfo response; |
| 6780 RunTransactionTestWithResponseInfo(cache.http_cache(), | 6796 RunTransactionTestWithResponseInfo(cache.http_cache(), |
| 6781 kTypicalGET_Transaction, &response); | 6797 kTypicalGET_Transaction, &response); |
| 6782 EXPECT_TRUE(response.metadata.get() == NULL); | 6798 EXPECT_TRUE(response.metadata.get() == NULL); |
| (...skipping 1346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8129 RunTransactionTestWithResponseInfo(cache.http_cache(), | 8145 RunTransactionTestWithResponseInfo(cache.http_cache(), |
| 8130 kTypicalGET_Transaction, &response_info); | 8146 kTypicalGET_Transaction, &response_info); |
| 8131 | 8147 |
| 8132 EXPECT_FALSE(response_info.was_cached); | 8148 EXPECT_FALSE(response_info.was_cached); |
| 8133 EXPECT_TRUE(response_info.network_accessed); | 8149 EXPECT_TRUE(response_info.network_accessed); |
| 8134 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, | 8150 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, |
| 8135 response_info.cache_entry_status); | 8151 response_info.cache_entry_status); |
| 8136 } | 8152 } |
| 8137 | 8153 |
| 8138 } // namespace net | 8154 } // namespace net |
| OLD | NEW |