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

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

Issue 6292013: Add chunked uploads support to SPDY (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 9 months 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_http_stream.h" 5 #include "net/spdy/spdy_http_stream.h"
6 #include "net/spdy/spdy_session.h" 6 #include "net/spdy/spdy_session.h"
7 #include "net/spdy/spdy_test_util.h" 7 #include "net/spdy/spdy_test_util.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace net { 10 namespace net {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // This triggers read 3. The empty read causes the session to shut down. 91 // This triggers read 3. The empty read causes the session to shut down.
92 data()->CompleteRead(); 92 data()->CompleteRead();
93 93
94 // Because we abandoned the stream, we don't expect to find a session in the 94 // Because we abandoned the stream, we don't expect to find a session in the
95 // pool anymore. 95 // pool anymore.
96 EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession(pair)); 96 EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession(pair));
97 EXPECT_TRUE(data()->at_read_eof()); 97 EXPECT_TRUE(data()->at_read_eof());
98 EXPECT_TRUE(data()->at_write_eof()); 98 EXPECT_TRUE(data()->at_write_eof());
99 } 99 }
100 100
101 TEST_F(SpdyHttpStreamTest, SendChunkedPost) {
102 EnableCompression(false);
103 SpdySession::SetSSLMode(false);
104
105 scoped_ptr<spdy::SpdyFrame> req(ConstructChunkedSpdyPost(NULL, 0));
106 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, false));
107 scoped_ptr<spdy::SpdyFrame> lastchunk(ConstructSpdyBodyFrame(1, NULL, 0,
108 true));
109 MockWrite writes[] = {
110 CreateMockWrite(*req.get(), 1),
111 CreateMockWrite(*body, 2), // POST upload frame
112 CreateMockWrite(*lastchunk, 3),
113 };
114 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyPostSynReply(NULL, 0));
115 MockRead reads[] = {
116 CreateMockRead(*resp, 4),
117 CreateMockRead(*body, 5),
118 CreateMockRead(*lastchunk, 6),
119 MockRead(false, 0, 7) // EOF
120 };
121
122 HostPortPair host_port_pair("www.google.com", 80);
123 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct());
124 EXPECT_EQ(OK, InitSession(reads, arraysize(reads), writes, arraysize(writes),
125 host_port_pair));
willchan no longer on Chromium 2011/03/02 18:44:40 host_port_pair must align with reads a la http://g
Satish 2011/03/03 13:50:10 Done.
126
127 HttpRequestInfo request;
128 request.method = "POST";
129 request.url = GURL("http://www.google.com/");
130 request.upload_data = new UploadData();
131 request.upload_data->set_is_chunked(true);
132 request.upload_data->AppendChunk(kUploadData, kUploadDataSize);
133 request.upload_data->AppendChunk(NULL, 0);
134 TestCompletionCallback callback;
135 HttpResponseInfo response;
136 HttpRequestHeaders headers;
137 BoundNetLog net_log;
138 scoped_ptr<SpdyHttpStream> http_stream(
willchan no longer on Chromium 2011/03/02 18:44:40 How about just instantiating this on the stack? Is
Satish 2011/03/03 13:50:10 Done.
139 new SpdyHttpStream(session_.get(), true));
140 ASSERT_EQ(
141 OK,
142 http_stream->InitializeStream(&request, net_log, NULL));
143
144 UploadDataStream* upload_stream =
145 UploadDataStream::Create(request.upload_data, NULL);
146 EXPECT_EQ(ERR_IO_PENDING, http_stream->SendRequest(
147 headers, upload_stream, &response, &callback));
148 EXPECT_TRUE(http_session_->spdy_session_pool()->HasSession(pair));
149
150 // This triggers the MockWrite and read 2
151 callback.WaitForResult();
152
153 // This triggers read 3. The empty read causes the session to shut down.
154 data()->CompleteRead();
155 MessageLoop::current()->RunAllPending();
156
157 // Because we abandoned the stream, we don't expect to find a session in the
158 // pool anymore.
159 EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession(pair));
willchan no longer on Chromium 2011/03/02 18:44:40 This should be EXPECT_FALSE instead of EXPECT_TRUE
Satish 2011/03/03 13:50:10 Done.
160 EXPECT_TRUE(data()->at_read_eof());
161 EXPECT_TRUE(data()->at_write_eof());
162 }
163
101 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058 164 // Test case for bug: http://code.google.com/p/chromium/issues/detail?id=50058
102 TEST_F(SpdyHttpStreamTest, SpdyURLTest) { 165 TEST_F(SpdyHttpStreamTest, SpdyURLTest) {
103 EnableCompression(false); 166 EnableCompression(false);
104 SpdySession::SetSSLMode(false); 167 SpdySession::SetSSLMode(false);
105 168
106 const char * const full_url = "http://www.google.com/foo?query=what#anchor"; 169 const char * const full_url = "http://www.google.com/foo?query=what#anchor";
107 const char * const base_url = "http://www.google.com/foo?query=what"; 170 const char * const base_url = "http://www.google.com/foo?query=what";
108 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST)); 171 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(base_url, false, 1, LOWEST));
109 MockWrite writes[] = { 172 MockWrite writes[] = {
110 CreateMockWrite(*req.get(), 1), 173 CreateMockWrite(*req.get(), 1),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // pool anymore. 216 // pool anymore.
154 EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession(pair)); 217 EXPECT_TRUE(!http_session_->spdy_session_pool()->HasSession(pair));
155 EXPECT_TRUE(data()->at_read_eof()); 218 EXPECT_TRUE(data()->at_read_eof());
156 EXPECT_TRUE(data()->at_write_eof()); 219 EXPECT_TRUE(data()->at_write_eof());
157 } 220 }
158 221
159 // TODO(willchan): Write a longer test for SpdyStream that exercises all 222 // TODO(willchan): Write a longer test for SpdyStream that exercises all
160 // methods. 223 // methods.
161 224
162 } // namespace net 225 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698