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

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: 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
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 late_headers;
mef 2016/04/28 20:43:18 maybe rename late_headers => trailers and trailers
xunjieli 2016/04/28 21:06:15 Done.
503 late_headers["foo"] = "bar";
504 std::unique_ptr<SpdySerializedFrame> trailers(
505 spdy_util_.ConstructSpdyResponseHeaders(1, late_headers, 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(*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 a
575 // the end event 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 index = ExpectLogContainsSomewhere(entries, index,
mef 2016/04/28 20:43:18 anything interesting to check at this index?
xunjieli 2016/04/28 21:06:15 Done. Nothing in particular, so i have got rid of
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 876 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 AlternativeServiceVector alternative_service_vector = 1497 AlternativeServiceVector alternative_service_vector =
1473 http_session_->http_server_properties()->GetAlternativeServices(server); 1498 http_session_->http_server_properties()->GetAlternativeServices(server);
1474 ASSERT_EQ(1u, alternative_service_vector.size()); 1499 ASSERT_EQ(1u, alternative_service_vector.size());
1475 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3), 1500 EXPECT_EQ(AlternateProtocolFromNextProto(kProtoQUIC1SPDY3),
1476 alternative_service_vector[0].protocol); 1501 alternative_service_vector[0].protocol);
1477 EXPECT_EQ("www.example.org", alternative_service_vector[0].host); 1502 EXPECT_EQ("www.example.org", alternative_service_vector[0].host);
1478 EXPECT_EQ(443, alternative_service_vector[0].port); 1503 EXPECT_EQ(443, alternative_service_vector[0].port);
1479 } 1504 }
1480 1505
1481 } // namespace net 1506 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698