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

Side by Side Diff: net/flip/flip_network_transaction_unittest.cc

Issue 338055: Update the unit test to test the FLIP client writes as well... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 | « no previous file | net/flip/flip_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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <math.h> // ceil 5 #include <math.h> // ceil
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "net/base/completion_callback.h" 8 #include "net/base/completion_callback.h"
9 #include "net/base/mock_host_resolver.h" 9 #include "net/base/mock_host_resolver.h"
10 #include "net/base/ssl_config_service_defaults.h" 10 #include "net/base/ssl_config_service_defaults.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 virtual void TearDown() { 82 virtual void TearDown() {
83 // Empty the current queue. 83 // Empty the current queue.
84 MessageLoop::current()->RunAllPending(); 84 MessageLoop::current()->RunAllPending();
85 PlatformTest::TearDown(); 85 PlatformTest::TearDown();
86 } 86 }
87 87
88 protected: 88 protected:
89 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure); 89 void KeepAliveConnectionResendRequestTest(const MockRead& read_failure);
90 90
91 struct SimpleGetHelperResult { 91 struct TransactionHelperResult {
92 int rv; 92 int rv;
93 std::string status_line; 93 std::string status_line;
94 std::string response_data; 94 std::string response_data;
95 }; 95 };
96 96
97 SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[]) { 97 TransactionHelperResult TransactionHelper(const HttpRequestInfo& request,
98 SimpleGetHelperResult out; 98 MockRead reads[],
99 MockWrite writes[]) {
100 TransactionHelperResult out;
101
102 // We disable SSL for this test.
103 FlipSession::SetSSLMode(false);
99 104
100 SessionDependencies session_deps; 105 SessionDependencies session_deps;
101 scoped_ptr<FlipNetworkTransaction> trans( 106 scoped_ptr<FlipNetworkTransaction> trans(
102 new FlipNetworkTransaction(CreateSession(&session_deps))); 107 new FlipNetworkTransaction(CreateSession(&session_deps)));
103 108
104 HttpRequestInfo request; 109 StaticMockSocket data(reads, writes);
105 request.method = "GET";
106 request.url = GURL("http://www.google.com/");
107 request.load_flags = 0;
108
109 StaticMockSocket data(data_reads, NULL);
110 session_deps.socket_factory.AddMockSocket(&data); 110 session_deps.socket_factory.AddMockSocket(&data);
111 111
112 TestCompletionCallback callback; 112 TestCompletionCallback callback;
113 113
114 int rv = trans->Start(&request, &callback, NULL); 114 int rv = trans->Start(&request, &callback, NULL);
115 EXPECT_EQ(ERR_IO_PENDING, rv); 115 EXPECT_EQ(ERR_IO_PENDING, rv);
116 116
117 out.rv = callback.WaitForResult(); 117 out.rv = callback.WaitForResult();
118 if (out.rv != OK) 118 if (out.rv != OK)
119 return out; 119 return out;
(...skipping 17 matching lines...) Expand all
137 //----------------------------------------------------------------------------- 137 //-----------------------------------------------------------------------------
138 138
139 // Verify FlipNetworkTransaction constructor. 139 // Verify FlipNetworkTransaction constructor.
140 TEST_F(FlipNetworkTransactionTest, Constructor) { 140 TEST_F(FlipNetworkTransactionTest, Constructor) {
141 SessionDependencies session_deps; 141 SessionDependencies session_deps;
142 scoped_refptr<net::HttpNetworkSession> session = 142 scoped_refptr<net::HttpNetworkSession> session =
143 CreateSession(&session_deps); 143 CreateSession(&session_deps);
144 scoped_ptr<HttpTransaction> trans(new FlipNetworkTransaction(session)); 144 scoped_ptr<HttpTransaction> trans(new FlipNetworkTransaction(session));
145 } 145 }
146 146
147 TEST_F(FlipNetworkTransactionTest, Connect) { 147 TEST_F(FlipNetworkTransactionTest, Get) {
148 static const unsigned char syn[] = {
149 0x80, 0x01, 0x00, 0x01, // header
150 0x01, 0x00, 0x00, 0x30, // FIN, len
151 0x00, 0x00, 0x00, 0x01, // stream id
152 0xc0, 0x00, 0x00, 0x03, // 4 headers
153 0x00, 0x06, 'm', 'e', 't', 'h', 'o', 'd', // "hello"
154 0x00, 0x03, 'G', 'E', 'T', // "bye"
155 0x00, 0x03, 'u', 'r', 'l', // "url"
156 0x00, 0x01, '/', // "/"
157 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n', // "status"
158 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1', // "200"
159 };
160
148 static const unsigned char syn_reply[] = { 161 static const unsigned char syn_reply[] = {
149 0x80, 0x01, 0x00, 0x02, // header 162 0x80, 0x01, 0x00, 0x02, // header
150 0x00, 0x00, 0x00, 0x45, 163 0x00, 0x00, 0x00, 0x45,
151 0x00, 0x00, 0x00, 0x01, 164 0x00, 0x00, 0x00, 0x01,
152 0x00, 0x00, 0x00, 0x04, // 4 headers 165 0x00, 0x00, 0x00, 0x04, // 4 headers
153 0x00, 0x05, 'h', 'e', 'l', 'l', 'o', // "hello" 166 0x00, 0x05, 'h', 'e', 'l', 'l', 'o', // "hello"
154 0x00, 0x03, 'b', 'y', 'e', // "bye" 167 0x00, 0x03, 'b', 'y', 'e', // "bye"
155 0x00, 0x06, 's', 't', 'a', 't', 'u', 's', // "status" 168 0x00, 0x06, 's', 't', 'a', 't', 'u', 's', // "status"
156 0x00, 0x03, '2', '0', '0', // "200" 169 0x00, 0x03, '2', '0', '0', // "200"
157 0x00, 0x03, 'u', 'r', 'l', // "url" 170 0x00, 0x03, 'u', 'r', 'l', // "url"
158 0x00, 0x0a, '/', 'i', 'n', 'd', 'e', 'x', '.', 'p', 'h', 'p', // "HTTP/1.1" 171 0x00, 0x0a, '/', 'i', 'n', 'd', 'e', 'x', '.', 'p', 'h', 'p', // "HTTP/1.1"
159 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n', // "version" 172 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n', // "version"
160 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1', // "HTTP/1.1" 173 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1', // "HTTP/1.1"
161 }; 174 };
162 static const unsigned char body_frame[] = { 175 static const unsigned char body_frame[] = {
163 0x00, 0x00, 0x00, 0x01, // header 176 0x00, 0x00, 0x00, 0x01, // header
164 0x00, 0x00, 0x00, 0x06, 177 0x00, 0x00, 0x00, 0x06,
165 'h', 'e', 'l', 'l', 'o', '!', // "hello" 178 'h', 'e', 'l', 'l', 'o', '!', // "hello"
166 }; 179 };
167 static const unsigned char fin_frame[] = { 180 static const unsigned char fin_frame[] = {
168 0x80, 0x01, 0x00, 0x03, // header 181 0x80, 0x01, 0x00, 0x03, // header
169 0x00, 0x00, 0x00, 0x08, 182 0x00, 0x00, 0x00, 0x08,
170 0x00, 0x00, 0x00, 0x01, 183 0x00, 0x00, 0x00, 0x01,
171 0x00, 0x00, 0x00, 0x00, 184 0x00, 0x00, 0x00, 0x00,
172 }; 185 };
173 186
187 MockWrite writes[] = {
188 MockWrite(true, reinterpret_cast<const char*>(syn), sizeof(syn)),
189 };
190
191 MockRead reads[] = {
192 MockRead(true, reinterpret_cast<const char*>(syn_reply), sizeof(syn_reply)),
193 MockWrite(true, reinterpret_cast<const char*>(body_frame),
194 sizeof(body_frame)),
195 MockWrite(true, reinterpret_cast<const char*>(fin_frame),
196 sizeof(fin_frame)),
197 MockRead(true, 0, 0) // EOF
198 };
199
200 HttpRequestInfo request;
201 request.method = "GET";
202 request.url = GURL("http://www.google.com/");
203 request.load_flags = 0;
204 TransactionHelperResult out = TransactionHelper(request, reads, writes);
205 EXPECT_EQ(OK, out.rv);
206 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
207 EXPECT_EQ("hello!", out.response_data);
208 }
209
210 // Test that a simple POST works.
211 TEST_F(FlipNetworkTransactionTest, Post) {
212 static const char upload[] = { "hello world" };
213
214 // Setup the request
215 HttpRequestInfo request;
216 request.method = "POST";
217 request.url = GURL("http://www.google.com/");
218 request.upload_data = new UploadData();
219 request.upload_data->AppendBytes(upload, sizeof(upload));
220
221 // TODO(mbelshe): Hook up the write validation.
222
223 //static const unsigned char syn[] = {
224 // 0x80, 0x01, 0x00, 0x01, // header
225 // 0x00, 0x00, 0x00, 0x30, // FIN, len
226 // 0x00, 0x00, 0x00, 0x01, // stream i d
227 // 0xc0, 0x00, 0x00, 0x03, // 4 header s
228 // 0x00, 0x06, 'm', 'e', 't', 'h', 'o', 'd', // "hello"
229 // 0x00, 0x03, 'G', 'E', 'T', // "bye"
230 // 0x00, 0x03, 'u', 'r', 'l', // "url"
231 // 0x00, 0x01, '/', // "/"
232 // 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n', // "status"
233 // 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1', // "200"
234 //};
235
236 //static const unsigned char upload_frame[] = {
237 // 0x00, 0x00, 0x00, 0x01, // header
238 // 0x01, 0x00, 0x00, 0x06, // FIN flag
239 // 'h', 'e', 'l', 'l', 'o', '!', // "hello"
240 //};
241
242 // The response
243 static const unsigned char syn_reply[] = {
244 0x80, 0x01, 0x00, 0x02, // header
245 0x00, 0x00, 0x00, 0x45,
246 0x00, 0x00, 0x00, 0x01,
247 0x00, 0x00, 0x00, 0x04, // 4 headers
248 0x00, 0x05, 'h', 'e', 'l', 'l', 'o', // "hello"
249 0x00, 0x03, 'b', 'y', 'e', // "bye"
250 0x00, 0x06, 's', 't', 'a', 't', 'u', 's', // "status"
251 0x00, 0x03, '2', '0', '0', // "200"
252 0x00, 0x03, 'u', 'r', 'l', // "url"
253 0x00, 0x0a, '/', 'i', 'n', 'd', 'e', 'x', '.', 'p', 'h', 'p', // "HTTP/1.1"
254 0x00, 0x07, 'v', 'e', 'r', 's', 'i', 'o', 'n', // "version"
255 0x00, 0x08, 'H', 'T', 'T', 'P', '/', '1', '.', '1', // "HTTP/1.1"
256 };
257 static const unsigned char body_frame[] = {
258 0x00, 0x00, 0x00, 0x01, // header
259 0x00, 0x00, 0x00, 0x06,
260 'h', 'e', 'l', 'l', 'o', '!', // "hello"
261 };
262 static const unsigned char fin_frame[] = {
263 0x80, 0x01, 0x00, 0x03, // header
264 0x00, 0x00, 0x00, 0x08,
265 0x00, 0x00, 0x00, 0x01,
266 0x00, 0x00, 0x00, 0x00,
267 };
268
269 //MockWrite writes[] = {
270 // MockWrite(true, reinterpret_cast<const char*>(syn), sizeof(syn)),
271 // MockWrite(true, reinterpret_cast<const char*>(upload_frame),
272 // sizeof(upload_frame)),
273 //};
274
174 MockRead data_reads[] = { 275 MockRead data_reads[] = {
175 MockRead(true, reinterpret_cast<const char*>(syn_reply), sizeof(syn_reply)), 276 MockRead(true, reinterpret_cast<const char*>(syn_reply), sizeof(syn_reply)),
176 MockRead(true, reinterpret_cast<const char*>(body_frame), 277 MockRead(true, reinterpret_cast<const char*>(body_frame),
177 sizeof(body_frame)), 278 sizeof(body_frame)),
178 MockRead(true, reinterpret_cast<const char*>(fin_frame), sizeof(fin_frame)), 279 MockRead(true, reinterpret_cast<const char*>(fin_frame), sizeof(fin_frame)),
179 MockRead(true, 0, 0), // EOF 280 MockRead(true, 0, 0) // EOF
180 }; 281 };
181 282
182 // We disable SSL for this test. 283 TransactionHelperResult out = TransactionHelper(request, data_reads, NULL);
183 FlipSession::SetSSLMode(false);
184 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
185 EXPECT_EQ(OK, out.rv); 284 EXPECT_EQ(OK, out.rv);
186 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 285 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
187 EXPECT_EQ("hello!", out.response_data); 286 EXPECT_EQ("hello!", out.response_data);
188 } 287 }
189 288
190 // Test that the transaction doesn't crash when we don't have a reply. 289 // Test that the transaction doesn't crash when we don't have a reply.
191 TEST_F(FlipNetworkTransactionTest, ResponseWithoutSynReply) { 290 TEST_F(FlipNetworkTransactionTest, ResponseWithoutSynReply) {
192 static const unsigned char body_frame[] = { 291 static const unsigned char body_frame[] = {
193 0x00, 0x00, 0x00, 0x01, // header 292 0x00, 0x00, 0x00, 0x01, // header
194 0x00, 0x00, 0x00, 0x06, 293 0x00, 0x00, 0x00, 0x06,
195 'h', 'e', 'l', 'l', 'o', '!', // "hello" 294 'h', 'e', 'l', 'l', 'o', '!', // "hello"
196 }; 295 };
197 static const unsigned char fin_frame[] = { 296 static const unsigned char fin_frame[] = {
198 0x80, 0x01, 0x00, 0x03, // header 297 0x80, 0x01, 0x00, 0x03, // header
199 0x00, 0x00, 0x00, 0x08, 298 0x00, 0x00, 0x00, 0x08,
200 0x00, 0x00, 0x00, 0x01, 299 0x00, 0x00, 0x00, 0x01,
201 0x00, 0x00, 0x00, 0x00, 300 0x00, 0x00, 0x00, 0x00,
202 }; 301 };
203 302
204 MockRead data_reads[] = { 303 MockRead data_reads[] = {
205 MockRead(true, reinterpret_cast<const char*>(body_frame), 304 MockRead(true, reinterpret_cast<const char*>(body_frame),
206 sizeof(body_frame)), 305 sizeof(body_frame)),
207 MockRead(true, reinterpret_cast<const char*>(fin_frame), sizeof(fin_frame)), 306 MockRead(true, reinterpret_cast<const char*>(fin_frame), sizeof(fin_frame)),
208 MockRead(true, 0, 0), // EOF 307 MockRead(true, 0, 0) // EOF
209 }; 308 };
210 309
211 // We disable SSL for this test. 310 HttpRequestInfo request;
212 FlipSession::SetSSLMode(false); 311 request.method = "GET";
213 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 312 request.url = GURL("http://www.google.com/");
313 request.load_flags = 0;
314 TransactionHelperResult out = TransactionHelper(request, data_reads, NULL);
214 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv); 315 EXPECT_EQ(ERR_SYN_REPLY_NOT_RECEIVED, out.rv);
215 } 316 }
216 317
318
wtc 2009/10/28 01:12:05 Please delete this blank line, too.
217 } // namespace net 319 } // namespace net
218 320
OLDNEW
« no previous file with comments | « no previous file | net/flip/flip_session.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698