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

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: Address more 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
« no previous file with comments | « 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},
271 { "foo\nbar\n\njunk", 9 }, 271 {"foo", -1},
272 { "foo\nbar\n\r\njunk", 10 }, 272 {"\r\n\r\n", 4},
273 { "foo\nbar\r\n\njunk", 10 }, 273 {"foo\r\nbar\r\n\r\n", 12},
274 {"foo\nbar\n\n", 9},
275 {"foo\r\nbar\r\n\r\njunk", 12},
276 {"foo\nbar\n\njunk", 9},
277 {"foo\nbar\n\r\njunk", 10},
278 {"foo\nbar\r\n\njunk", 10},
274 }; 279 };
275 for (size_t i = 0; i < arraysize(tests); ++i) { 280 for (size_t i = 0; i < arraysize(tests); ++i) {
276 int input_len = static_cast<int>(strlen(tests[i].input)); 281 int input_len = static_cast<int>(strlen(tests[i].input));
277 int eoh = HttpUtil::LocateEndOfHeaders(tests[i].input, input_len); 282 int eoh = HttpUtil::LocateEndOfHeaders(tests[i].input, input_len);
278 EXPECT_EQ(tests[i].expected_result, eoh); 283 EXPECT_EQ(tests[i].expected_result, eoh);
279 } 284 }
280 } 285 }
281 286
287 TEST(HttpUtilTest, LocateEndOfAdditionalHeaders) {
288 struct {
289 const char* const input;
290 int expected_result;
291 } tests[] = {
292 {"\r\n", 2},
293 {"\n", 1},
294 {"\r", -1},
295 {"foo", -1},
296 {"\r\n\r\n", 2},
297 {"foo\r\nbar\r\n\r\n", 12},
298 {"foo\nbar\n\n", 9},
299 {"foo\r\nbar\r\n\r\njunk", 12},
300 {"foo\nbar\n\njunk", 9},
301 {"foo\nbar\n\r\njunk", 10},
302 {"foo\nbar\r\n\njunk", 10},
303 };
304 for (size_t i = 0; i < arraysize(tests); ++i) {
305 int input_len = static_cast<int>(strlen(tests[i].input));
306 int eoh = HttpUtil::LocateEndOfAdditionalHeaders(tests[i].input, input_len);
307 EXPECT_EQ(tests[i].expected_result, eoh);
308 }
309 }
282 TEST(HttpUtilTest, AssembleRawHeaders) { 310 TEST(HttpUtilTest, AssembleRawHeaders) {
283 struct { 311 struct {
284 const char* const input; // with '|' representing '\0' 312 const char* const input; // with '|' representing '\0'
285 const char* const expected_result; // with '\0' changed to '|' 313 const char* const expected_result; // with '\0' changed to '|'
286 } tests[] = { 314 } tests[] = {
287 { "HTTP/1.0 200 OK\r\nFoo: 1\r\nBar: 2\r\n\r\n", 315 { "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||" }, 316 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" },
289 317
290 { "HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n", 318 { "HTTP/1.0 200 OK\nFoo: 1\nBar: 2\n\n",
291 "HTTP/1.0 200 OK|Foo: 1|Bar: 2||" }, 319 "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(), ';'); 1130 HttpUtil::NameValuePairsIterator parser(data.begin(), data.end(), ';');
1103 EXPECT_TRUE(parser.valid()); 1131 EXPECT_TRUE(parser.valid());
1104 1132
1105 ASSERT_NO_FATAL_FAILURE( 1133 ASSERT_NO_FATAL_FAILURE(
1106 CheckNextNameValuePair(&parser, true, true, "name", "value")); 1134 CheckNextNameValuePair(&parser, true, true, "name", "value"));
1107 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair( 1135 ASSERT_NO_FATAL_FAILURE(CheckNextNameValuePair(
1108 &parser, false, true, std::string(), std::string())); 1136 &parser, false, true, std::string(), std::string()));
1109 } 1137 }
1110 1138
1111 } // namespace net 1139 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698