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

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

Issue 448373003: parameterize http response header tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months 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 | « no previous file | 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 <algorithm> 5 #include <algorithm>
6 #include <limits> 6 #include <limits>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 15 matching lines...) Expand all
26 26
27 struct ContentTypeTestData { 27 struct ContentTypeTestData {
28 const std::string raw_headers; 28 const std::string raw_headers;
29 const std::string mime_type; 29 const std::string mime_type;
30 const bool has_mimetype; 30 const bool has_mimetype;
31 const std::string charset; 31 const std::string charset;
32 const bool has_charset; 32 const bool has_charset;
33 const std::string all_content_type; 33 const std::string all_content_type;
34 }; 34 };
35 35
36 struct MaxAgeTestData {
37 const char* max_age_string;
38 const int64 expected_seconds;
39 };
40
36 class HttpResponseHeadersTest : public testing::Test { 41 class HttpResponseHeadersTest : public testing::Test {
37 }; 42 };
38 43
39 // Transform "normal"-looking headers (\n-separated) to the appropriate 44 // Transform "normal"-looking headers (\n-separated) to the appropriate
40 // input format for ParseRawHeaders (\0-separated). 45 // input format for ParseRawHeaders (\0-separated).
41 void HeadersToRaw(std::string* headers) { 46 void HeadersToRaw(std::string* headers) {
42 std::replace(headers->begin(), headers->end(), '\n', '\0'); 47 std::replace(headers->begin(), headers->end(), '\n', '\0');
43 if (!headers->empty()) 48 if (!headers->empty())
44 *headers += '\0'; 49 *headers += '\0';
45 } 50 }
(...skipping 1973 matching lines...) Expand 10 before | Expand all | Expand 10 after
2019 2024
2020 TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeCaseInsensitive) { 2025 TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeCaseInsensitive) {
2021 InitializeHeadersWithCacheControl("Max-aGe=15"); 2026 InitializeHeadersWithCacheControl("Max-aGe=15");
2022 EXPECT_EQ(TimeDelta::FromSeconds(15), GetMaxAgeValue()); 2027 EXPECT_EQ(TimeDelta::FromSeconds(15), GetMaxAgeValue());
2023 } 2028 }
2024 2029
2025 TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeEdgeCases) { 2030 TEST_F(HttpResponseHeadersCacheControlTest, MaxAgeEdgeCases) {
2026 // This test doesn't use TEST_P() for consistency with the rest of the tests 2031 // This test doesn't use TEST_P() for consistency with the rest of the tests
2027 // in this file. 2032 // in this file.
2028 // TODO(ricea): Port the tests in this file to use TEST_P(). 2033 // TODO(ricea): Port the tests in this file to use TEST_P().
2029 const struct { 2034 const MaxAgeTestData tests[] = {
Adam Rice 2014/08/11 12:17:54 It would probably be better to use ARRAYSIZE_UNSAF
Mostyn Bramley-Moore 2014/08/11 12:24:02 I could try converting them all to use arraysize,
Adam Rice 2014/08/11 12:28:46 Unless you're willing to refactor all the tests to
Mostyn Bramley-Moore 2014/08/11 12:35:36 I will give that a try, but it might take a day or
2030 const char* max_age_string;
2031 int64 expected_seconds;
2032 } tests[] = {
2033 {" 1 ", 1}, // Spaces are ignored 2035 {" 1 ", 1}, // Spaces are ignored
2034 {"-1", -1}, // Negative numbers are passed through 2036 {"-1", -1}, // Negative numbers are passed through
2035 {"--1", 0}, // Leading junk gives 0 2037 {"--1", 0}, // Leading junk gives 0
2036 {"2s", 2}, // trailing junk is ignored 2038 {"2s", 2}, // trailing junk is ignored
2037 {"3 days", 3}, 2039 {"3 days", 3},
2038 {"'4'", 0}, // single quotes don't work 2040 {"'4'", 0}, // single quotes don't work
2039 {"\"5\"", 0}, // double quotes don't work 2041 {"\"5\"", 0}, // double quotes don't work
2040 {"0x6", 0}, // hex not parsed as hex 2042 {"0x6", 0}, // hex not parsed as hex
2041 {"7F", 7}, // hex without 0x still not parsed as hex 2043 {"7F", 7}, // hex without 0x still not parsed as hex
2042 {"010", 10}, // octal not parsed as octal 2044 {"010", 10}, // octal not parsed as octal
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 InitializeHeadersWithCacheControl("max-age=3600,stale-while-revalidate=7200"); 2080 InitializeHeadersWithCacheControl("max-age=3600,stale-while-revalidate=7200");
2079 EXPECT_EQ(TimeDelta::FromSeconds(7200), GetStaleWhileRevalidateValue()); 2081 EXPECT_EQ(TimeDelta::FromSeconds(7200), GetStaleWhileRevalidateValue());
2080 } 2082 }
2081 2083
2082 TEST_F(HttpResponseHeadersCacheControlTest, 2084 TEST_F(HttpResponseHeadersCacheControlTest,
2083 FirstStaleWhileRevalidateValueUsed) { 2085 FirstStaleWhileRevalidateValueUsed) {
2084 InitializeHeadersWithCacheControl( 2086 InitializeHeadersWithCacheControl(
2085 "stale-while-revalidate=1,stale-while-revalidate=7200"); 2087 "stale-while-revalidate=1,stale-while-revalidate=7200");
2086 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue()); 2088 EXPECT_EQ(TimeDelta::FromSeconds(1), GetStaleWhileRevalidateValue());
2087 } 2089 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698