| 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 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "net/base/host_port_pair.h" | 13 #include "net/base/host_port_pair.h" |
| 14 #include "net/base/ip_address.h" | 14 #include "net/base/ip_address.h" |
| 15 #include "net/http/http_network_session.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 class ListValue; | 20 class ListValue; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 class HttpServerPropertiesImplPeer { | 25 class HttpServerPropertiesImplPeer { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 53 bool HasAlternativeService(const url::SchemeHostPort& origin) { | 54 bool HasAlternativeService(const url::SchemeHostPort& origin) { |
| 54 const AlternativeServiceInfoVector alternative_service_info_vector = | 55 const AlternativeServiceInfoVector alternative_service_info_vector = |
| 55 impl_.GetAlternativeServiceInfos(origin); | 56 impl_.GetAlternativeServiceInfos(origin); |
| 56 return !alternative_service_info_vector.empty(); | 57 return !alternative_service_info_vector.empty(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 bool SetAlternativeService(const url::SchemeHostPort& origin, | 60 bool SetAlternativeService(const url::SchemeHostPort& origin, |
| 60 const AlternativeService& alternative_service) { | 61 const AlternativeService& alternative_service) { |
| 61 const base::Time expiration = | 62 const base::Time expiration = |
| 62 base::Time::Now() + base::TimeDelta::FromDays(1); | 63 base::Time::Now() + base::TimeDelta::FromDays(1); |
| 63 return impl_.SetAlternativeService(origin, alternative_service, expiration); | 64 return impl_.SetAlternativeService( |
| 65 origin, alternative_service, expiration, |
| 66 HttpNetworkSession::Params().quic_supported_versions); |
| 64 } | 67 } |
| 65 | 68 |
| 66 HttpServerPropertiesImpl impl_; | 69 HttpServerPropertiesImpl impl_; |
| 67 }; | 70 }; |
| 68 | 71 |
| 69 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; | 72 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; |
| 70 | 73 |
| 71 TEST_F(SpdyServerPropertiesTest, SetWithSchemeHostPort) { | 74 TEST_F(SpdyServerPropertiesTest, SetWithSchemeHostPort) { |
| 72 // Check spdy servers are correctly set with SchemeHostPort key. | 75 // Check spdy servers are correctly set with SchemeHostPort key. |
| 73 url::SchemeHostPort https_www_server("https", "www.google.com", 443); | 76 url::SchemeHostPort https_www_server("https", "www.google.com", 443); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 alternative_service_info_vector[0].alternative_service); | 360 alternative_service_info_vector[0].alternative_service); |
| 358 | 361 |
| 359 impl_.Clear(); | 362 impl_.Clear(); |
| 360 EXPECT_FALSE(HasAlternativeService(test_server)); | 363 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 361 } | 364 } |
| 362 | 365 |
| 363 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { | 366 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { |
| 364 AlternativeServiceInfoVector alternative_service_info_vector; | 367 AlternativeServiceInfoVector alternative_service_info_vector; |
| 365 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 368 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 366 // Same hostname, same port, TCP: should be ignored. | 369 // Same hostname, same port, TCP: should be ignored. |
| 367 AlternativeServiceInfo alternative_service_info1(kProtoHTTP2, "foo", 443, | 370 AlternativeServiceInfo alternative_service_info1( |
| 368 expiration); | 371 AlternativeService(kProtoHTTP2, "foo", 443), expiration); |
| 369 alternative_service_info_vector.push_back(alternative_service_info1); | 372 alternative_service_info_vector.push_back(alternative_service_info1); |
| 370 // Different hostname: GetAlternativeServiceInfos should return this one. | 373 // Different hostname: GetAlternativeServiceInfos should return this one. |
| 371 AlternativeServiceInfo alternative_service_info2(kProtoHTTP2, "bar", 443, | 374 AlternativeServiceInfo alternative_service_info2( |
| 372 expiration); | 375 AlternativeService(kProtoHTTP2, "bar", 443), expiration); |
| 373 alternative_service_info_vector.push_back(alternative_service_info2); | 376 alternative_service_info_vector.push_back(alternative_service_info2); |
| 374 // Different port: GetAlternativeServiceInfos should return this one too. | 377 // Different port: GetAlternativeServiceInfos should return this one too. |
| 375 AlternativeServiceInfo alternative_service_info3(kProtoHTTP2, "foo", 80, | 378 AlternativeServiceInfo alternative_service_info3( |
| 376 expiration); | 379 AlternativeService(kProtoHTTP2, "foo", 80), expiration); |
| 377 alternative_service_info_vector.push_back(alternative_service_info3); | 380 alternative_service_info_vector.push_back(alternative_service_info3); |
| 378 // QUIC: GetAlternativeServices should return this one too. | 381 // QUIC: GetAlternativeServices should return this one too. |
| 379 AlternativeServiceInfo alternative_service_info4(kProtoQUIC, "foo", 443, | 382 AlternativeServiceInfo alternative_service_info4( |
| 380 expiration); | 383 AlternativeService(kProtoQUIC, "foo", 443), expiration); |
| 381 alternative_service_info_vector.push_back(alternative_service_info4); | 384 alternative_service_info_vector.push_back(alternative_service_info4); |
| 382 | 385 |
| 383 url::SchemeHostPort test_server("https", "foo", 443); | 386 url::SchemeHostPort test_server("https", "foo", 443); |
| 384 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); | 387 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 385 | 388 |
| 386 const AlternativeServiceInfoVector alternative_service_info_vector2 = | 389 const AlternativeServiceInfoVector alternative_service_info_vector2 = |
| 387 impl_.GetAlternativeServiceInfos(test_server); | 390 impl_.GetAlternativeServiceInfos(test_server); |
| 388 ASSERT_EQ(3u, alternative_service_info_vector2.size()); | 391 ASSERT_EQ(3u, alternative_service_info_vector2.size()); |
| 389 EXPECT_EQ(alternative_service_info2, alternative_service_info_vector2[0]); | 392 EXPECT_EQ(alternative_service_info2, alternative_service_info_vector2[0]); |
| 390 EXPECT_EQ(alternative_service_info3, alternative_service_info_vector2[1]); | 393 EXPECT_EQ(alternative_service_info3, alternative_service_info_vector2[1]); |
| 391 EXPECT_EQ(alternative_service_info4, alternative_service_info_vector2[2]); | 394 EXPECT_EQ(alternative_service_info4, alternative_service_info_vector2[2]); |
| 392 } | 395 } |
| 393 | 396 |
| 394 TEST_F(AlternateProtocolServerPropertiesTest, Set) { | 397 TEST_F(AlternateProtocolServerPropertiesTest, Set) { |
| 395 // |test_server1| has an alternative service, which will not be | 398 // |test_server1| has an alternative service, which will not be |
| 396 // affected by SetAlternativeServiceServers(), because | 399 // affected by SetAlternativeServiceServers(), because |
| 397 // |alternative_service_map| does not have an entry for | 400 // |alternative_service_map| does not have an entry for |
| 398 // |test_server1|. | 401 // |test_server1|. |
| 399 url::SchemeHostPort test_server1("http", "foo1", 80); | 402 url::SchemeHostPort test_server1("http", "foo1", 80); |
| 400 const AlternativeService alternative_service1(kProtoHTTP2, "bar1", 443); | 403 const AlternativeService alternative_service1(kProtoHTTP2, "bar1", 443); |
| 401 const base::Time now = base::Time::Now(); | 404 const base::Time now = base::Time::Now(); |
| 402 base::Time expiration1 = now + base::TimeDelta::FromDays(1); | 405 base::Time expiration1 = now + base::TimeDelta::FromDays(1); |
| 403 // 1st entry in the memory. | 406 // 1st entry in the memory. |
| 404 impl_.SetAlternativeService(test_server1, alternative_service1, expiration1); | 407 impl_.SetAlternativeService( |
| 408 test_server1, alternative_service1, expiration1, |
| 409 HttpNetworkSession::Params().quic_supported_versions); |
| 405 | 410 |
| 406 // |test_server2| has an alternative service, which will be | 411 // |test_server2| has an alternative service, which will be |
| 407 // overwritten by SetAlternativeServiceServers(), because | 412 // overwritten by SetAlternativeServiceServers(), because |
| 408 // |alternative_service_map| has an entry for | 413 // |alternative_service_map| has an entry for |
| 409 // |test_server2|. | 414 // |test_server2|. |
| 410 AlternativeServiceInfoVector alternative_service_info_vector; | 415 AlternativeServiceInfoVector alternative_service_info_vector; |
| 411 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443); | 416 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443); |
| 412 base::Time expiration2 = now + base::TimeDelta::FromDays(2); | 417 base::Time expiration2 = now + base::TimeDelta::FromDays(2); |
| 413 alternative_service_info_vector.push_back( | 418 alternative_service_info_vector.push_back( |
| 414 AlternativeServiceInfo(alternative_service2, expiration2)); | 419 AlternativeServiceInfo(alternative_service2, expiration2)); |
| (...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); | 1244 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); |
| 1240 | 1245 |
| 1241 impl_.Clear(); | 1246 impl_.Clear(); |
| 1242 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1247 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
| 1243 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); | 1248 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); |
| 1244 } | 1249 } |
| 1245 | 1250 |
| 1246 } // namespace | 1251 } // namespace |
| 1247 | 1252 |
| 1248 } // namespace net | 1253 } // namespace net |
| OLD | NEW |