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 "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 5543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5554 << data->write_count() | 5554 << data->write_count() |
5555 << " Write index: " | 5555 << " Write index: " |
5556 << data->write_index(); | 5556 << data->write_index(); |
5557 | 5557 |
5558 // Verify the SYN_REPLY. | 5558 // Verify the SYN_REPLY. |
5559 HttpResponseInfo response = *trans->GetResponseInfo(); | 5559 HttpResponseInfo response = *trans->GetResponseInfo(); |
5560 EXPECT_TRUE(response.headers != NULL); | 5560 EXPECT_TRUE(response.headers != NULL); |
5561 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5561 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
5562 } | 5562 } |
5563 | 5563 |
| 5564 TEST_P(SpdyNetworkTransactionSpdy2Test, OutOfOrderSynStream) { |
| 5565 // This first request will start to establish the SpdySession. |
| 5566 // Then we will start the second (MEDIUM priority) and then third |
| 5567 // (HIGHEST priority) request in such a way that the third will actually |
| 5568 // start before the second, causing the second to be re-numbered. |
| 5569 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 5570 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 5, HIGHEST)); |
| 5571 scoped_ptr<SpdyFrame> req3(ConstructSpdyGet(NULL, 0, false, 7, MEDIUM)); |
| 5572 MockWrite writes[] = { |
| 5573 CreateMockWrite(*req1, 0), |
| 5574 CreateMockWrite(*req2, 3), |
| 5575 CreateMockWrite(*req3, 4), |
| 5576 }; |
| 5577 |
| 5578 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5579 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); |
| 5580 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 7)); |
| 5581 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(7, true)); |
| 5582 scoped_ptr<SpdyFrame> resp3(ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 5583 scoped_ptr<SpdyFrame> body3(ConstructSpdyBodyFrame(5, true)); |
| 5584 MockRead reads[] = { |
| 5585 CreateMockRead(*resp1, 1), |
| 5586 CreateMockRead(*body1, 2), |
| 5587 CreateMockRead(*resp2, 5), |
| 5588 CreateMockRead(*body2, 6), |
| 5589 CreateMockRead(*resp3, 7), |
| 5590 CreateMockRead(*body3, 8), |
| 5591 MockRead(ASYNC, 0, 9) // EOF |
| 5592 }; |
| 5593 |
| 5594 scoped_refptr<DeterministicSocketData> data( |
| 5595 new DeterministicSocketData(reads, arraysize(reads), |
| 5596 writes, arraysize(writes))); |
| 5597 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 5598 BoundNetLog(), GetParam(), NULL); |
| 5599 helper.SetDeterministic(); |
| 5600 helper.RunPreTestSetup(); |
| 5601 helper.AddDeterministicData(data.get()); |
| 5602 |
| 5603 // Start the first transaction to set up the SpdySession |
| 5604 HttpNetworkTransaction* trans = helper.trans(); |
| 5605 TestCompletionCallback callback; |
| 5606 HttpRequestInfo info1 = CreateGetRequest(); |
| 5607 info1.priority = LOWEST; |
| 5608 int rv = trans->Start(&info1, callback.callback(), BoundNetLog()); |
| 5609 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5610 |
| 5611 // Run the message loop, but do not allow the write to complete. |
| 5612 // This leaves the SpdySession with a write pending, which prevents |
| 5613 // SpdySession from attempting subsequent writes until this write completes. |
| 5614 MessageLoop::current()->RunAllPending(); |
| 5615 |
| 5616 // Now, start both new transactions |
| 5617 HttpRequestInfo info2 = CreateGetRequest(); |
| 5618 info2.priority = MEDIUM; |
| 5619 TestCompletionCallback callback2; |
| 5620 scoped_ptr<HttpNetworkTransaction> trans2( |
| 5621 new HttpNetworkTransaction(helper.session())); |
| 5622 rv = trans2->Start(&info2, callback2.callback(), BoundNetLog()); |
| 5623 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5624 MessageLoop::current()->RunAllPending(); |
| 5625 |
| 5626 HttpRequestInfo info3 = CreateGetRequest(); |
| 5627 info3.priority = HIGHEST; |
| 5628 TestCompletionCallback callback3; |
| 5629 scoped_ptr<HttpNetworkTransaction> trans3( |
| 5630 new HttpNetworkTransaction(helper.session())); |
| 5631 rv = trans3->Start(&info3, callback3.callback(), BoundNetLog()); |
| 5632 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5633 MessageLoop::current()->RunAllPending(); |
| 5634 |
| 5635 // We now have two SYN_STREAM frames queued up which will be |
| 5636 // dequeued only once the first write completes, which we |
| 5637 // now allow to happen. |
| 5638 data->RunFor(2); |
| 5639 EXPECT_EQ(OK, callback.WaitForResult()); |
| 5640 |
| 5641 // And now we can allow everything else to run to completion. |
| 5642 data->SetStop(10); |
| 5643 data->Run(); |
| 5644 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 5645 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 5646 |
| 5647 helper.VerifyDataConsumed(); |
| 5648 } |
| 5649 |
5564 } // namespace net | 5650 } // namespace net |
OLD | NEW |