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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 virtual void SetUp() OVERRIDE { | 44 virtual void SetUp() OVERRIDE { |
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() { |
mmenke
2012/02/23 18:54:58
Random comment, no action needed:
Is there a reas
James Simonsen
2012/02/23 23:49:46
You've asked that before. It's for the test where
mmenke
2012/02/24 00:20:14
Thanks. That means I won't have to ask it a third
| |
55 proxy_service_.reset(ProxyService::CreateDirect()); | 55 proxy_service_.reset(ProxyService::CreateDirect()); |
56 ssl_config_ = new SSLConfigServiceDefaults; | 56 ssl_config_ = new SSLConfigServiceDefaults; |
57 auth_handler_factory_.reset(new HttpAuthHandlerMock::Factory()); | 57 auth_handler_factory_.reset(new HttpAuthHandlerMock::Factory()); |
58 | 58 |
59 HttpNetworkSession::Params session_params; | 59 HttpNetworkSession::Params session_params; |
60 session_params.client_socket_factory = &factory_; | 60 session_params.client_socket_factory = &factory_; |
61 session_params.proxy_service = proxy_service_.get(); | 61 session_params.proxy_service = proxy_service_.get(); |
62 session_params.host_resolver = &mock_resolver_; | 62 session_params.host_resolver = &mock_resolver_; |
63 session_params.ssl_config_service = ssl_config_.get(); | 63 session_params.ssl_config_service = ssl_config_.get(); |
64 session_params.http_auth_handler_factory = auth_handler_factory_.get(); | 64 session_params.http_auth_handler_factory = auth_handler_factory_.get(); |
65 session_params.http_server_properties = &http_server_properties_; | 65 session_params.http_server_properties = &http_server_properties_; |
66 session_ = new HttpNetworkSession(session_params); | 66 session_ = new HttpNetworkSession(session_params); |
67 } | 67 } |
68 | 68 |
69 void AddExpectedConnection(MockRead* reads, size_t reads_count, | 69 void AddExpectedConnection(MockRead* reads, size_t reads_count, |
70 MockWrite* writes, size_t writes_count) { | 70 MockWrite* writes, size_t writes_count) { |
71 DeterministicSocketData* data = new DeterministicSocketData( | 71 DeterministicSocketData* data = new DeterministicSocketData( |
72 reads, reads_count, writes, writes_count); | 72 reads, reads_count, writes, writes_count); |
73 data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); | 73 data->set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
74 if (reads_count || writes_count) { | 74 if (reads_count || writes_count) { |
75 data->StopAfter(reads_count + writes_count); | 75 data->StopAfter(reads_count + writes_count); |
76 } | 76 } |
77 factory_.AddSocketDataProvider(data); | 77 factory_.AddSocketDataProvider(data); |
78 data_vector_.push_back(data); | 78 data_vector_.push_back(data); |
79 } | 79 } |
80 | 80 |
81 const HttpRequestInfo* GetRequestInfo(const char* filename) { | 81 HttpRequestInfo* GetRequestInfo(const char* filename) { |
82 std::string url = StringPrintf("http://localhost/%s", filename); | 82 std::string url = StringPrintf("http://localhost/%s", filename); |
83 HttpRequestInfo* request_info = new HttpRequestInfo; | 83 HttpRequestInfo* request_info = new HttpRequestInfo; |
84 request_info->url = GURL(url); | 84 request_info->url = GURL(url); |
85 request_info->method = "GET"; | 85 request_info->method = "GET"; |
86 request_info_vector_.push_back(request_info); | 86 request_info_vector_.push_back(request_info); |
87 return request_info; | 87 return request_info; |
88 } | 88 } |
89 | 89 |
90 void ExpectResponse(const std::string& expected, | 90 void ExpectResponse(const std::string& expected, |
91 HttpNetworkTransaction& transaction) { | 91 HttpNetworkTransaction& transaction, |
92 bool async) { | |
92 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); | 93 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); |
93 EXPECT_EQ(static_cast<int>(expected.size()), | 94 if (async) { |
94 transaction.Read(buffer.get(), expected.size(), | 95 EXPECT_EQ(ERR_IO_PENDING, transaction.Read(buffer.get(), expected.size(), |
95 callback_.callback())); | 96 callback_.callback())); |
97 data_vector_[0]->RunFor(1); | |
98 EXPECT_EQ(static_cast<int>(expected.length()), callback_.WaitForResult()); | |
99 } else { | |
100 EXPECT_EQ(static_cast<int>(expected.size()), | |
101 transaction.Read(buffer.get(), expected.size(), | |
102 callback_.callback())); | |
103 } | |
96 std::string actual(buffer->data(), expected.size()); | 104 std::string actual(buffer->data(), expected.size()); |
97 EXPECT_THAT(actual, StrEq(expected)); | 105 EXPECT_THAT(actual, StrEq(expected)); |
98 EXPECT_EQ(OK, transaction.Read(buffer.get(), expected.size(), | 106 EXPECT_EQ(OK, transaction.Read(buffer.get(), expected.size(), |
99 callback_.callback())); | 107 callback_.callback())); |
100 } | 108 } |
101 | 109 |
102 void CompleteTwoRequests(int data_index, int stop_at_step) { | 110 void CompleteTwoRequests(int data_index, int stop_at_step) { |
103 scoped_ptr<HttpNetworkTransaction> one_transaction( | 111 scoped_ptr<HttpNetworkTransaction> one_transaction( |
104 new HttpNetworkTransaction(session_.get())); | 112 new HttpNetworkTransaction(session_.get())); |
105 TestCompletionCallback one_callback; | 113 TestCompletionCallback one_callback; |
(...skipping 17 matching lines...) Expand all Loading... | |
123 data_vector_[data_index]->SetStop(stop_at_step); | 131 data_vector_[data_index]->SetStop(stop_at_step); |
124 data_vector_[data_index]->Run(); | 132 data_vector_[data_index]->Run(); |
125 EXPECT_EQ(8, one_read_callback.WaitForResult()); | 133 EXPECT_EQ(8, one_read_callback.WaitForResult()); |
126 data_vector_[data_index]->SetStop(10); | 134 data_vector_[data_index]->SetStop(10); |
127 std::string actual(buffer->data(), 8); | 135 std::string actual(buffer->data(), 8); |
128 EXPECT_THAT(actual, StrEq("one.html")); | 136 EXPECT_THAT(actual, StrEq("one.html")); |
129 EXPECT_EQ(OK, one_transaction->Read(buffer.get(), 8, | 137 EXPECT_EQ(OK, one_transaction->Read(buffer.get(), 8, |
130 one_read_callback.callback())); | 138 one_read_callback.callback())); |
131 | 139 |
132 EXPECT_EQ(OK, two_callback.WaitForResult()); | 140 EXPECT_EQ(OK, two_callback.WaitForResult()); |
133 ExpectResponse("two.html", two_transaction); | 141 ExpectResponse("two.html", two_transaction, false); |
134 } | 142 } |
135 | 143 |
136 void CompleteFourRequests() { | 144 void CompleteFourRequests() { |
137 scoped_ptr<HttpNetworkTransaction> one_transaction( | 145 scoped_ptr<HttpNetworkTransaction> one_transaction( |
138 new HttpNetworkTransaction(session_.get())); | 146 new HttpNetworkTransaction(session_.get())); |
139 TestCompletionCallback one_callback; | 147 TestCompletionCallback one_callback; |
140 EXPECT_EQ(ERR_IO_PENDING, | 148 EXPECT_EQ(ERR_IO_PENDING, |
141 one_transaction->Start(GetRequestInfo("one.html"), | 149 one_transaction->Start(GetRequestInfo("one.html"), |
142 one_callback.callback(), BoundNetLog())); | 150 one_callback.callback(), BoundNetLog())); |
143 EXPECT_EQ(OK, one_callback.WaitForResult()); | 151 EXPECT_EQ(OK, one_callback.WaitForResult()); |
(...skipping 10 matching lines...) Expand all Loading... | |
154 three_transaction.Start(GetRequestInfo("three.html"), | 162 three_transaction.Start(GetRequestInfo("three.html"), |
155 three_callback.callback(), | 163 three_callback.callback(), |
156 BoundNetLog())); | 164 BoundNetLog())); |
157 | 165 |
158 HttpNetworkTransaction four_transaction(session_.get()); | 166 HttpNetworkTransaction four_transaction(session_.get()); |
159 TestCompletionCallback four_callback; | 167 TestCompletionCallback four_callback; |
160 EXPECT_EQ(ERR_IO_PENDING, | 168 EXPECT_EQ(ERR_IO_PENDING, |
161 four_transaction.Start(GetRequestInfo("four.html"), | 169 four_transaction.Start(GetRequestInfo("four.html"), |
162 four_callback.callback(), BoundNetLog())); | 170 four_callback.callback(), BoundNetLog())); |
163 | 171 |
164 ExpectResponse("one.html", *one_transaction.get()); | 172 ExpectResponse("one.html", *one_transaction.get(), false); |
165 EXPECT_EQ(OK, two_callback.WaitForResult()); | 173 EXPECT_EQ(OK, two_callback.WaitForResult()); |
166 ExpectResponse("two.html", two_transaction); | 174 ExpectResponse("two.html", two_transaction, false); |
167 EXPECT_EQ(OK, three_callback.WaitForResult()); | 175 EXPECT_EQ(OK, three_callback.WaitForResult()); |
168 ExpectResponse("three.html", three_transaction); | 176 ExpectResponse("three.html", three_transaction, false); |
169 | 177 |
170 one_transaction.reset(); | 178 one_transaction.reset(); |
171 EXPECT_EQ(OK, four_callback.WaitForResult()); | 179 EXPECT_EQ(OK, four_callback.WaitForResult()); |
172 ExpectResponse("four.html", four_transaction); | 180 ExpectResponse("four.html", four_transaction, false); |
173 } | 181 } |
174 | 182 |
175 DeterministicMockClientSocketFactory factory_; | 183 DeterministicMockClientSocketFactory factory_; |
176 ClientSocketPoolHistograms histograms_; | 184 ClientSocketPoolHistograms histograms_; |
177 MockTransportClientSocketPool pool_; | 185 MockTransportClientSocketPool pool_; |
178 std::vector<scoped_refptr<DeterministicSocketData> > data_vector_; | 186 std::vector<scoped_refptr<DeterministicSocketData> > data_vector_; |
179 TestCompletionCallback callback_; | 187 TestCompletionCallback callback_; |
180 ScopedVector<HttpRequestInfo> request_info_vector_; | 188 ScopedVector<HttpRequestInfo> request_info_vector_; |
181 bool default_pipelining_enabled_; | 189 bool default_pipelining_enabled_; |
182 | 190 |
(...skipping 18 matching lines...) Expand all Loading... | |
201 MockRead(false, 2, "Content-Length: 9\r\n\r\n"), | 209 MockRead(false, 2, "Content-Length: 9\r\n\r\n"), |
202 MockRead(false, 3, "test.html"), | 210 MockRead(false, 3, "test.html"), |
203 }; | 211 }; |
204 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); | 212 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); |
205 | 213 |
206 HttpNetworkTransaction transaction(session_.get()); | 214 HttpNetworkTransaction transaction(session_.get()); |
207 EXPECT_EQ(ERR_IO_PENDING, | 215 EXPECT_EQ(ERR_IO_PENDING, |
208 transaction.Start(GetRequestInfo("test.html"), callback_.callback(), | 216 transaction.Start(GetRequestInfo("test.html"), callback_.callback(), |
209 BoundNetLog())); | 217 BoundNetLog())); |
210 EXPECT_EQ(OK, callback_.WaitForResult()); | 218 EXPECT_EQ(OK, callback_.WaitForResult()); |
211 ExpectResponse("test.html", transaction); | 219 ExpectResponse("test.html", transaction, false); |
212 } | 220 } |
213 | 221 |
214 TEST_F(HttpPipelinedNetworkTransactionTest, ReusePipeline) { | 222 TEST_F(HttpPipelinedNetworkTransactionTest, ReusePipeline) { |
215 Initialize(); | 223 Initialize(); |
216 | 224 |
217 MockWrite writes[] = { | 225 MockWrite writes[] = { |
218 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" | 226 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" |
219 "Host: localhost\r\n" | 227 "Host: localhost\r\n" |
220 "Connection: keep-alive\r\n\r\n"), | 228 "Connection: keep-alive\r\n\r\n"), |
221 MockWrite(false, 3, "GET /two.html HTTP/1.1\r\n" | 229 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()); | 386 HttpNetworkTransaction two_transaction(session_.get()); |
379 TestCompletionCallback two_callback; | 387 TestCompletionCallback two_callback; |
380 EXPECT_EQ(ERR_IO_PENDING, | 388 EXPECT_EQ(ERR_IO_PENDING, |
381 two_transaction.Start(GetRequestInfo("two.html"), | 389 two_transaction.Start(GetRequestInfo("two.html"), |
382 two_callback.callback(), BoundNetLog())); | 390 two_callback.callback(), BoundNetLog())); |
383 | 391 |
384 scoped_refptr<IOBuffer> buffer(new IOBuffer(1)); | 392 scoped_refptr<IOBuffer> buffer(new IOBuffer(1)); |
385 EXPECT_EQ(ERR_FAILED, | 393 EXPECT_EQ(ERR_FAILED, |
386 one_transaction.Read(buffer.get(), 1, callback_.callback())); | 394 one_transaction.Read(buffer.get(), 1, callback_.callback())); |
387 EXPECT_EQ(OK, two_callback.WaitForResult()); | 395 EXPECT_EQ(OK, two_callback.WaitForResult()); |
388 ExpectResponse("two.html", two_transaction); | 396 ExpectResponse("two.html", two_transaction, false); |
389 } | 397 } |
390 | 398 |
391 TEST_F(HttpPipelinedNetworkTransactionTest, SendErrorEvictsToNewPipeline) { | 399 TEST_F(HttpPipelinedNetworkTransactionTest, SendErrorEvictsToNewPipeline) { |
392 Initialize(); | 400 Initialize(); |
393 | 401 |
394 MockWrite writes[] = { | 402 MockWrite writes[] = { |
395 MockWrite(true, ERR_FAILED, 0), | 403 MockWrite(true, ERR_FAILED, 0), |
396 }; | 404 }; |
397 AddExpectedConnection(NULL, 0, writes, arraysize(writes)); | 405 AddExpectedConnection(NULL, 0, writes, arraysize(writes)); |
398 | 406 |
(...skipping 18 matching lines...) Expand all Loading... | |
417 HttpNetworkTransaction two_transaction(session_.get()); | 425 HttpNetworkTransaction two_transaction(session_.get()); |
418 TestCompletionCallback two_callback; | 426 TestCompletionCallback two_callback; |
419 EXPECT_EQ(ERR_IO_PENDING, | 427 EXPECT_EQ(ERR_IO_PENDING, |
420 two_transaction.Start(GetRequestInfo("two.html"), | 428 two_transaction.Start(GetRequestInfo("two.html"), |
421 two_callback.callback(), BoundNetLog())); | 429 two_callback.callback(), BoundNetLog())); |
422 | 430 |
423 data_vector_[0]->RunFor(1); | 431 data_vector_[0]->RunFor(1); |
424 EXPECT_EQ(ERR_FAILED, one_callback.WaitForResult()); | 432 EXPECT_EQ(ERR_FAILED, one_callback.WaitForResult()); |
425 | 433 |
426 EXPECT_EQ(OK, two_callback.WaitForResult()); | 434 EXPECT_EQ(OK, two_callback.WaitForResult()); |
427 ExpectResponse("two.html", two_transaction); | 435 ExpectResponse("two.html", two_transaction, false); |
428 } | 436 } |
429 | 437 |
430 TEST_F(HttpPipelinedNetworkTransactionTest, RedirectDrained) { | 438 TEST_F(HttpPipelinedNetworkTransactionTest, RedirectDrained) { |
431 Initialize(); | 439 Initialize(); |
432 | 440 |
433 MockWrite writes[] = { | 441 MockWrite writes[] = { |
434 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n" | 442 MockWrite(false, 0, "GET /redirect.html HTTP/1.1\r\n" |
435 "Host: localhost\r\n" | 443 "Host: localhost\r\n" |
436 "Connection: keep-alive\r\n\r\n"), | 444 "Connection: keep-alive\r\n\r\n"), |
437 MockWrite(false, 3, "GET /two.html HTTP/1.1\r\n" | 445 MockWrite(false, 3, "GET /two.html HTTP/1.1\r\n" |
(...skipping 22 matching lines...) Expand all Loading... | |
460 TestCompletionCallback two_callback; | 468 TestCompletionCallback two_callback; |
461 EXPECT_EQ(ERR_IO_PENDING, | 469 EXPECT_EQ(ERR_IO_PENDING, |
462 two_transaction.Start(GetRequestInfo("two.html"), | 470 two_transaction.Start(GetRequestInfo("two.html"), |
463 two_callback.callback(), BoundNetLog())); | 471 two_callback.callback(), BoundNetLog())); |
464 | 472 |
465 one_transaction.reset(); | 473 one_transaction.reset(); |
466 data_vector_[0]->RunFor(2); | 474 data_vector_[0]->RunFor(2); |
467 data_vector_[0]->SetStop(10); | 475 data_vector_[0]->SetStop(10); |
468 | 476 |
469 EXPECT_EQ(OK, two_callback.WaitForResult()); | 477 EXPECT_EQ(OK, two_callback.WaitForResult()); |
470 ExpectResponse("two.html", two_transaction); | 478 ExpectResponse("two.html", two_transaction, false); |
471 } | 479 } |
472 | 480 |
473 TEST_F(HttpPipelinedNetworkTransactionTest, BasicHttpAuthentication) { | 481 TEST_F(HttpPipelinedNetworkTransactionTest, BasicHttpAuthentication) { |
474 Initialize(); | 482 Initialize(); |
475 | 483 |
476 MockWrite writes[] = { | 484 MockWrite writes[] = { |
477 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" | 485 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" |
478 "Host: localhost\r\n" | 486 "Host: localhost\r\n" |
479 "Connection: keep-alive\r\n\r\n"), | 487 "Connection: keep-alive\r\n\r\n"), |
480 MockWrite(false, 5, "GET /one.html HTTP/1.1\r\n" | 488 MockWrite(false, 5, "GET /one.html HTTP/1.1\r\n" |
(...skipping 25 matching lines...) Expand all Loading... | |
506 | 514 |
507 HttpNetworkTransaction transaction(session_.get()); | 515 HttpNetworkTransaction transaction(session_.get()); |
508 EXPECT_EQ(ERR_IO_PENDING, | 516 EXPECT_EQ(ERR_IO_PENDING, |
509 transaction.Start(GetRequestInfo("one.html"), callback_.callback(), | 517 transaction.Start(GetRequestInfo("one.html"), callback_.callback(), |
510 BoundNetLog())); | 518 BoundNetLog())); |
511 EXPECT_EQ(OK, callback_.WaitForResult()); | 519 EXPECT_EQ(OK, callback_.WaitForResult()); |
512 | 520 |
513 AuthCredentials credentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")); | 521 AuthCredentials credentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")); |
514 EXPECT_EQ(OK, transaction.RestartWithAuth(credentials, callback_.callback())); | 522 EXPECT_EQ(OK, transaction.RestartWithAuth(credentials, callback_.callback())); |
515 | 523 |
516 ExpectResponse("one.html", transaction); | 524 ExpectResponse("one.html", transaction, false); |
517 } | 525 } |
518 | 526 |
519 TEST_F(HttpPipelinedNetworkTransactionTest, OldVersionDisablesPipelining) { | 527 TEST_F(HttpPipelinedNetworkTransactionTest, OldVersionDisablesPipelining) { |
520 Initialize(); | 528 Initialize(); |
521 | 529 |
522 MockWrite writes[] = { | 530 MockWrite writes[] = { |
523 MockWrite(false, 0, "GET /pipelined.html HTTP/1.1\r\n" | 531 MockWrite(false, 0, "GET /pipelined.html HTTP/1.1\r\n" |
524 "Host: localhost\r\n" | 532 "Host: localhost\r\n" |
525 "Connection: keep-alive\r\n\r\n"), | 533 "Connection: keep-alive\r\n\r\n"), |
526 }; | 534 }; |
(...skipping 29 matching lines...) Expand all Loading... | |
556 MockRead(false, OK, 4), | 564 MockRead(false, OK, 4), |
557 }; | 565 }; |
558 AddExpectedConnection(reads3, arraysize(reads3), writes3, arraysize(writes3)); | 566 AddExpectedConnection(reads3, arraysize(reads3), writes3, arraysize(writes3)); |
559 | 567 |
560 HttpNetworkTransaction one_transaction(session_.get()); | 568 HttpNetworkTransaction one_transaction(session_.get()); |
561 TestCompletionCallback one_callback; | 569 TestCompletionCallback one_callback; |
562 EXPECT_EQ(ERR_IO_PENDING, | 570 EXPECT_EQ(ERR_IO_PENDING, |
563 one_transaction.Start(GetRequestInfo("pipelined.html"), | 571 one_transaction.Start(GetRequestInfo("pipelined.html"), |
564 one_callback.callback(), BoundNetLog())); | 572 one_callback.callback(), BoundNetLog())); |
565 EXPECT_EQ(OK, one_callback.WaitForResult()); | 573 EXPECT_EQ(OK, one_callback.WaitForResult()); |
566 ExpectResponse("pipelined.html", one_transaction); | 574 ExpectResponse("pipelined.html", one_transaction, false); |
567 | 575 |
568 CompleteTwoRequests(1, 4); | 576 CompleteTwoRequests(1, 4); |
569 } | 577 } |
570 | 578 |
571 TEST_F(HttpPipelinedNetworkTransactionTest, PipelinesImmediatelyIfKnownGood) { | 579 TEST_F(HttpPipelinedNetworkTransactionTest, PipelinesImmediatelyIfKnownGood) { |
572 // The first request gets us an HTTP/1.1. The next 3 test pipelining. When the | 580 // 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 | 581 // 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 | 582 // complete, the 5th and 6th should then be immediately sent pipelined on a |
575 // new HttpPipelinedConnection. | 583 // new HttpPipelinedConnection. |
576 int old_max_sockets = ClientSocketPoolManager::max_sockets_per_group(); | 584 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()); | 640 HttpNetworkTransaction second_two_transaction(session_.get()); |
633 TestCompletionCallback second_two_callback; | 641 TestCompletionCallback second_two_callback; |
634 EXPECT_EQ(ERR_IO_PENDING, | 642 EXPECT_EQ(ERR_IO_PENDING, |
635 second_two_transaction.Start( | 643 second_two_transaction.Start( |
636 GetRequestInfo("second-pipeline-two.html"), | 644 GetRequestInfo("second-pipeline-two.html"), |
637 second_two_callback.callback(), BoundNetLog())); | 645 second_two_callback.callback(), BoundNetLog())); |
638 | 646 |
639 data_vector_[0]->RunFor(3); | 647 data_vector_[0]->RunFor(3); |
640 EXPECT_EQ(OK, second_one_callback.WaitForResult()); | 648 EXPECT_EQ(OK, second_one_callback.WaitForResult()); |
641 data_vector_[0]->StopAfter(100); | 649 data_vector_[0]->StopAfter(100); |
642 ExpectResponse("second-pipeline-one.html", second_one_transaction); | 650 ExpectResponse("second-pipeline-one.html", second_one_transaction, false); |
643 EXPECT_EQ(OK, second_two_callback.WaitForResult()); | 651 EXPECT_EQ(OK, second_two_callback.WaitForResult()); |
644 ExpectResponse("second-pipeline-two.html", second_two_transaction); | 652 ExpectResponse("second-pipeline-two.html", second_two_transaction, false); |
645 | 653 |
646 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets); | 654 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets); |
647 } | 655 } |
648 | 656 |
649 class DataRunnerObserver : public MessageLoop::TaskObserver { | 657 class DataRunnerObserver : public MessageLoop::TaskObserver { |
650 public: | 658 public: |
651 DataRunnerObserver(DeterministicSocketData* data, int run_before_task) | 659 DataRunnerObserver(DeterministicSocketData* data, int run_before_task) |
652 : data_(data), | 660 : data_(data), |
653 run_before_task_(run_before_task), | 661 run_before_task_(run_before_task), |
654 current_task_(0) { } | 662 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) | 735 // 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 | 736 // is called in between when task #3 is scheduled and when it runs. The |
729 // DataRunnerObserver does that. | 737 // DataRunnerObserver does that. |
730 DataRunnerObserver observer(data_vector_[0].get(), 3); | 738 DataRunnerObserver observer(data_vector_[0].get(), 3); |
731 MessageLoop::current()->AddTaskObserver(&observer); | 739 MessageLoop::current()->AddTaskObserver(&observer); |
732 data_vector_[0]->SetStop(4); | 740 data_vector_[0]->SetStop(4); |
733 MessageLoop::current()->RunAllPending(); | 741 MessageLoop::current()->RunAllPending(); |
734 data_vector_[0]->SetStop(10); | 742 data_vector_[0]->SetStop(10); |
735 | 743 |
736 EXPECT_EQ(OK, one_callback.WaitForResult()); | 744 EXPECT_EQ(OK, one_callback.WaitForResult()); |
737 ExpectResponse("one.html", one_transaction); | 745 ExpectResponse("one.html", one_transaction, false); |
738 EXPECT_EQ(OK, two_callback.WaitForResult()); | 746 EXPECT_EQ(OK, two_callback.WaitForResult()); |
739 ExpectResponse("two.html", two_transaction); | 747 ExpectResponse("two.html", two_transaction, false); |
748 } | |
749 | |
750 TEST_F(HttpPipelinedNetworkTransactionTest, ForcedPipelineSharesConnection) { | |
751 Initialize(); | |
752 | |
753 MockWrite writes[] = { | |
754 MockWrite(true, 0, "GET /one.html HTTP/1.1\r\n" | |
755 "Host: localhost\r\n" | |
756 "Connection: keep-alive\r\n\r\n" | |
757 "GET /two.html HTTP/1.1\r\n" | |
758 "Host: localhost\r\n" | |
759 "Connection: keep-alive\r\n\r\n"), | |
760 }; | |
761 MockRead reads[] = { | |
762 MockRead(true, 1, "HTTP/1.1 200 OK\r\n"), | |
763 MockRead(true, 2, "Content-Length: 8\r\n\r\n"), | |
764 MockRead(true, 3, "one.html"), | |
765 MockRead(true, 4, "HTTP/1.1 200 OK\r\n"), | |
766 MockRead(true, 5, "Content-Length: 8\r\n\r\n"), | |
767 MockRead(true, 6, "two.html"), | |
768 }; | |
769 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); | |
770 | |
771 scoped_ptr<HttpNetworkTransaction> one_transaction( | |
772 new HttpNetworkTransaction(session_.get())); | |
773 TestCompletionCallback one_callback; | |
774 HttpRequestInfo* one_info = GetRequestInfo("one.html"); | |
775 one_info->load_flags |= LOAD_FORCE_HTTP_PIPELINING; | |
776 EXPECT_EQ(ERR_IO_PENDING, | |
777 one_transaction->Start(one_info, | |
778 one_callback.callback(), BoundNetLog())); | |
779 | |
780 HttpNetworkTransaction two_transaction(session_.get()); | |
781 TestCompletionCallback two_callback; | |
782 HttpRequestInfo* two_info = GetRequestInfo("two.html"); | |
783 two_info->load_flags |= LOAD_FORCE_HTTP_PIPELINING; | |
784 EXPECT_EQ(ERR_IO_PENDING, | |
785 two_transaction.Start(two_info, | |
786 two_callback.callback(), BoundNetLog())); | |
787 | |
788 data_vector_[0]->RunFor(3); | |
mmenke
2012/02/23 18:54:58
Why is this 3 and the one below 2? I'd think they
James Simonsen
2012/02/23 23:49:46
The initial write is also async and is only includ
mmenke
2012/02/24 00:20:14
But it's event 0, not event 1, so it doesn't look
| |
789 EXPECT_EQ(OK, one_callback.WaitForResult()); | |
790 ExpectResponse("one.html", *one_transaction.get(), true); | |
791 one_transaction.reset(); | |
792 | |
793 data_vector_[0]->RunFor(2); | |
794 EXPECT_EQ(OK, two_callback.WaitForResult()); | |
795 ExpectResponse("two.html", two_transaction, true); | |
796 } | |
797 | |
798 TEST_F(HttpPipelinedNetworkTransactionTest, | |
799 ForcedPipelineConnectionErrorFailsBoth) { | |
800 Initialize(); | |
801 | |
802 scoped_refptr<DeterministicSocketData> data( | |
803 new DeterministicSocketData(NULL, 0, NULL, 0)); | |
804 data->set_connect_data(MockConnect(ASYNC, ERR_FAILED)); | |
805 factory_.AddSocketDataProvider(data); | |
806 | |
807 scoped_ptr<HttpNetworkTransaction> one_transaction( | |
808 new HttpNetworkTransaction(session_.get())); | |
809 TestCompletionCallback one_callback; | |
810 HttpRequestInfo* one_info = GetRequestInfo("one.html"); | |
811 one_info->load_flags |= LOAD_FORCE_HTTP_PIPELINING; | |
812 EXPECT_EQ(ERR_IO_PENDING, | |
813 one_transaction->Start(one_info, | |
814 one_callback.callback(), BoundNetLog())); | |
815 | |
816 HttpNetworkTransaction two_transaction(session_.get()); | |
817 TestCompletionCallback two_callback; | |
818 HttpRequestInfo* two_info = GetRequestInfo("two.html"); | |
819 two_info->load_flags |= LOAD_FORCE_HTTP_PIPELINING; | |
820 EXPECT_EQ(ERR_IO_PENDING, | |
821 two_transaction.Start(two_info, | |
822 two_callback.callback(), BoundNetLog())); | |
823 | |
824 data->Run(); | |
825 EXPECT_EQ(ERR_FAILED, one_callback.WaitForResult()); | |
826 EXPECT_EQ(ERR_FAILED, two_callback.WaitForResult()); | |
740 } | 827 } |
mmenke
2012/02/23 18:54:58
Suggest you also have a test where we get ERR_PIPE
James Simonsen
2012/02/23 23:49:46
Done.
| |
741 | 828 |
742 } // anonymous namespace | 829 } // anonymous namespace |
743 | 830 |
744 } // namespace net | 831 } // namespace net |
OLD | NEW |