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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 http_server_props_manager_->GetSupportsQuic( | 234 http_server_props_manager_->GetSupportsQuic( |
235 net::HostPortPair::FromString("www.google.com:80")); | 235 net::HostPortPair::FromString("www.google.com:80")); |
236 EXPECT_TRUE(supports_quic2.used_quic); | 236 EXPECT_TRUE(supports_quic2.used_quic); |
237 EXPECT_EQ("foo", supports_quic2.address); | 237 EXPECT_EQ("foo", supports_quic2.address); |
238 supports_quic2 = http_server_props_manager_->GetSupportsQuic( | 238 supports_quic2 = http_server_props_manager_->GetSupportsQuic( |
239 net::HostPortPair::FromString("mail.google.com:80")); | 239 net::HostPortPair::FromString("mail.google.com:80")); |
240 EXPECT_FALSE(supports_quic2.used_quic); | 240 EXPECT_FALSE(supports_quic2.used_quic); |
241 EXPECT_EQ("bar", supports_quic2.address); | 241 EXPECT_EQ("bar", supports_quic2.address); |
242 } | 242 } |
243 | 243 |
| 244 TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { |
| 245 ExpectCacheUpdate(); |
| 246 // The prefs are automaticalls updated in the case corruption is detected. |
| 247 ExpectPrefsUpdate(); |
| 248 |
| 249 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 250 |
| 251 // Set supports_spdy for www.google.com:65536. |
| 252 server_pref_dict->SetBoolean("supports_spdy", true); |
| 253 |
| 254 // Set up alternate_protocol for www.google.com:65536. |
| 255 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 256 alternate_protocol->SetInteger("port", 80); |
| 257 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 258 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
| 259 alternate_protocol); |
| 260 |
| 261 // Set up SupportsQuic for www.google.com:65536. |
| 262 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 263 supports_quic->SetBoolean("used_quic", true); |
| 264 supports_quic->SetString("address", "foo"); |
| 265 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); |
| 266 |
| 267 // Set the server preference for www.google.com:65536. |
| 268 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 269 servers_dict->SetWithoutPathExpansion("www.google.com:65536", |
| 270 server_pref_dict); |
| 271 |
| 272 base::DictionaryValue* http_server_properties_dict = |
| 273 new base::DictionaryValue; |
| 274 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 275 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 276 |
| 277 // Set up the pref. |
| 278 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 279 http_server_properties_dict); |
| 280 |
| 281 base::RunLoop().RunUntilIdle(); |
| 282 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 283 |
| 284 // Verify that nothing is set. |
| 285 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( |
| 286 net::HostPortPair::FromString("www.google.com:65536"))); |
| 287 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( |
| 288 net::HostPortPair::FromString("www.google.com:65536"))); |
| 289 net::SupportsQuic supports_quic2 = |
| 290 http_server_props_manager_->GetSupportsQuic( |
| 291 net::HostPortPair::FromString("www.google.com:65536")); |
| 292 EXPECT_FALSE(supports_quic2.used_quic); |
| 293 } |
| 294 |
| 295 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
| 296 ExpectCacheUpdate(); |
| 297 // The prefs are automaticalls updated in the case corruption is detected. |
| 298 ExpectPrefsUpdate(); |
| 299 |
| 300 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 301 |
| 302 // Set supports_spdy for www.google.com:80. |
| 303 server_pref_dict->SetBoolean("supports_spdy", true); |
| 304 |
| 305 // Set up alternate_protocol for www.google.com:80. |
| 306 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 307 alternate_protocol->SetInteger("port", 65536); |
| 308 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 309 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
| 310 alternate_protocol); |
| 311 |
| 312 // Set the server preference for www.google.com:80. |
| 313 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 314 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
| 315 |
| 316 base::DictionaryValue* http_server_properties_dict = |
| 317 new base::DictionaryValue; |
| 318 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 319 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 320 |
| 321 // Set up the pref. |
| 322 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 323 http_server_properties_dict); |
| 324 |
| 325 base::RunLoop().RunUntilIdle(); |
| 326 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 327 |
| 328 // Verify AlternateProtocol is not set. |
| 329 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( |
| 330 net::HostPortPair::FromString("www.google.com:80"))); |
| 331 } |
| 332 |
244 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 333 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
245 ExpectPrefsUpdate(); | 334 ExpectPrefsUpdate(); |
246 | 335 |
247 // Post an update task to the network thread. SetSupportsSpdy calls | 336 // Post an update task to the network thread. SetSupportsSpdy calls |
248 // ScheduleUpdatePrefsOnNetworkThread. | 337 // ScheduleUpdatePrefsOnNetworkThread. |
249 | 338 |
250 // Add mail.google.com:443 as a supporting spdy server. | 339 // Add mail.google.com:443 as a supporting spdy server. |
251 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 340 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
252 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 341 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
253 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 342 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 // Run the task after shutdown, but before deletion. | 617 // Run the task after shutdown, but before deletion. |
529 base::RunLoop().RunUntilIdle(); | 618 base::RunLoop().RunUntilIdle(); |
530 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 619 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
531 http_server_props_manager_.reset(); | 620 http_server_props_manager_.reset(); |
532 base::RunLoop().RunUntilIdle(); | 621 base::RunLoop().RunUntilIdle(); |
533 } | 622 } |
534 | 623 |
535 } // namespace | 624 } // namespace |
536 | 625 |
537 } // namespace net | 626 } // namespace net |
OLD | NEW |