| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 18 matching lines...) Expand all Loading... |
| 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) { | 37 TEST(HttpUtilTest, StripHeaders) { |
| 38 static const char* headers = | 38 static const char* headers = |
| 39 "Origin: origin\r\n" | 39 "Origin: origin\r\n" |
| 40 "Content-Type: text/plain\r\n" | 40 "Content-Type: text/plain\r\n" |
| 41 "Cookies: foo1\r\n" | 41 "Cookies: foo1\r\n" |
| 42 "Custom: baz\r\n" | 42 "Custom: baz\r\n" |
| 43 "COOKIES: foo2\r\n" | 43 "COOKIES: foo2\r\n" |
| 44 "Server: Apache\r\n" | 44 "Server: Apache\r\n" |
| 45 "OrIGin: origin2\r\n"; | 45 "OrIGin: origin2\r\n"; |
| 46 | 46 |
| 47 static const char* header_names[] = { | 47 static const char* header_names[] = { |
| 48 "origin", "content-type", "cookies" | 48 "origin", "content-type", "cookies" |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 static const char* expected_stripped_headers = | 51 static const char* expected_stripped_headers = |
| 52 "Custom: baz\r\n" | 52 "Custom: baz\r\n" |
| 53 "Server: Apache\r\n"; | 53 "Server: Apache\r\n"; |
| 54 | 54 |
| 55 EXPECT_EQ(expected_stripped_headers, | 55 EXPECT_EQ(expected_stripped_headers, |
| 56 HttpUtil::StripHeaders(headers, header_names, | 56 HttpUtil::StripHeaders(headers, header_names, |
| 57 arraysize(header_names))); | 57 arraysize(header_names))); |
| 58 } | 58 } |
| 59 | 59 |
| 60 TEST(HttpUtilTest, HeadersIterator) { | 60 TEST(HttpUtilTest, HeadersIterator) { |
| 61 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"; |
| 62 | 62 |
| 63 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); | 63 HttpUtil::HeadersIterator it(headers.begin(), headers.end(), "\r\n"); |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 EXPECT_EQ(tests[i].expected_ranges[j].expected_first_byte_position, | 664 EXPECT_EQ(tests[i].expected_ranges[j].expected_first_byte_position, |
| 665 ranges[j].first_byte_position()); | 665 ranges[j].first_byte_position()); |
| 666 EXPECT_EQ(tests[i].expected_ranges[j].expected_last_byte_position, | 666 EXPECT_EQ(tests[i].expected_ranges[j].expected_last_byte_position, |
| 667 ranges[j].last_byte_position()); | 667 ranges[j].last_byte_position()); |
| 668 EXPECT_EQ(tests[i].expected_ranges[j].expected_suffix_length, | 668 EXPECT_EQ(tests[i].expected_ranges[j].expected_suffix_length, |
| 669 ranges[j].suffix_length()); | 669 ranges[j].suffix_length()); |
| 670 } | 670 } |
| 671 } | 671 } |
| 672 } | 672 } |
| 673 } | 673 } |
| OLD | NEW |