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

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

Issue 997953003: Add IsAlternativeServiceBroken(), remove is_broken. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove ignore_result. Created 5 years, 9 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"
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "net/base/host_port_pair.h" 15 #include "net/base/host_port_pair.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 namespace base { 18 namespace base {
19 class ListValue; 19 class ListValue;
20 } 20 }
21 21
22 namespace net { 22 namespace net {
23 23
24 const int kMaxSupportsSpdyServerHosts = 500; 24 const int kMaxSupportsSpdyServerHosts = 500;
25 25
26 class HttpServerPropertiesImplPeer {
27 public:
28 static void AddBrokenAlternativeServiceWithExpirationTime(
29 HttpServerPropertiesImpl& impl,
30 AlternativeService alternative_service,
31 base::TimeTicks when) {
32 impl.broken_alternative_services_.insert(
33 std::make_pair(alternative_service, when));
34 ++impl.recently_broken_alternative_services_[alternative_service];
35 }
36
37 static void ExpireBrokenAlternateProtocolMappings(
38 HttpServerPropertiesImpl& impl) {
39 impl.ExpireBrokenAlternateProtocolMappings();
40 }
41 };
42
26 namespace { 43 namespace {
27 44
28 class HttpServerPropertiesImplTest : public testing::Test { 45 class HttpServerPropertiesImplTest : public testing::Test {
29 protected: 46 protected:
30 bool HasAlternateProtocol(const HostPortPair& server) { 47 bool HasAlternateProtocol(const HostPortPair& server) {
31 const AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(server); 48 const AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(server);
32 return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; 49 return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL;
33 } 50 }
34 51
35 HttpServerPropertiesImpl impl_; 52 HttpServerPropertiesImpl impl_;
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); 300 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map);
284 301
285 // Verify test_host_port_pair3 is the MRU server. 302 // Verify test_host_port_pair3 is the MRU server.
286 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); 303 const AlternateProtocolMap& map = impl_.alternate_protocol_map();
287 AlternateProtocolMap::const_iterator it = map.begin(); 304 AlternateProtocolMap::const_iterator it = map.begin();
288 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); 305 EXPECT_TRUE(it->first.Equals(test_host_port_pair3));
289 EXPECT_EQ(1234, it->second.port); 306 EXPECT_EQ(1234, it->second.port);
290 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); 307 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
291 308
292 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair1)); 309 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair1));
293 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair2)); 310 const AlternativeService alternative_service(
294 alternate = impl_.GetAlternateProtocol(test_host_port_pair1); 311 NPN_SPDY_3, test_host_port_pair1.host(), 443);
295 EXPECT_TRUE(alternate.is_broken); 312 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service));
296 alternate = impl_.GetAlternateProtocol(test_host_port_pair2); 313 alternate = impl_.GetAlternateProtocol(test_host_port_pair2);
297 EXPECT_EQ(123, alternate.port); 314 EXPECT_EQ(123, alternate.port);
298 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); 315 EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
299 } 316 }
300 317
301 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { 318 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) {
302 HostPortPair test_host_port_pair1("foo1", 80); 319 HostPortPair test_host_port_pair1("foo1", 80);
303 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); 320 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0);
304 HostPortPair test_host_port_pair2("foo2", 80); 321 HostPortPair test_host_port_pair2("foo2", 80);
305 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0); 322 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0);
(...skipping 13 matching lines...) Expand all
319 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); 336 EXPECT_TRUE(it->first.Equals(test_host_port_pair1));
320 EXPECT_EQ(443, it->second.port); 337 EXPECT_EQ(443, it->second.port);
321 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); 338 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
322 } 339 }
323 340
324 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { 341 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) {
325 HostPortPair test_host_port_pair("foo", 80); 342 HostPortPair test_host_port_pair("foo", 80);
326 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); 343 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0);
327 impl_.SetBrokenAlternateProtocol(test_host_port_pair); 344 impl_.SetBrokenAlternateProtocol(test_host_port_pair);
328 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); 345 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair));
329 AlternateProtocolInfo alternate = 346 const AlternativeService alternative_service(NPN_SPDY_3,
330 impl_.GetAlternateProtocol(test_host_port_pair); 347 test_host_port_pair.host(), 443);
331 EXPECT_TRUE(alternate.is_broken); 348 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service));
332 349
333 impl_.SetAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1.0); 350 impl_.SetAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1.0);
334 alternate = impl_.GetAlternateProtocol(test_host_port_pair); 351 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service));
335 EXPECT_TRUE(alternate.is_broken) << "Second attempt should be ignored."; 352 const AlternateProtocolInfo alternate =
353 impl_.GetAlternateProtocol(test_host_port_pair);
354 EXPECT_EQ(1234, alternate.port);
336 } 355 }
337 356
338 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { 357 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) {
339 HostPortPair test_host_port_pair("foo", 80); 358 HostPortPair test_host_port_pair("foo", 80);
340 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); 359 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0);
341 impl_.SetBrokenAlternateProtocol(test_host_port_pair); 360 impl_.SetBrokenAlternateProtocol(test_host_port_pair);
342 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); 361 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair));
343 AlternateProtocolInfo alternate = 362 const AlternativeService alternative_service(NPN_SPDY_3,
344 impl_.GetAlternateProtocol(test_host_port_pair); 363 test_host_port_pair.host(), 443);
345 EXPECT_TRUE(alternate.is_broken); 364 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service));
346 impl_.ClearAlternateProtocol(test_host_port_pair); 365 impl_.ClearAlternateProtocol(test_host_port_pair);
347 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); 366 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
348 } 367 }
349 368
350 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { 369 TEST_F(AlternateProtocolServerPropertiesTest, Forced) {
351 // Test forced alternate protocols. 370 // Test forced alternate protocols.
352 371
353 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); 372 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1);
354 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); 373 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol);
355 374
356 // Verify the forced protocol. 375 // Verify the forced protocol.
357 HostPortPair test_host_port_pair("foo", 80); 376 HostPortPair test_host_port_pair("foo", 80);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); 470 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
452 471
453 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, 472 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port,
454 canonical_protocol.protocol, 473 canonical_protocol.protocol,
455 canonical_protocol.probability); 474 canonical_protocol.probability);
456 475
457 impl_.SetBrokenAlternateProtocol(canonical_port_pair); 476 impl_.SetBrokenAlternateProtocol(canonical_port_pair);
458 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); 477 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair));
459 } 478 }
460 479
461 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken2) {
462 HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
463 HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
464
465 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
466
467 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port,
468 canonical_protocol.protocol,
469 canonical_protocol.probability);
470
471 impl_.SetBrokenAlternateProtocol(test_host_port_pair);
472 AlternateProtocolInfo alternate =
473 impl_.GetAlternateProtocol(test_host_port_pair);
474 EXPECT_TRUE(alternate.is_broken);
475 }
476
477 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { 480 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) {
478 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); 481 HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
479 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); 482 HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
480 483
481 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); 484 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
482 485
483 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, 486 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port,
484 canonical_protocol.protocol, 487 canonical_protocol.protocol,
485 canonical_protocol.probability); 488 canonical_protocol.probability);
486 489
487 impl_.Clear(); 490 impl_.Clear();
488 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); 491 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair));
489 } 492 }
490 493
494 TEST_F(AlternateProtocolServerPropertiesTest,
495 ExpireBrokenAlternateProtocolMappings) {
496 HostPortPair host_port_pair("foo", 443);
497 AlternativeService alternative_service(QUIC, "foo", 443);
498 impl_.SetAlternateProtocol(host_port_pair, 443, QUIC, 1.0);
499 EXPECT_TRUE(HasAlternateProtocol(host_port_pair));
500 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
501 EXPECT_FALSE(impl_.WasAlternateProtocolRecentlyBroken(host_port_pair));
502
503 base::TimeTicks past =
504 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42);
505 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime(
506 impl_, alternative_service, past);
507 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service));
508 EXPECT_TRUE(impl_.WasAlternateProtocolRecentlyBroken(host_port_pair));
509
510 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_);
511 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
512 // TODO(bnc): Test WasAlternateProtocolRecentlyBroken once it's changed to
513 // take AlternativeService as argument.
514 }
515
491 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; 516 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest;
492 517
493 TEST_F(SpdySettingsServerPropertiesTest, Initialize) { 518 TEST_F(SpdySettingsServerPropertiesTest, Initialize) {
494 HostPortPair spdy_server_google("www.google.com", 443); 519 HostPortPair spdy_server_google("www.google.com", 443);
495 520
496 // Check by initializing empty spdy settings. 521 // Check by initializing empty spdy settings.
497 SpdySettingsMap spdy_settings_map(SpdySettingsMap::NO_AUTO_EVICT); 522 SpdySettingsMap spdy_settings_map(SpdySettingsMap::NO_AUTO_EVICT);
498 impl_.InitializeSpdySettingsServers(&spdy_settings_map); 523 impl_.InitializeSpdySettingsServers(&spdy_settings_map);
499 EXPECT_TRUE(impl_.GetSpdySettings(spdy_server_google).empty()); 524 EXPECT_TRUE(impl_.GetSpdySettings(spdy_server_google).empty());
500 525
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
752 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); 777 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond());
753 778
754 impl_.Clear(); 779 impl_.Clear();
755 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); 780 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server);
756 EXPECT_EQ(NULL, stats3); 781 EXPECT_EQ(NULL, stats3);
757 } 782 }
758 783
759 } // namespace 784 } // namespace
760 785
761 } // namespace net 786 } // 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