OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "net/http/http_util.h" | 8 #include "net/http/http_util.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 { "foo: 1\r\nbar: 2", "foo", true }, | 27 { "foo: 1\r\nbar: 2", "foo", true }, |
28 { "fOO: 1\r\nbar: 2", "foo", true }, | 28 { "fOO: 1\r\nbar: 2", "foo", true }, |
29 { "g: 0\r\nfoo: 1\r\nbar: 2", "foo", true }, | 29 { "g: 0\r\nfoo: 1\r\nbar: 2", "foo", true }, |
30 }; | 30 }; |
31 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 31 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
32 bool result = HttpUtil::HasHeader(tests[i].headers, tests[i].name); | 32 bool result = HttpUtil::HasHeader(tests[i].headers, tests[i].name); |
33 EXPECT_EQ(tests[i].expected_result, result); | 33 EXPECT_EQ(tests[i].expected_result, result); |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
| 37 TEST(HttpUtilTest, StripHeaders) { |
| 38 static const char* headers = |
| 39 "Origin: origin\r\n" |
| 40 "Content-Type: text/plain\r\n" |
| 41 "Cookies: foo1\r\n" |
| 42 "Custom: baz\r\n" |
| 43 "COOKIES: foo2\r\n" |
| 44 "Server: Apache\r\n" |
| 45 "OrIGin: origin2\r\n"; |
| 46 |
| 47 static const char* header_names[] = { |
| 48 "origin", "content-type", "cookies" |
| 49 }; |
| 50 |
| 51 static const char* expected_stripped_headers = |
| 52 "Custom: baz\r\n" |
| 53 "Server: Apache\r\n"; |
| 54 |
| 55 EXPECT_EQ(expected_stripped_headers, |
| 56 HttpUtil::StripHeaders(headers, header_names, |
| 57 arraysize(header_names))); |
| 58 } |
| 59 |
37 TEST(HttpUtilTest, HeadersIterator) { | 60 TEST(HttpUtilTest, HeadersIterator) { |
38 std::string headers = "foo: 1\t\r\nbar: hello world\r\nbaz: 3 \r\n"; | 61 std::string headers = "foo: 1\t\r\nbar: hello world\r\nbaz: 3 \r\n"; |
39 | 62 |
40 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); | 63 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); |
41 | 64 |
42 ASSERT_TRUE(it.GetNext()); | 65 ASSERT_TRUE(it.GetNext()); |
43 EXPECT_EQ(std::string("foo"), it.name()); | 66 EXPECT_EQ(std::string("foo"), it.name()); |
44 EXPECT_EQ(std::string("1"), it.values()); | 67 EXPECT_EQ(std::string("1"), it.values()); |
45 | 68 |
46 ASSERT_TRUE(it.GetNext()); | 69 ASSERT_TRUE(it.GetNext()); |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 "ja;q=0.2"), | 506 "ja;q=0.2"), |
484 HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de,ko,zh-CN,ja")); | 507 HttpUtil::GenerateAcceptLanguageHeader("en-US,fr,de,ko,zh-CN,ja")); |
485 } | 508 } |
486 | 509 |
487 TEST(HttpUtilTest, GenerateAcceptCharsetHeader) { | 510 TEST(HttpUtilTest, GenerateAcceptCharsetHeader) { |
488 EXPECT_EQ(std::string("utf-8,*;q=0.5"), | 511 EXPECT_EQ(std::string("utf-8,*;q=0.5"), |
489 HttpUtil::GenerateAcceptCharsetHeader("utf-8")); | 512 HttpUtil::GenerateAcceptCharsetHeader("utf-8")); |
490 EXPECT_EQ(std::string("EUC-JP,utf-8;q=0.7,*;q=0.3"), | 513 EXPECT_EQ(std::string("EUC-JP,utf-8;q=0.7,*;q=0.3"), |
491 HttpUtil::GenerateAcceptCharsetHeader("EUC-JP")); | 514 HttpUtil::GenerateAcceptCharsetHeader("EUC-JP")); |
492 } | 515 } |
OLD | NEW |