| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 const base::Closure& callback) { | 67 const base::Closure& callback) { |
| 68 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); | 68 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); |
| 69 } | 69 } |
| 70 | 70 |
| 71 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); | 71 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); |
| 72 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); | 72 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); |
| 73 MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread, | 73 MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread, |
| 74 void(std::vector<std::string>* spdy_servers, | 74 void(std::vector<std::string>* spdy_servers, |
| 75 SpdySettingsMap* spdy_settings_map, | 75 SpdySettingsMap* spdy_settings_map, |
| 76 AlternateProtocolMap* alternate_protocol_map, | 76 AlternateProtocolMap* alternate_protocol_map, |
| 77 SupportsQuicMap* supports_quic_map, | 77 IPAddressNumber* last_quic_address, |
| 78 ServerNetworkStatsMap* server_network_stats_map, | 78 ServerNetworkStatsMap* server_network_stats_map, |
| 79 bool detected_corrupted_prefs)); | 79 bool detected_corrupted_prefs)); |
| 80 MOCK_METHOD5(UpdatePrefsOnPref, | 80 MOCK_METHOD5(UpdatePrefsOnPref, |
| 81 void(base::ListValue* spdy_server_list, | 81 void(base::ListValue* spdy_server_list, |
| 82 SpdySettingsMap* spdy_settings_map, | 82 SpdySettingsMap* spdy_settings_map, |
| 83 AlternateProtocolMap* alternate_protocol_map, | 83 AlternateProtocolMap* alternate_protocol_map, |
| 84 SupportsQuicMap* supports_quic_map, | 84 IPAddressNumber* last_quic_address, |
| 85 ServerNetworkStatsMap* server_network_stats_map)); | 85 ServerNetworkStatsMap* server_network_stats_map)); |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); | 88 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 class HttpServerPropertiesManagerTest : public testing::Test { | 91 class HttpServerPropertiesManagerTest : public testing::Test { |
| 92 protected: | 92 protected: |
| 93 HttpServerPropertiesManagerTest() {} | 93 HttpServerPropertiesManagerTest() {} |
| 94 | 94 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // Set supports_spdy for www.google.com:80. | 162 // Set supports_spdy for www.google.com:80. |
| 163 server_pref_dict->SetBoolean("supports_spdy", true); | 163 server_pref_dict->SetBoolean("supports_spdy", true); |
| 164 | 164 |
| 165 // Set up alternate_protocol for www.google.com:80. | 165 // Set up alternate_protocol for www.google.com:80. |
| 166 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 166 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 167 alternate_protocol->SetInteger("port", 443); | 167 alternate_protocol->SetInteger("port", 443); |
| 168 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 168 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 169 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 169 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
| 170 alternate_protocol); | 170 alternate_protocol); |
| 171 | 171 |
| 172 // Set up SupportsQuic for www.google.com:80. | |
| 173 base::DictionaryValue* supports_quic = new base::DictionaryValue; | |
| 174 supports_quic->SetBoolean("used_quic", true); | |
| 175 supports_quic->SetString("address", "foo"); | |
| 176 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); | |
| 177 | |
| 178 // Set up ServerNetworkStats for www.google.com:80. | 172 // Set up ServerNetworkStats for www.google.com:80. |
| 179 base::DictionaryValue* stats = new base::DictionaryValue; | 173 base::DictionaryValue* stats = new base::DictionaryValue; |
| 180 stats->SetInteger("srtt", 10); | 174 stats->SetInteger("srtt", 10); |
| 181 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 175 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
| 182 | 176 |
| 183 // Set the server preference for www.google.com:80. | 177 // Set the server preference for www.google.com:80. |
| 184 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 178 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 185 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 179 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
| 186 | 180 |
| 187 // Set the preference for mail.google.com server. | 181 // Set the preference for mail.google.com server. |
| 188 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 182 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 189 | 183 |
| 190 // Set supports_spdy for mail.google.com:80 | 184 // Set supports_spdy for mail.google.com:80 |
| 191 server_pref_dict1->SetBoolean("supports_spdy", true); | 185 server_pref_dict1->SetBoolean("supports_spdy", true); |
| 192 | 186 |
| 193 // Set up alternate_protocol for mail.google.com:80 | 187 // Set up alternate_protocol for mail.google.com:80 |
| 194 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; | 188 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; |
| 195 alternate_protocol1->SetInteger("port", 444); | 189 alternate_protocol1->SetInteger("port", 444); |
| 196 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); | 190 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); |
| 197 | 191 |
| 198 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", | 192 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", |
| 199 alternate_protocol1); | 193 alternate_protocol1); |
| 200 | 194 |
| 201 // Set up SupportsQuic for mail.google.com:80 | |
| 202 base::DictionaryValue* supports_quic1 = new base::DictionaryValue; | |
| 203 supports_quic1->SetBoolean("used_quic", false); | |
| 204 supports_quic1->SetString("address", "bar"); | |
| 205 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1); | |
| 206 | |
| 207 // Set up ServerNetworkStats for mail.google.com:80. | 195 // Set up ServerNetworkStats for mail.google.com:80. |
| 208 base::DictionaryValue* stats1 = new base::DictionaryValue; | 196 base::DictionaryValue* stats1 = new base::DictionaryValue; |
| 209 stats1->SetInteger("srtt", 20); | 197 stats1->SetInteger("srtt", 20); |
| 210 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); | 198 server_pref_dict1->SetWithoutPathExpansion("network_stats", stats1); |
| 211 // Set the server preference for mail.google.com:80. | 199 // Set the server preference for mail.google.com:80. |
| 212 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 200 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
| 213 server_pref_dict1); | 201 server_pref_dict1); |
| 214 | 202 |
| 215 base::DictionaryValue* http_server_properties_dict = | 203 base::DictionaryValue* http_server_properties_dict = |
| 216 new base::DictionaryValue; | 204 new base::DictionaryValue; |
| 217 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 205 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 218 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 206 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 207 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 208 supports_quic->SetBoolean("used_quic", true); |
| 209 supports_quic->SetString("address", "127.0.0.1"); |
| 210 http_server_properties_dict->SetWithoutPathExpansion("supports_quic", |
| 211 supports_quic); |
| 219 | 212 |
| 220 // Set the same value for kHttpServerProperties multiple times. | 213 // Set the same value for kHttpServerProperties multiple times. |
| 221 pref_service_.SetManagedPref(kTestHttpServerProperties, | 214 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 222 http_server_properties_dict); | 215 http_server_properties_dict); |
| 223 base::DictionaryValue* http_server_properties_dict2 = | 216 base::DictionaryValue* http_server_properties_dict2 = |
| 224 http_server_properties_dict->DeepCopy(); | 217 http_server_properties_dict->DeepCopy(); |
| 225 pref_service_.SetManagedPref(kTestHttpServerProperties, | 218 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 226 http_server_properties_dict2); | 219 http_server_properties_dict2); |
| 227 | 220 |
| 228 base::RunLoop().RunUntilIdle(); | 221 base::RunLoop().RunUntilIdle(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 239 AlternateProtocolInfo port_alternate_protocol = | 232 AlternateProtocolInfo port_alternate_protocol = |
| 240 http_server_props_manager_->GetAlternateProtocol(google_server); | 233 http_server_props_manager_->GetAlternateProtocol(google_server); |
| 241 EXPECT_EQ(443, port_alternate_protocol.port); | 234 EXPECT_EQ(443, port_alternate_protocol.port); |
| 242 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 235 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
| 243 port_alternate_protocol = | 236 port_alternate_protocol = |
| 244 http_server_props_manager_->GetAlternateProtocol(mail_server); | 237 http_server_props_manager_->GetAlternateProtocol(mail_server); |
| 245 EXPECT_EQ(444, port_alternate_protocol.port); | 238 EXPECT_EQ(444, port_alternate_protocol.port); |
| 246 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); | 239 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); |
| 247 | 240 |
| 248 // Verify SupportsQuic. | 241 // Verify SupportsQuic. |
| 249 SupportsQuic supports_quic2 = | 242 IPAddressNumber last_address; |
| 250 http_server_props_manager_->GetSupportsQuic(google_server); | 243 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); |
| 251 EXPECT_TRUE(supports_quic2.used_quic); | 244 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address)); |
| 252 EXPECT_EQ("foo", supports_quic2.address); | |
| 253 supports_quic2 = http_server_props_manager_->GetSupportsQuic(mail_server); | |
| 254 EXPECT_FALSE(supports_quic2.used_quic); | |
| 255 EXPECT_EQ("bar", supports_quic2.address); | |
| 256 | 245 |
| 257 // Verify ServerNetworkStats. | 246 // Verify ServerNetworkStats. |
| 258 const ServerNetworkStats* stats2 = | 247 const ServerNetworkStats* stats2 = |
| 259 http_server_props_manager_->GetServerNetworkStats(google_server); | 248 http_server_props_manager_->GetServerNetworkStats(google_server); |
| 260 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 249 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 261 const ServerNetworkStats* stats3 = | 250 const ServerNetworkStats* stats3 = |
| 262 http_server_props_manager_->GetServerNetworkStats(mail_server); | 251 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 263 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); | 252 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); |
| 264 } | 253 } |
| 265 | 254 |
| 266 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { | 255 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { |
| 267 ExpectCacheUpdate(); | 256 ExpectCacheUpdate(); |
| 268 // The prefs are automaticalls updated in the case corruption is detected. | 257 // The prefs are automaticalls updated in the case corruption is detected. |
| 269 ExpectPrefsUpdate(); | 258 ExpectPrefsUpdate(); |
| 270 | 259 |
| 271 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 260 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 272 | 261 |
| 273 // Set supports_spdy for www.google.com:65536. | 262 // Set supports_spdy for www.google.com:65536. |
| 274 server_pref_dict->SetBoolean("supports_spdy", true); | 263 server_pref_dict->SetBoolean("supports_spdy", true); |
| 275 | 264 |
| 276 // Set up alternate_protocol for www.google.com:65536. | 265 // Set up alternate_protocol for www.google.com:65536. |
| 277 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 266 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 278 alternate_protocol->SetInteger("port", 80); | 267 alternate_protocol->SetInteger("port", 80); |
| 279 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 268 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 280 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 269 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
| 281 alternate_protocol); | 270 alternate_protocol); |
| 282 | 271 |
| 283 // Set up SupportsQuic for www.google.com:65536. | |
| 284 base::DictionaryValue* supports_quic = new base::DictionaryValue; | |
| 285 supports_quic->SetBoolean("used_quic", true); | |
| 286 supports_quic->SetString("address", "foo"); | |
| 287 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); | |
| 288 | |
| 289 // Set up ServerNetworkStats for www.google.com:65536. | 272 // Set up ServerNetworkStats for www.google.com:65536. |
| 290 base::DictionaryValue* stats = new base::DictionaryValue; | 273 base::DictionaryValue* stats = new base::DictionaryValue; |
| 291 stats->SetInteger("srtt", 10); | 274 stats->SetInteger("srtt", 10); |
| 292 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); | 275 server_pref_dict->SetWithoutPathExpansion("network_stats", stats); |
| 293 | 276 |
| 294 // Set the server preference for www.google.com:65536. | 277 // Set the server preference for www.google.com:65536. |
| 295 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 278 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 296 servers_dict->SetWithoutPathExpansion("www.google.com:65536", | 279 servers_dict->SetWithoutPathExpansion("www.google.com:65536", |
| 297 server_pref_dict); | 280 server_pref_dict); |
| 298 | 281 |
| 299 base::DictionaryValue* http_server_properties_dict = | 282 base::DictionaryValue* http_server_properties_dict = |
| 300 new base::DictionaryValue; | 283 new base::DictionaryValue; |
| 301 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 284 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 302 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 285 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 303 | 286 |
| 304 // Set up the pref. | 287 // Set up the pref. |
| 305 pref_service_.SetManagedPref(kTestHttpServerProperties, | 288 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 306 http_server_properties_dict); | 289 http_server_properties_dict); |
| 307 | 290 |
| 308 base::RunLoop().RunUntilIdle(); | 291 base::RunLoop().RunUntilIdle(); |
| 309 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 292 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 310 | 293 |
| 311 // Verify that nothing is set. | 294 // Verify that nothing is set. |
| 312 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 295 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
| 313 HostPortPair::FromString("www.google.com:65536"))); | 296 HostPortPair::FromString("www.google.com:65536"))); |
| 314 EXPECT_FALSE( | 297 EXPECT_FALSE( |
| 315 HasAlternateProtocol(HostPortPair::FromString("www.google.com:65536"))); | 298 HasAlternateProtocol(HostPortPair::FromString("www.google.com:65536"))); |
| 316 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic( | |
| 317 HostPortPair::FromString("www.google.com:65536")); | |
| 318 EXPECT_FALSE(supports_quic2.used_quic); | |
| 319 const ServerNetworkStats* stats1 = | 299 const ServerNetworkStats* stats1 = |
| 320 http_server_props_manager_->GetServerNetworkStats( | 300 http_server_props_manager_->GetServerNetworkStats( |
| 321 HostPortPair::FromString("www.google.com:65536")); | 301 HostPortPair::FromString("www.google.com:65536")); |
| 322 EXPECT_EQ(NULL, stats1); | 302 EXPECT_EQ(NULL, stats1); |
| 323 } | 303 } |
| 324 | 304 |
| 325 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 305 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
| 326 ExpectCacheUpdate(); | 306 ExpectCacheUpdate(); |
| 327 // The prefs are automaticalls updated in the case corruption is detected. | 307 // The prefs are automaticalls updated in the case corruption is detected. |
| 328 ExpectPrefsUpdate(); | 308 ExpectPrefsUpdate(); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 const AlternateProtocolInfo alternate_protocol = | 476 const AlternateProtocolInfo alternate_protocol = |
| 497 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 477 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
| 498 EXPECT_EQ(443, alternate_protocol.port); | 478 EXPECT_EQ(443, alternate_protocol.port); |
| 499 EXPECT_EQ(NPN_SPDY_3, alternate_protocol.protocol); | 479 EXPECT_EQ(NPN_SPDY_3, alternate_protocol.protocol); |
| 500 EXPECT_EQ(1.0, alternate_protocol.probability); | 480 EXPECT_EQ(1.0, alternate_protocol.probability); |
| 501 } | 481 } |
| 502 | 482 |
| 503 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { | 483 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { |
| 504 ExpectPrefsUpdate(); | 484 ExpectPrefsUpdate(); |
| 505 | 485 |
| 506 HostPortPair quic_server_mail("mail.google.com", 80); | 486 IPAddressNumber address; |
| 507 SupportsQuic supports_quic = | 487 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 508 http_server_props_manager_->GetSupportsQuic(quic_server_mail); | 488 |
| 509 EXPECT_FALSE(supports_quic.used_quic); | 489 IPAddressNumber actual_address; |
| 510 EXPECT_EQ("", supports_quic.address); | 490 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
| 511 http_server_props_manager_->SetSupportsQuic(quic_server_mail, true, "foo"); | 491 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
| 512 | 492 |
| 513 // Run the task. | 493 // Run the task. |
| 514 base::RunLoop().RunUntilIdle(); | 494 base::RunLoop().RunUntilIdle(); |
| 515 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 495 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 516 | 496 |
| 517 SupportsQuic supports_quic1 = | 497 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 518 http_server_props_manager_->GetSupportsQuic(quic_server_mail); | 498 EXPECT_EQ(actual_address, address); |
| 519 EXPECT_TRUE(supports_quic1.used_quic); | |
| 520 EXPECT_EQ("foo", supports_quic1.address); | |
| 521 } | 499 } |
| 522 | 500 |
| 523 TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) { | 501 TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) { |
| 524 ExpectPrefsUpdate(); | 502 ExpectPrefsUpdate(); |
| 525 | 503 |
| 526 HostPortPair mail_server("mail.google.com", 80); | 504 HostPortPair mail_server("mail.google.com", 80); |
| 527 const ServerNetworkStats* stats = | 505 const ServerNetworkStats* stats = |
| 528 http_server_props_manager_->GetServerNetworkStats(mail_server); | 506 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 529 EXPECT_EQ(NULL, stats); | 507 EXPECT_EQ(NULL, stats); |
| 530 ServerNetworkStats stats1; | 508 ServerNetworkStats stats1; |
| 531 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 509 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 532 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); | 510 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); |
| 533 | 511 |
| 534 // Run the task. | 512 // Run the task. |
| 535 base::RunLoop().RunUntilIdle(); | 513 base::RunLoop().RunUntilIdle(); |
| 536 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 514 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 537 | 515 |
| 538 const ServerNetworkStats* stats2 = | 516 const ServerNetworkStats* stats2 = |
| 539 http_server_props_manager_->GetServerNetworkStats(mail_server); | 517 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 540 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 518 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 541 } | 519 } |
| 542 | 520 |
| 543 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 521 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
| 544 ExpectPrefsUpdate(); | 522 ExpectPrefsUpdate(); |
| 545 | 523 |
| 546 HostPortPair spdy_server_mail("mail.google.com", 443); | 524 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 547 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 525 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 548 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 526 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, |
| 549 NPN_SPDY_3, 1.0); | 527 NPN_SPDY_3, 1.0); |
| 550 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); | 528 IPAddressNumber actual_address; |
| 529 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
| 530 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
| 551 ServerNetworkStats stats; | 531 ServerNetworkStats stats; |
| 552 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 532 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
| 553 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 533 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); |
| 554 | 534 |
| 555 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 535 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 556 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 536 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 557 const uint32 value1 = 31337; | 537 const uint32 value1 = 31337; |
| 558 http_server_props_manager_->SetSpdySetting( | 538 http_server_props_manager_->SetSpdySetting( |
| 559 spdy_server_mail, id1, flags1, value1); | 539 spdy_server_mail, id1, flags1, value1); |
| 560 | 540 |
| 561 // Run the task. | 541 // Run the task. |
| 562 base::RunLoop().RunUntilIdle(); | 542 base::RunLoop().RunUntilIdle(); |
| 563 | 543 |
| 564 EXPECT_TRUE( | 544 EXPECT_TRUE( |
| 565 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 545 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
| 566 EXPECT_TRUE(HasAlternateProtocol(spdy_server_mail)); | 546 EXPECT_TRUE(HasAlternateProtocol(spdy_server_mail)); |
| 567 SupportsQuic supports_quic = | 547 IPAddressNumber address; |
| 568 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); | 548 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 569 EXPECT_TRUE(supports_quic.used_quic); | 549 EXPECT_EQ(actual_address, address); |
| 570 EXPECT_EQ("foo", supports_quic.address); | |
| 571 const ServerNetworkStats* stats1 = | 550 const ServerNetworkStats* stats1 = |
| 572 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 551 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 573 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); | 552 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); |
| 574 | 553 |
| 575 // Check SPDY settings values. | 554 // Check SPDY settings values. |
| 576 const SettingsMap& settings_map1_ret = | 555 const SettingsMap& settings_map1_ret = |
| 577 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 556 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 578 ASSERT_EQ(1U, settings_map1_ret.size()); | 557 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 579 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 558 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 580 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 559 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 581 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 560 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 582 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 561 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 583 EXPECT_EQ(value1, flags_and_value1_ret.second); | 562 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 584 | 563 |
| 585 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 564 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 586 | 565 |
| 587 ExpectPrefsUpdate(); | 566 ExpectPrefsUpdate(); |
| 588 | 567 |
| 589 // Clear http server data, time out if we do not get a completion callback. | 568 // Clear http server data, time out if we do not get a completion callback. |
| 590 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); | 569 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); |
| 591 base::RunLoop().Run(); | 570 base::RunLoop().Run(); |
| 592 | 571 |
| 593 EXPECT_FALSE( | 572 EXPECT_FALSE( |
| 594 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 573 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
| 595 EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail)); | 574 EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail)); |
| 596 SupportsQuic supports_quic1 = | 575 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 597 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); | |
| 598 EXPECT_FALSE(supports_quic1.used_quic); | |
| 599 EXPECT_EQ("", supports_quic1.address); | |
| 600 const ServerNetworkStats* stats2 = | 576 const ServerNetworkStats* stats2 = |
| 601 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 577 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 602 EXPECT_EQ(NULL, stats2); | 578 EXPECT_EQ(NULL, stats2); |
| 603 | 579 |
| 604 const SettingsMap& settings_map2_ret = | 580 const SettingsMap& settings_map2_ret = |
| 605 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 581 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 606 EXPECT_EQ(0U, settings_map2_ret.size()); | 582 EXPECT_EQ(0U, settings_map2_ret.size()); |
| 607 | 583 |
| 608 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 584 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 609 } | 585 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 622 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 598 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 623 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 599 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 624 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 600 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
| 625 alternate_protocol); | 601 alternate_protocol); |
| 626 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), | 602 servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), |
| 627 server_pref_dict); | 603 server_pref_dict); |
| 628 } | 604 } |
| 629 | 605 |
| 630 // Set the preference for mail.google.com server. | 606 // Set the preference for mail.google.com server. |
| 631 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 607 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 632 // Set up SupportsQuic for mail.google.com:80 | |
| 633 base::DictionaryValue* supports_quic = new base::DictionaryValue; | |
| 634 supports_quic->SetBoolean("used_quic", true); | |
| 635 supports_quic->SetString("address", "bar"); | |
| 636 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic); | |
| 637 | 608 |
| 638 // Set the server preference for mail.google.com:80. | 609 // Set the server preference for mail.google.com:80. |
| 639 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 610 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
| 640 server_pref_dict1); | 611 server_pref_dict1); |
| 641 | 612 |
| 642 base::DictionaryValue* http_server_properties_dict = | 613 base::DictionaryValue* http_server_properties_dict = |
| 643 new base::DictionaryValue; | 614 new base::DictionaryValue; |
| 644 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 615 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 645 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 616 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 646 | 617 |
| 618 // Set up SupportsQuic for 127.0.0.1 |
| 619 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 620 supports_quic->SetBoolean("used_quic", true); |
| 621 supports_quic->SetString("address", "127.0.0.1"); |
| 622 http_server_properties_dict->SetWithoutPathExpansion("supports_quic", |
| 623 supports_quic); |
| 624 |
| 647 // Set up the pref. | 625 // Set up the pref. |
| 648 pref_service_.SetManagedPref(kTestHttpServerProperties, | 626 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 649 http_server_properties_dict); | 627 http_server_properties_dict); |
| 650 | 628 |
| 651 base::RunLoop().RunUntilIdle(); | 629 base::RunLoop().RunUntilIdle(); |
| 652 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 630 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 653 | 631 |
| 654 // Verify AlternateProtocol. | 632 // Verify AlternateProtocol. |
| 655 for (int i = 0; i < 200; ++i) { | 633 for (int i = 0; i < 200; ++i) { |
| 656 std::string server = StringPrintf("www.google.com:%d", i); | 634 std::string server = StringPrintf("www.google.com:%d", i); |
| 657 AlternateProtocolInfo port_alternate_protocol = | 635 AlternateProtocolInfo port_alternate_protocol = |
| 658 http_server_props_manager_->GetAlternateProtocol( | 636 http_server_props_manager_->GetAlternateProtocol( |
| 659 HostPortPair::FromString(server)); | 637 HostPortPair::FromString(server)); |
| 660 EXPECT_EQ(i, port_alternate_protocol.port); | 638 EXPECT_EQ(i, port_alternate_protocol.port); |
| 661 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 639 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
| 662 } | 640 } |
| 663 | 641 |
| 664 // Verify SupportsQuic. | 642 // Verify SupportsQuic. |
| 665 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( | 643 IPAddressNumber address; |
| 666 HostPortPair::FromString("mail.google.com:80")); | 644 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 667 EXPECT_TRUE(supports_quic1.used_quic); | 645 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); |
| 668 EXPECT_EQ("bar", supports_quic1.address); | |
| 669 } | 646 } |
| 670 | 647 |
| 671 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 648 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
| 672 // Post an update task to the UI thread. | 649 // Post an update task to the UI thread. |
| 673 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 650 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 674 // Shutdown comes before the task is executed. | 651 // Shutdown comes before the task is executed. |
| 675 http_server_props_manager_->ShutdownOnPrefThread(); | 652 http_server_props_manager_->ShutdownOnPrefThread(); |
| 676 http_server_props_manager_.reset(); | 653 http_server_props_manager_.reset(); |
| 677 // Run the task after shutdown and deletion. | 654 // Run the task after shutdown and deletion. |
| 678 base::RunLoop().RunUntilIdle(); | 655 base::RunLoop().RunUntilIdle(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 // Run the task after shutdown, but before deletion. | 713 // Run the task after shutdown, but before deletion. |
| 737 base::RunLoop().RunUntilIdle(); | 714 base::RunLoop().RunUntilIdle(); |
| 738 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 715 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 739 http_server_props_manager_.reset(); | 716 http_server_props_manager_.reset(); |
| 740 base::RunLoop().RunUntilIdle(); | 717 base::RunLoop().RunUntilIdle(); |
| 741 } | 718 } |
| 742 | 719 |
| 743 } // namespace | 720 } // namespace |
| 744 | 721 |
| 745 } // namespace net | 722 } // namespace net |
| OLD | NEW |