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

Side by Side Diff: net/http/http_server_properties_impl_unittest.cc

Issue 8423028: Persist dynamically learned SPDY settings (like CWND). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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
« no previous file with comments | « net/http/http_server_properties_impl.cc ('k') | net/spdy/spdy_network_transaction_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_server_properties_impl.h" 5 #include "net/http/http_server_properties_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 impl_.Clear(); 124 impl_.Clear();
125 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); 125 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google));
126 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail)); 126 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_mail));
127 } 127 }
128 128
129 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { 129 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) {
130 base::ListValue spdy_server_list; 130 base::ListValue spdy_server_list;
131 131
132 // Check there are no spdy_servers. 132 // Check there are no spdy_servers.
133 impl_.GetSpdyServerList(&spdy_server_list); 133 impl_.GetSpdyServerList(&spdy_server_list);
134 EXPECT_EQ(0u, spdy_server_list.GetSize()); 134 EXPECT_EQ(0U, spdy_server_list.GetSize());
135 135
136 // Check empty server is not added. 136 // Check empty server is not added.
137 HostPortPair spdy_server_empty("", 443); 137 HostPortPair spdy_server_empty("", 443);
138 impl_.SetSupportsSpdy(spdy_server_empty, true); 138 impl_.SetSupportsSpdy(spdy_server_empty, true);
139 impl_.GetSpdyServerList(&spdy_server_list); 139 impl_.GetSpdyServerList(&spdy_server_list);
140 EXPECT_EQ(0u, spdy_server_list.GetSize()); 140 EXPECT_EQ(0U, spdy_server_list.GetSize());
141 141
142 std::string string_value_g; 142 std::string string_value_g;
143 std::string string_value_m; 143 std::string string_value_m;
144 HostPortPair spdy_server_google("www.google.com", 443); 144 HostPortPair spdy_server_google("www.google.com", 443);
145 std::string spdy_server_g = 145 std::string spdy_server_g =
146 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google); 146 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google);
147 HostPortPair spdy_server_mail("mail.google.com", 443); 147 HostPortPair spdy_server_mail("mail.google.com", 443);
148 std::string spdy_server_m = 148 std::string spdy_server_m =
149 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_mail); 149 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_mail);
150 150
151 // Add www.google.com:443 as not supporting SPDY. 151 // Add www.google.com:443 as not supporting SPDY.
152 impl_.SetSupportsSpdy(spdy_server_google, false); 152 impl_.SetSupportsSpdy(spdy_server_google, false);
153 impl_.GetSpdyServerList(&spdy_server_list); 153 impl_.GetSpdyServerList(&spdy_server_list);
154 EXPECT_EQ(0u, spdy_server_list.GetSize()); 154 EXPECT_EQ(0U, spdy_server_list.GetSize());
155 155
156 // Add www.google.com:443 as supporting SPDY. 156 // Add www.google.com:443 as supporting SPDY.
157 impl_.SetSupportsSpdy(spdy_server_google, true); 157 impl_.SetSupportsSpdy(spdy_server_google, true);
158 impl_.GetSpdyServerList(&spdy_server_list); 158 impl_.GetSpdyServerList(&spdy_server_list);
159 EXPECT_EQ(1u, spdy_server_list.GetSize()); 159 ASSERT_EQ(1U, spdy_server_list.GetSize());
160 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 160 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
161 ASSERT_EQ(spdy_server_g, string_value_g); 161 ASSERT_EQ(spdy_server_g, string_value_g);
162 162
163 // Add mail.google.com:443 as not supporting SPDY. 163 // Add mail.google.com:443 as not supporting SPDY.
164 impl_.SetSupportsSpdy(spdy_server_mail, false); 164 impl_.SetSupportsSpdy(spdy_server_mail, false);
165 impl_.GetSpdyServerList(&spdy_server_list); 165 impl_.GetSpdyServerList(&spdy_server_list);
166 EXPECT_EQ(1u, spdy_server_list.GetSize()); 166 ASSERT_EQ(1U, spdy_server_list.GetSize());
167 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 167 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
168 ASSERT_EQ(spdy_server_g, string_value_g); 168 ASSERT_EQ(spdy_server_g, string_value_g);
169 169
170 // Add mail.google.com:443 as supporting SPDY. 170 // Add mail.google.com:443 as supporting SPDY.
171 impl_.SetSupportsSpdy(spdy_server_mail, true); 171 impl_.SetSupportsSpdy(spdy_server_mail, true);
172 impl_.GetSpdyServerList(&spdy_server_list); 172 impl_.GetSpdyServerList(&spdy_server_list);
173 EXPECT_EQ(2u, spdy_server_list.GetSize()); 173 ASSERT_EQ(2U, spdy_server_list.GetSize());
174 174
175 // Verify www.google.com:443 and mail.google.com:443 are in the list. 175 // Verify www.google.com:443 and mail.google.com:443 are in the list.
176 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 176 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g));
177 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); 177 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m));
178 if (string_value_g.compare(spdy_server_g) == 0) { 178 if (string_value_g.compare(spdy_server_g) == 0) {
179 ASSERT_EQ(spdy_server_g, string_value_g); 179 ASSERT_EQ(spdy_server_g, string_value_g);
180 ASSERT_EQ(spdy_server_m, string_value_m); 180 ASSERT_EQ(spdy_server_m, string_value_m);
181 } else { 181 } else {
182 ASSERT_EQ(spdy_server_g, string_value_m); 182 ASSERT_EQ(spdy_server_g, string_value_m);
183 ASSERT_EQ(spdy_server_m, string_value_g); 183 ASSERT_EQ(spdy_server_m, string_value_g);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 // Turn off the static, forced alternate protocol so that tests don't 272 // Turn off the static, forced alternate protocol so that tests don't
273 // have this state. 273 // have this state.
274 HttpServerPropertiesImpl::DisableForcedAlternateProtocol(); 274 HttpServerPropertiesImpl::DisableForcedAlternateProtocol();
275 275
276 // Verify the forced protocol is off. 276 // Verify the forced protocol is off.
277 HostPortPair test_host_port_pair2("bar", 80); 277 HostPortPair test_host_port_pair2("bar", 80);
278 EXPECT_FALSE( 278 EXPECT_FALSE(
279 impl_.HasAlternateProtocol(test_host_port_pair2)); 279 impl_.HasAlternateProtocol(test_host_port_pair2));
280 } 280 }
281 281
282 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest;
283
284 TEST_F(SpdySettingsServerPropertiesTest, Initialize) {
285 HostPortPair spdy_server_google("www.google.com", 443);
286
287 // Check by initializing empty spdy settings.
288 SpdySettingsMap spdy_settings_map;
289 impl_.InitializeSpdySettingsServers(&spdy_settings_map);
290 EXPECT_TRUE(impl_.GetSpdySettings(spdy_server_google).empty());
291
292 // Check by initializing with www.google.com:443 spdy server settings.
293 spdy::SpdySettings spdy_settings;
294 spdy::SettingsFlagsAndId spdy_setting(0);
295 spdy_setting.set_flags(spdy::SETTINGS_FLAG_PERSISTED);
296 spdy_setting.set_id(1234);
297 spdy_settings.push_back(std::make_pair(spdy_setting, 31337));
298 spdy_settings_map[spdy_server_google] = spdy_settings;
299 impl_.InitializeSpdySettingsServers(&spdy_settings_map);
300 spdy::SpdySettings spdy_settings2 = impl_.GetSpdySettings(spdy_server_google);
301 ASSERT_EQ(1U, spdy_settings2.size());
302 spdy::SpdySetting spdy_setting2 = spdy_settings2.front();
303 spdy::SettingsFlagsAndId id2_ret(spdy_setting2.first);
304 EXPECT_EQ(1234U, id2_ret.id());
305 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id2_ret.flags());
306 EXPECT_EQ(31337U, spdy_settings2.front().second);
307 }
308
309 TEST_F(SpdySettingsServerPropertiesTest, SpdySettingsTest) {
310 HostPortPair spdy_server_empty("", 443);
311 spdy::SpdySettings spdy_settings0 = impl_.GetSpdySettings(spdy_server_empty);
312 EXPECT_EQ(0U, spdy_settings0.size()); // Returns kEmptySpdySettings
313
314 // Add www.google.com:443 as persisting.
315 HostPortPair spdy_server_google("www.google.com", 443);
316 spdy::SpdySettings spdy_settings1;
317 spdy::SettingsFlagsAndId id1(0);
318 id1.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST);
319 id1.set_id(1234);
320 spdy_settings1.push_back(std::make_pair(id1, 31337));
321 EXPECT_TRUE(impl_.SetSpdySettings(spdy_server_google, spdy_settings1));
322 spdy::SpdySettings spdy_settings1_ret =
323 impl_.GetSpdySettings(spdy_server_google);
324 ASSERT_EQ(1U, spdy_settings1_ret.size());
325 spdy::SpdySetting spdy_setting1_ret = spdy_settings1_ret.front();
326 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first);
327 EXPECT_EQ(1234U, id1_ret.id());
328 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags());
329 EXPECT_EQ(31337U, spdy_setting1_ret.second);
330
331 // Add mail.google.com:443 as not persisting.
332 HostPortPair spdy_server_mail("mail.google.com", 443);
333 spdy::SpdySettings spdy_settings2;
334 spdy::SettingsFlagsAndId id2(0);
335 id2.set_id(5678);
336 spdy_settings2.push_back(std::make_pair(id2, 62667));
337 EXPECT_FALSE(impl_.SetSpdySettings(spdy_server_mail, spdy_settings2));
338 spdy::SpdySettings spdy_settings2_ret =
339 impl_.GetSpdySettings(spdy_server_mail);
340 EXPECT_EQ(0U, spdy_settings2_ret.size()); // Returns kEmptySpdySettings
341
342 // Add docs.google.com:443 as persisting
343 HostPortPair spdy_server_docs("docs.google.com", 443);
344 spdy::SpdySettings spdy_settings3;
345 spdy::SettingsFlagsAndId id3(0);
346 id3.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST);
347 id3.set_id(9012);
348 spdy_settings3.push_back(std::make_pair(id3, 93997));
349 EXPECT_TRUE(impl_.SetSpdySettings(spdy_server_docs, spdy_settings3));
350 spdy::SpdySettings spdy_settings3_ret =
351 impl_.GetSpdySettings(spdy_server_docs);
352 ASSERT_EQ(1U, spdy_settings3_ret.size());
353 spdy::SpdySetting spdy_setting3_ret = spdy_settings3_ret.front();
354 spdy::SettingsFlagsAndId id3_ret(spdy_setting3_ret.first);
355 EXPECT_EQ(9012U, id3_ret.id());
356 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id3_ret.flags());
357 EXPECT_EQ(93997U, spdy_setting3_ret.second);
358 }
359
360 TEST_F(SpdySettingsServerPropertiesTest, Clear) {
361 // Add www.google.com:443 as persisting.
362 HostPortPair spdy_server_google("www.google.com", 443);
363 spdy::SpdySettings spdy_settings1;
364 spdy::SettingsFlagsAndId id1(0);
365 id1.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST);
366 id1.set_id(1234);
367 spdy_settings1.push_back(std::make_pair(id1, 31337));
368 EXPECT_TRUE(impl_.SetSpdySettings(spdy_server_google, spdy_settings1));
369 spdy::SpdySettings spdy_settings1_ret =
370 impl_.GetSpdySettings(spdy_server_google);
371 ASSERT_EQ(1U, spdy_settings1_ret.size());
372 spdy::SpdySetting spdy_setting1_ret = spdy_settings1_ret.front();
373 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first);
374 EXPECT_EQ(1234U, id1_ret.id());
375 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags());
376 EXPECT_EQ(31337U, spdy_setting1_ret.second);
377
378 // Add docs.google.com:443 as persisting
379 HostPortPair spdy_server_docs("docs.google.com", 443);
380 spdy::SpdySettings spdy_settings3;
381 spdy::SettingsFlagsAndId id3(0);
382 id3.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST);
383 id3.set_id(9012);
384 spdy_settings3.push_back(std::make_pair(id3, 93997));
385 EXPECT_TRUE(impl_.SetSpdySettings(spdy_server_docs, spdy_settings3));
386 spdy::SpdySettings spdy_settings3_ret =
387 impl_.GetSpdySettings(spdy_server_docs);
388 ASSERT_EQ(1U, spdy_settings3_ret.size());
389 spdy::SpdySetting spdy_setting3_ret = spdy_settings3_ret.front();
390 spdy::SettingsFlagsAndId id3_ret(spdy_setting3_ret.first);
391 EXPECT_EQ(9012U, id3_ret.id());
392 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id3_ret.flags());
393 EXPECT_EQ(93997U, spdy_setting3_ret.second);
394
395 impl_.Clear();
396 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_google).size());
397 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_docs).size());
398 }
399
282 } // namespace 400 } // namespace
283 401
284 } // namespace net 402 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_impl.cc ('k') | net/spdy/spdy_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698