| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_manager.h" | 5 #include "net/http/http_server_properties_manager.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 const base::Closure& completion)); | 136 const base::Closure& completion)); |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); | 139 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 } // namespace | 142 } // namespace |
| 143 | 143 |
| 144 // TODO(rtenneti): After we stop supporting version 3 and everyone has migrated | 144 // TODO(rtenneti): After we stop supporting version 3 and everyone has migrated |
| 145 // to version 4, delete the following code. | 145 // to version 4, delete the following code. |
| 146 static const int kHttpServerPropertiesVersions[] = {3, 4}; | 146 static const int kHttpServerPropertiesVersions[] = {3, 4, 5}; |
| 147 | 147 |
| 148 class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> { | 148 class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> { |
| 149 protected: | 149 protected: |
| 150 HttpServerPropertiesManagerTest() {} | 150 HttpServerPropertiesManagerTest() {} |
| 151 | 151 |
| 152 void SetUp() override { | 152 void SetUp() override { |
| 153 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1); | 153 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 154 pref_delegate_ = new MockPrefDelegate; | 154 pref_delegate_ = new MockPrefDelegate; |
| 155 http_server_props_manager_.reset( | 155 http_server_props_manager_.reset( |
| 156 new StrictMock<TestingHttpServerPropertiesManager>( | 156 new StrictMock<TestingHttpServerPropertiesManager>( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 199 |
| 200 void ExpectPrefsUpdateRepeatedly() { | 200 void ExpectPrefsUpdateRepeatedly() { |
| 201 EXPECT_CALL(*http_server_props_manager_, | 201 EXPECT_CALL(*http_server_props_manager_, |
| 202 UpdatePrefsFromCacheOnNetworkThread(_)) | 202 UpdatePrefsFromCacheOnNetworkThread(_)) |
| 203 .WillRepeatedly( | 203 .WillRepeatedly( |
| 204 Invoke(http_server_props_manager_.get(), | 204 Invoke(http_server_props_manager_.get(), |
| 205 &TestingHttpServerPropertiesManager:: | 205 &TestingHttpServerPropertiesManager:: |
| 206 UpdatePrefsFromCacheOnNetworkThreadConcrete)); | 206 UpdatePrefsFromCacheOnNetworkThreadConcrete)); |
| 207 } | 207 } |
| 208 | 208 |
| 209 bool HasAlternativeService(const HostPortPair& server) { | 209 bool HasAlternativeService(const url::SchemeHostPort& server) { |
| 210 const AlternativeServiceVector alternative_service_vector = | 210 const AlternativeServiceVector alternative_service_vector = |
| 211 http_server_props_manager_->GetAlternativeServices(server); | 211 http_server_props_manager_->GetAlternativeServices(server); |
| 212 return !alternative_service_vector.empty(); | 212 return !alternative_service_vector.empty(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 MockPrefDelegate* pref_delegate_; // Owned by HttpServerPropertiesManager. | 215 MockPrefDelegate* pref_delegate_; // Owned by HttpServerPropertiesManager. |
| 216 std::unique_ptr<TestingHttpServerPropertiesManager> | 216 std::unique_ptr<TestingHttpServerPropertiesManager> |
| 217 http_server_props_manager_; | 217 http_server_props_manager_; |
| 218 base::Time one_day_from_now_; | 218 base::Time one_day_from_now_; |
| 219 | 219 |
| 220 private: | 220 private: |
| 221 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); | 221 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 INSTANTIATE_TEST_CASE_P(Tests, | 224 INSTANTIATE_TEST_CASE_P(Tests, |
| 225 HttpServerPropertiesManagerTest, | 225 HttpServerPropertiesManagerTest, |
| 226 ::testing::ValuesIn(kHttpServerPropertiesVersions)); | 226 ::testing::ValuesIn(kHttpServerPropertiesVersions)); |
| 227 | 227 |
| 228 TEST_P(HttpServerPropertiesManagerTest, | 228 TEST_P(HttpServerPropertiesManagerTest, |
| 229 SingleUpdateForTwoSpdyServerPrefChanges) { | 229 SingleUpdateForTwoSpdyServerPrefChanges) { |
| 230 ExpectCacheUpdate(); | 230 ExpectCacheUpdate(); |
| 231 | 231 |
| 232 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set | 232 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set |
| 233 // it twice. Only expect a single cache update. | 233 // it twice. Only expect a single cache update. |
| 234 | 234 |
| 235 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 235 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 236 HostPortPair google_server("www.google.com", 80); | 236 url::SchemeHostPort google_server(GetParam() >= 5 ? "http" : "https", |
| 237 HostPortPair mail_server("mail.google.com", 80); | 237 "www.google.com", 80); |
| 238 url::SchemeHostPort mail_server(GetParam() >= 5 ? "http" : "https", |
| 239 "mail.google.com", 80); |
| 238 | 240 |
| 239 // Set supports_spdy for www.google.com:80. | 241 // Set supports_spdy for http://www.google.com:80. |
| 240 server_pref_dict->SetBoolean("supports_spdy", true); | 242 server_pref_dict->SetBoolean("supports_spdy", true); |
| 241 | 243 |
| 242 // Set up alternative_services for www.google.com:80. | 244 // Set up alternative_services for http://www.google.com:80. |
| 243 base::DictionaryValue* alternative_service_dict0 = new base::DictionaryValue; | 245 base::DictionaryValue* alternative_service_dict0 = new base::DictionaryValue; |
| 244 alternative_service_dict0->SetInteger("port", 443); | 246 alternative_service_dict0->SetInteger("port", 443); |
| 245 alternative_service_dict0->SetString("protocol_str", "npn-h2"); | 247 alternative_service_dict0->SetString("protocol_str", "npn-h2"); |
| 246 base::DictionaryValue* alternative_service_dict1 = new base::DictionaryValue; | 248 base::DictionaryValue* alternative_service_dict1 = new base::DictionaryValue; |
| 247 alternative_service_dict1->SetInteger("port", 1234); | 249 alternative_service_dict1->SetInteger("port", 1234); |
| 248 alternative_service_dict1->SetString("protocol_str", "quic"); | 250 alternative_service_dict1->SetString("protocol_str", "quic"); |
| 249 base::ListValue* alternative_service_list0 = new base::ListValue; | 251 base::ListValue* alternative_service_list0 = new base::ListValue; |
| 250 alternative_service_list0->Append(alternative_service_dict0); | 252 alternative_service_list0->Append(alternative_service_dict0); |
| 251 alternative_service_list0->Append(alternative_service_dict1); | 253 alternative_service_list0->Append(alternative_service_dict1); |
| 252 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 254 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 253 alternative_service_list0); | 255 alternative_service_list0); |
| 254 | 256 |
| 255 // Set up ServerNetworkStats for www.google.com:80. | 257 // Set up ServerNetworkStats for http://www.google.com:80. |
| 256 base::DictionaryValue* stats = new base::DictionaryValue; | 258 base::DictionaryValue* stats = new base::DictionaryValue; |
| 257 stats->SetInteger("srtt", 10); | 259 stats->SetInteger("srtt", 10); |
| 258 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 260 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
| 259 | 261 |
| 260 // Set the server preference for www.google.com:80. | 262 // Set the server preference for http://www.google.com:80. |
| 261 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 263 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 262 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 264 servers_dict->SetWithoutPathExpansion( |
| 265 GetParam() >= 5 ? "http://www.google.com" : "www.google.com:80", |
| 266 server_pref_dict); |
| 263 base::ListValue* servers_list = nullptr; | 267 base::ListValue* servers_list = nullptr; |
| 264 if (GetParam() == 4) { | 268 if (GetParam() >= 4) { |
| 265 servers_list = new base::ListValue; | 269 servers_list = new base::ListValue; |
| 266 // |servers_list| takes ownership of |servers_dict|. | 270 // |servers_list| takes ownership of |servers_dict|. |
| 267 servers_list->AppendIfNotPresent(servers_dict); | 271 servers_list->AppendIfNotPresent(servers_dict); |
| 268 servers_dict = new base::DictionaryValue; | 272 servers_dict = new base::DictionaryValue; |
| 269 } | 273 } |
| 270 | 274 |
| 271 // Set the preference for mail.google.com server. | 275 // Set the preference for mail.google.com server. |
| 272 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 276 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 273 | 277 |
| 274 // Set supports_spdy for mail.google.com:80 | 278 // Set supports_spdy for mail.google.com:80 |
| 275 server_pref_dict1->SetBoolean("supports_spdy", true); | 279 server_pref_dict1->SetBoolean("supports_spdy", true); |
| 276 | 280 |
| 277 // Set up alternative_services for mail.google.com:80. | 281 // Set up alternative_services for mail.google.com:80. |
| 278 base::DictionaryValue* alternative_service_dict2 = new base::DictionaryValue; | 282 base::DictionaryValue* alternative_service_dict2 = new base::DictionaryValue; |
| 279 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1"); | 283 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1"); |
| 280 alternative_service_dict2->SetInteger("port", 444); | 284 alternative_service_dict2->SetInteger("port", 444); |
| 281 base::ListValue* alternative_service_list1 = new base::ListValue; | 285 base::ListValue* alternative_service_list1 = new base::ListValue; |
| 282 alternative_service_list1->Append(alternative_service_dict2); | 286 alternative_service_list1->Append(alternative_service_dict2); |
| 283 server_pref_dict1->SetWithoutPathExpansion("alternative_service", | 287 server_pref_dict1->SetWithoutPathExpansion("alternative_service", |
| 284 alternative_service_list1); | 288 alternative_service_list1); |
| 285 | 289 |
| 286 // Set up ServerNetworkStats for mail.google.com:80 and it is the MRU server. | 290 // Set up ServerNetworkStats for http://mail.google.com:80 and it is the MRU |
| 291 // server. |
| 287 base::DictionaryValue* stats1 = new base::DictionaryValue; | 292 base::DictionaryValue* stats1 = new base::DictionaryValue; |
| 288 stats1->SetInteger("srtt", 20); | 293 stats1->SetInteger("srtt", 20); |
| 289 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); | 294 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); |
| 290 // Set the server preference for mail.google.com:80. | 295 // Set the server preference for http://mail.google.com:80. |
| 291 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 296 servers_dict->SetWithoutPathExpansion( |
| 292 server_pref_dict1); | 297 GetParam() >= 5 ? "http://mail.google.com" : "mail.google.com:80", |
| 298 server_pref_dict1); |
| 293 base::DictionaryValue http_server_properties_dict; | 299 base::DictionaryValue http_server_properties_dict; |
| 294 if (GetParam() == 4) { | 300 if (GetParam() >= 4) { |
| 295 // |servers_list| takes ownership of |servers_dict|. | 301 // |servers_list| takes ownership of |servers_dict|. |
| 296 servers_list->AppendIfNotPresent(servers_dict); | 302 servers_list->AppendIfNotPresent(servers_dict); |
| 297 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 303 if (GetParam() == 5) { |
| 304 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
| 305 } else { |
| 306 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 307 GetParam()); |
| 308 } |
| 298 http_server_properties_dict.SetWithoutPathExpansion("servers", | 309 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 299 servers_list); | 310 servers_list); |
| 300 } else { | 311 } else { |
| 301 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 312 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 302 GetParam()); | 313 GetParam()); |
| 303 http_server_properties_dict.SetWithoutPathExpansion("servers", | 314 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 304 servers_dict); | 315 servers_dict); |
| 305 } | 316 } |
| 306 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 317 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 307 supports_quic->SetBoolean("used_quic", true); | 318 supports_quic->SetBoolean("used_quic", true); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 pref_delegate_->SetPrefs(http_server_properties_dict); | 355 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 345 pref_delegate_->SetPrefs(http_server_properties_dict); | 356 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 346 | 357 |
| 347 base::RunLoop().RunUntilIdle(); | 358 base::RunLoop().RunUntilIdle(); |
| 348 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 359 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 349 | 360 |
| 350 // Verify SupportsSpdy. | 361 // Verify SupportsSpdy. |
| 351 EXPECT_TRUE( | 362 EXPECT_TRUE( |
| 352 http_server_props_manager_->SupportsRequestPriority(google_server)); | 363 http_server_props_manager_->SupportsRequestPriority(google_server)); |
| 353 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); | 364 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); |
| 354 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 365 HostPortPair foo_host_port_pair = |
| 355 HostPortPair::FromString("foo.google.com:1337"))); | 366 HostPortPair::FromString("foo.google.com:1337"); |
| 367 url::SchemeHostPort foo_server("http", foo_host_port_pair.host(), |
| 368 foo_host_port_pair.port()); |
| 369 |
| 370 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(foo_server)); |
| 356 | 371 |
| 357 // Verify alternative service. | 372 // Verify alternative service. |
| 358 if (GetParam() == 4) { | 373 if (GetParam() >= 4) { |
| 359 const AlternativeServiceMap& map = | 374 const AlternativeServiceMap& map = |
| 360 http_server_props_manager_->alternative_service_map(); | 375 http_server_props_manager_->alternative_service_map(); |
| 361 ASSERT_EQ(2u, map.size()); | 376 ASSERT_EQ(2u, map.size()); |
| 362 | 377 |
| 363 AlternativeServiceMap::const_iterator map_it = map.begin(); | 378 AlternativeServiceMap::const_iterator map_it = map.begin(); |
| 364 EXPECT_EQ("mail.google.com", map_it->first.host()); | 379 EXPECT_EQ("mail.google.com", map_it->first.host()); |
| 365 ASSERT_EQ(1u, map_it->second.size()); | 380 ASSERT_EQ(1u, map_it->second.size()); |
| 366 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol); | 381 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol); |
| 367 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 382 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
| 368 EXPECT_EQ(444, map_it->second[0].alternative_service.port); | 383 EXPECT_EQ(444, map_it->second[0].alternative_service.port); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 // Set up ServerNetworkStats for www.google.com:65536. | 465 // Set up ServerNetworkStats for www.google.com:65536. |
| 451 base::DictionaryValue* stats = new base::DictionaryValue; | 466 base::DictionaryValue* stats = new base::DictionaryValue; |
| 452 stats->SetInteger("srtt", 10); | 467 stats->SetInteger("srtt", 10); |
| 453 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 468 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
| 454 | 469 |
| 455 // Set the server preference for www.google.com:65536. | 470 // Set the server preference for www.google.com:65536. |
| 456 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 471 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 457 servers_dict->SetWithoutPathExpansion("www.google.com:65536", | 472 servers_dict->SetWithoutPathExpansion("www.google.com:65536", |
| 458 server_pref_dict); | 473 server_pref_dict); |
| 459 base::DictionaryValue http_server_properties_dict; | 474 base::DictionaryValue http_server_properties_dict; |
| 460 if (GetParam() == 4) { | 475 if (GetParam() >= 4) { |
| 461 base::ListValue* servers_list = new base::ListValue; | 476 base::ListValue* servers_list = new base::ListValue; |
| 462 // |servers_list| takes ownership of |servers_dict|. | 477 // |servers_list| takes ownership of |servers_dict|. |
| 463 servers_list->AppendIfNotPresent(servers_dict); | 478 servers_list->AppendIfNotPresent(servers_dict); |
| 464 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 479 if (GetParam() == 5) { |
| 480 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
| 481 } else { |
| 482 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 483 GetParam()); |
| 484 } |
| 465 http_server_properties_dict.SetWithoutPathExpansion("servers", | 485 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 466 servers_list); | 486 servers_list); |
| 467 } else { | 487 } else { |
| 468 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 488 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 469 GetParam()); | 489 GetParam()); |
| 470 http_server_properties_dict.SetWithoutPathExpansion("servers", | 490 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 471 servers_dict); | 491 servers_dict); |
| 472 } | 492 } |
| 473 | 493 |
| 474 // Set quic_server_info for www.google.com:65536. | 494 // Set quic_server_info for www.google.com:65536. |
| 475 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; | 495 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; |
| 476 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; | 496 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; |
| 477 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", | 497 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", |
| 478 "quic_server_info1"); | 498 "quic_server_info1"); |
| 479 quic_servers_dict->SetWithoutPathExpansion("http://mail.google.com:65536", | 499 quic_servers_dict->SetWithoutPathExpansion("http://mail.google.com:65536", |
| 480 quic_server_pref_dict1); | 500 quic_server_pref_dict1); |
| 481 | 501 |
| 482 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", | 502 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", |
| 483 quic_servers_dict); | 503 quic_servers_dict); |
| 484 | 504 |
| 485 // Set up the pref. | 505 // Set up the pref. |
| 486 pref_delegate_->SetPrefs(http_server_properties_dict); | 506 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 487 | 507 |
| 488 base::RunLoop().RunUntilIdle(); | 508 base::RunLoop().RunUntilIdle(); |
| 489 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 509 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 490 | 510 |
| 491 // Verify that nothing is set. | 511 // Verify that nothing is set. |
| 492 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 512 HostPortPair google_host_port_pair = |
| 493 HostPortPair::FromString("www.google.com:65536"))); | 513 HostPortPair::FromString("www.google.com:65536"); |
| 514 url::SchemeHostPort gooler_server("http", google_host_port_pair.host(), |
| 515 google_host_port_pair.port()); |
| 516 |
| 494 EXPECT_FALSE( | 517 EXPECT_FALSE( |
| 495 HasAlternativeService(HostPortPair::FromString("www.google.com:65536"))); | 518 http_server_props_manager_->SupportsRequestPriority(gooler_server)); |
| 519 EXPECT_FALSE(HasAlternativeService(gooler_server)); |
| 496 const ServerNetworkStats* stats1 = | 520 const ServerNetworkStats* stats1 = |
| 497 http_server_props_manager_->GetServerNetworkStats( | 521 http_server_props_manager_->GetServerNetworkStats(gooler_server); |
| 498 HostPortPair::FromString("www.google.com:65536")); | |
| 499 EXPECT_EQ(nullptr, stats1); | 522 EXPECT_EQ(nullptr, stats1); |
| 500 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); | 523 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); |
| 501 } | 524 } |
| 502 | 525 |
| 503 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 526 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
| 504 ExpectCacheUpdate(); | 527 ExpectCacheUpdate(); |
| 505 // The prefs are automaticalls updated in the case corruption is detected. | 528 // The prefs are automaticalls updated in the case corruption is detected. |
| 506 ExpectPrefsUpdate(); | 529 ExpectPrefsUpdate(); |
| 507 ExpectScheduleUpdatePrefsOnNetworkThread(); | 530 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 508 | 531 |
| 509 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 532 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 510 | 533 |
| 511 // Set supports_spdy for www.google.com:80. | 534 // Set supports_spdy for www.google.com:80. |
| 512 server_pref_dict->SetBoolean("supports_spdy", true); | 535 server_pref_dict->SetBoolean("supports_spdy", true); |
| 513 | 536 |
| 514 // Set up alternative_service for www.google.com:80. | 537 // Set up alternative_service for www.google.com:80. |
| 515 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; | 538 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
| 516 alternative_service_dict->SetString("protocol_str", "npn-h2"); | 539 alternative_service_dict->SetString("protocol_str", "npn-h2"); |
| 517 alternative_service_dict->SetInteger("port", 65536); | 540 alternative_service_dict->SetInteger("port", 65536); |
| 518 base::ListValue* alternative_service_list = new base::ListValue; | 541 base::ListValue* alternative_service_list = new base::ListValue; |
| 519 alternative_service_list->Append(alternative_service_dict); | 542 alternative_service_list->Append(alternative_service_dict); |
| 520 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 543 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 521 alternative_service_list); | 544 alternative_service_list); |
| 522 | 545 |
| 523 // Set the server preference for www.google.com:80. | 546 // Set the server preference for www.google.com:80. |
| 524 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 547 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 525 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 548 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
| 526 base::DictionaryValue http_server_properties_dict; | 549 base::DictionaryValue http_server_properties_dict; |
| 527 if (GetParam() == 4) { | 550 if (GetParam() >= 4) { |
| 528 base::ListValue* servers_list = new base::ListValue; | 551 base::ListValue* servers_list = new base::ListValue; |
| 529 // |servers_list| takes ownership of |servers_dict|. | 552 // |servers_list| takes ownership of |servers_dict|. |
| 530 servers_list->AppendIfNotPresent(servers_dict); | 553 servers_list->AppendIfNotPresent(servers_dict); |
| 531 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 554 if (GetParam() == 5) { |
| 555 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
| 556 } else { |
| 557 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 558 GetParam()); |
| 559 } |
| 532 http_server_properties_dict.SetWithoutPathExpansion("servers", | 560 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 533 servers_list); | 561 servers_list); |
| 534 } else { | 562 } else { |
| 535 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 563 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 536 GetParam()); | 564 GetParam()); |
| 537 http_server_properties_dict.SetWithoutPathExpansion("servers", | 565 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 538 servers_dict); | 566 servers_dict); |
| 539 } | 567 } |
| 540 | 568 |
| 541 // Set up the pref. | 569 // Set up the pref. |
| 542 pref_delegate_->SetPrefs(http_server_properties_dict); | 570 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 543 | 571 |
| 544 base::RunLoop().RunUntilIdle(); | 572 base::RunLoop().RunUntilIdle(); |
| 545 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 573 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 546 | 574 |
| 547 // Verify alternative service is not set. | 575 // Verify alternative service is not set. |
| 548 EXPECT_FALSE( | 576 EXPECT_FALSE( |
| 549 HasAlternativeService(HostPortPair::FromString("www.google.com:80"))); | 577 HasAlternativeService(url::SchemeHostPort("http", "www.google.com", 80))); |
| 550 } | 578 } |
| 551 | 579 |
| 552 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) { | 580 TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) { |
| 553 ExpectPrefsUpdate(); | 581 ExpectPrefsUpdate(); |
| 554 ExpectScheduleUpdatePrefsOnNetworkThread(); | 582 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 555 | 583 |
| 556 // Post an update task to the network thread. SetSupportsSpdy calls | 584 // Post an update task to the network thread. SetSupportsSpdy calls |
| 557 // ScheduleUpdatePrefsOnNetworkThread. | 585 // ScheduleUpdatePrefsOnNetworkThread. |
| 558 | 586 |
| 559 // Add mail.google.com:443 as a supporting spdy server. | 587 // Add mail.google.com:443 as a supporting spdy server. |
| 560 HostPortPair spdy_server_mail("mail.google.com", 443); | 588 url::SchemeHostPort spdy_server("https", "mail.google.com", 443); |
| 561 EXPECT_FALSE( | 589 EXPECT_FALSE( |
| 562 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 590 http_server_props_manager_->SupportsRequestPriority(spdy_server)); |
| 563 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 591 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); |
| 564 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 592 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 565 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 593 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); |
| 566 | 594 |
| 567 // Run the task. | 595 // Run the task. |
| 568 base::RunLoop().RunUntilIdle(); | 596 base::RunLoop().RunUntilIdle(); |
| 569 | 597 |
| 570 EXPECT_TRUE( | 598 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server)); |
| 571 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | |
| 572 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 599 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 573 } | 600 } |
| 574 | 601 |
| 575 TEST_P(HttpServerPropertiesManagerTest, SetSpdySetting) { | 602 TEST_P(HttpServerPropertiesManagerTest, SetSpdySetting) { |
| 576 ExpectPrefsUpdate(); | 603 ExpectPrefsUpdate(); |
| 577 ExpectScheduleUpdatePrefsOnNetworkThread(); | 604 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 578 | 605 |
| 579 // Add SpdySetting for mail.google.com:443. | 606 // Add SpdySetting for mail.google.com:443. |
| 580 HostPortPair spdy_server_mail("mail.google.com", 443); | 607 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 581 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 608 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 582 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 609 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 583 const uint32_t value1 = 31337; | 610 const uint32_t value1 = 31337; |
| 584 http_server_props_manager_->SetSpdySetting( | 611 http_server_props_manager_->SetSpdySetting( |
| 585 spdy_server_mail, id1, flags1, value1); | 612 spdy_server_mail, id1, flags1, value1); |
| 586 | 613 |
| 587 // Run the task. | 614 // Run the task. |
| 588 base::RunLoop().RunUntilIdle(); | 615 base::RunLoop().RunUntilIdle(); |
| 589 | 616 |
| 590 const SettingsMap& settings_map1_ret = | 617 const SettingsMap& settings_map1_ret = |
| 591 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 618 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 592 ASSERT_EQ(1U, settings_map1_ret.size()); | 619 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 593 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 620 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 594 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 621 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 595 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 622 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 596 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 623 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 597 EXPECT_EQ(value1, flags_and_value1_ret.second); | 624 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 598 | 625 |
| 599 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 626 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 600 } | 627 } |
| 601 | 628 |
| 602 TEST_P(HttpServerPropertiesManagerTest, ClearSpdySetting) { | 629 TEST_P(HttpServerPropertiesManagerTest, ClearSpdySetting) { |
| 603 ExpectPrefsUpdateRepeatedly(); | 630 ExpectPrefsUpdateRepeatedly(); |
| 604 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 631 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
| 605 | 632 |
| 606 // Add SpdySetting for mail.google.com:443. | 633 // Add SpdySetting for mail.google.com:443. |
| 607 HostPortPair spdy_server_mail("mail.google.com", 443); | 634 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 608 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 635 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 609 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 636 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 610 const uint32_t value1 = 31337; | 637 const uint32_t value1 = 31337; |
| 611 http_server_props_manager_->SetSpdySetting( | 638 http_server_props_manager_->SetSpdySetting( |
| 612 spdy_server_mail, id1, flags1, value1); | 639 spdy_server_mail, id1, flags1, value1); |
| 613 | 640 |
| 614 // Run the task. | 641 // Run the task. |
| 615 base::RunLoop().RunUntilIdle(); | 642 base::RunLoop().RunUntilIdle(); |
| 616 | 643 |
| 617 const SettingsMap& settings_map1_ret = | 644 const SettingsMap& settings_map1_ret = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 636 ASSERT_EQ(0U, settings_map2_ret.size()); | 663 ASSERT_EQ(0U, settings_map2_ret.size()); |
| 637 | 664 |
| 638 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 665 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 639 } | 666 } |
| 640 | 667 |
| 641 TEST_P(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { | 668 TEST_P(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { |
| 642 ExpectPrefsUpdateRepeatedly(); | 669 ExpectPrefsUpdateRepeatedly(); |
| 643 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 670 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
| 644 | 671 |
| 645 // Add SpdySetting for mail.google.com:443. | 672 // Add SpdySetting for mail.google.com:443. |
| 646 HostPortPair spdy_server_mail("mail.google.com", 443); | 673 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| 647 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 674 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 648 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 675 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 649 const uint32_t value1 = 31337; | 676 const uint32_t value1 = 31337; |
| 650 http_server_props_manager_->SetSpdySetting( | 677 http_server_props_manager_->SetSpdySetting( |
| 651 spdy_server_mail, id1, flags1, value1); | 678 spdy_server_mail, id1, flags1, value1); |
| 652 | 679 |
| 653 // Run the task. | 680 // Run the task. |
| 654 base::RunLoop().RunUntilIdle(); | 681 base::RunLoop().RunUntilIdle(); |
| 655 | 682 |
| 656 const SettingsMap& settings_map1_ret = | 683 const SettingsMap& settings_map1_ret = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 673 http_server_props_manager_->spdy_settings_map(); | 700 http_server_props_manager_->spdy_settings_map(); |
| 674 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); | 701 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); |
| 675 | 702 |
| 676 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 703 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 677 } | 704 } |
| 678 | 705 |
| 679 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) { | 706 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) { |
| 680 ExpectPrefsUpdate(); | 707 ExpectPrefsUpdate(); |
| 681 ExpectScheduleUpdatePrefsOnNetworkThread(); | 708 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 682 | 709 |
| 683 HostPortPair spdy_server_mail("mail.google.com", 80); | 710 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); |
| 684 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 711 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 685 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", | 712 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", |
| 686 443); | 713 443); |
| 687 http_server_props_manager_->SetAlternativeService( | 714 http_server_props_manager_->SetAlternativeService( |
| 688 spdy_server_mail, alternative_service, one_day_from_now_); | 715 spdy_server_mail, alternative_service, one_day_from_now_); |
| 689 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 716 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 690 http_server_props_manager_->SetAlternativeService( | 717 http_server_props_manager_->SetAlternativeService( |
| 691 spdy_server_mail, alternative_service, one_day_from_now_); | 718 spdy_server_mail, alternative_service, one_day_from_now_); |
| 692 | 719 |
| 693 // Run the task. | 720 // Run the task. |
| 694 base::RunLoop().RunUntilIdle(); | 721 base::RunLoop().RunUntilIdle(); |
| 695 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 722 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 696 | 723 |
| 697 AlternativeServiceVector alternative_service_vector = | 724 AlternativeServiceVector alternative_service_vector = |
| 698 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); | 725 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); |
| 699 ASSERT_EQ(1u, alternative_service_vector.size()); | 726 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 700 EXPECT_EQ(alternative_service, alternative_service_vector[0]); | 727 EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
| 701 } | 728 } |
| 702 | 729 |
| 703 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) { | 730 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) { |
| 704 ExpectPrefsUpdate(); | 731 ExpectPrefsUpdate(); |
| 705 ExpectScheduleUpdatePrefsOnNetworkThread(); | 732 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 706 | 733 |
| 707 HostPortPair spdy_server_mail("mail.google.com", 80); | 734 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); |
| 708 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 735 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 709 AlternativeServiceInfoVector alternative_service_info_vector; | 736 AlternativeServiceInfoVector alternative_service_info_vector; |
| 710 const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com", | 737 const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com", |
| 711 443); | 738 443); |
| 712 alternative_service_info_vector.push_back( | 739 alternative_service_info_vector.push_back( |
| 713 AlternativeServiceInfo(alternative_service1, one_day_from_now_)); | 740 AlternativeServiceInfo(alternative_service1, one_day_from_now_)); |
| 714 const AlternativeService alternative_service2(QUIC, "mail.google.com", 1234); | 741 const AlternativeService alternative_service2(QUIC, "mail.google.com", 1234); |
| 715 alternative_service_info_vector.push_back( | 742 alternative_service_info_vector.push_back( |
| 716 AlternativeServiceInfo(alternative_service2, one_day_from_now_)); | 743 AlternativeServiceInfo(alternative_service2, one_day_from_now_)); |
| 717 http_server_props_manager_->SetAlternativeServices( | 744 http_server_props_manager_->SetAlternativeServices( |
| 718 spdy_server_mail, alternative_service_info_vector); | 745 spdy_server_mail, alternative_service_info_vector); |
| 719 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 746 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 720 http_server_props_manager_->SetAlternativeServices( | 747 http_server_props_manager_->SetAlternativeServices( |
| 721 spdy_server_mail, alternative_service_info_vector); | 748 spdy_server_mail, alternative_service_info_vector); |
| 722 | 749 |
| 723 // Run the task. | 750 // Run the task. |
| 724 base::RunLoop().RunUntilIdle(); | 751 base::RunLoop().RunUntilIdle(); |
| 725 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 752 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 726 | 753 |
| 727 AlternativeServiceVector alternative_service_vector = | 754 AlternativeServiceVector alternative_service_vector = |
| 728 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); | 755 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); |
| 729 ASSERT_EQ(2u, alternative_service_vector.size()); | 756 ASSERT_EQ(2u, alternative_service_vector.size()); |
| 730 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 757 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
| 731 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); | 758 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); |
| 732 } | 759 } |
| 733 | 760 |
| 734 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) { | 761 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) { |
| 735 HostPortPair spdy_server_mail("mail.google.com", 80); | 762 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); |
| 736 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 763 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 737 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", | 764 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", |
| 738 443); | 765 443); |
| 739 http_server_props_manager_->SetAlternativeServices( | 766 http_server_props_manager_->SetAlternativeServices( |
| 740 spdy_server_mail, AlternativeServiceInfoVector()); | 767 spdy_server_mail, AlternativeServiceInfoVector()); |
| 741 // ExpectScheduleUpdatePrefsOnNetworkThread() should not be called. | 768 // ExpectScheduleUpdatePrefsOnNetworkThread() should not be called. |
| 742 | 769 |
| 743 // Run the task. | 770 // Run the task. |
| 744 base::RunLoop().RunUntilIdle(); | 771 base::RunLoop().RunUntilIdle(); |
| 745 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 772 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 746 | 773 |
| 747 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 774 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 748 } | 775 } |
| 749 | 776 |
| 750 TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) { | 777 TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) { |
| 751 ExpectPrefsUpdate(); | 778 ExpectPrefsUpdate(); |
| 752 ExpectScheduleUpdatePrefsOnNetworkThread(); | 779 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 753 | 780 |
| 754 HostPortPair spdy_server_mail("mail.google.com", 80); | 781 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); |
| 755 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 782 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 756 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); | 783 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); |
| 757 http_server_props_manager_->SetAlternativeService( | 784 http_server_props_manager_->SetAlternativeService( |
| 758 spdy_server_mail, alternative_service, one_day_from_now_); | 785 spdy_server_mail, alternative_service, one_day_from_now_); |
| 759 ExpectScheduleUpdatePrefsOnNetworkThread(); | 786 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 760 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); | 787 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); |
| 761 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 788 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 762 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); | 789 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); |
| 763 | 790 |
| 764 // Run the task. | 791 // Run the task. |
| 765 base::RunLoop().RunUntilIdle(); | 792 base::RunLoop().RunUntilIdle(); |
| 766 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 793 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 767 | 794 |
| 768 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 795 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 769 } | 796 } |
| 770 | 797 |
| 771 TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { | 798 TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { |
| 772 ExpectPrefsUpdate(); | 799 ExpectPrefsUpdate(); |
| 773 | 800 |
| 774 HostPortPair spdy_server_mail("mail.google.com", 80); | 801 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); |
| 775 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 802 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 776 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); | 803 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); |
| 777 | 804 |
| 778 ExpectScheduleUpdatePrefsOnNetworkThread(); | 805 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 779 http_server_props_manager_->SetAlternativeService( | 806 http_server_props_manager_->SetAlternativeService( |
| 780 spdy_server_mail, alternative_service, one_day_from_now_); | 807 spdy_server_mail, alternative_service, one_day_from_now_); |
| 781 | 808 |
| 782 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( | 809 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( |
| 783 alternative_service)); | 810 alternative_service)); |
| 784 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( | 811 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 858 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 832 | 859 |
| 833 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 860 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 834 EXPECT_EQ(actual_address, address); | 861 EXPECT_EQ(actual_address, address); |
| 835 } | 862 } |
| 836 | 863 |
| 837 TEST_P(HttpServerPropertiesManagerTest, ServerNetworkStats) { | 864 TEST_P(HttpServerPropertiesManagerTest, ServerNetworkStats) { |
| 838 ExpectPrefsUpdate(); | 865 ExpectPrefsUpdate(); |
| 839 ExpectScheduleUpdatePrefsOnNetworkThread(); | 866 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 840 | 867 |
| 841 HostPortPair mail_server("mail.google.com", 80); | 868 url::SchemeHostPort mail_server("http", "mail.google.com", 80); |
| 842 const ServerNetworkStats* stats = | 869 const ServerNetworkStats* stats = |
| 843 http_server_props_manager_->GetServerNetworkStats(mail_server); | 870 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 844 EXPECT_EQ(nullptr, stats); | 871 EXPECT_EQ(nullptr, stats); |
| 845 ServerNetworkStats stats1; | 872 ServerNetworkStats stats1; |
| 846 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 873 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 847 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); | 874 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); |
| 848 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 875 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 849 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); | 876 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); |
| 850 | 877 |
| 851 // Run the task. | 878 // Run the task. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 876 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 903 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 877 | 904 |
| 878 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( | 905 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( |
| 879 mail_quic_server_id)); | 906 mail_quic_server_id)); |
| 880 } | 907 } |
| 881 | 908 |
| 882 TEST_P(HttpServerPropertiesManagerTest, Clear) { | 909 TEST_P(HttpServerPropertiesManagerTest, Clear) { |
| 883 ExpectPrefsUpdate(); | 910 ExpectPrefsUpdate(); |
| 884 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 911 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
| 885 | 912 |
| 886 HostPortPair spdy_server_mail("mail.google.com", 443); | 913 url::SchemeHostPort spdy_server("https", "mail.google.com", 443); |
| 887 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 914 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); |
| 888 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); | 915 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); |
| 889 http_server_props_manager_->SetAlternativeService( | 916 http_server_props_manager_->SetAlternativeService( |
| 890 spdy_server_mail, alternative_service, one_day_from_now_); | 917 spdy_server, alternative_service, one_day_from_now_); |
| 891 IPAddress actual_address(127, 0, 0, 1); | 918 IPAddress actual_address(127, 0, 0, 1); |
| 892 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 919 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
| 893 ServerNetworkStats stats; | 920 ServerNetworkStats stats; |
| 894 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 921 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
| 895 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 922 http_server_props_manager_->SetServerNetworkStats(spdy_server, stats); |
| 896 | 923 |
| 897 QuicServerId mail_quic_server_id("mail.google.com", 80); | 924 QuicServerId mail_quic_server_id("mail.google.com", 80); |
| 898 std::string quic_server_info1("quic_server_info1"); | 925 std::string quic_server_info1("quic_server_info1"); |
| 899 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 926 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
| 900 quic_server_info1); | 927 quic_server_info1); |
| 901 | 928 |
| 902 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 929 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 903 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 930 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 904 const uint32_t value1 = 31337; | 931 const uint32_t value1 = 31337; |
| 905 http_server_props_manager_->SetSpdySetting(spdy_server_mail, id1, flags1, | 932 http_server_props_manager_->SetSpdySetting(spdy_server, id1, flags1, value1); |
| 906 value1); | |
| 907 | 933 |
| 908 // Run the task. | 934 // Run the task. |
| 909 base::RunLoop().RunUntilIdle(); | 935 base::RunLoop().RunUntilIdle(); |
| 910 | 936 |
| 911 EXPECT_TRUE( | 937 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server)); |
| 912 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 938 EXPECT_TRUE(HasAlternativeService(spdy_server)); |
| 913 EXPECT_TRUE(HasAlternativeService(spdy_server_mail)); | |
| 914 IPAddress address; | 939 IPAddress address; |
| 915 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 940 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 916 EXPECT_EQ(actual_address, address); | 941 EXPECT_EQ(actual_address, address); |
| 917 const ServerNetworkStats* stats1 = | 942 const ServerNetworkStats* stats1 = |
| 918 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 943 http_server_props_manager_->GetServerNetworkStats(spdy_server); |
| 919 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); | 944 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); |
| 920 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( | 945 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( |
| 921 mail_quic_server_id)); | 946 mail_quic_server_id)); |
| 922 | 947 |
| 923 // Check SPDY settings values. | 948 // Check SPDY settings values. |
| 924 const SettingsMap& settings_map1_ret = | 949 const SettingsMap& settings_map1_ret = |
| 925 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 950 http_server_props_manager_->GetSpdySettings(spdy_server); |
| 926 ASSERT_EQ(1U, settings_map1_ret.size()); | 951 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 927 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 952 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 928 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 953 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 929 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 954 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 930 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 955 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 931 EXPECT_EQ(value1, flags_and_value1_ret.second); | 956 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 932 | 957 |
| 933 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 958 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 934 | 959 |
| 935 ExpectPrefsUpdate(); | 960 ExpectPrefsUpdate(); |
| 936 | 961 |
| 937 // Clear http server data, time out if we do not get a completion callback. | 962 // Clear http server data, time out if we do not get a completion callback. |
| 938 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure()); | 963 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure()); |
| 939 base::RunLoop().Run(); | 964 base::RunLoop().Run(); |
| 940 | 965 |
| 941 EXPECT_FALSE( | 966 EXPECT_FALSE( |
| 942 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 967 http_server_props_manager_->SupportsRequestPriority(spdy_server)); |
| 943 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 968 EXPECT_FALSE(HasAlternativeService(spdy_server)); |
| 944 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); | 969 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 945 const ServerNetworkStats* stats2 = | 970 const ServerNetworkStats* stats2 = |
| 946 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 971 http_server_props_manager_->GetServerNetworkStats(spdy_server); |
| 947 EXPECT_EQ(nullptr, stats2); | 972 EXPECT_EQ(nullptr, stats2); |
| 948 EXPECT_EQ(nullptr, | 973 EXPECT_EQ(nullptr, |
| 949 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); | 974 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); |
| 950 | 975 |
| 951 const SettingsMap& settings_map2_ret = | 976 const SettingsMap& settings_map2_ret = |
| 952 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 977 http_server_props_manager_->GetSpdySettings(spdy_server); |
| 953 EXPECT_EQ(0U, settings_map2_ret.size()); | 978 EXPECT_EQ(0U, settings_map2_ret.size()); |
| 954 | 979 |
| 955 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 980 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 956 } | 981 } |
| 957 | 982 |
| 958 // https://crbug.com/444956: Add 200 alternative_service servers followed by | 983 // https://crbug.com/444956: Add 200 alternative_service servers followed by |
| 959 // supports_quic and verify we have read supports_quic from prefs. | 984 // supports_quic and verify we have read supports_quic from prefs. |
| 960 TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) { | 985 TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
| 961 ExpectCacheUpdate(); | 986 ExpectCacheUpdate(); |
| 962 | 987 |
| 963 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 988 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 964 base::ListValue* servers_list = nullptr; | 989 base::ListValue* servers_list = nullptr; |
| 965 if (GetParam() == 4) | 990 if (GetParam() >= 4) |
| 966 servers_list = new base::ListValue; | 991 servers_list = new base::ListValue; |
| 967 | 992 |
| 968 for (int i = 0; i < 200; ++i) { | 993 for (int i = 1; i <= 200; ++i) { |
| 969 // Set up alternative_service for www.google.com:i. | 994 // Set up alternative_service for www.google.com:i. |
| 970 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; | 995 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
| 971 alternative_service_dict->SetString("protocol_str", "quic"); | 996 alternative_service_dict->SetString("protocol_str", "quic"); |
| 972 alternative_service_dict->SetInteger("port", i); | 997 alternative_service_dict->SetInteger("port", i); |
| 973 base::ListValue* alternative_service_list = new base::ListValue; | 998 base::ListValue* alternative_service_list = new base::ListValue; |
| 974 alternative_service_list->Append(alternative_service_dict); | 999 alternative_service_list->Append(alternative_service_dict); |
| 975 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 1000 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 976 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 1001 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 977 alternative_service_list); | 1002 alternative_service_list); |
| 978 if (GetParam() == 4) { | 1003 if (GetParam() >= 5) { |
| 979 servers_dict->SetWithoutPathExpansion( | 1004 servers_dict->SetWithoutPathExpansion( |
| 980 StringPrintf("www.google.com:%d", i), server_pref_dict); | 1005 StringPrintf("http://www.google.com:%d", i), server_pref_dict); |
| 981 // |servers_list| takes ownership of |servers_dict|. | |
| 982 servers_list->AppendIfNotPresent(servers_dict); | |
| 983 servers_dict = new base::DictionaryValue; | |
| 984 } else { | 1006 } else { |
| 985 servers_dict->SetWithoutPathExpansion( | 1007 servers_dict->SetWithoutPathExpansion( |
| 986 StringPrintf("www.google.com:%d", i), server_pref_dict); | 1008 StringPrintf("www.google.com:%d", i), server_pref_dict); |
| 987 } | 1009 } |
| 1010 if (GetParam() >= 4) { |
| 1011 // |servers_list| takes ownership of |servers_dict|. |
| 1012 servers_list->AppendIfNotPresent(servers_dict); |
| 1013 servers_dict = new base::DictionaryValue; |
| 1014 } |
| 988 } | 1015 } |
| 989 | 1016 |
| 990 // Set the preference for mail.google.com server. | 1017 // Set the server preference for http://mail.google.com server. |
| 991 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 1018 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 992 | 1019 if (GetParam() >= 5) { |
| 993 // Set the server preference for mail.google.com:80. | 1020 servers_dict->SetWithoutPathExpansion("http://mail.google.com", |
| 994 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 1021 server_pref_dict1); |
| 995 server_pref_dict1); | 1022 } else { |
| 1023 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
| 1024 server_pref_dict1); |
| 1025 } |
| 996 base::DictionaryValue http_server_properties_dict; | 1026 base::DictionaryValue http_server_properties_dict; |
| 997 if (GetParam() == 4) { | 1027 if (GetParam() >= 4) { |
| 998 // |servers_list| takes ownership of |servers_dict|. | 1028 // |servers_list| takes ownership of |servers_dict|. |
| 999 servers_list->AppendIfNotPresent(servers_dict); | 1029 servers_list->AppendIfNotPresent(servers_dict); |
| 1000 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 1030 if (GetParam() == 5) { |
| 1031 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
| 1032 } else { |
| 1033 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 1034 GetParam()); |
| 1035 } |
| 1001 http_server_properties_dict.SetWithoutPathExpansion("servers", | 1036 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 1002 servers_list); | 1037 servers_list); |
| 1003 } else { | 1038 } else { |
| 1004 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 1039 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 1005 GetParam()); | 1040 GetParam()); |
| 1006 http_server_properties_dict.SetWithoutPathExpansion("servers", | 1041 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 1007 servers_dict); | 1042 servers_dict); |
| 1008 } | 1043 } |
| 1009 | 1044 |
| 1010 // Set up SupportsQuic for 127.0.0.1 | 1045 // Set up SupportsQuic for 127.0.0.1 |
| 1011 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 1046 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 1012 supports_quic->SetBoolean("used_quic", true); | 1047 supports_quic->SetBoolean("used_quic", true); |
| 1013 supports_quic->SetString("address", "127.0.0.1"); | 1048 supports_quic->SetString("address", "127.0.0.1"); |
| 1014 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", | 1049 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", |
| 1015 supports_quic); | 1050 supports_quic); |
| 1016 | 1051 |
| 1017 // Set up the pref. | 1052 // Set up the pref. |
| 1018 pref_delegate_->SetPrefs(http_server_properties_dict); | 1053 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 1019 | 1054 |
| 1020 base::RunLoop().RunUntilIdle(); | 1055 base::RunLoop().RunUntilIdle(); |
| 1021 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1056 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 1022 | 1057 |
| 1023 // Verify alternative service. | 1058 // Verify alternative service. |
| 1024 for (int i = 0; i < 200; ++i) { | 1059 for (int i = 1; i <= 200; ++i) { |
| 1025 std::string server = StringPrintf("www.google.com:%d", i); | 1060 GURL server_gurl; |
| 1061 if (GetParam() >= 5) { |
| 1062 server_gurl = GURL(StringPrintf("http://www.google.com:%d", i)); |
| 1063 } else { |
| 1064 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i)); |
| 1065 } |
| 1066 url::SchemeHostPort server(server_gurl); |
| 1026 AlternativeServiceVector alternative_service_vector = | 1067 AlternativeServiceVector alternative_service_vector = |
| 1027 http_server_props_manager_->GetAlternativeServices( | 1068 http_server_props_manager_->GetAlternativeServices(server); |
| 1028 HostPortPair::FromString(server)); | |
| 1029 ASSERT_EQ(1u, alternative_service_vector.size()); | 1069 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 1030 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); | 1070 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
| 1031 EXPECT_EQ(i, alternative_service_vector[0].port); | 1071 EXPECT_EQ(i, alternative_service_vector[0].port); |
| 1032 } | 1072 } |
| 1033 | 1073 |
| 1034 // Verify SupportsQuic. | 1074 // Verify SupportsQuic. |
| 1035 IPAddress address; | 1075 IPAddress address; |
| 1036 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 1076 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 1037 EXPECT_EQ("127.0.0.1", address.ToString()); | 1077 EXPECT_EQ("127.0.0.1", address.ToString()); |
| 1038 } | 1078 } |
| 1039 | 1079 |
| 1040 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { | 1080 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { |
| 1041 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 1081 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
| 1042 | 1082 |
| 1043 const HostPortPair server_www("www.google.com", 80); | 1083 const url::SchemeHostPort server_www("http", "www.google.com", 80); |
| 1044 const HostPortPair server_mail("mail.google.com", 80); | 1084 const url::SchemeHostPort server_mail("http", "mail.google.com", 80); |
| 1045 | 1085 |
| 1046 // Set alternate protocol. | 1086 // Set alternate protocol. |
| 1047 AlternativeServiceInfoVector alternative_service_info_vector; | 1087 AlternativeServiceInfoVector alternative_service_info_vector; |
| 1048 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); | 1088 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); |
| 1049 base::Time expiration1; | 1089 base::Time expiration1; |
| 1050 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); | 1090 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); |
| 1051 alternative_service_info_vector.push_back( | 1091 alternative_service_info_vector.push_back( |
| 1052 AlternativeServiceInfo(www_alternative_service1, expiration1)); | 1092 AlternativeServiceInfo(www_alternative_service1, expiration1)); |
| 1053 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", | 1093 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", |
| 1054 1234); | 1094 1234); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1084 ExpectPrefsUpdate(); | 1124 ExpectPrefsUpdate(); |
| 1085 ExpectCacheUpdate(); | 1125 ExpectCacheUpdate(); |
| 1086 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 1126 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 1087 base::RunLoop().RunUntilIdle(); | 1127 base::RunLoop().RunUntilIdle(); |
| 1088 | 1128 |
| 1089 // Verify preferences. | 1129 // Verify preferences. |
| 1090 const char expected_json[] = | 1130 const char expected_json[] = |
| 1091 "{\"quic_servers\":{\"https://" | 1131 "{\"quic_servers\":{\"https://" |
| 1092 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," | 1132 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," |
| 1093 "\"servers\":[" | 1133 "\"servers\":[" |
| 1094 "{\"www.google.com:80\":{" | 1134 "{\"http://www.google.com\":{" |
| 1095 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," | 1135 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," |
| 1096 "\"port\":443,\"protocol_str\":\"npn-h2\"}," | 1136 "\"port\":443,\"protocol_str\":\"npn-h2\"}," |
| 1097 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\"," | 1137 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\"," |
| 1098 "\"port\":1234,\"protocol_str\":\"npn-h2\"}]}}," | 1138 "\"port\":1234,\"protocol_str\":\"npn-h2\"}]}}," |
| 1099 "{\"mail.google.com:80\":{\"alternative_service\":[{" | 1139 "{\"http://mail.google.com\":{\"alternative_service\":[{" |
| 1100 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," | 1140 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," |
| 1101 "\"port\":444,\"protocol_str\":\"npn-spdy/3.1\"}]," | 1141 "\"port\":444,\"protocol_str\":\"npn-spdy/3.1\"}]," |
| 1102 "\"network_stats\":{\"srtt\":42}}}" | 1142 "\"network_stats\":{\"srtt\":42}}}" |
| 1103 "]," | 1143 "]," |
| 1104 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," | 1144 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," |
| 1105 "\"version\":4}"; | 1145 "\"version\":5}"; |
| 1106 | 1146 |
| 1107 const base::Value* http_server_properties = | 1147 const base::Value* http_server_properties = |
| 1108 &pref_delegate_->GetServerProperties(); | 1148 &pref_delegate_->GetServerProperties(); |
| 1109 std::string preferences_json; | 1149 std::string preferences_json; |
| 1110 EXPECT_TRUE( | 1150 EXPECT_TRUE( |
| 1111 base::JSONWriter::Write(*http_server_properties, &preferences_json)); | 1151 base::JSONWriter::Write(*http_server_properties, &preferences_json)); |
| 1112 EXPECT_EQ(expected_json, preferences_json); | 1152 EXPECT_EQ(expected_json, preferences_json); |
| 1113 } | 1153 } |
| 1114 | 1154 |
| 1115 TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) { | 1155 TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) { |
| 1116 std::unique_ptr<base::Value> server_value = base::JSONReader::Read( | 1156 std::unique_ptr<base::Value> server_value = base::JSONReader::Read( |
| 1117 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"}," | 1157 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"}," |
| 1118 "{\"port\":123,\"protocol_str\":\"quic\"," | 1158 "{\"port\":123,\"protocol_str\":\"quic\"," |
| 1119 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\"," | 1159 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\"," |
| 1120 "\"port\":1234,\"protocol_str\":\"npn-h2\"," | 1160 "\"port\":1234,\"protocol_str\":\"npn-h2\"," |
| 1121 "\"expiration\":\"13758804000000000\"}]}"); | 1161 "\"expiration\":\"13758804000000000\"}]}"); |
| 1122 ASSERT_TRUE(server_value); | 1162 ASSERT_TRUE(server_value); |
| 1123 base::DictionaryValue* server_dict; | 1163 base::DictionaryValue* server_dict; |
| 1124 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict)); | 1164 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict)); |
| 1125 | 1165 |
| 1126 const HostPortPair host_port_pair("example.com", 443); | 1166 const url::SchemeHostPort server("https", "example.com", 443); |
| 1127 AlternativeServiceMap alternative_service_map(/*max_size=*/5); | 1167 AlternativeServiceMap alternative_service_map(/*max_size=*/5); |
| 1128 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( | 1168 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( |
| 1129 host_port_pair, *server_dict, &alternative_service_map)); | 1169 server, *server_dict, &alternative_service_map)); |
| 1130 | 1170 |
| 1131 AlternativeServiceMap::iterator it = | 1171 AlternativeServiceMap::iterator it = alternative_service_map.Get(server); |
| 1132 alternative_service_map.Get(host_port_pair); | |
| 1133 ASSERT_NE(alternative_service_map.end(), it); | 1172 ASSERT_NE(alternative_service_map.end(), it); |
| 1134 AlternativeServiceInfoVector alternative_service_info_vector = it->second; | 1173 AlternativeServiceInfoVector alternative_service_info_vector = it->second; |
| 1135 ASSERT_EQ(3u, alternative_service_info_vector.size()); | 1174 ASSERT_EQ(3u, alternative_service_info_vector.size()); |
| 1136 | 1175 |
| 1137 EXPECT_EQ(NPN_HTTP_2, | 1176 EXPECT_EQ(NPN_HTTP_2, |
| 1138 alternative_service_info_vector[0].alternative_service.protocol); | 1177 alternative_service_info_vector[0].alternative_service.protocol); |
| 1139 EXPECT_EQ("", alternative_service_info_vector[0].alternative_service.host); | 1178 EXPECT_EQ("", alternative_service_info_vector[0].alternative_service.host); |
| 1140 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); | 1179 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); |
| 1141 // Expiration defaults to one day from now, testing with tolerance. | 1180 // Expiration defaults to one day from now, testing with tolerance. |
| 1142 const base::Time now = base::Time::Now(); | 1181 const base::Time now = base::Time::Now(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 const base::Time time_one_day_ago = | 1222 const base::Time time_one_day_ago = |
| 1184 base::Time::Now() - base::TimeDelta::FromDays(1); | 1223 base::Time::Now() - base::TimeDelta::FromDays(1); |
| 1185 alternative_service_info_vector.push_back( | 1224 alternative_service_info_vector.push_back( |
| 1186 AlternativeServiceInfo(expired_alternative_service, time_one_day_ago)); | 1225 AlternativeServiceInfo(expired_alternative_service, time_one_day_ago)); |
| 1187 | 1226 |
| 1188 const AlternativeService valid_alternative_service(NPN_HTTP_2, | 1227 const AlternativeService valid_alternative_service(NPN_HTTP_2, |
| 1189 "valid.example.com", 443); | 1228 "valid.example.com", 443); |
| 1190 alternative_service_info_vector.push_back( | 1229 alternative_service_info_vector.push_back( |
| 1191 AlternativeServiceInfo(valid_alternative_service, time_one_day_later)); | 1230 AlternativeServiceInfo(valid_alternative_service, time_one_day_later)); |
| 1192 | 1231 |
| 1193 const HostPortPair host_port_pair("www.example.com", 443); | 1232 const url::SchemeHostPort server("https", "www.example.com", 443); |
| 1194 http_server_props_manager_->SetAlternativeServices( | 1233 http_server_props_manager_->SetAlternativeServices( |
| 1195 host_port_pair, alternative_service_info_vector); | 1234 server, alternative_service_info_vector); |
| 1196 | 1235 |
| 1197 // Update cache. | 1236 // Update cache. |
| 1198 ExpectPrefsUpdate(); | 1237 ExpectPrefsUpdate(); |
| 1199 ExpectCacheUpdate(); | 1238 ExpectCacheUpdate(); |
| 1200 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 1239 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 1201 base::RunLoop().RunUntilIdle(); | 1240 base::RunLoop().RunUntilIdle(); |
| 1202 | 1241 |
| 1203 const base::DictionaryValue& pref_dict = | 1242 const base::DictionaryValue& pref_dict = |
| 1204 pref_delegate_->GetServerProperties(); | 1243 pref_delegate_->GetServerProperties(); |
| 1205 | 1244 |
| 1206 const base::ListValue* servers_list = nullptr; | 1245 const base::ListValue* servers_list = nullptr; |
| 1207 ASSERT_TRUE(pref_dict.GetListWithoutPathExpansion("servers", &servers_list)); | 1246 ASSERT_TRUE(pref_dict.GetListWithoutPathExpansion("servers", &servers_list)); |
| 1208 base::ListValue::const_iterator it = servers_list->begin(); | 1247 base::ListValue::const_iterator it = servers_list->begin(); |
| 1209 const base::DictionaryValue* server_pref_dict; | 1248 const base::DictionaryValue* server_pref_dict; |
| 1210 ASSERT_TRUE((*it)->GetAsDictionary(&server_pref_dict)); | 1249 ASSERT_TRUE((*it)->GetAsDictionary(&server_pref_dict)); |
| 1211 | 1250 |
| 1212 const base::DictionaryValue* example_pref_dict; | 1251 const base::DictionaryValue* example_pref_dict; |
| 1252 |
| 1213 ASSERT_TRUE(server_pref_dict->GetDictionaryWithoutPathExpansion( | 1253 ASSERT_TRUE(server_pref_dict->GetDictionaryWithoutPathExpansion( |
| 1214 "www.example.com:443", &example_pref_dict)); | 1254 "https://www.example.com", &example_pref_dict)); |
| 1215 | 1255 |
| 1216 const base::ListValue* altsvc_list; | 1256 const base::ListValue* altsvc_list; |
| 1217 ASSERT_TRUE(example_pref_dict->GetList("alternative_service", &altsvc_list)); | 1257 ASSERT_TRUE(example_pref_dict->GetList("alternative_service", &altsvc_list)); |
| 1218 | 1258 |
| 1219 ASSERT_EQ(1u, altsvc_list->GetSize()); | 1259 ASSERT_EQ(1u, altsvc_list->GetSize()); |
| 1220 | 1260 |
| 1221 const base::DictionaryValue* altsvc_entry; | 1261 const base::DictionaryValue* altsvc_entry; |
| 1222 ASSERT_TRUE(altsvc_list->GetDictionary(0, &altsvc_entry)); | 1262 ASSERT_TRUE(altsvc_list->GetDictionary(0, &altsvc_entry)); |
| 1223 | 1263 |
| 1224 std::string hostname; | 1264 std::string hostname; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1245 valid_dict->SetString("host", "valid.example.com"); | 1285 valid_dict->SetString("host", "valid.example.com"); |
| 1246 valid_dict->SetInteger("port", 443); | 1286 valid_dict->SetInteger("port", 443); |
| 1247 valid_dict->SetString( | 1287 valid_dict->SetString( |
| 1248 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue())); | 1288 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue())); |
| 1249 alternative_service_list->Append(valid_dict); | 1289 alternative_service_list->Append(valid_dict); |
| 1250 | 1290 |
| 1251 base::DictionaryValue server_pref_dict; | 1291 base::DictionaryValue server_pref_dict; |
| 1252 server_pref_dict.SetWithoutPathExpansion("alternative_service", | 1292 server_pref_dict.SetWithoutPathExpansion("alternative_service", |
| 1253 alternative_service_list.release()); | 1293 alternative_service_list.release()); |
| 1254 | 1294 |
| 1255 const HostPortPair host_port_pair("example.com", 443); | 1295 const url::SchemeHostPort server("https", "example.com", 443); |
| 1256 AlternativeServiceMap alternative_service_map(/*max_size=*/5); | 1296 AlternativeServiceMap alternative_service_map(/*max_size=*/5); |
| 1257 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( | 1297 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( |
| 1258 host_port_pair, server_pref_dict, &alternative_service_map)); | 1298 server, server_pref_dict, &alternative_service_map)); |
| 1259 | 1299 |
| 1260 AlternativeServiceMap::iterator it = | 1300 AlternativeServiceMap::iterator it = alternative_service_map.Get(server); |
| 1261 alternative_service_map.Get(host_port_pair); | |
| 1262 ASSERT_NE(alternative_service_map.end(), it); | 1301 ASSERT_NE(alternative_service_map.end(), it); |
| 1263 AlternativeServiceInfoVector alternative_service_info_vector = it->second; | 1302 AlternativeServiceInfoVector alternative_service_info_vector = it->second; |
| 1264 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 1303 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 1265 | 1304 |
| 1266 EXPECT_EQ(NPN_HTTP_2, | 1305 EXPECT_EQ(NPN_HTTP_2, |
| 1267 alternative_service_info_vector[0].alternative_service.protocol); | 1306 alternative_service_info_vector[0].alternative_service.protocol); |
| 1268 EXPECT_EQ("valid.example.com", | 1307 EXPECT_EQ("valid.example.com", |
| 1269 alternative_service_info_vector[0].alternative_service.host); | 1308 alternative_service_info_vector[0].alternative_service.host); |
| 1270 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); | 1309 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); |
| 1271 EXPECT_EQ(one_day_from_now_, alternative_service_info_vector[0].expiration); | 1310 EXPECT_EQ(one_day_from_now_, alternative_service_info_vector[0].expiration); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1337 // Shutdown comes before the task is executed. | 1376 // Shutdown comes before the task is executed. |
| 1338 http_server_props_manager_->ShutdownOnPrefThread(); | 1377 http_server_props_manager_->ShutdownOnPrefThread(); |
| 1339 // Run the task after shutdown, but before deletion. | 1378 // Run the task after shutdown, but before deletion. |
| 1340 base::RunLoop().RunUntilIdle(); | 1379 base::RunLoop().RunUntilIdle(); |
| 1341 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1380 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 1342 http_server_props_manager_.reset(); | 1381 http_server_props_manager_.reset(); |
| 1343 base::RunLoop().RunUntilIdle(); | 1382 base::RunLoop().RunUntilIdle(); |
| 1344 } | 1383 } |
| 1345 | 1384 |
| 1346 } // namespace net | 1385 } // namespace net |
| OLD | NEW |