| 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 4437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4448 new DelayedSocketData(1, reads, arraysize(reads), | 4448 new DelayedSocketData(1, reads, arraysize(reads), |
| 4449 writes, arraysize(writes))); | 4449 writes, arraysize(writes))); |
| 4450 helper.AddData(data.get()); | 4450 helper.AddData(data.get()); |
| 4451 helper.RunDefaultTest(); | 4451 helper.RunDefaultTest(); |
| 4452 helper.VerifyDataConsumed(); | 4452 helper.VerifyDataConsumed(); |
| 4453 TransactionHelperResult out = helper.output(); | 4453 TransactionHelperResult out = helper.output(); |
| 4454 EXPECT_EQ(OK, out.rv); | 4454 EXPECT_EQ(OK, out.rv); |
| 4455 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 4455 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4456 EXPECT_EQ("hello!", out.response_data); | 4456 EXPECT_EQ("hello!", out.response_data); |
| 4457 | 4457 |
| 4458 // TODO(rtenneti): Persist spdy settings. | |
| 4459 #ifdef PERSIST_SPDY_SETTINGS | |
| 4460 { | 4458 { |
| 4461 // Verify we had two persisted settings. | 4459 // Verify we had two persisted settings. |
| 4462 spdy::SpdySettings saved_settings = | 4460 const spdy::SettingsMap& settings_map = |
| 4463 spdy_session_pool->http_server_properties()->GetSpdySettings( | 4461 spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4464 host_port_pair); | 4462 host_port_pair); |
| 4465 ASSERT_EQ(2u, saved_settings.size()); | 4463 ASSERT_EQ(2u, settings_map.size()); |
| 4466 | 4464 |
| 4467 // Verify the first persisted setting. | 4465 // Verify the first persisted setting. |
| 4468 spdy::SpdySetting setting = saved_settings.front(); | 4466 spdy::SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); |
| 4469 saved_settings.pop_front(); | 4467 EXPECT_NE(it1, settings_map.end()); |
| 4470 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, setting.first.flags()); | 4468 spdy::SettingsFlagsAndValue flags_and_value1 = it1->second; |
| 4471 EXPECT_EQ(kSampleId1, setting.first.id()); | 4469 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, flags_and_value1.first); |
| 4472 EXPECT_EQ(kSampleValue1, setting.second); | 4470 EXPECT_EQ(kSampleValue1, flags_and_value1.second); |
| 4473 | 4471 |
| 4474 // Verify the second persisted setting. | 4472 // Verify the second persisted setting. |
| 4475 setting = saved_settings.front(); | 4473 spdy::SettingsMap::const_iterator it3 = settings_map.find(kSampleId3); |
| 4476 saved_settings.pop_front(); | 4474 EXPECT_NE(it3, settings_map.end()); |
| 4477 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, setting.first.flags()); | 4475 spdy::SettingsFlagsAndValue flags_and_value3 = it3->second; |
| 4478 EXPECT_EQ(kSampleId3, setting.first.id()); | 4476 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, flags_and_value3.first); |
| 4479 EXPECT_EQ(kSampleValue3, setting.second); | 4477 EXPECT_EQ(kSampleValue3, flags_and_value3.second); |
| 4480 } | 4478 } |
| 4481 #endif | |
| 4482 } | 4479 } |
| 4483 | 4480 |
| 4484 // Test that when there are settings saved that they are sent back to the | 4481 // Test that when there are settings saved that they are sent back to the |
| 4485 // server upon session establishment. | 4482 // server upon session establishment. |
| 4486 TEST_P(SpdyNetworkTransactionSpdy3Test, SettingsPlayback) { | 4483 TEST_P(SpdyNetworkTransactionSpdy3Test, SettingsPlayback) { |
| 4487 static const SpdyHeaderInfo kSynReplyInfo = { | 4484 static const SpdyHeaderInfo kSynReplyInfo = { |
| 4488 spdy::SYN_REPLY, // Syn Reply | 4485 spdy::SYN_REPLY, // Syn Reply |
| 4489 1, // Stream ID | 4486 1, // Stream ID |
| 4490 0, // Associated Stream ID | 4487 0, // Associated Stream ID |
| 4491 net::ConvertRequestPriorityToSpdyPriority(LOWEST), | 4488 net::ConvertRequestPriorityToSpdyPriority(LOWEST), |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4511 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); | 4508 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 4512 EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( | 4509 EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4513 host_port_pair).empty()); | 4510 host_port_pair).empty()); |
| 4514 | 4511 |
| 4515 unsigned int kSampleId1 = 0x1; | 4512 unsigned int kSampleId1 = 0x1; |
| 4516 unsigned int kSampleValue1 = 0x0a0a0a0a; | 4513 unsigned int kSampleValue1 = 0x0a0a0a0a; |
| 4517 unsigned int kSampleId2 = 0xababab; | 4514 unsigned int kSampleId2 = 0xababab; |
| 4518 unsigned int kSampleValue2 = 0x0c0c0c0c; | 4515 unsigned int kSampleValue2 = 0x0c0c0c0c; |
| 4519 // Manually insert settings into the SpdySettingsStorage here. | 4516 // Manually insert settings into the SpdySettingsStorage here. |
| 4520 { | 4517 { |
| 4521 spdy::SpdySettings settings; | |
| 4522 // First add a persisted setting | 4518 // First add a persisted setting |
| 4523 spdy::SettingsFlagsAndId setting1(spdy::SETTINGS_FLAG_PLEASE_PERSIST, | 4519 spdy::SettingsFlagsAndValue flags_and_value1( |
| 4524 kSampleId1); | 4520 spdy::SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue1); |
| 4525 settings.push_back(std::make_pair(setting1, kSampleValue1)); | 4521 spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4522 host_port_pair, kSampleId1, flags_and_value1); |
| 4523 |
| 4526 // Next add another persisted setting | 4524 // Next add another persisted setting |
| 4527 spdy::SettingsFlagsAndId setting2(spdy::SETTINGS_FLAG_PLEASE_PERSIST, | 4525 spdy::SettingsFlagsAndValue flags_and_value2( |
| 4528 kSampleId2); | 4526 spdy::SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue2); |
| 4529 settings.push_back(std::make_pair(setting2, kSampleValue2)); | 4527 spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4530 | 4528 host_port_pair, kSampleId2, flags_and_value2); |
| 4531 spdy_session_pool->http_server_properties()->SetSpdySettings( | |
| 4532 host_port_pair, settings); | |
| 4533 } | 4529 } |
| 4534 | 4530 |
| 4535 EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings( | 4531 EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4536 host_port_pair).size()); | 4532 host_port_pair).size()); |
| 4537 | 4533 |
| 4538 // Construct the SETTINGS frame. | 4534 // Construct the SETTINGS frame. |
| 4539 const spdy::SpdySettings& settings = | 4535 const spdy::SettingsMap& settings_map = |
| 4540 spdy_session_pool->http_server_properties()->GetSpdySettings( | 4536 spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4541 host_port_pair); | 4537 host_port_pair); |
| 4538 |
| 4539 spdy::SpdySettings settings; |
| 4540 for (spdy::SettingsMap::const_iterator i = settings_map.begin(), |
| 4541 end = settings_map.end(); i != end; ++i) { |
| 4542 const uint32 id = i->first; |
| 4543 const uint8 flags = i->second.first; |
| 4544 const uint32 val = i->second.second; |
| 4545 spdy::SettingsFlagsAndId flags_and_id(flags, id); |
| 4546 settings.push_back(spdy::SpdySetting(flags_and_id, val)); |
| 4547 } |
| 4548 |
| 4542 scoped_ptr<spdy::SpdyFrame> settings_frame(ConstructSpdySettings(settings)); | 4549 scoped_ptr<spdy::SpdyFrame> settings_frame(ConstructSpdySettings(settings)); |
| 4543 | 4550 |
| 4544 // Construct the request. | 4551 // Construct the request. |
| 4545 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 4552 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 4546 | 4553 |
| 4547 MockWrite writes[] = { | 4554 MockWrite writes[] = { |
| 4548 CreateMockWrite(*settings_frame), | 4555 CreateMockWrite(*settings_frame), |
| 4549 CreateMockWrite(*req), | 4556 CreateMockWrite(*req), |
| 4550 }; | 4557 }; |
| 4551 | 4558 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4570 helper.AddData(data.get()); | 4577 helper.AddData(data.get()); |
| 4571 helper.RunDefaultTest(); | 4578 helper.RunDefaultTest(); |
| 4572 helper.VerifyDataConsumed(); | 4579 helper.VerifyDataConsumed(); |
| 4573 TransactionHelperResult out = helper.output(); | 4580 TransactionHelperResult out = helper.output(); |
| 4574 EXPECT_EQ(OK, out.rv); | 4581 EXPECT_EQ(OK, out.rv); |
| 4575 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 4582 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4576 EXPECT_EQ("hello!", out.response_data); | 4583 EXPECT_EQ("hello!", out.response_data); |
| 4577 | 4584 |
| 4578 { | 4585 { |
| 4579 // Verify we had two persisted settings. | 4586 // Verify we had two persisted settings. |
| 4580 spdy::SpdySettings saved_settings = | 4587 const spdy::SettingsMap& settings_map = |
| 4581 spdy_session_pool->http_server_properties()->GetSpdySettings( | 4588 spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4582 host_port_pair); | 4589 host_port_pair); |
| 4583 ASSERT_EQ(2u, saved_settings.size()); | 4590 ASSERT_EQ(2u, settings_map.size()); |
| 4584 | 4591 |
| 4585 // Verify the first persisted setting. | 4592 // Verify the first persisted setting. |
| 4586 spdy::SpdySetting setting = saved_settings.front(); | 4593 spdy::SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); |
| 4587 saved_settings.pop_front(); | 4594 EXPECT_NE(it1, settings_map.end()); |
| 4588 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, setting.first.flags()); | 4595 spdy::SettingsFlagsAndValue flags_and_value1 = it1->second; |
| 4589 EXPECT_EQ(kSampleId1, setting.first.id()); | 4596 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, flags_and_value1.first); |
| 4590 EXPECT_EQ(kSampleValue1, setting.second); | 4597 EXPECT_EQ(kSampleValue1, flags_and_value1.second); |
| 4591 | 4598 |
| 4592 // Verify the second persisted setting. | 4599 // Verify the second persisted setting. |
| 4593 setting = saved_settings.front(); | 4600 spdy::SettingsMap::const_iterator it2 = settings_map.find(kSampleId2); |
| 4594 saved_settings.pop_front(); | 4601 EXPECT_NE(it2, settings_map.end()); |
| 4595 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, setting.first.flags()); | 4602 spdy::SettingsFlagsAndValue flags_and_value2 = it2->second; |
| 4596 EXPECT_EQ(kSampleId2, setting.first.id()); | 4603 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, flags_and_value2.first); |
| 4597 EXPECT_EQ(kSampleValue2, setting.second); | 4604 EXPECT_EQ(kSampleValue2, flags_and_value2.second); |
| 4598 } | 4605 } |
| 4599 } | 4606 } |
| 4600 | 4607 |
| 4601 TEST_P(SpdyNetworkTransactionSpdy3Test, GoAwayWithActiveStream) { | 4608 TEST_P(SpdyNetworkTransactionSpdy3Test, GoAwayWithActiveStream) { |
| 4602 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 4609 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 4603 MockWrite writes[] = { CreateMockWrite(*req) }; | 4610 MockWrite writes[] = { CreateMockWrite(*req) }; |
| 4604 | 4611 |
| 4605 scoped_ptr<spdy::SpdyFrame> go_away(ConstructSpdyGoAway()); | 4612 scoped_ptr<spdy::SpdyFrame> go_away(ConstructSpdyGoAway()); |
| 4606 MockRead reads[] = { | 4613 MockRead reads[] = { |
| 4607 CreateMockRead(*go_away), | 4614 CreateMockRead(*go_away), |
| (...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5867 << " Write index: " | 5874 << " Write index: " |
| 5868 << data->write_index(); | 5875 << data->write_index(); |
| 5869 | 5876 |
| 5870 // Verify the SYN_REPLY. | 5877 // Verify the SYN_REPLY. |
| 5871 HttpResponseInfo response = *trans->GetResponseInfo(); | 5878 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 5872 EXPECT_TRUE(response.headers != NULL); | 5879 EXPECT_TRUE(response.headers != NULL); |
| 5873 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5880 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5874 } | 5881 } |
| 5875 | 5882 |
| 5876 } // namespace net | 5883 } // namespace net |
| OLD | NEW |