| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/net/http_server_properties_manager.h" | 5 #include "chrome/browser/net/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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 HttpServerPropertiesManager::StartCacheUpdateTimerOnUI( | 54 HttpServerPropertiesManager::StartCacheUpdateTimerOnUI( |
| 55 base::TimeDelta()); | 55 base::TimeDelta()); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void UpdatePrefsFromCacheOnIOConcrete(const base::Closure& callback) { | 58 void UpdatePrefsFromCacheOnIOConcrete(const base::Closure& callback) { |
| 59 HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(callback); | 59 HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(callback); |
| 60 } | 60 } |
| 61 | 61 |
| 62 MOCK_METHOD0(UpdateCacheFromPrefsOnUI, void()); | 62 MOCK_METHOD0(UpdateCacheFromPrefsOnUI, void()); |
| 63 MOCK_METHOD1(UpdatePrefsFromCacheOnIO, void(const base::Closure&)); | 63 MOCK_METHOD1(UpdatePrefsFromCacheOnIO, void(const base::Closure&)); |
| 64 MOCK_METHOD6(UpdateCacheFromPrefsOnIO, | 64 MOCK_METHOD5(UpdateCacheFromPrefsOnIO, |
| 65 void(std::vector<std::string>* spdy_servers, | 65 void(std::vector<std::string>* spdy_servers, |
| 66 net::SpdySettingsMap* spdy_settings_map, | 66 net::SpdySettingsMap* spdy_settings_map, |
| 67 net::AlternateProtocolMap* alternate_protocol_map, | 67 net::AlternateProtocolMap* alternate_protocol_map, |
| 68 net::PipelineCapabilityMap* pipeline_capability_map, | |
| 69 net::AlternateProtocolExperiment experiment, | 68 net::AlternateProtocolExperiment experiment, |
| 70 bool detected_corrupted_prefs)); | 69 bool detected_corrupted_prefs)); |
| 71 MOCK_METHOD4(UpdatePrefsOnUI, | 70 MOCK_METHOD3(UpdatePrefsOnUI, |
| 72 void(base::ListValue* spdy_server_list, | 71 void(base::ListValue* spdy_server_list, |
| 73 net::SpdySettingsMap* spdy_settings_map, | 72 net::SpdySettingsMap* spdy_settings_map, |
| 74 net::AlternateProtocolMap* alternate_protocol_map, | 73 net::AlternateProtocolMap* alternate_protocol_map)); |
| 75 net::PipelineCapabilityMap* pipeline_capability_map)); | |
| 76 | 74 |
| 77 private: | 75 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); | 76 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); |
| 79 }; | 77 }; |
| 80 | 78 |
| 81 class HttpServerPropertiesManagerTest : public testing::Test { | 79 class HttpServerPropertiesManagerTest : public testing::Test { |
| 82 protected: | 80 protected: |
| 83 HttpServerPropertiesManagerTest() | 81 HttpServerPropertiesManagerTest() |
| 84 : ui_thread_(BrowserThread::UI, &loop_), | 82 : ui_thread_(BrowserThread::UI, &loop_), |
| 85 io_thread_(BrowserThread::IO, &loop_) { | 83 io_thread_(BrowserThread::IO, &loop_) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 // Set supports_spdy for www.google.com:80. | 148 // Set supports_spdy for www.google.com:80. |
| 151 server_pref_dict->SetBoolean("supports_spdy", true); | 149 server_pref_dict->SetBoolean("supports_spdy", true); |
| 152 | 150 |
| 153 // Set up alternate_protocol for www.google.com:80. | 151 // Set up alternate_protocol for www.google.com:80. |
| 154 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 152 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 155 alternate_protocol->SetInteger("port", 443); | 153 alternate_protocol->SetInteger("port", 443); |
| 156 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 154 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
| 157 server_pref_dict->SetWithoutPathExpansion( | 155 server_pref_dict->SetWithoutPathExpansion( |
| 158 "alternate_protocol", alternate_protocol); | 156 "alternate_protocol", alternate_protocol); |
| 159 | 157 |
| 160 // Set pipeline capability for www.google.com:80. | |
| 161 server_pref_dict->SetInteger("pipeline_capability", net::PIPELINE_CAPABLE); | |
| 162 | |
| 163 // Set the server preference for www.google.com:80. | 158 // Set the server preference for www.google.com:80. |
| 164 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 159 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 165 servers_dict->SetWithoutPathExpansion( | 160 servers_dict->SetWithoutPathExpansion( |
| 166 "www.google.com:80", server_pref_dict); | 161 "www.google.com:80", server_pref_dict); |
| 167 | 162 |
| 168 // Set the preference for mail.google.com server. | 163 // Set the preference for mail.google.com server. |
| 169 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 164 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
| 170 | 165 |
| 171 // Set supports_spdy for mail.google.com:80 | 166 // Set supports_spdy for mail.google.com:80 |
| 172 server_pref_dict1->SetBoolean("supports_spdy", true); | 167 server_pref_dict1->SetBoolean("supports_spdy", true); |
| 173 | 168 |
| 174 // Set up alternate_protocol for mail.google.com:80 | 169 // Set up alternate_protocol for mail.google.com:80 |
| 175 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; | 170 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; |
| 176 alternate_protocol1->SetInteger("port", 444); | 171 alternate_protocol1->SetInteger("port", 444); |
| 177 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); | 172 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); |
| 178 | 173 |
| 179 server_pref_dict1->SetWithoutPathExpansion( | 174 server_pref_dict1->SetWithoutPathExpansion( |
| 180 "alternate_protocol", alternate_protocol1); | 175 "alternate_protocol", alternate_protocol1); |
| 181 | 176 |
| 182 // Set pipelining capability for mail.google.com:80 | |
| 183 server_pref_dict1->SetInteger("pipeline_capability", net::PIPELINE_INCAPABLE); | |
| 184 | |
| 185 // Set the server preference for mail.google.com:80. | 177 // Set the server preference for mail.google.com:80. |
| 186 servers_dict->SetWithoutPathExpansion( | 178 servers_dict->SetWithoutPathExpansion( |
| 187 "mail.google.com:80", server_pref_dict1); | 179 "mail.google.com:80", server_pref_dict1); |
| 188 | 180 |
| 189 base::DictionaryValue* http_server_properties_dict = | 181 base::DictionaryValue* http_server_properties_dict = |
| 190 new base::DictionaryValue; | 182 new base::DictionaryValue; |
| 191 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 183 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
| 192 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 184 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 193 | 185 |
| 194 // Set the same value for kHttpServerProperties multiple times. | 186 // Set the same value for kHttpServerProperties multiple times. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 218 net::PortAlternateProtocolPair port_alternate_protocol = | 210 net::PortAlternateProtocolPair port_alternate_protocol = |
| 219 http_server_props_manager_->GetAlternateProtocol( | 211 http_server_props_manager_->GetAlternateProtocol( |
| 220 net::HostPortPair::FromString("www.google.com:80")); | 212 net::HostPortPair::FromString("www.google.com:80")); |
| 221 EXPECT_EQ(443, port_alternate_protocol.port); | 213 EXPECT_EQ(443, port_alternate_protocol.port); |
| 222 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); | 214 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); |
| 223 port_alternate_protocol = | 215 port_alternate_protocol = |
| 224 http_server_props_manager_->GetAlternateProtocol( | 216 http_server_props_manager_->GetAlternateProtocol( |
| 225 net::HostPortPair::FromString("mail.google.com:80")); | 217 net::HostPortPair::FromString("mail.google.com:80")); |
| 226 EXPECT_EQ(444, port_alternate_protocol.port); | 218 EXPECT_EQ(444, port_alternate_protocol.port); |
| 227 EXPECT_EQ(net::NPN_SPDY_3_1, port_alternate_protocol.protocol); | 219 EXPECT_EQ(net::NPN_SPDY_3_1, port_alternate_protocol.protocol); |
| 228 | |
| 229 // Verify pipeline capability. | |
| 230 EXPECT_EQ(net::PIPELINE_CAPABLE, | |
| 231 http_server_props_manager_->GetPipelineCapability( | |
| 232 net::HostPortPair::FromString("www.google.com:80"))); | |
| 233 EXPECT_EQ(net::PIPELINE_INCAPABLE, | |
| 234 http_server_props_manager_->GetPipelineCapability( | |
| 235 net::HostPortPair::FromString("mail.google.com:80"))); | |
| 236 } | 220 } |
| 237 | 221 |
| 238 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 222 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
| 239 ExpectPrefsUpdate(); | 223 ExpectPrefsUpdate(); |
| 240 | 224 |
| 241 // Post an update task to the IO thread. SetSupportsSpdy calls | 225 // Post an update task to the IO thread. SetSupportsSpdy calls |
| 242 // ScheduleUpdatePrefsOnIO. | 226 // ScheduleUpdatePrefsOnIO. |
| 243 | 227 |
| 244 // Add mail.google.com:443 as a supporting spdy server. | 228 // Add mail.google.com:443 as a supporting spdy server. |
| 245 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 229 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 352 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 369 | 353 |
| 370 ASSERT_TRUE( | 354 ASSERT_TRUE( |
| 371 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 355 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 372 net::PortAlternateProtocolPair port_alternate_protocol = | 356 net::PortAlternateProtocolPair port_alternate_protocol = |
| 373 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 357 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
| 374 EXPECT_EQ(443, port_alternate_protocol.port); | 358 EXPECT_EQ(443, port_alternate_protocol.port); |
| 375 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); | 359 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); |
| 376 } | 360 } |
| 377 | 361 |
| 378 TEST_F(HttpServerPropertiesManagerTest, PipelineCapability) { | |
| 379 ExpectPrefsUpdate(); | |
| 380 | |
| 381 net::HostPortPair known_pipeliner("pipeline.com", 8080); | |
| 382 net::HostPortPair bad_pipeliner("wordpress.com", 80); | |
| 383 EXPECT_EQ(net::PIPELINE_UNKNOWN, | |
| 384 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); | |
| 385 EXPECT_EQ(net::PIPELINE_UNKNOWN, | |
| 386 http_server_props_manager_->GetPipelineCapability(bad_pipeliner)); | |
| 387 | |
| 388 // Post an update task to the IO thread. SetPipelineCapability calls | |
| 389 // ScheduleUpdatePrefsOnIO. | |
| 390 http_server_props_manager_->SetPipelineCapability(known_pipeliner, | |
| 391 net::PIPELINE_CAPABLE); | |
| 392 http_server_props_manager_->SetPipelineCapability(bad_pipeliner, | |
| 393 net::PIPELINE_INCAPABLE); | |
| 394 | |
| 395 // Run the task. | |
| 396 loop_.RunUntilIdle(); | |
| 397 | |
| 398 EXPECT_EQ(net::PIPELINE_CAPABLE, | |
| 399 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); | |
| 400 EXPECT_EQ(net::PIPELINE_INCAPABLE, | |
| 401 http_server_props_manager_->GetPipelineCapability(bad_pipeliner)); | |
| 402 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | |
| 403 } | |
| 404 | |
| 405 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 362 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
| 406 ExpectPrefsUpdate(); | 363 ExpectPrefsUpdate(); |
| 407 | 364 |
| 408 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 365 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
| 409 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 366 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 410 http_server_props_manager_->SetAlternateProtocol( | 367 http_server_props_manager_->SetAlternateProtocol( |
| 411 spdy_server_mail, 443, net::NPN_SPDY_3); | 368 spdy_server_mail, 443, net::NPN_SPDY_3); |
| 412 | 369 |
| 413 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; | 370 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; |
| 414 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; | 371 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; |
| 415 const uint32 value1 = 31337; | 372 const uint32 value1 = 31337; |
| 416 http_server_props_manager_->SetSpdySetting( | 373 http_server_props_manager_->SetSpdySetting( |
| 417 spdy_server_mail, id1, flags1, value1); | 374 spdy_server_mail, id1, flags1, value1); |
| 418 | 375 |
| 419 net::HostPortPair known_pipeliner("pipeline.com", 8080); | |
| 420 http_server_props_manager_->SetPipelineCapability(known_pipeliner, | |
| 421 net::PIPELINE_CAPABLE); | |
| 422 | |
| 423 // Run the task. | 376 // Run the task. |
| 424 loop_.RunUntilIdle(); | 377 loop_.RunUntilIdle(); |
| 425 | 378 |
| 426 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 379 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
| 427 EXPECT_TRUE( | 380 EXPECT_TRUE( |
| 428 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 381 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 429 | 382 |
| 430 // Check SPDY settings values. | 383 // Check SPDY settings values. |
| 431 const net::SettingsMap& settings_map1_ret = | 384 const net::SettingsMap& settings_map1_ret = |
| 432 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 385 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 433 ASSERT_EQ(1U, settings_map1_ret.size()); | 386 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 434 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 387 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 435 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 388 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 436 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 389 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 437 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 390 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 438 EXPECT_EQ(value1, flags_and_value1_ret.second); | 391 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 439 | 392 |
| 440 EXPECT_EQ(net::PIPELINE_CAPABLE, | |
| 441 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); | |
| 442 | |
| 443 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 393 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 444 | 394 |
| 445 ExpectPrefsUpdate(); | 395 ExpectPrefsUpdate(); |
| 446 | 396 |
| 447 // Clear http server data, time out if we do not get a completion callback. | 397 // Clear http server data, time out if we do not get a completion callback. |
| 448 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); | 398 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); |
| 449 loop_.Run(); | 399 loop_.Run(); |
| 450 | 400 |
| 451 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 401 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
| 452 EXPECT_FALSE( | 402 EXPECT_FALSE( |
| 453 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 403 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 454 | 404 |
| 455 const net::SettingsMap& settings_map2_ret = | 405 const net::SettingsMap& settings_map2_ret = |
| 456 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 406 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 457 EXPECT_EQ(0U, settings_map2_ret.size()); | 407 EXPECT_EQ(0U, settings_map2_ret.size()); |
| 458 | 408 |
| 459 EXPECT_EQ(net::PIPELINE_UNKNOWN, | |
| 460 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); | |
| 461 | |
| 462 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 409 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 463 } | 410 } |
| 464 | 411 |
| 465 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 412 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
| 466 // Post an update task to the UI thread. | 413 // Post an update task to the UI thread. |
| 467 http_server_props_manager_->ScheduleUpdateCacheOnUI(); | 414 http_server_props_manager_->ScheduleUpdateCacheOnUI(); |
| 468 // Shutdown comes before the task is executed. | 415 // Shutdown comes before the task is executed. |
| 469 http_server_props_manager_->ShutdownOnUIThread(); | 416 http_server_props_manager_->ShutdownOnUIThread(); |
| 470 http_server_props_manager_.reset(); | 417 http_server_props_manager_.reset(); |
| 471 // Run the task after shutdown and deletion. | 418 // Run the task after shutdown and deletion. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 // Run the task after shutdown, but before deletion. | 476 // Run the task after shutdown, but before deletion. |
| 530 loop_.RunUntilIdle(); | 477 loop_.RunUntilIdle(); |
| 531 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 478 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 532 http_server_props_manager_.reset(); | 479 http_server_props_manager_.reset(); |
| 533 loop_.RunUntilIdle(); | 480 loop_.RunUntilIdle(); |
| 534 } | 481 } |
| 535 | 482 |
| 536 } // namespace | 483 } // namespace |
| 537 | 484 |
| 538 } // namespace chrome_browser_net | 485 } // namespace chrome_browser_net |
| OLD | NEW |