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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 default_pipelining_enabled_ = HttpStreamFactory::http_pipelining_enabled(); | 45 default_pipelining_enabled_ = HttpStreamFactory::http_pipelining_enabled(); |
46 HttpStreamFactory::set_http_pipelining_enabled(true); | 46 HttpStreamFactory::set_http_pipelining_enabled(true); |
47 } | 47 } |
48 | 48 |
49 virtual void TearDown() OVERRIDE { | 49 virtual void TearDown() OVERRIDE { |
50 MessageLoop::current()->RunAllPending(); | 50 MessageLoop::current()->RunAllPending(); |
51 HttpStreamFactory::set_http_pipelining_enabled(default_pipelining_enabled_); | 51 HttpStreamFactory::set_http_pipelining_enabled(default_pipelining_enabled_); |
52 } | 52 } |
53 | 53 |
54 void Initialize() { | 54 void Initialize() { |
| 55 // Normally, this code could just go in SetUp(). For a few of these tests, |
| 56 // we change the default number of sockets per group. That needs to be done |
| 57 // before we construct the HttpNetworkSession. |
55 proxy_service_.reset(ProxyService::CreateDirect()); | 58 proxy_service_.reset(ProxyService::CreateDirect()); |
56 ssl_config_ = new SSLConfigServiceDefaults; | 59 ssl_config_ = new SSLConfigServiceDefaults; |
57 auth_handler_factory_.reset(new HttpAuthHandlerMock::Factory()); | 60 auth_handler_factory_.reset(new HttpAuthHandlerMock::Factory()); |
58 | 61 |
59 HttpNetworkSession::Params session_params; | 62 HttpNetworkSession::Params session_params; |
60 session_params.client_socket_factory = &factory_; | 63 session_params.client_socket_factory = &factory_; |
61 session_params.proxy_service = proxy_service_.get(); | 64 session_params.proxy_service = proxy_service_.get(); |
62 session_params.host_resolver = &mock_resolver_; | 65 session_params.host_resolver = &mock_resolver_; |
63 session_params.ssl_config_service = ssl_config_.get(); | 66 session_params.ssl_config_service = ssl_config_.get(); |
64 session_params.http_auth_handler_factory = auth_handler_factory_.get(); | 67 session_params.http_auth_handler_factory = auth_handler_factory_.get(); |
65 session_params.http_server_properties = &http_server_properties_; | 68 session_params.http_server_properties = &http_server_properties_; |
66 session_ = new HttpNetworkSession(session_params); | 69 session_ = new HttpNetworkSession(session_params); |
67 } | 70 } |
68 | 71 |
69 void AddExpectedConnection(MockRead* reads, size_t reads_count, | 72 void AddExpectedConnection(MockRead* reads, size_t reads_count, |
70 MockWrite* writes, size_t writes_count) { | 73 MockWrite* writes, size_t writes_count) { |
71 DeterministicSocketData* data = new DeterministicSocketData( | 74 DeterministicSocketData* data = new DeterministicSocketData( |
72 reads, reads_count, writes, writes_count); | 75 reads, reads_count, writes, writes_count); |
73 data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | 76 data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
74 if (reads_count || writes_count) { | 77 if (reads_count || writes_count) { |
75 data->StopAfter(reads_count + writes_count); | 78 data->StopAfter(reads_count + writes_count); |
76 } | 79 } |
77 factory_.AddSocketDataProvider(data); | 80 factory_.AddSocketDataProvider(data); |
78 data_vector_.push_back(data); | 81 data_vector_.push_back(data); |
79 } | 82 } |
80 | 83 |
81 const HttpRequestInfo* GetRequestInfo(const char* filename) { | 84 HttpRequestInfo* GetRequestInfo(const char* filename) { |
82 std::string url = StringPrintf("http://localhost/%s", filename); | 85 std::string url = StringPrintf("http://localhost/%s", filename); |
83 HttpRequestInfo* request_info = new HttpRequestInfo; | 86 HttpRequestInfo* request_info = new HttpRequestInfo; |
84 request_info->url = GURL(url); | 87 request_info->url = GURL(url); |
85 request_info->method = "GET"; | 88 request_info->method = "GET"; |
86 request_info_vector_.push_back(request_info); | 89 request_info_vector_.push_back(request_info); |
87 return request_info; | 90 return request_info; |
88 } | 91 } |
89 | 92 |
90 void ExpectResponse(const std::string& expected, | 93 void ExpectResponse(const std::string& expected, |
91 HttpNetworkTransaction& transaction) { | 94 HttpNetworkTransaction& transaction, |
| 95 bool async) { |
92 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); | 96 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); |
93 EXPECT_EQ(static_cast<int>(expected.size()), | 97 if (async) { |
94 transaction.Read(buffer.get(), expected.size(), | 98 EXPECT_EQ(ERR_IO_PENDING, transaction.Read(buffer.get(), expected.size(), |
95 callback_.callback())); | 99 callback_.callback())); |
| 100 data_vector_[0]->RunFor(1); |
| 101 EXPECT_EQ(static_cast<int>(expected.length()), callback_.WaitForResult()); |
| 102 } else { |
| 103 EXPECT_EQ(static_cast<int>(expected.size()), |
| 104 transaction.Read(buffer.get(), expected.size(), |
| 105 callback_.callback())); |
| 106 } |
96 std::string actual(buffer->data(), expected.size()); | 107 std::string actual(buffer->data(), expected.size()); |
97 EXPECT_THAT(actual, StrEq(expected)); | 108 EXPECT_THAT(actual, StrEq(expected)); |
98 EXPECT_EQ(OK, transaction.Read(buffer.get(), expected.size(), | 109 EXPECT_EQ(OK, transaction.Read(buffer.get(), expected.size(), |
99 callback_.callback())); | 110 callback_.callback())); |
100 } | 111 } |
101 | 112 |
102 void CompleteTwoRequests(int data_index, int stop_at_step) { | 113 void CompleteTwoRequests(int data_index, int stop_at_step) { |
103 scoped_ptr<HttpNetworkTransaction> one_transaction( | 114 scoped_ptr<HttpNetworkTransaction> one_transaction( |
104 new HttpNetworkTransaction(session_.get())); | 115 new HttpNetworkTransaction(session_.get())); |
105 TestCompletionCallback one_callback; | 116 TestCompletionCallback one_callback; |
(...skipping 17 matching lines...) Expand all Loading... |
123 data_vector_[data_index]->SetStop(stop_at_step); | 134 data_vector_[data_index]->SetStop(stop_at_step); |
124 data_vector_[data_index]->Run(); | 135 data_vector_[data_index]->Run(); |
125 EXPECT_EQ(8, one_read_callback.WaitForResult()); | 136 EXPECT_EQ(8, one_read_callback.WaitForResult()); |
126 data_vector_[data_index]->SetStop(10); | 137 data_vector_[data_index]->SetStop(10); |
127 std::string actual(buffer->data(), 8); | 138 std::string actual(buffer->data(), 8); |
128 EXPECT_THAT(actual, StrEq("one.html")); | 139 EXPECT_THAT(actual, StrEq("one.html")); |
129 EXPECT_EQ(OK, one_transaction->Read(buffer.get(), 8, | 140 EXPECT_EQ(OK, one_transaction->Read(buffer.get(), 8, |
130 one_read_callback.callback())); | 141 one_read_callback.callback())); |
131 | 142 |
132 EXPECT_EQ(OK, two_callback.WaitForResult()); | 143 EXPECT_EQ(OK, two_callback.WaitForResult()); |
133 ExpectResponse("two.html", two_transaction); | 144 ExpectResponse("two.html", two_transaction, false); |
134 } | 145 } |
135 | 146 |
136 void CompleteFourRequests() { | 147 void CompleteFourRequests() { |
137 scoped_ptr<HttpNetworkTransaction> one_transaction( | 148 scoped_ptr<HttpNetworkTransaction> one_transaction( |
138 new HttpNetworkTransaction(session_.get())); | 149 new HttpNetworkTransaction(session_.get())); |
139 TestCompletionCallback one_callback; | 150 TestCompletionCallback one_callback; |
140 EXPECT_EQ(ERR_IO_PENDING, | 151 EXPECT_EQ(ERR_IO_PENDING, |
141 one_transaction->Start(GetRequestInfo("one.html"), | 152 one_transaction->Start(GetRequestInfo("one.html"), |
142 one_callback.callback(), BoundNetLog())); | 153 one_callback.callback(), BoundNetLog())); |
143 EXPECT_EQ(OK, one_callback.WaitForResult()); | 154 EXPECT_EQ(OK, one_callback.WaitForResult()); |
(...skipping 10 matching lines...) Expand all Loading... |
154 three_transaction.Start(GetRequestInfo("three.html"), | 165 three_transaction.Start(GetRequestInfo("three.html"), |
155 three_callback.callback(), | 166 three_callback.callback(), |
156 BoundNetLog())); | 167 BoundNetLog())); |
157 | 168 |
158 HttpNetworkTransaction four_transaction(session_.get()); | 169 HttpNetworkTransaction four_transaction(session_.get()); |
159 TestCompletionCallback four_callback; | 170 TestCompletionCallback four_callback; |
160 EXPECT_EQ(ERR_IO_PENDING, | 171 EXPECT_EQ(ERR_IO_PENDING, |
161 four_transaction.Start(GetRequestInfo("four.html"), | 172 four_transaction.Start(GetRequestInfo("four.html"), |
162 four_callback.callback(), BoundNetLog())); | 173 four_callback.callback(), BoundNetLog())); |
163 | 174 |
164 ExpectResponse("one.html", *one_transaction.get()); | 175 ExpectResponse("one.html", *one_transaction.get(), false); |
165 EXPECT_EQ(OK, two_callback.WaitForResult()); | 176 EXPECT_EQ(OK, two_callback.WaitForResult()); |
166 ExpectResponse("two.html", two_transaction); | 177 ExpectResponse("two.html", two_transaction, false); |
167 EXPECT_EQ(OK, three_callback.WaitForResult()); | 178 EXPECT_EQ(OK, three_callback.WaitForResult()); |
168 ExpectResponse("three.html", three_transaction); | 179 ExpectResponse("three.html", three_transaction, false); |
169 | 180 |
170 one_transaction.reset(); | 181 one_transaction.reset(); |
171 EXPECT_EQ(OK, four_callback.WaitForResult()); | 182 EXPECT_EQ(OK, four_callback.WaitForResult()); |
172 ExpectResponse("four.html", four_transaction); | 183 ExpectResponse("four.html", four_transaction, false); |
173 } | 184 } |
174 | 185 |
175 DeterministicMockClientSocketFactory factory_; | 186 DeterministicMockClientSocketFactory factory_; |
176 ClientSocketPoolHistograms histograms_; | 187 ClientSocketPoolHistograms histograms_; |
177 MockTransportClientSocketPool pool_; | 188 MockTransportClientSocketPool pool_; |
178 std::vector<scoped_refptr<DeterministicSocketData> > data_vector_; | 189 std::vector<scoped_refptr<DeterministicSocketData> > data_vector_; |
179 TestCompletionCallback callback_; | 190 TestCompletionCallback callback_; |
180 ScopedVector<HttpRequestInfo> request_info_vector_; | 191 ScopedVector<HttpRequestInfo> request_info_vector_; |
181 bool default_pipelining_enabled_; | 192 bool default_pipelining_enabled_; |
182 | 193 |
(...skipping 18 matching lines...) Expand all Loading... |
201 MockRead(false, 2, "Content-Length: 9\r\n\r\n"), | 212 MockRead(false, 2, "Content-Length: 9\r\n\r\n"), |
202 MockRead(false, 3, "test.html"), | 213 MockRead(false, 3, "test.html"), |
203 }; | 214 }; |
204 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); | 215 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); |
205 | 216 |
206 HttpNetworkTransaction transaction(session_.get()); | 217 HttpNetworkTransaction transaction(session_.get()); |
207 EXPECT_EQ(ERR_IO_PENDING, | 218 EXPECT_EQ(ERR_IO_PENDING, |
208 transaction.Start(GetRequestInfo("test.html"), callback_.callback(), | 219 transaction.Start(GetRequestInfo("test.html"), callback_.callback(), |
209 BoundNetLog())); | 220 BoundNetLog())); |
210 EXPECT_EQ(OK, callback_.WaitForResult()); | 221 EXPECT_EQ(OK, callback_.WaitForResult()); |
211 ExpectResponse("test.html", transaction); | 222 ExpectResponse("test.html", transaction, false); |
212 } | 223 } |
213 | 224 |
214 TEST_F(HttpPipelinedNetworkTransactionTest, ReusePipeline) { | 225 TEST_F(HttpPipelinedNetworkTransactionTest, ReusePipeline) { |
215 Initialize(); | 226 Initialize(); |
216 | 227 |
217 MockWrite writes[] = { | 228 MockWrite writes[] = { |
218 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" | 229 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" |
219 "Host: localhost\r\n" | 230 "Host: localhost\r\n" |
220 "Connection: keep-alive\r\n\r\n"), | 231 "Connection: keep-alive\r\n\r\n"), |
221 MockWrite(false, 3, "GET /two.html HTTP/1.1\r\n" | 232 MockWrite(false, 3, "GET /two.html HTTP/1.1\r\n" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 HttpNetworkTransaction two_transaction(session_.get()); | 389 HttpNetworkTransaction two_transaction(session_.get()); |
379 TestCompletionCallback two_callback; | 390 TestCompletionCallback two_callback; |
380 EXPECT_EQ(ERR_IO_PENDING, | 391 EXPECT_EQ(ERR_IO_PENDING, |
381 two_transaction.Start(GetRequestInfo("two.html"), | 392 two_transaction.Start(GetRequestInfo("two.html"), |
382 two_callback.callback(), BoundNetLog())); | 393 two_callback.callback(), BoundNetLog())); |
383 | 394 |
384 scoped_refptr<IOBuffer> buffer(new IOBuffer(1)); | 395 scoped_refptr<IOBuffer> buffer(new IOBuffer(1)); |
385 EXPECT_EQ(ERR_FAILED, | 396 EXPECT_EQ(ERR_FAILED, |
386 one_transaction.Read(buffer.get(), 1, callback_.callback())); | 397 one_transaction.Read(buffer.get(), 1, callback_.callback())); |
387 EXPECT_EQ(OK, two_callback.WaitForResult()); | 398 EXPECT_EQ(OK, two_callback.WaitForResult()); |
388 ExpectResponse("two.html", two_transaction); | 399 ExpectResponse("two.html", two_transaction, false); |
389 } | 400 } |
390 | 401 |
391 TEST_F(HttpPipelinedNetworkTransactionTest, SendErrorEvictsToNewPipeline) { | 402 TEST_F(HttpPipelinedNetworkTransactionTest, SendErrorEvictsToNewPipeline) { |
392 Initialize(); | 403 Initialize(); |
393 | 404 |
394 MockWrite writes[] = { | 405 MockWrite writes[] = { |
395 MockWrite(true, ERR_FAILED, 0), | 406 MockWrite(true, ERR_FAILED, 0), |
396 }; | 407 }; |
397 AddExpectedConnection(NULL, 0, writes, arraysize(writes)); | 408 AddExpectedConnection(NULL, 0, writes, arraysize(writes)); |
398 | 409 |
(...skipping 18 matching lines...) Expand all Loading... |
417 HttpNetworkTransaction two_transaction(session_.get()); | 428 HttpNetworkTransaction two_transaction(session_.get()); |
418 TestCompletionCallback two_callback; | 429 TestCompletionCallback two_callback; |
419 EXPECT_EQ(ERR_IO_PENDING, | 430 EXPECT_EQ(ERR_IO_PENDING, |
420 two_transaction.Start(GetRequestInfo("two.html"), | 431 two_transaction.Start(GetRequestInfo("two.html"), |
421 two_callback.callback(), BoundNetLog())); | 432 two_callback.callback(), BoundNetLog())); |
422 | 433 |
423 data_vector_[0]->RunFor(1); | 434 data_vector_[0]->RunFor(1); |
424 EXPECT_EQ(ERR_FAILED, one_callback.WaitForResult()); | 435 EXPECT_EQ(ERR_FAILED, one_callback.WaitForResult()); |
425 | 436 |
426 EXPECT_EQ(OK, two_callback.WaitForResult()); | 437 EXPECT_EQ(OK, two_callback.WaitForResult()); |
427 ExpectResponse("two.html", two_transaction); | 438 ExpectResponse("two.html", two_transaction, false); |
428 } | 439 } |
429 | 440 |
430 TEST_F(HttpPipelinedNetworkTransactionTest, RedirectDrained) { | 441 TEST_F(HttpPipelinedNetworkTransactionTest, RedirectDrained) { |
431 Initialize(); | 442 Initialize(); |
432 | 443 |
433 MockWrite writes[] = { | 444 MockWrite writes[] = { |
434 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n" | 445 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n" |
435 "Host: localhost\r\n" | 446 "Host: localhost\r\n" |
436 "Connection: keep-alive\r\n\r\n"), | 447 "Connection: keep-alive\r\n\r\n"), |
437 MockWrite(false, 3, "GET /two.html HTTP/1.1\r\n" | 448 MockWrite(false, 3, "GET /two.html HTTP/1.1\r\n" |
(...skipping 22 matching lines...) Expand all Loading... |
460 TestCompletionCallback two_callback; | 471 TestCompletionCallback two_callback; |
461 EXPECT_EQ(ERR_IO_PENDING, | 472 EXPECT_EQ(ERR_IO_PENDING, |
462 two_transaction.Start(GetRequestInfo("two.html"), | 473 two_transaction.Start(GetRequestInfo("two.html"), |
463 two_callback.callback(), BoundNetLog())); | 474 two_callback.callback(), BoundNetLog())); |
464 | 475 |
465 one_transaction.reset(); | 476 one_transaction.reset(); |
466 data_vector_[0]->RunFor(2); | 477 data_vector_[0]->RunFor(2); |
467 data_vector_[0]->SetStop(10); | 478 data_vector_[0]->SetStop(10); |
468 | 479 |
469 EXPECT_EQ(OK, two_callback.WaitForResult()); | 480 EXPECT_EQ(OK, two_callback.WaitForResult()); |
470 ExpectResponse("two.html", two_transaction); | 481 ExpectResponse("two.html", two_transaction, false); |
471 } | 482 } |
472 | 483 |
473 TEST_F(HttpPipelinedNetworkTransactionTest, BasicHttpAuthentication) { | 484 TEST_F(HttpPipelinedNetworkTransactionTest, BasicHttpAuthentication) { |
474 Initialize(); | 485 Initialize(); |
475 | 486 |
476 MockWrite writes[] = { | 487 MockWrite writes[] = { |
477 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" | 488 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" |
478 "Host: localhost\r\n" | 489 "Host: localhost\r\n" |
479 "Connection: keep-alive\r\n\r\n"), | 490 "Connection: keep-alive\r\n\r\n"), |
480 MockWrite(false, 5, "GET /one.html HTTP/1.1\r\n" | 491 MockWrite(false, 5, "GET /one.html HTTP/1.1\r\n" |
(...skipping 25 matching lines...) Expand all Loading... |
506 | 517 |
507 HttpNetworkTransaction transaction(session_.get()); | 518 HttpNetworkTransaction transaction(session_.get()); |
508 EXPECT_EQ(ERR_IO_PENDING, | 519 EXPECT_EQ(ERR_IO_PENDING, |
509 transaction.Start(GetRequestInfo("one.html"), callback_.callback(), | 520 transaction.Start(GetRequestInfo("one.html"), callback_.callback(), |
510 BoundNetLog())); | 521 BoundNetLog())); |
511 EXPECT_EQ(OK, callback_.WaitForResult()); | 522 EXPECT_EQ(OK, callback_.WaitForResult()); |
512 | 523 |
513 AuthCredentials credentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")); | 524 AuthCredentials credentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")); |
514 EXPECT_EQ(OK, transaction.RestartWithAuth(credentials, callback_.callback())); | 525 EXPECT_EQ(OK, transaction.RestartWithAuth(credentials, callback_.callback())); |
515 | 526 |
516 ExpectResponse("one.html", transaction); | 527 ExpectResponse("one.html", transaction, false); |
517 } | 528 } |
518 | 529 |
519 TEST_F(HttpPipelinedNetworkTransactionTest, OldVersionDisablesPipelining) { | 530 TEST_F(HttpPipelinedNetworkTransactionTest, OldVersionDisablesPipelining) { |
520 Initialize(); | 531 Initialize(); |
521 | 532 |
522 MockWrite writes[] = { | 533 MockWrite writes[] = { |
523 MockWrite(false, 0, "GET /pipelined.html HTTP/1.1\r\n" | 534 MockWrite(false, 0, "GET /pipelined.html HTTP/1.1\r\n" |
524 "Host: localhost\r\n" | 535 "Host: localhost\r\n" |
525 "Connection: keep-alive\r\n\r\n"), | 536 "Connection: keep-alive\r\n\r\n"), |
526 }; | 537 }; |
(...skipping 29 matching lines...) Expand all Loading... |
556 MockRead(false, OK, 4), | 567 MockRead(false, OK, 4), |
557 }; | 568 }; |
558 AddExpectedConnection(reads3, arraysize(reads3), writes3, arraysize(writes3)); | 569 AddExpectedConnection(reads3, arraysize(reads3), writes3, arraysize(writes3)); |
559 | 570 |
560 HttpNetworkTransaction one_transaction(session_.get()); | 571 HttpNetworkTransaction one_transaction(session_.get()); |
561 TestCompletionCallback one_callback; | 572 TestCompletionCallback one_callback; |
562 EXPECT_EQ(ERR_IO_PENDING, | 573 EXPECT_EQ(ERR_IO_PENDING, |
563 one_transaction.Start(GetRequestInfo("pipelined.html"), | 574 one_transaction.Start(GetRequestInfo("pipelined.html"), |
564 one_callback.callback(), BoundNetLog())); | 575 one_callback.callback(), BoundNetLog())); |
565 EXPECT_EQ(OK, one_callback.WaitForResult()); | 576 EXPECT_EQ(OK, one_callback.WaitForResult()); |
566 ExpectResponse("pipelined.html", one_transaction); | 577 ExpectResponse("pipelined.html", one_transaction, false); |
567 | 578 |
568 CompleteTwoRequests(1, 4); | 579 CompleteTwoRequests(1, 4); |
569 } | 580 } |
570 | 581 |
571 TEST_F(HttpPipelinedNetworkTransactionTest, PipelinesImmediatelyIfKnownGood) { | 582 TEST_F(HttpPipelinedNetworkTransactionTest, PipelinesImmediatelyIfKnownGood) { |
572 // The first request gets us an HTTP/1.1. The next 3 test pipelining. When the | 583 // The first request gets us an HTTP/1.1. The next 3 test pipelining. When the |
573 // 3rd request completes, we know pipelining is safe. After the first 4 | 584 // 3rd request completes, we know pipelining is safe. After the first 4 |
574 // complete, the 5th and 6th should then be immediately sent pipelined on a | 585 // complete, the 5th and 6th should then be immediately sent pipelined on a |
575 // new HttpPipelinedConnection. | 586 // new HttpPipelinedConnection. |
576 int old_max_sockets = ClientSocketPoolManager::max_sockets_per_group(); | 587 int old_max_sockets = ClientSocketPoolManager::max_sockets_per_group(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 HttpNetworkTransaction second_two_transaction(session_.get()); | 643 HttpNetworkTransaction second_two_transaction(session_.get()); |
633 TestCompletionCallback second_two_callback; | 644 TestCompletionCallback second_two_callback; |
634 EXPECT_EQ(ERR_IO_PENDING, | 645 EXPECT_EQ(ERR_IO_PENDING, |
635 second_two_transaction.Start( | 646 second_two_transaction.Start( |
636 GetRequestInfo("second-pipeline-two.html"), | 647 GetRequestInfo("second-pipeline-two.html"), |
637 second_two_callback.callback(), BoundNetLog())); | 648 second_two_callback.callback(), BoundNetLog())); |
638 | 649 |
639 data_vector_[0]->RunFor(3); | 650 data_vector_[0]->RunFor(3); |
640 EXPECT_EQ(OK, second_one_callback.WaitForResult()); | 651 EXPECT_EQ(OK, second_one_callback.WaitForResult()); |
641 data_vector_[0]->StopAfter(100); | 652 data_vector_[0]->StopAfter(100); |
642 ExpectResponse("second-pipeline-one.html", second_one_transaction); | 653 ExpectResponse("second-pipeline-one.html", second_one_transaction, false); |
643 EXPECT_EQ(OK, second_two_callback.WaitForResult()); | 654 EXPECT_EQ(OK, second_two_callback.WaitForResult()); |
644 ExpectResponse("second-pipeline-two.html", second_two_transaction); | 655 ExpectResponse("second-pipeline-two.html", second_two_transaction, false); |
645 | 656 |
646 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets); | 657 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets); |
647 } | 658 } |
648 | 659 |
649 class DataRunnerObserver : public MessageLoop::TaskObserver { | 660 class DataRunnerObserver : public MessageLoop::TaskObserver { |
650 public: | 661 public: |
651 DataRunnerObserver(DeterministicSocketData* data, int run_before_task) | 662 DataRunnerObserver(DeterministicSocketData* data, int run_before_task) |
652 : data_(data), | 663 : data_(data), |
653 run_before_task_(run_before_task), | 664 run_before_task_(run_before_task), |
654 current_task_(0) { } | 665 current_task_(0) { } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 // We need to make sure that the response that triggers OnPipelineFeedback(OK) | 738 // We need to make sure that the response that triggers OnPipelineFeedback(OK) |
728 // is called in between when task #3 is scheduled and when it runs. The | 739 // is called in between when task #3 is scheduled and when it runs. The |
729 // DataRunnerObserver does that. | 740 // DataRunnerObserver does that. |
730 DataRunnerObserver observer(data_vector_[0].get(), 3); | 741 DataRunnerObserver observer(data_vector_[0].get(), 3); |
731 MessageLoop::current()->AddTaskObserver(&observer); | 742 MessageLoop::current()->AddTaskObserver(&observer); |
732 data_vector_[0]->SetStop(4); | 743 data_vector_[0]->SetStop(4); |
733 MessageLoop::current()->RunAllPending(); | 744 MessageLoop::current()->RunAllPending(); |
734 data_vector_[0]->SetStop(10); | 745 data_vector_[0]->SetStop(10); |
735 | 746 |
736 EXPECT_EQ(OK, one_callback.WaitForResult()); | 747 EXPECT_EQ(OK, one_callback.WaitForResult()); |
737 ExpectResponse("one.html", one_transaction); | 748 ExpectResponse("one.html", one_transaction, false); |
738 EXPECT_EQ(OK, two_callback.WaitForResult()); | 749 EXPECT_EQ(OK, two_callback.WaitForResult()); |
739 ExpectResponse("two.html", two_transaction); | 750 ExpectResponse("two.html", two_transaction, false); |
| 751 } |
| 752 |
| 753 TEST_F(HttpPipelinedNetworkTransactionTest, ForcedPipelineSharesConnection) { |
| 754 Initialize(); |
| 755 |
| 756 MockWrite writes[] = { |
| 757 MockWrite(true, 0, "GET /one.html HTTP/1.1\r\n" |
| 758 "Host: localhost\r\n" |
| 759 "Connection: keep-alive\r\n\r\n" |
| 760 "GET /two.html HTTP/1.1\r\n" |
| 761 "Host: localhost\r\n" |
| 762 "Connection: keep-alive\r\n\r\n"), |
| 763 }; |
| 764 MockRead reads[] = { |
| 765 MockRead(true, 1, "HTTP/1.1 200 OK\r\n"), |
| 766 MockRead(true, 2, "Content-Length: 8\r\n\r\n"), |
| 767 MockRead(true, 3, "one.html"), |
| 768 MockRead(true, 4, "HTTP/1.1 200 OK\r\n"), |
| 769 MockRead(true, 5, "Content-Length: 8\r\n\r\n"), |
| 770 MockRead(true, 6, "two.html"), |
| 771 }; |
| 772 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); |
| 773 |
| 774 scoped_ptr<HttpNetworkTransaction> one_transaction( |
| 775 new HttpNetworkTransaction(session_.get())); |
| 776 TestCompletionCallback one_callback; |
| 777 HttpRequestInfo* one_info = GetRequestInfo("one.html"); |
| 778 one_info->load_flags |= LOAD_FORCE_HTTP_PIPELINING; |
| 779 EXPECT_EQ(ERR_IO_PENDING, |
| 780 one_transaction->Start(one_info, |
| 781 one_callback.callback(), BoundNetLog())); |
| 782 |
| 783 HttpNetworkTransaction two_transaction(session_.get()); |
| 784 TestCompletionCallback two_callback; |
| 785 HttpRequestInfo* two_info = GetRequestInfo("two.html"); |
| 786 two_info->load_flags |= LOAD_FORCE_HTTP_PIPELINING; |
| 787 EXPECT_EQ(ERR_IO_PENDING, |
| 788 two_transaction.Start(two_info, |
| 789 two_callback.callback(), BoundNetLog())); |
| 790 |
| 791 data_vector_[0]->RunFor(3); // Send + 2 lines of headers. |
| 792 EXPECT_EQ(OK, one_callback.WaitForResult()); |
| 793 ExpectResponse("one.html", *one_transaction.get(), true); |
| 794 one_transaction.reset(); |
| 795 |
| 796 data_vector_[0]->RunFor(2); // 2 lines of headers. |
| 797 EXPECT_EQ(OK, two_callback.WaitForResult()); |
| 798 ExpectResponse("two.html", two_transaction, true); |
| 799 } |
| 800 |
| 801 TEST_F(HttpPipelinedNetworkTransactionTest, |
| 802 ForcedPipelineConnectionErrorFailsBoth) { |
| 803 Initialize(); |
| 804 |
| 805 scoped_refptr<DeterministicSocketData> data( |
| 806 new DeterministicSocketData(NULL, 0, NULL, 0)); |
| 807 data->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); |
| 808 factory_.AddSocketDataProvider(data); |
| 809 |
| 810 scoped_ptr<HttpNetworkTransaction> one_transaction( |
| 811 new HttpNetworkTransaction(session_.get())); |
| 812 TestCompletionCallback one_callback; |
| 813 HttpRequestInfo* one_info = GetRequestInfo("one.html"); |
| 814 one_info->load_flags |= LOAD_FORCE_HTTP_PIPELINING; |
| 815 EXPECT_EQ(ERR_IO_PENDING, |
| 816 one_transaction->Start(one_info, |
| 817 one_callback.callback(), BoundNetLog())); |
| 818 |
| 819 HttpNetworkTransaction two_transaction(session_.get()); |
| 820 TestCompletionCallback two_callback; |
| 821 HttpRequestInfo* two_info = GetRequestInfo("two.html"); |
| 822 two_info->load_flags |= LOAD_FORCE_HTTP_PIPELINING; |
| 823 EXPECT_EQ(ERR_IO_PENDING, |
| 824 two_transaction.Start(two_info, |
| 825 two_callback.callback(), BoundNetLog())); |
| 826 |
| 827 data->Run(); |
| 828 EXPECT_EQ(ERR_FAILED, one_callback.WaitForResult()); |
| 829 EXPECT_EQ(ERR_FAILED, two_callback.WaitForResult()); |
| 830 } |
| 831 |
| 832 TEST_F(HttpPipelinedNetworkTransactionTest, ForcedPipelineEvictionIsFatal) { |
| 833 Initialize(); |
| 834 |
| 835 MockWrite writes[] = { |
| 836 MockWrite(true, 0, "GET /one.html HTTP/1.1\r\n" |
| 837 "Host: localhost\r\n" |
| 838 "Connection: keep-alive\r\n\r\n" |
| 839 "GET /two.html HTTP/1.1\r\n" |
| 840 "Host: localhost\r\n" |
| 841 "Connection: keep-alive\r\n\r\n"), |
| 842 }; |
| 843 MockRead reads[] = { |
| 844 MockRead(true, ERR_FAILED, 1), |
| 845 }; |
| 846 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); |
| 847 |
| 848 scoped_ptr<HttpNetworkTransaction> one_transaction( |
| 849 new HttpNetworkTransaction(session_.get())); |
| 850 TestCompletionCallback one_callback; |
| 851 HttpRequestInfo* one_info = GetRequestInfo("one.html"); |
| 852 one_info->load_flags |= LOAD_FORCE_HTTP_PIPELINING; |
| 853 EXPECT_EQ(ERR_IO_PENDING, |
| 854 one_transaction->Start(one_info, |
| 855 one_callback.callback(), BoundNetLog())); |
| 856 |
| 857 HttpNetworkTransaction two_transaction(session_.get()); |
| 858 TestCompletionCallback two_callback; |
| 859 HttpRequestInfo* two_info = GetRequestInfo("two.html"); |
| 860 two_info->load_flags |= LOAD_FORCE_HTTP_PIPELINING; |
| 861 EXPECT_EQ(ERR_IO_PENDING, |
| 862 two_transaction.Start(two_info, |
| 863 two_callback.callback(), BoundNetLog())); |
| 864 |
| 865 data_vector_[0]->RunFor(2); |
| 866 EXPECT_EQ(ERR_FAILED, one_callback.WaitForResult()); |
| 867 one_transaction.reset(); |
| 868 EXPECT_EQ(ERR_PIPELINE_EVICTION, two_callback.WaitForResult()); |
740 } | 869 } |
741 | 870 |
742 } // anonymous namespace | 871 } // anonymous namespace |
743 | 872 |
744 } // namespace net | 873 } // namespace net |
OLD | NEW |