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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 base::TimeDelta()); | 60 base::TimeDelta()); |
61 } | 61 } |
62 | 62 |
63 void UpdatePrefsFromCacheOnNetworkThreadConcrete( | 63 void UpdatePrefsFromCacheOnNetworkThreadConcrete( |
64 const base::Closure& callback) { | 64 const base::Closure& callback) { |
65 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); | 65 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); |
66 } | 66 } |
67 | 67 |
68 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); | 68 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); |
69 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); | 69 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); |
70 MOCK_METHOD5(UpdateCacheFromPrefsOnNetworkThread, | 70 MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread, |
71 void(std::vector<std::string>* spdy_servers, | 71 void(std::vector<std::string>* spdy_servers, |
72 net::SpdySettingsMap* spdy_settings_map, | 72 net::SpdySettingsMap* spdy_settings_map, |
73 net::AlternateProtocolMap* alternate_protocol_map, | 73 net::AlternateProtocolMap* alternate_protocol_map, |
74 net::AlternateProtocolExperiment experiment, | 74 net::AlternateProtocolExperiment experiment, |
| 75 net::SupportsQuicMap* supports_quic_map, |
75 bool detected_corrupted_prefs)); | 76 bool detected_corrupted_prefs)); |
76 MOCK_METHOD3(UpdatePrefsOnPref, | 77 MOCK_METHOD4(UpdatePrefsOnPref, |
77 void(base::ListValue* spdy_server_list, | 78 void(base::ListValue* spdy_server_list, |
78 net::SpdySettingsMap* spdy_settings_map, | 79 net::SpdySettingsMap* spdy_settings_map, |
79 net::AlternateProtocolMap* alternate_protocol_map)); | 80 net::AlternateProtocolMap* alternate_protocol_map, |
| 81 net::SupportsQuicMap* supports_quic_map)); |
80 | 82 |
81 private: | 83 private: |
82 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); | 84 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); |
83 }; | 85 }; |
84 | 86 |
85 class HttpServerPropertiesManagerTest : public testing::Test { | 87 class HttpServerPropertiesManagerTest : public testing::Test { |
86 protected: | 88 protected: |
87 HttpServerPropertiesManagerTest() {} | 89 HttpServerPropertiesManagerTest() {} |
88 | 90 |
89 virtual void SetUp() OVERRIDE { | 91 virtual void SetUp() OVERRIDE { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 // Set supports_spdy for www.google.com:80. | 150 // Set supports_spdy for www.google.com:80. |
149 server_pref_dict->SetBoolean("supports_spdy", true); | 151 server_pref_dict->SetBoolean("supports_spdy", true); |
150 | 152 |
151 // Set up alternate_protocol for www.google.com:80. | 153 // Set up alternate_protocol for www.google.com:80. |
152 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 154 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
153 alternate_protocol->SetInteger("port", 443); | 155 alternate_protocol->SetInteger("port", 443); |
154 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); | 156 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
155 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", | 157 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
156 alternate_protocol); | 158 alternate_protocol); |
157 | 159 |
| 160 // Set up SupportsQuic for www.google.com:80. |
| 161 base::DictionaryValue* supports_quic = new base::DictionaryValue; |
| 162 supports_quic->SetBoolean("used_quic", true); |
| 163 supports_quic->SetString("address", "foo"); |
| 164 server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); |
| 165 |
158 // Set the server preference for www.google.com:80. | 166 // Set the server preference for www.google.com:80. |
159 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 167 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
160 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); | 168 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); |
161 | 169 |
162 // Set the preference for mail.google.com server. | 170 // Set the preference for mail.google.com server. |
163 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 171 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
164 | 172 |
165 // Set supports_spdy for mail.google.com:80 | 173 // Set supports_spdy for mail.google.com:80 |
166 server_pref_dict1->SetBoolean("supports_spdy", true); | 174 server_pref_dict1->SetBoolean("supports_spdy", true); |
167 | 175 |
168 // Set up alternate_protocol for mail.google.com:80 | 176 // Set up alternate_protocol for mail.google.com:80 |
169 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; | 177 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; |
170 alternate_protocol1->SetInteger("port", 444); | 178 alternate_protocol1->SetInteger("port", 444); |
171 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); | 179 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); |
172 | 180 |
173 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", | 181 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", |
174 alternate_protocol1); | 182 alternate_protocol1); |
175 | 183 |
| 184 // Set up SupportsQuic for mail.google.com:80 |
| 185 base::DictionaryValue* supports_quic1 = new base::DictionaryValue; |
| 186 supports_quic1->SetBoolean("used_quic", false); |
| 187 supports_quic1->SetString("address", "bar"); |
| 188 server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1); |
| 189 |
176 // Set the server preference for mail.google.com:80. | 190 // Set the server preference for mail.google.com:80. |
177 servers_dict->SetWithoutPathExpansion("mail.google.com:80", | 191 servers_dict->SetWithoutPathExpansion("mail.google.com:80", |
178 server_pref_dict1); | 192 server_pref_dict1); |
179 | 193 |
180 base::DictionaryValue* http_server_properties_dict = | 194 base::DictionaryValue* http_server_properties_dict = |
181 new base::DictionaryValue; | 195 new base::DictionaryValue; |
182 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); | 196 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); |
183 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 197 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
184 | 198 |
185 // Set the same value for kHttpServerProperties multiple times. | 199 // Set the same value for kHttpServerProperties multiple times. |
(...skipping 22 matching lines...) Expand all Loading... |
208 net::HostPortPair::FromString("mail.google.com:80"))); | 222 net::HostPortPair::FromString("mail.google.com:80"))); |
209 net::AlternateProtocolInfo port_alternate_protocol = | 223 net::AlternateProtocolInfo port_alternate_protocol = |
210 http_server_props_manager_->GetAlternateProtocol( | 224 http_server_props_manager_->GetAlternateProtocol( |
211 net::HostPortPair::FromString("www.google.com:80")); | 225 net::HostPortPair::FromString("www.google.com:80")); |
212 EXPECT_EQ(443, port_alternate_protocol.port); | 226 EXPECT_EQ(443, port_alternate_protocol.port); |
213 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); | 227 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); |
214 port_alternate_protocol = http_server_props_manager_->GetAlternateProtocol( | 228 port_alternate_protocol = http_server_props_manager_->GetAlternateProtocol( |
215 net::HostPortPair::FromString("mail.google.com:80")); | 229 net::HostPortPair::FromString("mail.google.com:80")); |
216 EXPECT_EQ(444, port_alternate_protocol.port); | 230 EXPECT_EQ(444, port_alternate_protocol.port); |
217 EXPECT_EQ(net::NPN_SPDY_3_1, port_alternate_protocol.protocol); | 231 EXPECT_EQ(net::NPN_SPDY_3_1, port_alternate_protocol.protocol); |
| 232 |
| 233 // Verify SupportsQuic. |
| 234 net::SupportsQuic supports_quic2 = |
| 235 http_server_props_manager_->GetSupportsQuic( |
| 236 net::HostPortPair::FromString("www.google.com:80")); |
| 237 EXPECT_TRUE(supports_quic2.used_quic); |
| 238 EXPECT_EQ("foo", supports_quic2.address); |
| 239 supports_quic2 = http_server_props_manager_->GetSupportsQuic( |
| 240 net::HostPortPair::FromString("mail.google.com:80")); |
| 241 EXPECT_FALSE(supports_quic2.used_quic); |
| 242 EXPECT_EQ("bar", supports_quic2.address); |
218 } | 243 } |
219 | 244 |
220 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 245 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
221 ExpectPrefsUpdate(); | 246 ExpectPrefsUpdate(); |
222 | 247 |
223 // Post an update task to the network thread. SetSupportsSpdy calls | 248 // Post an update task to the network thread. SetSupportsSpdy calls |
224 // ScheduleUpdatePrefsOnNetworkThread. | 249 // ScheduleUpdatePrefsOnNetworkThread. |
225 | 250 |
226 // Add mail.google.com:443 as a supporting spdy server. | 251 // Add mail.google.com:443 as a supporting spdy server. |
227 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 252 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 375 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
351 | 376 |
352 ASSERT_TRUE( | 377 ASSERT_TRUE( |
353 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 378 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
354 net::AlternateProtocolInfo port_alternate_protocol = | 379 net::AlternateProtocolInfo port_alternate_protocol = |
355 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 380 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
356 EXPECT_EQ(443, port_alternate_protocol.port); | 381 EXPECT_EQ(443, port_alternate_protocol.port); |
357 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); | 382 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); |
358 } | 383 } |
359 | 384 |
| 385 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { |
| 386 ExpectPrefsUpdate(); |
| 387 |
| 388 net::HostPortPair quic_server_mail("mail.google.com", 80); |
| 389 net::SupportsQuic supports_quic = http_server_props_manager_->GetSupportsQuic( |
| 390 quic_server_mail); |
| 391 EXPECT_FALSE(supports_quic.used_quic); |
| 392 EXPECT_EQ("", supports_quic.address); |
| 393 http_server_props_manager_->SetSupportsQuic(quic_server_mail, true, "foo"); |
| 394 |
| 395 // Run the task. |
| 396 base::RunLoop().RunUntilIdle(); |
| 397 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 398 |
| 399 net::SupportsQuic supports_quic1 = |
| 400 http_server_props_manager_->GetSupportsQuic(quic_server_mail); |
| 401 EXPECT_TRUE(supports_quic1.used_quic); |
| 402 EXPECT_EQ("foo", supports_quic1.address); |
| 403 } |
| 404 |
360 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 405 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
361 ExpectPrefsUpdate(); | 406 ExpectPrefsUpdate(); |
362 | 407 |
363 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 408 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
364 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 409 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
365 http_server_props_manager_->SetAlternateProtocol( | 410 http_server_props_manager_->SetAlternateProtocol( |
366 spdy_server_mail, 443, net::NPN_SPDY_3, 1); | 411 spdy_server_mail, 443, net::NPN_SPDY_3, 1); |
| 412 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); |
367 | 413 |
368 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; | 414 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; |
369 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; | 415 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; |
370 const uint32 value1 = 31337; | 416 const uint32 value1 = 31337; |
371 http_server_props_manager_->SetSpdySetting( | 417 http_server_props_manager_->SetSpdySetting( |
372 spdy_server_mail, id1, flags1, value1); | 418 spdy_server_mail, id1, flags1, value1); |
373 | 419 |
374 // Run the task. | 420 // Run the task. |
375 base::RunLoop().RunUntilIdle(); | 421 base::RunLoop().RunUntilIdle(); |
376 | 422 |
377 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 423 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
378 EXPECT_TRUE( | 424 EXPECT_TRUE( |
379 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 425 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 426 net::SupportsQuic supports_quic = http_server_props_manager_->GetSupportsQuic( |
| 427 spdy_server_mail); |
| 428 EXPECT_TRUE(supports_quic.used_quic); |
| 429 EXPECT_EQ("foo", supports_quic.address); |
380 | 430 |
381 // Check SPDY settings values. | 431 // Check SPDY settings values. |
382 const net::SettingsMap& settings_map1_ret = | 432 const net::SettingsMap& settings_map1_ret = |
383 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 433 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
384 ASSERT_EQ(1U, settings_map1_ret.size()); | 434 ASSERT_EQ(1U, settings_map1_ret.size()); |
385 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 435 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
386 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 436 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
387 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 437 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
388 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 438 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
389 EXPECT_EQ(value1, flags_and_value1_ret.second); | 439 EXPECT_EQ(value1, flags_and_value1_ret.second); |
390 | 440 |
391 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 441 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
392 | 442 |
393 ExpectPrefsUpdate(); | 443 ExpectPrefsUpdate(); |
394 | 444 |
395 // Clear http server data, time out if we do not get a completion callback. | 445 // Clear http server data, time out if we do not get a completion callback. |
396 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); | 446 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); |
397 base::RunLoop().Run(); | 447 base::RunLoop().Run(); |
398 | 448 |
399 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 449 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
400 EXPECT_FALSE( | 450 EXPECT_FALSE( |
401 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 451 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 452 net::SupportsQuic supports_quic1 = |
| 453 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); |
| 454 EXPECT_FALSE(supports_quic1.used_quic); |
| 455 EXPECT_EQ("", supports_quic1.address); |
402 | 456 |
403 const net::SettingsMap& settings_map2_ret = | 457 const net::SettingsMap& settings_map2_ret = |
404 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 458 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
405 EXPECT_EQ(0U, settings_map2_ret.size()); | 459 EXPECT_EQ(0U, settings_map2_ret.size()); |
406 | 460 |
407 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 461 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
408 } | 462 } |
409 | 463 |
410 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 464 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
411 // Post an update task to the UI thread. | 465 // Post an update task to the UI thread. |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 // Run the task after shutdown, but before deletion. | 529 // Run the task after shutdown, but before deletion. |
476 base::RunLoop().RunUntilIdle(); | 530 base::RunLoop().RunUntilIdle(); |
477 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 531 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
478 http_server_props_manager_.reset(); | 532 http_server_props_manager_.reset(); |
479 base::RunLoop().RunUntilIdle(); | 533 base::RunLoop().RunUntilIdle(); |
480 } | 534 } |
481 | 535 |
482 } // namespace | 536 } // namespace |
483 | 537 |
484 } // namespace net | 538 } // namespace net |
OLD | NEW |