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

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 5026: Style refactoring to make MockRead initializers more readable. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 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
« no previous file with comments | « no previous file | no next file » | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/platform_test.h" 6 #include "base/platform_test.h"
7 #include "net/base/client_socket_factory.h" 7 #include "net/base/client_socket_factory.h"
8 #include "net/base/test_completion_callback.h" 8 #include "net/base/test_completion_callback.h"
9 #include "net/base/upload_data.h" 9 #include "net/base/upload_data.h"
10 #include "net/http/http_network_session.h" 10 #include "net/http/http_network_session.h"
11 #include "net/http/http_network_transaction.h" 11 #include "net/http/http_network_transaction.h"
12 #include "net/http/http_transaction_unittest.h" 12 #include "net/http/http_transaction_unittest.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 //----------------------------------------------------------------------------- 15 //-----------------------------------------------------------------------------
16 16
17 17
18 struct MockConnect { 18 struct MockConnect {
19 bool async; 19 bool async;
20 int result; 20 int result;
21
22 // Asynchronous connection success.
23 MockConnect() : async(true), result(net::OK) { }
wtc 2008/09/29 20:16:33 Nit: list the constructor before the members, as y
eroman 2008/09/29 20:29:17 oops. will fix. (I already submitted this as I rel
21 }; 24 };
22 25
23 struct MockRead { 26 struct MockRead {
27 // Read failure (no data).
28 MockRead(bool async, int result) : async(async) , result(result), data(NULL),
29 data_len(0) { }
30
31 // Asynchronous read success (inferred data length).
32 MockRead(const char* data) : async(true), data(data), data_len(strlen(data)),
33 result(0) { }
34
35 // Read success (inferred data length).
36 MockRead(bool async, const char* data) : async(async), data(data),
37 data_len(strlen(data)), result(0) { }
38
39 // Read success.
40 MockRead(bool async, const char* data, int data_len) : async(async),
41 data(data), data_len(data_len), result(0) { }
wtc 2008/09/29 20:16:33 Ideally, these should be accompanied with the C++
eroman 2008/09/29 20:29:17 That happens automatically -- once you have a user
42
24 bool async; 43 bool async;
25 int result; // Ignored if data is non-null. 44 int result;
26 const char* data; 45 const char* data;
27 int data_len; // -1 if strlen(data) should be used. 46 int data_len;
28 }; 47 };
29 48
30 struct MockSocket { 49 struct MockSocket {
50 MockSocket() : reads(NULL) { }
51
31 MockConnect connect; 52 MockConnect connect;
32 MockRead* reads; // Terminated by a MockRead element with data == NULL. 53 MockRead* reads;
wtc 2008/09/29 20:16:33 Do we still need to terminate the 'reads' array wi
eroman 2008/09/29 20:29:17 as far as I can tell, that comment was wrong -- no
33 }; 54 };
34 55
35 // Holds an array of MockSocket elements. As MockTCPClientSocket objects get 56 // Holds an array of MockSocket elements. As MockTCPClientSocket objects get
36 // instantiated, they take their data from the i'th element of this array. 57 // instantiated, they take their data from the i'th element of this array.
37 // 58 //
38 // Tests should assign the first N entries of mock_sockets to point to valid 59 // Tests should assign the first N entries of mock_sockets to point to valid
39 // MockSocket objects. The first unused entry should be NULL'd. 60 // MockSocket objects. The first unused entry should be NULL'd.
40 // 61 //
41 MockSocket* mock_sockets[10]; 62 MockSocket* mock_sockets[10];
42 63
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 97 }
77 virtual bool IsConnected() const { 98 virtual bool IsConnected() const {
78 return connected_; 99 return connected_;
79 } 100 }
80 // Socket methods: 101 // Socket methods:
81 virtual int Read(char* buf, int buf_len, net::CompletionCallback* callback) { 102 virtual int Read(char* buf, int buf_len, net::CompletionCallback* callback) {
82 DCHECK(!callback_); 103 DCHECK(!callback_);
83 MockRead& r = data_->reads[read_index_]; 104 MockRead& r = data_->reads[read_index_];
84 int result; 105 int result;
85 if (r.data) { 106 if (r.data) {
86 if (r.data_len == -1)
87 r.data_len = static_cast<int>(strlen(r.data));
88 if (r.data_len - read_offset_ > 0) { 107 if (r.data_len - read_offset_ > 0) {
89 result = std::min(buf_len, r.data_len - read_offset_); 108 result = std::min(buf_len, r.data_len - read_offset_);
90 memcpy(buf, r.data + read_offset_, result); 109 memcpy(buf, r.data + read_offset_, result);
91 read_offset_ += result; 110 read_offset_ += result;
92 if (read_offset_ == r.data_len) { 111 if (read_offset_ == r.data_len) {
93 read_index_++; 112 read_index_++;
94 read_offset_ = 0; 113 read_offset_ = 0;
95 } 114 }
96 } else { 115 } else {
97 result = 0; // EOF 116 result = 0; // EOF
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 203
185 net::HttpTransaction* trans = new net::HttpNetworkTransaction( 204 net::HttpTransaction* trans = new net::HttpNetworkTransaction(
186 CreateSession(), &mock_socket_factory); 205 CreateSession(), &mock_socket_factory);
187 206
188 net::HttpRequestInfo request; 207 net::HttpRequestInfo request;
189 request.method = "GET"; 208 request.method = "GET";
190 request.url = GURL("http://www.google.com/"); 209 request.url = GURL("http://www.google.com/");
191 request.load_flags = 0; 210 request.load_flags = 0;
192 211
193 MockSocket data; 212 MockSocket data;
194 data.connect.async = true;
195 data.connect.result = net::OK;
196 data.reads = data_reads; 213 data.reads = data_reads;
197 mock_sockets[0] = &data; 214 mock_sockets[0] = &data;
198 mock_sockets[1] = NULL; 215 mock_sockets[1] = NULL;
199 216
200 TestCompletionCallback callback; 217 TestCompletionCallback callback;
201 218
202 int rv = trans->Start(&request, &callback); 219 int rv = trans->Start(&request, &callback);
203 EXPECT_EQ(net::ERR_IO_PENDING, rv); 220 EXPECT_EQ(net::ERR_IO_PENDING, rv);
204 221
205 rv = callback.WaitForResult(); 222 rv = callback.WaitForResult();
(...skipping 19 matching lines...) Expand all
225 //----------------------------------------------------------------------------- 242 //-----------------------------------------------------------------------------
226 243
227 TEST_F(HttpNetworkTransactionTest, Basic) { 244 TEST_F(HttpNetworkTransactionTest, Basic) {
228 net::HttpTransaction* trans = new net::HttpNetworkTransaction( 245 net::HttpTransaction* trans = new net::HttpNetworkTransaction(
229 CreateSession(), &mock_socket_factory); 246 CreateSession(), &mock_socket_factory);
230 trans->Destroy(); 247 trans->Destroy();
231 } 248 }
232 249
233 TEST_F(HttpNetworkTransactionTest, SimpleGET) { 250 TEST_F(HttpNetworkTransactionTest, SimpleGET) {
234 MockRead data_reads[] = { 251 MockRead data_reads[] = {
235 { true, 0, "HTTP/1.0 200 OK\r\n\r\n", -1 }, 252 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
236 { true, 0, "hello world", -1 }, 253 MockRead("hello world"),
237 { false, net::OK, NULL, 0 }, 254 MockRead(false, net::OK),
238 }; 255 };
239 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 256 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
240 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); 257 EXPECT_EQ("HTTP/1.0 200 OK", out.status_line);
241 EXPECT_EQ("hello world", out.response_data); 258 EXPECT_EQ("hello world", out.response_data);
242 } 259 }
243 260
244 // Response with no status line. 261 // Response with no status line.
245 TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { 262 TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) {
246 MockRead data_reads[] = { 263 MockRead data_reads[] = {
247 { true, 0, "hello world", -1 }, 264 MockRead("hello world"),
248 { false, net::OK, NULL, 0 }, 265 MockRead(false, net::OK),
249 }; 266 };
250 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 267 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
251 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); 268 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
252 EXPECT_EQ("hello world", out.response_data); 269 EXPECT_EQ("hello world", out.response_data);
253 } 270 }
254 271
255 // Allow up to 4 bytes of junk to precede status line. 272 // Allow up to 4 bytes of junk to precede status line.
256 TEST_F(HttpNetworkTransactionTest, StatusLineJunk2Bytes) { 273 TEST_F(HttpNetworkTransactionTest, StatusLineJunk2Bytes) {
257 MockRead data_reads[] = { 274 MockRead data_reads[] = {
258 { true, 0, "xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA", -1 }, 275 MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
259 { false, net::OK, NULL, 0 }, 276 MockRead(false, net::OK),
260 }; 277 };
261 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 278 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
262 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); 279 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
263 EXPECT_EQ("DATA", out.response_data); 280 EXPECT_EQ("DATA", out.response_data);
264 } 281 }
265 282
266 // Allow up to 4 bytes of junk to precede status line. 283 // Allow up to 4 bytes of junk to precede status line.
267 TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { 284 TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) {
268 MockRead data_reads[] = { 285 MockRead data_reads[] = {
269 { true, 0, "\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA", -1 }, 286 MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
270 { false, net::OK, NULL, 0 }, 287 MockRead(false, net::OK),
271 }; 288 };
272 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 289 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
273 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); 290 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
274 EXPECT_EQ("DATA", out.response_data); 291 EXPECT_EQ("DATA", out.response_data);
275 } 292 }
276 293
277 // Beyond 4 bytes of slop and it should fail to find a status line. 294 // Beyond 4 bytes of slop and it should fail to find a status line.
278 TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { 295 TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) {
279 MockRead data_reads[] = { 296 MockRead data_reads[] = {
280 { true, 0, "xxxxxHTTP/1.1 404 Not Found\nServer: blah", -1 }, 297 MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"),
281 { false, net::OK, NULL, 0 }, 298 MockRead(false, net::OK),
282 }; 299 };
283 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 300 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
284 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); 301 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
285 EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); 302 EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data);
286 } 303 }
287 304
288 // Same as StatusLineJunk4Bytes, except the read chunks are smaller. 305 // Same as StatusLineJunk4Bytes, except the read chunks are smaller.
289 TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { 306 TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) {
290 MockRead data_reads[] = { 307 MockRead data_reads[] = {
291 { true, 0, "\n", -1 }, 308 MockRead("\n"),
292 { true, 0, "\n", -1 }, 309 MockRead("\n"),
293 { true, 0, "Q", -1 }, 310 MockRead("Q"),
294 { true, 0, "J", -1 }, 311 MockRead("J"),
295 { true, 0, "HTTP/1.0 404 Not Found\nServer: blah\n\nDATA", -1 }, 312 MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"),
296 { false, net::OK, NULL, 0 }, 313 MockRead(false, net::OK),
297 }; 314 };
298 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 315 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
299 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); 316 EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line);
300 EXPECT_EQ("DATA", out.response_data); 317 EXPECT_EQ("DATA", out.response_data);
301 } 318 }
302 319
303 // Close the connection before enough bytes to have a status line. 320 // Close the connection before enough bytes to have a status line.
304 TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { 321 TEST_F(HttpNetworkTransactionTest, StatusLinePartial) {
305 MockRead data_reads[] = { 322 MockRead data_reads[] = {
306 { true, 0, "HTT", -1 }, 323 MockRead("HTT"),
307 { false, net::OK, NULL, 0 }, 324 MockRead(false, net::OK),
308 }; 325 };
309 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 326 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
310 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); 327 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
311 EXPECT_EQ("HTT", out.response_data); 328 EXPECT_EQ("HTT", out.response_data);
312 } 329 }
313 330
314 // Simulate a 204 response, lacking a Content-Length header, sent over a 331 // Simulate a 204 response, lacking a Content-Length header, sent over a
315 // persistent connection. The response should still terminate since a 204 332 // persistent connection. The response should still terminate since a 204
316 // cannot have a response body. 333 // cannot have a response body.
317 TEST_F(HttpNetworkTransactionTest, StopsReading204) { 334 TEST_F(HttpNetworkTransactionTest, StopsReading204) {
318 MockRead data_reads[] = { 335 MockRead data_reads[] = {
319 { true, 0, "HTTP/1.1 204 No Content\r\n\r\n", -1 }, 336 MockRead("HTTP/1.1 204 No Content\r\n\r\n"),
320 { true, 0, "junk", -1 }, // Should not be read!! 337 MockRead("junk"), // Should not be read!!
321 { false, net::OK, NULL, 0 }, 338 MockRead(false, net::OK),
322 }; 339 };
323 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 340 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
324 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); 341 EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line);
325 EXPECT_EQ("", out.response_data); 342 EXPECT_EQ("", out.response_data);
326 } 343 }
327 344
328 TEST_F(HttpNetworkTransactionTest, ReuseConnection) { 345 TEST_F(HttpNetworkTransactionTest, ReuseConnection) {
329 scoped_refptr<net::HttpNetworkSession> session = CreateSession(); 346 scoped_refptr<net::HttpNetworkSession> session = CreateSession();
330 347
331 MockRead data_reads[] = { 348 MockRead data_reads[] = {
332 { true, 0, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n", -1 }, 349 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
333 { true, 0, "hello", -1 }, 350 MockRead("hello"),
334 { true, 0, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n", -1 }, 351 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
335 { true, 0, "world", -1 }, 352 MockRead("world"),
336 { false, net::OK, NULL, 0 }, 353 MockRead(false, net::OK),
337 }; 354 };
338 MockSocket data; 355 MockSocket data;
339 data.connect.async = true;
340 data.connect.result = net::OK;
341 data.reads = data_reads; 356 data.reads = data_reads;
342 mock_sockets[0] = &data; 357 mock_sockets[0] = &data;
343 mock_sockets[1] = NULL; 358 mock_sockets[1] = NULL;
344 359
345 const char* kExpectedResponseData[] = { 360 const char* kExpectedResponseData[] = {
346 "hello", "world" 361 "hello", "world"
347 }; 362 };
348 363
349 for (int i = 0; i < 2; ++i) { 364 for (int i = 0; i < 2; ++i) {
350 net::HttpTransaction* trans = 365 net::HttpTransaction* trans =
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 CreateSession(), &mock_socket_factory); 401 CreateSession(), &mock_socket_factory);
387 402
388 net::HttpRequestInfo request; 403 net::HttpRequestInfo request;
389 request.method = "POST"; 404 request.method = "POST";
390 request.url = GURL("http://www.foo.com/"); 405 request.url = GURL("http://www.foo.com/");
391 request.upload_data = new net::UploadData; 406 request.upload_data = new net::UploadData;
392 request.upload_data->AppendBytes("foo", 3); 407 request.upload_data->AppendBytes("foo", 3);
393 request.load_flags = 0; 408 request.load_flags = 0;
394 409
395 MockRead data_reads[] = { 410 MockRead data_reads[] = {
396 { true, 0, "HTTP/1.0 100 Continue\r\n\r\n", -1 }, 411 MockRead("HTTP/1.0 100 Continue\r\n\r\n"),
397 { true, 0, "HTTP/1.0 200 OK\r\n\r\n", -1 }, 412 MockRead("HTTP/1.0 200 OK\r\n\r\n"),
398 { true, 0, "hello world", -1 }, 413 MockRead("hello world"),
399 { false, net::OK, NULL, 0 }, 414 MockRead(false, net::OK),
400 }; 415 };
401 MockSocket data; 416 MockSocket data;
402 data.connect.async = true;
403 data.connect.result = net::OK;
404 data.reads = data_reads; 417 data.reads = data_reads;
405 mock_sockets[0] = &data; 418 mock_sockets[0] = &data;
406 mock_sockets[1] = NULL; 419 mock_sockets[1] = NULL;
407 420
408 TestCompletionCallback callback; 421 TestCompletionCallback callback;
409 422
410 int rv = trans->Start(&request, &callback); 423 int rv = trans->Start(&request, &callback);
411 EXPECT_EQ(net::ERR_IO_PENDING, rv); 424 EXPECT_EQ(net::ERR_IO_PENDING, rv);
412 425
413 rv = callback.WaitForResult(); 426 rv = callback.WaitForResult();
(...skipping 21 matching lines...) Expand all
435 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( 448 void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest(
436 const MockRead& read_failure) { 449 const MockRead& read_failure) {
437 scoped_refptr<net::HttpNetworkSession> session = CreateSession(); 450 scoped_refptr<net::HttpNetworkSession> session = CreateSession();
438 451
439 net::HttpRequestInfo request; 452 net::HttpRequestInfo request;
440 request.method = "GET"; 453 request.method = "GET";
441 request.url = GURL("http://www.foo.com/"); 454 request.url = GURL("http://www.foo.com/");
442 request.load_flags = 0; 455 request.load_flags = 0;
443 456
444 MockRead data1_reads[] = { 457 MockRead data1_reads[] = {
445 { true, 0, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n", -1 }, 458 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
446 { true, 0, "hello", -1 }, 459 MockRead("hello"),
447 read_failure, // Now, we reuse the connection and fail the first read. 460 read_failure, // Now, we reuse the connection and fail the first read.
448 }; 461 };
449 MockSocket data1; 462 MockSocket data1;
450 data1.connect.async = true;
451 data1.connect.result = net::OK;
452 data1.reads = data1_reads; 463 data1.reads = data1_reads;
453 mock_sockets[0] = &data1; 464 mock_sockets[0] = &data1;
454 465
455 MockRead data2_reads[] = { 466 MockRead data2_reads[] = {
456 { true, 0, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n", -1 }, 467 MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"),
457 { true, 0, "world", -1 }, 468 MockRead("world"),
458 { true, net::OK, NULL, 0 }, 469 MockRead(true, net::OK),
459 }; 470 };
460 MockSocket data2; 471 MockSocket data2;
461 data2.connect.async = true;
462 data2.connect.result = net::OK;
463 data2.reads = data2_reads; 472 data2.reads = data2_reads;
464 mock_sockets[1] = &data2; 473 mock_sockets[1] = &data2;
465 474
466 const char* kExpectedResponseData[] = { 475 const char* kExpectedResponseData[] = {
467 "hello", "world" 476 "hello", "world"
468 }; 477 };
469 478
470 for (int i = 0; i < 2; ++i) { 479 for (int i = 0; i < 2; ++i) {
471 TestCompletionCallback callback; 480 TestCompletionCallback callback;
472 481
(...skipping 18 matching lines...) Expand all
491 EXPECT_EQ(kExpectedResponseData[i], response_data); 500 EXPECT_EQ(kExpectedResponseData[i], response_data);
492 501
493 trans->Destroy(); 502 trans->Destroy();
494 503
495 // Empty the current queue. 504 // Empty the current queue.
496 MessageLoop::current()->RunAllPending(); 505 MessageLoop::current()->RunAllPending();
497 } 506 }
498 } 507 }
499 508
500 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { 509 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) {
501 MockRead read_failure = { true, net::ERR_CONNECTION_RESET, NULL, 0 }; 510 MockRead read_failure(true, net::ERR_CONNECTION_RESET);
502 KeepAliveConnectionResendRequestTest(read_failure); 511 KeepAliveConnectionResendRequestTest(read_failure);
503 } 512 }
504 513
505 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { 514 TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) {
506 MockRead read_failure = { false, net::OK, NULL, 0 }; // EOF 515 MockRead read_failure(false, net::OK); // EOF
507 KeepAliveConnectionResendRequestTest(read_failure); 516 KeepAliveConnectionResendRequestTest(read_failure);
508 } 517 }
509 518
510 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { 519 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) {
511 net::HttpTransaction* trans = new net::HttpNetworkTransaction( 520 net::HttpTransaction* trans = new net::HttpNetworkTransaction(
512 CreateSession(), &mock_socket_factory); 521 CreateSession(), &mock_socket_factory);
513 522
514 net::HttpRequestInfo request; 523 net::HttpRequestInfo request;
515 request.method = "GET"; 524 request.method = "GET";
516 request.url = GURL("http://www.google.com/"); 525 request.url = GURL("http://www.google.com/");
517 request.load_flags = 0; 526 request.load_flags = 0;
518 527
519 MockRead data_reads[] = { 528 MockRead data_reads[] = {
520 { true, net::ERR_CONNECTION_RESET, NULL, 0 }, 529 MockRead(true, net::ERR_CONNECTION_RESET),
521 { true, 0, "HTTP/1.0 200 OK\r\n\r\n", -1 }, // Should not be used 530 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used
522 { true, 0, "hello world", -1 }, 531 MockRead("hello world"),
523 { false, net::OK, NULL, 0 }, 532 MockRead(false, net::OK),
524 }; 533 };
525 MockSocket data; 534 MockSocket data;
526 data.connect.async = true;
527 data.connect.result = net::OK;
528 data.reads = data_reads; 535 data.reads = data_reads;
529 mock_sockets[0] = &data; 536 mock_sockets[0] = &data;
530 mock_sockets[1] = NULL; 537 mock_sockets[1] = NULL;
531 538
532 TestCompletionCallback callback; 539 TestCompletionCallback callback;
533 540
534 int rv = trans->Start(&request, &callback); 541 int rv = trans->Start(&request, &callback);
535 EXPECT_EQ(net::ERR_IO_PENDING, rv); 542 EXPECT_EQ(net::ERR_IO_PENDING, rv);
536 543
537 rv = callback.WaitForResult(); 544 rv = callback.WaitForResult();
(...skipping 12 matching lines...) Expand all
550 // connection without sending any response header or body? 557 // connection without sending any response header or body?
551 // 558 //
552 // IE7: error page 559 // IE7: error page
553 // Safari 3.1.2 (Windows): error page 560 // Safari 3.1.2 (Windows): error page
554 // Firefox 3.0.1: blank page 561 // Firefox 3.0.1: blank page
555 // Opera 9.52: after five attempts, blank page 562 // Opera 9.52: after five attempts, blank page
556 // Us with WinHTTP: error page (net::ERR_INVALID_RESPONSE) 563 // Us with WinHTTP: error page (net::ERR_INVALID_RESPONSE)
557 // Us: blank page 564 // Us: blank page
558 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { 565 TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) {
559 MockRead data_reads[] = { 566 MockRead data_reads[] = {
560 { false, net::OK, NULL, 0 }, // EOF 567 MockRead(false, net::OK), // EOF
561 { true, 0, "HTTP/1.0 200 OK\r\n\r\n", -1 }, // Should not be used 568 MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used
562 { true, 0, "hello world", -1 }, 569 MockRead("hello world"),
563 { false, net::OK, NULL, 0 }, 570 MockRead(false, net::OK),
564 }; 571 };
565 SimpleGetHelperResult out = SimpleGetHelper(data_reads); 572 SimpleGetHelperResult out = SimpleGetHelper(data_reads);
566 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); 573 EXPECT_EQ("HTTP/0.9 200 OK", out.status_line);
567 EXPECT_EQ("", out.response_data); 574 EXPECT_EQ("", out.response_data);
568 } 575 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698