Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 #include "net/socket/socket_performance_watcher.h" | 51 #include "net/socket/socket_performance_watcher.h" |
| 52 #include "net/socket/socket_performance_watcher_factory.h" | 52 #include "net/socket/socket_performance_watcher_factory.h" |
| 53 #include "net/socket/socket_test_util.h" | 53 #include "net/socket/socket_test_util.h" |
| 54 #include "net/socket/ssl_client_socket.h" | 54 #include "net/socket/ssl_client_socket.h" |
| 55 #include "net/spdy/spdy_frame_builder.h" | 55 #include "net/spdy/spdy_frame_builder.h" |
| 56 #include "net/spdy/spdy_framer.h" | 56 #include "net/spdy/spdy_framer.h" |
| 57 #include "net/ssl/ssl_config_service_defaults.h" | 57 #include "net/ssl/ssl_config_service_defaults.h" |
| 58 #include "net/test/cert_test_util.h" | 58 #include "net/test/cert_test_util.h" |
| 59 #include "net/test/gtest_util.h" | 59 #include "net/test/gtest_util.h" |
| 60 #include "net/test/test_data_directory.h" | 60 #include "net/test/test_data_directory.h" |
| 61 #include "net/url_request/url_request.h" | |
| 62 #include "net/url_request/url_request_job_factory_impl.h" | |
| 63 #include "net/url_request/url_request_test_util.h" | |
| 61 #include "testing/gmock/include/gmock/gmock.h" | 64 #include "testing/gmock/include/gmock/gmock.h" |
| 62 #include "testing/gtest/include/gtest/gtest.h" | 65 #include "testing/gtest/include/gtest/gtest.h" |
| 63 #include "testing/platform_test.h" | 66 #include "testing/platform_test.h" |
| 64 #include "url/gurl.h" | 67 #include "url/gurl.h" |
| 65 | 68 |
| 66 using net::test::IsError; | 69 using net::test::IsError; |
| 67 using net::test::IsOk; | 70 using net::test::IsOk; |
| 68 | 71 |
| 69 namespace net { | 72 namespace net { |
| 70 namespace test { | 73 namespace test { |
| (...skipping 2401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2472 &server_header_offset)); | 2475 &server_header_offset)); |
| 2473 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 2, 1, 1)); | 2476 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 2, 1, 1)); |
| 2474 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | 2477 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( |
| 2475 3, kServerDataStreamId1, false, false, GetResponseHeaders("200 OK"), | 2478 3, kServerDataStreamId1, false, false, GetResponseHeaders("200 OK"), |
| 2476 &server_header_offset)); | 2479 &server_header_offset)); |
| 2477 mock_quic_data.AddRead(ConstructServerDataPacket(4, kClientDataStreamId1, | 2480 mock_quic_data.AddRead(ConstructServerDataPacket(4, kClientDataStreamId1, |
| 2478 false, true, 0, "hello!")); | 2481 false, true, 0, "hello!")); |
| 2479 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 4, 3, 1)); | 2482 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 4, 3, 1)); |
| 2480 mock_quic_data.AddRead(ConstructServerDataPacket( | 2483 mock_quic_data.AddRead(ConstructServerDataPacket( |
| 2481 5, kServerDataStreamId1, false, true, 0, "and hello!")); | 2484 5, kServerDataStreamId1, false, true, 0, "and hello!")); |
| 2482 mock_quic_data.AddWrite( | 2485 mock_quic_data.AddWrite(ConstructClientAckAndRstPacket( |
| 2483 ConstructClientAckAndRstPacket(4, 4, QUIC_RST_ACKNOWLEDGEMENT, 5, 5, 1)); | 2486 4, kServerDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 5, 5, 1)); |
| 2484 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read | 2487 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
| 2485 mock_quic_data.AddRead(ASYNC, 0); // EOF | 2488 mock_quic_data.AddRead(ASYNC, 0); // EOF |
| 2486 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 2489 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
| 2487 | 2490 |
| 2488 // The non-alternate protocol job needs to hang in order to guarantee that | 2491 // The non-alternate protocol job needs to hang in order to guarantee that |
| 2489 // the alternate-protocol job will "win". | 2492 // the alternate-protocol job will "win". |
| 2490 AddHangingNonAlternateProtocolSocketData(); | 2493 AddHangingNonAlternateProtocolSocketData(); |
| 2491 | 2494 |
| 2492 CreateSession(); | 2495 CreateSession(); |
| 2493 | 2496 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2552 CreateSession(); | 2555 CreateSession(); |
| 2553 request_.method = "POST"; | 2556 request_.method = "POST"; |
| 2554 ChunkedUploadDataStream upload_data(0); | 2557 ChunkedUploadDataStream upload_data(0); |
| 2555 upload_data.AppendData("1", 1, true); | 2558 upload_data.AppendData("1", 1, true); |
| 2556 | 2559 |
| 2557 request_.upload_data_stream = &upload_data; | 2560 request_.upload_data_stream = &upload_data; |
| 2558 | 2561 |
| 2559 SendRequestAndExpectQuicResponse("hello!"); | 2562 SendRequestAndExpectQuicResponse("hello!"); |
| 2560 } | 2563 } |
| 2561 | 2564 |
| 2565 class QuicURLRequestContext : public URLRequestContext { | |
| 2566 public: | |
| 2567 QuicURLRequestContext(std::unique_ptr<HttpNetworkSession> session, | |
| 2568 MockClientSocketFactory* socket_factory) | |
| 2569 : storage_(this) { | |
| 2570 socket_factory_ = socket_factory; | |
| 2571 storage_.set_host_resolver( | |
| 2572 std::unique_ptr<HostResolver>(new MockHostResolver)); | |
| 2573 storage_.set_cert_verifier(base::WrapUnique(new MockCertVerifier)); | |
| 2574 storage_.set_transport_security_state( | |
| 2575 base::WrapUnique(new TransportSecurityState)); | |
| 2576 storage_.set_proxy_service(ProxyService::CreateDirect()); | |
| 2577 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); | |
| 2578 storage_.set_http_auth_handler_factory( | |
| 2579 HttpAuthHandlerFactory::CreateDefault(host_resolver())); | |
| 2580 storage_.set_http_server_properties( | |
| 2581 std::unique_ptr<HttpServerProperties>(new HttpServerPropertiesImpl())); | |
| 2582 storage_.set_job_factory(base::WrapUnique(new URLRequestJobFactoryImpl())); | |
| 2583 storage_.set_http_network_session(std::move(session)); | |
| 2584 storage_.set_http_transaction_factory(base::WrapUnique( | |
| 2585 new HttpCache(storage_.http_network_session(), | |
| 2586 HttpCache::DefaultBackend::InMemory(0), false))); | |
| 2587 } | |
| 2588 | |
| 2589 ~QuicURLRequestContext() override { AssertNoURLRequests(); } | |
| 2590 | |
| 2591 MockClientSocketFactory& socket_factory() { return *socket_factory_; } | |
| 2592 | |
| 2593 private: | |
| 2594 MockClientSocketFactory* socket_factory_; | |
| 2595 URLRequestContextStorage storage_; | |
| 2596 }; | |
| 2597 | |
| 2598 TEST_P(QuicNetworkTransactionTest, RawHeaderSizeSuccessfullRequest) { | |
| 2599 params_.origins_to_force_quic_on.insert( | |
| 2600 HostPortPair::FromString("mail.example.org:443")); | |
| 2601 | |
| 2602 MockQuicData mock_quic_data; | |
| 2603 SpdyHeaderBlock headers(GetRequestHeaders("GET", "https", "/")); | |
| 2604 headers["user-agent"] = ""; | |
| 2605 headers["accept-encoding"] = "gzip, deflate"; | |
| 2606 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( | |
| 2607 1, kClientDataStreamId1, true, true, std::move(headers))); | |
| 2608 | |
| 2609 QuicStreamOffset expected_raw_header_response_size = 0; | |
| 2610 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | |
| 2611 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"), | |
| 2612 &expected_raw_header_response_size)); | |
| 2613 | |
| 2614 mock_quic_data.AddRead(ConstructServerDataPacket( | |
| 2615 2, kClientDataStreamId1, false, true, 0, "Main Resource Data")); | |
| 2616 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 1)); | |
| 2617 | |
| 2618 mock_quic_data.AddRead(ASYNC, 0); // EOF | |
| 2619 | |
| 2620 CreateSession(); | |
| 2621 | |
| 2622 TestDelegate d; | |
|
Ryan Hamilton
2016/09/07 16:54:50
nit: "delegate" instead of "d".
https://google.g
allada
2016/09/07 18:14:57
The reason I was naming these variables simple is
Ryan Hamilton
2016/09/07 18:39:40
That's surprising! I don't see single character va
| |
| 2623 QuicURLRequestContext quic_url_request_context(std::move(session_), | |
| 2624 &socket_factory_); | |
| 2625 | |
| 2626 mock_quic_data.AddSocketDataToFactory( | |
| 2627 &quic_url_request_context.socket_factory()); | |
| 2628 TestNetworkDelegate network_delegate_; | |
| 2629 quic_url_request_context.set_network_delegate(&network_delegate_); | |
| 2630 | |
| 2631 std::unique_ptr<URLRequest> request(quic_url_request_context.CreateRequest( | |
| 2632 GURL("https://mail.example.org/"), DEFAULT_PRIORITY, &d)); | |
| 2633 quic_url_request_context.socket_factory().AddSSLSocketDataProvider( | |
| 2634 &ssl_data_); | |
| 2635 | |
| 2636 request->Start(); | |
| 2637 base::RunLoop().Run(); | |
| 2638 | |
| 2639 EXPECT_GT(request->GetTotalSentBytes(), 0); | |
|
Ryan Hamilton
2016/09/07 16:54:50
nit: I'm accustomed to seeing EXPECT written (expe
allada
2016/09/07 18:14:56
Done.
| |
| 2640 EXPECT_GT(request->GetTotalReceivedBytes(), 0); | |
| 2641 EXPECT_EQ(network_delegate_.total_network_bytes_sent(), | |
| 2642 request->GetTotalSentBytes()); | |
| 2643 EXPECT_EQ(network_delegate_.total_network_bytes_received(), | |
| 2644 request->GetTotalReceivedBytes()); | |
| 2645 EXPECT_EQ((int)expected_raw_header_response_size, request->raw_header_size()); | |
|
Ryan Hamilton
2016/09/07 16:54:50
nit: static_cast instead of (int).
allada
2016/09/07 18:14:56
Done.
| |
| 2646 EXPECT_TRUE(mock_quic_data.AllReadDataConsumed()); | |
| 2647 EXPECT_TRUE(mock_quic_data.AllWriteDataConsumed()); | |
| 2648 } | |
| 2649 | |
| 2650 TEST_P(QuicNetworkTransactionTest, RawHeaderSizeSuccessfullPushHeadersFirst) { | |
| 2651 params_.origins_to_force_quic_on.insert( | |
| 2652 HostPortPair::FromString("mail.example.org:443")); | |
| 2653 | |
| 2654 MockQuicData mock_quic_data; | |
| 2655 SpdyHeaderBlock headers(GetRequestHeaders("GET", "https", "/")); | |
| 2656 headers["user-agent"] = ""; | |
| 2657 headers["accept-encoding"] = "gzip, deflate"; | |
| 2658 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( | |
| 2659 1, kClientDataStreamId1, true, true, std::move(headers))); | |
| 2660 | |
| 2661 QuicStreamOffset server_header_offset = 0; | |
| 2662 QuicStreamOffset expected_raw_header_response_size = 0; | |
| 2663 | |
| 2664 mock_quic_data.AddRead(ConstructServerPushPromisePacket( | |
| 2665 1, kClientDataStreamId1, kServerDataStreamId1, false, | |
| 2666 GetRequestHeaders("GET", "https", "/pushed.jpg"), &server_header_offset, | |
| 2667 &server_maker_)); | |
| 2668 | |
| 2669 expected_raw_header_response_size = server_header_offset; | |
| 2670 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | |
| 2671 2, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"), | |
| 2672 &server_header_offset)); | |
| 2673 expected_raw_header_response_size = | |
| 2674 server_header_offset - expected_raw_header_response_size; | |
| 2675 | |
| 2676 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 2, 1, 1)); | |
| 2677 | |
| 2678 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | |
| 2679 3, kServerDataStreamId1, false, false, GetResponseHeaders("200 OK"), | |
| 2680 &server_header_offset)); | |
| 2681 mock_quic_data.AddRead(ConstructServerDataPacket( | |
| 2682 4, kServerDataStreamId1, false, true, 0, "Pushed Resource Data")); | |
| 2683 | |
| 2684 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 4, 3, 1)); | |
| 2685 mock_quic_data.AddRead(ConstructServerDataPacket( | |
| 2686 5, kClientDataStreamId1, false, true, 0, "Main Resource Data")); | |
| 2687 | |
| 2688 mock_quic_data.AddRead(ConstructServerConnectionClosePacket(6)); | |
| 2689 | |
| 2690 CreateSession(); | |
| 2691 | |
| 2692 TestDelegate d; | |
|
Ryan Hamilton
2016/09/07 16:54:50
ditto
allada
2016/09/07 18:14:56
Done.
| |
| 2693 QuicURLRequestContext quic_url_request_context(std::move(session_), | |
| 2694 &socket_factory_); | |
| 2695 | |
| 2696 mock_quic_data.AddSocketDataToFactory( | |
| 2697 &quic_url_request_context.socket_factory()); | |
| 2698 TestNetworkDelegate network_delegate_; | |
| 2699 quic_url_request_context.set_network_delegate(&network_delegate_); | |
| 2700 | |
| 2701 std::unique_ptr<URLRequest> request(quic_url_request_context.CreateRequest( | |
| 2702 GURL("https://mail.example.org/"), DEFAULT_PRIORITY, &d)); | |
| 2703 quic_url_request_context.socket_factory().AddSSLSocketDataProvider( | |
| 2704 &ssl_data_); | |
| 2705 | |
| 2706 request->Start(); | |
| 2707 base::RunLoop().Run(); | |
| 2708 | |
| 2709 EXPECT_GT(request->GetTotalSentBytes(), 0); | |
| 2710 EXPECT_GT(request->GetTotalReceivedBytes(), 0); | |
| 2711 EXPECT_EQ(network_delegate_.total_network_bytes_sent(), | |
| 2712 request->GetTotalSentBytes()); | |
| 2713 EXPECT_EQ(network_delegate_.total_network_bytes_received(), | |
| 2714 request->GetTotalReceivedBytes()); | |
| 2715 EXPECT_EQ((int)expected_raw_header_response_size, request->raw_header_size()); | |
|
Ryan Hamilton
2016/09/07 16:54:50
ditto
allada
2016/09/07 18:14:57
Done.
| |
| 2716 EXPECT_TRUE(mock_quic_data.AllReadDataConsumed()); | |
| 2717 EXPECT_TRUE(mock_quic_data.AllWriteDataConsumed()); | |
| 2718 } | |
| 2719 | |
| 2562 class QuicNetworkTransactionWithDestinationTest | 2720 class QuicNetworkTransactionWithDestinationTest |
| 2563 : public PlatformTest, | 2721 : public PlatformTest, |
| 2564 public ::testing::WithParamInterface<PoolingTestParams> { | 2722 public ::testing::WithParamInterface<PoolingTestParams> { |
| 2565 protected: | 2723 protected: |
| 2566 QuicNetworkTransactionWithDestinationTest() | 2724 QuicNetworkTransactionWithDestinationTest() |
| 2567 : clock_(new MockClock), | 2725 : clock_(new MockClock), |
| 2568 version_(GetParam().version), | 2726 version_(GetParam().version), |
| 2569 destination_type_(GetParam().destination_type), | 2727 destination_type_(GetParam().destination_type), |
| 2570 cert_transparency_verifier_(new MultiLogCTVerifier()), | 2728 cert_transparency_verifier_(new MultiLogCTVerifier()), |
| 2571 ssl_config_service_(new SSLConfigServiceDefaults), | 2729 ssl_config_service_(new SSLConfigServiceDefaults), |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2974 AddHangingSocketData(); | 3132 AddHangingSocketData(); |
| 2975 | 3133 |
| 2976 SendRequestAndExpectQuicResponse(origin1_); | 3134 SendRequestAndExpectQuicResponse(origin1_); |
| 2977 SendRequestAndExpectQuicResponse(origin2_); | 3135 SendRequestAndExpectQuicResponse(origin2_); |
| 2978 | 3136 |
| 2979 EXPECT_TRUE(AllDataConsumed()); | 3137 EXPECT_TRUE(AllDataConsumed()); |
| 2980 } | 3138 } |
| 2981 | 3139 |
| 2982 } // namespace test | 3140 } // namespace test |
| 2983 } // namespace net | 3141 } // namespace net |
| OLD | NEW |