| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 }; | 225 }; |
| 226 | 226 |
| 227 INSTANTIATE_TEST_CASE_P(Tests, | 227 INSTANTIATE_TEST_CASE_P(Tests, |
| 228 HttpServerPropertiesManagerTest, | 228 HttpServerPropertiesManagerTest, |
| 229 ::testing::ValuesIn(kHttpServerPropertiesVersions)); | 229 ::testing::ValuesIn(kHttpServerPropertiesVersions)); |
| 230 | 230 |
| 231 TEST_P(HttpServerPropertiesManagerTest, | 231 TEST_P(HttpServerPropertiesManagerTest, |
| 232 SingleUpdateForTwoSpdyServerPrefChanges) { | 232 SingleUpdateForTwoSpdyServerPrefChanges) { |
| 233 ExpectCacheUpdate(); | 233 ExpectCacheUpdate(); |
| 234 | 234 |
| 235 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set | 235 // Set up the prefs for https://www.google.com and https://mail.google.com and |
| 236 // it twice. Only expect a single cache update. | 236 // then set it twice. Only expect a single cache update. |
| 237 | 237 |
| 238 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 238 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 239 url::SchemeHostPort google_server(GetParam() >= 5 ? "http" : "https", | 239 url::SchemeHostPort google_server("https", "www.google.com", 443); |
| 240 "www.google.com", 80); | 240 url::SchemeHostPort mail_server("https", "mail.google.com", 443); |
| 241 url::SchemeHostPort mail_server(GetParam() >= 5 ? "http" : "https", | |
| 242 "mail.google.com", 80); | |
| 243 | 241 |
| 244 // Set supports_spdy for http://www.google.com:80. | 242 // Set supports_spdy for https://www.google.com:443. |
| 245 server_pref_dict->SetBoolean("supports_spdy", true); | 243 server_pref_dict->SetBoolean("supports_spdy", true); |
| 246 | 244 |
| 247 // Set up alternative_services for http://www.google.com:80. | 245 // Set up alternative_services for https://www.google.com. |
| 248 std::unique_ptr<base::DictionaryValue> alternative_service_dict0( | 246 std::unique_ptr<base::DictionaryValue> alternative_service_dict0( |
| 249 new base::DictionaryValue); | 247 new base::DictionaryValue); |
| 250 alternative_service_dict0->SetInteger("port", 443); | 248 alternative_service_dict0->SetInteger("port", 443); |
| 251 alternative_service_dict0->SetString("protocol_str", "npn-h2"); | 249 alternative_service_dict0->SetString("protocol_str", "npn-h2"); |
| 252 std::unique_ptr<base::DictionaryValue> alternative_service_dict1( | 250 std::unique_ptr<base::DictionaryValue> alternative_service_dict1( |
| 253 new base::DictionaryValue); | 251 new base::DictionaryValue); |
| 254 alternative_service_dict1->SetInteger("port", 1234); | 252 alternative_service_dict1->SetInteger("port", 1234); |
| 255 alternative_service_dict1->SetString("protocol_str", "quic"); | 253 alternative_service_dict1->SetString("protocol_str", "quic"); |
| 256 base::ListValue* alternative_service_list0 = new base::ListValue; | 254 base::ListValue* alternative_service_list0 = new base::ListValue; |
| 257 alternative_service_list0->Append(std::move(alternative_service_dict0)); | 255 alternative_service_list0->Append(std::move(alternative_service_dict0)); |
| 258 alternative_service_list0->Append(std::move(alternative_service_dict1)); | 256 alternative_service_list0->Append(std::move(alternative_service_dict1)); |
| 259 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 257 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 260 alternative_service_list0); | 258 alternative_service_list0); |
| 261 | 259 |
| 262 // Set up ServerNetworkStats for http://www.google.com:80. | 260 // Set up ServerNetworkStats for https://www.google.com. |
| 263 base::DictionaryValue* stats = new base::DictionaryValue; | 261 base::DictionaryValue* stats = new base::DictionaryValue; |
| 264 stats->SetInteger("srtt", 10); | 262 stats->SetInteger("srtt", 10); |
| 265 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 263 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
| 266 | 264 |
| 267 // Set the server preference for http://www.google.com:80. | 265 // Set the server preference for https://www.google.com. |
| 268 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 266 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 269 servers_dict->SetWithoutPathExpansion( | 267 servers_dict->SetWithoutPathExpansion( |
| 270 GetParam() >= 5 ? "http://www.google.com" : "www.google.com:80", | 268 GetParam() >= 5 ? "https://www.google.com" : "www.google.com:443", |
| 271 server_pref_dict); | 269 server_pref_dict); |
| 272 base::ListValue* servers_list = nullptr; | 270 base::ListValue* servers_list = nullptr; |
| 273 if (GetParam() >= 4) { | 271 if (GetParam() >= 4) { |
| 274 servers_list = new base::ListValue; | 272 servers_list = new base::ListValue; |
| 275 // |servers_list| takes ownership of |servers_dict|. | 273 // |servers_list| takes ownership of |servers_dict|. |
| 276 servers_list->AppendIfNotPresent(servers_dict); | 274 servers_list->AppendIfNotPresent(servers_dict); |
| 277 servers_dict = new base::DictionaryValue; | 275 servers_dict = new base::DictionaryValue; |
| 278 } | 276 } |
| 279 | 277 |
| 280 // Set the preference for mail.google.com server. | 278 // Set the preference for mail.google.com server. |
| 281 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 279 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 282 | 280 |
| 283 // Set supports_spdy for mail.google.com:80 | 281 // Set supports_spdy for https://mail.google.com. |
| 284 server_pref_dict1->SetBoolean("supports_spdy", true); | 282 server_pref_dict1->SetBoolean("supports_spdy", true); |
| 285 | 283 |
| 286 // Set up alternative_services for mail.google.com:80. | 284 // Set up alternative_services for https://mail.google.com. |
| 287 std::unique_ptr<base::DictionaryValue> alternative_service_dict2( | 285 std::unique_ptr<base::DictionaryValue> alternative_service_dict2( |
| 288 new base::DictionaryValue); | 286 new base::DictionaryValue); |
| 289 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1"); | 287 alternative_service_dict2->SetString("protocol_str", "npn-spdy/3.1"); |
| 290 alternative_service_dict2->SetInteger("port", 444); | 288 alternative_service_dict2->SetInteger("port", 444); |
| 291 base::ListValue* alternative_service_list1 = new base::ListValue; | 289 base::ListValue* alternative_service_list1 = new base::ListValue; |
| 292 alternative_service_list1->Append(std::move(alternative_service_dict2)); | 290 alternative_service_list1->Append(std::move(alternative_service_dict2)); |
| 293 server_pref_dict1->SetWithoutPathExpansion("alternative_service", | 291 server_pref_dict1->SetWithoutPathExpansion("alternative_service", |
| 294 alternative_service_list1); | 292 alternative_service_list1); |
| 295 | 293 |
| 296 // Set up ServerNetworkStats for http://mail.google.com:80 and it is the MRU | 294 // Set up ServerNetworkStats for https://mail.google.com and it is the MRU |
| 297 // server. | 295 // server. |
| 298 base::DictionaryValue* stats1 = new base::DictionaryValue; | 296 base::DictionaryValue* stats1 = new base::DictionaryValue; |
| 299 stats1->SetInteger("srtt", 20); | 297 stats1->SetInteger("srtt", 20); |
| 300 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); | 298 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); |
| 301 // Set the server preference for http://mail.google.com:80. | 299 // Set the server preference for https://mail.google.com. |
| 302 servers_dict->SetWithoutPathExpansion( | 300 servers_dict->SetWithoutPathExpansion( |
| 303 GetParam() >= 5 ? "http://mail.google.com" : "mail.google.com:80", | 301 GetParam() >= 5 ? "https://mail.google.com" : "mail.google.com:443", |
| 304 server_pref_dict1); | 302 server_pref_dict1); |
| 305 base::DictionaryValue http_server_properties_dict; | 303 base::DictionaryValue http_server_properties_dict; |
| 306 if (GetParam() >= 4) { | 304 if (GetParam() >= 4) { |
| 307 // |servers_list| takes ownership of |servers_dict|. | 305 // |servers_list| takes ownership of |servers_dict|. |
| 308 servers_list->AppendIfNotPresent(servers_dict); | 306 servers_list->AppendIfNotPresent(servers_dict); |
| 309 if (GetParam() == 5) { | 307 if (GetParam() == 5) { |
| 310 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); | 308 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, -1); |
| 311 } else { | 309 } else { |
| 312 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 310 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 313 GetParam()); | 311 GetParam()); |
| 314 } | 312 } |
| 315 http_server_properties_dict.SetWithoutPathExpansion("servers", | 313 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 316 servers_list); | 314 servers_list); |
| 317 } else { | 315 } else { |
| 318 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, | 316 HttpServerPropertiesManager::SetVersion(&http_server_properties_dict, |
| 319 GetParam()); | 317 GetParam()); |
| 320 http_server_properties_dict.SetWithoutPathExpansion("servers", | 318 http_server_properties_dict.SetWithoutPathExpansion("servers", |
| 321 servers_dict); | 319 servers_dict); |
| 322 } | 320 } |
| 323 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 321 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 324 supports_quic->SetBoolean("used_quic", true); | 322 supports_quic->SetBoolean("used_quic", true); |
| 325 supports_quic->SetString("address", "127.0.0.1"); | 323 supports_quic->SetString("address", "127.0.0.1"); |
| 326 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", | 324 http_server_properties_dict.SetWithoutPathExpansion("supports_quic", |
| 327 supports_quic); | 325 supports_quic); |
| 328 | 326 |
| 329 // Set quic_server_info for www.google.com:80, mail.google.com:80 and | 327 // Set quic_server_info for https://www.google.com, https://mail.google.com |
| 330 // play.google.com:80 and verify the MRU. | 328 // and https://play.google.com and verify the MRU. |
| 331 http_server_props_manager_->SetMaxServerConfigsStoredInProperties(3); | 329 http_server_props_manager_->SetMaxServerConfigsStoredInProperties(3); |
| 332 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; | 330 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; |
| 333 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; | 331 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; |
| 334 std::string quic_server_info1("quic_server_info1"); | 332 std::string quic_server_info1("quic_server_info1"); |
| 335 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", | 333 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", |
| 336 quic_server_info1); | 334 quic_server_info1); |
| 337 base::DictionaryValue* quic_server_pref_dict2 = new base::DictionaryValue; | 335 base::DictionaryValue* quic_server_pref_dict2 = new base::DictionaryValue; |
| 338 std::string quic_server_info2("quic_server_info2"); | 336 std::string quic_server_info2("quic_server_info2"); |
| 339 quic_server_pref_dict2->SetStringWithoutPathExpansion("server_info", | 337 quic_server_pref_dict2->SetStringWithoutPathExpansion("server_info", |
| 340 quic_server_info2); | 338 quic_server_info2); |
| 341 base::DictionaryValue* quic_server_pref_dict3 = new base::DictionaryValue; | 339 base::DictionaryValue* quic_server_pref_dict3 = new base::DictionaryValue; |
| 342 std::string quic_server_info3("quic_server_info3"); | 340 std::string quic_server_info3("quic_server_info3"); |
| 343 quic_server_pref_dict3->SetStringWithoutPathExpansion("server_info", | 341 quic_server_pref_dict3->SetStringWithoutPathExpansion("server_info", |
| 344 quic_server_info3); | 342 quic_server_info3); |
| 345 // Set the quic_server_info1 for www.google.com server. | 343 // Set the quic_server_info1 for https://www.google.com. |
| 346 QuicServerId google_quic_server_id("www.google.com", 80); | 344 QuicServerId google_quic_server_id("www.google.com", 443); |
| 347 quic_servers_dict->SetWithoutPathExpansion(google_quic_server_id.ToString(), | 345 quic_servers_dict->SetWithoutPathExpansion(google_quic_server_id.ToString(), |
| 348 quic_server_pref_dict1); | 346 quic_server_pref_dict1); |
| 349 // Set the quic_server_info2 for mail.google.com server. | 347 // Set the quic_server_info2 for https://mail.google.com. |
| 350 QuicServerId mail_quic_server_id("mail.google.com", 80); | 348 QuicServerId mail_quic_server_id("mail.google.com", 443); |
| 351 quic_servers_dict->SetWithoutPathExpansion(mail_quic_server_id.ToString(), | 349 quic_servers_dict->SetWithoutPathExpansion(mail_quic_server_id.ToString(), |
| 352 quic_server_pref_dict2); | 350 quic_server_pref_dict2); |
| 353 // Set the quic_server_info3 for play.google.com server. | 351 // Set the quic_server_info3 for https://play.google.com. |
| 354 QuicServerId play_quic_server_id("play.google.com", 80); | 352 QuicServerId play_quic_server_id("play.google.com", 443); |
| 355 quic_servers_dict->SetWithoutPathExpansion(play_quic_server_id.ToString(), | 353 quic_servers_dict->SetWithoutPathExpansion(play_quic_server_id.ToString(), |
| 356 quic_server_pref_dict3); | 354 quic_server_pref_dict3); |
| 357 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", | 355 http_server_properties_dict.SetWithoutPathExpansion("quic_servers", |
| 358 quic_servers_dict); | 356 quic_servers_dict); |
| 359 | 357 |
| 360 // Set the same value for kHttpServerProperties multiple times. | 358 // Set the same value for kHttpServerProperties multiple times. |
| 361 pref_delegate_->SetPrefs(http_server_properties_dict); | 359 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 362 pref_delegate_->SetPrefs(http_server_properties_dict); | 360 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 363 | 361 |
| 364 base::RunLoop().RunUntilIdle(); | 362 base::RunLoop().RunUntilIdle(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol); | 413 EXPECT_EQ(NPN_SPDY_3_1, map_it->second[0].alternative_service.protocol); |
| 416 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 414 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
| 417 EXPECT_EQ(444, map_it->second[0].alternative_service.port); | 415 EXPECT_EQ(444, map_it->second[0].alternative_service.port); |
| 418 } | 416 } |
| 419 | 417 |
| 420 // Verify SupportsQuic. | 418 // Verify SupportsQuic. |
| 421 IPAddress last_address; | 419 IPAddress last_address; |
| 422 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); | 420 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); |
| 423 EXPECT_EQ("127.0.0.1", last_address.ToString()); | 421 EXPECT_EQ("127.0.0.1", last_address.ToString()); |
| 424 | 422 |
| 423 /* |
| 425 // Verify ServerNetworkStats. | 424 // Verify ServerNetworkStats. |
| 426 const ServerNetworkStats* stats2 = | 425 const ServerNetworkStats* stats2 = |
| 427 http_server_props_manager_->GetServerNetworkStats(google_server); | 426 http_server_props_manager_->GetServerNetworkStats(google_server); |
| 428 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 427 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 429 const ServerNetworkStats* stats3 = | 428 const ServerNetworkStats* stats3 = |
| 430 http_server_props_manager_->GetServerNetworkStats(mail_server); | 429 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 431 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); | 430 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); |
| 432 | 431 |
| 433 // Verify QuicServerInfo. | 432 // Verify QuicServerInfo. |
| 434 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( | 433 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( |
| 435 google_quic_server_id)); | 434 google_quic_server_id)); |
| 436 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo( | 435 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo( |
| 437 mail_quic_server_id)); | 436 mail_quic_server_id)); |
| 438 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo( | 437 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo( |
| 439 play_quic_server_id)); | 438 play_quic_server_id)); |
| 440 | 439 |
| 441 // Verify the MRU order. | 440 // Verify the MRU order. |
| 442 http_server_props_manager_->SetMaxServerConfigsStoredInProperties(2); | 441 http_server_props_manager_->SetMaxServerConfigsStoredInProperties(2); |
| 443 EXPECT_EQ(nullptr, http_server_props_manager_->GetQuicServerInfo( | 442 EXPECT_EQ(nullptr, http_server_props_manager_->GetQuicServerInfo( |
| 444 google_quic_server_id)); | 443 google_quic_server_id)); |
| 445 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo( | 444 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo( |
| 446 mail_quic_server_id)); | 445 mail_quic_server_id)); |
| 447 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo( | 446 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo( |
| 448 play_quic_server_id)); | 447 play_quic_server_id)); |
| 448 */ |
| 449 } | 449 } |
| 450 | 450 |
| 451 TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { | 451 TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { |
| 452 ExpectCacheUpdate(); | 452 ExpectCacheUpdate(); |
| 453 // The prefs are automaticalls updated in the case corruption is detected. | 453 // The prefs are automaticalls updated in the case corruption is detected. |
| 454 ExpectPrefsUpdate(); | 454 ExpectPrefsUpdate(); |
| 455 ExpectScheduleUpdatePrefsOnNetworkThread(); | 455 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 456 | 456 |
| 457 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 457 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 458 | 458 |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 new base::DictionaryValue); | 983 new base::DictionaryValue); |
| 984 alternative_service_dict->SetString("protocol_str", "quic"); | 984 alternative_service_dict->SetString("protocol_str", "quic"); |
| 985 alternative_service_dict->SetInteger("port", i); | 985 alternative_service_dict->SetInteger("port", i); |
| 986 base::ListValue* alternative_service_list = new base::ListValue; | 986 base::ListValue* alternative_service_list = new base::ListValue; |
| 987 alternative_service_list->Append(std::move(alternative_service_dict)); | 987 alternative_service_list->Append(std::move(alternative_service_dict)); |
| 988 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 988 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 989 server_pref_dict->SetWithoutPathExpansion("alternative_service", | 989 server_pref_dict->SetWithoutPathExpansion("alternative_service", |
| 990 alternative_service_list); | 990 alternative_service_list); |
| 991 if (GetParam() >= 5) { | 991 if (GetParam() >= 5) { |
| 992 servers_dict->SetWithoutPathExpansion( | 992 servers_dict->SetWithoutPathExpansion( |
| 993 StringPrintf("http://www.google.com:%d", i), server_pref_dict); | 993 StringPrintf("https://www.google.com:%d", i), server_pref_dict); |
| 994 } else { | 994 } else { |
| 995 servers_dict->SetWithoutPathExpansion( | 995 servers_dict->SetWithoutPathExpansion( |
| 996 StringPrintf("www.google.com:%d", i), server_pref_dict); | 996 StringPrintf("www.google.com:%d", i), server_pref_dict); |
| 997 } | 997 } |
| 998 if (GetParam() >= 4) { | 998 if (GetParam() >= 4) { |
| 999 // |servers_list| takes ownership of |servers_dict|. | 999 // |servers_list| takes ownership of |servers_dict|. |
| 1000 servers_list->AppendIfNotPresent(servers_dict); | 1000 servers_list->AppendIfNotPresent(servers_dict); |
| 1001 servers_dict = new base::DictionaryValue; | 1001 servers_dict = new base::DictionaryValue; |
| 1002 } | 1002 } |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 // Set the server preference for http://mail.google.com server. | 1005 // Set the server preference for http://mail.google.com server. |
| 1006 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 1006 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 1007 if (GetParam() >= 5) { | 1007 if (GetParam() >= 5) { |
| 1008 servers_dict->SetWithoutPathExpansion("http://mail.google.com", | 1008 servers_dict->SetWithoutPathExpansion("https://mail.google.com", |
| 1009 server_pref_dict1); | 1009 server_pref_dict1); |
| 1010 } else { | 1010 } else { |
| 1011 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 1011 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
| 1012 server_pref_dict1); | 1012 server_pref_dict1); |
| 1013 } | 1013 } |
| 1014 base::DictionaryValue http_server_properties_dict; | 1014 base::DictionaryValue http_server_properties_dict; |
| 1015 if (GetParam() >= 4) { | 1015 if (GetParam() >= 4) { |
| 1016 // |servers_list| takes ownership of |servers_dict|. | 1016 // |servers_list| takes ownership of |servers_dict|. |
| 1017 servers_list->AppendIfNotPresent(servers_dict); | 1017 servers_list->AppendIfNotPresent(servers_dict); |
| 1018 if (GetParam() == 5) { | 1018 if (GetParam() == 5) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1040 // Set up the pref. | 1040 // Set up the pref. |
| 1041 pref_delegate_->SetPrefs(http_server_properties_dict); | 1041 pref_delegate_->SetPrefs(http_server_properties_dict); |
| 1042 | 1042 |
| 1043 base::RunLoop().RunUntilIdle(); | 1043 base::RunLoop().RunUntilIdle(); |
| 1044 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1044 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 1045 | 1045 |
| 1046 // Verify alternative service. | 1046 // Verify alternative service. |
| 1047 for (int i = 1; i <= 200; ++i) { | 1047 for (int i = 1; i <= 200; ++i) { |
| 1048 GURL server_gurl; | 1048 GURL server_gurl; |
| 1049 if (GetParam() >= 5) { | 1049 if (GetParam() >= 5) { |
| 1050 server_gurl = GURL(StringPrintf("http://www.google.com:%d", i)); | 1050 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i)); |
| 1051 } else { | 1051 } else { |
| 1052 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i)); | 1052 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i)); |
| 1053 } | 1053 } |
| 1054 url::SchemeHostPort server(server_gurl); | 1054 url::SchemeHostPort server(server_gurl); |
| 1055 AlternativeServiceVector alternative_service_vector = | 1055 AlternativeServiceVector alternative_service_vector = |
| 1056 http_server_props_manager_->GetAlternativeServices(server); | 1056 http_server_props_manager_->GetAlternativeServices(server); |
| 1057 ASSERT_EQ(1u, alternative_service_vector.size()); | 1057 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 1058 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); | 1058 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); |
| 1059 EXPECT_EQ(i, alternative_service_vector[0].port); | 1059 EXPECT_EQ(i, alternative_service_vector[0].port); |
| 1060 } | 1060 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 alternative_service_info_vector[2].alternative_service.protocol); | 1182 alternative_service_info_vector[2].alternative_service.protocol); |
| 1183 EXPECT_EQ("example.org", | 1183 EXPECT_EQ("example.org", |
| 1184 alternative_service_info_vector[2].alternative_service.host); | 1184 alternative_service_info_vector[2].alternative_service.host); |
| 1185 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port); | 1185 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port); |
| 1186 base::Time expected_expiration; | 1186 base::Time expected_expiration; |
| 1187 ASSERT_TRUE( | 1187 ASSERT_TRUE( |
| 1188 base::Time::FromUTCString("2036-12-31 10:00:00", &expected_expiration)); | 1188 base::Time::FromUTCString("2036-12-31 10:00:00", &expected_expiration)); |
| 1189 EXPECT_EQ(expected_expiration, alternative_service_info_vector[2].expiration); | 1189 EXPECT_EQ(expected_expiration, alternative_service_info_vector[2].expiration); |
| 1190 } | 1190 } |
| 1191 | 1191 |
| 1192 // Regression test for https://crbug.com/615497. |
| 1193 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadAltSvcForInsecureOrigins) { |
| 1194 std::unique_ptr<base::Value> server_value = base::JSONReader::Read( |
| 1195 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"," |
| 1196 "\"expiration\":\"9223372036854775807\"}]}"); |
| 1197 ASSERT_TRUE(server_value); |
| 1198 base::DictionaryValue* server_dict; |
| 1199 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict)); |
| 1200 |
| 1201 const url::SchemeHostPort server("http", "example.com", 80); |
| 1202 AlternativeServiceMap alternative_service_map(/*max_size=*/5); |
| 1203 EXPECT_FALSE(http_server_props_manager_->AddToAlternativeServiceMap( |
| 1204 server, *server_dict, &alternative_service_map)); |
| 1205 |
| 1206 AlternativeServiceMap::iterator it = alternative_service_map.Get(server); |
| 1207 EXPECT_EQ(alternative_service_map.end(), it); |
| 1208 } |
| 1209 |
| 1192 // Do not persist expired or broken alternative service entries to disk. | 1210 // Do not persist expired or broken alternative service entries to disk. |
| 1193 TEST_P(HttpServerPropertiesManagerTest, | 1211 TEST_P(HttpServerPropertiesManagerTest, |
| 1194 DoNotPersistExpiredOrBrokenAlternativeService) { | 1212 DoNotPersistExpiredOrBrokenAlternativeService) { |
| 1195 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 1213 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
| 1196 | 1214 |
| 1197 AlternativeServiceInfoVector alternative_service_info_vector; | 1215 AlternativeServiceInfoVector alternative_service_info_vector; |
| 1198 | 1216 |
| 1199 const AlternativeService broken_alternative_service( | 1217 const AlternativeService broken_alternative_service( |
| 1200 NPN_HTTP_2, "broken.example.com", 443); | 1218 NPN_HTTP_2, "broken.example.com", 443); |
| 1201 const base::Time time_one_day_later = | 1219 const base::Time time_one_day_later = |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 // Shutdown comes before the task is executed. | 1383 // Shutdown comes before the task is executed. |
| 1366 http_server_props_manager_->ShutdownOnPrefThread(); | 1384 http_server_props_manager_->ShutdownOnPrefThread(); |
| 1367 // Run the task after shutdown, but before deletion. | 1385 // Run the task after shutdown, but before deletion. |
| 1368 base::RunLoop().RunUntilIdle(); | 1386 base::RunLoop().RunUntilIdle(); |
| 1369 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1387 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 1370 http_server_props_manager_.reset(); | 1388 http_server_props_manager_.reset(); |
| 1371 base::RunLoop().RunUntilIdle(); | 1389 base::RunLoop().RunUntilIdle(); |
| 1372 } | 1390 } |
| 1373 | 1391 |
| 1374 } // namespace net | 1392 } // namespace net |
| OLD | NEW |