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)); |
|
allada
2016/08/31 23:21:39
I was using this area as a sample and realized it
| |
| 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, TestRawHeaderSizeSuccessfullRequest) { | |
|
Ryan Hamilton
2016/09/06 19:54:51
nit: Fwiw, our tests typically don't start with "T
allada
2016/09/07 06:01:11
Done.
| |
| 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 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | |
| 2610 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); | |
| 2611 | |
| 2612 mock_quic_data.AddRead(ConstructServerDataPacket( | |
| 2613 2, kClientDataStreamId1, false, true, 0, "Main Resource Data")); | |
| 2614 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 1)); | |
| 2615 | |
| 2616 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read | |
| 2617 mock_quic_data.AddRead(ASYNC, 0); // EOF | |
| 2618 | |
| 2619 CreateSession(); | |
| 2620 | |
| 2621 TestDelegate d; | |
| 2622 QuicURLRequestContext quic_url_request_context(std::move(session_), | |
| 2623 &socket_factory_); | |
| 2624 | |
| 2625 mock_quic_data.AddSocketDataToFactory( | |
| 2626 &quic_url_request_context.socket_factory()); | |
| 2627 TestNetworkDelegate network_delegate_; | |
| 2628 quic_url_request_context.set_network_delegate(&network_delegate_); | |
| 2629 | |
| 2630 std::unique_ptr<URLRequest> r(quic_url_request_context.CreateRequest( | |
|
Ryan Hamilton
2016/09/06 19:54:51
nit: instead of "r" how 'about "request"?
allada
2016/09/07 06:01:11
Done.
| |
| 2631 GURL("https://mail.example.org/"), DEFAULT_PRIORITY, &d)); | |
| 2632 quic_url_request_context.socket_factory().AddSSLSocketDataProvider( | |
| 2633 &ssl_data_); | |
| 2634 | |
| 2635 r->Start(); | |
| 2636 base::RunLoop().Run(); | |
| 2637 | |
| 2638 EXPECT_EQ(33, r->GetTotalSentBytes()); | |
| 2639 EXPECT_EQ(33, network_delegate_.total_network_bytes_sent()); | |
| 2640 EXPECT_EQ(49, r->GetTotalReceivedBytes()); | |
| 2641 EXPECT_EQ(31, r->raw_header_size()); | |
|
Ryan Hamilton
2016/09/06 19:54:51
Where do these magic numbers come from? Can we com
allada
2016/09/07 06:01:11
Done.
| |
| 2642 } | |
| 2643 | |
| 2644 TEST_P(QuicNetworkTransactionTest, | |
| 2645 TestRawHeaderSizeSuccessfullPushHeadersFirst) { | |
| 2646 params_.origins_to_force_quic_on.insert( | |
| 2647 HostPortPair::FromString("mail.example.org:443")); | |
| 2648 | |
| 2649 MockQuicData mock_quic_data; | |
| 2650 SpdyHeaderBlock headers(GetRequestHeaders("GET", "https", "/")); | |
| 2651 headers["user-agent"] = ""; | |
| 2652 headers["accept-encoding"] = "gzip, deflate"; | |
| 2653 mock_quic_data.AddWrite(ConstructClientRequestHeadersPacket( | |
| 2654 1, kClientDataStreamId1, true, true, std::move(headers))); | |
| 2655 | |
| 2656 QuicStreamOffset server_header_offset = 0; | |
| 2657 mock_quic_data.AddRead(ConstructServerPushPromisePacket( | |
| 2658 1, kClientDataStreamId1, kServerDataStreamId1, false, | |
| 2659 GetRequestHeaders("GET", "https", "/pushed.jpg"), &server_header_offset, | |
| 2660 &server_maker_)); | |
| 2661 | |
| 2662 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | |
| 2663 2, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"), | |
| 2664 &server_header_offset)); | |
| 2665 mock_quic_data.AddWrite(ConstructClientAckPacket(2, 2, 1, 1)); | |
| 2666 | |
| 2667 mock_quic_data.AddRead(ConstructServerResponseHeadersPacket( | |
| 2668 3, kServerDataStreamId1, false, false, GetResponseHeaders("200 OK"), | |
| 2669 &server_header_offset)); | |
| 2670 mock_quic_data.AddRead(ConstructServerDataPacket( | |
| 2671 4, kServerDataStreamId1, false, true, 0, "Pushed Resource Data")); | |
| 2672 | |
| 2673 mock_quic_data.AddWrite(ConstructClientAckPacket(3, 4, 3, 1)); | |
| 2674 mock_quic_data.AddRead(ConstructServerDataPacket( | |
| 2675 5, kClientDataStreamId1, false, true, 0, "Main Resource Data")); | |
| 2676 | |
| 2677 mock_quic_data.AddWrite(ConstructClientAckAndRstPacket( | |
| 2678 4, kServerDataStreamId1, QUIC_RST_ACKNOWLEDGEMENT, 5, 5, 1)); | |
| 2679 | |
| 2680 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read | |
| 2681 mock_quic_data.AddRead(ASYNC, 0); // EOF | |
| 2682 | |
| 2683 CreateSession(); | |
| 2684 | |
| 2685 TestDelegate d; | |
| 2686 QuicURLRequestContext quic_url_request_context(std::move(session_), | |
| 2687 &socket_factory_); | |
| 2688 | |
| 2689 mock_quic_data.AddSocketDataToFactory( | |
| 2690 &quic_url_request_context.socket_factory()); | |
| 2691 TestNetworkDelegate network_delegate_; | |
| 2692 quic_url_request_context.set_network_delegate(&network_delegate_); | |
| 2693 | |
| 2694 std::unique_ptr<URLRequest> r(quic_url_request_context.CreateRequest( | |
|
Ryan Hamilton
2016/09/06 19:54:51
ditto about "r"
allada
2016/09/07 06:01:12
Done.
| |
| 2695 GURL("https://mail.example.org/"), DEFAULT_PRIORITY, &d)); | |
| 2696 quic_url_request_context.socket_factory().AddSSLSocketDataProvider( | |
| 2697 &ssl_data_); | |
| 2698 | |
| 2699 r->Start(); | |
| 2700 base::RunLoop().Run(); | |
| 2701 | |
| 2702 EXPECT_EQ(33, r->GetTotalSentBytes()); | |
| 2703 EXPECT_EQ(33, network_delegate_.total_network_bytes_sent()); | |
| 2704 EXPECT_EQ(49, r->GetTotalReceivedBytes()); | |
| 2705 EXPECT_EQ(31, r->raw_header_size()); | |
| 2706 } | |
| 2707 | |
| 2562 class QuicNetworkTransactionWithDestinationTest | 2708 class QuicNetworkTransactionWithDestinationTest |
| 2563 : public PlatformTest, | 2709 : public PlatformTest, |
| 2564 public ::testing::WithParamInterface<PoolingTestParams> { | 2710 public ::testing::WithParamInterface<PoolingTestParams> { |
| 2565 protected: | 2711 protected: |
| 2566 QuicNetworkTransactionWithDestinationTest() | 2712 QuicNetworkTransactionWithDestinationTest() |
| 2567 : clock_(new MockClock), | 2713 : clock_(new MockClock), |
| 2568 version_(GetParam().version), | 2714 version_(GetParam().version), |
| 2569 destination_type_(GetParam().destination_type), | 2715 destination_type_(GetParam().destination_type), |
| 2570 cert_transparency_verifier_(new MultiLogCTVerifier()), | 2716 cert_transparency_verifier_(new MultiLogCTVerifier()), |
| 2571 ssl_config_service_(new SSLConfigServiceDefaults), | 2717 ssl_config_service_(new SSLConfigServiceDefaults), |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2974 AddHangingSocketData(); | 3120 AddHangingSocketData(); |
| 2975 | 3121 |
| 2976 SendRequestAndExpectQuicResponse(origin1_); | 3122 SendRequestAndExpectQuicResponse(origin1_); |
| 2977 SendRequestAndExpectQuicResponse(origin2_); | 3123 SendRequestAndExpectQuicResponse(origin2_); |
| 2978 | 3124 |
| 2979 EXPECT_TRUE(AllDataConsumed()); | 3125 EXPECT_TRUE(AllDataConsumed()); |
| 2980 } | 3126 } |
| 2981 | 3127 |
| 2982 } // namespace test | 3128 } // namespace test |
| 2983 } // namespace net | 3129 } // namespace net |
| OLD | NEW |