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