| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "net/http/http_util.h" | 9 #include "net/http/http_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 "user_agent", | 93 "user_agent", |
| 94 "viaa", | 94 "viaa", |
| 95 }; | 95 }; |
| 96 for (size_t i = 0; i < arraysize(safe_headers); ++i) { | 96 for (size_t i = 0; i < arraysize(safe_headers); ++i) { |
| 97 EXPECT_TRUE(HttpUtil::IsSafeHeader(safe_headers[i])) << safe_headers[i]; | 97 EXPECT_TRUE(HttpUtil::IsSafeHeader(safe_headers[i])) << safe_headers[i]; |
| 98 EXPECT_TRUE(HttpUtil::IsSafeHeader(base::ToUpperASCII(safe_headers[i]))) | 98 EXPECT_TRUE(HttpUtil::IsSafeHeader(base::ToUpperASCII(safe_headers[i]))) |
| 99 << safe_headers[i]; | 99 << safe_headers[i]; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST(HttpUtilTest, HasHeader) { | |
| 104 static const struct { | |
| 105 const char* const headers; | |
| 106 const char* const name; | |
| 107 bool expected_result; | |
| 108 } tests[] = { | |
| 109 { "", "foo", false }, | |
| 110 { "foo\r\nbar", "foo", false }, | |
| 111 { "ffoo: 1", "foo", false }, | |
| 112 { "foo: 1", "foo", true }, | |
| 113 { "foo: 1\r\nbar: 2", "foo", true }, | |
| 114 { "fOO: 1\r\nbar: 2", "foo", true }, | |
| 115 { "g: 0\r\nfoo: 1\r\nbar: 2", "foo", true }, | |
| 116 }; | |
| 117 for (size_t i = 0; i < arraysize(tests); ++i) { | |
| 118 bool result = HttpUtil::HasHeader(tests[i].headers, tests[i].name); | |
| 119 EXPECT_EQ(tests[i].expected_result, result); | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 TEST(HttpUtilTest, HeadersIterator) { | 103 TEST(HttpUtilTest, HeadersIterator) { |
| 124 std::string headers = "foo: 1\t\r\nbar: hello world\r\nbaz: 3 \r\n"; | 104 std::string headers = "foo: 1\t\r\nbar: hello world\r\nbaz: 3 \r\n"; |
| 125 | 105 |
| 126 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); | 106 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); |
| 127 | 107 |
| 128 ASSERT_TRUE(it.GetNext()); | 108 ASSERT_TRUE(it.GetNext()); |
| 129 EXPECT_EQ(std::string("foo"), it.name()); | 109 EXPECT_EQ(std::string("foo"), it.name()); |
| 130 EXPECT_EQ(std::string("1"), it.values()); | 110 EXPECT_EQ(std::string("1"), it.values()); |
| 131 | 111 |
| 132 ASSERT_TRUE(it.GetNext()); | 112 ASSERT_TRUE(it.GetNext()); |
| (...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1336 EXPECT_FALSE(HttpUtil::IsLWS('a')); | 1316 EXPECT_FALSE(HttpUtil::IsLWS('a')); |
| 1337 EXPECT_FALSE(HttpUtil::IsLWS('.')); | 1317 EXPECT_FALSE(HttpUtil::IsLWS('.')); |
| 1338 EXPECT_FALSE(HttpUtil::IsLWS('\n')); | 1318 EXPECT_FALSE(HttpUtil::IsLWS('\n')); |
| 1339 EXPECT_FALSE(HttpUtil::IsLWS('\r')); | 1319 EXPECT_FALSE(HttpUtil::IsLWS('\r')); |
| 1340 | 1320 |
| 1341 EXPECT_TRUE(HttpUtil::IsLWS('\t')); | 1321 EXPECT_TRUE(HttpUtil::IsLWS('\t')); |
| 1342 EXPECT_TRUE(HttpUtil::IsLWS(' ')); | 1322 EXPECT_TRUE(HttpUtil::IsLWS(' ')); |
| 1343 } | 1323 } |
| 1344 | 1324 |
| 1345 } // namespace net | 1325 } // namespace net |
| OLD | NEW |