| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 void ExpectResponse(const std::string& expected, | 90 void ExpectResponse(const std::string& expected, |
| 91 HttpNetworkTransaction& transaction) { | 91 HttpNetworkTransaction& transaction) { |
| 92 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); | 92 scoped_refptr<IOBuffer> buffer(new IOBuffer(expected.size())); |
| 93 EXPECT_EQ(static_cast<int>(expected.size()), | 93 EXPECT_EQ(static_cast<int>(expected.size()), |
| 94 transaction.Read(buffer.get(), expected.size(), &callback_)); | 94 transaction.Read(buffer.get(), expected.size(), &callback_)); |
| 95 std::string actual(buffer->data(), expected.size()); | 95 std::string actual(buffer->data(), expected.size()); |
| 96 EXPECT_THAT(actual, StrEq(expected)); | 96 EXPECT_THAT(actual, StrEq(expected)); |
| 97 EXPECT_EQ(OK, transaction.Read(buffer.get(), expected.size(), &callback_)); | 97 EXPECT_EQ(OK, transaction.Read(buffer.get(), expected.size(), &callback_)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void CompleteTwoRequests() { | 100 void CompleteTwoRequests(int data_index, int stop_at_step) { |
| 101 scoped_ptr<HttpNetworkTransaction> one_transaction( | 101 scoped_ptr<HttpNetworkTransaction> one_transaction( |
| 102 new HttpNetworkTransaction(session_.get())); | 102 new HttpNetworkTransaction(session_.get())); |
| 103 TestOldCompletionCallback one_callback; | 103 TestOldCompletionCallback one_callback; |
| 104 EXPECT_EQ(ERR_IO_PENDING, | 104 EXPECT_EQ(ERR_IO_PENDING, |
| 105 one_transaction->Start(GetRequestInfo("one.html"), &one_callback, | 105 one_transaction->Start(GetRequestInfo("one.html"), &one_callback, |
| 106 BoundNetLog())); | 106 BoundNetLog())); |
| 107 EXPECT_EQ(OK, one_callback.WaitForResult()); | 107 EXPECT_EQ(OK, one_callback.WaitForResult()); |
| 108 | 108 |
| 109 HttpNetworkTransaction two_transaction(session_.get()); | 109 HttpNetworkTransaction two_transaction(session_.get()); |
| 110 TestOldCompletionCallback two_callback; | 110 TestOldCompletionCallback two_callback; |
| 111 EXPECT_EQ(ERR_IO_PENDING, | 111 EXPECT_EQ(ERR_IO_PENDING, |
| 112 two_transaction.Start(GetRequestInfo("two.html"), &two_callback, | 112 two_transaction.Start(GetRequestInfo("two.html"), &two_callback, |
| 113 BoundNetLog())); | 113 BoundNetLog())); |
| 114 | 114 |
| 115 TestOldCompletionCallback one_read_callback; | 115 TestOldCompletionCallback one_read_callback; |
| 116 scoped_refptr<IOBuffer> buffer(new IOBuffer(8)); | 116 scoped_refptr<IOBuffer> buffer(new IOBuffer(8)); |
| 117 EXPECT_EQ(ERR_IO_PENDING, | 117 EXPECT_EQ(ERR_IO_PENDING, |
| 118 one_transaction->Read(buffer.get(), 8, &one_read_callback)); | 118 one_transaction->Read(buffer.get(), 8, &one_read_callback)); |
| 119 | 119 |
| 120 data_vector_[0]->RunFor(2); | 120 data_vector_[data_index]->SetStop(stop_at_step); |
| 121 data_vector_[data_index]->Run(); |
| 121 EXPECT_EQ(8, one_read_callback.WaitForResult()); | 122 EXPECT_EQ(8, one_read_callback.WaitForResult()); |
| 122 data_vector_[0]->SetStop(10); | 123 data_vector_[data_index]->SetStop(10); |
| 123 std::string actual(buffer->data(), 8); | 124 std::string actual(buffer->data(), 8); |
| 124 EXPECT_THAT(actual, StrEq("one.html")); | 125 EXPECT_THAT(actual, StrEq("one.html")); |
| 125 EXPECT_EQ(OK, one_transaction->Read(buffer.get(), 8, &one_read_callback)); | 126 EXPECT_EQ(OK, one_transaction->Read(buffer.get(), 8, &one_read_callback)); |
| 126 | 127 |
| 127 EXPECT_EQ(OK, two_callback.WaitForResult()); | 128 EXPECT_EQ(OK, two_callback.WaitForResult()); |
| 128 ExpectResponse("two.html", two_transaction); | 129 ExpectResponse("two.html", two_transaction); |
| 129 } | 130 } |
| 130 | 131 |
| 132 void CompleteFourRequests() { |
| 133 scoped_ptr<HttpNetworkTransaction> one_transaction( |
| 134 new HttpNetworkTransaction(session_.get())); |
| 135 TestOldCompletionCallback one_callback; |
| 136 EXPECT_EQ(ERR_IO_PENDING, |
| 137 one_transaction->Start(GetRequestInfo("one.html"), &one_callback, |
| 138 BoundNetLog())); |
| 139 EXPECT_EQ(OK, one_callback.WaitForResult()); |
| 140 |
| 141 HttpNetworkTransaction two_transaction(session_.get()); |
| 142 TestOldCompletionCallback two_callback; |
| 143 EXPECT_EQ(ERR_IO_PENDING, |
| 144 two_transaction.Start(GetRequestInfo("two.html"), &two_callback, |
| 145 BoundNetLog())); |
| 146 |
| 147 HttpNetworkTransaction three_transaction(session_.get()); |
| 148 TestOldCompletionCallback three_callback; |
| 149 EXPECT_EQ(ERR_IO_PENDING, |
| 150 three_transaction.Start(GetRequestInfo("three.html"), |
| 151 &three_callback, BoundNetLog())); |
| 152 |
| 153 HttpNetworkTransaction four_transaction(session_.get()); |
| 154 TestOldCompletionCallback four_callback; |
| 155 EXPECT_EQ(ERR_IO_PENDING, |
| 156 four_transaction.Start(GetRequestInfo("four.html"), |
| 157 &four_callback, BoundNetLog())); |
| 158 |
| 159 ExpectResponse("one.html", *one_transaction.get()); |
| 160 EXPECT_EQ(OK, two_callback.WaitForResult()); |
| 161 ExpectResponse("two.html", two_transaction); |
| 162 EXPECT_EQ(OK, three_callback.WaitForResult()); |
| 163 ExpectResponse("three.html", three_transaction); |
| 164 |
| 165 one_transaction.reset(); |
| 166 EXPECT_EQ(OK, four_callback.WaitForResult()); |
| 167 ExpectResponse("four.html", four_transaction); |
| 168 } |
| 169 |
| 131 DeterministicMockClientSocketFactory factory_; | 170 DeterministicMockClientSocketFactory factory_; |
| 132 ClientSocketPoolHistograms histograms_; | 171 ClientSocketPoolHistograms histograms_; |
| 133 MockTransportClientSocketPool pool_; | 172 MockTransportClientSocketPool pool_; |
| 134 std::vector<scoped_refptr<DeterministicSocketData> > data_vector_; | 173 std::vector<scoped_refptr<DeterministicSocketData> > data_vector_; |
| 135 TestOldCompletionCallback callback_; | 174 TestOldCompletionCallback callback_; |
| 136 ScopedVector<HttpRequestInfo> request_info_vector_; | 175 ScopedVector<HttpRequestInfo> request_info_vector_; |
| 137 bool default_pipelining_enabled_; | 176 bool default_pipelining_enabled_; |
| 138 | 177 |
| 139 scoped_ptr<ProxyService> proxy_service_; | 178 scoped_ptr<ProxyService> proxy_service_; |
| 140 MockHostResolver mock_resolver_; | 179 MockHostResolver mock_resolver_; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 MockRead reads[] = { | 220 MockRead reads[] = { |
| 182 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), | 221 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), |
| 183 MockRead(false, 2, "Content-Length: 8\r\n\r\n"), | 222 MockRead(false, 2, "Content-Length: 8\r\n\r\n"), |
| 184 MockRead(true, 4, "one.html"), | 223 MockRead(true, 4, "one.html"), |
| 185 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"), | 224 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"), |
| 186 MockRead(false, 6, "Content-Length: 8\r\n\r\n"), | 225 MockRead(false, 6, "Content-Length: 8\r\n\r\n"), |
| 187 MockRead(false, 7, "two.html"), | 226 MockRead(false, 7, "two.html"), |
| 188 }; | 227 }; |
| 189 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); | 228 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); |
| 190 | 229 |
| 191 CompleteTwoRequests(); | 230 CompleteTwoRequests(0, 5); |
| 192 } | 231 } |
| 193 | 232 |
| 194 TEST_F(HttpPipelinedNetworkTransactionTest, ReusesOnSpaceAvailable) { | 233 TEST_F(HttpPipelinedNetworkTransactionTest, ReusesOnSpaceAvailable) { |
| 195 int old_max_sockets = ClientSocketPoolManager::max_sockets_per_group(); | 234 int old_max_sockets = ClientSocketPoolManager::max_sockets_per_group(); |
| 196 ClientSocketPoolManager::set_max_sockets_per_group(1); | 235 ClientSocketPoolManager::set_max_sockets_per_group(1); |
| 197 Initialize(); | 236 Initialize(); |
| 198 | 237 |
| 199 MockWrite writes[] = { | 238 MockWrite writes[] = { |
| 200 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" | 239 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" |
| 201 "Host: localhost\r\n" | 240 "Host: localhost\r\n" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 219 MockRead(false, 8, "two.html"), | 258 MockRead(false, 8, "two.html"), |
| 220 MockRead(false, 9, "HTTP/1.1 200 OK\r\n"), | 259 MockRead(false, 9, "HTTP/1.1 200 OK\r\n"), |
| 221 MockRead(false, 10, "Content-Length: 10\r\n\r\n"), | 260 MockRead(false, 10, "Content-Length: 10\r\n\r\n"), |
| 222 MockRead(false, 11, "three.html"), | 261 MockRead(false, 11, "three.html"), |
| 223 MockRead(false, 13, "HTTP/1.1 200 OK\r\n"), | 262 MockRead(false, 13, "HTTP/1.1 200 OK\r\n"), |
| 224 MockRead(false, 14, "Content-Length: 9\r\n\r\n"), | 263 MockRead(false, 14, "Content-Length: 9\r\n\r\n"), |
| 225 MockRead(false, 15, "four.html"), | 264 MockRead(false, 15, "four.html"), |
| 226 }; | 265 }; |
| 227 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); | 266 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); |
| 228 | 267 |
| 229 scoped_ptr<HttpNetworkTransaction> one_transaction( | 268 CompleteFourRequests(); |
| 230 new HttpNetworkTransaction(session_.get())); | |
| 231 TestOldCompletionCallback one_callback; | |
| 232 EXPECT_EQ(ERR_IO_PENDING, | |
| 233 one_transaction->Start(GetRequestInfo("one.html"), &one_callback, | |
| 234 BoundNetLog())); | |
| 235 EXPECT_EQ(OK, one_callback.WaitForResult()); | |
| 236 | |
| 237 HttpNetworkTransaction two_transaction(session_.get()); | |
| 238 TestOldCompletionCallback two_callback; | |
| 239 EXPECT_EQ(ERR_IO_PENDING, | |
| 240 two_transaction.Start(GetRequestInfo("two.html"), &two_callback, | |
| 241 BoundNetLog())); | |
| 242 | |
| 243 HttpNetworkTransaction three_transaction(session_.get()); | |
| 244 TestOldCompletionCallback three_callback; | |
| 245 EXPECT_EQ(ERR_IO_PENDING, | |
| 246 three_transaction.Start(GetRequestInfo("three.html"), | |
| 247 &three_callback, BoundNetLog())); | |
| 248 | |
| 249 HttpNetworkTransaction four_transaction(session_.get()); | |
| 250 TestOldCompletionCallback four_callback; | |
| 251 EXPECT_EQ(ERR_IO_PENDING, | |
| 252 four_transaction.Start(GetRequestInfo("four.html"), &four_callback, | |
| 253 BoundNetLog())); | |
| 254 | |
| 255 ExpectResponse("one.html", *one_transaction.get()); | |
| 256 EXPECT_EQ(OK, two_callback.WaitForResult()); | |
| 257 ExpectResponse("two.html", two_transaction); | |
| 258 EXPECT_EQ(OK, three_callback.WaitForResult()); | |
| 259 ExpectResponse("three.html", three_transaction); | |
| 260 | |
| 261 one_transaction.reset(); | |
| 262 EXPECT_EQ(OK, four_callback.WaitForResult()); | |
| 263 ExpectResponse("four.html", four_transaction); | |
| 264 | 269 |
| 265 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets); | 270 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets); |
| 266 } | 271 } |
| 267 | 272 |
| 268 TEST_F(HttpPipelinedNetworkTransactionTest, UnknownSizeEvictsToNewPipeline) { | 273 TEST_F(HttpPipelinedNetworkTransactionTest, UnknownSizeEvictsToNewPipeline) { |
| 269 Initialize(); | 274 Initialize(); |
| 270 | 275 |
| 271 MockWrite writes[] = { | 276 MockWrite writes[] = { |
| 272 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" | 277 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" |
| 273 "Host: localhost\r\n" | 278 "Host: localhost\r\n" |
| 274 "Connection: keep-alive\r\n\r\n"), | 279 "Connection: keep-alive\r\n\r\n"), |
| 275 MockWrite(false, 2, "GET /two.html HTTP/1.1\r\n" | |
| 276 "Host: localhost\r\n" | |
| 277 "Connection: keep-alive\r\n\r\n"), | |
| 278 }; | 280 }; |
| 279 MockRead reads[] = { | 281 MockRead reads[] = { |
| 280 MockRead(false, 1, "HTTP/1.1 200 OK\r\n\r\n"), | 282 MockRead(false, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 281 MockRead(true, 3, "one.html"), | 283 MockRead(true, 2, "one.html"), |
| 282 MockRead(false, OK, 4), | 284 MockRead(false, OK, 3), |
| 283 }; | 285 }; |
| 284 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); | 286 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); |
| 285 | 287 |
| 286 MockWrite writes2[] = { | 288 MockWrite writes2[] = { |
| 287 MockWrite(false, 0, "GET /two.html HTTP/1.1\r\n" | 289 MockWrite(false, 0, "GET /two.html HTTP/1.1\r\n" |
| 288 "Host: localhost\r\n" | 290 "Host: localhost\r\n" |
| 289 "Connection: keep-alive\r\n\r\n"), | 291 "Connection: keep-alive\r\n\r\n"), |
| 290 }; | 292 }; |
| 291 MockRead reads2[] = { | 293 MockRead reads2[] = { |
| 292 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), | 294 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), |
| 293 MockRead(false, 2, "Content-Length: 8\r\n\r\n"), | 295 MockRead(false, 2, "Content-Length: 8\r\n\r\n"), |
| 294 MockRead(false, 3, "two.html"), | 296 MockRead(false, 3, "two.html"), |
| 295 }; | 297 }; |
| 296 AddExpectedConnection(reads2, arraysize(reads2), writes2, arraysize(writes2)); | 298 AddExpectedConnection(reads2, arraysize(reads2), writes2, arraysize(writes2)); |
| 297 | 299 |
| 298 CompleteTwoRequests(); | 300 CompleteTwoRequests(0, 3); |
| 299 } | 301 } |
| 300 | 302 |
| 301 TEST_F(HttpPipelinedNetworkTransactionTest, ConnectionCloseEvictToNewPipeline) { | 303 TEST_F(HttpPipelinedNetworkTransactionTest, ConnectionCloseEvictToNewPipeline) { |
| 302 Initialize(); | 304 Initialize(); |
| 303 | 305 |
| 304 MockWrite writes[] = { | 306 MockWrite writes[] = { |
| 305 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" | 307 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" |
| 306 "Host: localhost\r\n" | 308 "Host: localhost\r\n" |
| 307 "Connection: keep-alive\r\n\r\n"), | 309 "Connection: keep-alive\r\n\r\n"), |
| 308 MockWrite(false, 3, "GET /two.html HTTP/1.1\r\n" | 310 MockWrite(false, 3, "GET /two.html HTTP/1.1\r\n" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 322 "Host: localhost\r\n" | 324 "Host: localhost\r\n" |
| 323 "Connection: keep-alive\r\n\r\n"), | 325 "Connection: keep-alive\r\n\r\n"), |
| 324 }; | 326 }; |
| 325 MockRead reads2[] = { | 327 MockRead reads2[] = { |
| 326 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), | 328 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), |
| 327 MockRead(false, 2, "Content-Length: 8\r\n\r\n"), | 329 MockRead(false, 2, "Content-Length: 8\r\n\r\n"), |
| 328 MockRead(false, 3, "two.html"), | 330 MockRead(false, 3, "two.html"), |
| 329 }; | 331 }; |
| 330 AddExpectedConnection(reads2, arraysize(reads2), writes2, arraysize(writes2)); | 332 AddExpectedConnection(reads2, arraysize(reads2), writes2, arraysize(writes2)); |
| 331 | 333 |
| 332 CompleteTwoRequests(); | 334 CompleteTwoRequests(0, 5); |
| 333 } | 335 } |
| 334 | 336 |
| 335 TEST_F(HttpPipelinedNetworkTransactionTest, ErrorEvictsToNewPipeline) { | 337 TEST_F(HttpPipelinedNetworkTransactionTest, ErrorEvictsToNewPipeline) { |
| 336 Initialize(); | 338 Initialize(); |
| 337 | 339 |
| 338 MockWrite writes[] = { | 340 MockWrite writes[] = { |
| 339 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" | 341 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" |
| 340 "Host: localhost\r\n" | 342 "Host: localhost\r\n" |
| 341 "Connection: keep-alive\r\n\r\n"), | 343 "Connection: keep-alive\r\n\r\n"), |
| 342 MockWrite(false, 3, "GET /two.html HTTP/1.1\r\n" | 344 MockWrite(false, 3, "GET /two.html HTTP/1.1\r\n" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 ERR_IO_PENDING, | 460 ERR_IO_PENDING, |
| 459 transaction.Start(GetRequestInfo("one.html"), &callback_, BoundNetLog())); | 461 transaction.Start(GetRequestInfo("one.html"), &callback_, BoundNetLog())); |
| 460 EXPECT_EQ(OK, callback_.WaitForResult()); | 462 EXPECT_EQ(OK, callback_.WaitForResult()); |
| 461 | 463 |
| 462 AuthCredentials credentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")); | 464 AuthCredentials credentials(ASCIIToUTF16("user"), ASCIIToUTF16("pass")); |
| 463 EXPECT_EQ(OK, transaction.RestartWithAuth(credentials, &callback_)); | 465 EXPECT_EQ(OK, transaction.RestartWithAuth(credentials, &callback_)); |
| 464 | 466 |
| 465 ExpectResponse("one.html", transaction); | 467 ExpectResponse("one.html", transaction); |
| 466 } | 468 } |
| 467 | 469 |
| 470 TEST_F(HttpPipelinedNetworkTransactionTest, OldVersionDisablesPipelining) { |
| 471 Initialize(); |
| 472 |
| 473 MockWrite writes[] = { |
| 474 MockWrite(false, 0, "GET /pipelined.html HTTP/1.1\r\n" |
| 475 "Host: localhost\r\n" |
| 476 "Connection: keep-alive\r\n\r\n"), |
| 477 }; |
| 478 MockRead reads[] = { |
| 479 MockRead(false, 1, "HTTP/1.0 200 OK\r\n"), |
| 480 MockRead(false, 2, "Content-Length: 14\r\n\r\n"), |
| 481 MockRead(false, 3, "pipelined.html"), |
| 482 }; |
| 483 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); |
| 484 |
| 485 MockWrite writes2[] = { |
| 486 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" |
| 487 "Host: localhost\r\n" |
| 488 "Connection: keep-alive\r\n\r\n"), |
| 489 }; |
| 490 MockRead reads2[] = { |
| 491 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), |
| 492 MockRead(false, 2, "Content-Length: 8\r\n\r\n"), |
| 493 MockRead(true, 3, "one.html"), |
| 494 MockRead(false, OK, 4), |
| 495 }; |
| 496 AddExpectedConnection(reads2, arraysize(reads2), writes2, arraysize(writes2)); |
| 497 |
| 498 MockWrite writes3[] = { |
| 499 MockWrite(false, 0, "GET /two.html HTTP/1.1\r\n" |
| 500 "Host: localhost\r\n" |
| 501 "Connection: keep-alive\r\n\r\n"), |
| 502 }; |
| 503 MockRead reads3[] = { |
| 504 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), |
| 505 MockRead(false, 2, "Content-Length: 8\r\n\r\n"), |
| 506 MockRead(false, 3, "two.html"), |
| 507 MockRead(false, OK, 4), |
| 508 }; |
| 509 AddExpectedConnection(reads3, arraysize(reads3), writes3, arraysize(writes3)); |
| 510 |
| 511 HttpNetworkTransaction one_transaction(session_.get()); |
| 512 TestOldCompletionCallback one_callback; |
| 513 EXPECT_EQ(ERR_IO_PENDING, |
| 514 one_transaction.Start(GetRequestInfo("pipelined.html"), |
| 515 &one_callback, BoundNetLog())); |
| 516 EXPECT_EQ(OK, one_callback.WaitForResult()); |
| 517 ExpectResponse("pipelined.html", one_transaction); |
| 518 |
| 519 CompleteTwoRequests(1, 4); |
| 520 } |
| 521 |
| 522 TEST_F(HttpPipelinedNetworkTransactionTest, PipelinesImmediatelyIfKnownGood) { |
| 523 // The first request gets us an HTTP/1.1. The next 3 test pipelining. When the |
| 524 // 3rd request completes, we know pipelining is safe. After the first 4 |
| 525 // complete, the 5th and 6th should then be immediately sent pipelined on a |
| 526 // new HttpPipelinedConnection. |
| 527 int old_max_sockets = ClientSocketPoolManager::max_sockets_per_group(); |
| 528 ClientSocketPoolManager::set_max_sockets_per_group(1); |
| 529 Initialize(); |
| 530 |
| 531 MockWrite writes[] = { |
| 532 MockWrite(false, 0, "GET /one.html HTTP/1.1\r\n" |
| 533 "Host: localhost\r\n" |
| 534 "Connection: keep-alive\r\n\r\n"), |
| 535 MockWrite(false, 4, "GET /two.html HTTP/1.1\r\n" |
| 536 "Host: localhost\r\n" |
| 537 "Connection: keep-alive\r\n\r\n"), |
| 538 MockWrite(false, 7, "GET /three.html HTTP/1.1\r\n" |
| 539 "Host: localhost\r\n" |
| 540 "Connection: keep-alive\r\n\r\n"), |
| 541 MockWrite(false, 12, "GET /four.html HTTP/1.1\r\n" |
| 542 "Host: localhost\r\n" |
| 543 "Connection: keep-alive\r\n\r\n"), |
| 544 MockWrite(false, 16, "GET /second-pipeline-one.html HTTP/1.1\r\n" |
| 545 "Host: localhost\r\n" |
| 546 "Connection: keep-alive\r\n\r\n"), |
| 547 MockWrite(false, 17, "GET /second-pipeline-two.html HTTP/1.1\r\n" |
| 548 "Host: localhost\r\n" |
| 549 "Connection: keep-alive\r\n\r\n"), |
| 550 }; |
| 551 MockRead reads[] = { |
| 552 MockRead(false, 1, "HTTP/1.1 200 OK\r\n"), |
| 553 MockRead(false, 2, "Content-Length: 8\r\n\r\n"), |
| 554 MockRead(false, 3, "one.html"), |
| 555 MockRead(false, 5, "HTTP/1.1 200 OK\r\n"), |
| 556 MockRead(false, 6, "Content-Length: 8\r\n\r\n"), |
| 557 MockRead(false, 8, "two.html"), |
| 558 MockRead(false, 9, "HTTP/1.1 200 OK\r\n"), |
| 559 MockRead(false, 10, "Content-Length: 10\r\n\r\n"), |
| 560 MockRead(false, 11, "three.html"), |
| 561 MockRead(false, 13, "HTTP/1.1 200 OK\r\n"), |
| 562 MockRead(false, 14, "Content-Length: 9\r\n\r\n"), |
| 563 MockRead(false, 15, "four.html"), |
| 564 MockRead(true, 18, "HTTP/1.1 200 OK\r\n"), |
| 565 MockRead(true, 19, "Content-Length: 24\r\n\r\n"), |
| 566 MockRead(false, 20, "second-pipeline-one.html"), |
| 567 MockRead(false, 21, "HTTP/1.1 200 OK\r\n"), |
| 568 MockRead(false, 22, "Content-Length: 24\r\n\r\n"), |
| 569 MockRead(false, 23, "second-pipeline-two.html"), |
| 570 }; |
| 571 AddExpectedConnection(reads, arraysize(reads), writes, arraysize(writes)); |
| 572 |
| 573 CompleteFourRequests(); |
| 574 |
| 575 HttpNetworkTransaction second_one_transaction(session_.get()); |
| 576 TestOldCompletionCallback second_one_callback; |
| 577 EXPECT_EQ(ERR_IO_PENDING, |
| 578 second_one_transaction.Start( |
| 579 GetRequestInfo("second-pipeline-one.html"), |
| 580 &second_one_callback, BoundNetLog())); |
| 581 MessageLoop::current()->RunAllPending(); |
| 582 |
| 583 HttpNetworkTransaction second_two_transaction(session_.get()); |
| 584 TestOldCompletionCallback second_two_callback; |
| 585 EXPECT_EQ(ERR_IO_PENDING, |
| 586 second_two_transaction.Start( |
| 587 GetRequestInfo("second-pipeline-two.html"), |
| 588 &second_two_callback, BoundNetLog())); |
| 589 |
| 590 data_vector_[0]->RunFor(3); |
| 591 EXPECT_EQ(OK, second_one_callback.WaitForResult()); |
| 592 data_vector_[0]->StopAfter(100); |
| 593 ExpectResponse("second-pipeline-one.html", second_one_transaction); |
| 594 EXPECT_EQ(OK, second_two_callback.WaitForResult()); |
| 595 ExpectResponse("second-pipeline-two.html", second_two_transaction); |
| 596 |
| 597 ClientSocketPoolManager::set_max_sockets_per_group(old_max_sockets); |
| 598 } |
| 599 |
| 468 } // anonymous namespace | 600 } // anonymous namespace |
| 469 | 601 |
| 470 } // namespace net | 602 } // namespace net |
| OLD | NEW |