Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1298)

Side by Side Diff: net/spdy/spdy_network_transaction_unittest.cc

Issue 8892026: SPDY - add support for spdy/2.1 to support flow control. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_http_stream.cc ('k') | net/spdy/spdy_session.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "net/base/auth.h" 10 #include "net/base/auth.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 if (!session_.get()) 115 if (!session_.get())
116 session_ = SpdySessionDependencies::SpdyCreateSession( 116 session_ = SpdySessionDependencies::SpdyCreateSession(
117 session_deps_.get()); 117 session_deps_.get());
118 HttpStreamFactory::set_use_alternate_protocols(false); 118 HttpStreamFactory::set_use_alternate_protocols(false);
119 HttpStreamFactory::set_force_spdy_over_ssl(false); 119 HttpStreamFactory::set_force_spdy_over_ssl(false);
120 HttpStreamFactory::set_force_spdy_always(false); 120 HttpStreamFactory::set_force_spdy_always(false);
121 121
122 std::vector<std::string> next_protos; 122 std::vector<std::string> next_protos;
123 next_protos.push_back("http/1.1"); 123 next_protos.push_back("http/1.1");
124 next_protos.push_back("spdy/2"); 124 next_protos.push_back("spdy/2");
125 next_protos.push_back("spdy/2.1");
125 126
126 switch (test_type_) { 127 switch (test_type_) {
127 case SPDYNPN: 128 case SPDYNPN:
128 session_->http_server_properties()->SetAlternateProtocol( 129 session_->http_server_properties()->SetAlternateProtocol(
129 HostPortPair("www.google.com", 80), 443, 130 HostPortPair("www.google.com", 80), 443,
130 NPN_SPDY_2); 131 NPN_SPDY_2);
131 HttpStreamFactory::set_use_alternate_protocols(true); 132 HttpStreamFactory::set_use_alternate_protocols(true);
132 HttpStreamFactory::set_next_protos(next_protos); 133 HttpStreamFactory::set_next_protos(next_protos);
133 break; 134 break;
134 case SPDYNOSSL: 135 case SPDYNOSSL:
(...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after
1844 // enough number of WINDOW_UPDATEs to finish the first read and cause a 1845 // enough number of WINDOW_UPDATEs to finish the first read and cause a
1845 // write, leading to a complete write of request body; after that we send 1846 // write, leading to a complete write of request body; after that we send
1846 // a reply with a body, to cause a graceful shutdown. 1847 // a reply with a body, to cause a graceful shutdown.
1847 1848
1848 // TODO(agayev): develop a socket data provider where both, reads and 1849 // TODO(agayev): develop a socket data provider where both, reads and
1849 // writes are ordered so that writing tests like these are easy and rewrite 1850 // writes are ordered so that writing tests like these are easy and rewrite
1850 // all these tests using it. Right now we are working around the 1851 // all these tests using it. Right now we are working around the
1851 // limitations as described above and it's not deterministic, tests may 1852 // limitations as described above and it's not deterministic, tests may
1852 // fail under specific circumstances. 1853 // fail under specific circumstances.
1853 TEST_P(SpdyNetworkTransactionTest, WindowUpdateReceived) { 1854 TEST_P(SpdyNetworkTransactionTest, WindowUpdateReceived) {
1854 SpdySession::set_flow_control(true); 1855 SpdySession::set_use_flow_control(true);
1855 1856
1856 static int kFrameCount = 2; 1857 static int kFrameCount = 2;
1857 scoped_ptr<std::string> content( 1858 scoped_ptr<std::string> content(
1858 new std::string(kMaxSpdyFrameChunkSize, 'a')); 1859 new std::string(kMaxSpdyFrameChunkSize, 'a'));
1859 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyPost( 1860 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyPost(
1860 kMaxSpdyFrameChunkSize * kFrameCount, NULL, 0)); 1861 kMaxSpdyFrameChunkSize * kFrameCount, NULL, 0));
1861 scoped_ptr<spdy::SpdyFrame> body( 1862 scoped_ptr<spdy::SpdyFrame> body(
1862 ConstructSpdyBodyFrame(1, content->c_str(), content->size(), false)); 1863 ConstructSpdyBodyFrame(1, content->c_str(), content->size(), false));
1863 scoped_ptr<spdy::SpdyFrame> body_end( 1864 scoped_ptr<spdy::SpdyFrame> body_end(
1864 ConstructSpdyBodyFrame(1, content->c_str(), content->size(), true)); 1865 ConstructSpdyBodyFrame(1, content->c_str(), content->size(), true));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 EXPECT_EQ(OK, rv); 1916 EXPECT_EQ(OK, rv);
1916 1917
1917 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); 1918 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get());
1918 ASSERT_TRUE(stream != NULL); 1919 ASSERT_TRUE(stream != NULL);
1919 ASSERT_TRUE(stream->stream() != NULL); 1920 ASSERT_TRUE(stream->stream() != NULL);
1920 EXPECT_EQ(static_cast<int>(spdy::kSpdyStreamInitialWindowSize) + 1921 EXPECT_EQ(static_cast<int>(spdy::kSpdyStreamInitialWindowSize) +
1921 kDeltaWindowSize * kDeltaCount - 1922 kDeltaWindowSize * kDeltaCount -
1922 kMaxSpdyFrameChunkSize * kFrameCount, 1923 kMaxSpdyFrameChunkSize * kFrameCount,
1923 stream->stream()->send_window_size()); 1924 stream->stream()->send_window_size());
1924 helper.VerifyDataConsumed(); 1925 helper.VerifyDataConsumed();
1925 SpdySession::set_flow_control(false); 1926 SpdySession::set_use_flow_control(false);
1926 } 1927 }
1927 1928
1928 // Test that received data frames and sent WINDOW_UPDATE frames change 1929 // Test that received data frames and sent WINDOW_UPDATE frames change
1929 // the recv_window_size_ correctly. 1930 // the recv_window_size_ correctly.
1930 TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { 1931 TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) {
1931 SpdySession::set_flow_control(true); 1932 SpdySession::set_use_flow_control(true);
1932 1933
1933 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 1934 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
1934 scoped_ptr<spdy::SpdyFrame> window_update( 1935 scoped_ptr<spdy::SpdyFrame> window_update(
1935 ConstructSpdyWindowUpdate(1, kUploadDataSize)); 1936 ConstructSpdyWindowUpdate(1, kUploadDataSize));
1936 1937
1937 MockWrite writes[] = { 1938 MockWrite writes[] = {
1938 CreateMockWrite(*req), 1939 CreateMockWrite(*req),
1939 CreateMockWrite(*window_update), 1940 CreateMockWrite(*window_update),
1940 }; 1941 };
1941 1942
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 data->CompleteRead(); 1999 data->CompleteRead();
1999 2000
2000 // Force write of WINDOW_UPDATE which was scheduled during the above 2001 // Force write of WINDOW_UPDATE which was scheduled during the above
2001 // read. 2002 // read.
2002 MessageLoop::current()->RunAllPending(); 2003 MessageLoop::current()->RunAllPending();
2003 2004
2004 // Read EOF. 2005 // Read EOF.
2005 data->CompleteRead(); 2006 data->CompleteRead();
2006 2007
2007 helper.VerifyDataConsumed(); 2008 helper.VerifyDataConsumed();
2008 SpdySession::set_flow_control(false); 2009 SpdySession::set_use_flow_control(false);
2009 } 2010 }
2010 2011
2011 // Test that WINDOW_UPDATE frame causing overflow is handled correctly. We 2012 // Test that WINDOW_UPDATE frame causing overflow is handled correctly. We
2012 // use the same trick as in the above test to enforce our scenario. 2013 // use the same trick as in the above test to enforce our scenario.
2013 TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { 2014 TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) {
2014 SpdySession::set_flow_control(true); 2015 SpdySession::set_use_flow_control(true);
2015 2016
2016 // number of full frames we hope to write (but will not, used to 2017 // number of full frames we hope to write (but will not, used to
2017 // set content-length header correctly) 2018 // set content-length header correctly)
2018 static int kFrameCount = 3; 2019 static int kFrameCount = 3;
2019 2020
2020 scoped_ptr<std::string> content( 2021 scoped_ptr<std::string> content(
2021 new std::string(kMaxSpdyFrameChunkSize, 'a')); 2022 new std::string(kMaxSpdyFrameChunkSize, 'a'));
2022 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyPost( 2023 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyPost(
2023 kMaxSpdyFrameChunkSize * kFrameCount, NULL, 0)); 2024 kMaxSpdyFrameChunkSize * kFrameCount, NULL, 0));
2024 scoped_ptr<spdy::SpdyFrame> body( 2025 scoped_ptr<spdy::SpdyFrame> body(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 rv = callback.WaitForResult(); 2078 rv = callback.WaitForResult();
2078 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv); 2079 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv);
2079 2080
2080 data->CompleteRead(); 2081 data->CompleteRead();
2081 2082
2082 ASSERT_TRUE(helper.session() != NULL); 2083 ASSERT_TRUE(helper.session() != NULL);
2083 ASSERT_TRUE(helper.session()->spdy_session_pool() != NULL); 2084 ASSERT_TRUE(helper.session()->spdy_session_pool() != NULL);
2084 helper.session()->spdy_session_pool()->CloseAllSessions(); 2085 helper.session()->spdy_session_pool()->CloseAllSessions();
2085 helper.VerifyDataConsumed(); 2086 helper.VerifyDataConsumed();
2086 2087
2087 SpdySession::set_flow_control(false); 2088 SpdySession::set_use_flow_control(false);
2088 } 2089 }
2089 2090
2090 // Test that after hitting a send window size of 0, the write process 2091 // Test that after hitting a send window size of 0, the write process
2091 // stalls and upon receiving WINDOW_UPDATE frame write resumes. 2092 // stalls and upon receiving WINDOW_UPDATE frame write resumes.
2092 2093
2093 // This test constructs a POST request followed by enough data frames 2094 // This test constructs a POST request followed by enough data frames
2094 // containing 'a' that would make the window size 0, followed by another 2095 // containing 'a' that would make the window size 0, followed by another
2095 // data frame containing default content (which is "hello!") and this frame 2096 // data frame containing default content (which is "hello!") and this frame
2096 // also contains a FIN flag. DelayedSocketData is used to enforce all 2097 // also contains a FIN flag. DelayedSocketData is used to enforce all
2097 // writes go through before a read could happen. However, the last frame 2098 // writes go through before a read could happen. However, the last frame
2098 // ("hello!") is not supposed to go through since by the time its turn 2099 // ("hello!") is not supposed to go through since by the time its turn
2099 // arrives, window size is 0. At this point MessageLoop::Run() called via 2100 // arrives, window size is 0. At this point MessageLoop::Run() called via
2100 // callback would block. Therefore we call MessageLoop::RunAllPending() 2101 // callback would block. Therefore we call MessageLoop::RunAllPending()
2101 // which returns after performing all possible writes. We use DCHECKS to 2102 // which returns after performing all possible writes. We use DCHECKS to
2102 // ensure that last data frame is still there and stream has stalled. 2103 // ensure that last data frame is still there and stream has stalled.
2103 // After that, next read is artifically enforced, which causes a 2104 // After that, next read is artifically enforced, which causes a
2104 // WINDOW_UPDATE to be read and I/O process resumes. 2105 // WINDOW_UPDATE to be read and I/O process resumes.
2105 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) { 2106 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) {
2106 SpdySession::set_flow_control(true); 2107 SpdySession::set_use_flow_control(true);
2107 2108
2108 // Number of frames we need to send to zero out the window size: data 2109 // Number of frames we need to send to zero out the window size: data
2109 // frames plus SYN_STREAM plus the last data frame; also we need another 2110 // frames plus SYN_STREAM plus the last data frame; also we need another
2110 // data frame that we will send once the WINDOW_UPDATE is received, 2111 // data frame that we will send once the WINDOW_UPDATE is received,
2111 // therefore +3. 2112 // therefore +3.
2112 size_t nwrites = 2113 size_t nwrites =
2113 spdy::kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; 2114 spdy::kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3;
2114 2115
2115 // Calculate last frame's size; 0 size data frame is legal. 2116 // Calculate last frame's size; 0 size data frame is legal.
2116 size_t last_frame_size = 2117 size_t last_frame_size =
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2187 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); 2188 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get());
2188 ASSERT_TRUE(stream != NULL); 2189 ASSERT_TRUE(stream != NULL);
2189 ASSERT_TRUE(stream->stream() != NULL); 2190 ASSERT_TRUE(stream->stream() != NULL);
2190 EXPECT_EQ(0, stream->stream()->send_window_size()); 2191 EXPECT_EQ(0, stream->stream()->send_window_size());
2191 EXPECT_FALSE(stream->request_body_stream_->eof()); 2192 EXPECT_FALSE(stream->request_body_stream_->eof());
2192 2193
2193 data->ForceNextRead(); // Read in WINDOW_UPDATE frame. 2194 data->ForceNextRead(); // Read in WINDOW_UPDATE frame.
2194 rv = callback.WaitForResult(); 2195 rv = callback.WaitForResult();
2195 helper.VerifyDataConsumed(); 2196 helper.VerifyDataConsumed();
2196 2197
2197 SpdySession::set_flow_control(false); 2198 SpdySession::set_use_flow_control(false);
2198 } 2199 }
2199 2200
2200 TEST_P(SpdyNetworkTransactionTest, CancelledTransaction) { 2201 TEST_P(SpdyNetworkTransactionTest, CancelledTransaction) {
2201 // Construct the request. 2202 // Construct the request.
2202 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 2203 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
2203 MockWrite writes[] = { 2204 MockWrite writes[] = {
2204 CreateMockWrite(*req), 2205 CreateMockWrite(*req),
2205 }; 2206 };
2206 2207
2207 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); 2208 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1));
(...skipping 3454 matching lines...) Expand 10 before | Expand all | Expand 10 after
5662 << " Write index: " 5663 << " Write index: "
5663 << data->write_index(); 5664 << data->write_index();
5664 5665
5665 // Verify the SYN_REPLY. 5666 // Verify the SYN_REPLY.
5666 HttpResponseInfo response = *trans->GetResponseInfo(); 5667 HttpResponseInfo response = *trans->GetResponseInfo();
5667 EXPECT_TRUE(response.headers != NULL); 5668 EXPECT_TRUE(response.headers != NULL);
5668 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 5669 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
5669 } 5670 }
5670 5671
5671 } // namespace net 5672 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_http_stream.cc ('k') | net/spdy/spdy_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698