Chromium Code Reviews| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 }; | 188 }; |
| 189 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 189 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 190 int input_len = static_cast<int>(strlen(tests[i].input)); | 190 int input_len = static_cast<int>(strlen(tests[i].input)); |
| 191 int eoh = HttpUtil::LocateEndOfHeaders(tests[i].input, input_len); | 191 int eoh = HttpUtil::LocateEndOfHeaders(tests[i].input, input_len); |
| 192 EXPECT_EQ(tests[i].expected_result, eoh); | 192 EXPECT_EQ(tests[i].expected_result, eoh); |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 | 195 |
| 196 TEST(HttpUtilTest, AssembleRawHeaders) { | 196 TEST(HttpUtilTest, AssembleRawHeaders) { |
| 197 struct { | 197 struct { |
| 198 const char* input; | 198 const char* input; // with '|' representing \0 |
|
wtc
2011/09/12 18:48:09
Nit: \0 => '\0'
eroman
2011/09/12 21:19:24
Done.
| |
| 199 const char* expected_result; // with '\0' changed to '|' | 199 const char* expected_result; // with '\0' changed to '|' |
| 200 } tests[] = { | 200 } tests[] = { |
| 201 { "HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n", | 201 { "HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n", |
| 202 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, | 202 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, |
| 203 | 203 |
| 204 { "HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n", | 204 { "HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n", |
| 205 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, | 205 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, |
| 206 | 206 |
| 207 // Valid line continuation (single SP). | 207 // Valid line continuation (single SP). |
| 208 { | 208 { |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 " : 1\n" | 475 " : 1\n" |
| 476 " garbage\n" | 476 " garbage\n" |
| 477 "Bar: 2\n\n", | 477 "Bar: 2\n\n", |
| 478 | 478 |
| 479 "HTTP/1.0 200 OK|" | 479 "HTTP/1.0 200 OK|" |
| 480 " : 1|" | 480 " : 1|" |
| 481 " garbage|" | 481 " garbage|" |
| 482 "Bar: 2||", | 482 "Bar: 2||", |
| 483 }, | 483 }, |
| 484 | 484 |
| 485 // Embed NULLs in the status line. They should not be understood | |
| 486 // as line separators. | |
| 487 { | |
| 488 "HTTP/1.0 200 OK|Bar2:0|Baz2:1\r\nFoo: 1\r\nBar: 2\r\n\r\n", | |
| 489 "HTTP/1.0 200 OKBar2:0Baz2:1|Foo: 1|Bar: 2||" | |
| 490 }, | |
| 491 | |
| 492 // Embed NULLs in a header line. They should not be understood as | |
| 493 // line separators. | |
| 494 { | |
| 495 "HTTP/1.0 200 OK\nFoo: 1|Foo2: 3\nBar: 2\n\n", | |
| 496 "HTTP/1.0 200 OK|Foo: 1Foo2: 3|Bar: 2||" | |
| 497 }, | |
| 485 }; | 498 }; |
| 486 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 499 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 487 int input_len = static_cast<int>(strlen(tests[i].input)); | 500 std::string input = tests[i].input; |
| 488 std::string raw = HttpUtil::AssembleRawHeaders(tests[i].input, input_len); | 501 std::replace(input.begin(), input.end(), '|', '\0'); |
| 502 std::string raw = HttpUtil::AssembleRawHeaders(input.data(), input.size()); | |
| 489 std::replace(raw.begin(), raw.end(), '\0', '|'); | 503 std::replace(raw.begin(), raw.end(), '\0', '|'); |
| 490 EXPECT_TRUE(raw == tests[i].expected_result); | 504 EXPECT_EQ(raw, tests[i].expected_result); |
|
wtc
2011/09/12 18:48:09
Nit: reverse the arguments of EXPECT_EQ? I think
eroman
2011/09/12 21:19:24
Done.
| |
| 491 } | 505 } |
| 492 } | 506 } |
| 493 | 507 |
| 494 // Test SpecForRequest() and PathForRequest(). | 508 // Test SpecForRequest() and PathForRequest(). |
| 495 TEST(HttpUtilTest, RequestUrlSanitize) { | 509 TEST(HttpUtilTest, RequestUrlSanitize) { |
| 496 struct { | 510 struct { |
| 497 const char* url; | 511 const char* url; |
| 498 const char* expected_spec; | 512 const char* expected_spec; |
| 499 const char* expected_path; | 513 const char* expected_path; |
| 500 } tests[] = { | 514 } tests[] = { |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 TEST(HttpUtilTest, NameValuePairsIteratorMissingEndQuote) { | 878 TEST(HttpUtilTest, NameValuePairsIteratorMissingEndQuote) { |
| 865 std::string data = "name='value"; | 879 std::string data = "name='value"; |
| 866 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); | 880 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); |
| 867 EXPECT_TRUE(parser.valid()); | 881 EXPECT_TRUE(parser.valid()); |
| 868 | 882 |
| 869 ASSERT_NO_FATAL_FAILURE( | 883 ASSERT_NO_FATAL_FAILURE( |
| 870 CheckNextNameValuePair(&parser, true, true, "name", "value")); | 884 CheckNextNameValuePair(&parser, true, true, "name", "value")); |
| 871 ASSERT_NO_FATAL_FAILURE( | 885 ASSERT_NO_FATAL_FAILURE( |
| 872 CheckNextNameValuePair(&parser, false, true, "", "")); | 886 CheckNextNameValuePair(&parser, false, true, "", "")); |
| 873 } | 887 } |
| OLD | NEW |