| 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 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 "te", | 43 "te", |
| 44 "trailer", | 44 "trailer", |
| 45 "transfer-encoding", | 45 "transfer-encoding", |
| 46 "upgrade", | 46 "upgrade", |
| 47 "user-agent", | 47 "user-agent", |
| 48 "via", | 48 "via", |
| 49 }; | 49 }; |
| 50 for (size_t i = 0; i < arraysize(unsafe_headers); ++i) { | 50 for (size_t i = 0; i < arraysize(unsafe_headers); ++i) { |
| 51 EXPECT_FALSE(HttpUtil::IsSafeHeader(unsafe_headers[i])) | 51 EXPECT_FALSE(HttpUtil::IsSafeHeader(unsafe_headers[i])) |
| 52 << unsafe_headers[i]; | 52 << unsafe_headers[i]; |
| 53 EXPECT_FALSE(HttpUtil::IsSafeHeader( | 53 EXPECT_FALSE(HttpUtil::IsSafeHeader(base::ToUpperASCII(unsafe_headers[i]))) |
| 54 base::StringToUpperASCII(std::string(unsafe_headers[i])))) | |
| 55 << unsafe_headers[i]; | 54 << unsafe_headers[i]; |
| 56 } | 55 } |
| 57 static const char* const safe_headers[] = { | 56 static const char* const safe_headers[] = { |
| 58 "foo", | 57 "foo", |
| 59 "x-", | 58 "x-", |
| 60 "x-foo", | 59 "x-foo", |
| 61 "content-disposition", | 60 "content-disposition", |
| 62 "update", | 61 "update", |
| 63 "accept-charseta", | 62 "accept-charseta", |
| 64 "accept_charset", | 63 "accept_charset", |
| (...skipping 24 matching lines...) Expand all Loading... |
| 89 "trailera", | 88 "trailera", |
| 90 "transfer-encodinga", | 89 "transfer-encodinga", |
| 91 "transfer_encoding", | 90 "transfer_encoding", |
| 92 "upgradea", | 91 "upgradea", |
| 93 "user-agenta", | 92 "user-agenta", |
| 94 "user_agent", | 93 "user_agent", |
| 95 "viaa", | 94 "viaa", |
| 96 }; | 95 }; |
| 97 for (size_t i = 0; i < arraysize(safe_headers); ++i) { | 96 for (size_t i = 0; i < arraysize(safe_headers); ++i) { |
| 98 EXPECT_TRUE(HttpUtil::IsSafeHeader(safe_headers[i])) << safe_headers[i]; | 97 EXPECT_TRUE(HttpUtil::IsSafeHeader(safe_headers[i])) << safe_headers[i]; |
| 99 EXPECT_TRUE(HttpUtil::IsSafeHeader( | 98 EXPECT_TRUE(HttpUtil::IsSafeHeader(base::ToUpperASCII(safe_headers[i]))) |
| 100 base::StringToUpperASCII(std::string(safe_headers[i])))) | |
| 101 << safe_headers[i]; | 99 << safe_headers[i]; |
| 102 } | 100 } |
| 103 } | 101 } |
| 104 | 102 |
| 105 TEST(HttpUtilTest, HasHeader) { | 103 TEST(HttpUtilTest, HasHeader) { |
| 106 static const struct { | 104 static const struct { |
| 107 const char* const headers; | 105 const char* const headers; |
| 108 const char* const name; | 106 const char* const name; |
| 109 bool expected_result; | 107 bool expected_result; |
| 110 } tests[] = { | 108 } tests[] = { |
| (...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); | 1172 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); |
| 1175 EXPECT_TRUE(parser.valid()); | 1173 EXPECT_TRUE(parser.valid()); |
| 1176 | 1174 |
| 1177 ASSERT_NO_FATAL_FAILURE( | 1175 ASSERT_NO_FATAL_FAILURE( |
| 1178 CheckNextNameValuePair(&parser, true, true, "name", "value")); | 1176 CheckNextNameValuePair(&parser, true, true, "name", "value")); |
| 1179 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( | 1177 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( |
| 1180 &parser, false, true, std::string(), std::string())); | 1178 &parser, false, true, std::string(), std::string())); |
| 1181 } | 1179 } |
| 1182 | 1180 |
| 1183 } // namespace net | 1181 } // namespace net |
| OLD | NEW |