OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "net/base/net_log_unittest.h" | 7 #include "net/base/net_log_unittest.h" |
8 #include "net/http/http_transaction_unittest.h" | 8 #include "net/http/http_transaction_unittest.h" |
9 #include "net/spdy/spdy_http_stream.h" | 9 #include "net/spdy/spdy_http_stream.h" |
10 #include "net/spdy/spdy_network_transaction.h" | 10 #include "net/spdy/spdy_network_transaction.h" |
11 #include "net/spdy/spdy_test_util.h" | 11 #include "net/spdy/spdy_test_util.h" |
| 12 #include "net/url_request/url_request_unittest.h" |
12 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
13 | 14 |
14 //----------------------------------------------------------------------------- | 15 //----------------------------------------------------------------------------- |
15 | 16 |
16 namespace net { | 17 namespace net { |
17 | 18 |
18 // This is the expected list of advertised protocols from the browser's NPN | 19 // This is the expected list of advertised protocols from the browser's NPN |
19 // list. | 20 // list. |
20 static const char kExpectedNPNString[] = "\x08http/1.1\x06spdy/2"; | 21 static const char kExpectedNPNString[] = "\x08http/1.1\x06spdy/2"; |
21 | 22 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 NOTREACHED(); | 77 NOTREACHED(); |
77 } | 78 } |
78 } | 79 } |
79 | 80 |
80 void RunPreTestSetup() { | 81 void RunPreTestSetup() { |
81 if (!session_deps_.get()) | 82 if (!session_deps_.get()) |
82 session_deps_.reset(new SpdySessionDependencies()); | 83 session_deps_.reset(new SpdySessionDependencies()); |
83 if (!session_.get()) | 84 if (!session_.get()) |
84 session_ = SpdySessionDependencies::SpdyCreateSession( | 85 session_ = SpdySessionDependencies::SpdyCreateSession( |
85 session_deps_.get()); | 86 session_deps_.get()); |
86 | |
87 HttpNetworkTransaction::SetUseAlternateProtocols(false); | 87 HttpNetworkTransaction::SetUseAlternateProtocols(false); |
88 HttpNetworkTransaction::SetUseSSLOverSpdyWithoutNPN(false); | 88 HttpNetworkTransaction::SetUseSSLOverSpdyWithoutNPN(false); |
89 HttpNetworkTransaction::SetUseSpdyWithoutNPN(false); | 89 HttpNetworkTransaction::SetUseSpdyWithoutNPN(false); |
90 switch (test_type_) { | 90 switch (test_type_) { |
91 case SPDYNPN: | 91 case SPDYNPN: |
92 session_->mutable_alternate_protocols()->SetAlternateProtocolFor( | 92 session_->mutable_alternate_protocols()->SetAlternateProtocolFor( |
93 HostPortPair("www.google.com", 80), 443, | 93 HostPortPair("www.google.com", 80), 443, |
94 HttpAlternateProtocols::NPN_SPDY_2); | 94 HttpAlternateProtocols::NPN_SPDY_2); |
95 HttpNetworkTransaction::SetUseAlternateProtocols(true); | 95 HttpNetworkTransaction::SetUseAlternateProtocols(true); |
96 HttpNetworkTransaction::SetNextProtos(kExpectedNPNString); | 96 HttpNetworkTransaction::SetNextProtos(kExpectedNPNString); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 << " Read index: " | 174 << " Read index: " |
175 << (*it)->read_index(); | 175 << (*it)->read_index(); |
176 EXPECT_TRUE(!(*it)->at_write_eof()) << "Write count: " | 176 EXPECT_TRUE(!(*it)->at_write_eof()) << "Write count: " |
177 << (*it)->write_count() | 177 << (*it)->write_count() |
178 << " Write index: " | 178 << " Write index: " |
179 << (*it)->write_index(); | 179 << (*it)->write_index(); |
180 } | 180 } |
181 } | 181 } |
182 | 182 |
183 void RunToCompletion(StaticSocketDataProvider* data) { | 183 void RunToCompletion(StaticSocketDataProvider* data) { |
| 184 RunPreTestSetup(); |
184 AddData(data); | 185 AddData(data); |
185 RunPreTestSetup(); | |
186 RunDefaultTest(); | 186 RunDefaultTest(); |
187 VerifyDataConsumed(); | 187 VerifyDataConsumed(); |
188 } | 188 } |
189 | 189 |
190 void AddData(StaticSocketDataProvider* data) { | 190 void AddData(StaticSocketDataProvider* data) { |
191 data_vector_.push_back(data); | 191 data_vector_.push_back(data); |
192 linked_ptr<SSLSocketDataProvider> ssl_( | 192 linked_ptr<SSLSocketDataProvider> ssl_( |
193 new SSLSocketDataProvider(true, OK)); | 193 new SSLSocketDataProvider(true, OK)); |
194 if (test_type_ == SPDYNPN) { | 194 if (test_type_ == SPDYNPN) { |
195 ssl_->next_proto_status = SSLClientSocket::kNextProtoNegotiated; | 195 ssl_->next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 const BoundNetLog& log_; | 237 const BoundNetLog& log_; |
238 SpdyNetworkTransactionTestTypes test_type_; | 238 SpdyNetworkTransactionTestTypes test_type_; |
239 int port_; | 239 int port_; |
240 }; | 240 }; |
241 | 241 |
242 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, | 242 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
243 int expected_status); | 243 int expected_status); |
244 | 244 |
245 void ConnectStatusHelper(const MockRead& status); | 245 void ConnectStatusHelper(const MockRead& status); |
246 | 246 |
| 247 const HttpRequestInfo& CreateGetPushRequest() { |
| 248 google_get_push_request_.method = "GET"; |
| 249 google_get_push_request_.url = GURL("http://www.google.com/foo.dat"); |
| 250 google_get_push_request_.load_flags = 0; |
| 251 return google_get_push_request_; |
| 252 } |
| 253 |
247 const HttpRequestInfo& CreateGetRequest() { | 254 const HttpRequestInfo& CreateGetRequest() { |
248 if (!google_get_request_initialized_) { | 255 if (!google_get_request_initialized_) { |
249 google_get_request_.method = "GET"; | 256 google_get_request_.method = "GET"; |
250 google_get_request_.url = GURL("http://www.google.com/"); | 257 google_get_request_.url = GURL("http://www.google.com/"); |
251 google_get_request_.load_flags = 0; | 258 google_get_request_.load_flags = 0; |
252 google_get_request_initialized_ = true; | 259 google_get_request_initialized_ = true; |
253 } | 260 } |
254 return google_get_request_; | 261 return google_get_request_; |
255 } | 262 } |
256 | 263 |
| 264 class RunServerPushTestCallback : public CallbackRunner< Tuple1<int> > { |
| 265 public: |
| 266 RunServerPushTestCallback(scoped_refptr<net::IOBufferWithSize> buffer, |
| 267 std::string& result, bool& need_read_callback) |
| 268 : buffer_(buffer), result_(result), |
| 269 need_read_callback_(need_read_callback) {} |
| 270 |
| 271 virtual void RunWithParams(const Tuple1<int>& params) { |
| 272 // Indicates some type of error. |
| 273 if(params.a <= 0) |
| 274 return; |
| 275 |
| 276 std::string temp(buffer_->data(), params.a); |
| 277 result_.append(temp); |
| 278 need_read_callback_ = true; |
| 279 } |
| 280 |
| 281 private: |
| 282 scoped_refptr<net::IOBufferWithSize> buffer_; |
| 283 std::string& result_; |
| 284 bool need_read_callback_; |
| 285 }; |
| 286 |
| 287 void RunServerPushTest(MockWrite writes[], int writes_length, |
| 288 MockRead reads[], int reads_length, |
| 289 HttpResponseInfo* response, |
| 290 HttpResponseInfo* response2, |
| 291 std::string& expected) { |
| 292 scoped_refptr<OrderedSocketData> data( |
| 293 new OrderedSocketData(reads, reads_length, |
| 294 writes, writes_length)); |
| 295 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 296 BoundNetLog(), GetParam()); |
| 297 |
| 298 helper.RunPreTestSetup(); |
| 299 helper.AddData(data.get()); |
| 300 |
| 301 HttpNetworkTransaction* trans = helper.trans(); |
| 302 |
| 303 // Start the transaction with basic parameters. |
| 304 TestCompletionCallback callback; |
| 305 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
| 306 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 307 rv = callback.WaitForResult(); |
| 308 |
| 309 // Request the pushed path. |
| 310 const int kSize = 3000; |
| 311 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(kSize); |
| 312 scoped_ptr<HttpNetworkTransaction> trans2( |
| 313 new HttpNetworkTransaction(helper.session())); |
| 314 rv = trans2->Start(&CreateGetPushRequest(), &callback, BoundNetLog()); |
| 315 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 316 MessageLoop::current()->RunAllPending(); |
| 317 |
| 318 // The data for the pushed path may be coming in more than 1 packet. Compile |
| 319 // the results into a single string. |
| 320 std::string result; |
| 321 bool need_read_callback = true; |
| 322 RunServerPushTestCallback callback2(buf, result, need_read_callback); |
| 323 while(!data->at_read_eof()) |
| 324 { |
| 325 if(need_read_callback) { |
| 326 while((rv = trans2->Read(buf, kSize, &callback2)) > 0) { |
| 327 std::string result1(buf->data(),rv); |
| 328 result.append(result1); |
| 329 } |
| 330 need_read_callback = false; |
| 331 } |
| 332 else |
| 333 data->CompleteRead(); |
| 334 MessageLoop::current()->RunAllPending(); |
| 335 } |
| 336 |
| 337 // Verify that we consumed all test data. |
| 338 EXPECT_TRUE(data->at_read_eof()); |
| 339 EXPECT_TRUE(data->at_write_eof()); |
| 340 |
| 341 // Verify that the received push data is same as the expected push data. |
| 342 EXPECT_EQ(result.compare(expected),0) << "Received data: " |
| 343 << result |
| 344 << "||||| Expected data: " |
| 345 << expected; |
| 346 |
| 347 // Verify the SYN_REPLY. |
| 348 // Copy the response info, because trans goes away. |
| 349 *response = *trans->GetResponseInfo(); |
| 350 *response2 = *trans2->GetResponseInfo(); |
| 351 } |
| 352 |
257 private: | 353 private: |
258 bool google_get_request_initialized_; | 354 bool google_get_request_initialized_; |
259 HttpRequestInfo google_get_request_; | 355 HttpRequestInfo google_get_request_; |
| 356 HttpRequestInfo google_get_push_request_; |
260 }; | 357 }; |
261 | 358 |
262 //----------------------------------------------------------------------------- | 359 //----------------------------------------------------------------------------- |
263 // All tests are run with three different connection types: SPDY after NPN | 360 // All tests are run with three different connection types: SPDY after NPN |
264 // negotiation, SPDY without SSL, and SPDY with SSL. | 361 // negotiation, SPDY without SSL, and SPDY with SSL. |
265 INSTANTIATE_TEST_CASE_P(SpdyNetworkingTest, | 362 INSTANTIATE_TEST_CASE_P(SpdyNetworkingTest, |
266 SpdyNetworkTransactionTest, | 363 SpdyNetworkTransactionTest, |
267 ::testing::Values(SPDYNPN, SPDYNOSSL, SPDYSSL)); | 364 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); |
268 | 365 |
269 | 366 |
270 // Verify HttpNetworkTransaction constructor. | 367 // Verify HttpNetworkTransaction constructor. |
271 TEST_P(SpdyNetworkTransactionTest, Constructor) { | 368 TEST_P(SpdyNetworkTransactionTest, Constructor) { |
272 SpdySessionDependencies session_deps; | 369 SpdySessionDependencies session_deps; |
273 scoped_refptr<HttpNetworkSession> session = | 370 scoped_refptr<HttpNetworkSession> session = |
274 SpdySessionDependencies::SpdyCreateSession(&session_deps); | 371 SpdySessionDependencies::SpdyCreateSession(&session_deps); |
275 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); | 372 scoped_ptr<HttpTransaction> trans(new HttpNetworkTransaction(session)); |
276 } | 373 } |
277 | 374 |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 CreateMockRead(*resp.get(), 2), | 1104 CreateMockRead(*resp.get(), 2), |
1008 CreateMockRead(*body.get(), 3), | 1105 CreateMockRead(*body.get(), 3), |
1009 MockRead(false, 0, 0) // EOF | 1106 MockRead(false, 0, 0) // EOF |
1010 }; | 1107 }; |
1011 | 1108 |
1012 scoped_refptr<DelayedSocketData> data( | 1109 scoped_refptr<DelayedSocketData> data( |
1013 new DelayedSocketData(0, reads, arraysize(reads), | 1110 new DelayedSocketData(0, reads, arraysize(reads), |
1014 writes, arraysize(writes))); | 1111 writes, arraysize(writes))); |
1015 NormalSpdyTransactionHelper helper(request, | 1112 NormalSpdyTransactionHelper helper(request, |
1016 BoundNetLog(), GetParam()); | 1113 BoundNetLog(), GetParam()); |
| 1114 helper.RunPreTestSetup(); |
1017 helper.AddData(data.get()); | 1115 helper.AddData(data.get()); |
1018 helper.RunPreTestSetup(); | |
1019 helper.RunDefaultTest(); | 1116 helper.RunDefaultTest(); |
1020 TransactionHelperResult out = helper.output(); | 1117 TransactionHelperResult out = helper.output(); |
1021 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 1118 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
1022 } | 1119 } |
1023 | 1120 |
1024 // The client upon cancellation tries to send a RST_STREAM frame. The mock | 1121 // The client upon cancellation tries to send a RST_STREAM frame. The mock |
1025 // socket causes the TCP write to return zero. This test checks that the client | 1122 // socket causes the TCP write to return zero. This test checks that the client |
1026 // tries to queue up the RST_STREAM frame again. | 1123 // tries to queue up the RST_STREAM frame again. |
1027 TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { | 1124 TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { |
1028 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 1125 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 CreateMockRead(*body), | 1187 CreateMockRead(*body), |
1091 MockRead(true, 0, 0) // EOF | 1188 MockRead(true, 0, 0) // EOF |
1092 }; | 1189 }; |
1093 | 1190 |
1094 scoped_refptr<DelayedSocketData> data( | 1191 scoped_refptr<DelayedSocketData> data( |
1095 new DelayedSocketData(1, reads, arraysize(reads), | 1192 new DelayedSocketData(1, reads, arraysize(reads), |
1096 writes, arraysize(writes))); | 1193 writes, arraysize(writes))); |
1097 | 1194 |
1098 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 1195 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
1099 BoundNetLog(), GetParam()); | 1196 BoundNetLog(), GetParam()); |
| 1197 helper.RunPreTestSetup(); |
1100 helper.AddData(data.get()); | 1198 helper.AddData(data.get()); |
1101 helper.RunPreTestSetup(); | |
1102 | 1199 |
1103 HttpNetworkTransaction* trans = helper.trans(); | 1200 HttpNetworkTransaction* trans = helper.trans(); |
1104 | 1201 |
1105 TestCompletionCallback callback; | 1202 TestCompletionCallback callback; |
1106 int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); | 1203 int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); |
1107 EXPECT_EQ(ERR_IO_PENDING, rv); | 1204 EXPECT_EQ(ERR_IO_PENDING, rv); |
1108 rv = callback.WaitForResult(); | 1205 rv = callback.WaitForResult(); |
1109 EXPECT_EQ(OK, rv); | 1206 EXPECT_EQ(OK, rv); |
1110 | 1207 |
1111 const HttpResponseInfo* response = trans->GetResponseInfo(); | 1208 const HttpResponseInfo* response = trans->GetResponseInfo(); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 // HttpNetworkTransaction and still tries to continue Read()'ing. Any | 1381 // HttpNetworkTransaction and still tries to continue Read()'ing. Any |
1285 // MockRead will do here. | 1382 // MockRead will do here. |
1286 MockRead(true, 0, 0) // EOF | 1383 MockRead(true, 0, 0) // EOF |
1287 }; | 1384 }; |
1288 | 1385 |
1289 StaticSocketDataProvider data(reads, arraysize(reads), | 1386 StaticSocketDataProvider data(reads, arraysize(reads), |
1290 writes, arraysize(writes)); | 1387 writes, arraysize(writes)); |
1291 | 1388 |
1292 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 1389 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
1293 BoundNetLog(), GetParam()); | 1390 BoundNetLog(), GetParam()); |
| 1391 helper.RunPreTestSetup(); |
1294 helper.AddData(&data); | 1392 helper.AddData(&data); |
1295 helper.RunPreTestSetup(); | |
1296 HttpNetworkTransaction* trans = helper.trans(); | 1393 HttpNetworkTransaction* trans = helper.trans(); |
1297 | 1394 |
1298 TestCompletionCallback callback; | 1395 TestCompletionCallback callback; |
1299 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 1396 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
1300 EXPECT_EQ(ERR_IO_PENDING, rv); | 1397 EXPECT_EQ(ERR_IO_PENDING, rv); |
1301 helper.ResetTrans(); // Cancel the transaction. | 1398 helper.ResetTrans(); // Cancel the transaction. |
1302 | 1399 |
1303 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the | 1400 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
1304 // MockClientSocketFactory) are still alive. | 1401 // MockClientSocketFactory) are still alive. |
1305 MessageLoop::current()->RunAllPending(); | 1402 MessageLoop::current()->RunAllPending(); |
(...skipping 16 matching lines...) Expand all Loading... |
1322 MockRead(true, 0, 0, 4) // EOF | 1419 MockRead(true, 0, 0, 4) // EOF |
1323 }; | 1420 }; |
1324 | 1421 |
1325 scoped_refptr<OrderedSocketData> data( | 1422 scoped_refptr<OrderedSocketData> data( |
1326 new OrderedSocketData(reads, arraysize(reads), | 1423 new OrderedSocketData(reads, arraysize(reads), |
1327 writes, arraysize(writes))); | 1424 writes, arraysize(writes))); |
1328 | 1425 |
1329 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 1426 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
1330 BoundNetLog(), | 1427 BoundNetLog(), |
1331 GetParam()); | 1428 GetParam()); |
| 1429 helper.RunPreTestSetup(); |
1332 helper.AddData(data.get()); | 1430 helper.AddData(data.get()); |
1333 helper.RunPreTestSetup(); | |
1334 HttpNetworkTransaction* trans = helper.trans(); | 1431 HttpNetworkTransaction* trans = helper.trans(); |
1335 | 1432 |
1336 TestCompletionCallback callback; | 1433 TestCompletionCallback callback; |
1337 | 1434 |
1338 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 1435 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
1339 EXPECT_EQ(ERR_IO_PENDING, rv); | 1436 EXPECT_EQ(ERR_IO_PENDING, rv); |
1340 rv = callback.WaitForResult(); | 1437 rv = callback.WaitForResult(); |
1341 helper.ResetTrans(); // Cancel the transaction. | 1438 helper.ResetTrans(); // Cancel the transaction. |
1342 | 1439 |
1343 // Finish running rest of tasks. | 1440 // Finish running rest of tasks. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 | 1503 |
1407 scoped_refptr<OrderedSocketData> data( | 1504 scoped_refptr<OrderedSocketData> data( |
1408 new OrderedSocketData(reads, arraysize(reads), | 1505 new OrderedSocketData(reads, arraysize(reads), |
1409 writes, arraysize(writes))); | 1506 writes, arraysize(writes))); |
1410 scoped_refptr<DelayedSocketData> data2( | 1507 scoped_refptr<DelayedSocketData> data2( |
1411 new DelayedSocketData(0, reads2, arraysize(reads2), | 1508 new DelayedSocketData(0, reads2, arraysize(reads2), |
1412 writes2, arraysize(writes2))); | 1509 writes2, arraysize(writes2))); |
1413 | 1510 |
1414 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 1511 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
1415 BoundNetLog(), GetParam()); | 1512 BoundNetLog(), GetParam()); |
| 1513 helper.RunPreTestSetup(); |
1416 helper.AddData(data.get()); | 1514 helper.AddData(data.get()); |
1417 helper.AddData(data2.get()); | 1515 helper.AddData(data2.get()); |
1418 helper.RunPreTestSetup(); | |
1419 HttpNetworkTransaction* trans = helper.trans(); | 1516 HttpNetworkTransaction* trans = helper.trans(); |
1420 | 1517 |
1421 // Start the transaction with basic parameters. | 1518 // Start the transaction with basic parameters. |
1422 TestCompletionCallback callback; | 1519 TestCompletionCallback callback; |
1423 int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); | 1520 int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); |
1424 EXPECT_EQ(ERR_IO_PENDING, rv); | 1521 EXPECT_EQ(ERR_IO_PENDING, rv); |
1425 rv = callback.WaitForResult(); | 1522 rv = callback.WaitForResult(); |
1426 | 1523 |
1427 StartTransactionCallback callback2(helper.session(), helper); | 1524 StartTransactionCallback callback2(helper.session(), helper); |
1428 const int kSize = 3000; | 1525 const int kSize = 3000; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1465 CreateMockRead(*body.get(), 4), | 1562 CreateMockRead(*body.get(), 4), |
1466 MockRead(true, 0, 0, 5), // EOF | 1563 MockRead(true, 0, 0, 5), // EOF |
1467 }; | 1564 }; |
1468 | 1565 |
1469 scoped_refptr<OrderedSocketData> data( | 1566 scoped_refptr<OrderedSocketData> data( |
1470 new OrderedSocketData(reads, arraysize(reads), | 1567 new OrderedSocketData(reads, arraysize(reads), |
1471 writes, arraysize(writes))); | 1568 writes, arraysize(writes))); |
1472 | 1569 |
1473 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 1570 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
1474 BoundNetLog(), GetParam()); | 1571 BoundNetLog(), GetParam()); |
| 1572 helper.RunPreTestSetup(); |
1475 helper.AddData(data.get()); | 1573 helper.AddData(data.get()); |
1476 helper.RunPreTestSetup(); | |
1477 HttpNetworkTransaction* trans = helper.trans(); | 1574 HttpNetworkTransaction* trans = helper.trans(); |
1478 | 1575 |
1479 // Start the transaction with basic parameters. | 1576 // Start the transaction with basic parameters. |
1480 TestCompletionCallback callback; | 1577 TestCompletionCallback callback; |
1481 int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); | 1578 int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); |
1482 EXPECT_EQ(ERR_IO_PENDING, rv); | 1579 EXPECT_EQ(ERR_IO_PENDING, rv); |
1483 rv = callback.WaitForResult(); | 1580 rv = callback.WaitForResult(); |
1484 | 1581 |
1485 // Setup a user callback which will delete the session, and clear out the | 1582 // Setup a user callback which will delete the session, and clear out the |
1486 // memory holding the stream object. Note that the callback deletes trans. | 1583 // memory holding the stream object. Note that the callback deletes trans. |
1487 DeleteSessionCallback callback2(helper); | 1584 DeleteSessionCallback callback2(helper); |
1488 const int kSize = 3000; | 1585 const int kSize = 3000; |
1489 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); | 1586 scoped_refptr<net::IOBuffer> buf = new net::IOBuffer(kSize); |
1490 rv = trans->Read(buf, kSize, &callback2); | 1587 rv = trans->Read(buf, kSize, &callback2); |
1491 ASSERT_EQ(ERR_IO_PENDING, rv); | 1588 ASSERT_EQ(ERR_IO_PENDING, rv); |
1492 data->CompleteRead(); | 1589 data->CompleteRead(); |
1493 | 1590 |
1494 // Finish running rest of tasks. | 1591 // Finish running rest of tasks. |
1495 MessageLoop::current()->RunAllPending(); | 1592 MessageLoop::current()->RunAllPending(); |
1496 helper.VerifyDataConsumed(); | 1593 helper.VerifyDataConsumed(); |
1497 } | 1594 } |
1498 | 1595 |
| 1596 // Send a spdy request to www.google.com that gets redirected to www.foo.com. |
| 1597 TEST_P(SpdyNetworkTransactionTest, RedirectGetRequest) { |
| 1598 // These are headers which the URLRequest tacks on. |
| 1599 const char* const kExtraHeaders[] = { |
| 1600 "accept-charset", |
| 1601 "", |
| 1602 "accept-encoding", |
| 1603 "gzip,deflate", |
| 1604 "accept-language", |
| 1605 "", |
| 1606 }; |
| 1607 const SpdyHeaderInfo kSynStartHeader = make_spdy_header(spdy::SYN_STREAM); |
| 1608 const char* const kStandardGetHeaders[] = { |
| 1609 "host", |
| 1610 "www.google.com", |
| 1611 "method", |
| 1612 "GET", |
| 1613 "scheme", |
| 1614 "http", |
| 1615 "url", |
| 1616 "/", |
| 1617 "user-agent", |
| 1618 "", |
| 1619 "version", |
| 1620 "HTTP/1.1" |
| 1621 }; |
| 1622 const char* const kStandardGetHeaders2[] = { |
| 1623 "host", |
| 1624 "www.foo.com", |
| 1625 "method", |
| 1626 "GET", |
| 1627 "scheme", |
| 1628 "http", |
| 1629 "url", |
| 1630 "/index.php", |
| 1631 "user-agent", |
| 1632 "", |
| 1633 "version", |
| 1634 "HTTP/1.1" |
| 1635 }; |
| 1636 |
| 1637 // Setup writes/reads to www.google.com |
| 1638 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyPacket( |
| 1639 kSynStartHeader, kExtraHeaders, arraysize(kExtraHeaders)/2, |
| 1640 kStandardGetHeaders, arraysize(kStandardGetHeaders)/2)); |
| 1641 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyPacket( |
| 1642 kSynStartHeader, kExtraHeaders, arraysize(kExtraHeaders)/2, |
| 1643 kStandardGetHeaders2, arraysize(kStandardGetHeaders2)/2)); |
| 1644 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReplyRedirect(1)); |
| 1645 MockWrite writes[] = { |
| 1646 CreateMockWrite(*req, 1), |
| 1647 }; |
| 1648 MockRead reads[] = { |
| 1649 CreateMockRead(*resp, 2), |
| 1650 MockRead(true, 0, 0, 3) // EOF |
| 1651 }; |
| 1652 |
| 1653 // Setup writes/reads to www.foo.com |
| 1654 scoped_ptr<spdy::SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1655 scoped_ptr<spdy::SpdyFrame> body2(ConstructSpdyBodyFrame(1, true)); |
| 1656 MockWrite writes2[] = { |
| 1657 CreateMockWrite(*req2, 1), |
| 1658 }; |
| 1659 MockRead reads2[] = { |
| 1660 CreateMockRead(*resp2, 2), |
| 1661 CreateMockRead(*body2, 3), |
| 1662 MockRead(true, 0, 0, 4) // EOF |
| 1663 }; |
| 1664 scoped_refptr<OrderedSocketData> data( |
| 1665 new OrderedSocketData(reads, arraysize(reads), |
| 1666 writes, arraysize(writes))); |
| 1667 scoped_refptr<OrderedSocketData> data2( |
| 1668 new OrderedSocketData(reads2, arraysize(reads2), |
| 1669 writes2, arraysize(writes2))); |
| 1670 |
| 1671 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
| 1672 HttpNetworkTransaction::SetUseSSLOverSpdyWithoutNPN(false); |
| 1673 HttpNetworkTransaction::SetUseSpdyWithoutNPN(true); |
| 1674 TestDelegate d; |
| 1675 { |
| 1676 URLRequest r(GURL("http://www.google.com/"), &d); |
| 1677 SpdyURLRequestContext* spdy_url_request_context = |
| 1678 new SpdyURLRequestContext(); |
| 1679 r.set_context(spdy_url_request_context); |
| 1680 spdy_url_request_context->socket_factory(). |
| 1681 AddSocketDataProvider(data.get()); |
| 1682 spdy_url_request_context->socket_factory(). |
| 1683 AddSocketDataProvider(data2.get()); |
| 1684 |
| 1685 d.set_quit_on_redirect(true); |
| 1686 r.Start(); |
| 1687 MessageLoop::current()->Run(); |
| 1688 |
| 1689 EXPECT_EQ(1, d.received_redirect_count()); |
| 1690 |
| 1691 r.FollowDeferredRedirect(); |
| 1692 MessageLoop::current()->Run(); |
| 1693 EXPECT_EQ(1, d.response_started_count()); |
| 1694 EXPECT_FALSE(d.received_data_before_response()); |
| 1695 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 1696 std::string contents("hello!"); |
| 1697 EXPECT_EQ(contents, d.data_received()); |
| 1698 } |
| 1699 EXPECT_TRUE(data->at_read_eof()); |
| 1700 EXPECT_TRUE(data->at_write_eof()); |
| 1701 EXPECT_TRUE(data2->at_read_eof()); |
| 1702 EXPECT_TRUE(data2->at_write_eof()); |
| 1703 } |
| 1704 |
| 1705 // Send a spdy request to www.google.com. Get a pushed stream that redirects to |
| 1706 // www.foo.com. |
| 1707 TEST_P(SpdyNetworkTransactionTest, RedirectServerPush) { |
| 1708 // These are headers which the URLRequest tacks on. |
| 1709 const char* const kExtraHeaders[] = { |
| 1710 "accept-charset", |
| 1711 "", |
| 1712 "accept-encoding", |
| 1713 "gzip,deflate", |
| 1714 "accept-language", |
| 1715 "", |
| 1716 }; |
| 1717 const SpdyHeaderInfo kSynStartHeader = make_spdy_header(spdy::SYN_STREAM); |
| 1718 const char* const kStandardGetHeaders[] = { |
| 1719 "host", |
| 1720 "www.google.com", |
| 1721 "method", |
| 1722 "GET", |
| 1723 "scheme", |
| 1724 "http", |
| 1725 "url", |
| 1726 "/", |
| 1727 "user-agent", |
| 1728 "", |
| 1729 "version", |
| 1730 "HTTP/1.1" |
| 1731 }; |
| 1732 const char* const kStandardGetHeaders2[] = { |
| 1733 "host", |
| 1734 "www.foo.com", |
| 1735 "method", |
| 1736 "GET", |
| 1737 "scheme", |
| 1738 "http", |
| 1739 "url", |
| 1740 "/index.php", |
| 1741 "user-agent", |
| 1742 "", |
| 1743 "version", |
| 1744 "HTTP/1.1" |
| 1745 }; |
| 1746 |
| 1747 // Setup writes/reads to www.google.com |
| 1748 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyPacket( |
| 1749 kSynStartHeader, kExtraHeaders, arraysize(kExtraHeaders)/2, |
| 1750 kStandardGetHeaders, arraysize(kStandardGetHeaders)/2)); |
| 1751 scoped_ptr<spdy::SpdyFrame> req2(ConstructSpdyPacket( |
| 1752 kSynStartHeader, kExtraHeaders, arraysize(kExtraHeaders)/2, |
| 1753 kStandardGetHeaders2, arraysize(kStandardGetHeaders2)/2)); |
| 1754 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1755 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 1, "/foo.dat", |
| 1756 "301 Moved Permanently", "http://www.foo.com/index.php", |
| 1757 "http://www.foo.com/index.php")); |
| 1758 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); |
| 1759 scoped_ptr<spdy::SpdyFrame> res( |
| 1760 ConstructSpdyRstStream(2, spdy::CANCEL)); |
| 1761 MockWrite writes[] = { |
| 1762 CreateMockWrite(*req, 1), |
| 1763 CreateMockWrite(*res, 6), |
| 1764 }; |
| 1765 MockRead reads[] = { |
| 1766 CreateMockRead(*resp, 2), |
| 1767 CreateMockRead(*rep, 3), |
| 1768 CreateMockRead(*body, 4), |
| 1769 MockRead(true, ERR_IO_PENDING, 5), // Force a pause |
| 1770 MockRead(true, 0, 0, 7) // EOF |
| 1771 }; |
| 1772 |
| 1773 // Setup writes/reads to www.foo.com |
| 1774 scoped_ptr<spdy::SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1775 scoped_ptr<spdy::SpdyFrame> body2(ConstructSpdyBodyFrame(1, true)); |
| 1776 MockWrite writes2[] = { |
| 1777 CreateMockWrite(*req2, 1), |
| 1778 }; |
| 1779 MockRead reads2[] = { |
| 1780 CreateMockRead(*resp2, 2), |
| 1781 CreateMockRead(*body2, 3), |
| 1782 MockRead(true, 0, 0, 5) // EOF |
| 1783 }; |
| 1784 scoped_refptr<OrderedSocketData> data( |
| 1785 new OrderedSocketData(reads, arraysize(reads), |
| 1786 writes, arraysize(writes))); |
| 1787 scoped_refptr<OrderedSocketData> data2( |
| 1788 new OrderedSocketData(reads2, arraysize(reads2), |
| 1789 writes2, arraysize(writes2))); |
| 1790 |
| 1791 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
| 1792 HttpNetworkTransaction::SetUseSSLOverSpdyWithoutNPN(false); |
| 1793 HttpNetworkTransaction::SetUseSpdyWithoutNPN(true); |
| 1794 TestDelegate d; |
| 1795 TestDelegate d2; |
| 1796 { |
| 1797 URLRequest r(GURL("http://www.google.com/"), &d); |
| 1798 SpdyURLRequestContext* spdy_url_request_context = |
| 1799 new SpdyURLRequestContext(); |
| 1800 r.set_context(spdy_url_request_context); |
| 1801 spdy_url_request_context->socket_factory(). |
| 1802 AddSocketDataProvider(data.get()); |
| 1803 |
| 1804 r.Start(); |
| 1805 MessageLoop::current()->Run(); |
| 1806 |
| 1807 EXPECT_EQ(0, d.received_redirect_count()); |
| 1808 std::string contents("hello!"); |
| 1809 EXPECT_EQ(contents, d.data_received()); |
| 1810 |
| 1811 URLRequest r2(GURL("http://www.google.com/foo.dat"), &d2); |
| 1812 r2.set_context(spdy_url_request_context); |
| 1813 spdy_url_request_context->socket_factory(). |
| 1814 AddSocketDataProvider(data2.get()); |
| 1815 |
| 1816 d2.set_quit_on_redirect(true); |
| 1817 r2.Start(); |
| 1818 MessageLoop::current()->Run(); |
| 1819 EXPECT_EQ(1, d2.received_redirect_count()); |
| 1820 |
| 1821 r2.FollowDeferredRedirect(); |
| 1822 MessageLoop::current()->Run(); |
| 1823 EXPECT_EQ(1, d2.response_started_count()); |
| 1824 EXPECT_FALSE(d2.received_data_before_response()); |
| 1825 EXPECT_EQ(URLRequestStatus::SUCCESS, r2.status().status()); |
| 1826 std::string contents2("hello!"); |
| 1827 EXPECT_EQ(contents2, d2.data_received()); |
| 1828 } |
| 1829 data->CompleteRead(); |
| 1830 data2->CompleteRead(); |
| 1831 EXPECT_TRUE(data->at_read_eof()); |
| 1832 EXPECT_TRUE(data->at_write_eof()); |
| 1833 EXPECT_TRUE(data2->at_read_eof()); |
| 1834 EXPECT_TRUE(data2->at_write_eof()); |
| 1835 } |
| 1836 |
| 1837 TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { |
| 1838 static const unsigned char kPushBodyFrame[] = { |
| 1839 0x00, 0x00, 0x00, 0x02, // header, ID |
| 1840 0x01, 0x00, 0x00, 0x05, // FIN, length |
| 1841 'h', 'e', 'l', 'l', 'o', // "hello" |
| 1842 }; |
| 1843 |
| 1844 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 1845 MockWrite writes[] = { |
| 1846 CreateMockWrite(*req, 1), |
| 1847 }; |
| 1848 |
| 1849 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1850 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 1, "/foo.dat")); |
| 1851 MockRead reads[] = { |
| 1852 CreateMockRead(*resp, 2), |
| 1853 CreateMockRead(*rep, 3), |
| 1854 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame), |
| 1855 arraysize(kPushBodyFrame), 4), |
| 1856 MockRead(true, ERR_IO_PENDING, 5), // Force a pause |
| 1857 MockRead(true, 0, 0, 6) // EOF |
| 1858 }; |
| 1859 |
| 1860 HttpResponseInfo response; |
| 1861 HttpResponseInfo response2; |
| 1862 std::string expected_push_result("hello"); |
| 1863 RunServerPushTest(writes, arraysize(writes), reads, arraysize(reads), |
| 1864 &response, &response2, expected_push_result); |
| 1865 |
| 1866 // Verify the SYN_REPLY. |
| 1867 EXPECT_TRUE(response.headers != NULL); |
| 1868 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 1869 |
| 1870 // Verify the pushed stream. |
| 1871 EXPECT_TRUE(response2.headers != NULL); |
| 1872 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 1873 } |
| 1874 |
| 1875 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { |
| 1876 static const unsigned char kPushBodyFrame1[] = { |
| 1877 0x00, 0x00, 0x00, 0x02, // header, ID |
| 1878 0x01, 0x00, 0x00, 0x1E, // FIN, length |
| 1879 'h', 'e', 'l', 'l', 'o', // "hello" |
| 1880 }; |
| 1881 static const char kPushBodyFrame2[] = " my darling"; |
| 1882 static const char kPushBodyFrame3[] = " hello"; |
| 1883 static const char kPushBodyFrame4[] = " my baby"; |
| 1884 |
| 1885 scoped_ptr<spdy::SpdyFrame> req( |
| 1886 ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 1887 MockWrite writes[] = { |
| 1888 CreateMockWrite(*req, 1), |
| 1889 }; |
| 1890 |
| 1891 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1892 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 1, "/foo.dat")); |
| 1893 MockRead reads[] = { |
| 1894 CreateMockRead(*resp, 2), |
| 1895 CreateMockRead(*rep, 3), |
| 1896 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame1), |
| 1897 arraysize(kPushBodyFrame1), 4), |
| 1898 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame2), |
| 1899 arraysize(kPushBodyFrame2) - 1, 5), |
| 1900 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame3), |
| 1901 arraysize(kPushBodyFrame3) - 1, 6), |
| 1902 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame4), |
| 1903 arraysize(kPushBodyFrame4) - 1, 7), |
| 1904 MockRead(true, ERR_IO_PENDING, 8), // Force a pause |
| 1905 MockRead(true, 0, 0, 9) // EOF |
| 1906 }; |
| 1907 |
| 1908 HttpResponseInfo response; |
| 1909 HttpResponseInfo response2; |
| 1910 std::string expected_push_result("hello my darling hello my baby"); |
| 1911 RunServerPushTest(writes, arraysize(writes), reads, arraysize(reads), |
| 1912 &response, &response2, expected_push_result); |
| 1913 |
| 1914 // Verify the SYN_REPLY. |
| 1915 EXPECT_TRUE(response.headers != NULL); |
| 1916 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 1917 |
| 1918 // Verify the pushed stream. |
| 1919 EXPECT_TRUE(response2.headers != NULL); |
| 1920 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 1921 } |
| 1922 |
| 1923 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { |
| 1924 static const unsigned char kPushBodyFrame1[] = { |
| 1925 0x00, 0x00, 0x00, 0x02, // header, ID |
| 1926 0x01, 0x00, 0x00, 0x1E, // FIN, length |
| 1927 'h', 'e', 'l', 'l', 'o', // "hello" |
| 1928 }; |
| 1929 static const char kPushBodyFrame2[] = " my darling"; |
| 1930 static const char kPushBodyFrame3[] = " hello"; |
| 1931 static const char kPushBodyFrame4[] = " my baby"; |
| 1932 |
| 1933 scoped_ptr<spdy::SpdyFrame> req( |
| 1934 ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 1935 MockWrite writes[] = { |
| 1936 CreateMockWrite(*req, 1), |
| 1937 }; |
| 1938 |
| 1939 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1940 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 1, "/foo.dat")); |
| 1941 MockRead reads[] = { |
| 1942 CreateMockRead(*resp, 2), |
| 1943 CreateMockRead(*rep, 3), |
| 1944 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame1), |
| 1945 arraysize(kPushBodyFrame1), 4), |
| 1946 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame2), |
| 1947 arraysize(kPushBodyFrame2) - 1, 5), |
| 1948 MockRead(true, ERR_IO_PENDING, 6), // Force a pause |
| 1949 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame3), |
| 1950 arraysize(kPushBodyFrame3) - 1, 7), |
| 1951 MockRead(true, reinterpret_cast<const char*>(kPushBodyFrame4), |
| 1952 arraysize(kPushBodyFrame4) - 1, 8), |
| 1953 MockRead(true, 0, 0, 9) // EOF |
| 1954 }; |
| 1955 |
| 1956 HttpResponseInfo response; |
| 1957 HttpResponseInfo response2; |
| 1958 std::string expected_push_result("hello my darling hello my baby"); |
| 1959 RunServerPushTest(writes, arraysize(writes), reads, arraysize(reads), |
| 1960 &response, &response2, expected_push_result); |
| 1961 |
| 1962 // Verify the SYN_REPLY. |
| 1963 EXPECT_TRUE(response.headers != NULL); |
| 1964 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 1965 |
| 1966 // Verify the pushed stream. |
| 1967 EXPECT_TRUE(response2.headers != NULL); |
| 1968 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 1969 } |
| 1970 |
| 1971 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { |
| 1972 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 1973 scoped_ptr<spdy::SpdyFrame> res( |
| 1974 ConstructSpdyRstStream(2, spdy::INVALID_STREAM)); |
| 1975 MockWrite writes[] = { |
| 1976 CreateMockWrite(*req, 1), |
| 1977 CreateMockWrite(*res, 4), |
| 1978 }; |
| 1979 |
| 1980 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1981 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 0, "/foo.dat")); |
| 1982 MockRead reads[] = { |
| 1983 CreateMockRead(*resp, 2), |
| 1984 CreateMockRead(*rep, 3), |
| 1985 MockRead(true, 0, 0, 5) // EOF |
| 1986 }; |
| 1987 |
| 1988 scoped_refptr<OrderedSocketData> data( |
| 1989 new OrderedSocketData(reads, arraysize(reads), |
| 1990 writes, arraysize(writes))); |
| 1991 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 1992 BoundNetLog(), GetParam()); |
| 1993 |
| 1994 helper.RunPreTestSetup(); |
| 1995 helper.AddData(data.get()); |
| 1996 |
| 1997 HttpNetworkTransaction* trans = helper.trans(); |
| 1998 |
| 1999 // Start the transaction with basic parameters. |
| 2000 TestCompletionCallback callback; |
| 2001 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
| 2002 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2003 rv = callback.WaitForResult(); |
| 2004 data->CompleteRead(); |
| 2005 EXPECT_EQ(OK, rv); |
| 2006 |
| 2007 // Verify that we consumed all test data. |
| 2008 EXPECT_TRUE(data->at_read_eof()) << "Read count: " |
| 2009 << data->read_count() |
| 2010 << " Read index: " |
| 2011 << data->read_index(); |
| 2012 EXPECT_TRUE(data->at_write_eof()) << "Write count: " |
| 2013 << data->write_count() |
| 2014 << " Write index: " |
| 2015 << data->write_index(); |
| 2016 |
| 2017 // Verify the SYN_REPLY. |
| 2018 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 2019 EXPECT_TRUE(response.headers != NULL); |
| 2020 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2021 } |
| 2022 |
| 2023 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { |
| 2024 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 2025 scoped_ptr<spdy::SpdyFrame> res( |
| 2026 ConstructSpdyRstStream(2, spdy::INVALID_ASSOCIATED_STREAM)); |
| 2027 MockWrite writes[] = { |
| 2028 CreateMockWrite(*req, 1), |
| 2029 CreateMockWrite(*res, 4), |
| 2030 }; |
| 2031 |
| 2032 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2033 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 9, "/foo.dat")); |
| 2034 MockRead reads[] = { |
| 2035 CreateMockRead(*resp, 2), |
| 2036 CreateMockRead(*rep, 3), |
| 2037 MockRead(true, 0, 0, 5) // EOF |
| 2038 }; |
| 2039 |
| 2040 scoped_refptr<OrderedSocketData> data( |
| 2041 new OrderedSocketData(reads, arraysize(reads), |
| 2042 writes, arraysize(writes))); |
| 2043 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 2044 BoundNetLog(), GetParam()); |
| 2045 |
| 2046 helper.RunPreTestSetup(); |
| 2047 helper.AddData(data.get()); |
| 2048 |
| 2049 HttpNetworkTransaction* trans = helper.trans(); |
| 2050 |
| 2051 // Start the transaction with basic parameters. |
| 2052 TestCompletionCallback callback; |
| 2053 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
| 2054 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2055 rv = callback.WaitForResult(); |
| 2056 data->CompleteRead(); |
| 2057 EXPECT_EQ(OK, rv); |
| 2058 |
| 2059 // Verify that we consumed all test data. |
| 2060 EXPECT_TRUE(data->at_read_eof()) << "Read count: " |
| 2061 << data->read_count() |
| 2062 << " Read index: " |
| 2063 << data->read_index(); |
| 2064 EXPECT_TRUE(data->at_write_eof()) << "Write count: " |
| 2065 << data->write_count() |
| 2066 << " Write index: " |
| 2067 << data->write_index(); |
| 2068 |
| 2069 // Verify the SYN_REPLY. |
| 2070 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 2071 EXPECT_TRUE(response.headers != NULL); |
| 2072 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2073 } |
| 2074 |
| 2075 TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { |
| 2076 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 2077 scoped_ptr<spdy::SpdyFrame> res( |
| 2078 ConstructSpdyRstStream(2, spdy::PROTOCOL_ERROR)); |
| 2079 MockWrite writes[] = { |
| 2080 CreateMockWrite(*req, 1), |
| 2081 CreateMockWrite(*res, 4), |
| 2082 }; |
| 2083 |
| 2084 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2085 scoped_ptr<spdy::SpdyFrame> rep(ConstructSpdyPush(NULL, 0, 2, 1)); |
| 2086 MockRead reads[] = { |
| 2087 CreateMockRead(*resp, 2), |
| 2088 CreateMockRead(*rep, 3), |
| 2089 MockRead(true, 0, 0, 5) // EOF |
| 2090 }; |
| 2091 |
| 2092 scoped_refptr<OrderedSocketData> data( |
| 2093 new OrderedSocketData(reads, arraysize(reads), |
| 2094 writes, arraysize(writes))); |
| 2095 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 2096 BoundNetLog(), GetParam()); |
| 2097 |
| 2098 helper.RunPreTestSetup(); |
| 2099 helper.AddData(data.get()); |
| 2100 |
| 2101 HttpNetworkTransaction* trans = helper.trans(); |
| 2102 |
| 2103 // Start the transaction with basic parameters. |
| 2104 TestCompletionCallback callback; |
| 2105 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
| 2106 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2107 rv = callback.WaitForResult(); |
| 2108 data->CompleteRead(); |
| 2109 EXPECT_EQ(OK, rv); |
| 2110 // Verify that we consumed all test data. |
| 2111 EXPECT_TRUE(data->at_read_eof()) << "Read count: " |
| 2112 << data->read_count() |
| 2113 << " Read index: " |
| 2114 << data->read_index(); |
| 2115 EXPECT_TRUE(data->at_write_eof()) << "Write count: " |
| 2116 << data->write_count() |
| 2117 << " Write index: " |
| 2118 << data->write_index(); |
| 2119 |
| 2120 // Verify the SYN_REPLY. |
| 2121 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 2122 EXPECT_TRUE(response.headers != NULL); |
| 2123 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2124 } |
| 2125 |
1499 // Verify that various SynReply headers parse correctly through the | 2126 // Verify that various SynReply headers parse correctly through the |
1500 // HTTP layer. | 2127 // HTTP layer. |
1501 TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) { | 2128 TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) { |
1502 struct SynReplyHeadersTests { | 2129 struct SynReplyHeadersTests { |
1503 int num_headers; | 2130 int num_headers; |
1504 const char* extra_headers[5]; | 2131 const char* extra_headers[5]; |
1505 const char* expected_headers; | 2132 const char* expected_headers; |
1506 } test_cases[] = { | 2133 } test_cases[] = { |
1507 // This uses a multi-valued cookie header. | 2134 // This uses a multi-valued cookie header. |
1508 { 2, | 2135 { 2, |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2034 | 2661 |
2035 scoped_refptr<DelayedSocketData> data( | 2662 scoped_refptr<DelayedSocketData> data( |
2036 new DelayedSocketData(1, reads, arraysize(reads), | 2663 new DelayedSocketData(1, reads, arraysize(reads), |
2037 writes, arraysize(writes))); | 2664 writes, arraysize(writes))); |
2038 | 2665 |
2039 | 2666 |
2040 TestCompletionCallback callback; | 2667 TestCompletionCallback callback; |
2041 | 2668 |
2042 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 2669 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2043 BoundNetLog(), GetParam()); | 2670 BoundNetLog(), GetParam()); |
| 2671 helper.RunPreTestSetup(); |
2044 helper.AddData(data.get()); | 2672 helper.AddData(data.get()); |
2045 helper.RunPreTestSetup(); | |
2046 HttpNetworkTransaction* trans = helper.trans(); | 2673 HttpNetworkTransaction* trans = helper.trans(); |
2047 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 2674 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
2048 EXPECT_EQ(ERR_IO_PENDING, rv); | 2675 EXPECT_EQ(ERR_IO_PENDING, rv); |
2049 | 2676 |
2050 TransactionHelperResult out = helper.output(); | 2677 TransactionHelperResult out = helper.output(); |
2051 out.rv = callback.WaitForResult(); | 2678 out.rv = callback.WaitForResult(); |
2052 EXPECT_EQ(out.rv, OK); | 2679 EXPECT_EQ(out.rv, OK); |
2053 | 2680 |
2054 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2681 const HttpResponseInfo* response = trans->GetResponseInfo(); |
2055 EXPECT_TRUE(response->headers != NULL); | 2682 EXPECT_TRUE(response->headers != NULL); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2113 CreateMockRead(*resp), | 2740 CreateMockRead(*resp), |
2114 CreateMockRead(*body), | 2741 CreateMockRead(*body), |
2115 MockRead(true, 0, 0) // EOF | 2742 MockRead(true, 0, 0) // EOF |
2116 }; | 2743 }; |
2117 | 2744 |
2118 scoped_refptr<DelayedSocketData> data( | 2745 scoped_refptr<DelayedSocketData> data( |
2119 new DelayedSocketData(connects[index], 1, reads, arraysize(reads), | 2746 new DelayedSocketData(connects[index], 1, reads, arraysize(reads), |
2120 writes, arraysize(writes))); | 2747 writes, arraysize(writes))); |
2121 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 2748 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2122 BoundNetLog(), GetParam()); | 2749 BoundNetLog(), GetParam()); |
| 2750 helper.RunPreTestSetup(); |
2123 helper.AddData(data.get()); | 2751 helper.AddData(data.get()); |
2124 helper.RunPreTestSetup(); | |
2125 | 2752 |
2126 // Set up http fallback data. | 2753 // Set up http fallback data. |
2127 MockRead http_fallback_data[] = { | 2754 MockRead http_fallback_data[] = { |
2128 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | 2755 MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
2129 MockRead("hello world!!!"), | 2756 MockRead("hello world!!!"), |
2130 MockRead(true, OK), | 2757 MockRead(true, OK), |
2131 }; | 2758 }; |
2132 | 2759 |
2133 scoped_ptr<StaticSocketDataProvider> http_fallback( | 2760 scoped_ptr<StaticSocketDataProvider> http_fallback( |
2134 new StaticSocketDataProvider(http_fallback_data, | 2761 new StaticSocketDataProvider(http_fallback_data, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2197 MockRead(true, combined_data_frames, combined_data_frames_len), | 2824 MockRead(true, combined_data_frames, combined_data_frames_len), |
2198 MockRead(true, 0, 0) // EOF | 2825 MockRead(true, 0, 0) // EOF |
2199 }; | 2826 }; |
2200 | 2827 |
2201 scoped_refptr<DelayedSocketData> data( | 2828 scoped_refptr<DelayedSocketData> data( |
2202 new DelayedSocketData(1, reads, arraysize(reads), | 2829 new DelayedSocketData(1, reads, arraysize(reads), |
2203 writes, arraysize(writes))); | 2830 writes, arraysize(writes))); |
2204 | 2831 |
2205 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 2832 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2206 BoundNetLog(), GetParam()); | 2833 BoundNetLog(), GetParam()); |
| 2834 helper.RunPreTestSetup(); |
2207 helper.AddData(data.get()); | 2835 helper.AddData(data.get()); |
2208 helper.RunPreTestSetup(); | |
2209 HttpNetworkTransaction* trans = helper.trans(); | 2836 HttpNetworkTransaction* trans = helper.trans(); |
2210 | 2837 |
2211 TestCompletionCallback callback; | 2838 TestCompletionCallback callback; |
2212 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 2839 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
2213 EXPECT_EQ(ERR_IO_PENDING, rv); | 2840 EXPECT_EQ(ERR_IO_PENDING, rv); |
2214 | 2841 |
2215 TransactionHelperResult out = helper.output(); | 2842 TransactionHelperResult out = helper.output(); |
2216 out.rv = callback.WaitForResult(); | 2843 out.rv = callback.WaitForResult(); |
2217 EXPECT_EQ(out.rv, OK); | 2844 EXPECT_EQ(out.rv, OK); |
2218 | 2845 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2292 MockRead(true, combined_frames, combined_frames_len), | 2919 MockRead(true, combined_frames, combined_frames_len), |
2293 MockRead(true, 0, 0) // EOF | 2920 MockRead(true, 0, 0) // EOF |
2294 }; | 2921 }; |
2295 | 2922 |
2296 scoped_refptr<DelayedSocketData> data( | 2923 scoped_refptr<DelayedSocketData> data( |
2297 new DelayedSocketData(1, reads, arraysize(reads), | 2924 new DelayedSocketData(1, reads, arraysize(reads), |
2298 writes, arraysize(writes))); | 2925 writes, arraysize(writes))); |
2299 | 2926 |
2300 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 2927 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2301 BoundNetLog(), GetParam()); | 2928 BoundNetLog(), GetParam()); |
| 2929 helper.RunPreTestSetup(); |
2302 helper.AddData(data.get()); | 2930 helper.AddData(data.get()); |
2303 helper.RunPreTestSetup(); | |
2304 HttpNetworkTransaction* trans = helper.trans(); | 2931 HttpNetworkTransaction* trans = helper.trans(); |
2305 | 2932 |
2306 TestCompletionCallback callback; | 2933 TestCompletionCallback callback; |
2307 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 2934 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
2308 EXPECT_EQ(ERR_IO_PENDING, rv); | 2935 EXPECT_EQ(ERR_IO_PENDING, rv); |
2309 | 2936 |
2310 TransactionHelperResult out = helper.output(); | 2937 TransactionHelperResult out = helper.output(); |
2311 out.rv = callback.WaitForResult(); | 2938 out.rv = callback.WaitForResult(); |
2312 EXPECT_EQ(out.rv, OK); | 2939 EXPECT_EQ(out.rv, OK); |
2313 | 2940 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2380 MockRead(true, combined_data_frames, combined_data_frames_len), | 3007 MockRead(true, combined_data_frames, combined_data_frames_len), |
2381 MockRead(true, 0, 0) // EOF | 3008 MockRead(true, 0, 0) // EOF |
2382 }; | 3009 }; |
2383 | 3010 |
2384 scoped_refptr<DelayedSocketData> data( | 3011 scoped_refptr<DelayedSocketData> data( |
2385 new DelayedSocketData(1, reads, arraysize(reads), | 3012 new DelayedSocketData(1, reads, arraysize(reads), |
2386 writes, arraysize(writes))); | 3013 writes, arraysize(writes))); |
2387 | 3014 |
2388 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 3015 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2389 BoundNetLog(), GetParam()); | 3016 BoundNetLog(), GetParam()); |
| 3017 helper.RunPreTestSetup(); |
2390 helper.AddData(data.get()); | 3018 helper.AddData(data.get()); |
2391 helper.RunPreTestSetup(); | |
2392 HttpNetworkTransaction* trans = helper.trans(); | 3019 HttpNetworkTransaction* trans = helper.trans(); |
2393 | 3020 |
2394 TestCompletionCallback callback; | 3021 TestCompletionCallback callback; |
2395 | 3022 |
2396 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 3023 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
2397 EXPECT_EQ(ERR_IO_PENDING, rv); | 3024 EXPECT_EQ(ERR_IO_PENDING, rv); |
2398 | 3025 |
2399 TransactionHelperResult out = helper.output(); | 3026 TransactionHelperResult out = helper.output(); |
2400 out.rv = callback.WaitForResult(); | 3027 out.rv = callback.WaitForResult(); |
2401 EXPECT_EQ(out.rv, OK); | 3028 EXPECT_EQ(out.rv, OK); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2460 CreateMockRead(*data_frame), | 3087 CreateMockRead(*data_frame), |
2461 MockRead(true, 0, 0) // EOF | 3088 MockRead(true, 0, 0) // EOF |
2462 }; | 3089 }; |
2463 | 3090 |
2464 scoped_refptr<DelayedSocketData> data( | 3091 scoped_refptr<DelayedSocketData> data( |
2465 new DelayedSocketData(1, reads, arraysize(reads), | 3092 new DelayedSocketData(1, reads, arraysize(reads), |
2466 writes, arraysize(writes))); | 3093 writes, arraysize(writes))); |
2467 | 3094 |
2468 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 3095 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2469 BoundNetLog(), GetParam()); | 3096 BoundNetLog(), GetParam()); |
| 3097 helper.RunPreTestSetup(); |
2470 helper.AddData(data.get()); | 3098 helper.AddData(data.get()); |
2471 helper.RunPreTestSetup(); | |
2472 HttpNetworkTransaction* trans = helper.trans(); | 3099 HttpNetworkTransaction* trans = helper.trans(); |
2473 TestCompletionCallback callback; | 3100 TestCompletionCallback callback; |
2474 | 3101 |
2475 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 3102 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
2476 EXPECT_EQ(ERR_IO_PENDING, rv); | 3103 EXPECT_EQ(ERR_IO_PENDING, rv); |
2477 | 3104 |
2478 TransactionHelperResult out = helper.output(); | 3105 TransactionHelperResult out = helper.output(); |
2479 out.rv = callback.WaitForResult(); | 3106 out.rv = callback.WaitForResult(); |
2480 EXPECT_EQ(out.rv, OK); | 3107 EXPECT_EQ(out.rv, OK); |
2481 | 3108 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2528 0, // Data Length | 3155 0, // Data Length |
2529 spdy::DATA_FLAG_NONE // Data Flags | 3156 spdy::DATA_FLAG_NONE // Data Flags |
2530 }; | 3157 }; |
2531 static const char* const kExtraHeaders[] = { | 3158 static const char* const kExtraHeaders[] = { |
2532 "status", "200", | 3159 "status", "200", |
2533 "version", "HTTP/1.1" | 3160 "version", "HTTP/1.1" |
2534 }; | 3161 }; |
2535 | 3162 |
2536 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 3163 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2537 BoundNetLog(), GetParam()); | 3164 BoundNetLog(), GetParam()); |
| 3165 helper.RunPreTestSetup(); |
2538 | 3166 |
2539 // Verify that no settings exist initially. | 3167 // Verify that no settings exist initially. |
2540 HostPortPair host_port_pair("www.google.com", helper.port()); | 3168 HostPortPair host_port_pair("www.google.com", helper.port()); |
2541 EXPECT_TRUE(helper.session()->spdy_settings().Get(host_port_pair).empty()); | 3169 EXPECT_TRUE(helper.session()->spdy_settings().Get(host_port_pair).empty()); |
2542 | 3170 |
2543 // Construct the request. | 3171 // Construct the request. |
2544 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 3172 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
2545 MockWrite writes[] = { CreateMockWrite(*req) }; | 3173 MockWrite writes[] = { CreateMockWrite(*req) }; |
2546 | 3174 |
2547 // Construct the reply. | 3175 // Construct the reply. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2582 MockRead reads[] = { | 3210 MockRead reads[] = { |
2583 CreateMockRead(*reply), | 3211 CreateMockRead(*reply), |
2584 CreateMockRead(*body), | 3212 CreateMockRead(*body), |
2585 CreateMockRead(*settings_frame), | 3213 CreateMockRead(*settings_frame), |
2586 MockRead(true, 0, 0) // EOF | 3214 MockRead(true, 0, 0) // EOF |
2587 }; | 3215 }; |
2588 | 3216 |
2589 scoped_refptr<DelayedSocketData> data( | 3217 scoped_refptr<DelayedSocketData> data( |
2590 new DelayedSocketData(1, reads, arraysize(reads), | 3218 new DelayedSocketData(1, reads, arraysize(reads), |
2591 writes, arraysize(writes))); | 3219 writes, arraysize(writes))); |
2592 helper.RunToCompletion(data.get()); | 3220 helper.AddData(data.get()); |
| 3221 helper.RunDefaultTest(); |
| 3222 helper.VerifyDataConsumed(); |
2593 TransactionHelperResult out = helper.output(); | 3223 TransactionHelperResult out = helper.output(); |
2594 EXPECT_EQ(OK, out.rv); | 3224 EXPECT_EQ(OK, out.rv); |
2595 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 3225 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
2596 EXPECT_EQ("hello!", out.response_data); | 3226 EXPECT_EQ("hello!", out.response_data); |
2597 | 3227 |
2598 { | 3228 { |
2599 // Verify we had two persisted settings. | 3229 // Verify we had two persisted settings. |
2600 spdy::SpdySettings saved_settings = | 3230 spdy::SpdySettings saved_settings = |
2601 helper.session()->spdy_settings().Get(host_port_pair); | 3231 helper.session()->spdy_settings().Get(host_port_pair); |
2602 ASSERT_EQ(2u, saved_settings.size()); | 3232 ASSERT_EQ(2u, saved_settings.size()); |
(...skipping 30 matching lines...) Expand all Loading... |
2633 0, // Data Length | 3263 0, // Data Length |
2634 spdy::DATA_FLAG_NONE // Data Flags | 3264 spdy::DATA_FLAG_NONE // Data Flags |
2635 }; | 3265 }; |
2636 static const char* kExtraHeaders[] = { | 3266 static const char* kExtraHeaders[] = { |
2637 "status", "200", | 3267 "status", "200", |
2638 "version", "HTTP/1.1" | 3268 "version", "HTTP/1.1" |
2639 }; | 3269 }; |
2640 | 3270 |
2641 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 3271 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2642 BoundNetLog(), GetParam()); | 3272 BoundNetLog(), GetParam()); |
| 3273 helper.RunPreTestSetup(); |
2643 | 3274 |
2644 // Verify that no settings exist initially. | 3275 // Verify that no settings exist initially. |
2645 HostPortPair host_port_pair("www.google.com", helper.port()); | 3276 HostPortPair host_port_pair("www.google.com", helper.port()); |
2646 EXPECT_TRUE(helper.session()->spdy_settings().Get(host_port_pair).empty()); | 3277 EXPECT_TRUE(helper.session()->spdy_settings().Get(host_port_pair).empty()); |
2647 | 3278 |
2648 unsigned int kSampleId1 = 0x1; | 3279 unsigned int kSampleId1 = 0x1; |
2649 unsigned int kSampleValue1 = 0x0a0a0a0a; | 3280 unsigned int kSampleValue1 = 0x0a0a0a0a; |
2650 unsigned int kSampleId2 = 0xababab; | 3281 unsigned int kSampleId2 = 0xababab; |
2651 unsigned int kSampleValue2 = 0x0c0c0c0c; | 3282 unsigned int kSampleValue2 = 0x0c0c0c0c; |
2652 // Manually insert settings into the SpdySettingsStorage here. | 3283 // Manually insert settings into the SpdySettingsStorage here. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2691 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); | 3322 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); |
2692 MockRead reads[] = { | 3323 MockRead reads[] = { |
2693 CreateMockRead(*reply), | 3324 CreateMockRead(*reply), |
2694 CreateMockRead(*body), | 3325 CreateMockRead(*body), |
2695 MockRead(true, 0, 0) // EOF | 3326 MockRead(true, 0, 0) // EOF |
2696 }; | 3327 }; |
2697 | 3328 |
2698 scoped_refptr<DelayedSocketData> data( | 3329 scoped_refptr<DelayedSocketData> data( |
2699 new DelayedSocketData(2, reads, arraysize(reads), | 3330 new DelayedSocketData(2, reads, arraysize(reads), |
2700 writes, arraysize(writes))); | 3331 writes, arraysize(writes))); |
2701 helper.RunToCompletion(data.get()); | 3332 helper.AddData(data.get()); |
| 3333 helper.RunDefaultTest(); |
| 3334 helper.VerifyDataConsumed(); |
2702 TransactionHelperResult out = helper.output(); | 3335 TransactionHelperResult out = helper.output(); |
2703 EXPECT_EQ(OK, out.rv); | 3336 EXPECT_EQ(OK, out.rv); |
2704 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 3337 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
2705 EXPECT_EQ("hello!", out.response_data); | 3338 EXPECT_EQ("hello!", out.response_data); |
2706 | 3339 |
2707 { | 3340 { |
2708 // Verify we had two persisted settings. | 3341 // Verify we had two persisted settings. |
2709 spdy::SpdySettings saved_settings = | 3342 spdy::SpdySettings saved_settings = |
2710 helper.session()->spdy_settings().Get(host_port_pair); | 3343 helper.session()->spdy_settings().Get(host_port_pair); |
2711 ASSERT_EQ(2u, saved_settings.size()); | 3344 ASSERT_EQ(2u, saved_settings.size()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2802 CreateMockRead(*resp), | 3435 CreateMockRead(*resp), |
2803 MockRead(false, 0, 0) // EOF | 3436 MockRead(false, 0, 0) // EOF |
2804 }; | 3437 }; |
2805 | 3438 |
2806 scoped_refptr<DelayedSocketData> data( | 3439 scoped_refptr<DelayedSocketData> data( |
2807 new DelayedSocketData(1, reads, arraysize(reads), | 3440 new DelayedSocketData(1, reads, arraysize(reads), |
2808 writes, arraysize(writes))); | 3441 writes, arraysize(writes))); |
2809 BoundNetLog log; | 3442 BoundNetLog log; |
2810 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 3443 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
2811 log, GetParam()); | 3444 log, GetParam()); |
| 3445 helper.RunPreTestSetup(); |
2812 helper.AddData(data.get()); | 3446 helper.AddData(data.get()); |
2813 helper.RunPreTestSetup(); | |
2814 HttpNetworkTransaction* trans = helper.trans(); | 3447 HttpNetworkTransaction* trans = helper.trans(); |
2815 | 3448 |
2816 TestCompletionCallback callback; | 3449 TestCompletionCallback callback; |
2817 TransactionHelperResult out; | 3450 TransactionHelperResult out; |
2818 out.rv = trans->Start(&CreateGetRequest(), &callback, log); | 3451 out.rv = trans->Start(&CreateGetRequest(), &callback, log); |
2819 | 3452 |
2820 EXPECT_EQ(out.rv, ERR_IO_PENDING); | 3453 EXPECT_EQ(out.rv, ERR_IO_PENDING); |
2821 out.rv = callback.WaitForResult(); | 3454 out.rv = callback.WaitForResult(); |
2822 EXPECT_EQ(out.rv, OK); | 3455 EXPECT_EQ(out.rv, OK); |
2823 | 3456 |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3163 rv = ReadTransaction(trans.get(), &response_data); | 3796 rv = ReadTransaction(trans.get(), &response_data); |
3164 EXPECT_EQ(OK, rv); | 3797 EXPECT_EQ(OK, rv); |
3165 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 3798 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
3166 EXPECT_EQ("hello!", response_data); | 3799 EXPECT_EQ("hello!", response_data); |
3167 } | 3800 } |
3168 | 3801 |
3169 helper.VerifyDataConsumed(); | 3802 helper.VerifyDataConsumed(); |
3170 } | 3803 } |
3171 } | 3804 } |
3172 } // namespace net | 3805 } // namespace net |
OLD | NEW |