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 "net/base/net_log_unittest.h" | 5 #include "net/base/net_log_unittest.h" |
6 #include "net/http/http_transaction_unittest.h" | 6 #include "net/http/http_transaction_unittest.h" |
7 #include "net/spdy/spdy_http_stream.h" | 7 #include "net/spdy/spdy_http_stream.h" |
8 #include "net/spdy/spdy_network_transaction.h" | 8 #include "net/spdy/spdy_network_transaction.h" |
9 #include "net/spdy/spdy_test_util.h" | 9 #include "net/spdy/spdy_test_util.h" |
10 #include "testing/platform_test.h" | 10 #include "testing/platform_test.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 writes, arraysize(writes))); | 282 writes, arraysize(writes))); |
283 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 283 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
284 BoundNetLog(), GetParam()); | 284 BoundNetLog(), GetParam()); |
285 helper.RunToCompletion(data.get()); | 285 helper.RunToCompletion(data.get()); |
286 TransactionHelperResult out = helper.output(); | 286 TransactionHelperResult out = helper.output(); |
287 EXPECT_EQ(OK, out.rv); | 287 EXPECT_EQ(OK, out.rv); |
288 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 288 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
289 EXPECT_EQ("hello!", out.response_data); | 289 EXPECT_EQ("hello!", out.response_data); |
290 } | 290 } |
291 | 291 |
| 292 TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) { |
| 293 for (RequestPriority p = HIGHEST; p < NUM_PRIORITIES; |
| 294 p = RequestPriority(p+1)) { |
| 295 // Construct the request. |
| 296 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, p)); |
| 297 MockWrite writes[] = { CreateMockWrite(*req) }; |
| 298 |
| 299 const int spdy_prio = reinterpret_cast<spdy::SpdySynStreamControlFrame*>( |
| 300 req.get())->priority(); |
| 301 // this repeats the RequestPriority-->SpdyPriority mapping from |
| 302 // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make |
| 303 // sure it's being done right. |
| 304 switch(p) { |
| 305 case HIGHEST: |
| 306 EXPECT_EQ(0, spdy_prio); |
| 307 break; |
| 308 case MEDIUM: |
| 309 EXPECT_EQ(1, spdy_prio); |
| 310 break; |
| 311 case LOW: |
| 312 case LOWEST: |
| 313 EXPECT_EQ(2, spdy_prio); |
| 314 break; |
| 315 case IDLE: |
| 316 EXPECT_EQ(3, spdy_prio); |
| 317 break; |
| 318 default: |
| 319 FAIL(); |
| 320 } |
| 321 |
| 322 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 323 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); |
| 324 MockRead reads[] = { |
| 325 CreateMockRead(*resp), |
| 326 CreateMockRead(*body), |
| 327 MockRead(true, 0, 0) // EOF |
| 328 }; |
| 329 |
| 330 scoped_refptr<DelayedSocketData> data( |
| 331 new DelayedSocketData(1, reads, arraysize(reads), |
| 332 writes, arraysize(writes))); |
| 333 HttpRequestInfo http_req = CreateGetRequest(); |
| 334 http_req.priority = p; |
| 335 |
| 336 NormalSpdyTransactionHelper helper(http_req, BoundNetLog(), GetParam()); |
| 337 helper.RunToCompletion(data.get()); |
| 338 TransactionHelperResult out = helper.output(); |
| 339 EXPECT_EQ(OK, out.rv); |
| 340 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 341 EXPECT_EQ("hello!", out.response_data); |
| 342 } |
| 343 } |
| 344 |
292 // Start three gets simultaniously; making sure that multiplexed | 345 // Start three gets simultaniously; making sure that multiplexed |
293 // streams work properly. | 346 // streams work properly. |
294 | 347 |
295 // This can't use the TransactionHelper method, since it only | 348 // This can't use the TransactionHelper method, since it only |
296 // handles a single transaction, and finishes them as soon | 349 // handles a single transaction, and finishes them as soon |
297 // as it launches them. | 350 // as it launches them. |
298 | 351 |
299 // TODO(gavinp): create a working generalized TransactionHelper that | 352 // TODO(gavinp): create a working generalized TransactionHelper that |
300 // can allow multiple streams in flight. | 353 // can allow multiple streams in flight. |
301 | 354 |
(...skipping 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 } | 1459 } |
1407 } | 1460 } |
1408 | 1461 |
1409 // Verify that various SynReply headers parse vary fields correctly | 1462 // Verify that various SynReply headers parse vary fields correctly |
1410 // through the HTTP layer, and the response matches the request. | 1463 // through the HTTP layer, and the response matches the request. |
1411 TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { | 1464 TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { |
1412 static const SpdyHeaderInfo syn_reply_info = { | 1465 static const SpdyHeaderInfo syn_reply_info = { |
1413 spdy::SYN_REPLY, // Syn Reply | 1466 spdy::SYN_REPLY, // Syn Reply |
1414 1, // Stream ID | 1467 1, // Stream ID |
1415 0, // Associated Stream ID | 1468 0, // Associated Stream ID |
1416 SPDY_PRIORITY_LOWEST, // Priority | 1469 net::ConvertRequestPriorityToSpdyPriority(LOWEST), |
| 1470 // Priority |
1417 spdy::CONTROL_FLAG_NONE, // Control Flags | 1471 spdy::CONTROL_FLAG_NONE, // Control Flags |
1418 false, // Compressed | 1472 false, // Compressed |
1419 spdy::INVALID, // Status | 1473 spdy::INVALID, // Status |
1420 NULL, // Data | 1474 NULL, // Data |
1421 0, // Data Length | 1475 0, // Data Length |
1422 spdy::DATA_FLAG_NONE // Data Flags | 1476 spdy::DATA_FLAG_NONE // Data Flags |
1423 }; | 1477 }; |
1424 // Modify the following data to change/add test cases: | 1478 // Modify the following data to change/add test cases: |
1425 struct SynReplyTests { | 1479 struct SynReplyTests { |
1426 const SpdyHeaderInfo* syn_reply; | 1480 const SpdyHeaderInfo* syn_reply; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1574 EXPECT_EQ(std::string(reply_buffer), lines) << i; | 1628 EXPECT_EQ(std::string(reply_buffer), lines) << i; |
1575 } | 1629 } |
1576 } | 1630 } |
1577 | 1631 |
1578 // Verify that we don't crash on invalid SynReply responses. | 1632 // Verify that we don't crash on invalid SynReply responses. |
1579 TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) { | 1633 TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) { |
1580 const SpdyHeaderInfo kSynStartHeader = { | 1634 const SpdyHeaderInfo kSynStartHeader = { |
1581 spdy::SYN_REPLY, // Kind = SynReply | 1635 spdy::SYN_REPLY, // Kind = SynReply |
1582 1, // Stream ID | 1636 1, // Stream ID |
1583 0, // Associated stream ID | 1637 0, // Associated stream ID |
1584 SPDY_PRIORITY_LOWEST, // Priority | 1638 net::ConvertRequestPriorityToSpdyPriority(LOWEST), |
| 1639 // Priority |
1585 spdy::CONTROL_FLAG_NONE, // Control Flags | 1640 spdy::CONTROL_FLAG_NONE, // Control Flags |
1586 false, // Compressed | 1641 false, // Compressed |
1587 spdy::INVALID, // Status | 1642 spdy::INVALID, // Status |
1588 NULL, // Data | 1643 NULL, // Data |
1589 0, // Length | 1644 0, // Length |
1590 spdy::DATA_FLAG_NONE // Data Flags | 1645 spdy::DATA_FLAG_NONE // Data Flags |
1591 }; | 1646 }; |
1592 | 1647 |
1593 struct InvalidSynReplyTests { | 1648 struct InvalidSynReplyTests { |
1594 int num_headers; | 1649 int num_headers; |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2335 helper.VerifyDataConsumed(); | 2390 helper.VerifyDataConsumed(); |
2336 } | 2391 } |
2337 | 2392 |
2338 // Test that if the server requests persistence of settings, that we save | 2393 // Test that if the server requests persistence of settings, that we save |
2339 // the settings in the SpdySettingsStorage. | 2394 // the settings in the SpdySettingsStorage. |
2340 TEST_P(SpdyNetworkTransactionTest, SettingsSaved) { | 2395 TEST_P(SpdyNetworkTransactionTest, SettingsSaved) { |
2341 static const SpdyHeaderInfo kSynReplyInfo = { | 2396 static const SpdyHeaderInfo kSynReplyInfo = { |
2342 spdy::SYN_REPLY, // Syn Reply | 2397 spdy::SYN_REPLY, // Syn Reply |
2343 1, // Stream ID | 2398 1, // Stream ID |
2344 0, // Associated Stream ID | 2399 0, // Associated Stream ID |
2345 SPDY_PRIORITY_LOWEST, // Priority | 2400 net::ConvertRequestPriorityToSpdyPriority(LOWEST), |
| 2401 // Priority |
2346 spdy::CONTROL_FLAG_NONE, // Control Flags | 2402 spdy::CONTROL_FLAG_NONE, // Control Flags |
2347 false, // Compressed | 2403 false, // Compressed |
2348 spdy::INVALID, // Status | 2404 spdy::INVALID, // Status |
2349 NULL, // Data | 2405 NULL, // Data |
2350 0, // Data Length | 2406 0, // Data Length |
2351 spdy::DATA_FLAG_NONE // Data Flags | 2407 spdy::DATA_FLAG_NONE // Data Flags |
2352 }; | 2408 }; |
2353 static const char* const kExtraHeaders[] = { | 2409 static const char* const kExtraHeaders[] = { |
2354 "status", "200", | 2410 "status", "200", |
2355 "version", "HTTP/1.1" | 2411 "version", "HTTP/1.1" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2439 } | 2495 } |
2440 } | 2496 } |
2441 | 2497 |
2442 // Test that when there are settings saved that they are sent back to the | 2498 // Test that when there are settings saved that they are sent back to the |
2443 // server upon session establishment. | 2499 // server upon session establishment. |
2444 TEST_P(SpdyNetworkTransactionTest, SettingsPlayback) { | 2500 TEST_P(SpdyNetworkTransactionTest, SettingsPlayback) { |
2445 static const SpdyHeaderInfo kSynReplyInfo = { | 2501 static const SpdyHeaderInfo kSynReplyInfo = { |
2446 spdy::SYN_REPLY, // Syn Reply | 2502 spdy::SYN_REPLY, // Syn Reply |
2447 1, // Stream ID | 2503 1, // Stream ID |
2448 0, // Associated Stream ID | 2504 0, // Associated Stream ID |
2449 SPDY_PRIORITY_LOWEST, // Priority | 2505 net::ConvertRequestPriorityToSpdyPriority(LOWEST), |
| 2506 // Priority |
2450 spdy::CONTROL_FLAG_NONE, // Control Flags | 2507 spdy::CONTROL_FLAG_NONE, // Control Flags |
2451 false, // Compressed | 2508 false, // Compressed |
2452 spdy::INVALID, // Status | 2509 spdy::INVALID, // Status |
2453 NULL, // Data | 2510 NULL, // Data |
2454 0, // Data Length | 2511 0, // Data Length |
2455 spdy::DATA_FLAG_NONE // Data Flags | 2512 spdy::DATA_FLAG_NONE // Data Flags |
2456 }; | 2513 }; |
2457 static const char* kExtraHeaders[] = { | 2514 static const char* kExtraHeaders[] = { |
2458 "status", "200", | 2515 "status", "200", |
2459 "version", "HTTP/1.1" | 2516 "version", "HTTP/1.1" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2598 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2655 const HttpResponseInfo* response = trans->GetResponseInfo(); |
2599 EXPECT_TRUE(response->headers != NULL); | 2656 EXPECT_TRUE(response->headers != NULL); |
2600 EXPECT_TRUE(response->was_fetched_via_spdy); | 2657 EXPECT_TRUE(response->was_fetched_via_spdy); |
2601 out.rv = ReadTransaction(trans, &out.response_data); | 2658 out.rv = ReadTransaction(trans, &out.response_data); |
2602 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); | 2659 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); |
2603 | 2660 |
2604 // Verify that we consumed all test data. | 2661 // Verify that we consumed all test data. |
2605 helper.VerifyDataConsumed(); | 2662 helper.VerifyDataConsumed(); |
2606 } | 2663 } |
2607 } // namespace net | 2664 } // namespace net |
OLD | NEW |