| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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) { |
| 510 ExpectPrefsUpdate(); | 520 ExpectPrefsUpdate(); |
| 511 ExpectScheduleUpdatePrefsOnNetworkThread(); | 521 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 512 | 522 |
| 513 HostPortPair spdy_server_mail("mail.google.com", 80); | 523 HostPortPair spdy_server_mail("mail.google.com", 80); |
| 514 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 524 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 515 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443); | 525 const AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", |
| 526 443); |
| 516 http_server_props_manager_->SetAlternativeService(spdy_server_mail, | 527 http_server_props_manager_->SetAlternativeService(spdy_server_mail, |
| 517 alternative_service, 1.0); | 528 alternative_service, 1.0); |
| 518 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 529 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 519 http_server_props_manager_->SetAlternativeService(spdy_server_mail, | 530 http_server_props_manager_->SetAlternativeService(spdy_server_mail, |
| 520 alternative_service, 1.0); | 531 alternative_service, 1.0); |
| 521 | 532 |
| 522 // Run the task. | 533 // Run the task. |
| 523 base::RunLoop().RunUntilIdle(); | 534 base::RunLoop().RunUntilIdle(); |
| 524 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 535 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 525 | 536 |
| 526 alternative_service = | 537 AlternativeServiceVector alternative_service_vector = |
| 527 http_server_props_manager_->GetAlternativeService(spdy_server_mail); | 538 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); |
| 528 EXPECT_EQ(443, alternative_service.port); | 539 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 529 EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol); | 540 EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 530 } | 541 } |
| 531 | 542 |
| 532 TEST_F(HttpServerPropertiesManagerTest, ClearAlternativeService) { | 543 TEST_F(HttpServerPropertiesManagerTest, SetAlternativeServices) { |
| 533 ExpectPrefsUpdate(); | 544 ExpectPrefsUpdate(); |
| 534 ExpectScheduleUpdatePrefsOnNetworkThread(); | 545 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 535 | 546 |
| 547 HostPortPair spdy_server_mail("mail.google.com", 80); |
| 548 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 549 AlternativeServiceInfoVector alternative_service_info_vector; |
| 550 const AlternativeService alternative_service1(NPN_SPDY_4, "mail.google.com", |
| 551 443); |
| 552 alternative_service_info_vector.push_back( |
| 553 AlternativeServiceInfo(alternative_service1, 1.0)); |
| 554 const AlternativeService alternative_service2(QUIC, "mail.google.com", 1234); |
| 555 alternative_service_info_vector.push_back( |
| 556 AlternativeServiceInfo(alternative_service2, 1.0)); |
| 557 http_server_props_manager_->SetAlternativeServices( |
| 558 spdy_server_mail, alternative_service_info_vector); |
| 559 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 560 http_server_props_manager_->SetAlternativeServices( |
| 561 spdy_server_mail, alternative_service_info_vector); |
| 562 |
| 563 // Run the task. |
| 564 base::RunLoop().RunUntilIdle(); |
| 565 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 566 |
| 567 AlternativeServiceVector alternative_service_vector = |
| 568 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); |
| 569 ASSERT_EQ(2u, alternative_service_vector.size()); |
| 570 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 571 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); |
| 572 } |
| 573 |
| 574 TEST_F(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) { |
| 575 HostPortPair spdy_server_mail("mail.google.com", 80); |
| 576 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 577 const AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", |
| 578 443); |
| 579 http_server_props_manager_->SetAlternativeServices( |
| 580 spdy_server_mail, AlternativeServiceInfoVector()); |
| 581 // ExpectScheduleUpdatePrefsOnNetworkThread() should not be called. |
| 582 |
| 583 // Run the task. |
| 584 base::RunLoop().RunUntilIdle(); |
| 585 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 586 |
| 587 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 588 } |
| 589 |
| 590 TEST_F(HttpServerPropertiesManagerTest, ClearAlternativeServices) { |
| 591 ExpectPrefsUpdate(); |
| 592 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 593 |
| 536 HostPortPair spdy_server_mail("mail.google.com", 80); | 594 HostPortPair spdy_server_mail("mail.google.com", 80); |
| 537 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 595 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 538 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443); | 596 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443); |
| 539 http_server_props_manager_->SetAlternativeService(spdy_server_mail, | 597 http_server_props_manager_->SetAlternativeService(spdy_server_mail, |
| 540 alternative_service, 1.0); | 598 alternative_service, 1.0); |
| 541 ExpectScheduleUpdatePrefsOnNetworkThread(); | 599 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 542 http_server_props_manager_->ClearAlternativeService(spdy_server_mail); | 600 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); |
| 543 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 601 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 544 http_server_props_manager_->ClearAlternativeService(spdy_server_mail); | 602 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); |
| 545 | 603 |
| 546 // Run the task. | 604 // Run the task. |
| 547 base::RunLoop().RunUntilIdle(); | 605 base::RunLoop().RunUntilIdle(); |
| 548 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 606 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 549 | 607 |
| 550 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 608 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 551 } | 609 } |
| 552 | 610 |
| 553 TEST_F(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { | 611 TEST_F(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { |
| 554 ExpectPrefsUpdate(); | 612 ExpectPrefsUpdate(); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 // supports_quic and verify we have read supports_quic from prefs. | 770 // supports_quic and verify we have read supports_quic from prefs. |
| 713 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { | 771 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
| 714 ExpectCacheUpdate(); | 772 ExpectCacheUpdate(); |
| 715 | 773 |
| 716 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 774 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 717 | 775 |
| 718 for (int i = 0; i < 200; ++i) { | 776 for (int i = 0; i < 200; ++i) { |
| 719 // Set up alternative_service for www.google.com:i. | 777 // Set up alternative_service for www.google.com:i. |
| 720 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; | 778 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
| 721 alternative_service_dict->SetString("protocol_str", "npn-h2"); | 779 alternative_service_dict->SetString("protocol_str", "npn-h2"); |
| 722 alternative_service_dict->SetString("host", ""); | |
| 723 alternative_service_dict->SetInteger("port", i); | 780 alternative_service_dict->SetInteger("port", i); |
| 724 base::ListValue* alternative_service_list = new base::ListValue; | 781 base::ListValue* alternative_service_list = new base::ListValue; |
| 725 alternative_service_list->Append(alternative_service_dict); | 782 alternative_service_list->Append(alternative_service_dict); |
| 726 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 783 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 727 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 784 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 728 alternative_service_list); | 785 alternative_service_list); |
| 729 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), | 786 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), |
| 730 server_pref_dict); | 787 server_pref_dict); |
| 731 } | 788 } |
| 732 | 789 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 752 // Set up the pref. | 809 // Set up the pref. |
| 753 pref_service_.SetManagedPref(kTestHttpServerProperties, | 810 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 754 http_server_properties_dict); | 811 http_server_properties_dict); |
| 755 | 812 |
| 756 base::RunLoop().RunUntilIdle(); | 813 base::RunLoop().RunUntilIdle(); |
| 757 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 814 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 758 | 815 |
| 759 // Verify alternative service. | 816 // Verify alternative service. |
| 760 for (int i = 0; i < 200; ++i) { | 817 for (int i = 0; i < 200; ++i) { |
| 761 std::string server = StringPrintf("www.google.com:%d", i); | 818 std::string server = StringPrintf("www.google.com:%d", i); |
| 762 AlternativeService alternative_service = | 819 AlternativeServiceVector alternative_service_vector = |
| 763 http_server_props_manager_->GetAlternativeService( | 820 http_server_props_manager_->GetAlternativeServices( |
| 764 HostPortPair::FromString(server)); | 821 HostPortPair::FromString(server)); |
| 765 EXPECT_EQ(i, alternative_service.port); | 822 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 766 EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol); | 823 EXPECT_EQ(NPN_SPDY_4, alternative_service_vector[0].protocol); |
| 824 EXPECT_EQ(i, alternative_service_vector[0].port); |
| 767 } | 825 } |
| 768 | 826 |
| 769 // Verify SupportsQuic. | 827 // Verify SupportsQuic. |
| 770 IPAddressNumber address; | 828 IPAddressNumber address; |
| 771 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 829 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 772 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); | 830 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); |
| 773 } | 831 } |
| 774 | 832 |
| 775 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { | 833 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { |
| 776 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 834 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
| 777 | 835 |
| 778 const HostPortPair server_www("www.google.com", 80); | 836 const HostPortPair server_www("www.google.com", 80); |
| 779 const HostPortPair server_mail("mail.google.com", 80); | 837 const HostPortPair server_mail("mail.google.com", 80); |
| 780 | 838 |
| 781 // Set alternate protocol. | 839 // Set alternate protocol. |
| 782 AlternativeService www_altsvc(NPN_SPDY_4, "", 443); | 840 AlternativeServiceInfoVector alternative_service_info_vector; |
| 783 AlternativeService mail_altsvc(NPN_SPDY_3_1, "mail.google.com", 444); | 841 AlternativeService www_alternative_service1(NPN_SPDY_4, "", 443); |
| 784 http_server_props_manager_->SetAlternativeService(server_www, www_altsvc, | 842 alternative_service_info_vector.push_back( |
| 785 1.0); | 843 AlternativeServiceInfo(www_alternative_service1, 1.0)); |
| 786 http_server_props_manager_->SetAlternativeService(server_mail, mail_altsvc, | 844 AlternativeService www_alternative_service2(NPN_SPDY_4, "www.google.com", |
| 787 0.2); | 845 1234); |
| 846 alternative_service_info_vector.push_back( |
| 847 AlternativeServiceInfo(www_alternative_service2, 0.7)); |
| 848 http_server_props_manager_->SetAlternativeServices( |
| 849 server_www, alternative_service_info_vector); |
| 850 |
| 851 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com", |
| 852 444); |
| 853 http_server_props_manager_->SetAlternativeService( |
| 854 server_mail, mail_alternative_service, 0.2); |
| 788 | 855 |
| 789 // Set ServerNetworkStats. | 856 // Set ServerNetworkStats. |
| 790 ServerNetworkStats stats; | 857 ServerNetworkStats stats; |
| 791 stats.srtt = base::TimeDelta::FromInternalValue(42); | 858 stats.srtt = base::TimeDelta::FromInternalValue(42); |
| 792 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); | 859 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); |
| 793 | 860 |
| 794 // Set SupportsQuic. | 861 // Set SupportsQuic. |
| 795 IPAddressNumber actual_address; | 862 IPAddressNumber actual_address; |
| 796 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 863 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
| 797 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 864 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
| 798 | 865 |
| 799 // Update cache. | 866 // Update cache. |
| 800 ExpectPrefsUpdate(); | 867 ExpectPrefsUpdate(); |
| 801 ExpectCacheUpdate(); | 868 ExpectCacheUpdate(); |
| 802 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 869 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 803 base::RunLoop().RunUntilIdle(); | 870 base::RunLoop().RunUntilIdle(); |
| 804 | 871 |
| 805 // Verify preferences. | 872 // Verify preferences. |
| 806 const char expected_json[] = | 873 const char expected_json[] = |
| 807 "{\"servers\":{\"mail.google.com:80\":{\"alternative_service\":[{" | 874 "{\"servers\":{\"mail.google.com:80\":{\"alternative_service\":[{" |
| 808 "\"host\":" | 875 "\"host\":\"foo.google.com\",\"port\":444,\"probability\":0.2," |
| 809 "\"mail.google.com\",\"port\":444,\"probability\":0.2,\"protocol_str\":" | 876 "\"protocol_str\":\"npn-spdy/3.1\"}],\"network_stats\":{\"srtt\":42}}," |
| 810 "\"npn-spdy/" | 877 "\"www.google.com:80\":{\"alternative_service\":[{\"port\":443," |
| 811 "3.1\"}],\"network_stats\":{\"srtt\":42}},\"www.google.com:80\":" | 878 "\"probability\":1.0,\"protocol_str\":\"npn-h2\"}," |
| 812 "{\"alternative_service\":[{\"port\":443,\"probability\":1.0," | 879 "{\"host\":\"www.google.com\",\"port\":1234,\"probability\":0.7," |
| 813 "\"protocol_str\":\"npn-h2\"}]}},\"supports_quic\":" | 880 "\"protocol_str\":\"npn-h2\"}]}},\"supports_quic\":" |
| 814 "{\"address\":\"127.0.0.1\",\"used_quic\":true},\"version\":3}"; | 881 "{\"address\":\"127.0.0.1\",\"used_quic\":true},\"version\":3}"; |
| 815 | 882 |
| 816 const base::Value* http_server_properties = | 883 const base::Value* http_server_properties = |
| 817 pref_service_.GetUserPref(kTestHttpServerProperties); | 884 pref_service_.GetUserPref(kTestHttpServerProperties); |
| 818 ASSERT_NE(nullptr, http_server_properties); | 885 ASSERT_NE(nullptr, http_server_properties); |
| 819 std::string preferences_json; | 886 std::string preferences_json; |
| 820 EXPECT_TRUE( | 887 EXPECT_TRUE( |
| 821 base::JSONWriter::Write(*http_server_properties, &preferences_json)); | 888 base::JSONWriter::Write(*http_server_properties, &preferences_json)); |
| 822 EXPECT_EQ(expected_json, preferences_json); | 889 EXPECT_EQ(expected_json, preferences_json); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 // Run the task after shutdown, but before deletion. | 957 // Run the task after shutdown, but before deletion. |
| 891 base::RunLoop().RunUntilIdle(); | 958 base::RunLoop().RunUntilIdle(); |
| 892 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 959 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 893 http_server_props_manager_.reset(); | 960 http_server_props_manager_.reset(); |
| 894 base::RunLoop().RunUntilIdle(); | 961 base::RunLoop().RunUntilIdle(); |
| 895 } | 962 } |
| 896 | 963 |
| 897 } // namespace | 964 } // namespace |
| 898 | 965 |
| 899 } // namespace net | 966 } // namespace net |
| OLD | NEW |