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

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

Issue 2889273003: Fix some non-const ref function argument types. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/nqe/observation_buffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 namespace base { 18 namespace base {
19 class ListValue; 19 class ListValue;
20 } 20 }
21 21
22 namespace net { 22 namespace net {
23 23
24 class HttpServerPropertiesImplPeer { 24 class HttpServerPropertiesImplPeer {
25 public: 25 public:
26 static void AddBrokenAlternativeServiceWithExpirationTime( 26 static void AddBrokenAlternativeServiceWithExpirationTime(
27 HttpServerPropertiesImpl& impl, 27 HttpServerPropertiesImpl* impl,
28 AlternativeService alternative_service, 28 AlternativeService alternative_service,
29 base::TimeTicks when) { 29 base::TimeTicks when) {
30 impl.broken_alternative_services_.insert( 30 impl->broken_alternative_services_.insert(
31 std::make_pair(alternative_service, when)); 31 std::make_pair(alternative_service, when));
32 auto it = 32 auto it =
33 impl.recently_broken_alternative_services_.Get(alternative_service); 33 impl->recently_broken_alternative_services_.Get(alternative_service);
34 if (it == impl.recently_broken_alternative_services_.end()) { 34 if (it == impl->recently_broken_alternative_services_.end()) {
35 impl.recently_broken_alternative_services_.Put(alternative_service, 1); 35 impl->recently_broken_alternative_services_.Put(alternative_service, 1);
36 } else { 36 } else {
37 it->second++; 37 it->second++;
38 } 38 }
39 } 39 }
40 40
41 static void ExpireBrokenAlternateProtocolMappings( 41 static void ExpireBrokenAlternateProtocolMappings(
42 HttpServerPropertiesImpl& impl) { 42 HttpServerPropertiesImpl* impl) {
43 impl.ExpireBrokenAlternateProtocolMappings(); 43 impl->ExpireBrokenAlternateProtocolMappings();
44 } 44 }
45 }; 45 };
46 46
47 namespace { 47 namespace {
48 48
49 const int kMaxSupportsSpdyServerHosts = 500; 49 const int kMaxSupportsSpdyServerHosts = 500;
50 50
51 class HttpServerPropertiesImplTest : public testing::Test { 51 class HttpServerPropertiesImplTest : public testing::Test {
52 protected: 52 protected:
53 bool HasAlternativeService(const url::SchemeHostPort& origin) { 53 bool HasAlternativeService(const url::SchemeHostPort& origin) {
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 url::SchemeHostPort server("https", "foo", 443); 943 url::SchemeHostPort server("https", "foo", 443);
944 AlternativeService alternative_service(kProtoQUIC, "foo", 443); 944 AlternativeService alternative_service(kProtoQUIC, "foo", 443);
945 SetAlternativeService(server, alternative_service); 945 SetAlternativeService(server, alternative_service);
946 EXPECT_TRUE(HasAlternativeService(server)); 946 EXPECT_TRUE(HasAlternativeService(server));
947 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); 947 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
948 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); 948 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service));
949 949
950 base::TimeTicks past = 950 base::TimeTicks past =
951 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); 951 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42);
952 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( 952 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime(
953 impl_, alternative_service, past); 953 &impl_, alternative_service, past);
954 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); 954 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service));
955 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); 955 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service));
956 956
957 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); 957 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(&impl_);
958 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); 958 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
959 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); 959 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service));
960 } 960 }
961 961
962 // Regression test for https://crbug.com/505413. 962 // Regression test for https://crbug.com/505413.
963 TEST_F(AlternateProtocolServerPropertiesTest, RemoveExpiredBrokenAltSvc) { 963 TEST_F(AlternateProtocolServerPropertiesTest, RemoveExpiredBrokenAltSvc) {
964 url::SchemeHostPort foo_server("https", "foo", 443); 964 url::SchemeHostPort foo_server("https", "foo", 443);
965 AlternativeService bar_alternative_service(kProtoQUIC, "bar", 443); 965 AlternativeService bar_alternative_service(kProtoQUIC, "bar", 443);
966 SetAlternativeService(foo_server, bar_alternative_service); 966 SetAlternativeService(foo_server, bar_alternative_service);
967 EXPECT_TRUE(HasAlternativeService(foo_server)); 967 EXPECT_TRUE(HasAlternativeService(foo_server));
968 968
969 url::SchemeHostPort bar_server1("http", "bar", 80); 969 url::SchemeHostPort bar_server1("http", "bar", 80);
970 AlternativeService nohost_alternative_service(kProtoQUIC, "", 443); 970 AlternativeService nohost_alternative_service(kProtoQUIC, "", 443);
971 SetAlternativeService(bar_server1, nohost_alternative_service); 971 SetAlternativeService(bar_server1, nohost_alternative_service);
972 EXPECT_TRUE(HasAlternativeService(bar_server1)); 972 EXPECT_TRUE(HasAlternativeService(bar_server1));
973 973
974 url::SchemeHostPort bar_server2("https", "bar", 443); 974 url::SchemeHostPort bar_server2("https", "bar", 443);
975 AlternativeService baz_alternative_service(kProtoQUIC, "baz", 1234); 975 AlternativeService baz_alternative_service(kProtoQUIC, "baz", 1234);
976 SetAlternativeService(bar_server2, baz_alternative_service); 976 SetAlternativeService(bar_server2, baz_alternative_service);
977 EXPECT_TRUE(HasAlternativeService(bar_server2)); 977 EXPECT_TRUE(HasAlternativeService(bar_server2));
978 978
979 // Mark "bar:443" as broken. 979 // Mark "bar:443" as broken.
980 base::TimeTicks past = 980 base::TimeTicks past =
981 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); 981 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42);
982 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( 982 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime(
983 impl_, bar_alternative_service, past); 983 &impl_, bar_alternative_service, past);
984 984
985 // Expire brokenness of "bar:443". 985 // Expire brokenness of "bar:443".
986 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); 986 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(&impl_);
987 987
988 // "foo:443" should have no alternative service now. 988 // "foo:443" should have no alternative service now.
989 EXPECT_FALSE(HasAlternativeService(foo_server)); 989 EXPECT_FALSE(HasAlternativeService(foo_server));
990 // "bar:80" should have no alternative service now. 990 // "bar:80" should have no alternative service now.
991 EXPECT_FALSE(HasAlternativeService(bar_server1)); 991 EXPECT_FALSE(HasAlternativeService(bar_server1));
992 // The alternative service of "bar:443" should be unaffected. 992 // The alternative service of "bar:443" should be unaffected.
993 EXPECT_TRUE(HasAlternativeService(bar_server2)); 993 EXPECT_TRUE(HasAlternativeService(bar_server2));
994 994
995 EXPECT_TRUE( 995 EXPECT_TRUE(
996 impl_.WasAlternativeServiceRecentlyBroken(bar_alternative_service)); 996 impl_.WasAlternativeServiceRecentlyBroken(bar_alternative_service));
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); 1239 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id)));
1240 1240
1241 impl_.Clear(); 1241 impl_.Clear();
1242 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); 1242 EXPECT_EQ(0u, impl_.quic_server_info_map().size());
1243 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); 1243 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id));
1244 } 1244 }
1245 1245
1246 } // namespace 1246 } // namespace
1247 1247
1248 } // namespace net 1248 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/nqe/observation_buffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698