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