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

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

Issue 839143002: Roll Chrome into Mojo. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 11 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
« no previous file with comments | « net/http/http_server_properties_impl.cc ('k') | net/http/http_server_properties_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_server_properties_impl.h" 5 #include "net/http/http_server_properties_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 AlternateProtocolMap alternate_protocol_map( 288 AlternateProtocolMap alternate_protocol_map(
289 AlternateProtocolMap::NO_AUTO_EVICT); 289 AlternateProtocolMap::NO_AUTO_EVICT);
290 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1); 290 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1);
291 alternate_protocol_map.Put(test_host_port_pair2, alternate); 291 alternate_protocol_map.Put(test_host_port_pair2, alternate);
292 HostPortPair test_host_port_pair3("foo3", 80); 292 HostPortPair test_host_port_pair3("foo3", 80);
293 alternate.port = 1234; 293 alternate.port = 1234;
294 alternate_protocol_map.Put(test_host_port_pair3, alternate); 294 alternate_protocol_map.Put(test_host_port_pair3, alternate);
295 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); 295 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map);
296 296
297 // Verify test_host_port_pair3 is the MRU server. 297 // Verify test_host_port_pair3 is the MRU server.
298 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map(); 298 const AlternateProtocolMap& map = impl_.alternate_protocol_map();
299 net::AlternateProtocolMap::const_iterator it = map.begin(); 299 AlternateProtocolMap::const_iterator it = map.begin();
300 it = map.begin(); 300 it = map.begin();
301 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); 301 EXPECT_TRUE(it->first.Equals(test_host_port_pair3));
302 EXPECT_EQ(1234, it->second.port); 302 EXPECT_EQ(1234, it->second.port);
303 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); 303 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
304 304
305 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); 305 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1));
306 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2)); 306 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2));
307 alternate = impl_.GetAlternateProtocol(test_host_port_pair1); 307 alternate = impl_.GetAlternateProtocol(test_host_port_pair1);
308 EXPECT_TRUE(alternate.is_broken); 308 EXPECT_TRUE(alternate.is_broken);
309 alternate = impl_.GetAlternateProtocol(test_host_port_pair2); 309 alternate = impl_.GetAlternateProtocol(test_host_port_pair2);
310 EXPECT_EQ(123, alternate.port); 310 EXPECT_EQ(123, alternate.port);
311 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); 311 EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
312 } 312 }
313 313
314 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfHasAlternateProtocol) { 314 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfHasAlternateProtocol) {
315 HostPortPair test_host_port_pair1("foo1", 80); 315 HostPortPair test_host_port_pair1("foo1", 80);
316 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1); 316 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1);
317 HostPortPair test_host_port_pair2("foo2", 80); 317 HostPortPair test_host_port_pair2("foo2", 80);
318 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1); 318 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1);
319 319
320 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map(); 320 const AlternateProtocolMap& map = impl_.alternate_protocol_map();
321 net::AlternateProtocolMap::const_iterator it = map.begin(); 321 AlternateProtocolMap::const_iterator it = map.begin();
322 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); 322 EXPECT_TRUE(it->first.Equals(test_host_port_pair2));
323 EXPECT_EQ(1234, it->second.port); 323 EXPECT_EQ(1234, it->second.port);
324 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); 324 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
325 325
326 // HasAlternateProtocol should reoder the AlternateProtocol map. 326 // HasAlternateProtocol should reoder the AlternateProtocol map.
327 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); 327 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1));
328 it = map.begin(); 328 it = map.begin();
329 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); 329 EXPECT_TRUE(it->first.Equals(test_host_port_pair1));
330 EXPECT_EQ(443, it->second.port); 330 EXPECT_EQ(443, it->second.port);
331 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); 331 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
332 } 332 }
333 333
334 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { 334 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) {
335 HostPortPair test_host_port_pair1("foo1", 80); 335 HostPortPair test_host_port_pair1("foo1", 80);
336 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1); 336 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1);
337 HostPortPair test_host_port_pair2("foo2", 80); 337 HostPortPair test_host_port_pair2("foo2", 80);
338 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1); 338 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1);
339 339
340 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map(); 340 const AlternateProtocolMap& map = impl_.alternate_protocol_map();
341 net::AlternateProtocolMap::const_iterator it = map.begin(); 341 AlternateProtocolMap::const_iterator it = map.begin();
342 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); 342 EXPECT_TRUE(it->first.Equals(test_host_port_pair2));
343 EXPECT_EQ(1234, it->second.port); 343 EXPECT_EQ(1234, it->second.port);
344 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); 344 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
345 345
346 // GetAlternateProtocol should reoder the AlternateProtocol map. 346 // GetAlternateProtocol should reoder the AlternateProtocol map.
347 AlternateProtocolInfo alternate = 347 AlternateProtocolInfo alternate =
348 impl_.GetAlternateProtocol(test_host_port_pair1); 348 impl_.GetAlternateProtocol(test_host_port_pair1);
349 EXPECT_EQ(443, alternate.port); 349 EXPECT_EQ(443, alternate.port);
350 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); 350 EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
351 it = map.begin(); 351 it = map.begin();
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_google, id1, flags1, value1)); 678 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_google, id1, flags1, value1));
679 679
680 // Add docs.google.com:443 as persisting 680 // Add docs.google.com:443 as persisting
681 HostPortPair spdy_server_docs("docs.google.com", 443); 681 HostPortPair spdy_server_docs("docs.google.com", 443);
682 const SpdySettingsIds id2 = SETTINGS_ROUND_TRIP_TIME; 682 const SpdySettingsIds id2 = SETTINGS_ROUND_TRIP_TIME;
683 const SpdySettingsFlags flags2 = SETTINGS_FLAG_PLEASE_PERSIST; 683 const SpdySettingsFlags flags2 = SETTINGS_FLAG_PLEASE_PERSIST;
684 const uint32 value2 = 93997; 684 const uint32 value2 = 93997;
685 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_docs, id2, flags2, value2)); 685 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_docs, id2, flags2, value2));
686 686
687 // Verify the first element is docs.google.com:443. 687 // Verify the first element is docs.google.com:443.
688 const net::SpdySettingsMap& map = impl_.spdy_settings_map(); 688 const SpdySettingsMap& map = impl_.spdy_settings_map();
689 net::SpdySettingsMap::const_iterator it = map.begin(); 689 SpdySettingsMap::const_iterator it = map.begin();
690 EXPECT_TRUE(it->first.Equals(spdy_server_docs)); 690 EXPECT_TRUE(it->first.Equals(spdy_server_docs));
691 const SettingsMap& settings_map2_ret = it->second; 691 const SettingsMap& settings_map2_ret = it->second;
692 ASSERT_EQ(1U, settings_map2_ret.size()); 692 ASSERT_EQ(1U, settings_map2_ret.size());
693 SettingsMap::const_iterator it2_ret = settings_map2_ret.find(id2); 693 SettingsMap::const_iterator it2_ret = settings_map2_ret.find(id2);
694 EXPECT_TRUE(it2_ret != settings_map2_ret.end()); 694 EXPECT_TRUE(it2_ret != settings_map2_ret.end());
695 SettingsFlagsAndValue flags_and_value2_ret = it2_ret->second; 695 SettingsFlagsAndValue flags_and_value2_ret = it2_ret->second;
696 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2_ret.first); 696 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2_ret.first);
697 EXPECT_EQ(value2, flags_and_value2_ret.second); 697 EXPECT_EQ(value2, flags_and_value2_ret.second);
698 698
699 // GetSpdySettings should reoder the SpdySettingsMap. 699 // GetSpdySettings should reoder the SpdySettingsMap.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 impl_.SetSupportsQuic(test_host_port_pair, true, "foo"); 748 impl_.SetSupportsQuic(test_host_port_pair, true, "foo");
749 SupportsQuic supports_quic1 = impl_.GetSupportsQuic(test_host_port_pair); 749 SupportsQuic supports_quic1 = impl_.GetSupportsQuic(test_host_port_pair);
750 EXPECT_TRUE(supports_quic1.used_quic); 750 EXPECT_TRUE(supports_quic1.used_quic);
751 EXPECT_EQ("foo", supports_quic1.address); 751 EXPECT_EQ("foo", supports_quic1.address);
752 752
753 impl_.Clear(); 753 impl_.Clear();
754 SupportsQuic supports_quic2 = impl_.GetSupportsQuic(test_host_port_pair); 754 SupportsQuic supports_quic2 = impl_.GetSupportsQuic(test_host_port_pair);
755 EXPECT_FALSE(supports_quic2.used_quic); 755 EXPECT_FALSE(supports_quic2.used_quic);
756 EXPECT_EQ("", supports_quic2.address); 756 EXPECT_EQ("", supports_quic2.address);
757 } 757 }
758
759 typedef HttpServerPropertiesImplTest ServerNetworkStatsServerPropertiesTest;
760
761 TEST_F(ServerNetworkStatsServerPropertiesTest, Initialize) {
762 HostPortPair google_server("www.google.com", 443);
763
764 // Check by initializing empty ServerNetworkStats.
765 ServerNetworkStatsMap server_network_stats_map(
766 ServerNetworkStatsMap::NO_AUTO_EVICT);
767 impl_.InitializeServerNetworkStats(&server_network_stats_map);
768 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(google_server);
769 EXPECT_EQ(NULL, stats);
770
771 // Check by initializing with www.google.com:443.
772 ServerNetworkStats stats1;
773 stats1.srtt = base::TimeDelta::FromMicroseconds(10);
774 stats1.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100);
775 server_network_stats_map.Put(google_server, stats1);
776 impl_.InitializeServerNetworkStats(&server_network_stats_map);
777
778 const ServerNetworkStats* stats2 = impl_.GetServerNetworkStats(google_server);
779 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
780 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond());
781 }
782
783 TEST_F(ServerNetworkStatsServerPropertiesTest, SetServerNetworkStats) {
784 HostPortPair foo_server("foo", 80);
785 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(foo_server);
786 EXPECT_EQ(NULL, stats);
787
788 ServerNetworkStats stats1;
789 stats1.srtt = base::TimeDelta::FromMicroseconds(10);
790 stats1.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100);
791 impl_.SetServerNetworkStats(foo_server, stats1);
792
793 const ServerNetworkStats* stats2 = impl_.GetServerNetworkStats(foo_server);
794 EXPECT_EQ(10, stats2->srtt.ToInternalValue());
795 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond());
796
797 impl_.Clear();
798 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server);
799 EXPECT_EQ(NULL, stats3);
800 }
801
758 } // namespace 802 } // namespace
759 803
760 } // namespace net 804 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_impl.cc ('k') | net/http/http_server_properties_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698