| 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/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set | 149 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set |
| 150 // it twice. Only expect a single cache update. | 150 // it twice. Only expect a single cache update. |
| 151 | 151 |
| 152 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 152 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 153 HostPortPair google_server("www.google.com", 80); | 153 HostPortPair google_server("www.google.com", 80); |
| 154 HostPortPair mail_server("mail.google.com", 80); | 154 HostPortPair mail_server("mail.google.com", 80); |
| 155 | 155 |
| 156 // Set supports_spdy for www.google.com:80. | 156 // Set supports_spdy for www.google.com:80. |
| 157 server_pref_dict->SetBoolean("supports_spdy", true); | 157 server_pref_dict->SetBoolean("supports_spdy", true); |
| 158 | 158 |
| 159 // Set up alternate_protocol for www.google.com:80. | 159 // Set up alternative_services for www.google.com:80. |
| 160 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 160 base::DictionaryValue* alternate_protocol0 = new base::DictionaryValue; |
| 161 alternate_protocol->SetInteger("port", 443); | 161 alternate_protocol0->SetInteger("port", 443); |
| 162 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 162 alternate_protocol0->SetString("protocol_str", "npn-spdy/3"); |
| 163 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 163 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; |
| 164 alternate_protocol); | 164 alternate_protocol1->SetInteger("port", 1234); |
| 165 alternate_protocol1->SetString("protocol_str", "quic"); |
| 166 base::ListValue* alternative_services = new base::ListValue; |
| 167 alternative_services->Append(alternate_protocol0); |
| 168 alternative_services->Append(alternate_protocol1); |
| 169 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
| 170 alternative_services); |
| 165 | 171 |
| 166 // Set up SupportsQuic for www.google.com:80. | 172 // Set up SupportsQuic for www.google.com:80. |
| 167 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 173 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 168 supports_quic->SetBoolean("used_quic", true); | 174 supports_quic->SetBoolean("used_quic", true); |
| 169 supports_quic->SetString("address", "foo"); | 175 supports_quic->SetString("address", "foo"); |
| 170 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); | 176 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); |
| 171 | 177 |
| 172 // Set up ServerNetworkStats for www.google.com:80. | 178 // Set up ServerNetworkStats for www.google.com:80. |
| 173 base::DictionaryValue* stats = new base::DictionaryValue; | 179 base::DictionaryValue* stats = new base::DictionaryValue; |
| 174 stats->SetInteger("srtt", 10); | 180 stats->SetInteger("srtt", 10); |
| 175 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 181 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
| 176 | 182 |
| 177 // Set the server preference for www.google.com:80. | 183 // Set the server preference for www.google.com:80. |
| 178 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 184 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 179 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 185 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
| 180 | 186 |
| 181 // Set the preference for mail.google.com server. | 187 // Set the preference for mail.google.com server. |
| 182 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 188 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 183 | 189 |
| 184 // Set supports_spdy for mail.google.com:80 | 190 // Set supports_spdy for mail.google.com:80 |
| 185 server_pref_dict1->SetBoolean("supports_spdy", true); | 191 server_pref_dict1->SetBoolean("supports_spdy", true); |
| 186 | 192 |
| 187 // Set up alternate_protocol for mail.google.com:80 | 193 // Set up alternative_services for mail.google.com:80 |
| 188 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; | 194 base::DictionaryValue* alternate_protocol2 = new base::DictionaryValue; |
| 189 alternate_protocol1->SetInteger("port", 444); | 195 alternate_protocol2->SetInteger("port", 444); |
| 190 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); | 196 alternate_protocol2->SetString("protocol_str", "npn-spdy/3.1"); |
| 191 | 197 base::ListValue* alternative_services1 = new base::ListValue; |
| 192 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", | 198 alternative_services1->Append(alternate_protocol2); |
| 193 alternate_protocol1); | 199 server_pref_dict1->SetWithoutPathExpansion("alternative_services", |
| 200 alternative_services1); |
| 194 | 201 |
| 195 // Set up SupportsQuic for mail.google.com:80 | 202 // Set up SupportsQuic for mail.google.com:80 |
| 196 base::DictionaryValue* supports_quic1 = new base::DictionaryValue; | 203 base::DictionaryValue* supports_quic1 = new base::DictionaryValue; |
| 197 supports_quic1->SetBoolean("used_quic", false); | 204 supports_quic1->SetBoolean("used_quic", false); |
| 198 supports_quic1->SetString("address", "bar"); | 205 supports_quic1->SetString("address", "bar"); |
| 199 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1); | 206 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1); |
| 200 | 207 |
| 201 // Set up ServerNetworkStats for mail.google.com:80. | 208 // Set up ServerNetworkStats for mail.google.com:80. |
| 202 base::DictionaryValue* stats1 = new base::DictionaryValue; | 209 base::DictionaryValue* stats1 = new base::DictionaryValue; |
| 203 stats1->SetInteger("srtt", 20); | 210 stats1->SetInteger("srtt", 20); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 222 base::RunLoop().RunUntilIdle(); | 229 base::RunLoop().RunUntilIdle(); |
| 223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 230 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 224 | 231 |
| 225 // Verify SupportsSpdy. | 232 // Verify SupportsSpdy. |
| 226 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(google_server)); | 233 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(google_server)); |
| 227 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(mail_server)); | 234 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(mail_server)); |
| 228 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( | 235 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( |
| 229 HostPortPair::FromString("foo.google.com:1337"))); | 236 HostPortPair::FromString("foo.google.com:1337"))); |
| 230 | 237 |
| 231 // Verify AlternateProtocol. | 238 // Verify AlternateProtocol. |
| 232 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); | 239 const AlternateProtocolMap& map = |
| 233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); | 240 http_server_props_manager_->alternate_protocol_map(); |
| 234 AlternateProtocolInfo port_alternate_protocol = | 241 AlternateProtocolMap::const_iterator www_it = map.Peek(google_server); |
| 235 http_server_props_manager_->GetAlternateProtocol(google_server); | 242 ASSERT_NE(map.end(), www_it); |
| 236 EXPECT_EQ(443, port_alternate_protocol.port); | 243 const AlternateProtocols alternate_protocols0 = www_it->second; |
| 237 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 244 ASSERT_EQ(2u, alternate_protocols0.size()); |
| 238 port_alternate_protocol = | 245 EXPECT_EQ(443, alternate_protocols0[0].port); |
| 239 http_server_props_manager_->GetAlternateProtocol(mail_server); | 246 EXPECT_EQ(NPN_SPDY_3, alternate_protocols0[0].protocol); |
| 240 EXPECT_EQ(444, port_alternate_protocol.port); | 247 EXPECT_EQ(1234, alternate_protocols0[1].port); |
| 241 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); | 248 EXPECT_EQ(QUIC, alternate_protocols0[1].protocol); |
| 249 AlternateProtocolMap::const_iterator mail_it = map.Peek(mail_server); |
| 250 ASSERT_NE(map.end(), mail_it); |
| 251 const AlternateProtocols alternate_protocols1 = mail_it->second; |
| 252 ASSERT_EQ(1u, alternate_protocols1.size()); |
| 253 EXPECT_EQ(444, alternate_protocols1[0].port); |
| 254 EXPECT_EQ(NPN_SPDY_3_1, alternate_protocols1[0].protocol); |
| 242 | 255 |
| 243 // Verify SupportsQuic. | 256 // Verify SupportsQuic. |
| 244 SupportsQuic supports_quic2 = | 257 SupportsQuic supports_quic2 = |
| 245 http_server_props_manager_->GetSupportsQuic(google_server); | 258 http_server_props_manager_->GetSupportsQuic(google_server); |
| 246 EXPECT_TRUE(supports_quic2.used_quic); | 259 EXPECT_TRUE(supports_quic2.used_quic); |
| 247 EXPECT_EQ("foo", supports_quic2.address); | 260 EXPECT_EQ("foo", supports_quic2.address); |
| 248 supports_quic2 = http_server_props_manager_->GetSupportsQuic(mail_server); | 261 supports_quic2 = http_server_props_manager_->GetSupportsQuic(mail_server); |
| 249 EXPECT_FALSE(supports_quic2.used_quic); | 262 EXPECT_FALSE(supports_quic2.used_quic); |
| 250 EXPECT_EQ("bar", supports_quic2.address); | 263 EXPECT_EQ("bar", supports_quic2.address); |
| 251 | 264 |
| 252 // Verify ServerNetworkStats. | 265 // Verify ServerNetworkStats. |
| 253 const ServerNetworkStats* stats2 = | 266 const ServerNetworkStats* stats2 = |
| 254 http_server_props_manager_->GetServerNetworkStats(google_server); | 267 http_server_props_manager_->GetServerNetworkStats(google_server); |
| 255 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 268 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 256 const ServerNetworkStats* stats3 = | 269 const ServerNetworkStats* stats3 = |
| 257 http_server_props_manager_->GetServerNetworkStats(mail_server); | 270 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 258 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); | 271 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); |
| 259 } | 272 } |
| 260 | 273 |
| 261 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { | 274 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { |
| 262 ExpectCacheUpdate(); | 275 ExpectCacheUpdate(); |
| 263 // The prefs are automaticalls updated in the case corruption is detected. | 276 // The prefs are automaticalls updated in the case corruption is detected. |
| 264 ExpectPrefsUpdate(); | 277 ExpectPrefsUpdate(); |
| 265 | 278 |
| 266 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 279 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 267 | 280 |
| 268 // Set supports_spdy for www.google.com:65536. | 281 // Set supports_spdy for www.google.com:65536. |
| 269 server_pref_dict->SetBoolean("supports_spdy", true); | 282 server_pref_dict->SetBoolean("supports_spdy", true); |
| 270 | 283 |
| 271 // Set up alternate_protocol for www.google.com:65536. | 284 // Set up alternative_services for www.google.com:65536. |
| 272 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 285 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 273 alternate_protocol->SetInteger("port", 80); | 286 alternate_protocol->SetInteger("port", 80); |
| 274 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 287 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 275 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 288 base::ListValue* alternative_services = new base::ListValue; |
| 276 alternate_protocol); | 289 alternative_services->Append(alternate_protocol); |
| 290 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
| 291 alternative_services); |
| 277 | 292 |
| 278 // Set up SupportsQuic for www.google.com:65536. | 293 // Set up SupportsQuic for www.google.com:65536. |
| 279 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 294 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 280 supports_quic->SetBoolean("used_quic", true); | 295 supports_quic->SetBoolean("used_quic", true); |
| 281 supports_quic->SetString("address", "foo"); | 296 supports_quic->SetString("address", "foo"); |
| 282 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); | 297 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); |
| 283 | 298 |
| 284 // Set up ServerNetworkStats for www.google.com:65536. | 299 // Set up ServerNetworkStats for www.google.com:65536. |
| 285 base::DictionaryValue* stats = new base::DictionaryValue; | 300 base::DictionaryValue* stats = new base::DictionaryValue; |
| 286 stats->SetInteger("srtt", 10); | 301 stats->SetInteger("srtt", 10); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 335 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
| 321 ExpectCacheUpdate(); | 336 ExpectCacheUpdate(); |
| 322 // The prefs are automaticalls updated in the case corruption is detected. | 337 // The prefs are automaticalls updated in the case corruption is detected. |
| 323 ExpectPrefsUpdate(); | 338 ExpectPrefsUpdate(); |
| 324 | 339 |
| 325 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 340 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 326 | 341 |
| 327 // Set supports_spdy for www.google.com:80. | 342 // Set supports_spdy for www.google.com:80. |
| 328 server_pref_dict->SetBoolean("supports_spdy", true); | 343 server_pref_dict->SetBoolean("supports_spdy", true); |
| 329 | 344 |
| 330 // Set up alternate_protocol for www.google.com:80. | 345 // Set up alternative_services for www.google.com:80. |
| 331 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 346 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 332 alternate_protocol->SetInteger("port", 65536); | 347 alternate_protocol->SetInteger("port", 65536); |
| 333 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 348 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 334 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 349 base::ListValue* alternative_services = new base::ListValue; |
| 335 alternate_protocol); | 350 alternative_services->Append(alternate_protocol); |
| 351 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
| 352 alternative_services); |
| 336 | 353 |
| 337 // Set the server preference for www.google.com:80. | 354 // Set the server preference for www.google.com:80. |
| 338 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 355 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 339 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 356 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
| 340 | 357 |
| 341 base::DictionaryValue* http_server_properties_dict = | 358 base::DictionaryValue* http_server_properties_dict = |
| 342 new base::DictionaryValue; | 359 new base::DictionaryValue; |
| 343 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 360 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 344 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 361 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 345 | 362 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 490 |
| 474 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 491 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 475 } | 492 } |
| 476 | 493 |
| 477 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { | 494 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { |
| 478 ExpectPrefsUpdate(); | 495 ExpectPrefsUpdate(); |
| 479 | 496 |
| 480 HostPortPair spdy_server_mail("mail.google.com", 80); | 497 HostPortPair spdy_server_mail("mail.google.com", 80); |
| 481 EXPECT_FALSE( | 498 EXPECT_FALSE( |
| 482 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 499 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 483 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 500 http_server_props_manager_->AddAlternateProtocol(spdy_server_mail, 443, |
| 484 NPN_SPDY_3, 1); | 501 NPN_SPDY_3, 1); |
| 485 | 502 |
| 486 // Run the task. | 503 // Run the task. |
| 487 base::RunLoop().RunUntilIdle(); | 504 base::RunLoop().RunUntilIdle(); |
| 488 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 505 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 489 | 506 |
| 490 ASSERT_TRUE( | |
| 491 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | |
| 492 AlternateProtocolInfo port_alternate_protocol = | 507 AlternateProtocolInfo port_alternate_protocol = |
| 493 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 508 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
| 494 EXPECT_EQ(443, port_alternate_protocol.port); | 509 EXPECT_EQ(443, port_alternate_protocol.port); |
| 495 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 510 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
| 496 } | 511 } |
| 497 | 512 |
| 498 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { | 513 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { |
| 499 ExpectPrefsUpdate(); | 514 ExpectPrefsUpdate(); |
| 500 | 515 |
| 501 HostPortPair quic_server_mail("mail.google.com", 80); | 516 HostPortPair quic_server_mail("mail.google.com", 80); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 const ServerNetworkStats* stats2 = | 548 const ServerNetworkStats* stats2 = |
| 534 http_server_props_manager_->GetServerNetworkStats(mail_server); | 549 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 535 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 550 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 536 } | 551 } |
| 537 | 552 |
| 538 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 553 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
| 539 ExpectPrefsUpdate(); | 554 ExpectPrefsUpdate(); |
| 540 | 555 |
| 541 HostPortPair spdy_server_mail("mail.google.com", 443); | 556 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 542 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 557 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 543 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 558 http_server_props_manager_->AddAlternateProtocol(spdy_server_mail, 443, |
| 544 NPN_SPDY_3, 1); | 559 NPN_SPDY_3, 1); |
| 545 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); | 560 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); |
| 546 ServerNetworkStats stats; | 561 ServerNetworkStats stats; |
| 547 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 562 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
| 548 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 563 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); |
| 549 | 564 |
| 550 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 565 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 551 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 566 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 552 const uint32 value1 = 31337; | 567 const uint32 value1 = 31337; |
| 553 http_server_props_manager_->SetSpdySetting( | 568 http_server_props_manager_->SetSpdySetting( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 611 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 597 EXPECT_EQ(NULL, stats2); | 612 EXPECT_EQ(NULL, stats2); |
| 598 | 613 |
| 599 const SettingsMap& settings_map2_ret = | 614 const SettingsMap& settings_map2_ret = |
| 600 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 615 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 601 EXPECT_EQ(0U, settings_map2_ret.size()); | 616 EXPECT_EQ(0U, settings_map2_ret.size()); |
| 602 | 617 |
| 603 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 618 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 604 } | 619 } |
| 605 | 620 |
| 606 // crbug.com/444956: Add 200 alternate_protocol servers followed by | 621 // https://crbug.com/444956: Add 200 alternate_protocol servers followed by |
| 607 // supports_quic and verify we have read supports_quic from prefs. | 622 // supports_quic and verify we have read supports_quic from prefs. |
| 608 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { | 623 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
| 609 ExpectCacheUpdate(); | 624 ExpectCacheUpdate(); |
| 610 | 625 |
| 611 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 626 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 612 | 627 |
| 613 for (int i = 0; i < 200; ++i) { | 628 for (int i = 0; i < 200; ++i) { |
| 614 // Set up alternate_protocol for www.google.com:i. | 629 // Set up alternate_protocol for www.google.com:i. |
| 615 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 630 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 616 alternate_protocol->SetInteger("port", i); | 631 alternate_protocol->SetInteger("port", i); |
| 617 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 632 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 633 base::ListValue* alternative_services = new base::ListValue; |
| 634 alternative_services->Append(alternate_protocol); |
| 618 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 635 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 619 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 636 server_pref_dict->SetWithoutPathExpansion("alternative_services", |
| 620 alternate_protocol); | 637 alternative_services); |
| 621 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), | 638 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), |
| 622 server_pref_dict); | 639 server_pref_dict); |
| 623 } | 640 } |
| 624 | 641 |
| 625 // Set the preference for mail.google.com server. | 642 // Set the preference for mail.google.com server. |
| 626 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 643 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 627 // Set up SupportsQuic for mail.google.com:80 | 644 // Set up SupportsQuic for mail.google.com:80 |
| 628 base::DictionaryValue* supports_quic = new base::DictionaryValue; | 645 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 629 supports_quic->SetBoolean("used_quic", true); | 646 supports_quic->SetBoolean("used_quic", true); |
| 630 supports_quic->SetString("address", "bar"); | 647 supports_quic->SetString("address", "bar"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 642 // Set up the pref. | 659 // Set up the pref. |
| 643 pref_service_.SetManagedPref(kTestHttpServerProperties, | 660 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 644 http_server_properties_dict); | 661 http_server_properties_dict); |
| 645 | 662 |
| 646 base::RunLoop().RunUntilIdle(); | 663 base::RunLoop().RunUntilIdle(); |
| 647 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 664 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 648 | 665 |
| 649 // Verify AlternateProtocol. | 666 // Verify AlternateProtocol. |
| 650 for (int i = 0; i < 200; ++i) { | 667 for (int i = 0; i < 200; ++i) { |
| 651 std::string server = StringPrintf("www.google.com:%d", i); | 668 std::string server = StringPrintf("www.google.com:%d", i); |
| 652 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | 669 AlternateProtocolInfo port_alternate_protocol = |
| 653 net::HostPortPair::FromString(server))); | |
| 654 net::AlternateProtocolInfo port_alternate_protocol = | |
| 655 http_server_props_manager_->GetAlternateProtocol( | 670 http_server_props_manager_->GetAlternateProtocol( |
| 656 net::HostPortPair::FromString(server)); | 671 HostPortPair::FromString(server)); |
| 657 EXPECT_EQ(i, port_alternate_protocol.port); | 672 EXPECT_EQ(i, port_alternate_protocol.port); |
| 658 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); | 673 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
| 659 } | 674 } |
| 660 | 675 |
| 661 // Verify SupportsQuic. | 676 // Verify SupportsQuic. |
| 662 net::SupportsQuic supports_quic1 = | 677 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( |
| 663 http_server_props_manager_->GetSupportsQuic( | 678 HostPortPair::FromString("mail.google.com:80")); |
| 664 net::HostPortPair::FromString("mail.google.com:80")); | |
| 665 EXPECT_TRUE(supports_quic1.used_quic); | 679 EXPECT_TRUE(supports_quic1.used_quic); |
| 666 EXPECT_EQ("bar", supports_quic1.address); | 680 EXPECT_EQ("bar", supports_quic1.address); |
| 667 } | 681 } |
| 668 | 682 |
| 669 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 683 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
| 670 // Post an update task to the UI thread. | 684 // Post an update task to the UI thread. |
| 671 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 685 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 672 // Shutdown comes before the task is executed. | 686 // Shutdown comes before the task is executed. |
| 673 http_server_props_manager_->ShutdownOnPrefThread(); | 687 http_server_props_manager_->ShutdownOnPrefThread(); |
| 674 http_server_props_manager_.reset(); | 688 http_server_props_manager_.reset(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 // Run the task after shutdown, but before deletion. | 748 // Run the task after shutdown, but before deletion. |
| 735 base::RunLoop().RunUntilIdle(); | 749 base::RunLoop().RunUntilIdle(); |
| 736 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 750 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 737 http_server_props_manager_.reset(); | 751 http_server_props_manager_.reset(); |
| 738 base::RunLoop().RunUntilIdle(); | 752 base::RunLoop().RunUntilIdle(); |
| 739 } | 753 } |
| 740 | 754 |
| 741 } // namespace | 755 } // namespace |
| 742 | 756 |
| 743 } // namespace net | 757 } // namespace net |
| OLD | NEW |