| OLD | NEW |
| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 const SpdySettingsIds kSpdySettingsId = SETTINGS_UPLOAD_BANDWIDTH; | 49 const SpdySettingsIds kSpdySettingsId = SETTINGS_UPLOAD_BANDWIDTH; |
| 50 const SpdySettingsFlags kSpdySettingsFlags = SETTINGS_FLAG_PERSISTED; | 50 const SpdySettingsFlags kSpdySettingsFlags = SETTINGS_FLAG_PERSISTED; |
| 51 | 51 |
| 52 struct SpdySettingsDataToVerify { | 52 struct SpdySettingsDataToVerify { |
| 53 url::SchemeHostPort spdy_server; | 53 url::SchemeHostPort spdy_server; |
| 54 uint32_t value; | 54 uint32_t value; |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class HttpServerPropertiesImplTest : public testing::Test { | 57 class HttpServerPropertiesImplTest : public testing::Test { |
| 58 protected: | 58 protected: |
| 59 bool HasAlternativeService(const HostPortPair& origin) { | 59 bool HasAlternativeService(const url::SchemeHostPort& origin) { |
| 60 const AlternativeServiceVector alternative_service_vector = | 60 const AlternativeServiceVector alternative_service_vector = |
| 61 impl_.GetAlternativeServices(origin); | 61 impl_.GetAlternativeServices(origin); |
| 62 return !alternative_service_vector.empty(); | 62 return !alternative_service_vector.empty(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool SetAlternativeService(const HostPortPair& origin, | 65 bool SetAlternativeService(const url::SchemeHostPort& origin, |
| 66 const AlternativeService& alternative_service) { | 66 const AlternativeService& alternative_service) { |
| 67 const base::Time expiration = | 67 const base::Time expiration = |
| 68 base::Time::Now() + base::TimeDelta::FromDays(1); | 68 base::Time::Now() + base::TimeDelta::FromDays(1); |
| 69 return impl_.SetAlternativeService(origin, alternative_service, expiration); | 69 return impl_.SetAlternativeService(origin, alternative_service, expiration); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void InitializeSpdySettingsUploadBandwidth( | 72 void InitializeSpdySettingsUploadBandwidth( |
| 73 SpdySettingsMap* spdy_settings_map, | 73 SpdySettingsMap* spdy_settings_map, |
| 74 const url::SchemeHostPort& spdy_server, | 74 const url::SchemeHostPort& spdy_server, |
| 75 uint32_t value) { | 75 uint32_t value) { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // Add mail.google.com:443 as not supporting SPDY. | 240 // Add mail.google.com:443 as not supporting SPDY. |
| 241 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); | 241 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 242 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 242 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 243 | 243 |
| 244 // Add docs.google.com:443 as supporting SPDY. | 244 // Add docs.google.com:443 as supporting SPDY. |
| 245 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); | 245 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
| 246 impl_.SetSupportsSpdy(spdy_server_docs, true); | 246 impl_.SetSupportsSpdy(spdy_server_docs, true); |
| 247 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 247 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 248 | 248 |
| 249 // Add www.youtube.com:443 as supporting QUIC. | 249 // Add www.youtube.com:443 as supporting QUIC. |
| 250 HostPortPair quic_server_youtube("www.youtube.com", 443); | |
| 251 url::SchemeHostPort youtube_server("https", "www.youtube.com", 443); | 250 url::SchemeHostPort youtube_server("https", "www.youtube.com", 443); |
| 252 const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443); | 251 const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443); |
| 253 SetAlternativeService(quic_server_youtube, alternative_service1); | 252 SetAlternativeService(youtube_server, alternative_service1); |
| 254 EXPECT_TRUE(impl_.SupportsRequestPriority(youtube_server)); | 253 EXPECT_TRUE(impl_.SupportsRequestPriority(youtube_server)); |
| 255 | 254 |
| 256 // Add www.example.com:443 with two alternative services, one supporting QUIC. | 255 // Add www.example.com:443 with two alternative services, one supporting QUIC. |
| 257 HostPortPair quic_server_example("www.example.com", 443); | |
| 258 url::SchemeHostPort example_server("https", "www.example.com", 443); | 256 url::SchemeHostPort example_server("https", "www.example.com", 443); |
| 259 const AlternativeService alternative_service2(NPN_HTTP_2, "", 443); | 257 const AlternativeService alternative_service2(NPN_HTTP_2, "", 443); |
| 260 SetAlternativeService(quic_server_example, alternative_service2); | 258 SetAlternativeService(example_server, alternative_service2); |
| 261 SetAlternativeService(quic_server_example, alternative_service1); | 259 SetAlternativeService(example_server, alternative_service1); |
| 262 EXPECT_TRUE(impl_.SupportsRequestPriority(example_server)); | 260 EXPECT_TRUE(impl_.SupportsRequestPriority(example_server)); |
| 263 | 261 |
| 264 // Verify all the entries are the same after additions. | 262 // Verify all the entries are the same after additions. |
| 265 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 263 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 266 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 264 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 267 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 265 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 268 EXPECT_TRUE(impl_.SupportsRequestPriority(youtube_server)); | 266 EXPECT_TRUE(impl_.SupportsRequestPriority(youtube_server)); |
| 269 EXPECT_TRUE(impl_.SupportsRequestPriority(example_server)); | 267 EXPECT_TRUE(impl_.SupportsRequestPriority(example_server)); |
| 270 } | 268 } |
| 271 | 269 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 ASSERT_EQ(2U, spdy_server_list.GetSize()); | 373 ASSERT_EQ(2U, spdy_server_list.GetSize()); |
| 376 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 374 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
| 377 ASSERT_EQ(spdy_server_g, string_value_g); | 375 ASSERT_EQ(spdy_server_g, string_value_g); |
| 378 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); | 376 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); |
| 379 ASSERT_EQ(spdy_server_m, string_value_m); | 377 ASSERT_EQ(spdy_server_m, string_value_m); |
| 380 } | 378 } |
| 381 | 379 |
| 382 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; | 380 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; |
| 383 | 381 |
| 384 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { | 382 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { |
| 385 HostPortPair test_host_port_pair("foo", 80); | 383 url::SchemeHostPort test_server("http", "foo", 80); |
| 386 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 384 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 387 | 385 |
| 388 AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); | 386 AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
| 389 SetAlternativeService(test_host_port_pair, alternative_service); | 387 SetAlternativeService(test_server, alternative_service); |
| 390 const AlternativeServiceVector alternative_service_vector = | 388 const AlternativeServiceVector alternative_service_vector = |
| 391 impl_.GetAlternativeServices(test_host_port_pair); | 389 impl_.GetAlternativeServices(test_server); |
| 392 ASSERT_EQ(1u, alternative_service_vector.size()); | 390 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 393 EXPECT_EQ(alternative_service, alternative_service_vector[0]); | 391 EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 394 | 392 |
| 395 impl_.Clear(); | 393 impl_.Clear(); |
| 396 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 394 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 397 } | 395 } |
| 398 | 396 |
| 399 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { | 397 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { |
| 400 AlternativeServiceInfoVector alternative_service_info_vector; | 398 AlternativeServiceInfoVector alternative_service_info_vector; |
| 401 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 399 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 402 // Same hostname, same port, TCP: should be ignored. | 400 // Same hostname, same port, TCP: should be ignored. |
| 403 AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); | 401 AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); |
| 404 alternative_service_info_vector.push_back( | 402 alternative_service_info_vector.push_back( |
| 405 AlternativeServiceInfo(alternative_service1, expiration)); | 403 AlternativeServiceInfo(alternative_service1, expiration)); |
| 406 // Different hostname: GetAlternativeServices should return this one. | 404 // Different hostname: GetAlternativeServices should return this one. |
| 407 AlternativeService alternative_service2(NPN_HTTP_2, "bar", 443); | 405 AlternativeService alternative_service2(NPN_HTTP_2, "bar", 443); |
| 408 alternative_service_info_vector.push_back( | 406 alternative_service_info_vector.push_back( |
| 409 AlternativeServiceInfo(alternative_service2, expiration)); | 407 AlternativeServiceInfo(alternative_service2, expiration)); |
| 410 // Different port: GetAlternativeServices should return this one too. | 408 // Different port: GetAlternativeServices should return this one too. |
| 411 AlternativeService alternative_service3(NPN_HTTP_2, "foo", 80); | 409 AlternativeService alternative_service3(NPN_HTTP_2, "foo", 80); |
| 412 alternative_service_info_vector.push_back( | 410 alternative_service_info_vector.push_back( |
| 413 AlternativeServiceInfo(alternative_service3, expiration)); | 411 AlternativeServiceInfo(alternative_service3, expiration)); |
| 414 // QUIC: GetAlternativeServices should return this one too. | 412 // QUIC: GetAlternativeServices should return this one too. |
| 415 AlternativeService alternative_service4(QUIC, "foo", 443); | 413 AlternativeService alternative_service4(QUIC, "foo", 443); |
| 416 alternative_service_info_vector.push_back( | 414 alternative_service_info_vector.push_back( |
| 417 AlternativeServiceInfo(alternative_service4, expiration)); | 415 AlternativeServiceInfo(alternative_service4, expiration)); |
| 418 | 416 |
| 419 HostPortPair test_host_port_pair("foo", 443); | 417 url::SchemeHostPort test_server("https", "foo", 443); |
| 420 impl_.SetAlternativeServices(test_host_port_pair, | 418 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 421 alternative_service_info_vector); | |
| 422 | 419 |
| 423 const AlternativeServiceVector alternative_service_vector = | 420 const AlternativeServiceVector alternative_service_vector = |
| 424 impl_.GetAlternativeServices(test_host_port_pair); | 421 impl_.GetAlternativeServices(test_server); |
| 425 ASSERT_EQ(3u, alternative_service_vector.size()); | 422 ASSERT_EQ(3u, alternative_service_vector.size()); |
| 426 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); | 423 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
| 427 EXPECT_EQ(alternative_service3, alternative_service_vector[1]); | 424 EXPECT_EQ(alternative_service3, alternative_service_vector[1]); |
| 428 EXPECT_EQ(alternative_service4, alternative_service_vector[2]); | 425 EXPECT_EQ(alternative_service4, alternative_service_vector[2]); |
| 429 } | 426 } |
| 430 | 427 |
| 431 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { | 428 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { |
| 432 // |test_host_port_pair1| has an alternative service, which will not be | 429 // |test_server1| has an alternative service, which will not be |
| 433 // affected by InitializeAlternativeServiceServers(), because | 430 // affected by InitializeAlternativeServiceServers(), because |
| 434 // |alternative_service_map| does not have an entry for | 431 // |alternative_service_map| does not have an entry for |
| 435 // |test_host_port_pair1|. | 432 // |test_server1|. |
| 436 HostPortPair test_host_port_pair1("foo1", 80); | 433 url::SchemeHostPort test_server1("http", "foo1", 80); |
| 437 const AlternativeService alternative_service1(NPN_HTTP_2, "bar1", 443); | 434 const AlternativeService alternative_service1(NPN_HTTP_2, "bar1", 443); |
| 438 const base::Time now = base::Time::Now(); | 435 const base::Time now = base::Time::Now(); |
| 439 base::Time expiration1 = now + base::TimeDelta::FromDays(1); | 436 base::Time expiration1 = now + base::TimeDelta::FromDays(1); |
| 440 // 1st entry in the memory. | 437 // 1st entry in the memory. |
| 441 impl_.SetAlternativeService(test_host_port_pair1, alternative_service1, | 438 impl_.SetAlternativeService(test_server1, alternative_service1, expiration1); |
| 442 expiration1); | |
| 443 | 439 |
| 444 // |test_host_port_pair2| has an alternative service, which will be | 440 // |test_server2| has an alternative service, which will be |
| 445 // overwritten by InitializeAlternativeServiceServers(), because | 441 // overwritten by InitializeAlternativeServiceServers(), because |
| 446 // |alternative_service_map| has an entry for | 442 // |alternative_service_map| has an entry for |
| 447 // |test_host_port_pair2|. | 443 // |test_server2|. |
| 448 AlternativeServiceInfoVector alternative_service_info_vector; | 444 AlternativeServiceInfoVector alternative_service_info_vector; |
| 449 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443); | 445 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443); |
| 450 base::Time expiration2 = now + base::TimeDelta::FromDays(2); | 446 base::Time expiration2 = now + base::TimeDelta::FromDays(2); |
| 451 alternative_service_info_vector.push_back( | 447 alternative_service_info_vector.push_back( |
| 452 AlternativeServiceInfo(alternative_service2, expiration2)); | 448 AlternativeServiceInfo(alternative_service2, expiration2)); |
| 453 HostPortPair test_host_port_pair2("foo2", 80); | 449 url::SchemeHostPort test_server2("http", "foo2", 80); |
| 454 // 0th entry in the memory. | 450 // 0th entry in the memory. |
| 455 impl_.SetAlternativeServices(test_host_port_pair2, | 451 impl_.SetAlternativeServices(test_server2, alternative_service_info_vector); |
| 456 alternative_service_info_vector); | |
| 457 | 452 |
| 458 // Prepare |alternative_service_map| to be loaded by | 453 // Prepare |alternative_service_map| to be loaded by |
| 459 // InitializeAlternativeServiceServers(). | 454 // InitializeAlternativeServiceServers(). |
| 460 AlternativeServiceMap alternative_service_map( | 455 AlternativeServiceMap alternative_service_map( |
| 461 AlternativeServiceMap::NO_AUTO_EVICT); | 456 AlternativeServiceMap::NO_AUTO_EVICT); |
| 462 const AlternativeService alternative_service3(NPN_HTTP_2, "bar3", 123); | 457 const AlternativeService alternative_service3(NPN_HTTP_2, "bar3", 123); |
| 463 base::Time expiration3 = now + base::TimeDelta::FromDays(3); | 458 base::Time expiration3 = now + base::TimeDelta::FromDays(3); |
| 464 const AlternativeServiceInfo alternative_service_info1(alternative_service3, | 459 const AlternativeServiceInfo alternative_service_info1(alternative_service3, |
| 465 expiration3); | 460 expiration3); |
| 466 // Simulate updating data for 0th entry with data from Preferences. | 461 // Simulate updating data for 0th entry with data from Preferences. |
| 467 alternative_service_map.Put( | 462 alternative_service_map.Put( |
| 468 test_host_port_pair2, | 463 test_server2, |
| 469 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); | 464 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); |
| 470 | 465 |
| 471 HostPortPair test_host_port_pair3("foo3", 80); | 466 url::SchemeHostPort test_server3("http", "foo3", 80); |
| 472 const AlternativeService alternative_service4(NPN_HTTP_2, "bar4", 1234); | 467 const AlternativeService alternative_service4(NPN_HTTP_2, "bar4", 1234); |
| 473 base::Time expiration4 = now + base::TimeDelta::FromDays(4); | 468 base::Time expiration4 = now + base::TimeDelta::FromDays(4); |
| 474 const AlternativeServiceInfo alternative_service_info2(alternative_service4, | 469 const AlternativeServiceInfo alternative_service_info2(alternative_service4, |
| 475 expiration4); | 470 expiration4); |
| 476 // Add an old entry from Preferences, this will be added to end of recency | 471 // Add an old entry from Preferences, this will be added to end of recency |
| 477 // list. | 472 // list. |
| 478 alternative_service_map.Put( | 473 alternative_service_map.Put( |
| 479 test_host_port_pair3, | 474 test_server3, |
| 480 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); | 475 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); |
| 481 | 476 |
| 482 // MRU list will be test_host_port_pair2, test_host_port_pair1, | 477 // MRU list will be test_server2, test_server1, test_server3. |
| 483 // test_host_port_pair3. | |
| 484 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 478 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
| 485 | 479 |
| 486 // Verify alternative_service_map. | 480 // Verify alternative_service_map. |
| 487 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 481 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 488 ASSERT_EQ(3u, map.size()); | 482 ASSERT_EQ(3u, map.size()); |
| 489 AlternativeServiceMap::const_iterator map_it = map.begin(); | 483 AlternativeServiceMap::const_iterator map_it = map.begin(); |
| 490 | 484 |
| 491 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair2)); | 485 EXPECT_TRUE(map_it->first.Equals(test_server2)); |
| 492 ASSERT_EQ(1u, map_it->second.size()); | 486 ASSERT_EQ(1u, map_it->second.size()); |
| 493 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service); | 487 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service); |
| 494 EXPECT_EQ(expiration3, map_it->second[0].expiration); | 488 EXPECT_EQ(expiration3, map_it->second[0].expiration); |
| 495 ++map_it; | 489 ++map_it; |
| 496 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair1)); | 490 EXPECT_TRUE(map_it->first.Equals(test_server1)); |
| 497 ASSERT_EQ(1u, map_it->second.size()); | 491 ASSERT_EQ(1u, map_it->second.size()); |
| 498 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); | 492 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); |
| 499 EXPECT_EQ(expiration1, map_it->second[0].expiration); | 493 EXPECT_EQ(expiration1, map_it->second[0].expiration); |
| 500 ++map_it; | 494 ++map_it; |
| 501 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair3)); | 495 EXPECT_TRUE(map_it->first.Equals(test_server3)); |
| 502 ASSERT_EQ(1u, map_it->second.size()); | 496 ASSERT_EQ(1u, map_it->second.size()); |
| 503 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service); | 497 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service); |
| 504 EXPECT_EQ(expiration4, map_it->second[0].expiration); | 498 EXPECT_EQ(expiration4, map_it->second[0].expiration); |
| 505 } | 499 } |
| 506 | 500 |
| 507 // Regression test for https://crbug.com/504032: | 501 // Regression test for https://crbug.com/504032: |
| 508 // InitializeAlternativeServiceServers() should not crash if there is an empty | 502 // InitializeAlternativeServiceServers() should not crash if there is an empty |
| 509 // hostname is the mapping. | 503 // hostname is the mapping. |
| 510 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) { | 504 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) { |
| 511 const HostPortPair host_port_pair("foo", 443); | 505 url::SchemeHostPort server("https", "foo", 443); |
| 512 const AlternativeService alternative_service_with_empty_hostname(NPN_HTTP_2, | 506 const AlternativeService alternative_service_with_empty_hostname(NPN_HTTP_2, |
| 513 "", 1234); | 507 "", 1234); |
| 514 const AlternativeService alternative_service_with_foo_hostname(NPN_HTTP_2, | 508 const AlternativeService alternative_service_with_foo_hostname(NPN_HTTP_2, |
| 515 "foo", 1234); | 509 "foo", 1234); |
| 516 SetAlternativeService(host_port_pair, | 510 SetAlternativeService(server, alternative_service_with_empty_hostname); |
| 517 alternative_service_with_empty_hostname); | |
| 518 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); | 511 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); |
| 519 | 512 |
| 520 AlternativeServiceMap alternative_service_map( | 513 AlternativeServiceMap alternative_service_map( |
| 521 AlternativeServiceMap::NO_AUTO_EVICT); | 514 AlternativeServiceMap::NO_AUTO_EVICT); |
| 522 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 515 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
| 523 | 516 |
| 524 EXPECT_TRUE( | 517 EXPECT_TRUE( |
| 525 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); | 518 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); |
| 526 const AlternativeServiceVector alternative_service_vector = | 519 const AlternativeServiceVector alternative_service_vector = |
| 527 impl_.GetAlternativeServices(host_port_pair); | 520 impl_.GetAlternativeServices(server); |
| 528 ASSERT_EQ(1u, alternative_service_vector.size()); | 521 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 529 EXPECT_EQ(alternative_service_with_foo_hostname, | 522 EXPECT_EQ(alternative_service_with_foo_hostname, |
| 530 alternative_service_vector[0]); | 523 alternative_service_vector[0]); |
| 531 } | 524 } |
| 532 | 525 |
| 533 // Regression test for https://crbug.com/516486: | 526 // Regression test for https://crbug.com/516486: |
| 534 // GetAlternativeServices() should remove |alternative_service_map_| elements | 527 // GetAlternativeServices() should remove |alternative_service_map_| elements |
| 535 // with empty value. | 528 // with empty value. |
| 536 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { | 529 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { |
| 537 HostPortPair host_port_pair("foo", 443); | 530 url::SchemeHostPort server("https", "foo", 443); |
| 538 const AlternativeService alternative_service(NPN_HTTP_2, "bar", 443); | 531 const AlternativeService alternative_service(NPN_HTTP_2, "bar", 443); |
| 539 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); | 532 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); |
| 540 const AlternativeServiceInfo alternative_service_info(alternative_service, | 533 const AlternativeServiceInfo alternative_service_info(alternative_service, |
| 541 expiration); | 534 expiration); |
| 542 AlternativeServiceMap alternative_service_map( | 535 AlternativeServiceMap alternative_service_map( |
| 543 AlternativeServiceMap::NO_AUTO_EVICT); | 536 AlternativeServiceMap::NO_AUTO_EVICT); |
| 544 alternative_service_map.Put( | 537 alternative_service_map.Put( |
| 545 host_port_pair, | 538 server, |
| 546 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 539 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
| 547 | 540 |
| 548 // Prepare |alternative_service_map_| with a single key that has a single | 541 // Prepare |alternative_service_map_| with a single key that has a single |
| 549 // AlternativeServiceInfo with identical hostname and port. | 542 // AlternativeServiceInfo with identical hostname and port. |
| 550 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 543 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
| 551 | 544 |
| 552 // GetAlternativeServices() should remove such AlternativeServiceInfo from | 545 // GetAlternativeServices() should remove such AlternativeServiceInfo from |
| 553 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector | 546 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector |
| 554 // corresponding to |host_port_pair|. | 547 // corresponding to |server|. |
| 555 AlternativeServiceVector alternative_service_vector = | 548 AlternativeServiceVector alternative_service_vector = |
| 556 impl_.GetAlternativeServices(host_port_pair); | 549 impl_.GetAlternativeServices(server); |
| 557 ASSERT_TRUE(alternative_service_vector.empty()); | 550 ASSERT_TRUE(alternative_service_vector.empty()); |
| 558 | 551 |
| 559 // GetAlternativeServices() should remove this key from | 552 // GetAlternativeServices() should remove this key from |
| 560 // |alternative_service_map_|, and SetAlternativeServices() should not crash. | 553 // |alternative_service_map_|, and SetAlternativeServices() should not crash. |
| 561 impl_.SetAlternativeServices( | 554 impl_.SetAlternativeServices( |
| 562 host_port_pair, | 555 server, |
| 563 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 556 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
| 564 | 557 |
| 565 // There should still be no alternative service assigned to |host_port_pair|. | 558 // There should still be no alternative service assigned to |server|. |
| 566 alternative_service_vector = impl_.GetAlternativeServices(host_port_pair); | 559 alternative_service_vector = impl_.GetAlternativeServices(server); |
| 567 ASSERT_TRUE(alternative_service_vector.empty()); | 560 ASSERT_TRUE(alternative_service_vector.empty()); |
| 568 } | 561 } |
| 569 | 562 |
| 570 // Regression test for https://crbug.com/516486 for the canonical host case. | 563 // Regression test for https://crbug.com/516486 for the canonical host case. |
| 571 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) { | 564 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) { |
| 572 HostPortPair host_port_pair("foo.c.youtube.com", 443); | 565 url::SchemeHostPort server("https", "foo.c.youtube.com", 443); |
| 573 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 443); | 566 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 574 const AlternativeService alternative_service(NPN_HTTP_2, "", 443); | 567 const AlternativeService alternative_service(NPN_HTTP_2, "", 443); |
| 575 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); | 568 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); |
| 576 const AlternativeServiceInfo alternative_service_info(alternative_service, | 569 const AlternativeServiceInfo alternative_service_info(alternative_service, |
| 577 expiration); | 570 expiration); |
| 578 AlternativeServiceMap alternative_service_map( | 571 AlternativeServiceMap alternative_service_map( |
| 579 AlternativeServiceMap::NO_AUTO_EVICT); | 572 AlternativeServiceMap::NO_AUTO_EVICT); |
| 580 alternative_service_map.Put( | 573 alternative_service_map.Put( |
| 581 canonical_host_port_pair, | 574 canonical_server, |
| 582 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 575 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
| 583 | 576 |
| 584 // Prepare |alternative_service_map_| with a single key that has a single | 577 // Prepare |alternative_service_map_| with a single key that has a single |
| 585 // AlternativeServiceInfo with identical hostname and port. | 578 // AlternativeServiceInfo with identical hostname and port. |
| 586 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 579 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
| 587 | 580 |
| 588 // GetAlternativeServices() should remove such AlternativeServiceInfo from | 581 // GetAlternativeServices() should remove such AlternativeServiceInfo from |
| 589 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector | 582 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector |
| 590 // corresponding to |canonical_host_port_pair|, even when looking up | 583 // corresponding to |canonical_server|, even when looking up |
| 591 // alternative services for |host_port_pair|. | 584 // alternative services for |server|. |
| 592 AlternativeServiceVector alternative_service_vector = | 585 AlternativeServiceVector alternative_service_vector = |
| 593 impl_.GetAlternativeServices(host_port_pair); | 586 impl_.GetAlternativeServices(server); |
| 594 ASSERT_TRUE(alternative_service_vector.empty()); | 587 ASSERT_TRUE(alternative_service_vector.empty()); |
| 595 | 588 |
| 596 // GetAlternativeServices() should remove this key from | 589 // GetAlternativeServices() should remove this key from |
| 597 // |alternative_service_map_|, and SetAlternativeServices() should not crash. | 590 // |alternative_service_map_|, and SetAlternativeServices() should not crash. |
| 598 impl_.SetAlternativeServices( | 591 impl_.SetAlternativeServices( |
| 599 canonical_host_port_pair, | 592 canonical_server, |
| 600 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 593 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
| 601 | 594 |
| 602 // There should still be no alternative service assigned to | 595 // There should still be no alternative service assigned to |
| 603 // |canonical_host_port_pair|. | 596 // |canonical_server|. |
| 604 alternative_service_vector = | 597 alternative_service_vector = impl_.GetAlternativeServices(canonical_server); |
| 605 impl_.GetAlternativeServices(canonical_host_port_pair); | |
| 606 ASSERT_TRUE(alternative_service_vector.empty()); | 598 ASSERT_TRUE(alternative_service_vector.empty()); |
| 607 } | 599 } |
| 608 | 600 |
| 609 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) { | 601 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) { |
| 610 HostPortPair test_host_port_pair1("foo1", 80); | 602 url::SchemeHostPort test_server1("http", "foo1", 80); |
| 611 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo1", 443); | 603 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo1", 443); |
| 612 SetAlternativeService(test_host_port_pair1, alternative_service1); | 604 SetAlternativeService(test_server1, alternative_service1); |
| 613 HostPortPair test_host_port_pair2("foo2", 80); | 605 url::SchemeHostPort test_server2("http", "foo2", 80); |
| 614 const AlternativeService alternative_service2(NPN_HTTP_2, "foo2", 1234); | 606 const AlternativeService alternative_service2(NPN_HTTP_2, "foo2", 1234); |
| 615 SetAlternativeService(test_host_port_pair2, alternative_service2); | 607 SetAlternativeService(test_server2, alternative_service2); |
| 616 | 608 |
| 617 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 609 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 618 AlternativeServiceMap::const_iterator it = map.begin(); | 610 AlternativeServiceMap::const_iterator it = map.begin(); |
| 619 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); | 611 EXPECT_TRUE(it->first.Equals(test_server2)); |
| 620 ASSERT_EQ(1u, it->second.size()); | 612 ASSERT_EQ(1u, it->second.size()); |
| 621 EXPECT_EQ(alternative_service2, it->second[0].alternative_service); | 613 EXPECT_EQ(alternative_service2, it->second[0].alternative_service); |
| 622 | 614 |
| 623 const AlternativeServiceVector alternative_service_vector = | 615 const AlternativeServiceVector alternative_service_vector = |
| 624 impl_.GetAlternativeServices(test_host_port_pair1); | 616 impl_.GetAlternativeServices(test_server1); |
| 625 ASSERT_EQ(1u, alternative_service_vector.size()); | 617 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 626 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 618 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 627 | 619 |
| 628 // GetAlternativeServices should reorder the AlternateProtocol map. | 620 // GetAlternativeServices should reorder the AlternateProtocol map. |
| 629 it = map.begin(); | 621 it = map.begin(); |
| 630 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); | 622 EXPECT_TRUE(it->first.Equals(test_server1)); |
| 631 ASSERT_EQ(1u, it->second.size()); | 623 ASSERT_EQ(1u, it->second.size()); |
| 632 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); | 624 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); |
| 633 } | 625 } |
| 634 | 626 |
| 635 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { | 627 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { |
| 636 HostPortPair test_host_port_pair("foo", 80); | 628 url::SchemeHostPort test_server("http", "foo", 80); |
| 637 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); | 629 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); |
| 638 SetAlternativeService(test_host_port_pair, alternative_service1); | 630 SetAlternativeService(test_server, alternative_service1); |
| 639 AlternativeServiceVector alternative_service_vector = | 631 AlternativeServiceVector alternative_service_vector = |
| 640 impl_.GetAlternativeServices(test_host_port_pair); | 632 impl_.GetAlternativeServices(test_server); |
| 641 ASSERT_EQ(1u, alternative_service_vector.size()); | 633 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 642 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 634 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 643 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 635 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
| 644 | 636 |
| 645 // GetAlternativeServices should return the broken alternative service. | 637 // GetAlternativeServices should return the broken alternative service. |
| 646 impl_.MarkAlternativeServiceBroken(alternative_service1); | 638 impl_.MarkAlternativeServiceBroken(alternative_service1); |
| 647 alternative_service_vector = | 639 alternative_service_vector = impl_.GetAlternativeServices(test_server); |
| 648 impl_.GetAlternativeServices(test_host_port_pair); | |
| 649 ASSERT_EQ(1u, alternative_service_vector.size()); | 640 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 650 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 641 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 651 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 642 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
| 652 | 643 |
| 653 // SetAlternativeServices should add a broken alternative service to the map. | 644 // SetAlternativeServices should add a broken alternative service to the map. |
| 654 AlternativeServiceInfoVector alternative_service_info_vector; | 645 AlternativeServiceInfoVector alternative_service_info_vector; |
| 655 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 646 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 656 alternative_service_info_vector.push_back( | 647 alternative_service_info_vector.push_back( |
| 657 AlternativeServiceInfo(alternative_service1, expiration)); | 648 AlternativeServiceInfo(alternative_service1, expiration)); |
| 658 const AlternativeService alternative_service2(NPN_HTTP_2, "foo", 1234); | 649 const AlternativeService alternative_service2(NPN_HTTP_2, "foo", 1234); |
| 659 alternative_service_info_vector.push_back( | 650 alternative_service_info_vector.push_back( |
| 660 AlternativeServiceInfo(alternative_service2, expiration)); | 651 AlternativeServiceInfo(alternative_service2, expiration)); |
| 661 impl_.SetAlternativeServices(test_host_port_pair, | 652 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 662 alternative_service_info_vector); | 653 alternative_service_vector = impl_.GetAlternativeServices(test_server); |
| 663 alternative_service_vector = | |
| 664 impl_.GetAlternativeServices(test_host_port_pair); | |
| 665 ASSERT_EQ(2u, alternative_service_vector.size()); | 654 ASSERT_EQ(2u, alternative_service_vector.size()); |
| 666 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 655 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 667 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); | 656 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); |
| 668 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); | 657 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); |
| 669 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service_vector[1])); | 658 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service_vector[1])); |
| 670 | 659 |
| 671 // SetAlternativeService should add a broken alternative service to the map. | 660 // SetAlternativeService should add a broken alternative service to the map. |
| 672 SetAlternativeService(test_host_port_pair, alternative_service1); | 661 SetAlternativeService(test_server, alternative_service1); |
| 673 alternative_service_vector = | 662 alternative_service_vector = impl_.GetAlternativeServices(test_server); |
| 674 impl_.GetAlternativeServices(test_host_port_pair); | |
| 675 ASSERT_EQ(1u, alternative_service_vector.size()); | 663 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 676 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 664 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 677 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); | 665 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); |
| 678 } | 666 } |
| 679 | 667 |
| 680 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { | 668 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { |
| 681 AlternativeServiceInfoVector alternative_service_info_vector; | 669 AlternativeServiceInfoVector alternative_service_info_vector; |
| 682 base::Time now = base::Time::Now(); | 670 base::Time now = base::Time::Now(); |
| 683 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 671 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
| 684 | 672 |
| 685 // First alternative service expired one day ago, should not be returned by | 673 // First alternative service expired one day ago, should not be returned by |
| 686 // GetAlternativeServices(). | 674 // GetAlternativeServices(). |
| 687 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 675 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
| 688 alternative_service_info_vector.push_back( | 676 alternative_service_info_vector.push_back( |
| 689 AlternativeServiceInfo(alternative_service1, now - one_day)); | 677 AlternativeServiceInfo(alternative_service1, now - one_day)); |
| 690 | 678 |
| 691 // Second alterrnative service will expire one day from now, should be | 679 // Second alterrnative service will expire one day from now, should be |
| 692 // returned by GetAlternativeSerices(). | 680 // returned by GetAlternativeSerices(). |
| 693 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 681 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 694 alternative_service_info_vector.push_back( | 682 alternative_service_info_vector.push_back( |
| 695 AlternativeServiceInfo(alternative_service2, now + one_day)); | 683 AlternativeServiceInfo(alternative_service2, now + one_day)); |
| 696 | 684 |
| 697 HostPortPair test_host_port_pair("foo", 80); | 685 url::SchemeHostPort test_server("http", "foo", 80); |
| 698 impl_.SetAlternativeServices(test_host_port_pair, | 686 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 699 alternative_service_info_vector); | |
| 700 | 687 |
| 701 AlternativeServiceVector alternative_service_vector = | 688 AlternativeServiceVector alternative_service_vector = |
| 702 impl_.GetAlternativeServices(test_host_port_pair); | 689 impl_.GetAlternativeServices(test_server); |
| 703 ASSERT_EQ(1u, alternative_service_vector.size()); | 690 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 704 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); | 691 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
| 705 } | 692 } |
| 706 | 693 |
| 707 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { | 694 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { |
| 708 AlternativeServiceInfoVector alternative_service_info_vector; | 695 AlternativeServiceInfoVector alternative_service_info_vector; |
| 709 base::Time now = base::Time::Now(); | 696 base::Time now = base::Time::Now(); |
| 710 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 697 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
| 711 | 698 |
| 712 // First alternative service expired one day ago, should not be returned by | 699 // First alternative service expired one day ago, should not be returned by |
| 713 // GetAlternativeServices(). | 700 // GetAlternativeServices(). |
| 714 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 701 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
| 715 alternative_service_info_vector.push_back( | 702 alternative_service_info_vector.push_back( |
| 716 AlternativeServiceInfo(alternative_service1, now - one_day)); | 703 AlternativeServiceInfo(alternative_service1, now - one_day)); |
| 717 | 704 |
| 718 // Second alterrnative service will expire one day from now, should be | 705 // Second alterrnative service will expire one day from now, should be |
| 719 // returned by GetAlternativeSerices(). | 706 // returned by GetAlternativeSerices(). |
| 720 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 707 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 721 alternative_service_info_vector.push_back( | 708 alternative_service_info_vector.push_back( |
| 722 AlternativeServiceInfo(alternative_service2, now + one_day)); | 709 AlternativeServiceInfo(alternative_service2, now + one_day)); |
| 723 | 710 |
| 724 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 711 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 725 impl_.SetAlternativeServices(canonical_host_port_pair, | 712 impl_.SetAlternativeServices(canonical_server, |
| 726 alternative_service_info_vector); | 713 alternative_service_info_vector); |
| 727 | 714 |
| 728 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 715 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 729 AlternativeServiceVector alternative_service_vector = | 716 AlternativeServiceVector alternative_service_vector = |
| 730 impl_.GetAlternativeServices(test_host_port_pair); | 717 impl_.GetAlternativeServices(test_server); |
| 731 ASSERT_EQ(1u, alternative_service_vector.size()); | 718 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 732 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); | 719 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
| 733 } | 720 } |
| 734 | 721 |
| 722 TEST_F(AlternateProtocolServerPropertiesTest, AlternativeServiceWithScheme) { |
| 723 AlternativeServiceInfoVector alternative_service_info_vector; |
| 724 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
| 725 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 726 alternative_service_info_vector.push_back( |
| 727 AlternativeServiceInfo(alternative_service1, expiration)); |
| 728 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 729 alternative_service_info_vector.push_back( |
| 730 AlternativeServiceInfo(alternative_service2, expiration)); |
| 731 // Set Alt-Svc list for |http_server|. |
| 732 url::SchemeHostPort http_server("http", "foo", 80); |
| 733 impl_.SetAlternativeServices(http_server, alternative_service_info_vector); |
| 734 |
| 735 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 736 net::AlternativeServiceMap::const_iterator it = map.begin(); |
| 737 EXPECT_TRUE(it->first.Equals(http_server)); |
| 738 ASSERT_EQ(2u, it->second.size()); |
| 739 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); |
| 740 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); |
| 741 |
| 742 // Check Alt-Svc list should not be set for |https_server|. |
| 743 url::SchemeHostPort https_server("https", "foo", 80); |
| 744 EXPECT_EQ(0u, impl_.GetAlternativeServices(https_server).size()); |
| 745 |
| 746 // Set Alt-Svc list for |https_server|. |
| 747 impl_.SetAlternativeServices(https_server, alternative_service_info_vector); |
| 748 EXPECT_EQ(2u, impl_.GetAlternativeServices(https_server).size()); |
| 749 EXPECT_EQ(2u, impl_.GetAlternativeServices(http_server).size()); |
| 750 |
| 751 // Clear Alt-Svc list for |http_server|. |
| 752 impl_.ClearAlternativeServices(http_server); |
| 753 EXPECT_EQ(0u, impl_.GetAlternativeServices(http_server).size()); |
| 754 EXPECT_EQ(2u, impl_.GetAlternativeServices(https_server).size()); |
| 755 } |
| 756 |
| 735 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) { | 757 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) { |
| 736 AlternativeServiceInfoVector alternative_service_info_vector; | 758 AlternativeServiceInfoVector alternative_service_info_vector; |
| 737 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 759 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
| 738 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 760 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 739 alternative_service_info_vector.push_back( | 761 alternative_service_info_vector.push_back( |
| 740 AlternativeServiceInfo(alternative_service1, expiration)); | 762 AlternativeServiceInfo(alternative_service1, expiration)); |
| 741 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 763 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 742 alternative_service_info_vector.push_back( | 764 alternative_service_info_vector.push_back( |
| 743 AlternativeServiceInfo(alternative_service2, expiration)); | 765 AlternativeServiceInfo(alternative_service2, expiration)); |
| 744 HostPortPair test_host_port_pair("foo", 80); | 766 url::SchemeHostPort test_server("http", "foo", 80); |
| 745 impl_.SetAlternativeServices(test_host_port_pair, | 767 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 746 alternative_service_info_vector); | |
| 747 | 768 |
| 748 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); | 769 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 749 net::AlternativeServiceMap::const_iterator it = map.begin(); | 770 net::AlternativeServiceMap::const_iterator it = map.begin(); |
| 750 EXPECT_TRUE(it->first.Equals(test_host_port_pair)); | 771 EXPECT_TRUE(it->first.Equals(test_server)); |
| 751 ASSERT_EQ(2u, it->second.size()); | 772 ASSERT_EQ(2u, it->second.size()); |
| 752 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); | 773 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); |
| 753 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); | 774 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); |
| 754 | 775 |
| 755 impl_.ClearAlternativeServices(test_host_port_pair); | 776 impl_.ClearAlternativeServices(test_server); |
| 756 EXPECT_TRUE(map.empty()); | 777 EXPECT_TRUE(map.empty()); |
| 757 } | 778 } |
| 758 | 779 |
| 759 // A broken alternative service in the mapping carries meaningful information, | 780 // A broken alternative service in the mapping carries meaningful information, |
| 760 // therefore it should not be ignored by SetAlternativeService(). In | 781 // therefore it should not be ignored by SetAlternativeService(). In |
| 761 // particular, an alternative service mapped to an origin shadows alternative | 782 // particular, an alternative service mapped to an origin shadows alternative |
| 762 // services of canonical hosts. | 783 // services of canonical hosts. |
| 763 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) { | 784 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) { |
| 764 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 785 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 765 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 786 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 766 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 787 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 767 1234); | 788 1234); |
| 768 SetAlternativeService(canonical_host_port_pair, | 789 SetAlternativeService(canonical_server, canonical_alternative_service); |
| 769 canonical_alternative_service); | |
| 770 AlternativeServiceVector alternative_service_vector = | 790 AlternativeServiceVector alternative_service_vector = |
| 771 impl_.GetAlternativeServices(test_host_port_pair); | 791 impl_.GetAlternativeServices(test_server); |
| 772 ASSERT_EQ(1u, alternative_service_vector.size()); | 792 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 773 EXPECT_EQ(canonical_alternative_service, alternative_service_vector[0]); | 793 EXPECT_EQ(canonical_alternative_service, alternative_service_vector[0]); |
| 774 | 794 |
| 775 const AlternativeService broken_alternative_service(NPN_HTTP_2, "foo", 443); | 795 const AlternativeService broken_alternative_service(NPN_HTTP_2, "foo", 443); |
| 776 impl_.MarkAlternativeServiceBroken(broken_alternative_service); | 796 impl_.MarkAlternativeServiceBroken(broken_alternative_service); |
| 777 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); | 797 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); |
| 778 | 798 |
| 779 SetAlternativeService(test_host_port_pair, broken_alternative_service); | 799 SetAlternativeService(test_server, broken_alternative_service); |
| 780 alternative_service_vector = | 800 alternative_service_vector = impl_.GetAlternativeServices(test_server); |
| 781 impl_.GetAlternativeServices(test_host_port_pair); | |
| 782 ASSERT_EQ(1u, alternative_service_vector.size()); | 801 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 783 EXPECT_EQ(broken_alternative_service, alternative_service_vector[0]); | 802 EXPECT_EQ(broken_alternative_service, alternative_service_vector[0]); |
| 784 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); | 803 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); |
| 785 } | 804 } |
| 786 | 805 |
| 787 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { | 806 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { |
| 788 HostPortPair test_host_port_pair("foo", 80); | 807 url::SchemeHostPort test_server("http", "foo", 80); |
| 789 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); | 808 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
| 790 SetAlternativeService(test_host_port_pair, alternative_service); | 809 SetAlternativeService(test_server, alternative_service); |
| 791 impl_.MarkAlternativeServiceBroken(alternative_service); | 810 impl_.MarkAlternativeServiceBroken(alternative_service); |
| 792 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); | 811 ASSERT_TRUE(HasAlternativeService(test_server)); |
| 793 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 812 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 794 // ClearAlternativeServices should leave a broken alternative service marked | 813 // ClearAlternativeServices should leave a broken alternative service marked |
| 795 // as such. | 814 // as such. |
| 796 impl_.ClearAlternativeServices(test_host_port_pair); | 815 impl_.ClearAlternativeServices(test_server); |
| 797 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 816 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 798 } | 817 } |
| 799 | 818 |
| 800 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) { | 819 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) { |
| 801 HostPortPair host_port_pair("foo", 80); | 820 url::SchemeHostPort server("http", "foo", 80); |
| 802 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); | 821 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
| 803 SetAlternativeService(host_port_pair, alternative_service); | 822 SetAlternativeService(server, alternative_service); |
| 804 | 823 |
| 805 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 824 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 806 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 825 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 807 | 826 |
| 808 impl_.MarkAlternativeServiceRecentlyBroken(alternative_service); | 827 impl_.MarkAlternativeServiceRecentlyBroken(alternative_service); |
| 809 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 828 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 810 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 829 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 811 | 830 |
| 812 impl_.ConfirmAlternativeService(alternative_service); | 831 impl_.ConfirmAlternativeService(alternative_service); |
| 813 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 832 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 814 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 833 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 815 } | 834 } |
| 816 | 835 |
| 817 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { | 836 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { |
| 818 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 837 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 819 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 838 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 820 | 839 |
| 821 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 840 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 822 EXPECT_FALSE(HasAlternativeService(canonical_host_port_pair)); | 841 EXPECT_FALSE(HasAlternativeService(canonical_server)); |
| 823 | 842 |
| 824 AlternativeServiceInfoVector alternative_service_info_vector; | 843 AlternativeServiceInfoVector alternative_service_info_vector; |
| 825 const AlternativeService canonical_alternative_service1( | 844 const AlternativeService canonical_alternative_service1( |
| 826 QUIC, "bar.c.youtube.com", 1234); | 845 QUIC, "bar.c.youtube.com", 1234); |
| 827 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 846 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 828 alternative_service_info_vector.push_back( | 847 alternative_service_info_vector.push_back( |
| 829 AlternativeServiceInfo(canonical_alternative_service1, expiration)); | 848 AlternativeServiceInfo(canonical_alternative_service1, expiration)); |
| 830 const AlternativeService canonical_alternative_service2(NPN_HTTP_2, "", 443); | 849 const AlternativeService canonical_alternative_service2(NPN_HTTP_2, "", 443); |
| 831 alternative_service_info_vector.push_back( | 850 alternative_service_info_vector.push_back( |
| 832 AlternativeServiceInfo(canonical_alternative_service2, expiration)); | 851 AlternativeServiceInfo(canonical_alternative_service2, expiration)); |
| 833 impl_.SetAlternativeServices(canonical_host_port_pair, | 852 impl_.SetAlternativeServices(canonical_server, |
| 834 alternative_service_info_vector); | 853 alternative_service_info_vector); |
| 835 | 854 |
| 836 // Since |test_host_port_pair| does not have an alternative service itself, | 855 // Since |test_server| does not have an alternative service itself, |
| 837 // GetAlternativeServices should return those of |canonical_host_port_pair|. | 856 // GetAlternativeServices should return those of |canonical_server|. |
| 838 AlternativeServiceVector alternative_service_vector = | 857 AlternativeServiceVector alternative_service_vector = |
| 839 impl_.GetAlternativeServices(test_host_port_pair); | 858 impl_.GetAlternativeServices(test_server); |
| 840 ASSERT_EQ(2u, alternative_service_vector.size()); | 859 ASSERT_EQ(2u, alternative_service_vector.size()); |
| 841 EXPECT_EQ(canonical_alternative_service1, alternative_service_vector[0]); | 860 EXPECT_EQ(canonical_alternative_service1, alternative_service_vector[0]); |
| 842 | 861 |
| 843 // Since |canonical_alternative_service2| has an empty host, | 862 // Since |canonical_alternative_service2| has an empty host, |
| 844 // GetAlternativeServices should substitute the hostname of its |origin| | 863 // GetAlternativeServices should substitute the hostname of its |origin| |
| 845 // argument. | 864 // argument. |
| 846 EXPECT_EQ(test_host_port_pair.host(), alternative_service_vector[1].host); | 865 EXPECT_EQ(test_server.host(), alternative_service_vector[1].host); |
| 847 EXPECT_EQ(canonical_alternative_service2.protocol, | 866 EXPECT_EQ(canonical_alternative_service2.protocol, |
| 848 alternative_service_vector[1].protocol); | 867 alternative_service_vector[1].protocol); |
| 849 EXPECT_EQ(canonical_alternative_service2.port, | 868 EXPECT_EQ(canonical_alternative_service2.port, |
| 850 alternative_service_vector[1].port); | 869 alternative_service_vector[1].port); |
| 851 | 870 |
| 852 // Verify the canonical suffix. | 871 // Verify the canonical suffix. |
| 872 EXPECT_EQ(".c.youtube.com", impl_.GetCanonicalSuffix(test_server.host())); |
| 853 EXPECT_EQ(".c.youtube.com", | 873 EXPECT_EQ(".c.youtube.com", |
| 854 impl_.GetCanonicalSuffix(test_host_port_pair.host())); | 874 impl_.GetCanonicalSuffix(canonical_server.host())); |
| 855 EXPECT_EQ(".c.youtube.com", | |
| 856 impl_.GetCanonicalSuffix(canonical_host_port_pair.host())); | |
| 857 } | 875 } |
| 858 | 876 |
| 859 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { | 877 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { |
| 860 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 878 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 861 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 879 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 862 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 880 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 863 1234); | 881 1234); |
| 864 | 882 |
| 865 SetAlternativeService(canonical_host_port_pair, | 883 SetAlternativeService(canonical_server, canonical_alternative_service); |
| 866 canonical_alternative_service); | 884 impl_.ClearAlternativeServices(canonical_server); |
| 867 impl_.ClearAlternativeServices(canonical_host_port_pair); | 885 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 868 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | |
| 869 } | 886 } |
| 870 | 887 |
| 871 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { | 888 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { |
| 872 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 889 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 873 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 890 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 874 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 891 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 875 1234); | 892 1234); |
| 876 | 893 |
| 877 SetAlternativeService(canonical_host_port_pair, | 894 SetAlternativeService(canonical_server, canonical_alternative_service); |
| 878 canonical_alternative_service); | |
| 879 impl_.MarkAlternativeServiceBroken(canonical_alternative_service); | 895 impl_.MarkAlternativeServiceBroken(canonical_alternative_service); |
| 880 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 896 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 881 } | 897 } |
| 882 | 898 |
| 883 // Adding an alternative service for a new host overrides canonical host. | 899 // Adding an alternative service for a new host overrides canonical host. |
| 884 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) { | 900 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) { |
| 885 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 901 url::SchemeHostPort foo_server("https", "foo.c.youtube.com", 443); |
| 886 HostPortPair bar_host_port_pair("bar.c.youtube.com", 80); | 902 url::SchemeHostPort bar_server("https", "bar.c.youtube.com", 443); |
| 887 AlternativeService bar_alternative_service(QUIC, "bar.c.youtube.com", 1234); | 903 AlternativeService bar_alternative_service(QUIC, "bar.c.youtube.com", 1234); |
| 888 SetAlternativeService(bar_host_port_pair, bar_alternative_service); | 904 SetAlternativeService(bar_server, bar_alternative_service); |
| 889 AlternativeServiceVector alternative_service_vector = | 905 AlternativeServiceVector alternative_service_vector = |
| 890 impl_.GetAlternativeServices(test_host_port_pair); | 906 impl_.GetAlternativeServices(foo_server); |
| 891 ASSERT_EQ(1u, alternative_service_vector.size()); | 907 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 892 EXPECT_EQ(bar_alternative_service, alternative_service_vector[0]); | 908 EXPECT_EQ(bar_alternative_service, alternative_service_vector[0]); |
| 893 | 909 |
| 894 HostPortPair qux_host_port_pair("qux.c.youtube.com", 80); | 910 url::SchemeHostPort qux_server("https", "qux.c.youtube.com", 443); |
| 895 AlternativeService qux_alternative_service(QUIC, "qux.c.youtube.com", 443); | 911 AlternativeService qux_alternative_service(QUIC, "qux.c.youtube.com", 443); |
| 896 SetAlternativeService(qux_host_port_pair, qux_alternative_service); | 912 SetAlternativeService(qux_server, qux_alternative_service); |
| 897 alternative_service_vector = | 913 alternative_service_vector = impl_.GetAlternativeServices(foo_server); |
| 898 impl_.GetAlternativeServices(test_host_port_pair); | |
| 899 ASSERT_EQ(1u, alternative_service_vector.size()); | 914 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 900 EXPECT_EQ(qux_alternative_service, alternative_service_vector[0]); | 915 EXPECT_EQ(qux_alternative_service, alternative_service_vector[0]); |
| 901 } | 916 } |
| 902 | 917 |
| 903 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { | 918 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { |
| 904 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 919 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 905 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 920 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 906 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 921 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 907 1234); | 922 1234); |
| 908 | 923 |
| 909 SetAlternativeService(canonical_host_port_pair, | 924 SetAlternativeService(canonical_server, canonical_alternative_service); |
| 910 canonical_alternative_service); | |
| 911 impl_.Clear(); | 925 impl_.Clear(); |
| 912 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 926 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 913 } | 927 } |
| 914 | 928 |
| 915 TEST_F(AlternateProtocolServerPropertiesTest, | 929 TEST_F(AlternateProtocolServerPropertiesTest, |
| 916 ExpireBrokenAlternateProtocolMappings) { | 930 ExpireBrokenAlternateProtocolMappings) { |
| 917 HostPortPair host_port_pair("foo", 443); | 931 url::SchemeHostPort server("https", "foo", 443); |
| 918 AlternativeService alternative_service(QUIC, "foo", 443); | 932 AlternativeService alternative_service(QUIC, "foo", 443); |
| 919 SetAlternativeService(host_port_pair, alternative_service); | 933 SetAlternativeService(server, alternative_service); |
| 920 EXPECT_TRUE(HasAlternativeService(host_port_pair)); | 934 EXPECT_TRUE(HasAlternativeService(server)); |
| 921 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 935 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 922 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 936 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 923 | 937 |
| 924 base::TimeTicks past = | 938 base::TimeTicks past = |
| 925 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); | 939 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); |
| 926 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( | 940 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( |
| 927 impl_, alternative_service, past); | 941 impl_, alternative_service, past); |
| 928 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 942 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 929 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 943 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 930 | 944 |
| 931 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); | 945 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); |
| 932 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 946 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 933 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 947 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 934 } | 948 } |
| 935 | 949 |
| 936 // Regression test for https://crbug.com/505413. | 950 // Regression test for https://crbug.com/505413. |
| 937 TEST_F(AlternateProtocolServerPropertiesTest, RemoveExpiredBrokenAltSvc) { | 951 TEST_F(AlternateProtocolServerPropertiesTest, RemoveExpiredBrokenAltSvc) { |
| 938 HostPortPair foo_host_port_pair("foo", 443); | 952 url::SchemeHostPort foo_server("https", "foo", 443); |
| 939 AlternativeService bar_alternative_service(QUIC, "bar", 443); | 953 AlternativeService bar_alternative_service(QUIC, "bar", 443); |
| 940 SetAlternativeService(foo_host_port_pair, bar_alternative_service); | 954 SetAlternativeService(foo_server, bar_alternative_service); |
| 941 EXPECT_TRUE(HasAlternativeService(foo_host_port_pair)); | 955 EXPECT_TRUE(HasAlternativeService(foo_server)); |
| 942 | 956 |
| 943 HostPortPair bar_host_port_pair1("bar", 80); | 957 url::SchemeHostPort bar_server1("http", "bar", 80); |
| 944 AlternativeService nohost_alternative_service(QUIC, "", 443); | 958 AlternativeService nohost_alternative_service(QUIC, "", 443); |
| 945 SetAlternativeService(bar_host_port_pair1, nohost_alternative_service); | 959 SetAlternativeService(bar_server1, nohost_alternative_service); |
| 946 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair1)); | 960 EXPECT_TRUE(HasAlternativeService(bar_server1)); |
| 947 | 961 |
| 948 HostPortPair bar_host_port_pair2("bar", 443); | 962 url::SchemeHostPort bar_server2("https", "bar", 443); |
| 949 AlternativeService baz_alternative_service(QUIC, "baz", 1234); | 963 AlternativeService baz_alternative_service(QUIC, "baz", 1234); |
| 950 SetAlternativeService(bar_host_port_pair2, baz_alternative_service); | 964 SetAlternativeService(bar_server2, baz_alternative_service); |
| 951 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair2)); | 965 EXPECT_TRUE(HasAlternativeService(bar_server2)); |
| 952 | 966 |
| 953 // Mark "bar:443" as broken. | 967 // Mark "bar:443" as broken. |
| 954 base::TimeTicks past = | 968 base::TimeTicks past = |
| 955 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); | 969 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); |
| 956 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( | 970 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( |
| 957 impl_, bar_alternative_service, past); | 971 impl_, bar_alternative_service, past); |
| 958 | 972 |
| 959 // Expire brokenness of "bar:443". | 973 // Expire brokenness of "bar:443". |
| 960 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); | 974 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); |
| 961 | 975 |
| 962 // "foo:443" should have no alternative service now. | 976 // "foo:443" should have no alternative service now. |
| 963 EXPECT_FALSE(HasAlternativeService(foo_host_port_pair)); | 977 EXPECT_FALSE(HasAlternativeService(foo_server)); |
| 964 // "bar:80" should have no alternative service now. | 978 // "bar:80" should have no alternative service now. |
| 965 EXPECT_FALSE(HasAlternativeService(bar_host_port_pair1)); | 979 EXPECT_FALSE(HasAlternativeService(bar_server1)); |
| 966 // The alternative service of "bar:443" should be unaffected. | 980 // The alternative service of "bar:443" should be unaffected. |
| 967 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair2)); | 981 EXPECT_TRUE(HasAlternativeService(bar_server2)); |
| 968 | 982 |
| 969 EXPECT_TRUE( | 983 EXPECT_TRUE( |
| 970 impl_.WasAlternativeServiceRecentlyBroken(bar_alternative_service)); | 984 impl_.WasAlternativeServiceRecentlyBroken(bar_alternative_service)); |
| 971 EXPECT_FALSE( | 985 EXPECT_FALSE( |
| 972 impl_.WasAlternativeServiceRecentlyBroken(baz_alternative_service)); | 986 impl_.WasAlternativeServiceRecentlyBroken(baz_alternative_service)); |
| 973 } | 987 } |
| 974 | 988 |
| 975 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; | 989 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; |
| 976 | 990 |
| 977 TEST_F(SpdySettingsServerPropertiesTest, Initialize) { | 991 TEST_F(SpdySettingsServerPropertiesTest, Initialize) { |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); | 1497 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); |
| 1484 | 1498 |
| 1485 impl_.Clear(); | 1499 impl_.Clear(); |
| 1486 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1500 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
| 1487 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); | 1501 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); |
| 1488 } | 1502 } |
| 1489 | 1503 |
| 1490 } // namespace | 1504 } // namespace |
| 1491 | 1505 |
| 1492 } // namespace net | 1506 } // namespace net |
| OLD | NEW |