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/test/test_mock_time_task_runner.h" | 12 #include "base/test/test_mock_time_task_runner.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
15 #include "net/base/ip_address.h" | 15 #include "net/base/ip_address.h" |
16 #include "net/http/http_network_session.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class ListValue; | 21 class ListValue; |
21 } | 22 } |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 | 25 |
25 const base::TimeDelta BROKEN_ALT_SVC_EXPIRE_DELAYS[10] = { | 26 const base::TimeDelta BROKEN_ALT_SVC_EXPIRE_DELAYS[10] = { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 bool HasAlternativeService(const url::SchemeHostPort& origin) { | 72 bool HasAlternativeService(const url::SchemeHostPort& origin) { |
72 const AlternativeServiceInfoVector alternative_service_info_vector = | 73 const AlternativeServiceInfoVector alternative_service_info_vector = |
73 impl_.GetAlternativeServiceInfos(origin); | 74 impl_.GetAlternativeServiceInfos(origin); |
74 return !alternative_service_info_vector.empty(); | 75 return !alternative_service_info_vector.empty(); |
75 } | 76 } |
76 | 77 |
77 bool SetAlternativeService(const url::SchemeHostPort& origin, | 78 bool SetAlternativeService(const url::SchemeHostPort& origin, |
78 const AlternativeService& alternative_service) { | 79 const AlternativeService& alternative_service) { |
79 const base::Time expiration = | 80 const base::Time expiration = |
80 base::Time::Now() + base::TimeDelta::FromDays(1); | 81 base::Time::Now() + base::TimeDelta::FromDays(1); |
81 return impl_.SetAlternativeService(origin, alternative_service, expiration); | 82 return impl_.SetAlternativeService( |
83 origin, alternative_service, expiration, | |
84 HttpNetworkSession::Params().quic_supported_versions); | |
82 } | 85 } |
83 | 86 |
84 void MarkBrokenAndLetExpireAlternativeServiceNTimes( | 87 void MarkBrokenAndLetExpireAlternativeServiceNTimes( |
85 const AlternativeService& alternative_service, | 88 const AlternativeService& alternative_service, |
86 int num_times) {} | 89 int num_times) {} |
87 | 90 |
88 scoped_refptr<base::TestMockTimeTaskRunner> test_task_runner_; | 91 scoped_refptr<base::TestMockTimeTaskRunner> test_task_runner_; |
89 | 92 |
90 std::unique_ptr<base::TickClock> broken_services_clock_; | 93 std::unique_ptr<base::TickClock> broken_services_clock_; |
91 HttpServerPropertiesImpl impl_; | 94 HttpServerPropertiesImpl impl_; |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 alternative_service_info_vector[0].alternative_service); | 385 alternative_service_info_vector[0].alternative_service); |
383 | 386 |
384 impl_.Clear(); | 387 impl_.Clear(); |
385 EXPECT_FALSE(HasAlternativeService(test_server)); | 388 EXPECT_FALSE(HasAlternativeService(test_server)); |
386 } | 389 } |
387 | 390 |
388 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { | 391 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { |
389 AlternativeServiceInfoVector alternative_service_info_vector; | 392 AlternativeServiceInfoVector alternative_service_info_vector; |
390 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 393 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
391 // Same hostname, same port, TCP: should be ignored. | 394 // Same hostname, same port, TCP: should be ignored. |
392 AlternativeServiceInfo alternative_service_info1(kProtoHTTP2, "foo", 443, | 395 AlternativeServiceInfo alternative_service_info1( |
393 expiration); | 396 AlternativeService(kProtoHTTP2, "foo", 443), expiration); |
394 alternative_service_info_vector.push_back(alternative_service_info1); | 397 alternative_service_info_vector.push_back(alternative_service_info1); |
395 // Different hostname: GetAlternativeServiceInfos should return this one. | 398 // Different hostname: GetAlternativeServiceInfos should return this one. |
396 AlternativeServiceInfo alternative_service_info2(kProtoHTTP2, "bar", 443, | 399 AlternativeServiceInfo alternative_service_info2( |
397 expiration); | 400 AlternativeService(kProtoHTTP2, "bar", 443), expiration); |
398 alternative_service_info_vector.push_back(alternative_service_info2); | 401 alternative_service_info_vector.push_back(alternative_service_info2); |
399 // Different port: GetAlternativeServiceInfos should return this one too. | 402 // Different port: GetAlternativeServiceInfos should return this one too. |
400 AlternativeServiceInfo alternative_service_info3(kProtoHTTP2, "foo", 80, | 403 AlternativeServiceInfo alternative_service_info3( |
401 expiration); | 404 AlternativeService(kProtoHTTP2, "foo", 80), expiration); |
402 alternative_service_info_vector.push_back(alternative_service_info3); | 405 alternative_service_info_vector.push_back(alternative_service_info3); |
403 // QUIC: GetAlternativeServices should return this one too. | 406 // QUIC: GetAlternativeServices should return this one too. |
404 AlternativeServiceInfo alternative_service_info4(kProtoQUIC, "foo", 443, | 407 AlternativeServiceInfo alternative_service_info4( |
405 expiration); | 408 AlternativeService(kProtoQUIC, "foo", 443), expiration); |
406 alternative_service_info_vector.push_back(alternative_service_info4); | 409 alternative_service_info_vector.push_back(alternative_service_info4); |
407 | 410 |
408 url::SchemeHostPort test_server("https", "foo", 443); | 411 url::SchemeHostPort test_server("https", "foo", 443); |
409 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); | 412 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
410 | 413 |
411 const AlternativeServiceInfoVector alternative_service_info_vector2 = | 414 const AlternativeServiceInfoVector alternative_service_info_vector2 = |
412 impl_.GetAlternativeServiceInfos(test_server); | 415 impl_.GetAlternativeServiceInfos(test_server); |
413 ASSERT_EQ(3u, alternative_service_info_vector2.size()); | 416 ASSERT_EQ(3u, alternative_service_info_vector2.size()); |
414 EXPECT_EQ(alternative_service_info2, alternative_service_info_vector2[0]); | 417 EXPECT_EQ(alternative_service_info2, alternative_service_info_vector2[0]); |
415 EXPECT_EQ(alternative_service_info3, alternative_service_info_vector2[1]); | 418 EXPECT_EQ(alternative_service_info3, alternative_service_info_vector2[1]); |
416 EXPECT_EQ(alternative_service_info4, alternative_service_info_vector2[2]); | 419 EXPECT_EQ(alternative_service_info4, alternative_service_info_vector2[2]); |
417 } | 420 } |
418 | 421 |
419 TEST_F(AlternateProtocolServerPropertiesTest, Set) { | 422 TEST_F(AlternateProtocolServerPropertiesTest, Set) { |
420 // |test_server1| has an alternative service, which will not be | 423 // |test_server1| has an alternative service, which will not be |
421 // affected by SetAlternativeServiceServers(), because | 424 // affected by SetAlternativeServiceServers(), because |
422 // |alternative_service_map| does not have an entry for | 425 // |alternative_service_map| does not have an entry for |
423 // |test_server1|. | 426 // |test_server1|. |
424 url::SchemeHostPort test_server1("http", "foo1", 80); | 427 url::SchemeHostPort test_server1("http", "foo1", 80); |
425 const AlternativeService alternative_service1(kProtoHTTP2, "bar1", 443); | 428 const AlternativeService alternative_service1(kProtoHTTP2, "bar1", 443); |
426 const base::Time now = base::Time::Now(); | 429 const base::Time now = base::Time::Now(); |
427 base::Time expiration1 = now + base::TimeDelta::FromDays(1); | 430 base::Time expiration1 = now + base::TimeDelta::FromDays(1); |
428 // 1st entry in the memory. | 431 // 1st entry in the memory. |
429 impl_.SetAlternativeService(test_server1, alternative_service1, expiration1); | 432 impl_.SetAlternativeService( |
433 test_server1, alternative_service1, expiration1, | |
434 HttpNetworkSession::Params().quic_supported_versions); | |
Ryan Hamilton
2017/06/07 20:52:23
For tests, I'd just use QuicSupportedVersions()?
Zhongyi Shi
2017/06/08 23:11:16
Fixed. We should use an empty version vector actua
| |
430 | 435 |
431 // |test_server2| has an alternative service, which will be | 436 // |test_server2| has an alternative service, which will be |
432 // overwritten by SetAlternativeServiceServers(), because | 437 // overwritten by SetAlternativeServiceServers(), because |
433 // |alternative_service_map| has an entry for | 438 // |alternative_service_map| has an entry for |
434 // |test_server2|. | 439 // |test_server2|. |
435 AlternativeServiceInfoVector alternative_service_info_vector; | 440 AlternativeServiceInfoVector alternative_service_info_vector; |
436 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443); | 441 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443); |
437 base::Time expiration2 = now + base::TimeDelta::FromDays(2); | 442 base::Time expiration2 = now + base::TimeDelta::FromDays(2); |
438 alternative_service_info_vector.push_back( | 443 alternative_service_info_vector.push_back( |
439 AlternativeServiceInfo(alternative_service2, expiration2)); | 444 AlternativeServiceInfo(alternative_service2, expiration2)); |
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1328 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); | 1333 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); |
1329 | 1334 |
1330 impl_.Clear(); | 1335 impl_.Clear(); |
1331 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1336 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
1332 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); | 1337 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); |
1333 } | 1338 } |
1334 | 1339 |
1335 } // namespace | 1340 } // namespace |
1336 | 1341 |
1337 } // namespace net | 1342 } // namespace net |
OLD | NEW |