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

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

Issue 1216703002: Implement multiple alternative services per origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_manager.h" 5 #include "net/http/http_server_properties_manager.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/pref_registry_simple.h"
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 void ExpectPrefsUpdateRepeatedly() { 155 void ExpectPrefsUpdateRepeatedly() {
156 EXPECT_CALL(*http_server_props_manager_, 156 EXPECT_CALL(*http_server_props_manager_,
157 UpdatePrefsFromCacheOnNetworkThread(_)) 157 UpdatePrefsFromCacheOnNetworkThread(_))
158 .WillRepeatedly( 158 .WillRepeatedly(
159 Invoke(http_server_props_manager_.get(), 159 Invoke(http_server_props_manager_.get(),
160 &TestingHttpServerPropertiesManager:: 160 &TestingHttpServerPropertiesManager::
161 UpdatePrefsFromCacheOnNetworkThreadConcrete)); 161 UpdatePrefsFromCacheOnNetworkThreadConcrete));
162 } 162 }
163 163
164 bool HasAlternativeService(const HostPortPair& server) { 164 bool HasAlternativeService(const HostPortPair& server) {
165 const AlternativeService alternative_service = 165 const AlternativeServiceVector alternative_service_vector =
166 http_server_props_manager_->GetAlternativeService(server); 166 http_server_props_manager_->GetAlternativeServices(server);
167 return alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; 167 return !alternative_service_vector.empty();
168 } 168 }
169 169
170 //base::RunLoop loop_; 170 //base::RunLoop loop_;
171 TestingPrefServiceSimple pref_service_; 171 TestingPrefServiceSimple pref_service_;
172 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; 172 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_;
173 173
174 private: 174 private:
175 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); 175 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest);
176 }; 176 };
177 177
178 TEST_F(HttpServerPropertiesManagerTest, 178 TEST_F(HttpServerPropertiesManagerTest,
179 SingleUpdateForTwoSpdyServerPrefChanges) { 179 SingleUpdateForTwoSpdyServerPrefChanges) {
180 ExpectCacheUpdate(); 180 ExpectCacheUpdate();
181 181
182 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set 182 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set
183 // it twice. Only expect a single cache update. 183 // it twice. Only expect a single cache update.
184 184
185 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 185 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
186 HostPortPair google_server("www.google.com", 80); 186 HostPortPair google_server("www.google.com", 80);
187 HostPortPair mail_server("mail.google.com", 80); 187 HostPortPair mail_server("mail.google.com", 80);
188 188
189 // Set supports_spdy for www.google.com:80. 189 // Set supports_spdy for www.google.com:80.
190 server_pref_dict->SetBoolean("supports_spdy", true); 190 server_pref_dict->SetBoolean("supports_spdy", true);
191 191
192 // Set up alternative_service for www.google.com:80. 192 // Set up alternative_services for www.google.com:80.
193 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; 193 base::DictionaryValue* alternative_service_dict0 = new base::DictionaryValue;
194 alternative_service_dict->SetString("protocol_str", "npn-h2"); 194 alternative_service_dict0->SetInteger("port", 443);
195 alternative_service_dict->SetString("host", "maps.google.com"); 195 alternative_service_dict0->SetString("protocol_str", "npn-spdy/3");
196 alternative_service_dict->SetInteger("port", 443); 196 base::DictionaryValue* alternative_service_dict1 = new base::DictionaryValue;
197 alternative_service_dict1->SetInteger("port", 1234);
198 alternative_service_dict1->SetString("protocol_str", "quic");
197 base::ListValue* alternative_service_list = new base::ListValue; 199 base::ListValue* alternative_service_list = new base::ListValue;
198 alternative_service_list->Append(alternative_service_dict); 200 alternative_service_list->Append(alternative_service_dict0);
201 alternative_service_list->Append(alternative_service_dict1);
199 server_pref_dict->SetWithoutPathExpansion("alternative_service", 202 server_pref_dict->SetWithoutPathExpansion("alternative_service",
200 alternative_service_list); 203 alternative_service_list);
201 204
202 // Set up ServerNetworkStats for www.google.com:80. 205 // Set up ServerNetworkStats for www.google.com:80.
203 base::DictionaryValue* stats = new base::DictionaryValue; 206 base::DictionaryValue* stats = new base::DictionaryValue;
204 stats->SetInteger("srtt", 10); 207 stats->SetInteger("srtt", 10);
205 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); 208 server_pref_dict->SetWithoutPathExpansion("network_stats", stats);
206 209
207 // Set the server preference for www.google.com:80. 210 // Set the server preference for www.google.com:80.
208 base::DictionaryValue* servers_dict = new base::DictionaryValue; 211 base::DictionaryValue* servers_dict = new base::DictionaryValue;
209 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); 212 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict);
210 213
211 // Set the preference for mail.google.com server. 214 // Set the preference for mail.google.com server.
212 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; 215 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
213 216
214 // Set supports_spdy for mail.google.com:80 217 // Set supports_spdy for mail.google.com:80
215 server_pref_dict1->SetBoolean("supports_spdy", true); 218 server_pref_dict1->SetBoolean("supports_spdy", true);
216 219
217 // Set up alternate_protocol for mail.google.com:80 to test migration to 220 // Set up alternate_protocol for mail.google.com:80 to test migration to
218 // alternative-service. 221 // alternative_service.
219 base::DictionaryValue* alternate_protocol_dict = new base::DictionaryValue; 222 base::DictionaryValue* alternate_protocol_dict = new base::DictionaryValue;
220 alternate_protocol_dict->SetString("protocol_str", "npn-spdy/3.1"); 223 alternate_protocol_dict->SetString("protocol_str", "npn-spdy/3.1");
221 alternate_protocol_dict->SetInteger("port", 444); 224 alternate_protocol_dict->SetInteger("port", 444);
222 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", 225 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol",
223 alternate_protocol_dict); 226 alternate_protocol_dict);
224 227
225 // Set up ServerNetworkStats for mail.google.com:80. 228 // Set up ServerNetworkStats for mail.google.com:80.
226 base::DictionaryValue* stats1 = new base::DictionaryValue; 229 base::DictionaryValue* stats1 = new base::DictionaryValue;
227 stats1->SetInteger("srtt", 20); 230 stats1->SetInteger("srtt", 20);
228 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); 231 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1);
(...skipping 23 matching lines...) Expand all
252 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 255 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
253 256
254 // Verify SupportsSpdy. 257 // Verify SupportsSpdy.
255 EXPECT_TRUE( 258 EXPECT_TRUE(
256 http_server_props_manager_->SupportsRequestPriority(google_server)); 259 http_server_props_manager_->SupportsRequestPriority(google_server));
257 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); 260 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server));
258 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( 261 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
259 HostPortPair::FromString("foo.google.com:1337"))); 262 HostPortPair::FromString("foo.google.com:1337")));
260 263
261 // Verify alternative service. 264 // Verify alternative service.
262 AlternativeService alternative_service = 265 const AlternativeServiceMap& map =
263 http_server_props_manager_->GetAlternativeService(google_server); 266 http_server_props_manager_->alternative_service_map();
264 EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol); 267 ASSERT_EQ(2u, map.size());
265 EXPECT_EQ("maps.google.com", alternative_service.host); 268 AlternativeServiceMap::const_iterator map_it = map.begin();
266 EXPECT_EQ(443, alternative_service.port); 269 EXPECT_EQ("www.google.com", map_it->first.host());
267 alternative_service = 270 ASSERT_EQ(2u, map_it->second.size());
268 http_server_props_manager_->GetAlternativeService(mail_server); 271 EXPECT_EQ(NPN_SPDY_3, map_it->second[0].alternative_service.protocol);
269 EXPECT_EQ(NPN_SPDY_3_1, alternative_service.protocol); 272 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty());
270 EXPECT_EQ("mail.google.com", alternative_service.host); 273 EXPECT_EQ(443, map_it->second[0].alternative_service.port);
271 EXPECT_EQ(444, alternative_service.port); 274 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol);
275 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty());
276 EXPECT_EQ(1234, map_it->second[1].alternative_service.port);
277 ++map_it;
278 EXPECT_EQ("mail.google.com", map_it->first.host());
279 ASSERT_EQ(1u, map_it->second.size());
280 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol);
281 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty());
282 EXPECT_EQ(444, map_it->second[0].alternative_service.port);
272 283
273 // Verify SupportsQuic. 284 // Verify SupportsQuic.
274 IPAddressNumber last_address; 285 IPAddressNumber last_address;
275 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); 286 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address));
276 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address)); 287 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address));
277 288
278 // Verify ServerNetworkStats. 289 // Verify ServerNetworkStats.
279 const ServerNetworkStats* stats2 = 290 const ServerNetworkStats* stats2 =
280 http_server_props_manager_->GetServerNetworkStats(google_server); 291 http_server_props_manager_->GetServerNetworkStats(google_server);
281 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); 292 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
282 const ServerNetworkStats* stats3 = 293 const ServerNetworkStats* stats3 =
283 http_server_props_manager_->GetServerNetworkStats(mail_server); 294 http_server_props_manager_->GetServerNetworkStats(mail_server);
284 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); 295 EXPECT_EQ(20, stats3->srtt.ToInternalValue());
285 } 296 }
286 297
287 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { 298 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
288 ExpectCacheUpdate(); 299 ExpectCacheUpdate();
289 // The prefs are automaticalls updated in the case corruption is detected. 300 // The prefs are automaticalls updated in the case corruption is detected.
290 ExpectPrefsUpdate(); 301 ExpectPrefsUpdate();
291 ExpectScheduleUpdatePrefsOnNetworkThread(); 302 ExpectScheduleUpdatePrefsOnNetworkThread();
292 303
293 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 304 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
294 305
295 // Set supports_spdy for www.google.com:65536. 306 // Set supports_spdy for www.google.com:65536.
296 server_pref_dict->SetBoolean("supports_spdy", true); 307 server_pref_dict->SetBoolean("supports_spdy", true);
297 308
298 // Set up alternative_service for www.google.com:65536. 309 // Set up alternative_service for www.google.com:65536.
299
300 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; 310 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue;
301 alternative_service_dict->SetString("protocol_str", "npn-spdy/3"); 311 alternative_service_dict->SetString("protocol_str", "npn-spdy/3");
302 alternative_service_dict->SetInteger("port", 80); 312 alternative_service_dict->SetInteger("port", 80);
303 base::ListValue* alternative_service_list = new base::ListValue; 313 base::ListValue* alternative_service_list = new base::ListValue;
304 alternative_service_list->Append(alternative_service_dict); 314 alternative_service_list->Append(alternative_service_dict);
305 server_pref_dict->SetWithoutPathExpansion("alternative_service", 315 server_pref_dict->SetWithoutPathExpansion("alternative_service",
306 alternative_service_list); 316 alternative_service_list);
307 317
308 // Set up ServerNetworkStats for www.google.com:65536. 318 // Set up ServerNetworkStats for www.google.com:65536.
309 base::DictionaryValue* stats = new base::DictionaryValue; 319 base::DictionaryValue* stats = new base::DictionaryValue;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 base::RunLoop().RunUntilIdle(); 509 base::RunLoop().RunUntilIdle();
500 510
501 // Verify that there are no entries in the settings map. 511 // Verify that there are no entries in the settings map.
502 const SpdySettingsMap& spdy_settings_map2_ret = 512 const SpdySettingsMap& spdy_settings_map2_ret =
503 http_server_props_manager_->spdy_settings_map(); 513 http_server_props_manager_->spdy_settings_map();
504 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); 514 ASSERT_EQ(0U, spdy_settings_map2_ret.size());
505 515
506 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 516 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
507 } 517 }
508 518
509 TEST_F(HttpServerPropertiesManagerTest, GetAlternativeService) { 519 TEST_F(HttpServerPropertiesManagerTest, GetAlternativeServices) {
520 ExpectPrefsUpdate();
521 ExpectScheduleUpdatePrefsOnNetworkThread();
522
523 HostPortPair spdy_server_mail("mail.google.com", 80);
524 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
525 const AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com",
526 443);
527 http_server_props_manager_->AddAlternativeService(spdy_server_mail,
528 alternative_service, 1.0);
529
530 // Run the task.
531 base::RunLoop().RunUntilIdle();
532 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
533
534 AlternativeServiceVector alternative_service_vector =
535 http_server_props_manager_->GetAlternativeServices(spdy_server_mail);
536 ASSERT_EQ(1u, alternative_service_vector.size());
537 EXPECT_EQ(alternative_service, alternative_service_vector[0]);
538 }
539
540 TEST_F(HttpServerPropertiesManagerTest, ClearAlternativeServices) {
510 ExpectPrefsUpdate(); 541 ExpectPrefsUpdate();
511 ExpectScheduleUpdatePrefsOnNetworkThread(); 542 ExpectScheduleUpdatePrefsOnNetworkThread();
512 543
513 HostPortPair spdy_server_mail("mail.google.com", 80); 544 HostPortPair spdy_server_mail("mail.google.com", 80);
514 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 545 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
515 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443); 546 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443);
516 http_server_props_manager_->SetAlternativeService(spdy_server_mail, 547 http_server_props_manager_->AddAlternativeService(spdy_server_mail,
517 alternative_service, 1.0); 548 alternative_service, 1.0);
549 ExpectScheduleUpdatePrefsOnNetworkThread();
550 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail);
518 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 551 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
519 http_server_props_manager_->SetAlternativeService(spdy_server_mail, 552 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail);
520 alternative_service, 1.0);
521 553
522 // Run the task. 554 // Run the task.
523 base::RunLoop().RunUntilIdle(); 555 base::RunLoop().RunUntilIdle();
524 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
525
526 alternative_service =
527 http_server_props_manager_->GetAlternativeService(spdy_server_mail);
528 EXPECT_EQ(443, alternative_service.port);
529 EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol);
530 }
531
532 TEST_F(HttpServerPropertiesManagerTest, ClearAlternativeService) {
533 ExpectPrefsUpdate();
534 ExpectScheduleUpdatePrefsOnNetworkThread();
535
536 HostPortPair spdy_server_mail("mail.google.com", 80);
537 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
538 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443);
539 http_server_props_manager_->SetAlternativeService(spdy_server_mail,
540 alternative_service, 1.0);
541 ExpectScheduleUpdatePrefsOnNetworkThread();
542 http_server_props_manager_->ClearAlternativeService(spdy_server_mail);
543 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
544 http_server_props_manager_->ClearAlternativeService(spdy_server_mail);
545
546 // Run the task.
547 base::RunLoop().RunUntilIdle();
548 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 556 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
549 557
550 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 558 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
551 } 559 }
552 560
553 TEST_F(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { 561 TEST_F(HttpServerPropertiesManagerTest, ConfirmAlternativeService) {
554 ExpectPrefsUpdate(); 562 ExpectPrefsUpdate();
555 563
556 HostPortPair spdy_server_mail("mail.google.com", 80); 564 HostPortPair spdy_server_mail("mail.google.com", 80);
557 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 565 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
558 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443); 566 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443);
559 567
560 ExpectScheduleUpdatePrefsOnNetworkThread(); 568 ExpectScheduleUpdatePrefsOnNetworkThread();
561 http_server_props_manager_->SetAlternativeService(spdy_server_mail, 569 http_server_props_manager_->AddAlternativeService(spdy_server_mail,
562 alternative_service, 1.0); 570 alternative_service, 1.0);
563 571
564 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( 572 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken(
565 alternative_service)); 573 alternative_service));
566 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( 574 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken(
567 alternative_service)); 575 alternative_service));
568 576
569 ExpectScheduleUpdatePrefsOnNetworkThread(); 577 ExpectScheduleUpdatePrefsOnNetworkThread();
570 http_server_props_manager_->MarkAlternativeServiceBroken(alternative_service); 578 http_server_props_manager_->MarkAlternativeServiceBroken(alternative_service);
571 EXPECT_TRUE(http_server_props_manager_->IsAlternativeServiceBroken( 579 EXPECT_TRUE(http_server_props_manager_->IsAlternativeServiceBroken(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); 648 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
641 } 649 }
642 650
643 TEST_F(HttpServerPropertiesManagerTest, Clear) { 651 TEST_F(HttpServerPropertiesManagerTest, Clear) {
644 ExpectPrefsUpdate(); 652 ExpectPrefsUpdate();
645 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 653 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
646 654
647 HostPortPair spdy_server_mail("mail.google.com", 443); 655 HostPortPair spdy_server_mail("mail.google.com", 443);
648 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 656 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
649 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443); 657 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443);
650 http_server_props_manager_->SetAlternativeService(spdy_server_mail, 658 http_server_props_manager_->AddAlternativeService(spdy_server_mail,
651 alternative_service, 1.0); 659 alternative_service, 1.0);
652 IPAddressNumber actual_address; 660 IPAddressNumber actual_address;
653 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); 661 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address));
654 http_server_props_manager_->SetSupportsQuic(true, actual_address); 662 http_server_props_manager_->SetSupportsQuic(true, actual_address);
655 ServerNetworkStats stats; 663 ServerNetworkStats stats;
656 stats.srtt = base::TimeDelta::FromMicroseconds(10); 664 stats.srtt = base::TimeDelta::FromMicroseconds(10);
657 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); 665 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats);
658 666
659 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; 667 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH;
660 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; 668 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 // supports_quic and verify we have read supports_quic from prefs. 720 // supports_quic and verify we have read supports_quic from prefs.
713 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { 721 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) {
714 ExpectCacheUpdate(); 722 ExpectCacheUpdate();
715 723
716 base::DictionaryValue* servers_dict = new base::DictionaryValue; 724 base::DictionaryValue* servers_dict = new base::DictionaryValue;
717 725
718 for (int i = 0; i < 200; ++i) { 726 for (int i = 0; i < 200; ++i) {
719 // Set up alternative_service for www.google.com:i. 727 // Set up alternative_service for www.google.com:i.
720 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; 728 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue;
721 alternative_service_dict->SetString("protocol_str", "npn-h2"); 729 alternative_service_dict->SetString("protocol_str", "npn-h2");
722 alternative_service_dict->SetString("host", "");
723 alternative_service_dict->SetInteger("port", i); 730 alternative_service_dict->SetInteger("port", i);
724 base::ListValue* alternative_service_list = new base::ListValue; 731 base::ListValue* alternative_service_list = new base::ListValue;
725 alternative_service_list->Append(alternative_service_dict); 732 alternative_service_list->Append(alternative_service_dict);
726 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 733 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
727 server_pref_dict->SetWithoutPathExpansion("alternative_service", 734 server_pref_dict->SetWithoutPathExpansion("alternative_service",
728 alternative_service_list); 735 alternative_service_list);
729 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), 736 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i),
730 server_pref_dict); 737 server_pref_dict);
731 } 738 }
732 739
(...skipping 19 matching lines...) Expand all
752 // Set up the pref. 759 // Set up the pref.
753 pref_service_.SetManagedPref(kTestHttpServerProperties, 760 pref_service_.SetManagedPref(kTestHttpServerProperties,
754 http_server_properties_dict); 761 http_server_properties_dict);
755 762
756 base::RunLoop().RunUntilIdle(); 763 base::RunLoop().RunUntilIdle();
757 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 764 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
758 765
759 // Verify alternative service. 766 // Verify alternative service.
760 for (int i = 0; i < 200; ++i) { 767 for (int i = 0; i < 200; ++i) {
761 std::string server = StringPrintf("www.google.com:%d", i); 768 std::string server = StringPrintf("www.google.com:%d", i);
762 AlternativeService alternative_service = 769 AlternativeServiceVector alternative_service_vector =
763 http_server_props_manager_->GetAlternativeService( 770 http_server_props_manager_->GetAlternativeServices(
764 HostPortPair::FromString(server)); 771 HostPortPair::FromString(server));
765 EXPECT_EQ(i, alternative_service.port); 772 ASSERT_EQ(1u, alternative_service_vector.size());
766 EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol); 773 EXPECT_EQ(NPN_SPDY_4, alternative_service_vector[0].protocol);
774 EXPECT_EQ(i, alternative_service_vector[0].port);
767 } 775 }
768 776
769 // Verify SupportsQuic. 777 // Verify SupportsQuic.
770 IPAddressNumber address; 778 IPAddressNumber address;
771 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); 779 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
772 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); 780 EXPECT_EQ("127.0.0.1", IPAddressToString(address));
773 } 781 }
774 782
775 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { 783 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
776 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 784 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
777 785
778 const HostPortPair server_www("www.google.com", 80); 786 const HostPortPair server_www("www.google.com", 80);
779 const HostPortPair server_mail("mail.google.com", 80); 787 const HostPortPair server_mail("mail.google.com", 80);
780 788
781 // Set alternate protocol. 789 // Set alternate protocol.
782 AlternativeService www_altsvc(NPN_SPDY_4, "", 443); 790 AlternativeService www_alternative_service1(NPN_SPDY_4, "", 443);
783 AlternativeService mail_altsvc(NPN_SPDY_3_1, "mail.google.com", 444); 791 http_server_props_manager_->AddAlternativeService(
784 http_server_props_manager_->SetAlternativeService(server_www, www_altsvc, 792 server_www, www_alternative_service1, 1.0);
785 1.0); 793 AlternativeService www_alternative_service2(NPN_SPDY_4, "www.google.com",
786 http_server_props_manager_->SetAlternativeService(server_mail, mail_altsvc, 794 1234);
787 0.2); 795 http_server_props_manager_->AddAlternativeService(
796 server_www, www_alternative_service2, 0.7);
797 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com",
798 444);
799 http_server_props_manager_->AddAlternativeService(
800 server_mail, mail_alternative_service, 0.2);
788 801
789 // Set ServerNetworkStats. 802 // Set ServerNetworkStats.
790 ServerNetworkStats stats; 803 ServerNetworkStats stats;
791 stats.srtt = base::TimeDelta::FromInternalValue(42); 804 stats.srtt = base::TimeDelta::FromInternalValue(42);
792 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); 805 http_server_props_manager_->SetServerNetworkStats(server_mail, stats);
793 806
794 // Set SupportsQuic. 807 // Set SupportsQuic.
795 IPAddressNumber actual_address; 808 IPAddressNumber actual_address;
796 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); 809 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address));
797 http_server_props_manager_->SetSupportsQuic(true, actual_address); 810 http_server_props_manager_->SetSupportsQuic(true, actual_address);
798 811
799 // Update cache. 812 // Update cache.
800 ExpectPrefsUpdate(); 813 ExpectPrefsUpdate();
801 ExpectCacheUpdate(); 814 ExpectCacheUpdate();
802 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 815 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
803 base::RunLoop().RunUntilIdle(); 816 base::RunLoop().RunUntilIdle();
804 817
805 // Verify preferences. 818 // Verify preferences.
806 const char expected_json[] = 819 const char expected_json[] =
807 "{\"servers\":{\"mail.google.com:80\":{\"alternative_service\":[{" 820 "{\"servers\":{\"mail.google.com:80\":{\"alternative_service\":[{"
808 "\"host\":" 821 "\"host\":\"foo.google.com\",\"port\":444,\"probability\":0.2,"
809 "\"mail.google.com\",\"port\":444,\"probability\":0.2,\"protocol_str\":" 822 "\"protocol_str\":\"npn-spdy/3.1\"}],\"network_stats\":{\"srtt\":42}},"
810 "\"npn-spdy/" 823 "\"www.google.com:80\":{\"alternative_service\":[{\"port\":443,"
811 "3.1\"}],\"network_stats\":{\"srtt\":42}},\"www.google.com:80\":" 824 "\"probability\":1.0,\"protocol_str\":\"npn-h2\"},"
812 "{\"alternative_service\":[{\"port\":443,\"probability\":1.0," 825 "{\"host\":\"www.google.com\",\"port\":1234,\"probability\":0.7,"
813 "\"protocol_str\":\"npn-h2\"}]}},\"supports_quic\":" 826 "\"protocol_str\":\"npn-h2\"}]}},\"supports_quic\":"
814 "{\"address\":\"127.0.0.1\",\"used_quic\":true},\"version\":3}"; 827 "{\"address\":\"127.0.0.1\",\"used_quic\":true},\"version\":3}";
815 828
816 const base::Value* http_server_properties = 829 const base::Value* http_server_properties =
817 pref_service_.GetUserPref(kTestHttpServerProperties); 830 pref_service_.GetUserPref(kTestHttpServerProperties);
818 ASSERT_NE(nullptr, http_server_properties); 831 ASSERT_NE(nullptr, http_server_properties);
819 std::string preferences_json; 832 std::string preferences_json;
820 EXPECT_TRUE( 833 EXPECT_TRUE(
821 base::JSONWriter::Write(*http_server_properties, &preferences_json)); 834 base::JSONWriter::Write(*http_server_properties, &preferences_json));
822 EXPECT_EQ(expected_json, preferences_json); 835 EXPECT_EQ(expected_json, preferences_json);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 // Run the task after shutdown, but before deletion. 903 // Run the task after shutdown, but before deletion.
891 base::RunLoop().RunUntilIdle(); 904 base::RunLoop().RunUntilIdle();
892 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 905 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
893 http_server_props_manager_.reset(); 906 http_server_props_manager_.reset();
894 base::RunLoop().RunUntilIdle(); 907 base::RunLoop().RunUntilIdle();
895 } 908 }
896 909
897 } // namespace 910 } // namespace
898 911
899 } // namespace net 912 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698