Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(766)

Side by Side Diff: net/http/http_util_unittest.cc

Issue 1166953002: Use net's response header parser for parsing multipart headers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed Matt's comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« net/http/http_util.h ('K') | « net/http/http_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 // Replace <backslash> X with X 259 // Replace <backslash> X with X
260 EXPECT_STREQ("\"xyzXabc\"", HttpUtil::Quote("xyzXabc").c_str()); 260 EXPECT_STREQ("\"xyzXabc\"", HttpUtil::Quote("xyzXabc").c_str());
261 } 261 }
262 262
263 TEST(HttpUtilTest, LocateEndOfHeaders) { 263 TEST(HttpUtilTest, LocateEndOfHeaders) {
264 struct { 264 struct {
265 const char* const input; 265 const char* const input;
266 int expected_result; 266 int expected_result;
267 } tests[] = { 267 } tests[] = {
268 { "foo\r\nbar\r\n\r\n", 12 }, 268 {"\r\n", -1},
269 { "foo\nbar\n\n", 9 }, 269 {"\n", -1},
270 { "foo\r\nbar\r\n\r\njunk", 12 }, 270 {"\r", -1},
mmenke 2015/06/09 20:23:37 Suggest tossing in \r\n\r\n or \n\n.
haavardm 2015/06/10 11:54:02 Done.
271 { "foo\nbar\n\njunk", 9 }, 271 {"foo", -1},
272 { "foo\nbar\n\r\njunk", 10 }, 272 {"foo\r\nbar\r\n\r\n", 12},
273 { "foo\nbar\r\n\njunk", 10 }, 273 {"foo\nbar\n\n", 9},
274 {"foo\r\nbar\r\n\r\njunk", 12},
275 {"foo\nbar\n\njunk", 9},
276 {"foo\nbar\n\r\njunk", 10},
277 {"foo\nbar\r\n\njunk", 10},
274 }; 278 };
275 for (size_t i = 0; i < arraysize(tests); ++i) { 279 for (size_t i = 0; i < arraysize(tests); ++i) {
276 int input_len = static_cast<int>(strlen(tests[i].input)); 280 int input_len = static_cast<int>(strlen(tests[i].input));
277 int eoh = HttpUtil::LocateEndOfHeaders(tests[i].input, input_len); 281 int eoh = HttpUtil::LocateEndOfHeaders(tests[i].input, input_len);
278 EXPECT_EQ(tests[i].expected_result, eoh); 282 EXPECT_EQ(tests[i].expected_result, eoh);
279 } 283 }
280 } 284 }
281 285
286 TEST(HttpUtilTest, LocateEndOfAdditionalHeaders) {
287 struct {
288 const char* const input;
289 int expected_result;
290 } tests[] = {
291 {"\r\n", 2},
292 {"\n", 1},
293 {"\r", -1},
294 {"foo", -1},
295 {"foo\r\nbar\r\n\r\n", 12},
296 {"foo\nbar\n\n", 9},
297 {"foo\r\nbar\r\n\r\njunk", 12},
298 {"foo\nbar\n\njunk", 9},
299 {"foo\nbar\n\r\njunk", 10},
300 {"foo\nbar\r\n\njunk", 10},
301 };
302 for (size_t i = 0; i < arraysize(tests); ++i) {
303 int input_len = static_cast<int>(strlen(tests[i].input));
304 int eoh = HttpUtil::LocateEndOfAdditionalHeaders(tests[i].input, input_len);
305 EXPECT_EQ(tests[i].expected_result, eoh);
306 }
307 }
282 TEST(HttpUtilTest, AssembleRawHeaders) { 308 TEST(HttpUtilTest, AssembleRawHeaders) {
283 struct { 309 struct {
284 const char* const input; // with '|' representing '\0' 310 const char* const input; // with '|' representing '\0'
285 const char* const expected_result; // with '\0' changed to '|' 311 const char* const expected_result; // with '\0' changed to '|'
286 } tests[] = { 312 } tests[] = {
287 { "HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n", 313 { "HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n",
288 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, 314 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" },
289 315
290 { "HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n", 316 { "HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n",
291 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, 317 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" },
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';'); 1128 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';');
1103 EXPECT_TRUE(parser.valid()); 1129 EXPECT_TRUE(parser.valid());
1104 1130
1105 ASSERT_NO_FATAL_FAILURE( 1131 ASSERT_NO_FATAL_FAILURE(
1106 CheckNextNameValuePair(&parser, true, true, "name", "value")); 1132 CheckNextNameValuePair(&parser, true, true, "name", "value"));
1107 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( 1133 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair(
1108 &parser, false, true, std::string(), std::string())); 1134 &parser, false, true, std::string(), std::string()));
1109 } 1135 }
1110 1136
1111 } // namespace net 1137 } // namespace net
OLDNEW
« net/http/http_util.h ('K') | « net/http/http_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698