Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: net/http/http_cache_unittest.cc

Issue 2539323003: [HttpCacheTransaction] Ignore vary check for WriteMetadata requests (Closed)
Patch Set: Nits Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 6770 matching lines...) Expand 10 before | Expand all | Expand 10 after
6781 6781
6782 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction, 6782 RunTransactionTestWithResponseInfo(cache.http_cache(), kSimpleGET_Transaction,
6783 &response); 6783 &response);
6784 EXPECT_TRUE(response.metadata.get() == NULL); 6784 EXPECT_TRUE(response.metadata.get() == NULL);
6785 6785
6786 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 6786 EXPECT_EQ(1, cache.network_layer()->transaction_count());
6787 EXPECT_EQ(2, cache.disk_cache()->open_count()); 6787 EXPECT_EQ(2, cache.disk_cache()->open_count());
6788 EXPECT_EQ(1, cache.disk_cache()->create_count()); 6788 EXPECT_EQ(1, cache.disk_cache()->create_count());
6789 } 6789 }
6790 6790
6791 // Tests that we ignore VARY checks when writing metadata since the request
6792 // headers for the WriteMetadata transaction are made up.
6793 TEST(HttpCache, WriteMetadata_IgnoreVary) {
6794 MockHttpCache cache;
6795
6796 // Write to the cache
6797 HttpResponseInfo response;
6798 ScopedMockTransaction transaction(kSimpleGET_Transaction);
6799 transaction.request_headers = "accept-encoding: gzip\r\n";
6800 transaction.response_headers =
6801 "Vary: accept-encoding\n"
6802 "Cache-Control: max-age=10000\n";
6803
6804 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction,
6805 &response);
6806 EXPECT_FALSE(response.metadata);
6807
6808 // Attempt to write meta data to the same entry.
6809 scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(50));
6810 memset(buf->data(), 0, buf->size());
6811 base::strlcpy(buf->data(), "Hi there", buf->size());
6812 cache.http_cache()->WriteMetadata(GURL(transaction.url), DEFAULT_PRIORITY,
6813 response.response_time, buf.get(),
6814 buf->size());
6815
6816 // Makes sure we finish pending operations.
6817 base::RunLoop().RunUntilIdle();
6818
6819 RunTransactionTestWithResponseInfo(cache.http_cache(), transaction,
6820 &response);
6821 ASSERT_TRUE(response.metadata);
6822 EXPECT_EQ(50, response.metadata->size());
6823 EXPECT_EQ(0, strcmp(response.metadata->data(), "Hi there"));
6824
6825 EXPECT_EQ(1, cache.network_layer()->transaction_count());
6826 EXPECT_EQ(2, cache.disk_cache()->open_count());
6827 EXPECT_EQ(1, cache.disk_cache()->create_count());
6828 }
6829
6830 TEST(HttpCache, SkipVaryCheck) {
6831 MockHttpCache cache;
6832
6833 // Write a simple vary transaction to the cache.
6834 HttpResponseInfo response;
6835 ScopedMockTransaction transaction(kSimpleGET_Transaction);
6836 transaction.request_headers = "accept-encoding: gzip\r\n";
6837 transaction.response_headers =
6838 "Vary: accept-encoding\n"
6839 "Cache-Control: max-age=10000\n";
6840 RunTransactionTest(cache.http_cache(), transaction);
6841
6842 // Change the request headers so that the request doesn't match due to vary.
6843 // The request should fail.
6844 transaction.load_flags = LOAD_ONLY_FROM_CACHE;
6845 transaction.request_headers = "accept-encoding: foo\r\n";
6846 transaction.return_code = ERR_CACHE_MISS;
6847 RunTransactionTest(cache.http_cache(), transaction);
6848
6849 // Change the load flags to ignore vary checks, the request should now hit.
6850 transaction.load_flags = LOAD_ONLY_FROM_CACHE | LOAD_SKIP_VARY_CHECK;
6851 transaction.return_code = OK;
6852 RunTransactionTest(cache.http_cache(), transaction);
6853 }
6854
6791 // Tests that we only return valid entries with LOAD_ONLY_FROM_CACHE 6855 // Tests that we only return valid entries with LOAD_ONLY_FROM_CACHE
6792 // transactions unless LOAD_SKIP_CACHE_VALIDATION is set. 6856 // transactions unless LOAD_SKIP_CACHE_VALIDATION is set.
6793 TEST(HttpCache, ValidLoadOnlyFromCache) { 6857 TEST(HttpCache, ValidLoadOnlyFromCache) {
6794 MockHttpCache cache; 6858 MockHttpCache cache;
6795 base::SimpleTestClock* clock = new base::SimpleTestClock(); 6859 base::SimpleTestClock* clock = new base::SimpleTestClock();
6796 cache.http_cache()->SetClockForTesting(base::WrapUnique(clock)); 6860 cache.http_cache()->SetClockForTesting(base::WrapUnique(clock));
6797 cache.network_layer()->SetClock(clock); 6861 cache.network_layer()->SetClock(clock);
6798 6862
6799 // Write a resource that will expire in 100 seconds. 6863 // Write a resource that will expire in 100 seconds.
6800 ScopedMockTransaction transaction(kSimpleGET_Transaction); 6864 ScopedMockTransaction transaction(kSimpleGET_Transaction);
(...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after
8190 RunTransactionTestWithResponseInfo(cache.http_cache(), 8254 RunTransactionTestWithResponseInfo(cache.http_cache(),
8191 kTypicalGET_Transaction, &response_info); 8255 kTypicalGET_Transaction, &response_info);
8192 8256
8193 EXPECT_FALSE(response_info.was_cached); 8257 EXPECT_FALSE(response_info.was_cached);
8194 EXPECT_TRUE(response_info.network_accessed); 8258 EXPECT_TRUE(response_info.network_accessed);
8195 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE, 8259 EXPECT_EQ(CacheEntryStatus::ENTRY_CANT_CONDITIONALIZE,
8196 response_info.cache_entry_status); 8260 response_info.cache_entry_status);
8197 } 8261 }
8198 8262
8199 } // namespace net 8263 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache_transaction.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698