| 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 "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class ListValue; | 19 class ListValue; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace net { | 22 namespace net { |
| 22 | 23 |
| 23 class HttpServerPropertiesImplPeer { | 24 class HttpServerPropertiesImplPeer { |
| 24 public: | 25 public: |
| 25 static void AddBrokenAlternativeServiceWithExpirationTime( | 26 static void AddBrokenAlternativeServiceWithExpirationTime( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 41 *os << alternative_service.ToString(); | 42 *os << alternative_service.ToString(); |
| 42 } | 43 } |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| 45 | 46 |
| 46 const int kMaxSupportsSpdyServerHosts = 500; | 47 const int kMaxSupportsSpdyServerHosts = 500; |
| 47 const SpdySettingsIds kSpdySettingsId = SETTINGS_UPLOAD_BANDWIDTH; | 48 const SpdySettingsIds kSpdySettingsId = SETTINGS_UPLOAD_BANDWIDTH; |
| 48 const SpdySettingsFlags kSpdySettingsFlags = SETTINGS_FLAG_PERSISTED; | 49 const SpdySettingsFlags kSpdySettingsFlags = SETTINGS_FLAG_PERSISTED; |
| 49 | 50 |
| 50 struct SpdySettingsDataToVerify { | 51 struct SpdySettingsDataToVerify { |
| 51 HostPortPair spdy_server; | 52 url::SchemeHostPort spdy_server; |
| 52 uint32_t value; | 53 uint32_t value; |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 class HttpServerPropertiesImplTest : public testing::Test { | 56 class HttpServerPropertiesImplTest : public testing::Test { |
| 56 protected: | 57 protected: |
| 57 bool HasAlternativeService(const HostPortPair& origin) { | 58 bool HasAlternativeService(const url::SchemeHostPort& origin) { |
| 58 const AlternativeServiceVector alternative_service_vector = | 59 const AlternativeServiceVector alternative_service_vector = |
| 59 impl_.GetAlternativeServices(origin); | 60 impl_.GetAlternativeServices(origin); |
| 60 return !alternative_service_vector.empty(); | 61 return !alternative_service_vector.empty(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 bool SetAlternativeService(const HostPortPair& origin, | 64 bool SetAlternativeService(const url::SchemeHostPort& origin, |
| 64 const AlternativeService& alternative_service) { | 65 const AlternativeService& alternative_service) { |
| 65 const base::Time expiration = | 66 const base::Time expiration = |
| 66 base::Time::Now() + base::TimeDelta::FromDays(1); | 67 base::Time::Now() + base::TimeDelta::FromDays(1); |
| 67 return impl_.SetAlternativeService(origin, alternative_service, expiration); | 68 return impl_.SetAlternativeService(origin, alternative_service, expiration); |
| 68 } | 69 } |
| 69 | 70 |
| 70 void InitializeSpdySettingsUploadBandwidth(SpdySettingsMap* spdy_settings_map, | 71 void InitializeSpdySettingsUploadBandwidth( |
| 71 const HostPortPair& spdy_server, | 72 SpdySettingsMap* spdy_settings_map, |
| 72 uint32_t value) { | 73 const url::SchemeHostPort& spdy_server, |
| 74 uint32_t value) { |
| 73 SettingsMap settings_map; | 75 SettingsMap settings_map; |
| 74 settings_map[kSpdySettingsId] = | 76 settings_map[kSpdySettingsId] = |
| 75 SettingsFlagsAndValue(kSpdySettingsFlags, value); | 77 SettingsFlagsAndValue(kSpdySettingsFlags, value); |
| 76 spdy_settings_map->Put(spdy_server, settings_map); | 78 spdy_settings_map->Put(spdy_server, settings_map); |
| 77 } | 79 } |
| 78 | 80 |
| 79 void VerifySpdySettingsUploadBandwidth( | 81 void VerifySpdySettingsUploadBandwidth( |
| 80 const SpdySettingsDataToVerify* data_to_verify) { | 82 const SpdySettingsDataToVerify* data_to_verify) { |
| 81 const SpdySettingsMap& spdy_settings_map = impl_.spdy_settings_map(); | 83 const SpdySettingsMap& spdy_settings_map = impl_.spdy_settings_map(); |
| 82 int count = 0; | 84 int count = 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 EXPECT_EQ(kSpdySettingsFlags, flags_and_value_memory.first); | 96 EXPECT_EQ(kSpdySettingsFlags, flags_and_value_memory.first); |
| 95 EXPECT_EQ(data.value, flags_and_value_memory.second); | 97 EXPECT_EQ(data.value, flags_and_value_memory.second); |
| 96 } | 98 } |
| 97 } | 99 } |
| 98 | 100 |
| 99 HttpServerPropertiesImpl impl_; | 101 HttpServerPropertiesImpl impl_; |
| 100 }; | 102 }; |
| 101 | 103 |
| 102 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; | 104 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; |
| 103 | 105 |
| 106 TEST_F(SpdyServerPropertiesTest, InitializeWithSchemeHostPort) { |
| 107 // Check spdy servers are correctly set with SchemeHostPort key. |
| 108 url::SchemeHostPort https_www_server("https", "www.google.com", 443); |
| 109 url::SchemeHostPort http_photo_server("http", "photos.google.com", 80); |
| 110 // Servers with port equal to default port in scheme will drop port components |
| 111 // when calling Serialize(). |
| 112 std::string spdy_server_g = https_www_server.Serialize(); |
| 113 std::string spdy_server_p = http_photo_server.Serialize(); |
| 114 |
| 115 url::SchemeHostPort http_google_server("http", "www.google.com", 443); |
| 116 url::SchemeHostPort https_photos_server("https", "photos.google.com", 443); |
| 117 url::SchemeHostPort valid_google_server((GURL("https://www.google.com"))); |
| 118 |
| 119 // Initializing https://www.google.com:443 and https://photos.google.com:443 |
| 120 // as spdy servers. |
| 121 std::vector<std::string> spdy_servers1; |
| 122 spdy_servers1.push_back(spdy_server_g); // Will be 0th index. |
| 123 spdy_servers1.push_back(spdy_server_p); // Will be 1st index. |
| 124 impl_.InitializeSpdyServers(&spdy_servers1, true); |
| 125 EXPECT_TRUE(impl_.SupportsRequestPriority(http_photo_server)); |
| 126 EXPECT_TRUE(impl_.SupportsRequestPriority(https_www_server)); |
| 127 EXPECT_FALSE(impl_.SupportsRequestPriority(http_google_server)); |
| 128 EXPECT_FALSE(impl_.SupportsRequestPriority(https_photos_server)); |
| 129 EXPECT_TRUE(impl_.SupportsRequestPriority(valid_google_server)); |
| 130 } |
| 131 |
| 104 TEST_F(SpdyServerPropertiesTest, Initialize) { | 132 TEST_F(SpdyServerPropertiesTest, Initialize) { |
| 105 HostPortPair spdy_server_google("www.google.com", 443); | 133 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 106 std::string spdy_server_g = spdy_server_google.ToString(); | 134 std::string spdy_server_g = spdy_server_google.Serialize(); |
| 107 | 135 |
| 108 HostPortPair spdy_server_photos("photos.google.com", 443); | 136 url::SchemeHostPort spdy_server_photos("https", "photos.google.com", 443); |
| 109 std::string spdy_server_p = spdy_server_photos.ToString(); | 137 std::string spdy_server_p = spdy_server_photos.Serialize(); |
| 110 | 138 |
| 111 HostPortPair spdy_server_docs("docs.google.com", 443); | 139 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
| 112 std::string spdy_server_d = spdy_server_docs.ToString(); | 140 std::string spdy_server_d = spdy_server_docs.Serialize(); |
| 113 | 141 |
| 114 HostPortPair spdy_server_mail("mail.google.com", 443); | 142 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 115 std::string spdy_server_m = spdy_server_mail.ToString(); | 143 std::string spdy_server_m = spdy_server_mail.Serialize(); |
| 116 | 144 |
| 117 // Check by initializing NULL spdy servers. | 145 // Check by initializing NULL spdy servers. |
| 118 impl_.InitializeSpdyServers(NULL, true); | 146 impl_.InitializeSpdyServers(NULL, true); |
| 119 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); | 147 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 120 | 148 |
| 121 // Check by initializing empty spdy servers. | 149 // Check by initializing empty spdy servers. |
| 122 std::vector<std::string> spdy_servers; | 150 std::vector<std::string> spdy_servers; |
| 123 impl_.InitializeSpdyServers(&spdy_servers, true); | 151 impl_.InitializeSpdyServers(&spdy_servers, true); |
| 124 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); | 152 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 125 | 153 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 221 |
| 194 // Verify photos and mail servers don't support SPDY and other servers support | 222 // Verify photos and mail servers don't support SPDY and other servers support |
| 195 // SPDY. | 223 // SPDY. |
| 196 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 224 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 197 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 225 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 198 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_photos)); | 226 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_photos)); |
| 199 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 227 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 200 } | 228 } |
| 201 | 229 |
| 202 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) { | 230 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) { |
| 203 HostPortPair spdy_server_empty(std::string(), 443); | 231 url::SchemeHostPort spdy_server_empty("https", std::string(), 443); |
| 204 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty)); | 232 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty)); |
| 205 | 233 |
| 206 // Add www.google.com:443 as supporting SPDY. | 234 // Add www.google.com:443 as supporting SPDY. |
| 207 HostPortPair spdy_server_google("www.google.com", 443); | 235 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 208 impl_.SetSupportsSpdy(spdy_server_google, true); | 236 impl_.SetSupportsSpdy(spdy_server_google, true); |
| 209 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 237 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 210 | 238 |
| 211 // Add mail.google.com:443 as not supporting SPDY. | 239 // Add mail.google.com:443 as not supporting SPDY. |
| 212 HostPortPair spdy_server_mail("mail.google.com", 443); | 240 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 213 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 241 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 214 | 242 |
| 215 // Add docs.google.com:443 as supporting SPDY. | 243 // Add docs.google.com:443 as supporting SPDY. |
| 216 HostPortPair spdy_server_docs("docs.google.com", 443); | 244 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
| 217 impl_.SetSupportsSpdy(spdy_server_docs, true); | 245 impl_.SetSupportsSpdy(spdy_server_docs, true); |
| 218 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 246 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 219 | 247 |
| 220 // Add www.youtube.com:443 as supporting QUIC. | 248 // Add www.youtube.com:443 as supporting QUIC. |
| 221 HostPortPair quic_server_youtube("www.youtube.com", 443); | 249 url::SchemeHostPort youtube_server("https", "www.youtube.com", 443); |
| 222 const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443); | 250 const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443); |
| 223 SetAlternativeService(quic_server_youtube, alternative_service1); | 251 SetAlternativeService(youtube_server, alternative_service1); |
| 224 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); | 252 EXPECT_TRUE(impl_.SupportsRequestPriority(youtube_server)); |
| 225 | 253 |
| 226 // Add www.example.com:443 with two alternative services, one supporting QUIC. | 254 // Add www.example.com:443 with two alternative services, one supporting QUIC. |
| 227 HostPortPair quic_server_example("www.example.com", 443); | 255 url::SchemeHostPort example_server("https", "www.example.com", 443); |
| 228 const AlternativeService alternative_service2(NPN_HTTP_2, "", 443); | 256 const AlternativeService alternative_service2(NPN_HTTP_2, "", 443); |
| 229 SetAlternativeService(quic_server_example, alternative_service2); | 257 SetAlternativeService(example_server, alternative_service2); |
| 230 SetAlternativeService(quic_server_example, alternative_service1); | 258 SetAlternativeService(example_server, alternative_service1); |
| 231 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); | 259 EXPECT_TRUE(impl_.SupportsRequestPriority(example_server)); |
| 232 | 260 |
| 233 // Verify all the entries are the same after additions. | 261 // Verify all the entries are the same after additions. |
| 234 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 262 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 235 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 263 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 236 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 264 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 237 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); | 265 EXPECT_TRUE(impl_.SupportsRequestPriority(youtube_server)); |
| 238 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); | 266 EXPECT_TRUE(impl_.SupportsRequestPriority(example_server)); |
| 239 } | 267 } |
| 240 | 268 |
| 241 TEST_F(SpdyServerPropertiesTest, Clear) { | 269 TEST_F(SpdyServerPropertiesTest, Clear) { |
| 242 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. | 270 // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. |
| 243 HostPortPair spdy_server_google("www.google.com", 443); | 271 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 244 impl_.SetSupportsSpdy(spdy_server_google, true); | 272 impl_.SetSupportsSpdy(spdy_server_google, true); |
| 245 HostPortPair spdy_server_mail("mail.google.com", 443); | 273 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 246 impl_.SetSupportsSpdy(spdy_server_mail, true); | 274 impl_.SetSupportsSpdy(spdy_server_mail, true); |
| 247 | 275 |
| 248 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 276 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 249 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); | 277 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 250 | 278 |
| 251 impl_.Clear(); | 279 impl_.Clear(); |
| 252 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); | 280 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 253 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 281 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 254 } | 282 } |
| 255 | 283 |
| 256 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { | 284 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { |
| 257 base::ListValue spdy_server_list; | 285 base::ListValue spdy_server_list; |
| 258 | 286 |
| 259 // Check there are no spdy_servers. | 287 // Check there are no spdy_servers. |
| 260 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 288 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 261 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 289 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
| 262 | 290 |
| 263 // Check empty server is not added. | 291 // Check empty server is not added. |
| 264 HostPortPair spdy_server_empty(std::string(), 443); | 292 url::SchemeHostPort spdy_server_empty("https", std::string(), 443); |
| 265 impl_.SetSupportsSpdy(spdy_server_empty, true); | 293 impl_.SetSupportsSpdy(spdy_server_empty, true); |
| 266 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 294 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 267 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 295 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
| 268 | 296 |
| 269 std::string string_value_g; | 297 std::string string_value_g; |
| 270 std::string string_value_m; | 298 std::string string_value_m; |
| 271 HostPortPair spdy_server_google("www.google.com", 443); | 299 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 272 std::string spdy_server_g = spdy_server_google.ToString(); | 300 std::string spdy_server_g = spdy_server_google.Serialize(); |
| 273 HostPortPair spdy_server_mail("mail.google.com", 443); | 301 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 274 std::string spdy_server_m = spdy_server_mail.ToString(); | 302 std::string spdy_server_m = spdy_server_mail.Serialize(); |
| 275 | 303 |
| 276 // Add www.google.com:443 as not supporting SPDY. | 304 // Add www.google.com:443 as not supporting SPDY. |
| 277 impl_.SetSupportsSpdy(spdy_server_google, false); | 305 impl_.SetSupportsSpdy(spdy_server_google, false); |
| 278 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 306 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 279 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 307 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
| 280 | 308 |
| 281 // Add www.google.com:443 as supporting SPDY. | 309 // Add www.google.com:443 as supporting SPDY. |
| 282 impl_.SetSupportsSpdy(spdy_server_google, true); | 310 impl_.SetSupportsSpdy(spdy_server_google, true); |
| 283 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 311 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 284 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 312 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 308 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 336 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
| 309 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); | 337 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); |
| 310 ASSERT_EQ(spdy_server_m, string_value_m); | 338 ASSERT_EQ(spdy_server_m, string_value_m); |
| 311 } | 339 } |
| 312 | 340 |
| 313 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) { | 341 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) { |
| 314 base::ListValue spdy_server_list; | 342 base::ListValue spdy_server_list; |
| 315 | 343 |
| 316 std::string string_value_g; | 344 std::string string_value_g; |
| 317 std::string string_value_m; | 345 std::string string_value_m; |
| 318 HostPortPair spdy_server_google("www.google.com", 443); | 346 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 319 std::string spdy_server_g = spdy_server_google.ToString(); | 347 std::string spdy_server_g = spdy_server_google.Serialize(); |
| 320 HostPortPair spdy_server_mail("mail.google.com", 443); | 348 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 321 std::string spdy_server_m = spdy_server_mail.ToString(); | 349 std::string spdy_server_m = spdy_server_mail.Serialize(); |
| 322 | 350 |
| 323 // Add www.google.com:443 as supporting SPDY. | 351 // Add www.google.com:443 as supporting SPDY. |
| 324 impl_.SetSupportsSpdy(spdy_server_google, true); | 352 impl_.SetSupportsSpdy(spdy_server_google, true); |
| 325 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 353 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| 326 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 354 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
| 327 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 355 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
| 328 ASSERT_EQ(spdy_server_g, string_value_g); | 356 ASSERT_EQ(spdy_server_g, string_value_g); |
| 329 | 357 |
| 330 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and | 358 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and |
| 331 // www.google.com:443 are in the list. | 359 // www.google.com:443 are in the list. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 344 ASSERT_EQ(2U, spdy_server_list.GetSize()); | 372 ASSERT_EQ(2U, spdy_server_list.GetSize()); |
| 345 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 373 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
| 346 ASSERT_EQ(spdy_server_g, string_value_g); | 374 ASSERT_EQ(spdy_server_g, string_value_g); |
| 347 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); | 375 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); |
| 348 ASSERT_EQ(spdy_server_m, string_value_m); | 376 ASSERT_EQ(spdy_server_m, string_value_m); |
| 349 } | 377 } |
| 350 | 378 |
| 351 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; | 379 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; |
| 352 | 380 |
| 353 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { | 381 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { |
| 354 HostPortPair test_host_port_pair("foo", 80); | 382 url::SchemeHostPort test_server("http", "foo", 80); |
| 355 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 383 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 356 | 384 |
| 357 AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); | 385 AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
| 358 SetAlternativeService(test_host_port_pair, alternative_service); | 386 SetAlternativeService(test_server, alternative_service); |
| 359 const AlternativeServiceVector alternative_service_vector = | 387 const AlternativeServiceVector alternative_service_vector = |
| 360 impl_.GetAlternativeServices(test_host_port_pair); | 388 impl_.GetAlternativeServices(test_server); |
| 361 ASSERT_EQ(1u, alternative_service_vector.size()); | 389 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 362 EXPECT_EQ(alternative_service, alternative_service_vector[0]); | 390 EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 363 | 391 |
| 364 impl_.Clear(); | 392 impl_.Clear(); |
| 365 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 393 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 366 } | 394 } |
| 367 | 395 |
| 368 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { | 396 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { |
| 369 AlternativeServiceInfoVector alternative_service_info_vector; | 397 AlternativeServiceInfoVector alternative_service_info_vector; |
| 370 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 398 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 371 // Same hostname, same port, TCP: should be ignored. | 399 // Same hostname, same port, TCP: should be ignored. |
| 372 AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); | 400 AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); |
| 373 alternative_service_info_vector.push_back( | 401 alternative_service_info_vector.push_back( |
| 374 AlternativeServiceInfo(alternative_service1, expiration)); | 402 AlternativeServiceInfo(alternative_service1, expiration)); |
| 375 // Different hostname: GetAlternativeServices should return this one. | 403 // Different hostname: GetAlternativeServices should return this one. |
| 376 AlternativeService alternative_service2(NPN_HTTP_2, "bar", 443); | 404 AlternativeService alternative_service2(NPN_HTTP_2, "bar", 443); |
| 377 alternative_service_info_vector.push_back( | 405 alternative_service_info_vector.push_back( |
| 378 AlternativeServiceInfo(alternative_service2, expiration)); | 406 AlternativeServiceInfo(alternative_service2, expiration)); |
| 379 // Different port: GetAlternativeServices should return this one too. | 407 // Different port: GetAlternativeServices should return this one too. |
| 380 AlternativeService alternative_service3(NPN_HTTP_2, "foo", 80); | 408 AlternativeService alternative_service3(NPN_HTTP_2, "foo", 80); |
| 381 alternative_service_info_vector.push_back( | 409 alternative_service_info_vector.push_back( |
| 382 AlternativeServiceInfo(alternative_service3, expiration)); | 410 AlternativeServiceInfo(alternative_service3, expiration)); |
| 383 // QUIC: GetAlternativeServices should return this one too. | 411 // QUIC: GetAlternativeServices should return this one too. |
| 384 AlternativeService alternative_service4(QUIC, "foo", 443); | 412 AlternativeService alternative_service4(QUIC, "foo", 443); |
| 385 alternative_service_info_vector.push_back( | 413 alternative_service_info_vector.push_back( |
| 386 AlternativeServiceInfo(alternative_service4, expiration)); | 414 AlternativeServiceInfo(alternative_service4, expiration)); |
| 387 | 415 |
| 388 HostPortPair test_host_port_pair("foo", 443); | 416 url::SchemeHostPort test_server("https", "foo", 443); |
| 389 impl_.SetAlternativeServices(test_host_port_pair, | 417 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 390 alternative_service_info_vector); | |
| 391 | 418 |
| 392 const AlternativeServiceVector alternative_service_vector = | 419 const AlternativeServiceVector alternative_service_vector = |
| 393 impl_.GetAlternativeServices(test_host_port_pair); | 420 impl_.GetAlternativeServices(test_server); |
| 394 ASSERT_EQ(3u, alternative_service_vector.size()); | 421 ASSERT_EQ(3u, alternative_service_vector.size()); |
| 395 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); | 422 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
| 396 EXPECT_EQ(alternative_service3, alternative_service_vector[1]); | 423 EXPECT_EQ(alternative_service3, alternative_service_vector[1]); |
| 397 EXPECT_EQ(alternative_service4, alternative_service_vector[2]); | 424 EXPECT_EQ(alternative_service4, alternative_service_vector[2]); |
| 398 } | 425 } |
| 399 | 426 |
| 400 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { | 427 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { |
| 401 // |test_host_port_pair1| has an alternative service, which will not be | 428 // |test_server1| has an alternative service, which will not be |
| 402 // affected by InitializeAlternativeServiceServers(), because | 429 // affected by InitializeAlternativeServiceServers(), because |
| 403 // |alternative_service_map| does not have an entry for | 430 // |alternative_service_map| does not have an entry for |
| 404 // |test_host_port_pair1|. | 431 // |test_server1|. |
| 405 HostPortPair test_host_port_pair1("foo1", 80); | 432 url::SchemeHostPort test_server1("http", "foo1", 80); |
| 406 const AlternativeService alternative_service1(NPN_HTTP_2, "bar1", 443); | 433 const AlternativeService alternative_service1(NPN_HTTP_2, "bar1", 443); |
| 407 const base::Time now = base::Time::Now(); | 434 const base::Time now = base::Time::Now(); |
| 408 base::Time expiration1 = now + base::TimeDelta::FromDays(1); | 435 base::Time expiration1 = now + base::TimeDelta::FromDays(1); |
| 409 // 1st entry in the memory. | 436 // 1st entry in the memory. |
| 410 impl_.SetAlternativeService(test_host_port_pair1, alternative_service1, | 437 impl_.SetAlternativeService(test_server1, alternative_service1, expiration1); |
| 411 expiration1); | |
| 412 | 438 |
| 413 // |test_host_port_pair2| has an alternative service, which will be | 439 // |test_server2| has an alternative service, which will be |
| 414 // overwritten by InitializeAlternativeServiceServers(), because | 440 // overwritten by InitializeAlternativeServiceServers(), because |
| 415 // |alternative_service_map| has an entry for | 441 // |alternative_service_map| has an entry for |
| 416 // |test_host_port_pair2|. | 442 // |test_server2|. |
| 417 AlternativeServiceInfoVector alternative_service_info_vector; | 443 AlternativeServiceInfoVector alternative_service_info_vector; |
| 418 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443); | 444 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443); |
| 419 base::Time expiration2 = now + base::TimeDelta::FromDays(2); | 445 base::Time expiration2 = now + base::TimeDelta::FromDays(2); |
| 420 alternative_service_info_vector.push_back( | 446 alternative_service_info_vector.push_back( |
| 421 AlternativeServiceInfo(alternative_service2, expiration2)); | 447 AlternativeServiceInfo(alternative_service2, expiration2)); |
| 422 HostPortPair test_host_port_pair2("foo2", 80); | 448 url::SchemeHostPort test_server2("http", "foo2", 80); |
| 423 // 0th entry in the memory. | 449 // 0th entry in the memory. |
| 424 impl_.SetAlternativeServices(test_host_port_pair2, | 450 impl_.SetAlternativeServices(test_server2, alternative_service_info_vector); |
| 425 alternative_service_info_vector); | |
| 426 | 451 |
| 427 // Prepare |alternative_service_map| to be loaded by | 452 // Prepare |alternative_service_map| to be loaded by |
| 428 // InitializeAlternativeServiceServers(). | 453 // InitializeAlternativeServiceServers(). |
| 429 AlternativeServiceMap alternative_service_map( | 454 AlternativeServiceMap alternative_service_map( |
| 430 AlternativeServiceMap::NO_AUTO_EVICT); | 455 AlternativeServiceMap::NO_AUTO_EVICT); |
| 431 const AlternativeService alternative_service3(NPN_HTTP_2, "bar3", 123); | 456 const AlternativeService alternative_service3(NPN_HTTP_2, "bar3", 123); |
| 432 base::Time expiration3 = now + base::TimeDelta::FromDays(3); | 457 base::Time expiration3 = now + base::TimeDelta::FromDays(3); |
| 433 const AlternativeServiceInfo alternative_service_info1(alternative_service3, | 458 const AlternativeServiceInfo alternative_service_info1(alternative_service3, |
| 434 expiration3); | 459 expiration3); |
| 435 // Simulate updating data for 0th entry with data from Preferences. | 460 // Simulate updating data for 0th entry with data from Preferences. |
| 436 alternative_service_map.Put( | 461 alternative_service_map.Put( |
| 437 test_host_port_pair2, | 462 test_server2, |
| 438 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); | 463 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); |
| 439 | 464 |
| 440 HostPortPair test_host_port_pair3("foo3", 80); | 465 url::SchemeHostPort test_server3("http", "foo3", 80); |
| 441 const AlternativeService alternative_service4(NPN_HTTP_2, "bar4", 1234); | 466 const AlternativeService alternative_service4(NPN_HTTP_2, "bar4", 1234); |
| 442 base::Time expiration4 = now + base::TimeDelta::FromDays(4); | 467 base::Time expiration4 = now + base::TimeDelta::FromDays(4); |
| 443 const AlternativeServiceInfo alternative_service_info2(alternative_service4, | 468 const AlternativeServiceInfo alternative_service_info2(alternative_service4, |
| 444 expiration4); | 469 expiration4); |
| 445 // Add an old entry from Preferences, this will be added to end of recency | 470 // Add an old entry from Preferences, this will be added to end of recency |
| 446 // list. | 471 // list. |
| 447 alternative_service_map.Put( | 472 alternative_service_map.Put( |
| 448 test_host_port_pair3, | 473 test_server3, |
| 449 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); | 474 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); |
| 450 | 475 |
| 451 // MRU list will be test_host_port_pair2, test_host_port_pair1, | 476 // MRU list will be test_server2, test_server1, test_server3. |
| 452 // test_host_port_pair3. | |
| 453 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 477 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
| 454 | 478 |
| 455 // Verify alternative_service_map. | 479 // Verify alternative_service_map. |
| 456 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 480 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 457 ASSERT_EQ(3u, map.size()); | 481 ASSERT_EQ(3u, map.size()); |
| 458 AlternativeServiceMap::const_iterator map_it = map.begin(); | 482 AlternativeServiceMap::const_iterator map_it = map.begin(); |
| 459 | 483 |
| 460 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair2)); | 484 EXPECT_TRUE(map_it->first.Equals(test_server2)); |
| 461 ASSERT_EQ(1u, map_it->second.size()); | 485 ASSERT_EQ(1u, map_it->second.size()); |
| 462 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service); | 486 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service); |
| 463 EXPECT_EQ(expiration3, map_it->second[0].expiration); | 487 EXPECT_EQ(expiration3, map_it->second[0].expiration); |
| 464 ++map_it; | 488 ++map_it; |
| 465 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair1)); | 489 EXPECT_TRUE(map_it->first.Equals(test_server1)); |
| 466 ASSERT_EQ(1u, map_it->second.size()); | 490 ASSERT_EQ(1u, map_it->second.size()); |
| 467 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); | 491 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); |
| 468 EXPECT_EQ(expiration1, map_it->second[0].expiration); | 492 EXPECT_EQ(expiration1, map_it->second[0].expiration); |
| 469 ++map_it; | 493 ++map_it; |
| 470 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair3)); | 494 EXPECT_TRUE(map_it->first.Equals(test_server3)); |
| 471 ASSERT_EQ(1u, map_it->second.size()); | 495 ASSERT_EQ(1u, map_it->second.size()); |
| 472 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service); | 496 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service); |
| 473 EXPECT_EQ(expiration4, map_it->second[0].expiration); | 497 EXPECT_EQ(expiration4, map_it->second[0].expiration); |
| 474 } | 498 } |
| 475 | 499 |
| 476 // Regression test for https://crbug.com/504032: | 500 // Regression test for https://crbug.com/504032: |
| 477 // InitializeAlternativeServiceServers() should not crash if there is an empty | 501 // InitializeAlternativeServiceServers() should not crash if there is an empty |
| 478 // hostname is the mapping. | 502 // hostname is the mapping. |
| 479 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) { | 503 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) { |
| 480 const HostPortPair host_port_pair("foo", 443); | 504 url::SchemeHostPort server("https", "foo", 443); |
| 481 const AlternativeService alternative_service_with_empty_hostname(NPN_HTTP_2, | 505 const AlternativeService alternative_service_with_empty_hostname(NPN_HTTP_2, |
| 482 "", 1234); | 506 "", 1234); |
| 483 const AlternativeService alternative_service_with_foo_hostname(NPN_HTTP_2, | 507 const AlternativeService alternative_service_with_foo_hostname(NPN_HTTP_2, |
| 484 "foo", 1234); | 508 "foo", 1234); |
| 485 SetAlternativeService(host_port_pair, | 509 SetAlternativeService(server, alternative_service_with_empty_hostname); |
| 486 alternative_service_with_empty_hostname); | |
| 487 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); | 510 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); |
| 488 | 511 |
| 489 AlternativeServiceMap alternative_service_map( | 512 AlternativeServiceMap alternative_service_map( |
| 490 AlternativeServiceMap::NO_AUTO_EVICT); | 513 AlternativeServiceMap::NO_AUTO_EVICT); |
| 491 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 514 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
| 492 | 515 |
| 493 EXPECT_TRUE( | 516 EXPECT_TRUE( |
| 494 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); | 517 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); |
| 495 const AlternativeServiceVector alternative_service_vector = | 518 const AlternativeServiceVector alternative_service_vector = |
| 496 impl_.GetAlternativeServices(host_port_pair); | 519 impl_.GetAlternativeServices(server); |
| 497 ASSERT_EQ(1u, alternative_service_vector.size()); | 520 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 498 EXPECT_EQ(alternative_service_with_foo_hostname, | 521 EXPECT_EQ(alternative_service_with_foo_hostname, |
| 499 alternative_service_vector[0]); | 522 alternative_service_vector[0]); |
| 500 } | 523 } |
| 501 | 524 |
| 502 // Regression test for https://crbug.com/516486: | 525 // Regression test for https://crbug.com/516486: |
| 503 // GetAlternativeServices() should remove |alternative_service_map_| elements | 526 // GetAlternativeServices() should remove |alternative_service_map_| elements |
| 504 // with empty value. | 527 // with empty value. |
| 505 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { | 528 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { |
| 506 HostPortPair host_port_pair("foo", 443); | 529 url::SchemeHostPort server("https", "foo", 443); |
| 507 const AlternativeService alternative_service(NPN_HTTP_2, "bar", 443); | 530 const AlternativeService alternative_service(NPN_HTTP_2, "bar", 443); |
| 508 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); | 531 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); |
| 509 const AlternativeServiceInfo alternative_service_info(alternative_service, | 532 const AlternativeServiceInfo alternative_service_info(alternative_service, |
| 510 expiration); | 533 expiration); |
| 511 AlternativeServiceMap alternative_service_map( | 534 AlternativeServiceMap alternative_service_map( |
| 512 AlternativeServiceMap::NO_AUTO_EVICT); | 535 AlternativeServiceMap::NO_AUTO_EVICT); |
| 513 alternative_service_map.Put( | 536 alternative_service_map.Put( |
| 514 host_port_pair, | 537 server, |
| 515 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 538 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
| 516 | 539 |
| 517 // Prepare |alternative_service_map_| with a single key that has a single | 540 // Prepare |alternative_service_map_| with a single key that has a single |
| 518 // AlternativeServiceInfo with identical hostname and port. | 541 // AlternativeServiceInfo with identical hostname and port. |
| 519 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 542 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
| 520 | 543 |
| 521 // GetAlternativeServices() should remove such AlternativeServiceInfo from | 544 // GetAlternativeServices() should remove such AlternativeServiceInfo from |
| 522 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector | 545 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector |
| 523 // corresponding to |host_port_pair|. | 546 // corresponding to |server|. |
| 524 AlternativeServiceVector alternative_service_vector = | 547 AlternativeServiceVector alternative_service_vector = |
| 525 impl_.GetAlternativeServices(host_port_pair); | 548 impl_.GetAlternativeServices(server); |
| 526 ASSERT_TRUE(alternative_service_vector.empty()); | 549 ASSERT_TRUE(alternative_service_vector.empty()); |
| 527 | 550 |
| 528 // GetAlternativeServices() should remove this key from | 551 // GetAlternativeServices() should remove this key from |
| 529 // |alternative_service_map_|, and SetAlternativeServices() should not crash. | 552 // |alternative_service_map_|, and SetAlternativeServices() should not crash. |
| 530 impl_.SetAlternativeServices( | 553 impl_.SetAlternativeServices( |
| 531 host_port_pair, | 554 server, |
| 532 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 555 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
| 533 | 556 |
| 534 // There should still be no alternative service assigned to |host_port_pair|. | 557 // There should still be no alternative service assigned to |server|. |
| 535 alternative_service_vector = impl_.GetAlternativeServices(host_port_pair); | 558 alternative_service_vector = impl_.GetAlternativeServices(server); |
| 536 ASSERT_TRUE(alternative_service_vector.empty()); | 559 ASSERT_TRUE(alternative_service_vector.empty()); |
| 537 } | 560 } |
| 538 | 561 |
| 539 // Regression test for https://crbug.com/516486 for the canonical host case. | 562 // Regression test for https://crbug.com/516486 for the canonical host case. |
| 540 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) { | 563 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) { |
| 541 HostPortPair host_port_pair("foo.c.youtube.com", 443); | 564 url::SchemeHostPort server("https", "foo.c.youtube.com", 443); |
| 542 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 443); | 565 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 543 const AlternativeService alternative_service(NPN_HTTP_2, "", 443); | 566 const AlternativeService alternative_service(NPN_HTTP_2, "", 443); |
| 544 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); | 567 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); |
| 545 const AlternativeServiceInfo alternative_service_info(alternative_service, | 568 const AlternativeServiceInfo alternative_service_info(alternative_service, |
| 546 expiration); | 569 expiration); |
| 547 AlternativeServiceMap alternative_service_map( | 570 AlternativeServiceMap alternative_service_map( |
| 548 AlternativeServiceMap::NO_AUTO_EVICT); | 571 AlternativeServiceMap::NO_AUTO_EVICT); |
| 549 alternative_service_map.Put( | 572 alternative_service_map.Put( |
| 550 canonical_host_port_pair, | 573 canonical_server, |
| 551 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 574 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
| 552 | 575 |
| 553 // Prepare |alternative_service_map_| with a single key that has a single | 576 // Prepare |alternative_service_map_| with a single key that has a single |
| 554 // AlternativeServiceInfo with identical hostname and port. | 577 // AlternativeServiceInfo with identical hostname and port. |
| 555 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 578 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
| 556 | 579 |
| 557 // GetAlternativeServices() should remove such AlternativeServiceInfo from | 580 // GetAlternativeServices() should remove such AlternativeServiceInfo from |
| 558 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector | 581 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector |
| 559 // corresponding to |canonical_host_port_pair|, even when looking up | 582 // corresponding to |canonical_server|, even when looking up |
| 560 // alternative services for |host_port_pair|. | 583 // alternative services for |server|. |
| 561 AlternativeServiceVector alternative_service_vector = | 584 AlternativeServiceVector alternative_service_vector = |
| 562 impl_.GetAlternativeServices(host_port_pair); | 585 impl_.GetAlternativeServices(server); |
| 563 ASSERT_TRUE(alternative_service_vector.empty()); | 586 ASSERT_TRUE(alternative_service_vector.empty()); |
| 564 | 587 |
| 565 // GetAlternativeServices() should remove this key from | 588 // GetAlternativeServices() should remove this key from |
| 566 // |alternative_service_map_|, and SetAlternativeServices() should not crash. | 589 // |alternative_service_map_|, and SetAlternativeServices() should not crash. |
| 567 impl_.SetAlternativeServices( | 590 impl_.SetAlternativeServices( |
| 568 canonical_host_port_pair, | 591 canonical_server, |
| 569 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 592 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
| 570 | 593 |
| 571 // There should still be no alternative service assigned to | 594 // There should still be no alternative service assigned to |
| 572 // |canonical_host_port_pair|. | 595 // |canonical_server|. |
| 573 alternative_service_vector = | 596 alternative_service_vector = impl_.GetAlternativeServices(canonical_server); |
| 574 impl_.GetAlternativeServices(canonical_host_port_pair); | |
| 575 ASSERT_TRUE(alternative_service_vector.empty()); | 597 ASSERT_TRUE(alternative_service_vector.empty()); |
| 576 } | 598 } |
| 577 | 599 |
| 578 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) { | 600 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) { |
| 579 HostPortPair test_host_port_pair1("foo1", 80); | 601 url::SchemeHostPort test_server1("http", "foo1", 80); |
| 580 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo1", 443); | 602 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo1", 443); |
| 581 SetAlternativeService(test_host_port_pair1, alternative_service1); | 603 SetAlternativeService(test_server1, alternative_service1); |
| 582 HostPortPair test_host_port_pair2("foo2", 80); | 604 url::SchemeHostPort test_server2("http", "foo2", 80); |
| 583 const AlternativeService alternative_service2(NPN_HTTP_2, "foo2", 1234); | 605 const AlternativeService alternative_service2(NPN_HTTP_2, "foo2", 1234); |
| 584 SetAlternativeService(test_host_port_pair2, alternative_service2); | 606 SetAlternativeService(test_server2, alternative_service2); |
| 585 | 607 |
| 586 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 608 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 587 AlternativeServiceMap::const_iterator it = map.begin(); | 609 AlternativeServiceMap::const_iterator it = map.begin(); |
| 588 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); | 610 EXPECT_TRUE(it->first.Equals(test_server2)); |
| 589 ASSERT_EQ(1u, it->second.size()); | 611 ASSERT_EQ(1u, it->second.size()); |
| 590 EXPECT_EQ(alternative_service2, it->second[0].alternative_service); | 612 EXPECT_EQ(alternative_service2, it->second[0].alternative_service); |
| 591 | 613 |
| 592 const AlternativeServiceVector alternative_service_vector = | 614 const AlternativeServiceVector alternative_service_vector = |
| 593 impl_.GetAlternativeServices(test_host_port_pair1); | 615 impl_.GetAlternativeServices(test_server1); |
| 594 ASSERT_EQ(1u, alternative_service_vector.size()); | 616 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 595 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 617 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 596 | 618 |
| 597 // GetAlternativeServices should reorder the AlternateProtocol map. | 619 // GetAlternativeServices should reorder the AlternateProtocol map. |
| 598 it = map.begin(); | 620 it = map.begin(); |
| 599 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); | 621 EXPECT_TRUE(it->first.Equals(test_server1)); |
| 600 ASSERT_EQ(1u, it->second.size()); | 622 ASSERT_EQ(1u, it->second.size()); |
| 601 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); | 623 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); |
| 602 } | 624 } |
| 603 | 625 |
| 604 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { | 626 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { |
| 605 HostPortPair test_host_port_pair("foo", 80); | 627 url::SchemeHostPort test_server("http", "foo", 80); |
| 606 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); | 628 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); |
| 607 SetAlternativeService(test_host_port_pair, alternative_service1); | 629 SetAlternativeService(test_server, alternative_service1); |
| 608 AlternativeServiceVector alternative_service_vector = | 630 AlternativeServiceVector alternative_service_vector = |
| 609 impl_.GetAlternativeServices(test_host_port_pair); | 631 impl_.GetAlternativeServices(test_server); |
| 610 ASSERT_EQ(1u, alternative_service_vector.size()); | 632 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 611 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 633 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 612 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 634 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
| 613 | 635 |
| 614 // GetAlternativeServices should return the broken alternative service. | 636 // GetAlternativeServices should return the broken alternative service. |
| 615 impl_.MarkAlternativeServiceBroken(alternative_service1); | 637 impl_.MarkAlternativeServiceBroken(alternative_service1); |
| 616 alternative_service_vector = | 638 alternative_service_vector = impl_.GetAlternativeServices(test_server); |
| 617 impl_.GetAlternativeServices(test_host_port_pair); | |
| 618 ASSERT_EQ(1u, alternative_service_vector.size()); | 639 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 619 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 640 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 620 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 641 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
| 621 | 642 |
| 622 // SetAlternativeServices should add a broken alternative service to the map. | 643 // SetAlternativeServices should add a broken alternative service to the map. |
| 623 AlternativeServiceInfoVector alternative_service_info_vector; | 644 AlternativeServiceInfoVector alternative_service_info_vector; |
| 624 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 645 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 625 alternative_service_info_vector.push_back( | 646 alternative_service_info_vector.push_back( |
| 626 AlternativeServiceInfo(alternative_service1, expiration)); | 647 AlternativeServiceInfo(alternative_service1, expiration)); |
| 627 const AlternativeService alternative_service2(NPN_HTTP_2, "foo", 1234); | 648 const AlternativeService alternative_service2(NPN_HTTP_2, "foo", 1234); |
| 628 alternative_service_info_vector.push_back( | 649 alternative_service_info_vector.push_back( |
| 629 AlternativeServiceInfo(alternative_service2, expiration)); | 650 AlternativeServiceInfo(alternative_service2, expiration)); |
| 630 impl_.SetAlternativeServices(test_host_port_pair, | 651 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 631 alternative_service_info_vector); | 652 alternative_service_vector = impl_.GetAlternativeServices(test_server); |
| 632 alternative_service_vector = | |
| 633 impl_.GetAlternativeServices(test_host_port_pair); | |
| 634 ASSERT_EQ(2u, alternative_service_vector.size()); | 653 ASSERT_EQ(2u, alternative_service_vector.size()); |
| 635 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 654 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 636 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); | 655 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); |
| 637 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); | 656 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); |
| 638 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service_vector[1])); | 657 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service_vector[1])); |
| 639 | 658 |
| 640 // SetAlternativeService should add a broken alternative service to the map. | 659 // SetAlternativeService should add a broken alternative service to the map. |
| 641 SetAlternativeService(test_host_port_pair, alternative_service1); | 660 SetAlternativeService(test_server, alternative_service1); |
| 642 alternative_service_vector = | 661 alternative_service_vector = impl_.GetAlternativeServices(test_server); |
| 643 impl_.GetAlternativeServices(test_host_port_pair); | |
| 644 ASSERT_EQ(1u, alternative_service_vector.size()); | 662 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 645 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 663 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 646 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); | 664 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); |
| 647 } | 665 } |
| 648 | 666 |
| 649 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { | 667 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { |
| 650 AlternativeServiceInfoVector alternative_service_info_vector; | 668 AlternativeServiceInfoVector alternative_service_info_vector; |
| 651 base::Time now = base::Time::Now(); | 669 base::Time now = base::Time::Now(); |
| 652 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 670 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
| 653 | 671 |
| 654 // First alternative service expired one day ago, should not be returned by | 672 // First alternative service expired one day ago, should not be returned by |
| 655 // GetAlternativeServices(). | 673 // GetAlternativeServices(). |
| 656 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 674 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
| 657 alternative_service_info_vector.push_back( | 675 alternative_service_info_vector.push_back( |
| 658 AlternativeServiceInfo(alternative_service1, now - one_day)); | 676 AlternativeServiceInfo(alternative_service1, now - one_day)); |
| 659 | 677 |
| 660 // Second alterrnative service will expire one day from now, should be | 678 // Second alterrnative service will expire one day from now, should be |
| 661 // returned by GetAlternativeSerices(). | 679 // returned by GetAlternativeSerices(). |
| 662 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 680 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 663 alternative_service_info_vector.push_back( | 681 alternative_service_info_vector.push_back( |
| 664 AlternativeServiceInfo(alternative_service2, now + one_day)); | 682 AlternativeServiceInfo(alternative_service2, now + one_day)); |
| 665 | 683 |
| 666 HostPortPair test_host_port_pair("foo", 80); | 684 url::SchemeHostPort test_server("http", "foo", 80); |
| 667 impl_.SetAlternativeServices(test_host_port_pair, | 685 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 668 alternative_service_info_vector); | |
| 669 | 686 |
| 670 AlternativeServiceVector alternative_service_vector = | 687 AlternativeServiceVector alternative_service_vector = |
| 671 impl_.GetAlternativeServices(test_host_port_pair); | 688 impl_.GetAlternativeServices(test_server); |
| 672 ASSERT_EQ(1u, alternative_service_vector.size()); | 689 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 673 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); | 690 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
| 674 } | 691 } |
| 675 | 692 |
| 676 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { | 693 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { |
| 677 AlternativeServiceInfoVector alternative_service_info_vector; | 694 AlternativeServiceInfoVector alternative_service_info_vector; |
| 678 base::Time now = base::Time::Now(); | 695 base::Time now = base::Time::Now(); |
| 679 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 696 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
| 680 | 697 |
| 681 // First alternative service expired one day ago, should not be returned by | 698 // First alternative service expired one day ago, should not be returned by |
| 682 // GetAlternativeServices(). | 699 // GetAlternativeServices(). |
| 683 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 700 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
| 684 alternative_service_info_vector.push_back( | 701 alternative_service_info_vector.push_back( |
| 685 AlternativeServiceInfo(alternative_service1, now - one_day)); | 702 AlternativeServiceInfo(alternative_service1, now - one_day)); |
| 686 | 703 |
| 687 // Second alterrnative service will expire one day from now, should be | 704 // Second alterrnative service will expire one day from now, should be |
| 688 // returned by GetAlternativeSerices(). | 705 // returned by GetAlternativeSerices(). |
| 689 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 706 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 690 alternative_service_info_vector.push_back( | 707 alternative_service_info_vector.push_back( |
| 691 AlternativeServiceInfo(alternative_service2, now + one_day)); | 708 AlternativeServiceInfo(alternative_service2, now + one_day)); |
| 692 | 709 |
| 693 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 710 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 694 impl_.SetAlternativeServices(canonical_host_port_pair, | 711 impl_.SetAlternativeServices(canonical_server, |
| 695 alternative_service_info_vector); | 712 alternative_service_info_vector); |
| 696 | 713 |
| 697 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 714 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 698 AlternativeServiceVector alternative_service_vector = | 715 AlternativeServiceVector alternative_service_vector = |
| 699 impl_.GetAlternativeServices(test_host_port_pair); | 716 impl_.GetAlternativeServices(test_server); |
| 700 ASSERT_EQ(1u, alternative_service_vector.size()); | 717 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 701 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); | 718 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
| 702 } | 719 } |
| 703 | 720 |
| 721 TEST_F(AlternateProtocolServerPropertiesTest, AlternativeServiceWithScheme) { |
| 722 AlternativeServiceInfoVector alternative_service_info_vector; |
| 723 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
| 724 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 725 alternative_service_info_vector.push_back( |
| 726 AlternativeServiceInfo(alternative_service1, expiration)); |
| 727 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 728 alternative_service_info_vector.push_back( |
| 729 AlternativeServiceInfo(alternative_service2, expiration)); |
| 730 // Set Alt-Svc list for |http_server|. |
| 731 url::SchemeHostPort http_server("http", "foo", 80); |
| 732 impl_.SetAlternativeServices(http_server, alternative_service_info_vector); |
| 733 |
| 734 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 735 net::AlternativeServiceMap::const_iterator it = map.begin(); |
| 736 EXPECT_TRUE(it->first.Equals(http_server)); |
| 737 ASSERT_EQ(2u, it->second.size()); |
| 738 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); |
| 739 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); |
| 740 |
| 741 // Check Alt-Svc list should not be set for |https_server|. |
| 742 url::SchemeHostPort https_server("https", "foo", 80); |
| 743 EXPECT_EQ(0u, impl_.GetAlternativeServices(https_server).size()); |
| 744 |
| 745 // Set Alt-Svc list for |https_server|. |
| 746 impl_.SetAlternativeServices(https_server, alternative_service_info_vector); |
| 747 EXPECT_EQ(2u, impl_.GetAlternativeServices(https_server).size()); |
| 748 EXPECT_EQ(2u, impl_.GetAlternativeServices(http_server).size()); |
| 749 |
| 750 // Clear Alt-Svc list for |http_server|. |
| 751 impl_.ClearAlternativeServices(http_server); |
| 752 EXPECT_EQ(0u, impl_.GetAlternativeServices(http_server).size()); |
| 753 EXPECT_EQ(2u, impl_.GetAlternativeServices(https_server).size()); |
| 754 } |
| 755 |
| 704 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) { | 756 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) { |
| 705 AlternativeServiceInfoVector alternative_service_info_vector; | 757 AlternativeServiceInfoVector alternative_service_info_vector; |
| 706 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 758 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
| 707 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 759 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 708 alternative_service_info_vector.push_back( | 760 alternative_service_info_vector.push_back( |
| 709 AlternativeServiceInfo(alternative_service1, expiration)); | 761 AlternativeServiceInfo(alternative_service1, expiration)); |
| 710 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 762 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 711 alternative_service_info_vector.push_back( | 763 alternative_service_info_vector.push_back( |
| 712 AlternativeServiceInfo(alternative_service2, expiration)); | 764 AlternativeServiceInfo(alternative_service2, expiration)); |
| 713 HostPortPair test_host_port_pair("foo", 80); | 765 url::SchemeHostPort test_server("http", "foo", 80); |
| 714 impl_.SetAlternativeServices(test_host_port_pair, | 766 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 715 alternative_service_info_vector); | |
| 716 | 767 |
| 717 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); | 768 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 718 net::AlternativeServiceMap::const_iterator it = map.begin(); | 769 net::AlternativeServiceMap::const_iterator it = map.begin(); |
| 719 EXPECT_TRUE(it->first.Equals(test_host_port_pair)); | 770 EXPECT_TRUE(it->first.Equals(test_server)); |
| 720 ASSERT_EQ(2u, it->second.size()); | 771 ASSERT_EQ(2u, it->second.size()); |
| 721 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); | 772 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); |
| 722 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); | 773 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); |
| 723 | 774 |
| 724 impl_.ClearAlternativeServices(test_host_port_pair); | 775 impl_.ClearAlternativeServices(test_server); |
| 725 EXPECT_TRUE(map.empty()); | 776 EXPECT_TRUE(map.empty()); |
| 726 } | 777 } |
| 727 | 778 |
| 728 // A broken alternative service in the mapping carries meaningful information, | 779 // A broken alternative service in the mapping carries meaningful information, |
| 729 // therefore it should not be ignored by SetAlternativeService(). In | 780 // therefore it should not be ignored by SetAlternativeService(). In |
| 730 // particular, an alternative service mapped to an origin shadows alternative | 781 // particular, an alternative service mapped to an origin shadows alternative |
| 731 // services of canonical hosts. | 782 // services of canonical hosts. |
| 732 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) { | 783 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) { |
| 733 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 784 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 734 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 785 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 735 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 786 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 736 1234); | 787 1234); |
| 737 SetAlternativeService(canonical_host_port_pair, | 788 SetAlternativeService(canonical_server, canonical_alternative_service); |
| 738 canonical_alternative_service); | |
| 739 AlternativeServiceVector alternative_service_vector = | 789 AlternativeServiceVector alternative_service_vector = |
| 740 impl_.GetAlternativeServices(test_host_port_pair); | 790 impl_.GetAlternativeServices(test_server); |
| 741 ASSERT_EQ(1u, alternative_service_vector.size()); | 791 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 742 EXPECT_EQ(canonical_alternative_service, alternative_service_vector[0]); | 792 EXPECT_EQ(canonical_alternative_service, alternative_service_vector[0]); |
| 743 | 793 |
| 744 const AlternativeService broken_alternative_service(NPN_HTTP_2, "foo", 443); | 794 const AlternativeService broken_alternative_service(NPN_HTTP_2, "foo", 443); |
| 745 impl_.MarkAlternativeServiceBroken(broken_alternative_service); | 795 impl_.MarkAlternativeServiceBroken(broken_alternative_service); |
| 746 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); | 796 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); |
| 747 | 797 |
| 748 SetAlternativeService(test_host_port_pair, broken_alternative_service); | 798 SetAlternativeService(test_server, broken_alternative_service); |
| 749 alternative_service_vector = | 799 alternative_service_vector = impl_.GetAlternativeServices(test_server); |
| 750 impl_.GetAlternativeServices(test_host_port_pair); | |
| 751 ASSERT_EQ(1u, alternative_service_vector.size()); | 800 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 752 EXPECT_EQ(broken_alternative_service, alternative_service_vector[0]); | 801 EXPECT_EQ(broken_alternative_service, alternative_service_vector[0]); |
| 753 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); | 802 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); |
| 754 } | 803 } |
| 755 | 804 |
| 756 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { | 805 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { |
| 757 HostPortPair test_host_port_pair("foo", 80); | 806 url::SchemeHostPort test_server("http", "foo", 80); |
| 758 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); | 807 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
| 759 SetAlternativeService(test_host_port_pair, alternative_service); | 808 SetAlternativeService(test_server, alternative_service); |
| 760 impl_.MarkAlternativeServiceBroken(alternative_service); | 809 impl_.MarkAlternativeServiceBroken(alternative_service); |
| 761 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); | 810 ASSERT_TRUE(HasAlternativeService(test_server)); |
| 762 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 811 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 763 // ClearAlternativeServices should leave a broken alternative service marked | 812 // ClearAlternativeServices should leave a broken alternative service marked |
| 764 // as such. | 813 // as such. |
| 765 impl_.ClearAlternativeServices(test_host_port_pair); | 814 impl_.ClearAlternativeServices(test_server); |
| 766 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 815 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 767 } | 816 } |
| 768 | 817 |
| 769 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) { | 818 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) { |
| 770 HostPortPair host_port_pair("foo", 80); | 819 url::SchemeHostPort server("http", "foo", 80); |
| 771 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); | 820 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
| 772 SetAlternativeService(host_port_pair, alternative_service); | 821 SetAlternativeService(server, alternative_service); |
| 773 | 822 |
| 774 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 823 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 775 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 824 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 776 | 825 |
| 777 impl_.MarkAlternativeServiceRecentlyBroken(alternative_service); | 826 impl_.MarkAlternativeServiceRecentlyBroken(alternative_service); |
| 778 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 827 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 779 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 828 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 780 | 829 |
| 781 impl_.ConfirmAlternativeService(alternative_service); | 830 impl_.ConfirmAlternativeService(alternative_service); |
| 782 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 831 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 783 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 832 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 784 } | 833 } |
| 785 | 834 |
| 786 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { | 835 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { |
| 787 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 836 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 788 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 837 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 789 | 838 |
| 790 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 839 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 791 EXPECT_FALSE(HasAlternativeService(canonical_host_port_pair)); | 840 EXPECT_FALSE(HasAlternativeService(canonical_server)); |
| 792 | 841 |
| 793 AlternativeServiceInfoVector alternative_service_info_vector; | 842 AlternativeServiceInfoVector alternative_service_info_vector; |
| 794 const AlternativeService canonical_alternative_service1( | 843 const AlternativeService canonical_alternative_service1( |
| 795 QUIC, "bar.c.youtube.com", 1234); | 844 QUIC, "bar.c.youtube.com", 1234); |
| 796 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 845 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 797 alternative_service_info_vector.push_back( | 846 alternative_service_info_vector.push_back( |
| 798 AlternativeServiceInfo(canonical_alternative_service1, expiration)); | 847 AlternativeServiceInfo(canonical_alternative_service1, expiration)); |
| 799 const AlternativeService canonical_alternative_service2(NPN_HTTP_2, "", 443); | 848 const AlternativeService canonical_alternative_service2(NPN_HTTP_2, "", 443); |
| 800 alternative_service_info_vector.push_back( | 849 alternative_service_info_vector.push_back( |
| 801 AlternativeServiceInfo(canonical_alternative_service2, expiration)); | 850 AlternativeServiceInfo(canonical_alternative_service2, expiration)); |
| 802 impl_.SetAlternativeServices(canonical_host_port_pair, | 851 impl_.SetAlternativeServices(canonical_server, |
| 803 alternative_service_info_vector); | 852 alternative_service_info_vector); |
| 804 | 853 |
| 805 // Since |test_host_port_pair| does not have an alternative service itself, | 854 // Since |test_server| does not have an alternative service itself, |
| 806 // GetAlternativeServices should return those of |canonical_host_port_pair|. | 855 // GetAlternativeServices should return those of |canonical_server|. |
| 807 AlternativeServiceVector alternative_service_vector = | 856 AlternativeServiceVector alternative_service_vector = |
| 808 impl_.GetAlternativeServices(test_host_port_pair); | 857 impl_.GetAlternativeServices(test_server); |
| 809 ASSERT_EQ(2u, alternative_service_vector.size()); | 858 ASSERT_EQ(2u, alternative_service_vector.size()); |
| 810 EXPECT_EQ(canonical_alternative_service1, alternative_service_vector[0]); | 859 EXPECT_EQ(canonical_alternative_service1, alternative_service_vector[0]); |
| 811 | 860 |
| 812 // Since |canonical_alternative_service2| has an empty host, | 861 // Since |canonical_alternative_service2| has an empty host, |
| 813 // GetAlternativeServices should substitute the hostname of its |origin| | 862 // GetAlternativeServices should substitute the hostname of its |origin| |
| 814 // argument. | 863 // argument. |
| 815 EXPECT_EQ(test_host_port_pair.host(), alternative_service_vector[1].host); | 864 EXPECT_EQ(test_server.host(), alternative_service_vector[1].host); |
| 816 EXPECT_EQ(canonical_alternative_service2.protocol, | 865 EXPECT_EQ(canonical_alternative_service2.protocol, |
| 817 alternative_service_vector[1].protocol); | 866 alternative_service_vector[1].protocol); |
| 818 EXPECT_EQ(canonical_alternative_service2.port, | 867 EXPECT_EQ(canonical_alternative_service2.port, |
| 819 alternative_service_vector[1].port); | 868 alternative_service_vector[1].port); |
| 820 | 869 |
| 821 // Verify the canonical suffix. | 870 // Verify the canonical suffix. |
| 871 EXPECT_EQ(".c.youtube.com", impl_.GetCanonicalSuffix(test_server.host())); |
| 822 EXPECT_EQ(".c.youtube.com", | 872 EXPECT_EQ(".c.youtube.com", |
| 823 impl_.GetCanonicalSuffix(test_host_port_pair.host())); | 873 impl_.GetCanonicalSuffix(canonical_server.host())); |
| 824 EXPECT_EQ(".c.youtube.com", | |
| 825 impl_.GetCanonicalSuffix(canonical_host_port_pair.host())); | |
| 826 } | 874 } |
| 827 | 875 |
| 828 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { | 876 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { |
| 829 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 877 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 830 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 878 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 831 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 879 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 832 1234); | 880 1234); |
| 833 | 881 |
| 834 SetAlternativeService(canonical_host_port_pair, | 882 SetAlternativeService(canonical_server, canonical_alternative_service); |
| 835 canonical_alternative_service); | 883 impl_.ClearAlternativeServices(canonical_server); |
| 836 impl_.ClearAlternativeServices(canonical_host_port_pair); | 884 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 837 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | |
| 838 } | 885 } |
| 839 | 886 |
| 840 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { | 887 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { |
| 841 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 888 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 842 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 889 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 843 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 890 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 844 1234); | 891 1234); |
| 845 | 892 |
| 846 SetAlternativeService(canonical_host_port_pair, | 893 SetAlternativeService(canonical_server, canonical_alternative_service); |
| 847 canonical_alternative_service); | |
| 848 impl_.MarkAlternativeServiceBroken(canonical_alternative_service); | 894 impl_.MarkAlternativeServiceBroken(canonical_alternative_service); |
| 849 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 895 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 850 } | 896 } |
| 851 | 897 |
| 852 // Adding an alternative service for a new host overrides canonical host. | 898 // Adding an alternative service for a new host overrides canonical host. |
| 853 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) { | 899 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) { |
| 854 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 900 url::SchemeHostPort foo_server("https", "foo.c.youtube.com", 443); |
| 855 HostPortPair bar_host_port_pair("bar.c.youtube.com", 80); | 901 url::SchemeHostPort bar_server("https", "bar.c.youtube.com", 443); |
| 856 AlternativeService bar_alternative_service(QUIC, "bar.c.youtube.com", 1234); | 902 AlternativeService bar_alternative_service(QUIC, "bar.c.youtube.com", 1234); |
| 857 SetAlternativeService(bar_host_port_pair, bar_alternative_service); | 903 SetAlternativeService(bar_server, bar_alternative_service); |
| 858 AlternativeServiceVector alternative_service_vector = | 904 AlternativeServiceVector alternative_service_vector = |
| 859 impl_.GetAlternativeServices(test_host_port_pair); | 905 impl_.GetAlternativeServices(foo_server); |
| 860 ASSERT_EQ(1u, alternative_service_vector.size()); | 906 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 861 EXPECT_EQ(bar_alternative_service, alternative_service_vector[0]); | 907 EXPECT_EQ(bar_alternative_service, alternative_service_vector[0]); |
| 862 | 908 |
| 863 HostPortPair qux_host_port_pair("qux.c.youtube.com", 80); | 909 url::SchemeHostPort qux_server("https", "qux.c.youtube.com", 443); |
| 864 AlternativeService qux_alternative_service(QUIC, "qux.c.youtube.com", 443); | 910 AlternativeService qux_alternative_service(QUIC, "qux.c.youtube.com", 443); |
| 865 SetAlternativeService(qux_host_port_pair, qux_alternative_service); | 911 SetAlternativeService(qux_server, qux_alternative_service); |
| 866 alternative_service_vector = | 912 alternative_service_vector = impl_.GetAlternativeServices(foo_server); |
| 867 impl_.GetAlternativeServices(test_host_port_pair); | |
| 868 ASSERT_EQ(1u, alternative_service_vector.size()); | 913 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 869 EXPECT_EQ(qux_alternative_service, alternative_service_vector[0]); | 914 EXPECT_EQ(qux_alternative_service, alternative_service_vector[0]); |
| 870 } | 915 } |
| 871 | 916 |
| 872 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { | 917 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { |
| 873 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 918 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 874 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 919 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 875 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 920 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 876 1234); | 921 1234); |
| 877 | 922 |
| 878 SetAlternativeService(canonical_host_port_pair, | 923 SetAlternativeService(canonical_server, canonical_alternative_service); |
| 879 canonical_alternative_service); | |
| 880 impl_.Clear(); | 924 impl_.Clear(); |
| 881 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 925 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 882 } | 926 } |
| 883 | 927 |
| 884 TEST_F(AlternateProtocolServerPropertiesTest, | 928 TEST_F(AlternateProtocolServerPropertiesTest, |
| 885 ExpireBrokenAlternateProtocolMappings) { | 929 ExpireBrokenAlternateProtocolMappings) { |
| 886 HostPortPair host_port_pair("foo", 443); | 930 url::SchemeHostPort server("https", "foo", 443); |
| 887 AlternativeService alternative_service(QUIC, "foo", 443); | 931 AlternativeService alternative_service(QUIC, "foo", 443); |
| 888 SetAlternativeService(host_port_pair, alternative_service); | 932 SetAlternativeService(server, alternative_service); |
| 889 EXPECT_TRUE(HasAlternativeService(host_port_pair)); | 933 EXPECT_TRUE(HasAlternativeService(server)); |
| 890 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 934 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 891 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 935 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 892 | 936 |
| 893 base::TimeTicks past = | 937 base::TimeTicks past = |
| 894 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); | 938 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); |
| 895 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( | 939 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( |
| 896 impl_, alternative_service, past); | 940 impl_, alternative_service, past); |
| 897 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 941 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 898 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 942 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 899 | 943 |
| 900 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); | 944 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); |
| 901 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 945 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 902 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 946 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
| 903 } | 947 } |
| 904 | 948 |
| 905 // Regression test for https://crbug.com/505413. | 949 // Regression test for https://crbug.com/505413. |
| 906 TEST_F(AlternateProtocolServerPropertiesTest, RemoveExpiredBrokenAltSvc) { | 950 TEST_F(AlternateProtocolServerPropertiesTest, RemoveExpiredBrokenAltSvc) { |
| 907 HostPortPair foo_host_port_pair("foo", 443); | 951 url::SchemeHostPort foo_server("https", "foo", 443); |
| 908 AlternativeService bar_alternative_service(QUIC, "bar", 443); | 952 AlternativeService bar_alternative_service(QUIC, "bar", 443); |
| 909 SetAlternativeService(foo_host_port_pair, bar_alternative_service); | 953 SetAlternativeService(foo_server, bar_alternative_service); |
| 910 EXPECT_TRUE(HasAlternativeService(foo_host_port_pair)); | 954 EXPECT_TRUE(HasAlternativeService(foo_server)); |
| 911 | 955 |
| 912 HostPortPair bar_host_port_pair1("bar", 80); | 956 url::SchemeHostPort bar_server1("http", "bar", 80); |
| 913 AlternativeService nohost_alternative_service(QUIC, "", 443); | 957 AlternativeService nohost_alternative_service(QUIC, "", 443); |
| 914 SetAlternativeService(bar_host_port_pair1, nohost_alternative_service); | 958 SetAlternativeService(bar_server1, nohost_alternative_service); |
| 915 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair1)); | 959 EXPECT_TRUE(HasAlternativeService(bar_server1)); |
| 916 | 960 |
| 917 HostPortPair bar_host_port_pair2("bar", 443); | 961 url::SchemeHostPort bar_server2("https", "bar", 443); |
| 918 AlternativeService baz_alternative_service(QUIC, "baz", 1234); | 962 AlternativeService baz_alternative_service(QUIC, "baz", 1234); |
| 919 SetAlternativeService(bar_host_port_pair2, baz_alternative_service); | 963 SetAlternativeService(bar_server2, baz_alternative_service); |
| 920 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair2)); | 964 EXPECT_TRUE(HasAlternativeService(bar_server2)); |
| 921 | 965 |
| 922 // Mark "bar:443" as broken. | 966 // Mark "bar:443" as broken. |
| 923 base::TimeTicks past = | 967 base::TimeTicks past = |
| 924 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); | 968 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); |
| 925 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( | 969 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( |
| 926 impl_, bar_alternative_service, past); | 970 impl_, bar_alternative_service, past); |
| 927 | 971 |
| 928 // Expire brokenness of "bar:443". | 972 // Expire brokenness of "bar:443". |
| 929 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); | 973 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); |
| 930 | 974 |
| 931 // "foo:443" should have no alternative service now. | 975 // "foo:443" should have no alternative service now. |
| 932 EXPECT_FALSE(HasAlternativeService(foo_host_port_pair)); | 976 EXPECT_FALSE(HasAlternativeService(foo_server)); |
| 933 // "bar:80" should have no alternative service now. | 977 // "bar:80" should have no alternative service now. |
| 934 EXPECT_FALSE(HasAlternativeService(bar_host_port_pair1)); | 978 EXPECT_FALSE(HasAlternativeService(bar_server1)); |
| 935 // The alternative service of "bar:443" should be unaffected. | 979 // The alternative service of "bar:443" should be unaffected. |
| 936 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair2)); | 980 EXPECT_TRUE(HasAlternativeService(bar_server2)); |
| 937 | 981 |
| 938 EXPECT_TRUE( | 982 EXPECT_TRUE( |
| 939 impl_.WasAlternativeServiceRecentlyBroken(bar_alternative_service)); | 983 impl_.WasAlternativeServiceRecentlyBroken(bar_alternative_service)); |
| 940 EXPECT_FALSE( | 984 EXPECT_FALSE( |
| 941 impl_.WasAlternativeServiceRecentlyBroken(baz_alternative_service)); | 985 impl_.WasAlternativeServiceRecentlyBroken(baz_alternative_service)); |
| 942 } | 986 } |
| 943 | 987 |
| 944 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; | 988 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; |
| 945 | 989 |
| 946 TEST_F(SpdySettingsServerPropertiesTest, Initialize) { | 990 TEST_F(SpdySettingsServerPropertiesTest, Initialize) { |
| 947 HostPortPair spdy_server_google("www.google.com", 443); | 991 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 948 HostPortPair spdy_server_photos("photos.google.com", 443); | 992 url::SchemeHostPort spdy_server_photos("https", "photos.google.com", 443); |
| 949 HostPortPair spdy_server_docs("docs.google.com", 443); | 993 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
| 950 HostPortPair spdy_server_mail("mail.google.com", 443); | 994 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 951 | 995 |
| 952 // Check by initializing empty spdy settings. | 996 // Check by initializing empty spdy settings. |
| 953 SpdySettingsMap spdy_settings_map(SpdySettingsMap::NO_AUTO_EVICT); | 997 SpdySettingsMap spdy_settings_map(SpdySettingsMap::NO_AUTO_EVICT); |
| 954 impl_.InitializeSpdySettingsServers(&spdy_settings_map); | 998 impl_.InitializeSpdySettingsServers(&spdy_settings_map); |
| 955 EXPECT_TRUE(impl_.GetSpdySettings(spdy_server_google).empty()); | 999 EXPECT_TRUE(impl_.GetSpdySettings(spdy_server_google).empty()); |
| 956 | 1000 |
| 957 // Check by initializing spdy server settings for www.google.com:443 and | 1001 // Check by initializing spdy server settings for www.google.com:443 and |
| 958 // photos.google.com:443. | 1002 // photos.google.com:443. |
| 959 const SpdySettingsDataToVerify data_to_verify1[] = { | 1003 const SpdySettingsDataToVerify data_to_verify1[] = { |
| 960 {spdy_server_google, 10000}, {spdy_server_photos, 20000}, | 1004 {spdy_server_google, 10000}, {spdy_server_photos, 20000}, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 data_to_verify3[3].spdy_server, | 1046 data_to_verify3[3].spdy_server, |
| 1003 data_to_verify3[3].value); | 1047 data_to_verify3[3].value); |
| 1004 InitializeSpdySettingsUploadBandwidth(&spdy_settings_map3, | 1048 InitializeSpdySettingsUploadBandwidth(&spdy_settings_map3, |
| 1005 data_to_verify3[1].spdy_server, | 1049 data_to_verify3[1].spdy_server, |
| 1006 data_to_verify3[1].value); | 1050 data_to_verify3[1].value); |
| 1007 impl_.InitializeSpdySettingsServers(&spdy_settings_map3); | 1051 impl_.InitializeSpdySettingsServers(&spdy_settings_map3); |
| 1008 VerifySpdySettingsUploadBandwidth(data_to_verify3); | 1052 VerifySpdySettingsUploadBandwidth(data_to_verify3); |
| 1009 } | 1053 } |
| 1010 | 1054 |
| 1011 TEST_F(SpdySettingsServerPropertiesTest, SetSpdySetting) { | 1055 TEST_F(SpdySettingsServerPropertiesTest, SetSpdySetting) { |
| 1012 HostPortPair spdy_server_empty(std::string(), 443); | 1056 url::SchemeHostPort spdy_server_empty("https", std::string(), 443); |
| 1013 const SettingsMap& settings_map0 = impl_.GetSpdySettings(spdy_server_empty); | 1057 const SettingsMap& settings_map0 = impl_.GetSpdySettings(spdy_server_empty); |
| 1014 EXPECT_EQ(0U, settings_map0.size()); // Returns kEmptySettingsMap. | 1058 EXPECT_EQ(0U, settings_map0.size()); // Returns kEmptySettingsMap. |
| 1015 | 1059 |
| 1016 // Add www.google.com:443 as persisting. | 1060 // Add www.google.com:443 as persisting. |
| 1017 HostPortPair spdy_server_google("www.google.com", 443); | 1061 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 1018 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 1062 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 1019 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 1063 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 1020 const uint32_t value1 = 31337; | 1064 const uint32_t value1 = 31337; |
| 1021 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_google, id1, flags1, value1)); | 1065 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_google, id1, flags1, value1)); |
| 1022 // Check the values. | 1066 // Check the values. |
| 1023 const SettingsMap& settings_map1_ret = | 1067 const SettingsMap& settings_map1_ret = |
| 1024 impl_.GetSpdySettings(spdy_server_google); | 1068 impl_.GetSpdySettings(spdy_server_google); |
| 1025 ASSERT_EQ(1U, settings_map1_ret.size()); | 1069 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 1026 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 1070 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 1027 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 1071 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 1028 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 1072 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 1029 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 1073 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 1030 EXPECT_EQ(value1, flags_and_value1_ret.second); | 1074 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 1031 | 1075 |
| 1032 // Add mail.google.com:443 as not persisting. | 1076 // Add mail.google.com:443 as not persisting. |
| 1033 HostPortPair spdy_server_mail("mail.google.com", 443); | 1077 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 1034 const SpdySettingsIds id2 = SETTINGS_DOWNLOAD_BANDWIDTH; | 1078 const SpdySettingsIds id2 = SETTINGS_DOWNLOAD_BANDWIDTH; |
| 1035 const SpdySettingsFlags flags2 = SETTINGS_FLAG_NONE; | 1079 const SpdySettingsFlags flags2 = SETTINGS_FLAG_NONE; |
| 1036 const uint32_t value2 = 62667; | 1080 const uint32_t value2 = 62667; |
| 1037 EXPECT_FALSE(impl_.SetSpdySetting(spdy_server_mail, id2, flags2, value2)); | 1081 EXPECT_FALSE(impl_.SetSpdySetting(spdy_server_mail, id2, flags2, value2)); |
| 1038 const SettingsMap& settings_map2_ret = | 1082 const SettingsMap& settings_map2_ret = |
| 1039 impl_.GetSpdySettings(spdy_server_mail); | 1083 impl_.GetSpdySettings(spdy_server_mail); |
| 1040 EXPECT_EQ(0U, settings_map2_ret.size()); // Returns kEmptySettingsMap. | 1084 EXPECT_EQ(0U, settings_map2_ret.size()); // Returns kEmptySettingsMap. |
| 1041 | 1085 |
| 1042 // Add docs.google.com:443 as persisting | 1086 // Add docs.google.com:443 as persisting |
| 1043 HostPortPair spdy_server_docs("docs.google.com", 443); | 1087 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
| 1044 const SpdySettingsIds id3 = SETTINGS_ROUND_TRIP_TIME; | 1088 const SpdySettingsIds id3 = SETTINGS_ROUND_TRIP_TIME; |
| 1045 const SpdySettingsFlags flags3 = SETTINGS_FLAG_PLEASE_PERSIST; | 1089 const SpdySettingsFlags flags3 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 1046 const uint32_t value3 = 93997; | 1090 const uint32_t value3 = 93997; |
| 1047 SettingsFlagsAndValue flags_and_value3(flags3, value3); | 1091 SettingsFlagsAndValue flags_and_value3(flags3, value3); |
| 1048 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_docs, id3, flags3, value3)); | 1092 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_docs, id3, flags3, value3)); |
| 1049 // Check the values. | 1093 // Check the values. |
| 1050 const SettingsMap& settings_map3_ret = | 1094 const SettingsMap& settings_map3_ret = |
| 1051 impl_.GetSpdySettings(spdy_server_docs); | 1095 impl_.GetSpdySettings(spdy_server_docs); |
| 1052 ASSERT_EQ(1U, settings_map3_ret.size()); | 1096 ASSERT_EQ(1U, settings_map3_ret.size()); |
| 1053 SettingsMap::const_iterator it3_ret = settings_map3_ret.find(id3); | 1097 SettingsMap::const_iterator it3_ret = settings_map3_ret.find(id3); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1072 const SettingsMap& settings_map5_ret = | 1116 const SettingsMap& settings_map5_ret = |
| 1073 impl_.GetSpdySettings(spdy_server_google); | 1117 impl_.GetSpdySettings(spdy_server_google); |
| 1074 ASSERT_EQ(0U, settings_map5_ret.size()); | 1118 ASSERT_EQ(0U, settings_map5_ret.size()); |
| 1075 | 1119 |
| 1076 // Clear all settings. | 1120 // Clear all settings. |
| 1077 ASSERT_GT(impl_.spdy_settings_map().size(), 0U); | 1121 ASSERT_GT(impl_.spdy_settings_map().size(), 0U); |
| 1078 impl_.ClearAllSpdySettings(); | 1122 impl_.ClearAllSpdySettings(); |
| 1079 ASSERT_EQ(0U, impl_.spdy_settings_map().size()); | 1123 ASSERT_EQ(0U, impl_.spdy_settings_map().size()); |
| 1080 } | 1124 } |
| 1081 | 1125 |
| 1126 TEST_F(SpdySettingsServerPropertiesTest, SpdySettingWithSchemeHostPort) { |
| 1127 // Test SpdySettingMap is correctly maintained with setting and |
| 1128 // clearing method. |
| 1129 // Add https://www.google.com:443 as persisting. |
| 1130 url::SchemeHostPort https_www_server("https", "www.google.com", 443); |
| 1131 url::SchemeHostPort http_www_server("http", "www.google.com", 443); |
| 1132 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 1133 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 1134 const uint32_t value1 = 31337; |
| 1135 EXPECT_TRUE(impl_.SetSpdySetting(https_www_server, id1, flags1, value1)); |
| 1136 // Check the values. |
| 1137 const SettingsMap& settings_map1_ret = |
| 1138 impl_.GetSpdySettings(https_www_server); |
| 1139 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 1140 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 1141 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 1142 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 1143 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 1144 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 1145 // Check the values is not set for http server. |
| 1146 const SettingsMap& settings_map1_ret2 = |
| 1147 impl_.GetSpdySettings(http_www_server); |
| 1148 ASSERT_EQ(0U, settings_map1_ret2.size()); |
| 1149 |
| 1150 // Add http://www.google.com:443 as persisting |
| 1151 const SpdySettingsIds id2 = SETTINGS_ROUND_TRIP_TIME; |
| 1152 const SpdySettingsFlags flags2 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 1153 const uint32_t value2 = 93997; |
| 1154 SettingsFlagsAndValue flags_and_value2(flags2, value2); |
| 1155 EXPECT_TRUE(impl_.SetSpdySetting(http_www_server, id2, flags2, value2)); |
| 1156 // Check the values. |
| 1157 const SettingsMap& settings_map2_ret = impl_.GetSpdySettings(http_www_server); |
| 1158 ASSERT_EQ(1U, settings_map2_ret.size()); |
| 1159 SettingsMap::const_iterator it2_ret = settings_map2_ret.find(id2); |
| 1160 EXPECT_TRUE(it2_ret != settings_map2_ret.end()); |
| 1161 SettingsFlagsAndValue flags_and_value2_ret = it2_ret->second; |
| 1162 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2_ret.first); |
| 1163 EXPECT_EQ(value2, flags_and_value2_ret.second); |
| 1164 |
| 1165 // Clear https://www.google.com:443 as persisting. |
| 1166 impl_.ClearSpdySettings(https_www_server); |
| 1167 // Check the values. |
| 1168 const SettingsMap& settings_map3_ret = |
| 1169 impl_.GetSpdySettings(https_www_server); |
| 1170 ASSERT_EQ(0U, settings_map3_ret.size()); |
| 1171 // Check the setting is not cleared for http server. |
| 1172 const SettingsMap& settings_map3_ret2 = |
| 1173 impl_.GetSpdySettings(http_www_server); |
| 1174 ASSERT_EQ(1U, settings_map3_ret2.size()); |
| 1175 |
| 1176 // Clear all settings. |
| 1177 ASSERT_GT(impl_.spdy_settings_map().size(), 0U); |
| 1178 impl_.ClearAllSpdySettings(); |
| 1179 ASSERT_EQ(0U, impl_.spdy_settings_map().size()); |
| 1180 } |
| 1181 |
| 1082 TEST_F(SpdySettingsServerPropertiesTest, Clear) { | 1182 TEST_F(SpdySettingsServerPropertiesTest, Clear) { |
| 1083 // Add www.google.com:443 as persisting. | 1183 // Add www.google.com:443 as persisting. |
| 1084 HostPortPair spdy_server_google("www.google.com", 443); | 1184 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 1085 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 1185 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 1086 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 1186 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 1087 const uint32_t value1 = 31337; | 1187 const uint32_t value1 = 31337; |
| 1088 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_google, id1, flags1, value1)); | 1188 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_google, id1, flags1, value1)); |
| 1089 // Check the values. | 1189 // Check the values. |
| 1090 const SettingsMap& settings_map1_ret = | 1190 const SettingsMap& settings_map1_ret = |
| 1091 impl_.GetSpdySettings(spdy_server_google); | 1191 impl_.GetSpdySettings(spdy_server_google); |
| 1092 ASSERT_EQ(1U, settings_map1_ret.size()); | 1192 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 1093 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 1193 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 1094 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 1194 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 1095 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 1195 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 1096 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 1196 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 1097 EXPECT_EQ(value1, flags_and_value1_ret.second); | 1197 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 1098 | 1198 |
| 1099 // Add docs.google.com:443 as persisting | 1199 // Add docs.google.com:443 as persisting |
| 1100 HostPortPair spdy_server_docs("docs.google.com", 443); | 1200 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
| 1101 const SpdySettingsIds id3 = SETTINGS_ROUND_TRIP_TIME; | 1201 const SpdySettingsIds id3 = SETTINGS_ROUND_TRIP_TIME; |
| 1102 const SpdySettingsFlags flags3 = SETTINGS_FLAG_PLEASE_PERSIST; | 1202 const SpdySettingsFlags flags3 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 1103 const uint32_t value3 = 93997; | 1203 const uint32_t value3 = 93997; |
| 1104 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_docs, id3, flags3, value3)); | 1204 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_docs, id3, flags3, value3)); |
| 1105 // Check the values. | 1205 // Check the values. |
| 1106 const SettingsMap& settings_map3_ret = | 1206 const SettingsMap& settings_map3_ret = |
| 1107 impl_.GetSpdySettings(spdy_server_docs); | 1207 impl_.GetSpdySettings(spdy_server_docs); |
| 1108 ASSERT_EQ(1U, settings_map3_ret.size()); | 1208 ASSERT_EQ(1U, settings_map3_ret.size()); |
| 1109 SettingsMap::const_iterator it3_ret = settings_map3_ret.find(id3); | 1209 SettingsMap::const_iterator it3_ret = settings_map3_ret.find(id3); |
| 1110 EXPECT_TRUE(it3_ret != settings_map3_ret.end()); | 1210 EXPECT_TRUE(it3_ret != settings_map3_ret.end()); |
| 1111 SettingsFlagsAndValue flags_and_value3_ret = it3_ret->second; | 1211 SettingsFlagsAndValue flags_and_value3_ret = it3_ret->second; |
| 1112 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value3_ret.first); | 1212 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value3_ret.first); |
| 1113 EXPECT_EQ(value3, flags_and_value3_ret.second); | 1213 EXPECT_EQ(value3, flags_and_value3_ret.second); |
| 1114 | 1214 |
| 1115 impl_.Clear(); | 1215 impl_.Clear(); |
| 1116 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_google).size()); | 1216 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_google).size()); |
| 1117 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_docs).size()); | 1217 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_docs).size()); |
| 1118 } | 1218 } |
| 1119 | 1219 |
| 1120 TEST_F(SpdySettingsServerPropertiesTest, MRUOfGetSpdySettings) { | 1220 TEST_F(SpdySettingsServerPropertiesTest, MRUOfGetSpdySettings) { |
| 1121 // Add www.google.com:443 as persisting. | 1221 // Add www.google.com:443 as persisting. |
| 1122 HostPortPair spdy_server_google("www.google.com", 443); | 1222 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| 1123 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 1223 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 1124 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 1224 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 1125 const uint32_t value1 = 31337; | 1225 const uint32_t value1 = 31337; |
| 1126 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_google, id1, flags1, value1)); | 1226 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_google, id1, flags1, value1)); |
| 1127 | 1227 |
| 1128 // Add docs.google.com:443 as persisting | 1228 // Add docs.google.com:443 as persisting |
| 1129 HostPortPair spdy_server_docs("docs.google.com", 443); | 1229 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
| 1130 const SpdySettingsIds id2 = SETTINGS_ROUND_TRIP_TIME; | 1230 const SpdySettingsIds id2 = SETTINGS_ROUND_TRIP_TIME; |
| 1131 const SpdySettingsFlags flags2 = SETTINGS_FLAG_PLEASE_PERSIST; | 1231 const SpdySettingsFlags flags2 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 1132 const uint32_t value2 = 93997; | 1232 const uint32_t value2 = 93997; |
| 1133 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_docs, id2, flags2, value2)); | 1233 EXPECT_TRUE(impl_.SetSpdySetting(spdy_server_docs, id2, flags2, value2)); |
| 1134 | 1234 |
| 1135 // Verify the first element is docs.google.com:443. | 1235 // Verify the first element is docs.google.com:443. |
| 1136 const SpdySettingsMap& map = impl_.spdy_settings_map(); | 1236 const SpdySettingsMap& map = impl_.spdy_settings_map(); |
| 1137 SpdySettingsMap::const_iterator it = map.begin(); | 1237 SpdySettingsMap::const_iterator it = map.begin(); |
| 1138 EXPECT_TRUE(it->first.Equals(spdy_server_docs)); | 1238 EXPECT_TRUE(it->first.Equals(spdy_server_docs)); |
| 1139 const SettingsMap& settings_map2_ret = it->second; | 1239 const SettingsMap& settings_map2_ret = it->second; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 EXPECT_EQ(actual_address, address); | 1299 EXPECT_EQ(actual_address, address); |
| 1200 | 1300 |
| 1201 impl_.Clear(); | 1301 impl_.Clear(); |
| 1202 | 1302 |
| 1203 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); | 1303 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); |
| 1204 } | 1304 } |
| 1205 | 1305 |
| 1206 typedef HttpServerPropertiesImplTest ServerNetworkStatsServerPropertiesTest; | 1306 typedef HttpServerPropertiesImplTest ServerNetworkStatsServerPropertiesTest; |
| 1207 | 1307 |
| 1208 TEST_F(ServerNetworkStatsServerPropertiesTest, Initialize) { | 1308 TEST_F(ServerNetworkStatsServerPropertiesTest, Initialize) { |
| 1209 HostPortPair google_server("www.google.com", 443); | 1309 url::SchemeHostPort google_server("https", "www.google.com", 443); |
| 1210 | 1310 |
| 1211 // Check by initializing empty ServerNetworkStats. | 1311 // Check by initializing empty ServerNetworkStats. |
| 1212 ServerNetworkStatsMap init_server_network_stats_map( | 1312 ServerNetworkStatsMap init_server_network_stats_map( |
| 1213 ServerNetworkStatsMap::NO_AUTO_EVICT); | 1313 ServerNetworkStatsMap::NO_AUTO_EVICT); |
| 1214 impl_.InitializeServerNetworkStats(&init_server_network_stats_map); | 1314 impl_.InitializeServerNetworkStats(&init_server_network_stats_map); |
| 1215 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(google_server); | 1315 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(google_server); |
| 1216 EXPECT_EQ(NULL, stats); | 1316 EXPECT_EQ(NULL, stats); |
| 1217 | 1317 |
| 1218 // Check by initializing with www.google.com:443. | 1318 // Check by initializing with www.google.com:443. |
| 1219 ServerNetworkStats stats_google; | 1319 ServerNetworkStats stats_google; |
| 1220 stats_google.srtt = base::TimeDelta::FromMicroseconds(10); | 1320 stats_google.srtt = base::TimeDelta::FromMicroseconds(10); |
| 1221 stats_google.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100); | 1321 stats_google.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100); |
| 1222 init_server_network_stats_map.Put(google_server, stats_google); | 1322 init_server_network_stats_map.Put(google_server, stats_google); |
| 1223 impl_.InitializeServerNetworkStats(&init_server_network_stats_map); | 1323 impl_.InitializeServerNetworkStats(&init_server_network_stats_map); |
| 1224 | 1324 |
| 1225 // Verify data for www.google.com:443. | 1325 // Verify data for www.google.com:443. |
| 1226 ASSERT_EQ(1u, impl_.server_network_stats_map().size()); | 1326 ASSERT_EQ(1u, impl_.server_network_stats_map().size()); |
| 1227 EXPECT_EQ(stats_google, *(impl_.GetServerNetworkStats(google_server))); | 1327 EXPECT_EQ(stats_google, *(impl_.GetServerNetworkStats(google_server))); |
| 1228 | 1328 |
| 1229 // Test recency order and overwriting of data. | 1329 // Test recency order and overwriting of data. |
| 1230 // | 1330 // |
| 1231 // |docs_server| has a ServerNetworkStats, which will be overwritten by | 1331 // |docs_server| has a ServerNetworkStats, which will be overwritten by |
| 1232 // InitializeServerNetworkStats(), because |server_network_stats_map| has an | 1332 // InitializeServerNetworkStats(), because |server_network_stats_map| has an |
| 1233 // entry for |docs_server|. | 1333 // entry for |docs_server|. |
| 1234 HostPortPair docs_server("docs.google.com", 443); | 1334 url::SchemeHostPort docs_server("https", "docs.google.com", 443); |
| 1235 ServerNetworkStats stats_docs; | 1335 ServerNetworkStats stats_docs; |
| 1236 stats_docs.srtt = base::TimeDelta::FromMicroseconds(20); | 1336 stats_docs.srtt = base::TimeDelta::FromMicroseconds(20); |
| 1237 stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(200); | 1337 stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(200); |
| 1238 // Recency order will be |docs_server| and |google_server|. | 1338 // Recency order will be |docs_server| and |google_server|. |
| 1239 impl_.SetServerNetworkStats(docs_server, stats_docs); | 1339 impl_.SetServerNetworkStats(docs_server, stats_docs); |
| 1240 | 1340 |
| 1241 // Prepare |server_network_stats_map| to be loaded by | 1341 // Prepare |server_network_stats_map| to be loaded by |
| 1242 // InitializeServerNetworkStats(). | 1342 // InitializeServerNetworkStats(). |
| 1243 ServerNetworkStatsMap server_network_stats_map( | 1343 ServerNetworkStatsMap server_network_stats_map( |
| 1244 ServerNetworkStatsMap::NO_AUTO_EVICT); | 1344 ServerNetworkStatsMap::NO_AUTO_EVICT); |
| 1245 | 1345 |
| 1246 // Change the values for |docs_server|. | 1346 // Change the values for |docs_server|. |
| 1247 ServerNetworkStats new_stats_docs; | 1347 ServerNetworkStats new_stats_docs; |
| 1248 new_stats_docs.srtt = base::TimeDelta::FromMicroseconds(25); | 1348 new_stats_docs.srtt = base::TimeDelta::FromMicroseconds(25); |
| 1249 new_stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(250); | 1349 new_stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(250); |
| 1250 server_network_stats_map.Put(docs_server, new_stats_docs); | 1350 server_network_stats_map.Put(docs_server, new_stats_docs); |
| 1251 // Add data for mail.google.com:443. | 1351 // Add data for mail.google.com:443. |
| 1252 HostPortPair mail_server("mail.google.com", 443); | 1352 url::SchemeHostPort mail_server("https", "mail.google.com", 443); |
| 1253 ServerNetworkStats stats_mail; | 1353 ServerNetworkStats stats_mail; |
| 1254 stats_mail.srtt = base::TimeDelta::FromMicroseconds(30); | 1354 stats_mail.srtt = base::TimeDelta::FromMicroseconds(30); |
| 1255 stats_mail.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(300); | 1355 stats_mail.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(300); |
| 1256 server_network_stats_map.Put(mail_server, stats_mail); | 1356 server_network_stats_map.Put(mail_server, stats_mail); |
| 1257 | 1357 |
| 1258 // Recency order will be |docs_server|, |google_server| and |mail_server|. | 1358 // Recency order will be |docs_server|, |google_server| and |mail_server|. |
| 1259 impl_.InitializeServerNetworkStats(&server_network_stats_map); | 1359 impl_.InitializeServerNetworkStats(&server_network_stats_map); |
| 1260 | 1360 |
| 1261 const ServerNetworkStatsMap& map = impl_.server_network_stats_map(); | 1361 const ServerNetworkStatsMap& map = impl_.server_network_stats_map(); |
| 1262 ASSERT_EQ(3u, map.size()); | 1362 ASSERT_EQ(3u, map.size()); |
| 1263 ServerNetworkStatsMap::const_iterator map_it = map.begin(); | 1363 ServerNetworkStatsMap::const_iterator map_it = map.begin(); |
| 1264 | 1364 |
| 1265 EXPECT_TRUE(map_it->first.Equals(docs_server)); | 1365 EXPECT_TRUE(map_it->first.Equals(docs_server)); |
| 1266 EXPECT_EQ(new_stats_docs, map_it->second); | 1366 EXPECT_EQ(new_stats_docs, map_it->second); |
| 1267 ++map_it; | 1367 ++map_it; |
| 1268 EXPECT_TRUE(map_it->first.Equals(google_server)); | 1368 EXPECT_TRUE(map_it->first.Equals(google_server)); |
| 1269 EXPECT_EQ(stats_google, map_it->second); | 1369 EXPECT_EQ(stats_google, map_it->second); |
| 1270 ++map_it; | 1370 ++map_it; |
| 1271 EXPECT_TRUE(map_it->first.Equals(mail_server)); | 1371 EXPECT_TRUE(map_it->first.Equals(mail_server)); |
| 1272 EXPECT_EQ(stats_mail, map_it->second); | 1372 EXPECT_EQ(stats_mail, map_it->second); |
| 1273 } | 1373 } |
| 1274 | 1374 |
| 1275 TEST_F(ServerNetworkStatsServerPropertiesTest, SetServerNetworkStats) { | 1375 TEST_F(ServerNetworkStatsServerPropertiesTest, SetServerNetworkStats) { |
| 1276 HostPortPair foo_server("foo", 80); | 1376 url::SchemeHostPort foo_http_server("http", "foo", 443); |
| 1277 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(foo_server); | 1377 url::SchemeHostPort foo_https_server("https", "foo", 443); |
| 1278 EXPECT_EQ(NULL, stats); | 1378 EXPECT_EQ(NULL, impl_.GetServerNetworkStats(foo_http_server)); |
| 1379 EXPECT_EQ(NULL, impl_.GetServerNetworkStats(foo_https_server)); |
| 1279 | 1380 |
| 1280 ServerNetworkStats stats1; | 1381 ServerNetworkStats stats1; |
| 1281 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 1382 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 1282 stats1.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100); | 1383 stats1.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100); |
| 1283 impl_.SetServerNetworkStats(foo_server, stats1); | 1384 impl_.SetServerNetworkStats(foo_http_server, stats1); |
| 1284 | 1385 |
| 1285 const ServerNetworkStats* stats2 = impl_.GetServerNetworkStats(foo_server); | 1386 const ServerNetworkStats* stats2 = |
| 1387 impl_.GetServerNetworkStats(foo_http_server); |
| 1286 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 1388 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 1287 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); | 1389 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); |
| 1390 // Https server should have nothing set for server network stats. |
| 1391 EXPECT_EQ(NULL, impl_.GetServerNetworkStats(foo_https_server)); |
| 1288 | 1392 |
| 1289 impl_.Clear(); | 1393 impl_.Clear(); |
| 1290 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); | 1394 EXPECT_EQ(NULL, impl_.GetServerNetworkStats(foo_http_server)); |
| 1291 EXPECT_EQ(NULL, stats3); | 1395 EXPECT_EQ(NULL, impl_.GetServerNetworkStats(foo_https_server)); |
| 1292 } | 1396 } |
| 1293 | 1397 |
| 1294 typedef HttpServerPropertiesImplTest QuicServerInfoServerPropertiesTest; | 1398 typedef HttpServerPropertiesImplTest QuicServerInfoServerPropertiesTest; |
| 1295 | 1399 |
| 1296 TEST_F(QuicServerInfoServerPropertiesTest, Initialize) { | 1400 TEST_F(QuicServerInfoServerPropertiesTest, Initialize) { |
| 1297 HostPortPair google_server("www.google.com", 443); | 1401 HostPortPair google_server("www.google.com", 443); |
| 1298 QuicServerId google_quic_server_id(google_server, PRIVACY_MODE_ENABLED); | 1402 QuicServerId google_quic_server_id(google_server, PRIVACY_MODE_ENABLED); |
| 1299 | 1403 |
| 1300 EXPECT_EQ(QuicServerInfoMap::NO_AUTO_EVICT, | 1404 EXPECT_EQ(QuicServerInfoMap::NO_AUTO_EVICT, |
| 1301 impl_.quic_server_info_map().max_size()); | 1405 impl_.quic_server_info_map().max_size()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); | 1496 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); |
| 1393 | 1497 |
| 1394 impl_.Clear(); | 1498 impl_.Clear(); |
| 1395 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1499 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
| 1396 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); | 1500 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); |
| 1397 } | 1501 } |
| 1398 | 1502 |
| 1399 } // namespace | 1503 } // namespace |
| 1400 | 1504 |
| 1401 } // namespace net | 1505 } // namespace net |
| OLD | NEW |