| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <sys/epoll.h> | 6 #include <sys/epoll.h> |
| 7 | 7 |
| 8 #include <cstdint> | 8 #include <cstdint> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "net/quic/core/crypto/null_encrypter.h" | 25 #include "net/quic/core/crypto/null_encrypter.h" |
| 26 #include "net/quic/core/quic_client_session_base.h" | 26 #include "net/quic/core/quic_client_session_base.h" |
| 27 #include "net/quic/core/quic_flags.h" | 27 #include "net/quic/core/quic_flags.h" |
| 28 #include "net/quic/core/quic_framer.h" | 28 #include "net/quic/core/quic_framer.h" |
| 29 #include "net/quic/core/quic_packet_creator.h" | 29 #include "net/quic/core/quic_packet_creator.h" |
| 30 #include "net/quic/core/quic_packets.h" | 30 #include "net/quic/core/quic_packets.h" |
| 31 #include "net/quic/core/quic_server_id.h" | 31 #include "net/quic/core/quic_server_id.h" |
| 32 #include "net/quic/core/quic_session.h" | 32 #include "net/quic/core/quic_session.h" |
| 33 #include "net/quic/core/quic_utils.h" | 33 #include "net/quic/core/quic_utils.h" |
| 34 #include "net/quic/platform/api/quic_socket_address.h" | 34 #include "net/quic/platform/api/quic_socket_address.h" |
| 35 #include "net/quic/platform/api/quic_str_cat.h" |
| 35 #include "net/quic/test_tools/crypto_test_utils.h" | 36 #include "net/quic/test_tools/crypto_test_utils.h" |
| 36 #include "net/quic/test_tools/quic_config_peer.h" | 37 #include "net/quic/test_tools/quic_config_peer.h" |
| 37 #include "net/quic/test_tools/quic_connection_peer.h" | 38 #include "net/quic/test_tools/quic_connection_peer.h" |
| 38 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 39 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
| 39 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" | 40 #include "net/quic/test_tools/quic_sent_packet_manager_peer.h" |
| 40 #include "net/quic/test_tools/quic_session_peer.h" | 41 #include "net/quic/test_tools/quic_session_peer.h" |
| 41 #include "net/quic/test_tools/quic_spdy_session_peer.h" | 42 #include "net/quic/test_tools/quic_spdy_session_peer.h" |
| 42 #include "net/quic/test_tools/quic_stream_peer.h" | 43 #include "net/quic/test_tools/quic_stream_peer.h" |
| 43 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" | 44 #include "net/quic/test_tools/quic_stream_sequencer_peer.h" |
| 44 #include "net/quic/test_tools/quic_test_utils.h" | 45 #include "net/quic/test_tools/quic_test_utils.h" |
| (...skipping 2581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2626 string large_resource; | 2627 string large_resource; |
| 2627 if (use_large_response) { | 2628 if (use_large_response) { |
| 2628 // Generate a response common body larger than flow control window for | 2629 // Generate a response common body larger than flow control window for |
| 2629 // push response. | 2630 // push response. |
| 2630 large_resource = string(resource_size, 'a'); | 2631 large_resource = string(resource_size, 'a'); |
| 2631 } | 2632 } |
| 2632 std::list<QuicHttpResponseCache::ServerPushInfo> push_resources; | 2633 std::list<QuicHttpResponseCache::ServerPushInfo> push_resources; |
| 2633 for (size_t i = 0; i < num_resources; ++i) { | 2634 for (size_t i = 0; i < num_resources; ++i) { |
| 2634 string url = push_urls[i]; | 2635 string url = push_urls[i]; |
| 2635 GURL resource_url(url); | 2636 GURL resource_url(url); |
| 2636 string body = use_large_response | 2637 string body = |
| 2637 ? large_resource | 2638 use_large_response |
| 2638 : "This is server push response body for " + url; | 2639 ? large_resource |
| 2640 : QuicStrCat("This is server push response body for ", url); |
| 2639 SpdyHeaderBlock response_headers; | 2641 SpdyHeaderBlock response_headers; |
| 2640 response_headers[":version"] = "HTTP/1.1"; | 2642 response_headers[":version"] = "HTTP/1.1"; |
| 2641 response_headers[":status"] = "200"; | 2643 response_headers[":status"] = "200"; |
| 2642 response_headers["content-length"] = IntToString(body.size()); | 2644 response_headers["content-length"] = IntToString(body.size()); |
| 2643 push_resources.push_back(QuicHttpResponseCache::ServerPushInfo( | 2645 push_resources.push_back(QuicHttpResponseCache::ServerPushInfo( |
| 2644 resource_url, std::move(response_headers), kV3LowestPriority, body)); | 2646 resource_url, std::move(response_headers), kV3LowestPriority, body)); |
| 2645 } | 2647 } |
| 2646 | 2648 |
| 2647 response_cache_.AddSimpleResponseWithServerPushResources( | 2649 response_cache_.AddSimpleResponseWithServerPushResources( |
| 2648 host, path, 200, response_body, push_resources); | 2650 host, path, 200, response_body, push_resources); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2681 "https://example.com/push_example")); | 2683 "https://example.com/push_example")); |
| 2682 QuicHeadersStream* headers_stream = | 2684 QuicHeadersStream* headers_stream = |
| 2683 QuicSpdySessionPeer::GetHeadersStream(client_->client()->session()); | 2685 QuicSpdySessionPeer::GetHeadersStream(client_->client()->session()); |
| 2684 QuicStreamSequencer* sequencer = QuicStreamPeer::sequencer(headers_stream); | 2686 QuicStreamSequencer* sequencer = QuicStreamPeer::sequencer(headers_stream); |
| 2685 // Headers stream's sequencer buffer shouldn't be released because server push | 2687 // Headers stream's sequencer buffer shouldn't be released because server push |
| 2686 // hasn't finished yet. | 2688 // hasn't finished yet. |
| 2687 EXPECT_TRUE(QuicStreamSequencerPeer::IsUnderlyingBufferAllocated(sequencer)); | 2689 EXPECT_TRUE(QuicStreamSequencerPeer::IsUnderlyingBufferAllocated(sequencer)); |
| 2688 | 2690 |
| 2689 for (const string& url : push_urls) { | 2691 for (const string& url : push_urls) { |
| 2690 DVLOG(1) << "send request for pushed stream on url " << url; | 2692 DVLOG(1) << "send request for pushed stream on url " << url; |
| 2691 string expected_body = "This is server push response body for " + url; | 2693 string expected_body = |
| 2694 QuicStrCat("This is server push response body for ", url); |
| 2692 string response_body = client_->SendSynchronousRequest(url); | 2695 string response_body = client_->SendSynchronousRequest(url); |
| 2693 DVLOG(1) << "response body " << response_body; | 2696 DVLOG(1) << "response body " << response_body; |
| 2694 EXPECT_EQ(expected_body, response_body); | 2697 EXPECT_EQ(expected_body, response_body); |
| 2695 } | 2698 } |
| 2696 EXPECT_NE( | 2699 EXPECT_NE( |
| 2697 FLAGS_quic_reloadable_flag_quic_headers_stream_release_sequencer_buffer && | 2700 FLAGS_quic_reloadable_flag_quic_headers_stream_release_sequencer_buffer && |
| 2698 FLAGS_quic_reloadable_flag_quic_reduce_sequencer_buffer_memory_life_ti
me, // NOLINT | 2701 FLAGS_quic_reloadable_flag_quic_reduce_sequencer_buffer_memory_life_ti
me, // NOLINT |
| 2699 QuicStreamSequencerPeer::IsUnderlyingBufferAllocated(sequencer)); | 2702 QuicStreamSequencerPeer::IsUnderlyingBufferAllocated(sequencer)); |
| 2700 } | 2703 } |
| 2701 | 2704 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2728 // Send the first request: this will trigger the server to send all the push | 2731 // Send the first request: this will trigger the server to send all the push |
| 2729 // resources associated with this request, and these will be cached by the | 2732 // resources associated with this request, and these will be cached by the |
| 2730 // client. | 2733 // client. |
| 2731 EXPECT_EQ(kBody, client_->SendSynchronousRequest( | 2734 EXPECT_EQ(kBody, client_->SendSynchronousRequest( |
| 2732 "https://example.com/push_example")); | 2735 "https://example.com/push_example")); |
| 2733 | 2736 |
| 2734 for (const string& url : push_urls) { | 2737 for (const string& url : push_urls) { |
| 2735 // Sending subsequent requesets will not actually send anything on the wire, | 2738 // Sending subsequent requesets will not actually send anything on the wire, |
| 2736 // as the responses are already in the client's cache. | 2739 // as the responses are already in the client's cache. |
| 2737 DVLOG(1) << "send request for pushed stream on url " << url; | 2740 DVLOG(1) << "send request for pushed stream on url " << url; |
| 2738 string expected_body = "This is server push response body for " + url; | 2741 string expected_body = |
| 2742 QuicStrCat("This is server push response body for ", url); |
| 2739 string response_body = client_->SendSynchronousRequest(url); | 2743 string response_body = client_->SendSynchronousRequest(url); |
| 2740 DVLOG(1) << "response body " << response_body; | 2744 DVLOG(1) << "response body " << response_body; |
| 2741 EXPECT_EQ(expected_body, response_body); | 2745 EXPECT_EQ(expected_body, response_body); |
| 2742 } | 2746 } |
| 2743 // Expect only original request has been sent and push responses have been | 2747 // Expect only original request has been sent and push responses have been |
| 2744 // received as normal response. | 2748 // received as normal response. |
| 2745 EXPECT_EQ(1u, client_->num_requests()); | 2749 EXPECT_EQ(1u, client_->num_requests()); |
| 2746 EXPECT_EQ(1u + kNumResources, client_->num_responses()); | 2750 EXPECT_EQ(1u + kNumResources, client_->num_responses()); |
| 2747 } | 2751 } |
| 2748 | 2752 |
| 2749 TEST_P(EndToEndTestServerPush, ServerPushOverLimitNonBlocking) { | 2753 TEST_P(EndToEndTestServerPush, ServerPushOverLimitNonBlocking) { |
| 2750 // Tests that when streams are not blocked by flow control or congestion | 2754 // Tests that when streams are not blocked by flow control or congestion |
| 2751 // control, pushing even more resources than max number of open outgoing | 2755 // control, pushing even more resources than max number of open outgoing |
| 2752 // streams should still work because all response streams get closed | 2756 // streams should still work because all response streams get closed |
| 2753 // immediately after pushing resources. | 2757 // immediately after pushing resources. |
| 2754 ASSERT_TRUE(Initialize()); | 2758 ASSERT_TRUE(Initialize()); |
| 2755 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); | 2759 EXPECT_TRUE(client_->client()->WaitForCryptoHandshakeConfirmed()); |
| 2756 | 2760 |
| 2757 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. | 2761 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. |
| 2758 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 2762 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
| 2759 SetReorderPercentage(30); | 2763 SetReorderPercentage(30); |
| 2760 | 2764 |
| 2761 // Add a response with headers, body, and push resources. | 2765 // Add a response with headers, body, and push resources. |
| 2762 const string kBody = "body content"; | 2766 const string kBody = "body content"; |
| 2763 | 2767 |
| 2764 // One more resource than max number of outgoing stream of this session. | 2768 // One more resource than max number of outgoing stream of this session. |
| 2765 const size_t kNumResources = 1 + kNumMaxStreams; // 11. | 2769 const size_t kNumResources = 1 + kNumMaxStreams; // 11. |
| 2766 string push_urls[11]; | 2770 string push_urls[11]; |
| 2767 for (size_t i = 0; i < kNumResources; ++i) { | 2771 for (size_t i = 0; i < kNumResources; ++i) { |
| 2768 push_urls[i] = "https://example.com/push_resources" + base::UintToString(i); | 2772 push_urls[i] = QuicStrCat("https://example.com/push_resources", i); |
| 2769 } | 2773 } |
| 2770 AddRequestAndResponseWithServerPush("example.com", "/push_example", kBody, | 2774 AddRequestAndResponseWithServerPush("example.com", "/push_example", kBody, |
| 2771 push_urls, kNumResources, 0); | 2775 push_urls, kNumResources, 0); |
| 2772 client_->client()->set_response_listener( | 2776 client_->client()->set_response_listener( |
| 2773 std::unique_ptr<QuicClientBase::ResponseListener>( | 2777 std::unique_ptr<QuicClientBase::ResponseListener>( |
| 2774 new TestResponseListener)); | 2778 new TestResponseListener)); |
| 2775 | 2779 |
| 2776 // Send the first request: this will trigger the server to send all the push | 2780 // Send the first request: this will trigger the server to send all the push |
| 2777 // resources associated with this request, and these will be cached by the | 2781 // resources associated with this request, and these will be cached by the |
| 2778 // client. | 2782 // client. |
| 2779 EXPECT_EQ(kBody, client_->SendSynchronousRequest( | 2783 EXPECT_EQ(kBody, client_->SendSynchronousRequest( |
| 2780 "https://example.com/push_example")); | 2784 "https://example.com/push_example")); |
| 2781 | 2785 |
| 2782 for (const string& url : push_urls) { | 2786 for (const string& url : push_urls) { |
| 2783 // Sending subsequent requesets will not actually send anything on the wire, | 2787 // Sending subsequent requesets will not actually send anything on the wire, |
| 2784 // as the responses are already in the client's cache. | 2788 // as the responses are already in the client's cache. |
| 2785 EXPECT_EQ("This is server push response body for " + url, | 2789 EXPECT_EQ(QuicStrCat("This is server push response body for ", url), |
| 2786 client_->SendSynchronousRequest(url)); | 2790 client_->SendSynchronousRequest(url)); |
| 2787 } | 2791 } |
| 2788 | 2792 |
| 2789 // Only 1 request should have been sent. | 2793 // Only 1 request should have been sent. |
| 2790 EXPECT_EQ(1u, client_->num_requests()); | 2794 EXPECT_EQ(1u, client_->num_requests()); |
| 2791 // The responses to the original request and all the promised resources | 2795 // The responses to the original request and all the promised resources |
| 2792 // should have been received. | 2796 // should have been received. |
| 2793 EXPECT_EQ(12u, client_->num_responses()); | 2797 EXPECT_EQ(12u, client_->num_responses()); |
| 2794 } | 2798 } |
| 2795 | 2799 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2815 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. | 2819 // Set reordering to ensure that body arriving before PUSH_PROMISE is ok. |
| 2816 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); | 2820 SetPacketSendDelay(QuicTime::Delta::FromMilliseconds(2)); |
| 2817 SetReorderPercentage(30); | 2821 SetReorderPercentage(30); |
| 2818 | 2822 |
| 2819 // Add a response with headers, body, and push resources. | 2823 // Add a response with headers, body, and push resources. |
| 2820 const string kBody = "body content"; | 2824 const string kBody = "body content"; |
| 2821 | 2825 |
| 2822 const size_t kNumResources = kNumMaxStreams + 1; | 2826 const size_t kNumResources = kNumMaxStreams + 1; |
| 2823 string push_urls[11]; | 2827 string push_urls[11]; |
| 2824 for (size_t i = 0; i < kNumResources; ++i) { | 2828 for (size_t i = 0; i < kNumResources; ++i) { |
| 2825 push_urls[i] = "http://example.com/push_resources" + base::UintToString(i); | 2829 push_urls[i] = QuicStrCat("http://example.com/push_resources", i); |
| 2826 } | 2830 } |
| 2827 AddRequestAndResponseWithServerPush("example.com", "/push_example", kBody, | 2831 AddRequestAndResponseWithServerPush("example.com", "/push_example", kBody, |
| 2828 push_urls, kNumResources, kBodySize); | 2832 push_urls, kNumResources, kBodySize); |
| 2829 | 2833 |
| 2830 client_->client()->set_response_listener( | 2834 client_->client()->set_response_listener( |
| 2831 std::unique_ptr<QuicClientBase::ResponseListener>( | 2835 std::unique_ptr<QuicClientBase::ResponseListener>( |
| 2832 new TestResponseListener)); | 2836 new TestResponseListener)); |
| 2833 | 2837 |
| 2834 client_->SendRequest("https://example.com/push_example"); | 2838 client_->SendRequest("https://example.com/push_example"); |
| 2835 | 2839 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2895 push_urls, kNumResources, 0); | 2899 push_urls, kNumResources, 0); |
| 2896 client_->client()->set_response_listener( | 2900 client_->client()->set_response_listener( |
| 2897 std::unique_ptr<QuicClientBase::ResponseListener>( | 2901 std::unique_ptr<QuicClientBase::ResponseListener>( |
| 2898 new TestResponseListener)); | 2902 new TestResponseListener)); |
| 2899 EXPECT_EQ(kBody, client_->SendSynchronousRequest( | 2903 EXPECT_EQ(kBody, client_->SendSynchronousRequest( |
| 2900 "https://example.com/push_example")); | 2904 "https://example.com/push_example")); |
| 2901 | 2905 |
| 2902 for (const string& url : push_urls) { | 2906 for (const string& url : push_urls) { |
| 2903 // Sending subsequent requests will trigger sending real requests because | 2907 // Sending subsequent requests will trigger sending real requests because |
| 2904 // client doesn't support server push. | 2908 // client doesn't support server push. |
| 2905 const string expected_body = "This is server push response body for " + url; | 2909 const string expected_body = |
| 2910 QuicStrCat("This is server push response body for ", url); |
| 2906 const string response_body = client_->SendSynchronousRequest(url); | 2911 const string response_body = client_->SendSynchronousRequest(url); |
| 2907 EXPECT_EQ(expected_body, response_body); | 2912 EXPECT_EQ(expected_body, response_body); |
| 2908 } | 2913 } |
| 2909 // Same number of requests are sent as that of responses received. | 2914 // Same number of requests are sent as that of responses received. |
| 2910 EXPECT_EQ(1 + kNumResources, client_->num_requests()); | 2915 EXPECT_EQ(1 + kNumResources, client_->num_requests()); |
| 2911 EXPECT_EQ(1 + kNumResources, client_->num_responses()); | 2916 EXPECT_EQ(1 + kNumResources, client_->num_responses()); |
| 2912 } | 2917 } |
| 2913 | 2918 |
| 2914 // TODO(fayang): this test seems to cause net_unittests timeouts :| | 2919 // TODO(fayang): this test seems to cause net_unittests timeouts :| |
| 2915 TEST_P(EndToEndTest, DISABLED_TestHugePostWithPacketLoss) { | 2920 TEST_P(EndToEndTest, DISABLED_TestHugePostWithPacketLoss) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3051 client_->WaitForResponse(); | 3056 client_->WaitForResponse(); |
| 3052 EXPECT_EQ(kBarResponseBody, client_->response_body()); | 3057 EXPECT_EQ(kBarResponseBody, client_->response_body()); |
| 3053 QuicConnectionStats client_stats = | 3058 QuicConnectionStats client_stats = |
| 3054 client_->client()->session()->connection()->GetStats(); | 3059 client_->client()->session()->connection()->GetStats(); |
| 3055 EXPECT_EQ(0u, client_stats.packets_lost); | 3060 EXPECT_EQ(0u, client_stats.packets_lost); |
| 3056 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); | 3061 EXPECT_EQ(1, client_->client()->GetNumSentClientHellos()); |
| 3057 } | 3062 } |
| 3058 } // namespace | 3063 } // namespace |
| 3059 } // namespace test | 3064 } // namespace test |
| 3060 } // namespace net | 3065 } // namespace net |
| OLD | NEW |