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_response_headers.h" | 5 #include "net/http/http_response_headers.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iostream> | 10 #include <iostream> |
(...skipping 25 matching lines...) Expand all Loading... | |
36 }; | 36 }; |
37 | 37 |
38 // Transform "normal"-looking headers (\n-separated) to the appropriate | 38 // Transform "normal"-looking headers (\n-separated) to the appropriate |
39 // input format for ParseRawHeaders (\0-separated). | 39 // input format for ParseRawHeaders (\0-separated). |
40 void HeadersToRaw(std::string* headers) { | 40 void HeadersToRaw(std::string* headers) { |
41 std::replace(headers->begin(), headers->end(), '\n', '\0'); | 41 std::replace(headers->begin(), headers->end(), '\n', '\0'); |
42 if (!headers->empty()) | 42 if (!headers->empty()) |
43 *headers += '\0'; | 43 *headers += '\0'; |
44 } | 44 } |
45 | 45 |
46 class HttpResponseHeadersCacheControlTest : public HttpResponseHeadersTest { | 46 class HttpResponseHeadersCacheControlTest : public HttpResponseHeadersTest { |
mmenke
2017/03/23 21:39:35
Test fixture no longer used.
scottmg
2017/03/24 22:46:00
Sorry, I don't understand this one. This class is
mmenke
2017/03/27 14:21:38
Ahh, missed those. The fixture was added for SWR,
| |
47 protected: | 47 protected: |
48 // Make tests less verbose. | 48 // Make tests less verbose. |
49 typedef base::TimeDelta TimeDelta; | 49 typedef base::TimeDelta TimeDelta; |
50 | 50 |
51 // Initilise the headers() value with a Cache-Control header set to | 51 // Initilise the headers() value with a Cache-Control header set to |
52 // |cache_control|. |cache_control| is copied and so can safely be a | 52 // |cache_control|. |cache_control| is copied and so can safely be a |
53 // temporary. | 53 // temporary. |
54 void InitializeHeadersWithCacheControl(const char* cache_control) { | 54 void InitializeHeadersWithCacheControl(const char* cache_control) { |
55 std::string raw_headers("HTTP/1.1 200 OK\n"); | 55 std::string raw_headers("HTTP/1.1 200 OK\n"); |
56 raw_headers += "Cache-Control: "; | 56 raw_headers += "Cache-Control: "; |
(...skipping 11 matching lines...) Expand all Loading... | |
68 | 68 |
69 // Get the max-age value. This should only be used in tests where a valid | 69 // Get the max-age value. This should only be used in tests where a valid |
70 // max-age parameter is expected to be present. | 70 // max-age parameter is expected to be present. |
71 TimeDelta GetMaxAgeValue() { | 71 TimeDelta GetMaxAgeValue() { |
72 DCHECK(headers_.get()) << "Call InitializeHeadersWithCacheControl() first"; | 72 DCHECK(headers_.get()) << "Call InitializeHeadersWithCacheControl() first"; |
73 TimeDelta max_age_value; | 73 TimeDelta max_age_value; |
74 EXPECT_TRUE(headers()->GetMaxAgeValue(&max_age_value)); | 74 EXPECT_TRUE(headers()->GetMaxAgeValue(&max_age_value)); |
75 return max_age_value; | 75 return max_age_value; |
76 } | 76 } |
77 | 77 |
78 // Get the stale-while-revalidate value. This should only be used in tests | |
79 // where a valid max-age parameter is expected to be present. | |
80 TimeDelta GetStaleWhileRevalidateValue() { | |
81 DCHECK(headers_.get()) << "Call InitializeHeadersWithCacheControl() first"; | |
82 TimeDelta stale_while_revalidate_value; | |
83 EXPECT_TRUE( | |
84 headers()->GetStaleWhileRevalidateValue(&stale_while_revalidate_value)); | |
85 return stale_while_revalidate_value; | |
86 } | |
87 | |
88 private: | 78 private: |
89 scoped_refptr<HttpResponseHeaders> headers_; | 79 scoped_refptr<HttpResponseHeaders> headers_; |
90 TimeDelta delta_; | 80 TimeDelta delta_; |
91 }; | 81 }; |
92 | 82 |
93 class CommonHttpResponseHeadersTest | 83 class CommonHttpResponseHeadersTest |
94 : public HttpResponseHeadersTest, | 84 : public HttpResponseHeadersTest, |
95 public ::testing::WithParamInterface<TestData> { | 85 public ::testing::WithParamInterface<TestData> { |
96 }; | 86 }; |
97 | 87 |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
801 "", false, | 791 "", false, |
802 "*/*" }, | 792 "*/*" }, |
803 }; | 793 }; |
804 | 794 |
805 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, | 795 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, |
806 ContentTypeTest, | 796 ContentTypeTest, |
807 testing::ValuesIn(mimetype_tests)); | 797 testing::ValuesIn(mimetype_tests)); |
808 | 798 |
809 struct RequiresValidationTestData { | 799 struct RequiresValidationTestData { |
810 const char* headers; | 800 const char* headers; |
811 ValidationType validation_type; | 801 bool requires_validation; |
812 }; | 802 }; |
813 | 803 |
814 class RequiresValidationTest | 804 class RequiresValidationTest |
815 : public HttpResponseHeadersTest, | 805 : public HttpResponseHeadersTest, |
816 public ::testing::WithParamInterface<RequiresValidationTestData> { | 806 public ::testing::WithParamInterface<RequiresValidationTestData> { |
817 }; | 807 }; |
818 | 808 |
819 TEST_P(RequiresValidationTest, RequiresValidation) { | 809 TEST_P(RequiresValidationTest, RequiresValidation) { |
820 const RequiresValidationTestData test = GetParam(); | 810 const RequiresValidationTestData test = GetParam(); |
821 | 811 |
822 base::Time request_time, response_time, current_time; | 812 base::Time request_time, response_time, current_time; |
823 ASSERT_TRUE( | 813 ASSERT_TRUE( |
824 base::Time::FromString("Wed, 28 Nov 2007 00:40:09 GMT", &request_time)); | 814 base::Time::FromString("Wed, 28 Nov 2007 00:40:09 GMT", &request_time)); |
825 ASSERT_TRUE( | 815 ASSERT_TRUE( |
826 base::Time::FromString("Wed, 28 Nov 2007 00:40:12 GMT", &response_time)); | 816 base::Time::FromString("Wed, 28 Nov 2007 00:40:12 GMT", &response_time)); |
827 ASSERT_TRUE( | 817 ASSERT_TRUE( |
828 base::Time::FromString("Wed, 28 Nov 2007 00:45:20 GMT", ¤t_time)); | 818 base::Time::FromString("Wed, 28 Nov 2007 00:45:20 GMT", ¤t_time)); |
829 | 819 |
830 std::string headers(test.headers); | 820 std::string headers(test.headers); |
831 HeadersToRaw(&headers); | 821 HeadersToRaw(&headers); |
832 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); | 822 scoped_refptr<HttpResponseHeaders> parsed(new HttpResponseHeaders(headers)); |
833 | 823 |
834 ValidationType validation_type = | 824 bool requires_validation = |
835 parsed->RequiresValidation(request_time, response_time, current_time); | 825 parsed->RequiresValidation(request_time, response_time, current_time); |
836 EXPECT_EQ(test.validation_type, validation_type); | 826 EXPECT_EQ(test.requires_validation, requires_validation); |
837 } | 827 } |
838 | 828 |
839 const struct RequiresValidationTestData requires_validation_tests[] = { | 829 const struct RequiresValidationTestData requires_validation_tests[] = { |
840 // No expiry info: expires immediately. | 830 // No expiry info: expires immediately. |
841 { "HTTP/1.1 200 OK\n" | 831 { "HTTP/1.1 200 OK\n" |
842 "\n", | 832 "\n", |
843 VALIDATION_SYNCHRONOUS | 833 true |
844 }, | 834 }, |
845 // No expiry info: expires immediately. | 835 // No expiry info: expires immediately. |
846 { "HTTP/1.1 200 OK\n" | 836 { "HTTP/1.1 200 OK\n" |
847 "\n", | 837 "\n", |
848 VALIDATION_SYNCHRONOUS | 838 true |
849 }, | 839 }, |
850 // Valid for a little while. | 840 // Valid for a little while. |
851 { "HTTP/1.1 200 OK\n" | 841 { "HTTP/1.1 200 OK\n" |
852 "cache-control: max-age=10000\n" | 842 "cache-control: max-age=10000\n" |
853 "\n", | 843 "\n", |
854 VALIDATION_NONE | 844 false |
855 }, | 845 }, |
856 // Expires in the future. | 846 // Expires in the future. |
857 { "HTTP/1.1 200 OK\n" | 847 { "HTTP/1.1 200 OK\n" |
858 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 848 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
859 "expires: Wed, 28 Nov 2007 01:00:00 GMT\n" | 849 "expires: Wed, 28 Nov 2007 01:00:00 GMT\n" |
860 "\n", | 850 "\n", |
861 VALIDATION_NONE | 851 false |
862 }, | 852 }, |
863 // Already expired. | 853 // Already expired. |
864 { "HTTP/1.1 200 OK\n" | 854 { "HTTP/1.1 200 OK\n" |
865 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 855 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
866 "expires: Wed, 28 Nov 2007 00:00:00 GMT\n" | 856 "expires: Wed, 28 Nov 2007 00:00:00 GMT\n" |
867 "\n", | 857 "\n", |
868 VALIDATION_SYNCHRONOUS | 858 true |
869 }, | 859 }, |
870 // Max-age trumps expires. | 860 // Max-age trumps expires. |
871 { "HTTP/1.1 200 OK\n" | 861 { "HTTP/1.1 200 OK\n" |
872 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 862 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
873 "expires: Wed, 28 Nov 2007 00:00:00 GMT\n" | 863 "expires: Wed, 28 Nov 2007 00:00:00 GMT\n" |
874 "cache-control: max-age=10000\n" | 864 "cache-control: max-age=10000\n" |
875 "\n", | 865 "\n", |
876 VALIDATION_NONE | 866 false |
877 }, | 867 }, |
878 // Last-modified heuristic: modified a while ago. | 868 // Last-modified heuristic: modified a while ago. |
879 { "HTTP/1.1 200 OK\n" | 869 { "HTTP/1.1 200 OK\n" |
880 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 870 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
881 "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" | 871 "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" |
882 "\n", | 872 "\n", |
883 VALIDATION_NONE | 873 false |
884 }, | 874 }, |
885 { "HTTP/1.1 203 Non-Authoritative Information\n" | 875 { "HTTP/1.1 203 Non-Authoritative Information\n" |
886 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 876 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
887 "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" | 877 "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" |
888 "\n", | 878 "\n", |
889 VALIDATION_NONE | 879 false |
890 }, | 880 }, |
891 { "HTTP/1.1 206 Partial Content\n" | 881 { "HTTP/1.1 206 Partial Content\n" |
892 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 882 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
893 "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" | 883 "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" |
894 "\n", | 884 "\n", |
895 VALIDATION_NONE | 885 false |
896 }, | 886 }, |
897 // Last-modified heuristic: modified recently. | 887 // Last-modified heuristic: modified recently. |
898 { "HTTP/1.1 200 OK\n" | 888 { "HTTP/1.1 200 OK\n" |
899 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 889 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
900 "last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n" | 890 "last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n" |
901 "\n", | 891 "\n", |
902 VALIDATION_SYNCHRONOUS | 892 true |
903 }, | 893 }, |
904 { "HTTP/1.1 203 Non-Authoritative Information\n" | 894 { "HTTP/1.1 203 Non-Authoritative Information\n" |
905 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 895 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
906 "last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n" | 896 "last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n" |
907 "\n", | 897 "\n", |
908 VALIDATION_SYNCHRONOUS | 898 true |
909 }, | 899 }, |
910 { "HTTP/1.1 206 Partial Content\n" | 900 { "HTTP/1.1 206 Partial Content\n" |
911 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 901 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
912 "last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n" | 902 "last-modified: Wed, 28 Nov 2007 00:40:10 GMT\n" |
913 "\n", | 903 "\n", |
914 VALIDATION_SYNCHRONOUS | 904 true |
915 }, | 905 }, |
916 // Cached permanent redirect. | 906 // Cached permanent redirect. |
917 { "HTTP/1.1 301 Moved Permanently\n" | 907 { "HTTP/1.1 301 Moved Permanently\n" |
918 "\n", | 908 "\n", |
919 VALIDATION_NONE | 909 false |
920 }, | 910 }, |
921 // Another cached permanent redirect. | 911 // Another cached permanent redirect. |
922 { "HTTP/1.1 308 Permanent Redirect\n" | 912 { "HTTP/1.1 308 Permanent Redirect\n" |
923 "\n", | 913 "\n", |
924 VALIDATION_NONE | 914 false |
925 }, | 915 }, |
926 // Cached redirect: not reusable even though by default it would be. | 916 // Cached redirect: not reusable even though by default it would be. |
927 { "HTTP/1.1 300 Multiple Choices\n" | 917 { "HTTP/1.1 300 Multiple Choices\n" |
928 "Cache-Control: no-cache\n" | 918 "Cache-Control: no-cache\n" |
929 "\n", | 919 "\n", |
930 VALIDATION_SYNCHRONOUS | 920 true |
931 }, | 921 }, |
932 // Cached forever by default. | 922 // Cached forever by default. |
933 { "HTTP/1.1 410 Gone\n" | 923 { "HTTP/1.1 410 Gone\n" |
934 "\n", | 924 "\n", |
935 VALIDATION_NONE | 925 false |
936 }, | 926 }, |
937 // Cached temporary redirect: not reusable. | 927 // Cached temporary redirect: not reusable. |
938 { "HTTP/1.1 302 Found\n" | 928 { "HTTP/1.1 302 Found\n" |
939 "\n", | 929 "\n", |
940 VALIDATION_SYNCHRONOUS | 930 true |
941 }, | 931 }, |
942 // Cached temporary redirect: reusable. | 932 // Cached temporary redirect: reusable. |
943 { "HTTP/1.1 302 Found\n" | 933 { "HTTP/1.1 302 Found\n" |
944 "cache-control: max-age=10000\n" | 934 "cache-control: max-age=10000\n" |
945 "\n", | 935 "\n", |
946 VALIDATION_NONE | 936 false |
947 }, | 937 }, |
948 // Cache-control: max-age=N overrides expires: date in the past. | 938 // Cache-control: max-age=N overrides expires: date in the past. |
949 { "HTTP/1.1 200 OK\n" | 939 { "HTTP/1.1 200 OK\n" |
950 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 940 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
951 "expires: Wed, 28 Nov 2007 00:20:11 GMT\n" | 941 "expires: Wed, 28 Nov 2007 00:20:11 GMT\n" |
952 "cache-control: max-age=10000\n" | 942 "cache-control: max-age=10000\n" |
953 "\n", | 943 "\n", |
954 VALIDATION_NONE | 944 false |
955 }, | 945 }, |
956 // Cache-control: no-store overrides expires: in the future. | 946 // Cache-control: no-store overrides expires: in the future. |
957 { "HTTP/1.1 200 OK\n" | 947 { "HTTP/1.1 200 OK\n" |
958 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 948 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
959 "expires: Wed, 29 Nov 2007 00:40:11 GMT\n" | 949 "expires: Wed, 29 Nov 2007 00:40:11 GMT\n" |
960 "cache-control: no-store,private,no-cache=\"foo\"\n" | 950 "cache-control: no-store,private,no-cache=\"foo\"\n" |
961 "\n", | 951 "\n", |
962 VALIDATION_SYNCHRONOUS | 952 true |
963 }, | 953 }, |
964 // Pragma: no-cache overrides last-modified heuristic. | 954 // Pragma: no-cache overrides last-modified heuristic. |
965 { "HTTP/1.1 200 OK\n" | 955 { "HTTP/1.1 200 OK\n" |
966 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 956 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
967 "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" | 957 "last-modified: Wed, 27 Nov 2007 08:00:00 GMT\n" |
968 "pragma: no-cache\n" | 958 "pragma: no-cache\n" |
969 "\n", | 959 "\n", |
970 VALIDATION_SYNCHRONOUS | 960 true |
971 }, | 961 }, |
972 // max-age has expired, needs synchronous revalidation | 962 // max-age has expired, needs synchronous revalidation |
973 { "HTTP/1.1 200 OK\n" | 963 { "HTTP/1.1 200 OK\n" |
974 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | 964 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" |
975 "cache-control: max-age=300\n" | 965 "cache-control: max-age=300\n" |
976 "\n", | 966 "\n", |
977 VALIDATION_SYNCHRONOUS | 967 true |
978 }, | |
979 // max-age has expired, stale-while-revalidate has not, eligible for | |
980 // asynchronous revalidation | |
981 { "HTTP/1.1 200 OK\n" | |
982 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | |
983 "cache-control: max-age=300, stale-while-revalidate=3600\n" | |
984 "\n", | |
985 VALIDATION_ASYNCHRONOUS | |
986 }, | |
987 // max-age and stale-while-revalidate have expired, needs synchronous | |
988 // revalidation | |
989 { "HTTP/1.1 200 OK\n" | |
990 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | |
991 "cache-control: max-age=300, stale-while-revalidate=5\n" | |
992 "\n", | |
993 VALIDATION_SYNCHRONOUS | |
994 }, | |
995 // max-age is 0, stale-while-revalidate is large enough to permit | |
996 // asynchronous revalidation | |
997 { "HTTP/1.1 200 OK\n" | |
998 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | |
999 "cache-control: max-age=0, stale-while-revalidate=360\n" | |
1000 "\n", | |
1001 VALIDATION_ASYNCHRONOUS | |
1002 }, | |
1003 // stale-while-revalidate must not override no-cache or similar directives. | |
1004 { "HTTP/1.1 200 OK\n" | |
1005 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | |
1006 "cache-control: no-cache, stale-while-revalidate=360\n" | |
1007 "\n", | |
1008 VALIDATION_SYNCHRONOUS | |
1009 }, | |
1010 // max-age has not expired, so no revalidation is needed. | |
1011 { "HTTP/1.1 200 OK\n" | |
1012 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | |
1013 "cache-control: max-age=3600, stale-while-revalidate=3600\n" | |
1014 "\n", | |
1015 VALIDATION_NONE | |
1016 }, | |
1017 // must-revalidate overrides stale-while-revalidate, so synchronous validation | |
1018 // is needed. | |
1019 { "HTTP/1.1 200 OK\n" | |
1020 "date: Wed, 28 Nov 2007 00:40:11 GMT\n" | |
1021 "cache-control: must-revalidate, max-age=300, stale-while-revalidate=3600\n" | |
1022 "\n", | |
1023 VALIDATION_SYNCHRONOUS | |
1024 }, | 968 }, |
1025 | 969 |
1026 // TODO(darin): Add many many more tests here. | 970 // TODO(darin): Add many many more tests here. |
1027 }; | 971 }; |
1028 | 972 |
1029 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, | 973 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, |
1030 RequiresValidationTest, | 974 RequiresValidationTest, |
1031 testing::ValuesIn(requires_validation_tests)); | 975 testing::ValuesIn(requires_validation_tests)); |
1032 | 976 |
1033 struct UpdateTestData { | 977 struct UpdateTestData { |
(...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2186 // {"9223372036854775806", -2}, // Undefined behaviour. | 2130 // {"9223372036854775806", -2}, // Undefined behaviour. |
2187 {"9223372036854775807", 9223372036854775807}, | 2131 {"9223372036854775807", 9223372036854775807}, |
2188 {"20000000000000000000", | 2132 {"20000000000000000000", |
2189 std::numeric_limits<int64_t>::max()}, // Overflow int64_t. | 2133 std::numeric_limits<int64_t>::max()}, // Overflow int64_t. |
2190 }; | 2134 }; |
2191 | 2135 |
2192 INSTANTIATE_TEST_CASE_P(HttpResponseHeadersCacheControl, | 2136 INSTANTIATE_TEST_CASE_P(HttpResponseHeadersCacheControl, |
2193 MaxAgeEdgeCasesTest, | 2137 MaxAgeEdgeCasesTest, |
2194 testing::ValuesIn(max_age_tests)); | 2138 testing::ValuesIn(max_age_tests)); |
2195 | 2139 |
2196 TEST_F(HttpResponseHeadersCacheControlTest, | |
2197 AbsentStaleWhileRevalidateReturnsFalse) { | |
2198 InitializeHeadersWithCacheControl("max-age=3600"); | |
2199 EXPECT_FALSE(headers()->GetStaleWhileRevalidateValue(TimeDeltaPointer())); | |
2200 } | |
2201 | |
2202 TEST_F(HttpResponseHeadersCacheControlTest, | |
2203 StaleWhileRevalidateWithoutValueRejected) { | |
2204 InitializeHeadersWithCacheControl("max-age=3600,stale-while-revalidate="); | |
2205 EXPECT_FALSE(headers()->GetStaleWhileRevalidateValue(TimeDeltaPointer())); | |
2206 } | |
2207 | |
2208 TEST_F(HttpResponseHeadersCacheControlTest, | |
2209 StaleWhileRevalidateWithInvalidValueTreatedAsZero) { | |
2210 InitializeHeadersWithCacheControl("max-age=3600,stale-while-revalidate=true"); | |
2211 EXPECT_EQ(TimeDelta(), GetStaleWhileRevalidateValue()); | |
2212 } | |
2213 | |
2214 TEST_F(HttpResponseHeadersCacheControlTest, StaleWhileRevalidateValueReturned) { | |
2215 InitializeHeadersWithCacheControl("max-age=3600,stale-while-revalidate=7200"); | |
2216 EXPECT_EQ(TimeDelta::FromSeconds(7200), GetStaleWhileRevalidateValue()); | |
2217 } | |
2218 | |
2219 TEST_F(HttpResponseHeadersCacheControlTest, | |
2220 FirstStaleWhileRevalidateValueUsed) { | |
2221 InitializeHeadersWithCacheControl( | |
2222 "stale-while-revalidate=1,stale-while-revalidate=7200"); | |
2223 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); | |
2224 } | |
2225 | |
2226 struct GetCurrentAgeTestData { | 2140 struct GetCurrentAgeTestData { |
2227 const char* headers; | 2141 const char* headers; |
2228 const char* request_time; | 2142 const char* request_time; |
2229 const char* response_time; | 2143 const char* response_time; |
2230 const char* current_time; | 2144 const char* current_time; |
2231 const int expected_age; | 2145 const int expected_age; |
2232 }; | 2146 }; |
2233 | 2147 |
2234 class GetCurrentAgeTest | 2148 class GetCurrentAgeTest |
2235 : public HttpResponseHeadersTest, | 2149 : public HttpResponseHeadersTest, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2282 "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT", | 2196 "Fri, 20 Jan 2011 10:40:08 GMT", "Fri, 20 Jan 2011 10:40:12 GMT", |
2283 "Fri, 20 Jan 2011 10:40:14 GMT", 7}}; | 2197 "Fri, 20 Jan 2011 10:40:14 GMT", 7}}; |
2284 | 2198 |
2285 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, | 2199 INSTANTIATE_TEST_CASE_P(HttpResponseHeaders, |
2286 GetCurrentAgeTest, | 2200 GetCurrentAgeTest, |
2287 testing::ValuesIn(get_current_age_tests)); | 2201 testing::ValuesIn(get_current_age_tests)); |
2288 | 2202 |
2289 } // namespace | 2203 } // namespace |
2290 | 2204 |
2291 } // namespace net | 2205 } // namespace net |
OLD | NEW |