Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: net/spdy/spdy_network_transaction_spdy2_unittest.cc

Issue 9802003: SPDY - persist SPDY settings. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 4073 matching lines...) Expand 10 before | Expand all | Expand 10 after
4084 new DelayedSocketData(1, reads, arraysize(reads), 4084 new DelayedSocketData(1, reads, arraysize(reads),
4085 writes, arraysize(writes))); 4085 writes, arraysize(writes)));
4086 helper.AddData(data.get()); 4086 helper.AddData(data.get());
4087 helper.RunDefaultTest(); 4087 helper.RunDefaultTest();
4088 helper.VerifyDataConsumed(); 4088 helper.VerifyDataConsumed();
4089 TransactionHelperResult out = helper.output(); 4089 TransactionHelperResult out = helper.output();
4090 EXPECT_EQ(OK, out.rv); 4090 EXPECT_EQ(OK, out.rv);
4091 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 4091 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
4092 EXPECT_EQ("hello!", out.response_data); 4092 EXPECT_EQ("hello!", out.response_data);
4093 4093
4094 // TODO(rtenneti): Persist spdy settings.
4095 #ifdef PERSIST_SPDY_SETTINGS
4096 { 4094 {
4097 // Verify we had two persisted settings. 4095 // Verify we had two persisted settings.
4098 spdy::SpdySettings saved_settings = 4096 const spdy::SettingsMap& settings_map =
4099 spdy_session_pool->http_server_properties()->GetSpdySettings( 4097 spdy_session_pool->http_server_properties()->GetSpdySettings(
4100 host_port_pair); 4098 host_port_pair);
4101 ASSERT_EQ(2u, saved_settings.size()); 4099 ASSERT_EQ(2u, settings_map.size());
4102 4100
4103 // Verify the first persisted setting. 4101 // Verify the first persisted setting.
4104 spdy::SpdySetting setting = saved_settings.front(); 4102 spdy::SettingsMap::const_iterator it1 = settings_map.find(kSampleId1);
4105 saved_settings.pop_front(); 4103 EXPECT_NE(it1, settings_map.end());
4106 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, setting.first.flags()); 4104 spdy::SettingsFlagsAndValue flags_and_value1 = it1->second;
4107 EXPECT_EQ(kSampleId1, setting.first.id()); 4105 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, flags_and_value1.first);
4108 EXPECT_EQ(kSampleValue1, setting.second); 4106 EXPECT_EQ(kSampleValue1, flags_and_value1.second);
4109 4107
4110 // Verify the second persisted setting. 4108 // Verify the second persisted setting.
4111 setting = saved_settings.front(); 4109 spdy::SettingsMap::const_iterator it3 = settings_map.find(kSampleId3);
4112 saved_settings.pop_front(); 4110 EXPECT_NE(it3, settings_map.end());
4113 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, setting.first.flags()); 4111 spdy::SettingsFlagsAndValue flags_and_value3 = it3->second;
4114 EXPECT_EQ(kSampleId3, setting.first.id()); 4112 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, flags_and_value3.first);
4115 EXPECT_EQ(kSampleValue3, setting.second); 4113 EXPECT_EQ(kSampleValue3, flags_and_value3.second);
4116 } 4114 }
4117 #endif
4118 } 4115 }
4119 4116
4120 // Test that when there are settings saved that they are sent back to the 4117 // Test that when there are settings saved that they are sent back to the
4121 // server upon session establishment. 4118 // server upon session establishment.
4122 TEST_P(SpdyNetworkTransactionSpdy2Test, SettingsPlayback) { 4119 TEST_P(SpdyNetworkTransactionSpdy2Test, SettingsPlayback) {
4123 static const SpdyHeaderInfo kSynReplyInfo = { 4120 static const SpdyHeaderInfo kSynReplyInfo = {
4124 spdy::SYN_REPLY, // Syn Reply 4121 spdy::SYN_REPLY, // Syn Reply
4125 1, // Stream ID 4122 1, // Stream ID
4126 0, // Associated Stream ID 4123 0, // Associated Stream ID
4127 net::ConvertRequestPriorityToSpdyPriority(LOWEST), 4124 net::ConvertRequestPriorityToSpdyPriority(LOWEST),
(...skipping 19 matching lines...) Expand all
4147 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); 4144 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool();
4148 EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( 4145 EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings(
4149 host_port_pair).empty()); 4146 host_port_pair).empty());
4150 4147
4151 unsigned int kSampleId1 = 0x1; 4148 unsigned int kSampleId1 = 0x1;
4152 unsigned int kSampleValue1 = 0x0a0a0a0a; 4149 unsigned int kSampleValue1 = 0x0a0a0a0a;
4153 unsigned int kSampleId2 = 0xababab; 4150 unsigned int kSampleId2 = 0xababab;
4154 unsigned int kSampleValue2 = 0x0c0c0c0c; 4151 unsigned int kSampleValue2 = 0x0c0c0c0c;
4155 // Manually insert settings into the SpdySettingsStorage here. 4152 // Manually insert settings into the SpdySettingsStorage here.
4156 { 4153 {
4157 spdy::SpdySettings settings;
4158 // First add a persisted setting 4154 // First add a persisted setting
4159 spdy::SettingsFlagsAndId setting1(spdy::SETTINGS_FLAG_PLEASE_PERSIST, 4155 spdy::SettingsFlagsAndValue flags_and_value1(
4160 kSampleId1); 4156 spdy::SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue1);
4161 settings.push_back(std::make_pair(setting1, kSampleValue1)); 4157 spdy_session_pool->http_server_properties()->SetSpdySetting(
4158 host_port_pair, kSampleId1, flags_and_value1);
4159
4162 // Next add another persisted setting 4160 // Next add another persisted setting
4163 spdy::SettingsFlagsAndId setting2(spdy::SETTINGS_FLAG_PLEASE_PERSIST, 4161 spdy::SettingsFlagsAndValue flags_and_value2(
4164 kSampleId2); 4162 spdy::SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue2);
4165 settings.push_back(std::make_pair(setting2, kSampleValue2)); 4163 spdy_session_pool->http_server_properties()->SetSpdySetting(
4166 4164 host_port_pair, kSampleId2, flags_and_value2);
4167 spdy_session_pool->http_server_properties()->SetSpdySettings(
4168 host_port_pair, settings);
4169 } 4165 }
4170 4166
4171 EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings( 4167 EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings(
4172 host_port_pair).size()); 4168 host_port_pair).size());
4173 4169
4174 // Construct the SETTINGS frame. 4170 // Construct the SETTINGS frame.
4175 const spdy::SpdySettings& settings = 4171 const spdy::SettingsMap& settings_map =
4176 spdy_session_pool->http_server_properties()->GetSpdySettings( 4172 spdy_session_pool->http_server_properties()->GetSpdySettings(
4177 host_port_pair); 4173 host_port_pair);
4174
4175 spdy::SpdySettings settings;
4176 for (spdy::SettingsMap::const_iterator i = settings_map.begin(),
4177 end = settings_map.end(); i != end; ++i) {
4178 const uint32 id = i->first;
4179 const uint8 flags = i->second.first;
4180 const uint32 val = i->second.second;
4181 spdy::SettingsFlagsAndId flags_and_id(flags, id);
4182 settings.push_back(spdy::SpdySetting(flags_and_id, val));
4183 }
4184
4178 scoped_ptr<spdy::SpdyFrame> settings_frame(ConstructSpdySettings(settings)); 4185 scoped_ptr<spdy::SpdyFrame> settings_frame(ConstructSpdySettings(settings));
4179 4186
4180 // Construct the request. 4187 // Construct the request.
4181 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 4188 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
4182 4189
4183 MockWrite writes[] = { 4190 MockWrite writes[] = {
4184 CreateMockWrite(*settings_frame), 4191 CreateMockWrite(*settings_frame),
4185 CreateMockWrite(*req), 4192 CreateMockWrite(*req),
4186 }; 4193 };
4187 4194
(...skipping 18 matching lines...) Expand all
4206 helper.AddData(data.get()); 4213 helper.AddData(data.get());
4207 helper.RunDefaultTest(); 4214 helper.RunDefaultTest();
4208 helper.VerifyDataConsumed(); 4215 helper.VerifyDataConsumed();
4209 TransactionHelperResult out = helper.output(); 4216 TransactionHelperResult out = helper.output();
4210 EXPECT_EQ(OK, out.rv); 4217 EXPECT_EQ(OK, out.rv);
4211 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); 4218 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line);
4212 EXPECT_EQ("hello!", out.response_data); 4219 EXPECT_EQ("hello!", out.response_data);
4213 4220
4214 { 4221 {
4215 // Verify we had two persisted settings. 4222 // Verify we had two persisted settings.
4216 spdy::SpdySettings saved_settings = 4223 const spdy::SettingsMap& settings_map =
4217 spdy_session_pool->http_server_properties()->GetSpdySettings( 4224 spdy_session_pool->http_server_properties()->GetSpdySettings(
4218 host_port_pair); 4225 host_port_pair);
4219 ASSERT_EQ(2u, saved_settings.size()); 4226 ASSERT_EQ(2u, settings_map.size());
4220 4227
4221 // Verify the first persisted setting. 4228 // Verify the first persisted setting.
4222 spdy::SpdySetting setting = saved_settings.front(); 4229 spdy::SettingsMap::const_iterator it1 = settings_map.find(kSampleId1);
4223 saved_settings.pop_front(); 4230 EXPECT_NE(it1, settings_map.end());
4224 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, setting.first.flags()); 4231 spdy::SettingsFlagsAndValue flags_and_value1 = it1->second;
4225 EXPECT_EQ(kSampleId1, setting.first.id()); 4232 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, flags_and_value1.first);
4226 EXPECT_EQ(kSampleValue1, setting.second); 4233 EXPECT_EQ(kSampleValue1, flags_and_value1.second);
4227 4234
4228 // Verify the second persisted setting. 4235 // Verify the second persisted setting.
4229 setting = saved_settings.front(); 4236 spdy::SettingsMap::const_iterator it2 = settings_map.find(kSampleId2);
4230 saved_settings.pop_front(); 4237 EXPECT_NE(it2, settings_map.end());
4231 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, setting.first.flags()); 4238 spdy::SettingsFlagsAndValue flags_and_value2 = it2->second;
4232 EXPECT_EQ(kSampleId2, setting.first.id()); 4239 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, flags_and_value2.first);
4233 EXPECT_EQ(kSampleValue2, setting.second); 4240 EXPECT_EQ(kSampleValue2, flags_and_value2.second);
4234 } 4241 }
4235 } 4242 }
4236 4243
4237 TEST_P(SpdyNetworkTransactionSpdy2Test, GoAwayWithActiveStream) { 4244 TEST_P(SpdyNetworkTransactionSpdy2Test, GoAwayWithActiveStream) {
4238 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); 4245 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST));
4239 MockWrite writes[] = { CreateMockWrite(*req) }; 4246 MockWrite writes[] = { CreateMockWrite(*req) };
4240 4247
4241 scoped_ptr<spdy::SpdyFrame> go_away(ConstructSpdyGoAway()); 4248 scoped_ptr<spdy::SpdyFrame> go_away(ConstructSpdyGoAway());
4242 MockRead reads[] = { 4249 MockRead reads[] = {
4243 CreateMockRead(*go_away), 4250 CreateMockRead(*go_away),
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
5503 << " Write index: " 5510 << " Write index: "
5504 << data->write_index(); 5511 << data->write_index();
5505 5512
5506 // Verify the SYN_REPLY. 5513 // Verify the SYN_REPLY.
5507 HttpResponseInfo response = *trans->GetResponseInfo(); 5514 HttpResponseInfo response = *trans->GetResponseInfo();
5508 EXPECT_TRUE(response.headers != NULL); 5515 EXPECT_TRUE(response.headers != NULL);
5509 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); 5516 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine());
5510 } 5517 }
5511 5518
5512 } // namespace net 5519 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698