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