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