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

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

Issue 1932853002: Log urls and headers in BIDIRECTIONAL_STREAM events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 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
« no previous file with comments | « net/http/bidirectional_stream.cc ('k') | net/http/http_log_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "net/http/bidirectional_stream.h" 5 #include "net/http/bidirectional_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 EXPECT_EQ("header-value", response_headers.find("header-name")->second); 473 EXPECT_EQ("header-value", response_headers.find("header-name")->second);
474 EXPECT_EQ(1, delegate->on_data_read_count()); 474 EXPECT_EQ(1, delegate->on_data_read_count());
475 EXPECT_EQ(0, delegate->on_data_sent_count()); 475 EXPECT_EQ(0, delegate->on_data_sent_count());
476 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); 476 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol());
477 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 477 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
478 delegate->GetTotalSentBytes()); 478 delegate->GetTotalSentBytes());
479 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 479 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
480 delegate->GetTotalReceivedBytes()); 480 delegate->GetTotalReceivedBytes());
481 } 481 }
482 482
483 TEST_F(BidirectionalStreamTest, TestContainFullBytes) { 483 // Tests that the NetLog contains correct entries.
484 TEST_F(BidirectionalStreamTest, TestNetLogContainEntries) {
484 BufferedSpdyFramer framer(spdy_util_.spdy_version()); 485 BufferedSpdyFramer framer(spdy_util_.spdy_version());
485 486
486 std::unique_ptr<SpdySerializedFrame> req(spdy_util_.ConstructSpdyPost( 487 std::unique_ptr<SpdySerializedFrame> req(spdy_util_.ConstructSpdyPost(
487 "https://www.example.org", 1, kBodyDataSize * 3, LOWEST, nullptr, 0)); 488 "https://www.example.org", 1, kBodyDataSize * 3, LOWEST, nullptr, 0));
488 std::unique_ptr<SpdySerializedFrame> data_frame( 489 std::unique_ptr<SpdySerializedFrame> data_frame(
489 framer.CreateDataFrame(1, kBodyData, kBodyDataSize, DATA_FLAG_FIN)); 490 framer.CreateDataFrame(1, kBodyData, kBodyDataSize, DATA_FLAG_FIN));
490 MockWrite writes[] = { 491 MockWrite writes[] = {
491 CreateMockWrite(*req, 0), CreateMockWrite(*data_frame, 3), 492 CreateMockWrite(*req, 0), CreateMockWrite(*data_frame, 3),
492 }; 493 };
493 494
494 std::unique_ptr<SpdySerializedFrame> resp( 495 std::unique_ptr<SpdySerializedFrame> resp(
495 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); 496 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1));
496 std::unique_ptr<SpdySerializedFrame> response_body_frame1( 497 std::unique_ptr<SpdySerializedFrame> response_body_frame1(
497 spdy_util_.ConstructSpdyBodyFrame(1, false)); 498 spdy_util_.ConstructSpdyBodyFrame(1, false));
498 std::unique_ptr<SpdySerializedFrame> response_body_frame2( 499 std::unique_ptr<SpdySerializedFrame> response_body_frame2(
499 spdy_util_.ConstructSpdyBodyFrame(1, true)); 500 spdy_util_.ConstructSpdyBodyFrame(1, false));
501
502 SpdyHeaderBlock trailers;
503 trailers["foo"] = "bar";
504 std::unique_ptr<SpdySerializedFrame> response_trailers(
505 spdy_util_.ConstructSpdyResponseHeaders(1, trailers, true));
500 506
501 MockRead reads[] = { 507 MockRead reads[] = {
502 CreateMockRead(*resp, 1), 508 CreateMockRead(*resp, 1),
503 MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause. 509 MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause.
504 CreateMockRead(*response_body_frame1, 4), 510 CreateMockRead(*response_body_frame1, 4),
505 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause. 511 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause.
506 CreateMockRead(*response_body_frame2, 6), 512 CreateMockRead(*response_body_frame2, 6),
507 MockRead(ASYNC, 0, 7), 513 CreateMockRead(*response_trailers, 7),
514 MockRead(ASYNC, 0, 8),
508 }; 515 };
509 516
510 HostPortPair host_port_pair("www.example.org", 443); 517 HostPortPair host_port_pair("www.example.org", 443);
511 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), 518 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
512 PRIVACY_MODE_DISABLED); 519 PRIVACY_MODE_DISABLED);
513 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); 520 InitSession(reads, arraysize(reads), writes, arraysize(writes), key);
514 521
515 std::unique_ptr<BidirectionalStreamRequestInfo> request_info( 522 std::unique_ptr<BidirectionalStreamRequestInfo> request_info(
516 new BidirectionalStreamRequestInfo); 523 new BidirectionalStreamRequestInfo);
517 request_info->method = "POST"; 524 request_info->method = "POST";
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 sequenced_data_->Resume(); 558 sequenced_data_->Resume();
552 base::RunLoop().RunUntilIdle(); 559 base::RunLoop().RunUntilIdle();
553 // All data has been delivered, and OnClosed() has been invoked. 560 // All data has been delivered, and OnClosed() has been invoked.
554 // Read now, and it should complete synchronously. 561 // Read now, and it should complete synchronously.
555 rv = delegate->ReadData(); 562 rv = delegate->ReadData();
556 EXPECT_EQ(kUploadDataSize, rv); 563 EXPECT_EQ(kUploadDataSize, rv);
557 EXPECT_EQ("200", delegate->response_headers().find(":status")->second); 564 EXPECT_EQ("200", delegate->response_headers().find(":status")->second);
558 EXPECT_EQ(1, delegate->on_data_read_count()); 565 EXPECT_EQ(1, delegate->on_data_read_count());
559 EXPECT_EQ(1, delegate->on_data_sent_count()); 566 EXPECT_EQ(1, delegate->on_data_sent_count());
560 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol()); 567 EXPECT_EQ(kProtoHTTP2, delegate->GetProtocol());
568 EXPECT_EQ("bar", delegate->trailers().find("foo")->second);
561 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)), 569 EXPECT_EQ(CountWriteBytes(writes, arraysize(writes)),
562 delegate->GetTotalSentBytes()); 570 delegate->GetTotalSentBytes());
563 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)), 571 EXPECT_EQ(CountReadBytes(reads, arraysize(reads)),
564 delegate->GetTotalReceivedBytes()); 572 delegate->GetTotalReceivedBytes());
565 573
574 // Destroy the delegate will destroy the stream, so we can get an end event
575 // for BIDIRECTIONAL_STREAM_ALIVE.
576 delegate.reset();
566 TestNetLogEntry::List entries; 577 TestNetLogEntry::List entries;
567 net_log_.GetEntries(&entries); 578 net_log_.GetEntries(&entries);
579 size_t index = ExpectLogContainsSomewhere(
580 entries, 0, NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE, NetLog::PHASE_BEGIN);
581 // Headers received should happen after BIDIRECTIONAL_STREAM_ALIVE.
582 index = ExpectLogContainsSomewhere(
583 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_HEADERS,
584 NetLog::PHASE_NONE);
585 // Trailers received should happen after headers received. It might happen
586 // before the reads complete.
587 ExpectLogContainsSomewhere(entries, index,
588 NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_TRAILERS,
589 NetLog::PHASE_NONE);
568 // Sent bytes. Sending data is always asynchronous. 590 // Sent bytes. Sending data is always asynchronous.
569 size_t index = ExpectLogContainsSomewhere( 591 index = ExpectLogContainsSomewhere(
570 entries, 0, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_SENT, 592 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_SENT,
571 NetLog::PHASE_NONE); 593 NetLog::PHASE_NONE);
572 TestNetLogEntry entry = entries[index]; 594 TestNetLogEntry entry = entries[index];
573 EXPECT_EQ(NetLog::SOURCE_BIDIRECTIONAL_STREAM, entry.source.type); 595 EXPECT_EQ(NetLog::SOURCE_BIDIRECTIONAL_STREAM, entry.source.type);
574 // Received bytes for asynchronous read. 596 // Received bytes for asynchronous read.
575 index = ExpectLogContainsSomewhere( 597 index = ExpectLogContainsSomewhere(
576 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, 598 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED,
577 NetLog::PHASE_NONE); 599 NetLog::PHASE_NONE);
578 entry = entries[index]; 600 entry = entries[index];
579 EXPECT_EQ(NetLog::SOURCE_BIDIRECTIONAL_STREAM, entry.source.type); 601 EXPECT_EQ(NetLog::SOURCE_BIDIRECTIONAL_STREAM, entry.source.type);
580 // Received bytes for synchronous read. 602 // Received bytes for synchronous read.
581 index = ExpectLogContainsSomewhere( 603 index = ExpectLogContainsSomewhere(
582 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, 604 entries, index, NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED,
583 NetLog::PHASE_NONE); 605 NetLog::PHASE_NONE);
584 entry = entries[index]; 606 entry = entries[index];
585 EXPECT_EQ(NetLog::SOURCE_BIDIRECTIONAL_STREAM, entry.source.type); 607 EXPECT_EQ(NetLog::SOURCE_BIDIRECTIONAL_STREAM, entry.source.type);
608 ExpectLogContainsSomewhere(entries, index,
609 NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE,
610 NetLog::PHASE_END);
586 } 611 }
587 612
588 TEST_F(BidirectionalStreamTest, TestInterleaveReadDataAndSendData) { 613 TEST_F(BidirectionalStreamTest, TestInterleaveReadDataAndSendData) {
589 BufferedSpdyFramer framer(spdy_util_.spdy_version()); 614 BufferedSpdyFramer framer(spdy_util_.spdy_version());
590 615
591 std::unique_ptr<SpdySerializedFrame> req(spdy_util_.ConstructSpdyPost( 616 std::unique_ptr<SpdySerializedFrame> req(spdy_util_.ConstructSpdyPost(
592 "https://www.example.org", 1, kBodyDataSize * 3, LOWEST, nullptr, 0)); 617 "https://www.example.org", 1, kBodyDataSize * 3, LOWEST, nullptr, 0));
593 std::unique_ptr<SpdySerializedFrame> data_frame1( 618 std::unique_ptr<SpdySerializedFrame> data_frame1(
594 framer.CreateDataFrame(1, kBodyData, kBodyDataSize, DATA_FLAG_NONE)); 619 framer.CreateDataFrame(1, kBodyData, kBodyDataSize, DATA_FLAG_NONE));
595 std::unique_ptr<SpdySerializedFrame> data_frame2( 620 std::unique_ptr<SpdySerializedFrame> data_frame2(
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 }; 945 };
921 946
922 const char* const kExtraResponseHeaders[] = {"header-name", "header-value"}; 947 const char* const kExtraResponseHeaders[] = {"header-name", "header-value"};
923 948
924 std::unique_ptr<SpdySerializedFrame> resp( 949 std::unique_ptr<SpdySerializedFrame> resp(
925 spdy_util_.ConstructSpdyGetSynReply(kExtraResponseHeaders, 1, 1)); 950 spdy_util_.ConstructSpdyGetSynReply(kExtraResponseHeaders, 1, 1));
926 951
927 std::unique_ptr<SpdySerializedFrame> body_frame( 952 std::unique_ptr<SpdySerializedFrame> body_frame(
928 spdy_util_.ConstructSpdyBodyFrame(1, false)); 953 spdy_util_.ConstructSpdyBodyFrame(1, false));
929 954
930 SpdyHeaderBlock late_headers; 955 SpdyHeaderBlock trailers;
931 late_headers["foo"] = "bar"; 956 trailers["foo"] = "bar";
932 std::unique_ptr<SpdySerializedFrame> trailers( 957 std::unique_ptr<SpdySerializedFrame> response_trailers(
933 spdy_util_.ConstructSpdyResponseHeaders(1, late_headers, true)); 958 spdy_util_.ConstructSpdyResponseHeaders(1, trailers, true));
934 959
935 MockRead reads[] = { 960 MockRead reads[] = {
936 CreateMockRead(*resp, 1), CreateMockRead(*body_frame, 2), 961 CreateMockRead(*resp, 1),
937 CreateMockRead(*body_frame, 3), CreateMockRead(*body_frame, 4), 962 CreateMockRead(*body_frame, 2),
963 CreateMockRead(*body_frame, 3),
964 CreateMockRead(*body_frame, 4),
938 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause. 965 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause.
939 CreateMockRead(*trailers, 6), MockRead(SYNCHRONOUS, 0, 7), 966 CreateMockRead(*response_trailers, 6),
967 MockRead(SYNCHRONOUS, 0, 7),
940 }; 968 };
941 969
942 HostPortPair host_port_pair("www.example.org", 443); 970 HostPortPair host_port_pair("www.example.org", 443);
943 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), 971 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
944 PRIVACY_MODE_DISABLED); 972 PRIVACY_MODE_DISABLED);
945 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); 973 InitSession(reads, arraysize(reads), writes, arraysize(writes), key);
946 974
947 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize)); 975 scoped_refptr<IOBuffer> read_buffer(new IOBuffer(kReadBufferSize));
948 MockTimer* timer = new MockTimer(); 976 MockTimer* timer = new MockTimer();
949 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase( 977 std::unique_ptr<TestDelegateBase> delegate(new TestDelegateBase(
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 }; 1329 };
1302 1330
1303 const char* const kExtraResponseHeaders[] = {"header-name", "header-value"}; 1331 const char* const kExtraResponseHeaders[] = {"header-name", "header-value"};
1304 1332
1305 std::unique_ptr<SpdySerializedFrame> resp( 1333 std::unique_ptr<SpdySerializedFrame> resp(
1306 spdy_util_.ConstructSpdyGetSynReply(kExtraResponseHeaders, 1, 1)); 1334 spdy_util_.ConstructSpdyGetSynReply(kExtraResponseHeaders, 1, 1));
1307 1335
1308 std::unique_ptr<SpdySerializedFrame> response_body_frame( 1336 std::unique_ptr<SpdySerializedFrame> response_body_frame(
1309 spdy_util_.ConstructSpdyBodyFrame(1, false)); 1337 spdy_util_.ConstructSpdyBodyFrame(1, false));
1310 1338
1311 SpdyHeaderBlock late_headers; 1339 SpdyHeaderBlock trailers;
1312 late_headers["foo"] = "bar"; 1340 trailers["foo"] = "bar";
1313 std::unique_ptr<SpdySerializedFrame> trailers( 1341 std::unique_ptr<SpdySerializedFrame> response_trailers(
1314 spdy_util_.ConstructSpdyResponseHeaders(1, late_headers, true)); 1342 spdy_util_.ConstructSpdyResponseHeaders(1, trailers, true));
1315 1343
1316 MockRead reads[] = { 1344 MockRead reads[] = {
1317 CreateMockRead(*resp, 1), CreateMockRead(*response_body_frame, 2), 1345 CreateMockRead(*resp, 1), CreateMockRead(*response_body_frame, 2),
1318 CreateMockRead(*trailers, 3), MockRead(ASYNC, 0, 5), 1346 CreateMockRead(*response_trailers, 3), MockRead(ASYNC, 0, 5),
1319 }; 1347 };
1320 1348
1321 HostPortPair host_port_pair("www.example.org", 443); 1349 HostPortPair host_port_pair("www.example.org", 443);
1322 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), 1350 SpdySessionKey key(host_port_pair, ProxyServer::Direct(),
1323 PRIVACY_MODE_DISABLED); 1351 PRIVACY_MODE_DISABLED);
1324 InitSession(reads, arraysize(reads), writes, arraysize(writes), key); 1352 InitSession(reads, arraysize(reads), writes, arraysize(writes), key);
1325 1353
1326 std::unique_ptr<BidirectionalStreamRequestInfo> request_info( 1354 std::unique_ptr<BidirectionalStreamRequestInfo> request_info(
1327 new BidirectionalStreamRequestInfo); 1355 new BidirectionalStreamRequestInfo);
1328 request_info->method = "GET"; 1356 request_info->method = "GET";
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 AlternativeServiceVector alternative_service_vector = 1500 AlternativeServiceVector alternative_service_vector =
1473 http_session_->http_server_properties()->GetAlternativeServices(server); 1501 http_session_->http_server_properties()->GetAlternativeServices(server);
1474 ASSERT_EQ(1u, alternative_service_vector.size()); 1502 ASSERT_EQ(1u, alternative_service_vector.size());
1475 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3), 1503 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3),
1476 alternative_service_vector[0].protocol); 1504 alternative_service_vector[0].protocol);
1477 EXPECT_EQ("www.example.org", alternative_service_vector[0].host); 1505 EXPECT_EQ("www.example.org", alternative_service_vector[0].host);
1478 EXPECT_EQ(443, alternative_service_vector[0].port); 1506 EXPECT_EQ(443, alternative_service_vector[0].port);
1479 } 1507 }
1480 1508
1481 } // namespace net 1509 } // namespace net
OLDNEW
« no previous file with comments | « net/http/bidirectional_stream.cc ('k') | net/http/http_log_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698