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

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

Issue 2889033002: Better header value parsing for Server-Timing. (Closed)
Patch Set: test escaped double-quotes Created 3 years, 7 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 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 // quoted-string
990 testServerTimingHeader("metric;\"\"", {{"metric", "0", ""}});
991 testServerTimingHeader("metric;\"\"\"", {{"metric", "0", ""}});
992 testServerTimingHeader("metric;\"\\\"\"", {{"metric", "0", "\""}});
993 testServerTimingHeader("metric;\"\\\\\"\"", {{"metric", "0", "\\"}});
994 testServerTimingHeader("metric;\"\\\\\\\"\"", {{"metric", "0", "\\\""}});
1000 } 995 }
1001 996
1002 } // namespace blink 997 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698