Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "platform/network/HTTPParsers.h" | 5 #include "platform/network/HTTPParsers.h" |
| 6 | 6 |
| 7 #include "platform/heap/Handle.h" | 7 #include "platform/heap/Handle.h" |
| 8 #include "platform/loader/fetch/ResourceResponse.h" | 8 #include "platform/loader/fetch/ResourceResponse.h" |
| 9 #include "platform/weborigin/Suborigin.h" | 9 #include "platform/weborigin/Suborigin.h" |
| 10 #include "platform/wtf/MathExtras.h" | 10 #include "platform/wtf/MathExtras.h" |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 bool result = | 493 bool result = |
| 494 ParseMultipartHeadersFromBody(kData, strlen(kData), &response, &end); | 494 ParseMultipartHeadersFromBody(kData, strlen(kData), &response, &end); |
| 495 | 495 |
| 496 EXPECT_TRUE(result); | 496 EXPECT_TRUE(result); |
| 497 EXPECT_EQ(strlen(kData), end); | 497 EXPECT_EQ(strlen(kData), end); |
| 498 EXPECT_EQ("text/html; charset=utf-8", | 498 EXPECT_EQ("text/html; charset=utf-8", |
| 499 response.HttpHeaderField("content-type")); | 499 response.HttpHeaderField("content-type")); |
| 500 EXPECT_EQ("utf-8", response.TextEncodingName()); | 500 EXPECT_EQ("utf-8", response.TextEncodingName()); |
| 501 } | 501 } |
| 502 | 502 |
| 503 TEST(HTTPParsersTest, CheckDoubleQuotedString) { | |
| 504 EXPECT_EQ(CheckDoubleQuotedString(""), ""); | |
| 505 EXPECT_EQ(CheckDoubleQuotedString("\""), "\""); | |
| 506 EXPECT_EQ(CheckDoubleQuotedString("\"\""), ""); | |
| 507 EXPECT_EQ(CheckDoubleQuotedString("foo"), "foo"); | |
| 508 EXPECT_EQ(CheckDoubleQuotedString("\"foo"), "\"foo"); | |
| 509 EXPECT_EQ(CheckDoubleQuotedString("foo\""), "foo\""); | |
| 510 EXPECT_EQ(CheckDoubleQuotedString("\"foo\""), "foo"); | |
| 511 EXPECT_EQ(CheckDoubleQuotedString("\"foo\"bar\""), "foo\"bar"); | |
| 512 EXPECT_EQ(CheckDoubleQuotedString("\"foo\\bar\""), "foobar"); | |
| 513 } | |
| 514 | |
| 515 void testServerTimingHeader(const char* headerValue, | 503 void testServerTimingHeader(const char* headerValue, |
| 516 Vector<Vector<String>> expectedResults) { | 504 Vector<Vector<String>> expectedResults) { |
| 517 std::unique_ptr<ServerTimingHeaderVector> results = | 505 std::unique_ptr<ServerTimingHeaderVector> results = |
| 518 ParseServerTimingHeader(headerValue); | 506 ParseServerTimingHeader(headerValue); |
| 519 EXPECT_EQ((*results).size(), expectedResults.size()); | 507 EXPECT_EQ((*results).size(), expectedResults.size()); |
| 520 unsigned i = 0; | 508 unsigned i = 0; |
| 521 for (const auto& header : *results) { | 509 for (const auto& header : *results) { |
| 522 Vector<String> expectedResult = expectedResults[i++]; | 510 Vector<String> expectedResult = expectedResults[i++]; |
| 523 EXPECT_EQ(header->metric, expectedResult[0]); | 511 EXPECT_EQ(header->metric, expectedResult[0]); |
| 524 EXPECT_EQ(header->duration, expectedResult[1].ToDouble()); | 512 EXPECT_EQ(header->duration, expectedResult[1].ToDouble()); |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 990 {{"metric", "123.4", "description"}}); | 978 {{"metric", "123.4", "description"}}); |
| 991 testServerTimingHeader(" metric = 123.4 ; description ,", | 979 testServerTimingHeader(" metric = 123.4 ; description ,", |
| 992 {{"metric", "123.4", "description"}}); | 980 {{"metric", "123.4", "description"}}); |
| 993 | 981 |
| 994 testServerTimingHeader( | 982 testServerTimingHeader( |
| 995 "metric1=12.3;description1,metric2=45.6;description2,metric3=78.9;" | 983 "metric1=12.3;description1,metric2=45.6;description2,metric3=78.9;" |
| 996 "description3", | 984 "description3", |
| 997 {{"metric1", "12.3", "description1"}, | 985 {{"metric1", "12.3", "description1"}, |
| 998 {"metric2", "45.6", "description2"}, | 986 {"metric2", "45.6", "description2"}, |
| 999 {"metric3", "78.9", "description3"}}); | 987 {"metric3", "78.9", "description3"}}); |
| 988 | |
| 989 // header value: metric;"description" | |
| 990 // expected description: description | |
| 991 testServerTimingHeader("metric;\"description\"", | |
| 992 {{"metric", "0", "description"}}); | |
| 993 | |
| 994 // header value: metric;"1\"2" | |
| 995 // expected description: 1"2 | |
| 996 std::string headerValue = "metric;"; | |
| 997 headerValue.push_back('"'); | |
| 998 headerValue.push_back('1'); | |
| 999 headerValue.push_back('\\'); | |
| 1000 headerValue.push_back('"'); | |
| 1001 headerValue.push_back('2'); | |
| 1002 headerValue.push_back('"'); | |
|
Yoav Weiss
2017/05/18 21:45:05
Why are you pushing back the chars here? Did strin
| |
| 1003 std::string expectedDescription = ""; | |
| 1004 expectedDescription.push_back('1'); | |
| 1005 expectedDescription.push_back('"'); | |
| 1006 expectedDescription.push_back('2'); | |
| 1007 testServerTimingHeader( | |
| 1008 headerValue.c_str(), | |
| 1009 {{"metric", "0", String(expectedDescription.c_str())}}); | |
| 1010 | |
| 1011 // header value: metric;"1\=\;\,2" | |
| 1012 // expected description: 1=;,2 | |
| 1013 testServerTimingHeader("metric;\"1\\=\\;\\,2\"", {{"metric", "0", "1=;,2"}}); | |
| 1014 | |
| 1015 // header value: metric;"1=;,2" | |
| 1016 // expected description: 1=;,2 | |
| 1017 testServerTimingHeader("metric;\"1=;,2\"", {{"metric", "0", "1=;,2"}}); | |
| 1000 } | 1018 } |
| 1001 | 1019 |
| 1002 } // namespace blink | 1020 } // namespace blink |
| OLD | NEW |