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 6126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6137 << data->write_count() | 6137 << data->write_count() |
6138 << " Write index: " | 6138 << " Write index: " |
6139 << data->write_index(); | 6139 << data->write_index(); |
6140 | 6140 |
6141 // Verify the SYN_REPLY. | 6141 // Verify the SYN_REPLY. |
6142 HttpResponseInfo response = *trans->GetResponseInfo(); | 6142 HttpResponseInfo response = *trans->GetResponseInfo(); |
6143 EXPECT_TRUE(response.headers != NULL); | 6143 EXPECT_TRUE(response.headers != NULL); |
6144 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 6144 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
6145 } | 6145 } |
6146 | 6146 |
| 6147 TEST_P(SpdyNetworkTransactionSpdy3Test, OutOfOrderSynStream) { |
| 6148 // This first request will start to establish the SpdySession. |
| 6149 // Then we will start the second (MEDIUM priority) and then third |
| 6150 // (HIGHEST priority) request in such a way that the third will actually |
| 6151 // start before the second, causing the second to be re-numbered. |
| 6152 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 6153 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 5, HIGHEST)); |
| 6154 scoped_ptr<SpdyFrame> req3(ConstructSpdyGet(NULL, 0, false, 7, MEDIUM)); |
| 6155 MockWrite writes[] = { |
| 6156 CreateMockWrite(*req1, 0), |
| 6157 CreateMockWrite(*req2, 3), |
| 6158 CreateMockWrite(*req3, 4), |
| 6159 }; |
| 6160 |
| 6161 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 6162 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(1, true)); |
| 6163 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 7)); |
| 6164 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(7, true)); |
| 6165 scoped_ptr<SpdyFrame> resp3(ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 6166 scoped_ptr<SpdyFrame> body3(ConstructSpdyBodyFrame(5, true)); |
| 6167 MockRead reads[] = { |
| 6168 CreateMockRead(*resp1, 1), |
| 6169 CreateMockRead(*body1, 2), |
| 6170 CreateMockRead(*resp2, 5), |
| 6171 CreateMockRead(*body2, 6), |
| 6172 CreateMockRead(*resp3, 7), |
| 6173 CreateMockRead(*body3, 8), |
| 6174 MockRead(ASYNC, 0, 9) // EOF |
| 6175 }; |
| 6176 |
| 6177 scoped_refptr<DeterministicSocketData> data( |
| 6178 new DeterministicSocketData(reads, arraysize(reads), |
| 6179 writes, arraysize(writes))); |
| 6180 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 6181 BoundNetLog(), GetParam(), NULL); |
| 6182 helper.SetDeterministic(); |
| 6183 helper.RunPreTestSetup(); |
| 6184 helper.AddDeterministicData(data.get()); |
| 6185 |
| 6186 // Start the first transaction to set up the SpdySession |
| 6187 HttpNetworkTransaction* trans = helper.trans(); |
| 6188 TestCompletionCallback callback; |
| 6189 HttpRequestInfo info1 = CreateGetRequest(); |
| 6190 info1.priority = LOWEST; |
| 6191 int rv = trans->Start(&info1, callback.callback(), BoundNetLog()); |
| 6192 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6193 |
| 6194 // Run the message loop, but do not allow the write to complete. |
| 6195 // This leaves the SpdySession with a write pending, which prevents |
| 6196 // SpdySession from attempting subsequent writes until this write completes. |
| 6197 MessageLoop::current()->RunAllPending(); |
| 6198 |
| 6199 // Now, start both new transactions |
| 6200 HttpRequestInfo info2 = CreateGetRequest(); |
| 6201 info2.priority = MEDIUM; |
| 6202 TestCompletionCallback callback2; |
| 6203 scoped_ptr<HttpNetworkTransaction> trans2( |
| 6204 new HttpNetworkTransaction(helper.session())); |
| 6205 rv = trans2->Start(&info2, callback2.callback(), BoundNetLog()); |
| 6206 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6207 MessageLoop::current()->RunAllPending(); |
| 6208 |
| 6209 HttpRequestInfo info3 = CreateGetRequest(); |
| 6210 info3.priority = HIGHEST; |
| 6211 TestCompletionCallback callback3; |
| 6212 scoped_ptr<HttpNetworkTransaction> trans3( |
| 6213 new HttpNetworkTransaction(helper.session())); |
| 6214 rv = trans3->Start(&info3, callback3.callback(), BoundNetLog()); |
| 6215 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6216 MessageLoop::current()->RunAllPending(); |
| 6217 |
| 6218 // We now have two SYN_STREAM frames queued up which will be |
| 6219 // dequeued only once the first write completes, which we |
| 6220 // now allow to happen. |
| 6221 data->RunFor(2); |
| 6222 EXPECT_EQ(OK, callback.WaitForResult()); |
| 6223 |
| 6224 // And now we can allow everything else to run to completion. |
| 6225 data->SetStop(10); |
| 6226 data->Run(); |
| 6227 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 6228 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 6229 |
| 6230 helper.VerifyDataConsumed(); |
| 6231 } |
| 6232 |
6147 } // namespace net | 6233 } // namespace net |
OLD | NEW |