Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: net/http/http_server_properties_impl_unittest.cc

Issue 2901093004: Add and persist a new field in AlternativeServiceInfo to list QUIC verisons advertised (Closed)
Patch Set: manually fix rebase issues Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 QuicVersionVector advertised_versions;
83 if (alternative_service.protocol == kProtoQUIC) {
84 advertised_versions =
85 HttpNetworkSession::Params().quic_supported_versions;
86 }
87 return impl_.SetAlternativeService(origin, alternative_service, expiration,
88 advertised_versions);
82 } 89 }
83 90
84 void MarkBrokenAndLetExpireAlternativeServiceNTimes( 91 void MarkBrokenAndLetExpireAlternativeServiceNTimes(
85 const AlternativeService& alternative_service, 92 const AlternativeService& alternative_service,
86 int num_times) {} 93 int num_times) {}
87 94
88 scoped_refptr<base::TestMockTimeTaskRunner> test_task_runner_; 95 scoped_refptr<base::TestMockTimeTaskRunner> test_task_runner_;
89 96
90 std::unique_ptr<base::TickClock> broken_services_clock_; 97 std::unique_ptr<base::TickClock> broken_services_clock_;
91 HttpServerPropertiesImpl impl_; 98 HttpServerPropertiesImpl impl_;
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 alternative_service_info_vector[0].alternative_service); 389 alternative_service_info_vector[0].alternative_service);
383 390
384 impl_.Clear(); 391 impl_.Clear();
385 EXPECT_FALSE(HasAlternativeService(test_server)); 392 EXPECT_FALSE(HasAlternativeService(test_server));
386 } 393 }
387 394
388 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { 395 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) {
389 AlternativeServiceInfoVector alternative_service_info_vector; 396 AlternativeServiceInfoVector alternative_service_info_vector;
390 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 397 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
391 // Same hostname, same port, TCP: should be ignored. 398 // Same hostname, same port, TCP: should be ignored.
392 AlternativeServiceInfo alternative_service_info1(kProtoHTTP2, "foo", 443, 399 AlternativeServiceInfo alternative_service_info1(
393 expiration); 400 AlternativeService(kProtoHTTP2, "foo", 443), expiration);
394 alternative_service_info_vector.push_back(alternative_service_info1); 401 alternative_service_info_vector.push_back(alternative_service_info1);
395 // Different hostname: GetAlternativeServiceInfos should return this one. 402 // Different hostname: GetAlternativeServiceInfos should return this one.
396 AlternativeServiceInfo alternative_service_info2(kProtoHTTP2, "bar", 443, 403 AlternativeServiceInfo alternative_service_info2(
397 expiration); 404 AlternativeService(kProtoHTTP2, "bar", 443), expiration);
398 alternative_service_info_vector.push_back(alternative_service_info2); 405 alternative_service_info_vector.push_back(alternative_service_info2);
399 // Different port: GetAlternativeServiceInfos should return this one too. 406 // Different port: GetAlternativeServiceInfos should return this one too.
400 AlternativeServiceInfo alternative_service_info3(kProtoHTTP2, "foo", 80, 407 AlternativeServiceInfo alternative_service_info3(
401 expiration); 408 AlternativeService(kProtoHTTP2, "foo", 80), expiration);
402 alternative_service_info_vector.push_back(alternative_service_info3); 409 alternative_service_info_vector.push_back(alternative_service_info3);
403 // QUIC: GetAlternativeServices should return this one too. 410 // QUIC: GetAlternativeServices should return this one too.
404 AlternativeServiceInfo alternative_service_info4(kProtoQUIC, "foo", 443, 411 AlternativeServiceInfo alternative_service_info4(
405 expiration); 412 AlternativeService(kProtoQUIC, "foo", 443), expiration);
406 alternative_service_info_vector.push_back(alternative_service_info4); 413 alternative_service_info_vector.push_back(alternative_service_info4);
407 414
408 url::SchemeHostPort test_server("https", "foo", 443); 415 url::SchemeHostPort test_server("https", "foo", 443);
409 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); 416 impl_.SetAlternativeServices(test_server, alternative_service_info_vector);
410 417
411 const AlternativeServiceInfoVector alternative_service_info_vector2 = 418 const AlternativeServiceInfoVector alternative_service_info_vector2 =
412 impl_.GetAlternativeServiceInfos(test_server); 419 impl_.GetAlternativeServiceInfos(test_server);
413 ASSERT_EQ(3u, alternative_service_info_vector2.size()); 420 ASSERT_EQ(3u, alternative_service_info_vector2.size());
414 EXPECT_EQ(alternative_service_info2, alternative_service_info_vector2[0]); 421 EXPECT_EQ(alternative_service_info2, alternative_service_info_vector2[0]);
415 EXPECT_EQ(alternative_service_info3, alternative_service_info_vector2[1]); 422 EXPECT_EQ(alternative_service_info3, alternative_service_info_vector2[1]);
416 EXPECT_EQ(alternative_service_info4, alternative_service_info_vector2[2]); 423 EXPECT_EQ(alternative_service_info4, alternative_service_info_vector2[2]);
417 } 424 }
418 425
419 TEST_F(AlternateProtocolServerPropertiesTest, Set) { 426 TEST_F(AlternateProtocolServerPropertiesTest, Set) {
420 // |test_server1| has an alternative service, which will not be 427 // |test_server1| has an alternative service, which will not be
421 // affected by SetAlternativeServiceServers(), because 428 // affected by SetAlternativeServiceServers(), because
422 // |alternative_service_map| does not have an entry for 429 // |alternative_service_map| does not have an entry for
423 // |test_server1|. 430 // |test_server1|.
424 url::SchemeHostPort test_server1("http", "foo1", 80); 431 url::SchemeHostPort test_server1("http", "foo1", 80);
425 const AlternativeService alternative_service1(kProtoHTTP2, "bar1", 443); 432 const AlternativeService alternative_service1(kProtoHTTP2, "bar1", 443);
426 const base::Time now = base::Time::Now(); 433 const base::Time now = base::Time::Now();
427 base::Time expiration1 = now + base::TimeDelta::FromDays(1); 434 base::Time expiration1 = now + base::TimeDelta::FromDays(1);
428 // 1st entry in the memory. 435 // 1st entry in the memory.
429 impl_.SetAlternativeService(test_server1, alternative_service1, expiration1); 436 impl_.SetAlternativeService(test_server1, alternative_service1, expiration1,
437 QuicVersionVector());
430 438
431 // |test_server2| has an alternative service, which will be 439 // |test_server2| has an alternative service, which will be
432 // overwritten by SetAlternativeServiceServers(), because 440 // overwritten by SetAlternativeServiceServers(), because
433 // |alternative_service_map| has an entry for 441 // |alternative_service_map| has an entry for
434 // |test_server2|. 442 // |test_server2|.
435 AlternativeServiceInfoVector alternative_service_info_vector; 443 AlternativeServiceInfoVector alternative_service_info_vector;
436 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443); 444 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443);
437 base::Time expiration2 = now + base::TimeDelta::FromDays(2); 445 base::Time expiration2 = now + base::TimeDelta::FromDays(2);
438 alternative_service_info_vector.push_back( 446 alternative_service_info_vector.push_back(
439 AlternativeServiceInfo(alternative_service2, expiration2)); 447 AlternativeServiceInfo(alternative_service2, expiration2));
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); 1336 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id)));
1329 1337
1330 impl_.Clear(); 1338 impl_.Clear();
1331 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); 1339 EXPECT_EQ(0u, impl_.quic_server_info_map().size());
1332 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); 1340 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id));
1333 } 1341 }
1334 1342
1335 } // namespace 1343 } // namespace
1336 1344
1337 } // namespace net 1345 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698