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

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

Issue 345019: Http cache: Allow multiple external validation headers.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_cache.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) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_vector.h" 9 #include "base/scoped_vector.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 1761 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 "" 1772 ""
1773 }; 1773 };
1774 1774
1775 // Different etag from original response. 1775 // Different etag from original response.
1776 const char* kExtraRequestHeaders = "If-None-Match: \"Foo2\"\n"; 1776 const char* kExtraRequestHeaders = "If-None-Match: \"Foo2\"\n";
1777 1777
1778 ConditionalizedRequestUpdatesCacheHelper( 1778 ConditionalizedRequestUpdatesCacheHelper(
1779 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders); 1779 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders);
1780 } 1780 }
1781 1781
1782 // Test that doing an externally conditionalized request with both if-none-match
1783 // and if-modified-since updates the cache.
1784 TEST(HttpCache, ConditionalizedRequestUpdatesCache8) {
1785 static const Response kNetResponse1 = {
1786 "HTTP/1.1 200 OK",
1787 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n"
1788 "Etag: \"Foo1\"\n"
1789 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
1790 "body1"
1791 };
1792
1793 // Second network response for |kUrl|.
1794 static const Response kNetResponse2 = {
1795 "HTTP/1.1 200 OK",
1796 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
1797 "Etag: \"Foo2\"\n"
1798 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n",
1799 "body2"
1800 };
1801
1802 const char* kExtraRequestHeaders =
1803 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\n"
1804 "If-None-Match: \"Foo1\"\n";
1805
1806 ConditionalizedRequestUpdatesCacheHelper(
1807 kNetResponse1, kNetResponse2, kNetResponse2, kExtraRequestHeaders);
1808 }
1809
1810 // Test that doing an externally conditionalized request with both if-none-match
1811 // and if-modified-since does not update the cache with only one match.
1812 TEST(HttpCache, ConditionalizedRequestUpdatesCache9) {
1813 static const Response kNetResponse1 = {
1814 "HTTP/1.1 200 OK",
1815 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n"
1816 "Etag: \"Foo1\"\n"
1817 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
1818 "body1"
1819 };
1820
1821 // Second network response for |kUrl|.
1822 static const Response kNetResponse2 = {
1823 "HTTP/1.1 200 OK",
1824 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
1825 "Etag: \"Foo2\"\n"
1826 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n",
1827 "body2"
1828 };
1829
1830 // The etag doesn't match what we have stored.
1831 const char* kExtraRequestHeaders =
1832 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\n"
1833 "If-None-Match: \"Foo2\"\n";
1834
1835 ConditionalizedRequestUpdatesCacheHelper(
1836 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders);
1837 }
1838
1839 // Test that doing an externally conditionalized request with both if-none-match
1840 // and if-modified-since does not update the cache with only one match.
1841 TEST(HttpCache, ConditionalizedRequestUpdatesCache10) {
1842 static const Response kNetResponse1 = {
1843 "HTTP/1.1 200 OK",
1844 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n"
1845 "Etag: \"Foo1\"\n"
1846 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
1847 "body1"
1848 };
1849
1850 // Second network response for |kUrl|.
1851 static const Response kNetResponse2 = {
1852 "HTTP/1.1 200 OK",
1853 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
1854 "Etag: \"Foo2\"\n"
1855 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n",
1856 "body2"
1857 };
1858
1859 // The modification date doesn't match what we have stored.
1860 const char* kExtraRequestHeaders =
1861 "If-Modified-Since: Fri, 08 Feb 2008 22:38:21 GMT\n"
1862 "If-None-Match: \"Foo1\"\n";
1863
1864 ConditionalizedRequestUpdatesCacheHelper(
1865 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders);
1866 }
1867
1868 // Test that doing an externally conditionalized request with two conflicting
1869 // headers does not update the cache.
1870 TEST(HttpCache, ConditionalizedRequestUpdatesCache11) {
1871 static const Response kNetResponse1 = {
1872 "HTTP/1.1 200 OK",
1873 "Date: Fri, 12 Jun 2009 21:46:42 GMT\n"
1874 "Etag: \"Foo1\"\n"
1875 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
1876 "body1"
1877 };
1878
1879 // Second network response for |kUrl|.
1880 static const Response kNetResponse2 = {
1881 "HTTP/1.1 200 OK",
1882 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
1883 "Etag: \"Foo2\"\n"
1884 "Last-Modified: Fri, 03 Jul 2009 02:14:27 GMT\n",
1885 "body2"
1886 };
1887
1888 // Two dates, the second matches what we have stored.
1889 const char* kExtraRequestHeaders =
1890 "If-Modified-Since: Mon, 04 Feb 2008 22:38:21 GMT\n"
1891 "If-Modified-Since: Wed, 06 Feb 2008 22:38:21 GMT\n";
1892
1893 ConditionalizedRequestUpdatesCacheHelper(
1894 kNetResponse1, kNetResponse2, kNetResponse1, kExtraRequestHeaders);
1895 }
1896
1782 TEST(HttpCache, UrlContainingHash) { 1897 TEST(HttpCache, UrlContainingHash) {
1783 MockHttpCache cache; 1898 MockHttpCache cache;
1784 1899
1785 // Do a typical GET request -- should write an entry into our cache. 1900 // Do a typical GET request -- should write an entry into our cache.
1786 MockTransaction trans(kTypicalGET_Transaction); 1901 MockTransaction trans(kTypicalGET_Transaction);
1787 RunTransactionTest(cache.http_cache(), trans); 1902 RunTransactionTest(cache.http_cache(), trans);
1788 1903
1789 EXPECT_EQ(1, cache.network_layer()->transaction_count()); 1904 EXPECT_EQ(1, cache.network_layer()->transaction_count());
1790 EXPECT_EQ(0, cache.disk_cache()->open_count()); 1905 EXPECT_EQ(0, cache.disk_cache()->open_count());
1791 EXPECT_EQ(1, cache.disk_cache()->create_count()); 1906 EXPECT_EQ(1, cache.disk_cache()->create_count());
(...skipping 1466 matching lines...) Expand 10 before | Expand all | Expand 10 after
3258 std::string headers; 3373 std::string headers;
3259 response.headers->GetNormalizedHeaders(&headers); 3374 response.headers->GetNormalizedHeaders(&headers);
3260 3375
3261 EXPECT_EQ("HTTP/1.1 200 OK\n" 3376 EXPECT_EQ("HTTP/1.1 200 OK\n"
3262 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n" 3377 "Date: Wed, 22 Jul 2009 03:15:26 GMT\n"
3263 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n", 3378 "Last-Modified: Wed, 06 Feb 2008 22:38:21 GMT\n",
3264 headers); 3379 headers);
3265 3380
3266 RemoveMockTransaction(&mock_network_response); 3381 RemoveMockTransaction(&mock_network_response);
3267 } 3382 }
OLDNEW
« no previous file with comments | « net/http/http_cache.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698