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

Side by Side Diff: net/quic/chromium/quic_network_transaction_unittest.cc

Issue 2167853003: [DevTools] Always report encodedDataLength in Network.ResponseReceived. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes Created 4 years, 3 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <memory> 5 #include <memory>
6 #include <ostream> 6 #include <ostream>
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "net/socket/socket_performance_watcher.h" 52 #include "net/socket/socket_performance_watcher.h"
53 #include "net/socket/socket_performance_watcher_factory.h" 53 #include "net/socket/socket_performance_watcher_factory.h"
54 #include "net/socket/socket_test_util.h" 54 #include "net/socket/socket_test_util.h"
55 #include "net/socket/ssl_client_socket.h" 55 #include "net/socket/ssl_client_socket.h"
56 #include "net/spdy/spdy_frame_builder.h" 56 #include "net/spdy/spdy_frame_builder.h"
57 #include "net/spdy/spdy_framer.h" 57 #include "net/spdy/spdy_framer.h"
58 #include "net/ssl/ssl_config_service_defaults.h" 58 #include "net/ssl/ssl_config_service_defaults.h"
59 #include "net/test/cert_test_util.h" 59 #include "net/test/cert_test_util.h"
60 #include "net/test/gtest_util.h" 60 #include "net/test/gtest_util.h"
61 #include "net/test/test_data_directory.h" 61 #include "net/test/test_data_directory.h"
62 #include "net/url_request/url_request.h"
63 #include "net/url_request/url_request_job_factory_impl.h"
64 #include "net/url_request/url_request_test_util.h"
62 #include "testing/gmock/include/gmock/gmock.h" 65 #include "testing/gmock/include/gmock/gmock.h"
63 #include "testing/gtest/include/gtest/gtest.h" 66 #include "testing/gtest/include/gtest/gtest.h"
64 #include "testing/platform_test.h" 67 #include "testing/platform_test.h"
65 #include "url/gurl.h" 68 #include "url/gurl.h"
66 69
67 using net::test::IsError; 70 using net::test::IsError;
68 using net::test::IsOk; 71 using net::test::IsOk;
69 72
70 namespace net { 73 namespace net {
71 namespace test { 74 namespace test {
(...skipping 2450 matching lines...) Expand 10 before | Expand all | Expand 10 after
2522 &server_header_offset)); 2525 &server_header_offset));
2523 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 2, 1, 1)); 2526 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 2, 1, 1));
2524 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( 2527 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
2525 3, kServerDataStreamId1, false, false, GetResponseHeaders("200 OK"), 2528 3, kServerDataStreamId1, false, false, GetResponseHeaders("200 OK"),
2526 &server_header_offset)); 2529 &server_header_offset));
2527 mock_quic_data.AddRead(ConstructServerDataPacket(4, kClientDataStreamId1, 2530 mock_quic_data.AddRead(ConstructServerDataPacket(4, kClientDataStreamId1,
2528 false, true, 0, "hello!")); 2531 false, true, 0, "hello!"));
2529 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 4, 3, 1)); 2532 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 4, 3, 1));
2530 mock_quic_data.AddRead(ConstructServerDataPacket( 2533 mock_quic_data.AddRead(ConstructServerDataPacket(
2531 5, kServerDataStreamId1, false, true, 0, "and hello!")); 2534 5, kServerDataStreamId1, false, true, 0, "and hello!"));
2532 mock_quic_data.AddWrite( 2535 mock_quic_data.AddWrite(ConstructClientAckAndRstPacket(
2533 ConstructClientAckAndRstPacket(4, 4, QUIC_RST_ACKNOWLEDGEMENT, 5, 5, 1)); 2536 4, kServerDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 5, 5, 1));
2534 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read 2537 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read
2535 mock_quic_data.AddRead(ASYNC, 0); // EOF 2538 mock_quic_data.AddRead(ASYNC, 0); // EOF
2536 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 2539 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
2537 2540
2538 // The non-alternate protocol job needs to hang in order to guarantee that 2541 // The non-alternate protocol job needs to hang in order to guarantee that
2539 // the alternate-protocol job will "win". 2542 // the alternate-protocol job will "win".
2540 AddHangingNonAlternateProtocolSocketData(); 2543 AddHangingNonAlternateProtocolSocketData();
2541 2544
2542 CreateSession(); 2545 CreateSession();
2543 2546
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 CreateSession(); 2605 CreateSession();
2603 request_.method = "POST"; 2606 request_.method = "POST";
2604 ChunkedUploadDataStream upload_data(0); 2607 ChunkedUploadDataStream upload_data(0);
2605 upload_data.AppendData("1", 1, true); 2608 upload_data.AppendData("1", 1, true);
2606 2609
2607 request_.upload_data_stream = &upload_data; 2610 request_.upload_data_stream = &upload_data;
2608 2611
2609 SendRequestAndExpectQuicResponse("hello!"); 2612 SendRequestAndExpectQuicResponse("hello!");
2610 } 2613 }
2611 2614
2615 class QuicURLRequestContext : public URLRequestContext {
2616 public:
2617 QuicURLRequestContext(std::unique_ptr<HttpNetworkSession> session,
2618 MockClientSocketFactory* socket_factory)
2619 : storage_(this) {
2620 socket_factory_ = socket_factory;
2621 storage_.set_host_resolver(
2622 std::unique_ptr<HostResolver>(new MockHostResolver));
2623 storage_.set_cert_verifier(base::WrapUnique(new MockCertVerifier));
2624 storage_.set_transport_security_state(
2625 base::WrapUnique(new TransportSecurityState));
2626 storage_.set_proxy_service(ProxyService::CreateDirect());
2627 storage_.set_ssl_config_service(new SSLConfigServiceDefaults);
2628 storage_.set_http_auth_handler_factory(
2629 HttpAuthHandlerFactory::CreateDefault(host_resolver()));
2630 storage_.set_http_server_properties(
2631 std::unique_ptr<HttpServerProperties>(new HttpServerPropertiesImpl()));
2632 storage_.set_job_factory(base::WrapUnique(new URLRequestJobFactoryImpl()));
2633 storage_.set_http_network_session(std::move(session));
2634 storage_.set_http_transaction_factory(base::WrapUnique(
2635 new HttpCache(storage_.http_network_session(),
2636 HttpCache::DefaultBackend::InMemory(0), false)));
2637 }
2638
2639 ~QuicURLRequestContext() override { AssertNoURLRequests(); }
2640
2641 MockClientSocketFactory& socket_factory() { return *socket_factory_; }
2642
2643 private:
2644 MockClientSocketFactory* socket_factory_;
2645 URLRequestContextStorage storage_;
2646 };
2647
2648 TEST_P(QuicNetworkTransactionTest, RawHeaderSizeSuccessfullRequest) {
2649 params_.origins_to_force_quic_on.insert(
2650 HostPortPair::FromString("mail.example.org:443"));
2651
2652 MockQuicData mock_quic_data;
2653 SpdyHeaderBlock headers(GetRequestHeaders("GET", "https", "/"));
2654 headers["user-agent"] = "";
2655 headers["accept-encoding"] = "gzip, deflate";
2656 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
2657 1, kClientDataStreamId1, true, true, std::move(headers)));
2658
2659 QuicStreamOffset expected_raw_header_response_size = 0;
2660 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
2661 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"),
2662 &expected_raw_header_response_size));
2663
2664 mock_quic_data.AddRead(ConstructServerDataPacket(
2665 2, kClientDataStreamId1, false, true, 0, "Main Resource Data"));
2666 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 1));
2667
2668 mock_quic_data.AddRead(ASYNC, 0); // EOF
2669
2670 CreateSession();
2671
2672 TestDelegate delegate;
2673 QuicURLRequestContext quic_url_request_context(std::move(session_),
2674 &socket_factory_);
2675
2676 mock_quic_data.AddSocketDataToFactory(
2677 &quic_url_request_context.socket_factory());
2678 TestNetworkDelegate network_delegate;
2679 quic_url_request_context.set_network_delegate(&network_delegate);
2680
2681 std::unique_ptr<URLRequest> request(quic_url_request_context.CreateRequest(
2682 GURL("https://mail.example.org/"), DEFAULT_PRIORITY, &delegate));
2683 quic_url_request_context.socket_factory().AddSSLSocketDataProvider(
2684 &ssl_data_);
2685
2686 request->Start();
2687 base::RunLoop().Run();
2688
2689 EXPECT_LT(0, request->GetTotalSentBytes());
2690 EXPECT_LT(0, request->GetTotalReceivedBytes());
2691 EXPECT_EQ(network_delegate.total_network_bytes_sent(),
2692 request->GetTotalSentBytes());
2693 EXPECT_EQ(network_delegate.total_network_bytes_received(),
2694 request->GetTotalReceivedBytes());
2695 EXPECT_EQ(static_cast<int>(expected_raw_header_response_size),
2696 request->raw_header_size());
2697 EXPECT_TRUE(mock_quic_data.AllReadDataConsumed());
2698 EXPECT_TRUE(mock_quic_data.AllWriteDataConsumed());
2699 }
2700
2701 TEST_P(QuicNetworkTransactionTest, RawHeaderSizeSuccessfullPushHeadersFirst) {
2702 params_.origins_to_force_quic_on.insert(
2703 HostPortPair::FromString("mail.example.org:443"));
2704
2705 MockQuicData mock_quic_data;
2706 SpdyHeaderBlock headers(GetRequestHeaders("GET", "https", "/"));
2707 headers["user-agent"] = "";
2708 headers["accept-encoding"] = "gzip, deflate";
2709 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket(
2710 1, kClientDataStreamId1, true, true, std::move(headers)));
2711
2712 QuicStreamOffset server_header_offset = 0;
2713 QuicStreamOffset expected_raw_header_response_size = 0;
2714
2715 mock_quic_data.AddRead(ConstructServerPushPromisePacket(
2716 1, kClientDataStreamId1, kServerDataStreamId1, false,
2717 GetRequestHeaders("GET", "https", "/pushed.jpg"), &server_header_offset,
2718 &server_maker_));
2719
2720 expected_raw_header_response_size = server_header_offset;
2721 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
2722 2, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"),
2723 &server_header_offset));
2724 expected_raw_header_response_size =
2725 server_header_offset - expected_raw_header_response_size;
2726
2727 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 2, 1, 1));
2728
2729 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket(
2730 3, kServerDataStreamId1, false, false, GetResponseHeaders("200 OK"),
2731 &server_header_offset));
2732 mock_quic_data.AddRead(ConstructServerDataPacket(
2733 4, kServerDataStreamId1, false, true, 0, "Pushed Resource Data"));
2734
2735 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 4, 3, 1));
2736 mock_quic_data.AddRead(ConstructServerDataPacket(
2737 5, kClientDataStreamId1, false, true, 0, "Main Resource Data"));
2738
2739 mock_quic_data.AddRead(ConstructServerConnectionClosePacket(6));
2740
2741 CreateSession();
2742
2743 TestDelegate delegate;
2744 QuicURLRequestContext quic_url_request_context(std::move(session_),
2745 &socket_factory_);
2746
2747 mock_quic_data.AddSocketDataToFactory(
2748 &quic_url_request_context.socket_factory());
2749 TestNetworkDelegate network_delegate;
2750 quic_url_request_context.set_network_delegate(&network_delegate);
2751
2752 std::unique_ptr<URLRequest> request(quic_url_request_context.CreateRequest(
2753 GURL("https://mail.example.org/"), DEFAULT_PRIORITY, &delegate));
2754 quic_url_request_context.socket_factory().AddSSLSocketDataProvider(
2755 &ssl_data_);
2756
2757 request->Start();
2758 base::RunLoop().Run();
2759
2760 EXPECT_LT(0, request->GetTotalSentBytes());
2761 EXPECT_LT(0, request->GetTotalReceivedBytes());
2762 EXPECT_EQ(network_delegate.total_network_bytes_sent(),
2763 request->GetTotalSentBytes());
2764 EXPECT_EQ(network_delegate.total_network_bytes_received(),
2765 request->GetTotalReceivedBytes());
2766 EXPECT_EQ(static_cast<int>(expected_raw_header_response_size),
2767 request->raw_header_size());
2768 EXPECT_TRUE(mock_quic_data.AllReadDataConsumed());
2769 EXPECT_TRUE(mock_quic_data.AllWriteDataConsumed());
2770 }
2771
2612 class QuicNetworkTransactionWithDestinationTest 2772 class QuicNetworkTransactionWithDestinationTest
2613 : public PlatformTest, 2773 : public PlatformTest,
2614 public ::testing::WithParamInterface<PoolingTestParams> { 2774 public ::testing::WithParamInterface<PoolingTestParams> {
2615 protected: 2775 protected:
2616 QuicNetworkTransactionWithDestinationTest() 2776 QuicNetworkTransactionWithDestinationTest()
2617 : clock_(new MockClock), 2777 : clock_(new MockClock),
2618 version_(GetParam().version), 2778 version_(GetParam().version),
2619 destination_type_(GetParam().destination_type), 2779 destination_type_(GetParam().destination_type),
2620 cert_transparency_verifier_(new MultiLogCTVerifier()), 2780 cert_transparency_verifier_(new MultiLogCTVerifier()),
2621 ssl_config_service_(new SSLConfigServiceDefaults), 2781 ssl_config_service_(new SSLConfigServiceDefaults),
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
3024 AddHangingSocketData(); 3184 AddHangingSocketData();
3025 3185
3026 SendRequestAndExpectQuicResponse(origin1_); 3186 SendRequestAndExpectQuicResponse(origin1_);
3027 SendRequestAndExpectQuicResponse(origin2_); 3187 SendRequestAndExpectQuicResponse(origin2_);
3028 3188
3029 EXPECT_TRUE(AllDataConsumed()); 3189 EXPECT_TRUE(AllDataConsumed());
3030 } 3190 }
3031 3191
3032 } // namespace test 3192 } // namespace test
3033 } // namespace net 3193 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698