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