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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 void ExpectPrefsUpdateRepeatedly() { | 128 void ExpectPrefsUpdateRepeatedly() { |
129 EXPECT_CALL(*http_server_props_manager_, | 129 EXPECT_CALL(*http_server_props_manager_, |
130 UpdatePrefsFromCacheOnNetworkThread(_)) | 130 UpdatePrefsFromCacheOnNetworkThread(_)) |
131 .WillRepeatedly( | 131 .WillRepeatedly( |
132 Invoke(http_server_props_manager_.get(), | 132 Invoke(http_server_props_manager_.get(), |
133 &TestingHttpServerPropertiesManager:: | 133 &TestingHttpServerPropertiesManager:: |
134 UpdatePrefsFromCacheOnNetworkThreadConcrete)); | 134 UpdatePrefsFromCacheOnNetworkThreadConcrete)); |
135 } | 135 } |
136 | 136 |
| 137 bool HasAlternateProtocol(const HostPortPair& server) { |
| 138 const AlternateProtocolInfo alternate = |
| 139 http_server_props_manager_->GetAlternateProtocol(server); |
| 140 return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; |
| 141 } |
| 142 |
137 //base::RunLoop loop_; | 143 //base::RunLoop loop_; |
138 TestingPrefServiceSimple pref_service_; | 144 TestingPrefServiceSimple pref_service_; |
139 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; | 145 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; |
140 | 146 |
141 private: | 147 private: |
142 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); | 148 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); |
143 }; | 149 }; |
144 | 150 |
145 TEST_F(HttpServerPropertiesManagerTest, | 151 TEST_F(HttpServerPropertiesManagerTest, |
146 SingleUpdateForTwoSpdyServerPrefChanges) { | 152 SingleUpdateForTwoSpdyServerPrefChanges) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 229 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
224 | 230 |
225 // Verify SupportsSpdy. | 231 // Verify SupportsSpdy. |
226 EXPECT_TRUE( | 232 EXPECT_TRUE( |
227 http_server_props_manager_->SupportsRequestPriority(google_server)); | 233 http_server_props_manager_->SupportsRequestPriority(google_server)); |
228 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); | 234 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); |
229 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 235 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
230 HostPortPair::FromString("foo.google.com:1337"))); | 236 HostPortPair::FromString("foo.google.com:1337"))); |
231 | 237 |
232 // Verify AlternateProtocol. | 238 // Verify AlternateProtocol. |
233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); | |
234 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); | |
235 AlternateProtocolInfo port_alternate_protocol = | 239 AlternateProtocolInfo port_alternate_protocol = |
236 http_server_props_manager_->GetAlternateProtocol(google_server); | 240 http_server_props_manager_->GetAlternateProtocol(google_server); |
237 EXPECT_EQ(443, port_alternate_protocol.port); | 241 EXPECT_EQ(443, port_alternate_protocol.port); |
238 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 242 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
239 port_alternate_protocol = | 243 port_alternate_protocol = |
240 http_server_props_manager_->GetAlternateProtocol(mail_server); | 244 http_server_props_manager_->GetAlternateProtocol(mail_server); |
241 EXPECT_EQ(444, port_alternate_protocol.port); | 245 EXPECT_EQ(444, port_alternate_protocol.port); |
242 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); | 246 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); |
243 | 247 |
244 // Verify SupportsQuic. | 248 // Verify SupportsQuic. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 // Set up the pref. | 304 // Set up the pref. |
301 pref_service_.SetManagedPref(kTestHttpServerProperties, | 305 pref_service_.SetManagedPref(kTestHttpServerProperties, |
302 http_server_properties_dict); | 306 http_server_properties_dict); |
303 | 307 |
304 base::RunLoop().RunUntilIdle(); | 308 base::RunLoop().RunUntilIdle(); |
305 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 309 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
306 | 310 |
307 // Verify that nothing is set. | 311 // Verify that nothing is set. |
308 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 312 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
309 HostPortPair::FromString("www.google.com:65536"))); | 313 HostPortPair::FromString("www.google.com:65536"))); |
310 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( | 314 EXPECT_FALSE( |
311 HostPortPair::FromString("www.google.com:65536"))); | 315 HasAlternateProtocol(HostPortPair::FromString("www.google.com:65536"))); |
312 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic( | 316 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic( |
313 HostPortPair::FromString("www.google.com:65536")); | 317 HostPortPair::FromString("www.google.com:65536")); |
314 EXPECT_FALSE(supports_quic2.used_quic); | 318 EXPECT_FALSE(supports_quic2.used_quic); |
315 const ServerNetworkStats* stats1 = | 319 const ServerNetworkStats* stats1 = |
316 http_server_props_manager_->GetServerNetworkStats( | 320 http_server_props_manager_->GetServerNetworkStats( |
317 HostPortPair::FromString("www.google.com:65536")); | 321 HostPortPair::FromString("www.google.com:65536")); |
318 EXPECT_EQ(NULL, stats1); | 322 EXPECT_EQ(NULL, stats1); |
319 } | 323 } |
320 | 324 |
321 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 325 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
(...skipping 23 matching lines...) Expand all Loading... |
345 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 349 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
346 | 350 |
347 // Set up the pref. | 351 // Set up the pref. |
348 pref_service_.SetManagedPref(kTestHttpServerProperties, | 352 pref_service_.SetManagedPref(kTestHttpServerProperties, |
349 http_server_properties_dict); | 353 http_server_properties_dict); |
350 | 354 |
351 base::RunLoop().RunUntilIdle(); | 355 base::RunLoop().RunUntilIdle(); |
352 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 356 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
353 | 357 |
354 // Verify AlternateProtocol is not set. | 358 // Verify AlternateProtocol is not set. |
355 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( | 359 EXPECT_FALSE( |
356 HostPortPair::FromString("www.google.com:80"))); | 360 HasAlternateProtocol(HostPortPair::FromString("www.google.com:80"))); |
357 } | 361 } |
358 | 362 |
359 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 363 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
360 ExpectPrefsUpdate(); | 364 ExpectPrefsUpdate(); |
361 | 365 |
362 // Post an update task to the network thread. SetSupportsSpdy calls | 366 // Post an update task to the network thread. SetSupportsSpdy calls |
363 // ScheduleUpdatePrefsOnNetworkThread. | 367 // ScheduleUpdatePrefsOnNetworkThread. |
364 | 368 |
365 // Add mail.google.com:443 as a supporting spdy server. | 369 // Add mail.google.com:443 as a supporting spdy server. |
366 HostPortPair spdy_server_mail("mail.google.com", 443); | 370 HostPortPair spdy_server_mail("mail.google.com", 443); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 base::RunLoop().RunUntilIdle(); | 474 base::RunLoop().RunUntilIdle(); |
471 | 475 |
472 // Verify that there are no entries in the settings map. | 476 // Verify that there are no entries in the settings map. |
473 const SpdySettingsMap& spdy_settings_map2_ret = | 477 const SpdySettingsMap& spdy_settings_map2_ret = |
474 http_server_props_manager_->spdy_settings_map(); | 478 http_server_props_manager_->spdy_settings_map(); |
475 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); | 479 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); |
476 | 480 |
477 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 481 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
478 } | 482 } |
479 | 483 |
480 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { | 484 TEST_F(HttpServerPropertiesManagerTest, GetAlternateProtocol) { |
481 ExpectPrefsUpdate(); | 485 ExpectPrefsUpdate(); |
482 | 486 |
483 HostPortPair spdy_server_mail("mail.google.com", 80); | 487 HostPortPair spdy_server_mail("mail.google.com", 80); |
484 EXPECT_FALSE( | 488 EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail)); |
485 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | |
486 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 489 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, |
487 NPN_SPDY_3, 1.0); | 490 NPN_SPDY_3, 1.0); |
488 | 491 |
489 // Run the task. | 492 // Run the task. |
490 base::RunLoop().RunUntilIdle(); | 493 base::RunLoop().RunUntilIdle(); |
491 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 494 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
492 | 495 |
493 ASSERT_TRUE( | 496 const AlternateProtocolInfo alternate_protocol = |
494 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | |
495 AlternateProtocolInfo port_alternate_protocol = | |
496 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 497 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
497 EXPECT_EQ(443, port_alternate_protocol.port); | 498 EXPECT_EQ(443, alternate_protocol.port); |
498 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 499 EXPECT_EQ(NPN_SPDY_3, alternate_protocol.protocol); |
| 500 EXPECT_EQ(1.0, alternate_protocol.probability); |
499 } | 501 } |
500 | 502 |
501 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { | 503 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { |
502 ExpectPrefsUpdate(); | 504 ExpectPrefsUpdate(); |
503 | 505 |
504 HostPortPair quic_server_mail("mail.google.com", 80); | 506 HostPortPair quic_server_mail("mail.google.com", 80); |
505 SupportsQuic supports_quic = | 507 SupportsQuic supports_quic = |
506 http_server_props_manager_->GetSupportsQuic(quic_server_mail); | 508 http_server_props_manager_->GetSupportsQuic(quic_server_mail); |
507 EXPECT_FALSE(supports_quic.used_quic); | 509 EXPECT_FALSE(supports_quic.used_quic); |
508 EXPECT_EQ("", supports_quic.address); | 510 EXPECT_EQ("", supports_quic.address); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 556 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
555 const uint32 value1 = 31337; | 557 const uint32 value1 = 31337; |
556 http_server_props_manager_->SetSpdySetting( | 558 http_server_props_manager_->SetSpdySetting( |
557 spdy_server_mail, id1, flags1, value1); | 559 spdy_server_mail, id1, flags1, value1); |
558 | 560 |
559 // Run the task. | 561 // Run the task. |
560 base::RunLoop().RunUntilIdle(); | 562 base::RunLoop().RunUntilIdle(); |
561 | 563 |
562 EXPECT_TRUE( | 564 EXPECT_TRUE( |
563 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 565 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
564 EXPECT_TRUE( | 566 EXPECT_TRUE(HasAlternateProtocol(spdy_server_mail)); |
565 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | |
566 SupportsQuic supports_quic = | 567 SupportsQuic supports_quic = |
567 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); | 568 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); |
568 EXPECT_TRUE(supports_quic.used_quic); | 569 EXPECT_TRUE(supports_quic.used_quic); |
569 EXPECT_EQ("foo", supports_quic.address); | 570 EXPECT_EQ("foo", supports_quic.address); |
570 const ServerNetworkStats* stats1 = | 571 const ServerNetworkStats* stats1 = |
571 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 572 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
572 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); | 573 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); |
573 | 574 |
574 // Check SPDY settings values. | 575 // Check SPDY settings values. |
575 const SettingsMap& settings_map1_ret = | 576 const SettingsMap& settings_map1_ret = |
576 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 577 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
577 ASSERT_EQ(1U, settings_map1_ret.size()); | 578 ASSERT_EQ(1U, settings_map1_ret.size()); |
578 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 579 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
579 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 580 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
580 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 581 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
581 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 582 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
582 EXPECT_EQ(value1, flags_and_value1_ret.second); | 583 EXPECT_EQ(value1, flags_and_value1_ret.second); |
583 | 584 |
584 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 585 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
585 | 586 |
586 ExpectPrefsUpdate(); | 587 ExpectPrefsUpdate(); |
587 | 588 |
588 // Clear http server data, time out if we do not get a completion callback. | 589 // Clear http server data, time out if we do not get a completion callback. |
589 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); | 590 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); |
590 base::RunLoop().Run(); | 591 base::RunLoop().Run(); |
591 | 592 |
592 EXPECT_FALSE( | 593 EXPECT_FALSE( |
593 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 594 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
594 EXPECT_FALSE( | 595 EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail)); |
595 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | |
596 SupportsQuic supports_quic1 = | 596 SupportsQuic supports_quic1 = |
597 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); | 597 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); |
598 EXPECT_FALSE(supports_quic1.used_quic); | 598 EXPECT_FALSE(supports_quic1.used_quic); |
599 EXPECT_EQ("", supports_quic1.address); | 599 EXPECT_EQ("", supports_quic1.address); |
600 const ServerNetworkStats* stats2 = | 600 const ServerNetworkStats* stats2 = |
601 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 601 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
602 EXPECT_EQ(NULL, stats2); | 602 EXPECT_EQ(NULL, stats2); |
603 | 603 |
604 const SettingsMap& settings_map2_ret = | 604 const SettingsMap& settings_map2_ret = |
605 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 605 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 // Set up the pref. | 647 // Set up the pref. |
648 pref_service_.SetManagedPref(kTestHttpServerProperties, | 648 pref_service_.SetManagedPref(kTestHttpServerProperties, |
649 http_server_properties_dict); | 649 http_server_properties_dict); |
650 | 650 |
651 base::RunLoop().RunUntilIdle(); | 651 base::RunLoop().RunUntilIdle(); |
652 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 652 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
653 | 653 |
654 // Verify AlternateProtocol. | 654 // Verify AlternateProtocol. |
655 for (int i = 0; i < 200; ++i) { | 655 for (int i = 0; i < 200; ++i) { |
656 std::string server = StringPrintf("www.google.com:%d", i); | 656 std::string server = StringPrintf("www.google.com:%d", i); |
657 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | |
658 HostPortPair::FromString(server))); | |
659 AlternateProtocolInfo port_alternate_protocol = | 657 AlternateProtocolInfo port_alternate_protocol = |
660 http_server_props_manager_->GetAlternateProtocol( | 658 http_server_props_manager_->GetAlternateProtocol( |
661 HostPortPair::FromString(server)); | 659 HostPortPair::FromString(server)); |
662 EXPECT_EQ(i, port_alternate_protocol.port); | 660 EXPECT_EQ(i, port_alternate_protocol.port); |
663 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 661 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
664 } | 662 } |
665 | 663 |
666 // Verify SupportsQuic. | 664 // Verify SupportsQuic. |
667 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( | 665 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( |
668 HostPortPair::FromString("mail.google.com:80")); | 666 HostPortPair::FromString("mail.google.com:80")); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 // Run the task after shutdown, but before deletion. | 736 // Run the task after shutdown, but before deletion. |
739 base::RunLoop().RunUntilIdle(); | 737 base::RunLoop().RunUntilIdle(); |
740 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 738 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
741 http_server_props_manager_.reset(); | 739 http_server_props_manager_.reset(); |
742 base::RunLoop().RunUntilIdle(); | 740 base::RunLoop().RunUntilIdle(); |
743 } | 741 } |
744 | 742 |
745 } // namespace | 743 } // namespace |
746 | 744 |
747 } // namespace net | 745 } // namespace net |
OLD | NEW |