| 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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 http_server_properties_dict); | 216 http_server_properties_dict); |
| 217 base::DictionaryValue* http_server_properties_dict2 = | 217 base::DictionaryValue* http_server_properties_dict2 = |
| 218 http_server_properties_dict->DeepCopy(); | 218 http_server_properties_dict->DeepCopy(); |
| 219 pref_service_.SetManagedPref(kTestHttpServerProperties, | 219 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 220 http_server_properties_dict2); | 220 http_server_properties_dict2); |
| 221 | 221 |
| 222 base::RunLoop().RunUntilIdle(); | 222 base::RunLoop().RunUntilIdle(); |
| 223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 224 | 224 |
| 225 // Verify SupportsSpdy. | 225 // Verify SupportsSpdy. |
| 226 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(google_server)); | 226 EXPECT_TRUE( |
| 227 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(mail_server)); | 227 http_server_props_manager_->SupportsRequestPriority(google_server)); |
| 228 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( | 228 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); |
| 229 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
| 229 HostPortPair::FromString("foo.google.com:1337"))); | 230 HostPortPair::FromString("foo.google.com:1337"))); |
| 230 | 231 |
| 231 // Verify AlternateProtocol. | 232 // Verify AlternateProtocol. |
| 232 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); | 233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); |
| 233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); | 234 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); |
| 234 AlternateProtocolInfo port_alternate_protocol = | 235 AlternateProtocolInfo port_alternate_protocol = |
| 235 http_server_props_manager_->GetAlternateProtocol(google_server); | 236 http_server_props_manager_->GetAlternateProtocol(google_server); |
| 236 EXPECT_EQ(443, port_alternate_protocol.port); | 237 EXPECT_EQ(443, port_alternate_protocol.port); |
| 237 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 238 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
| 238 port_alternate_protocol = | 239 port_alternate_protocol = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 298 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 298 | 299 |
| 299 // Set up the pref. | 300 // Set up the pref. |
| 300 pref_service_.SetManagedPref(kTestHttpServerProperties, | 301 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 301 http_server_properties_dict); | 302 http_server_properties_dict); |
| 302 | 303 |
| 303 base::RunLoop().RunUntilIdle(); | 304 base::RunLoop().RunUntilIdle(); |
| 304 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 305 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 305 | 306 |
| 306 // Verify that nothing is set. | 307 // Verify that nothing is set. |
| 307 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( | 308 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
| 308 HostPortPair::FromString("www.google.com:65536"))); | 309 HostPortPair::FromString("www.google.com:65536"))); |
| 309 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( | 310 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( |
| 310 HostPortPair::FromString("www.google.com:65536"))); | 311 HostPortPair::FromString("www.google.com:65536"))); |
| 311 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic( | 312 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic( |
| 312 HostPortPair::FromString("www.google.com:65536")); | 313 HostPortPair::FromString("www.google.com:65536")); |
| 313 EXPECT_FALSE(supports_quic2.used_quic); | 314 EXPECT_FALSE(supports_quic2.used_quic); |
| 314 const ServerNetworkStats* stats1 = | 315 const ServerNetworkStats* stats1 = |
| 315 http_server_props_manager_->GetServerNetworkStats( | 316 http_server_props_manager_->GetServerNetworkStats( |
| 316 HostPortPair::FromString("www.google.com:65536")); | 317 HostPortPair::FromString("www.google.com:65536")); |
| 317 EXPECT_EQ(NULL, stats1); | 318 EXPECT_EQ(NULL, stats1); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 } | 357 } |
| 357 | 358 |
| 358 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 359 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
| 359 ExpectPrefsUpdate(); | 360 ExpectPrefsUpdate(); |
| 360 | 361 |
| 361 // Post an update task to the network thread. SetSupportsSpdy calls | 362 // Post an update task to the network thread. SetSupportsSpdy calls |
| 362 // ScheduleUpdatePrefsOnNetworkThread. | 363 // ScheduleUpdatePrefsOnNetworkThread. |
| 363 | 364 |
| 364 // Add mail.google.com:443 as a supporting spdy server. | 365 // Add mail.google.com:443 as a supporting spdy server. |
| 365 HostPortPair spdy_server_mail("mail.google.com", 443); | 366 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 366 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 367 EXPECT_FALSE( |
| 368 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
| 367 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 369 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 368 | 370 |
| 369 // Run the task. | 371 // Run the task. |
| 370 base::RunLoop().RunUntilIdle(); | 372 base::RunLoop().RunUntilIdle(); |
| 371 | 373 |
| 372 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 374 EXPECT_TRUE( |
| 375 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
| 373 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 376 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 374 } | 377 } |
| 375 | 378 |
| 376 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { | 379 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { |
| 377 ExpectPrefsUpdate(); | 380 ExpectPrefsUpdate(); |
| 378 | 381 |
| 379 // Add SpdySetting for mail.google.com:443. | 382 // Add SpdySetting for mail.google.com:443. |
| 380 HostPortPair spdy_server_mail("mail.google.com", 443); | 383 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 381 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 384 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 382 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 385 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 | 552 |
| 550 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 553 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 551 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 554 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 552 const uint32 value1 = 31337; | 555 const uint32 value1 = 31337; |
| 553 http_server_props_manager_->SetSpdySetting( | 556 http_server_props_manager_->SetSpdySetting( |
| 554 spdy_server_mail, id1, flags1, value1); | 557 spdy_server_mail, id1, flags1, value1); |
| 555 | 558 |
| 556 // Run the task. | 559 // Run the task. |
| 557 base::RunLoop().RunUntilIdle(); | 560 base::RunLoop().RunUntilIdle(); |
| 558 | 561 |
| 559 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 562 EXPECT_TRUE( |
| 563 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
| 560 EXPECT_TRUE( | 564 EXPECT_TRUE( |
| 561 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 565 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 562 SupportsQuic supports_quic = | 566 SupportsQuic supports_quic = |
| 563 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); | 567 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); |
| 564 EXPECT_TRUE(supports_quic.used_quic); | 568 EXPECT_TRUE(supports_quic.used_quic); |
| 565 EXPECT_EQ("foo", supports_quic.address); | 569 EXPECT_EQ("foo", supports_quic.address); |
| 566 const ServerNetworkStats* stats1 = | 570 const ServerNetworkStats* stats1 = |
| 567 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 571 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 568 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); | 572 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); |
| 569 | 573 |
| 570 // Check SPDY settings values. | 574 // Check SPDY settings values. |
| 571 const SettingsMap& settings_map1_ret = | 575 const SettingsMap& settings_map1_ret = |
| 572 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 576 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 573 ASSERT_EQ(1U, settings_map1_ret.size()); | 577 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 574 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 578 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 575 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 579 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 576 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 580 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 577 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 581 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 578 EXPECT_EQ(value1, flags_and_value1_ret.second); | 582 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 579 | 583 |
| 580 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 584 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 581 | 585 |
| 582 ExpectPrefsUpdate(); | 586 ExpectPrefsUpdate(); |
| 583 | 587 |
| 584 // Clear http server data, time out if we do not get a completion callback. | 588 // Clear http server data, time out if we do not get a completion callback. |
| 585 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); | 589 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); |
| 586 base::RunLoop().Run(); | 590 base::RunLoop().Run(); |
| 587 | 591 |
| 588 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 592 EXPECT_FALSE( |
| 593 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
| 589 EXPECT_FALSE( | 594 EXPECT_FALSE( |
| 590 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 595 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 591 SupportsQuic supports_quic1 = | 596 SupportsQuic supports_quic1 = |
| 592 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); | 597 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); |
| 593 EXPECT_FALSE(supports_quic1.used_quic); | 598 EXPECT_FALSE(supports_quic1.used_quic); |
| 594 EXPECT_EQ("", supports_quic1.address); | 599 EXPECT_EQ("", supports_quic1.address); |
| 595 const ServerNetworkStats* stats2 = | 600 const ServerNetworkStats* stats2 = |
| 596 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 601 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 597 EXPECT_EQ(NULL, stats2); | 602 EXPECT_EQ(NULL, stats2); |
| 598 | 603 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 // Run the task after shutdown, but before deletion. | 739 // Run the task after shutdown, but before deletion. |
| 735 base::RunLoop().RunUntilIdle(); | 740 base::RunLoop().RunUntilIdle(); |
| 736 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 741 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 737 http_server_props_manager_.reset(); | 742 http_server_props_manager_.reset(); |
| 738 base::RunLoop().RunUntilIdle(); | 743 base::RunLoop().RunUntilIdle(); |
| 739 } | 744 } |
| 740 | 745 |
| 741 } // namespace | 746 } // namespace |
| 742 | 747 |
| 743 } // namespace net | 748 } // namespace net |
| OLD | NEW |