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 "net/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/callback.h" |
7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
8 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
9 #include "net/base/ip_endpoint.h" | 11 #include "net/base/ip_endpoint.h" |
10 #include "net/base/net_log_unittest.h" | 12 #include "net/base/net_log_unittest.h" |
11 #include "net/base/request_priority.h" | 13 #include "net/base/request_priority.h" |
12 #include "net/base/test_data_directory.h" | 14 #include "net/base/test_data_directory.h" |
13 #include "net/base/test_data_stream.h" | 15 #include "net/base/test_data_stream.h" |
14 #include "net/dns/host_cache.h" | 16 #include "net/dns/host_cache.h" |
15 #include "net/spdy/spdy_http_utils.h" | 17 #include "net/spdy/spdy_http_utils.h" |
16 #include "net/spdy/spdy_session_pool.h" | 18 #include "net/spdy/spdy_session_pool.h" |
(...skipping 20 matching lines...) Expand all Loading... |
37 const base::StringPiece kBodyDataStringPiece(kBodyData, kBodyDataSize); | 39 const base::StringPiece kBodyDataStringPiece(kBodyData, kBodyDataSize); |
38 | 40 |
39 static int g_delta_seconds = 0; | 41 static int g_delta_seconds = 0; |
40 base::TimeTicks TheNearFuture() { | 42 base::TimeTicks TheNearFuture() { |
41 return base::TimeTicks::Now() + base::TimeDelta::FromSeconds(g_delta_seconds); | 43 return base::TimeTicks::Now() + base::TimeDelta::FromSeconds(g_delta_seconds); |
42 } | 44 } |
43 | 45 |
44 } // namespace | 46 } // namespace |
45 | 47 |
46 class SpdySessionSpdy3Test : public PlatformTest { | 48 class SpdySessionSpdy3Test : public PlatformTest { |
| 49 public: |
| 50 // Functions used with RunResumeAfterUnstallTest31(). |
| 51 |
| 52 void StallSessionOnly(SpdySession* session, SpdyStream* stream) { |
| 53 StallSessionSend(session); |
| 54 } |
| 55 |
| 56 void StallStreamOnly(SpdySession* session, SpdyStream* stream) { |
| 57 StallStreamSend(stream); |
| 58 } |
| 59 |
| 60 void StallSessionStream(SpdySession* session, SpdyStream* stream) { |
| 61 StallSessionSend(session); |
| 62 StallStreamSend(stream); |
| 63 } |
| 64 |
| 65 void StallStreamSession(SpdySession* session, SpdyStream* stream) { |
| 66 StallStreamSend(stream); |
| 67 StallSessionSend(session); |
| 68 } |
| 69 |
| 70 void UnstallSessionOnly(SpdySession* session, |
| 71 SpdyStream* stream, |
| 72 int32 delta_window_size) { |
| 73 UnstallSessionSend(session, delta_window_size); |
| 74 } |
| 75 |
| 76 void UnstallStreamOnly(SpdySession* session, |
| 77 SpdyStream* stream, |
| 78 int32 delta_window_size) { |
| 79 UnstallStreamSend(stream, delta_window_size); |
| 80 } |
| 81 |
| 82 void UnstallSessionStream(SpdySession* session, |
| 83 SpdyStream* stream, |
| 84 int32 delta_window_size) { |
| 85 UnstallSessionSend(session, delta_window_size); |
| 86 UnstallStreamSend(stream, delta_window_size); |
| 87 } |
| 88 |
| 89 void UnstallStreamSession(SpdySession* session, |
| 90 SpdyStream* stream, |
| 91 int32 delta_window_size) { |
| 92 UnstallStreamSend(stream, delta_window_size); |
| 93 UnstallSessionSend(session, delta_window_size); |
| 94 } |
| 95 |
47 protected: | 96 protected: |
48 SpdySessionSpdy3Test() | 97 SpdySessionSpdy3Test() |
49 : spdy_session_pool_(NULL), | 98 : spdy_session_pool_(NULL), |
50 test_url_(kTestUrl), | 99 test_url_(kTestUrl), |
51 test_host_port_pair_(kTestHost, kTestPort), | 100 test_host_port_pair_(kTestHost, kTestPort), |
52 pair_(test_host_port_pair_, ProxyServer::Direct()) { | 101 pair_(test_host_port_pair_, ProxyServer::Direct()) { |
53 } | 102 } |
54 | 103 |
55 virtual void SetUp() { | 104 virtual void SetUp() { |
56 g_delta_seconds = 0; | 105 g_delta_seconds = 0; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 while (session->session_send_window_size_ > 0) { | 156 while (session->session_send_window_size_ > 0) { |
108 session->DecreaseSendWindowSize( | 157 session->DecreaseSendWindowSize( |
109 std::min(kMaxSpdyFrameChunkSize, session->session_send_window_size_)); | 158 std::min(kMaxSpdyFrameChunkSize, session->session_send_window_size_)); |
110 } | 159 } |
111 } | 160 } |
112 | 161 |
113 void UnstallSessionSend(SpdySession* session, int32 delta_window_size) { | 162 void UnstallSessionSend(SpdySession* session, int32 delta_window_size) { |
114 session->IncreaseSendWindowSize(delta_window_size); | 163 session->IncreaseSendWindowSize(delta_window_size); |
115 } | 164 } |
116 | 165 |
| 166 void StallStreamSend(SpdyStream* stream) { |
| 167 // Reduce the send window size to 0 to stall. |
| 168 while (stream->send_window_size() > 0) { |
| 169 stream->DecreaseSendWindowSize( |
| 170 std::min(kMaxSpdyFrameChunkSize, stream->send_window_size())); |
| 171 } |
| 172 } |
| 173 |
| 174 void UnstallStreamSend(SpdyStream* stream, int32 delta_window_size) { |
| 175 stream->IncreaseSendWindowSize(delta_window_size); |
| 176 } |
| 177 |
| 178 void RunResumeAfterUnstallTest31( |
| 179 const base::Callback<void(SpdySession*, SpdyStream*)>& stall_fn, |
| 180 const base::Callback<void(SpdySession*, SpdyStream*, int32)>& unstall_fn); |
| 181 |
117 scoped_refptr<TransportSocketParams> transport_params_; | 182 scoped_refptr<TransportSocketParams> transport_params_; |
118 SpdySessionDependencies session_deps_; | 183 SpdySessionDependencies session_deps_; |
119 scoped_refptr<HttpNetworkSession> http_session_; | 184 scoped_refptr<HttpNetworkSession> http_session_; |
120 SpdySessionPool* spdy_session_pool_; | 185 SpdySessionPool* spdy_session_pool_; |
121 GURL test_url_; | 186 GURL test_url_; |
122 HostPortPair test_host_port_pair_; | 187 HostPortPair test_host_port_pair_; |
123 HostPortProxyPair pair_; | 188 HostPortProxyPair pair_; |
124 }; | 189 }; |
125 | 190 |
126 TEST_F(SpdySessionSpdy3Test, GoAway) { | 191 TEST_F(SpdySessionSpdy3Test, GoAway) { |
(...skipping 2467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2594 | 2659 |
2595 stream->Close(); | 2660 stream->Close(); |
2596 | 2661 |
2597 EXPECT_EQ(OK, delegate.WaitForClose()); | 2662 EXPECT_EQ(OK, delegate.WaitForClose()); |
2598 | 2663 |
2599 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); | 2664 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); |
2600 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); | 2665 EXPECT_EQ(kDefaultInitialRecvWindowSize, session->session_recv_window_size_); |
2601 EXPECT_EQ(msg_data_size, session->session_unacked_recv_window_bytes_); | 2666 EXPECT_EQ(msg_data_size, session->session_unacked_recv_window_bytes_); |
2602 } | 2667 } |
2603 | 2668 |
2604 // Cause a stall by reducing the flow control send window to 0. The | 2669 // Given a stall function and an unstall function, runs a test to make |
2605 // stream should resume when that window is then increased. | 2670 // sure that a stream resumes after unstall. |
2606 TEST_F(SpdySessionSpdy3Test, ResumeAfterSendWindowSizeIncrease31) { | 2671 void SpdySessionSpdy3Test::RunResumeAfterUnstallTest31( |
| 2672 const base::Callback<void(SpdySession*, SpdyStream*)>& stall_fn, |
| 2673 const base::Callback<void(SpdySession*, SpdyStream*, int32)>& unstall_fn) { |
2607 const char kStreamUrl[] = "http://www.google.com/"; | 2674 const char kStreamUrl[] = "http://www.google.com/"; |
2608 GURL url(kStreamUrl); | 2675 GURL url(kStreamUrl); |
2609 | 2676 |
2610 session_deps_.enable_spdy_31 = true; | 2677 session_deps_.enable_spdy_31 = true; |
2611 session_deps_.host_resolver->set_synchronous_mode(true); | 2678 session_deps_.host_resolver->set_synchronous_mode(true); |
2612 | 2679 |
2613 scoped_ptr<SpdyFrame> initial_window_update( | 2680 scoped_ptr<SpdyFrame> initial_window_update( |
2614 ConstructSpdyWindowUpdate( | 2681 ConstructSpdyWindowUpdate( |
2615 kSessionFlowControlStreamId, | 2682 kSessionFlowControlStreamId, |
2616 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | 2683 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2660 ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); | 2727 ConstructPostHeaderBlock(kStreamUrl, kBodyDataSize)); |
2661 EXPECT_TRUE(stream->HasUrl()); | 2728 EXPECT_TRUE(stream->HasUrl()); |
2662 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); | 2729 EXPECT_EQ(kStreamUrl, stream->GetUrl().spec()); |
2663 | 2730 |
2664 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); | 2731 EXPECT_EQ(ERR_IO_PENDING, stream->SendRequest(true)); |
2665 | 2732 |
2666 data.RunFor(3); | 2733 data.RunFor(3); |
2667 | 2734 |
2668 EXPECT_FALSE(stream->send_stalled_by_flow_control()); | 2735 EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
2669 | 2736 |
2670 StallSessionSend(session); | 2737 stall_fn.Run(session, stream); |
2671 | 2738 |
2672 EXPECT_EQ(ERR_IO_PENDING, delegate.OnSendBody()); | 2739 EXPECT_EQ(ERR_IO_PENDING, delegate.OnSendBody()); |
2673 | 2740 |
2674 EXPECT_TRUE(stream->send_stalled_by_flow_control()); | 2741 EXPECT_TRUE(stream->send_stalled_by_flow_control()); |
2675 | 2742 |
2676 UnstallSessionSend(session, kBodyDataSize); | 2743 unstall_fn.Run(session, stream, kBodyDataSize); |
2677 | 2744 |
2678 EXPECT_FALSE(stream->send_stalled_by_flow_control()); | 2745 EXPECT_FALSE(stream->send_stalled_by_flow_control()); |
2679 | 2746 |
2680 data.RunFor(3); | 2747 data.RunFor(3); |
2681 | 2748 |
2682 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); | 2749 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); |
2683 | 2750 |
2684 EXPECT_TRUE(delegate.send_headers_completed()); | 2751 EXPECT_TRUE(delegate.send_headers_completed()); |
2685 EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); | 2752 EXPECT_EQ("200", delegate.GetResponseHeaderValue(":status")); |
2686 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); | 2753 EXPECT_EQ("HTTP/1.1", delegate.GetResponseHeaderValue(":version")); |
2687 EXPECT_EQ(kBodyDataStringPiece.as_string(), delegate.TakeReceivedData()); | 2754 EXPECT_EQ(kBodyDataStringPiece.as_string(), delegate.TakeReceivedData()); |
2688 EXPECT_EQ(static_cast<int>(kBodyDataSize), delegate.body_data_sent()); | 2755 EXPECT_EQ(static_cast<int>(kBodyDataSize), delegate.body_data_sent()); |
2689 } | 2756 } |
2690 | 2757 |
| 2758 // Run the resume-after-unstall test with all possible stall and |
| 2759 // unstall sequences. |
| 2760 |
| 2761 TEST_F(SpdySessionSpdy3Test, ResumeAfterUnstallSession31) { |
| 2762 RunResumeAfterUnstallTest31( |
| 2763 base::Bind(&SpdySessionSpdy3Test::StallSessionOnly, |
| 2764 base::Unretained(this)), |
| 2765 base::Bind(&SpdySessionSpdy3Test::UnstallSessionOnly, |
| 2766 base::Unretained(this))); |
| 2767 } |
| 2768 |
| 2769 // Equivalent to |
| 2770 // SpdyStreamSpdy3Test.ResumeAfterSendWindowSizeIncrease. |
| 2771 TEST_F(SpdySessionSpdy3Test, ResumeAfterUnstallStream31) { |
| 2772 RunResumeAfterUnstallTest31( |
| 2773 base::Bind(&SpdySessionSpdy3Test::StallStreamOnly, |
| 2774 base::Unretained(this)), |
| 2775 base::Bind(&SpdySessionSpdy3Test::UnstallStreamOnly, |
| 2776 base::Unretained(this))); |
| 2777 } |
| 2778 |
| 2779 TEST_F(SpdySessionSpdy3Test, |
| 2780 StallSessionStreamResumeAfterUnstallSessionStream31) { |
| 2781 RunResumeAfterUnstallTest31( |
| 2782 base::Bind(&SpdySessionSpdy3Test::StallSessionStream, |
| 2783 base::Unretained(this)), |
| 2784 base::Bind(&SpdySessionSpdy3Test::UnstallSessionStream, |
| 2785 base::Unretained(this))); |
| 2786 } |
| 2787 |
| 2788 TEST_F(SpdySessionSpdy3Test, |
| 2789 StallStreamSessionResumeAfterUnstallSessionStream31) { |
| 2790 RunResumeAfterUnstallTest31( |
| 2791 base::Bind(&SpdySessionSpdy3Test::StallStreamSession, |
| 2792 base::Unretained(this)), |
| 2793 base::Bind(&SpdySessionSpdy3Test::UnstallSessionStream, |
| 2794 base::Unretained(this))); |
| 2795 } |
| 2796 |
| 2797 TEST_F(SpdySessionSpdy3Test, |
| 2798 StallStreamSessionResumeAfterUnstallStreamSession31) { |
| 2799 RunResumeAfterUnstallTest31( |
| 2800 base::Bind(&SpdySessionSpdy3Test::StallStreamSession, |
| 2801 base::Unretained(this)), |
| 2802 base::Bind(&SpdySessionSpdy3Test::UnstallStreamSession, |
| 2803 base::Unretained(this))); |
| 2804 } |
| 2805 |
| 2806 TEST_F(SpdySessionSpdy3Test, |
| 2807 StallSessionStreamResumeAfterUnstallStreamSession31) { |
| 2808 RunResumeAfterUnstallTest31( |
| 2809 base::Bind(&SpdySessionSpdy3Test::StallSessionStream, |
| 2810 base::Unretained(this)), |
| 2811 base::Bind(&SpdySessionSpdy3Test::UnstallStreamSession, |
| 2812 base::Unretained(this))); |
| 2813 } |
| 2814 |
2691 // Cause a stall by reducing the flow control send window to 0. The | 2815 // Cause a stall by reducing the flow control send window to 0. The |
2692 // streams should resume in priority order when that window is then | 2816 // streams should resume in priority order when that window is then |
2693 // increased. | 2817 // increased. |
2694 TEST_F(SpdySessionSpdy3Test, ResumeByPriorityAfterSendWindowSizeIncrease31) { | 2818 TEST_F(SpdySessionSpdy3Test, ResumeByPriorityAfterSendWindowSizeIncrease31) { |
2695 const char kStreamUrl[] = "http://www.google.com/"; | 2819 const char kStreamUrl[] = "http://www.google.com/"; |
2696 GURL url(kStreamUrl); | 2820 GURL url(kStreamUrl); |
2697 | 2821 |
2698 session_deps_.enable_spdy_31 = true; | 2822 session_deps_.enable_spdy_31 = true; |
2699 session_deps_.host_resolver->set_synchronous_mode(true); | 2823 session_deps_.host_resolver->set_synchronous_mode(true); |
2700 | 2824 |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3179 EXPECT_EQ(0, delegate1.body_data_sent()); | 3303 EXPECT_EQ(0, delegate1.body_data_sent()); |
3180 | 3304 |
3181 EXPECT_TRUE(delegate2.send_headers_completed()); | 3305 EXPECT_TRUE(delegate2.send_headers_completed()); |
3182 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); | 3306 EXPECT_EQ("200", delegate2.GetResponseHeaderValue(":status")); |
3183 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); | 3307 EXPECT_EQ("HTTP/1.1", delegate2.GetResponseHeaderValue(":version")); |
3184 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); | 3308 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); |
3185 EXPECT_EQ(0, delegate2.body_data_sent()); | 3309 EXPECT_EQ(0, delegate2.body_data_sent()); |
3186 } | 3310 } |
3187 | 3311 |
3188 } // namespace net | 3312 } // namespace net |
OLD | NEW |