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

Side by Side Diff: third_party/WebKit/Source/platform/network/HTTPParsersTest.cpp

Issue 2889033002: Better header value parsing for Server-Timing. (Closed)
Patch Set: use HeaderFieldTokenizer instead of redundant methods Created 3 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
OLDNEW
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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 bool result = 470 bool result =
471 ParseMultipartHeadersFromBody(kData, strlen(kData), &response, &end); 471 ParseMultipartHeadersFromBody(kData, strlen(kData), &response, &end);
472 472
473 EXPECT_TRUE(result); 473 EXPECT_TRUE(result);
474 EXPECT_EQ(strlen(kData), end); 474 EXPECT_EQ(strlen(kData), end);
475 EXPECT_EQ("text/html; charset=utf-8", 475 EXPECT_EQ("text/html; charset=utf-8",
476 response.HttpHeaderField("content-type")); 476 response.HttpHeaderField("content-type"));
477 EXPECT_EQ("utf-8", response.TextEncodingName()); 477 EXPECT_EQ("utf-8", response.TextEncodingName());
478 } 478 }
479 479
480 TEST(HTTPParsersTest, CheckDoubleQuotedString) {
481 EXPECT_EQ(CheckDoubleQuotedString(""), "");
482 EXPECT_EQ(CheckDoubleQuotedString("\""), "\"");
483 EXPECT_EQ(CheckDoubleQuotedString("\"\""), "");
484 EXPECT_EQ(CheckDoubleQuotedString("foo"), "foo");
485 EXPECT_EQ(CheckDoubleQuotedString("\"foo"), "\"foo");
486 EXPECT_EQ(CheckDoubleQuotedString("foo\""), "foo\"");
487 EXPECT_EQ(CheckDoubleQuotedString("\"foo\""), "foo");
488 EXPECT_EQ(CheckDoubleQuotedString("\"foo\"bar\""), "foo\"bar");
489 EXPECT_EQ(CheckDoubleQuotedString("\"foo\\bar\""), "foobar");
490 }
491
492 void testServerTimingHeader(const char* headerValue, 480 void testServerTimingHeader(const char* headerValue,
493 Vector<Vector<String>> expectedResults) { 481 Vector<Vector<String>> expectedResults) {
494 std::unique_ptr<ServerTimingHeaderVector> results = 482 std::unique_ptr<ServerTimingHeaderVector> results =
495 ParseServerTimingHeader(headerValue); 483 ParseServerTimingHeader(headerValue);
496 EXPECT_EQ((*results).size(), expectedResults.size()); 484 EXPECT_EQ((*results).size(), expectedResults.size());
497 unsigned i = 0; 485 unsigned i = 0;
498 for (const auto& header : *results) { 486 for (const auto& header : *results) {
499 Vector<String> expectedResult = expectedResults[i++]; 487 Vector<String> expectedResult = expectedResults[i++];
500 EXPECT_EQ(header->metric, expectedResult[0]); 488 EXPECT_EQ(header->metric, expectedResult[0]);
501 EXPECT_EQ(header->duration, expectedResult[1].ToDouble()); 489 EXPECT_EQ(header->duration, expectedResult[1].ToDouble());
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 {{"metric", "123.4", "description"}}); 955 {{"metric", "123.4", "description"}});
968 testServerTimingHeader(" metric = 123.4 ; description ,", 956 testServerTimingHeader(" metric = 123.4 ; description ,",
969 {{"metric", "123.4", "description"}}); 957 {{"metric", "123.4", "description"}});
970 958
971 testServerTimingHeader( 959 testServerTimingHeader(
972 "metric1=12.3;description1,metric2=45.6;description2,metric3=78.9;" 960 "metric1=12.3;description1,metric2=45.6;description2,metric3=78.9;"
973 "description3", 961 "description3",
974 {{"metric1", "12.3", "description1"}, 962 {{"metric1", "12.3", "description1"},
975 {"metric2", "45.6", "description2"}, 963 {"metric2", "45.6", "description2"},
976 {"metric3", "78.9", "description3"}}); 964 {"metric3", "78.9", "description3"}});
965
966 // quoted-string
967 testServerTimingHeader("metric;\"\"", {{"metric", "0", ""}});
968 testServerTimingHeader("metric;\"\"\"", {{"metric", "0", ""}});
969 testServerTimingHeader("metric;\"\\\"\"", {{"metric", "0", "\""}});
970 testServerTimingHeader("metric;\"\\\\\"\"", {{"metric", "0", "\\"}});
971 testServerTimingHeader("metric;\"\\\\\\\"\"", {{"metric", "0", "\\\""}});
Yoav Weiss 2017/06/08 06:07:55 Can you add a test where there's a leading space h
977 } 972 }
978 973
979 } // namespace blink 974 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698