OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 8 #include "base/message_loop.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 HttpServerPropertiesManager::StartCacheUpdateTimerOnUI( | 53 HttpServerPropertiesManager::StartCacheUpdateTimerOnUI( |
54 base::TimeDelta()); | 54 base::TimeDelta()); |
55 } | 55 } |
56 | 56 |
57 void UpdatePrefsFromCacheOnIOConcrete() { | 57 void UpdatePrefsFromCacheOnIOConcrete() { |
58 HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(); | 58 HttpServerPropertiesManager::UpdatePrefsFromCacheOnIO(); |
59 } | 59 } |
60 | 60 |
61 MOCK_METHOD0(UpdateCacheFromPrefsOnUI, void()); | 61 MOCK_METHOD0(UpdateCacheFromPrefsOnUI, void()); |
62 MOCK_METHOD0(UpdatePrefsFromCacheOnIO, void()); | 62 MOCK_METHOD0(UpdatePrefsFromCacheOnIO, void()); |
63 MOCK_METHOD3(UpdateCacheFromPrefsOnIO, | 63 MOCK_METHOD4(UpdateCacheFromPrefsOnIO, |
64 void(std::vector<std::string>* spdy_servers, | 64 void(std::vector<std::string>* spdy_servers, |
65 net::SpdySettingsMap* spdy_settings_map, | 65 net::SpdySettingsMap* spdy_settings_map, |
66 net::AlternateProtocolMap* alternate_protocol_map)); | 66 net::AlternateProtocolMap* alternate_protocol_map, |
67 MOCK_METHOD3(UpdatePrefsOnUI, | 67 net::PipelineCapabilityMap* pipeline_capability_map)); |
| 68 MOCK_METHOD4(UpdatePrefsOnUI, |
68 void(base::ListValue* spdy_server_list, | 69 void(base::ListValue* spdy_server_list, |
69 net::SpdySettingsMap* spdy_settings_map, | 70 net::SpdySettingsMap* spdy_settings_map, |
70 net::AlternateProtocolMap* alternate_protocol_map)); | 71 net::AlternateProtocolMap* alternate_protocol_map, |
| 72 net::PipelineCapabilityMap* pipeline_capability_map)); |
71 | 73 |
72 private: | 74 private: |
73 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); | 75 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); |
74 }; | 76 }; |
75 | 77 |
76 class HttpServerPropertiesManagerTest : public testing::Test { | 78 class HttpServerPropertiesManagerTest : public testing::Test { |
77 protected: | 79 protected: |
78 HttpServerPropertiesManagerTest() | 80 HttpServerPropertiesManagerTest() |
79 : ui_thread_(BrowserThread::UI, &loop_), | 81 : ui_thread_(BrowserThread::UI, &loop_), |
80 io_thread_(BrowserThread::IO, &loop_) { | 82 io_thread_(BrowserThread::IO, &loop_) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 spdy_settings_list->Append(spdy_setting_dict); | 147 spdy_settings_list->Append(spdy_setting_dict); |
146 server_pref_dict->Set("settings", spdy_settings_list); | 148 server_pref_dict->Set("settings", spdy_settings_list); |
147 | 149 |
148 // Set up alternate_protocol for www.google.com:80. | 150 // Set up alternate_protocol for www.google.com:80. |
149 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 151 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
150 alternate_protocol->SetInteger("port", 443); | 152 alternate_protocol->SetInteger("port", 443); |
151 alternate_protocol->SetInteger("protocol", static_cast<int>(net::NPN_SPDY_1)); | 153 alternate_protocol->SetInteger("protocol", static_cast<int>(net::NPN_SPDY_1)); |
152 server_pref_dict->SetWithoutPathExpansion( | 154 server_pref_dict->SetWithoutPathExpansion( |
153 "alternate_protocol", alternate_protocol); | 155 "alternate_protocol", alternate_protocol); |
154 | 156 |
| 157 // Set pipeline capability for www.google.com:80. |
| 158 server_pref_dict->SetInteger("pipeline_capability", net::PIPELINE_CAPABLE); |
| 159 |
155 // Set the server preference for www.google.com:80. | 160 // Set the server preference for www.google.com:80. |
156 base::DictionaryValue* http_server_properties_dict = | 161 base::DictionaryValue* http_server_properties_dict = |
157 new base::DictionaryValue; | 162 new base::DictionaryValue; |
158 http_server_properties_dict->SetWithoutPathExpansion( | 163 http_server_properties_dict->SetWithoutPathExpansion( |
159 "www.google.com:80", server_pref_dict); | 164 "www.google.com:80", server_pref_dict); |
160 | 165 |
161 // Set the preference for mail.google.com server. | 166 // Set the preference for mail.google.com server. |
162 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; | 167 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; |
163 | 168 |
164 // Set supports_spdy for mail.google.com:80 | 169 // Set supports_spdy for mail.google.com:80 |
165 server_pref_dict1->SetBoolean("supports_spdy", true); | 170 server_pref_dict1->SetBoolean("supports_spdy", true); |
166 | 171 |
167 // Set up the SpdySettings for mail.google.com:80 | 172 // Set up the SpdySettings for mail.google.com:80 |
168 base::ListValue* spdy_settings_list1 = new base::ListValue; | 173 base::ListValue* spdy_settings_list1 = new base::ListValue; |
169 base::DictionaryValue* spdy_setting_dict1 = new base::DictionaryValue; | 174 base::DictionaryValue* spdy_setting_dict1 = new base::DictionaryValue; |
170 spdy_setting_dict1->SetInteger("flags", spdy::SETTINGS_FLAG_PERSISTED); | 175 spdy_setting_dict1->SetInteger("flags", spdy::SETTINGS_FLAG_PERSISTED); |
171 spdy_setting_dict1->SetInteger("id", 5678); | 176 spdy_setting_dict1->SetInteger("id", 5678); |
172 spdy_setting_dict1->SetInteger("value", 62667); | 177 spdy_setting_dict1->SetInteger("value", 62667); |
173 spdy_settings_list1->Append(spdy_setting_dict1); | 178 spdy_settings_list1->Append(spdy_setting_dict1); |
174 server_pref_dict1->Set("settings", spdy_settings_list1); | 179 server_pref_dict1->Set("settings", spdy_settings_list1); |
175 | 180 |
176 // Set up alternate_protocol for mail.google.com:80 | 181 // Set up alternate_protocol for mail.google.com:80 |
177 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; | 182 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; |
178 alternate_protocol1->SetInteger("port", 444); | 183 alternate_protocol1->SetInteger("port", 444); |
179 alternate_protocol1->SetInteger( | 184 alternate_protocol1->SetInteger( |
180 "protocol", static_cast<int>(net::NPN_SPDY_2)); | 185 "protocol", static_cast<int>(net::NPN_SPDY_2)); |
181 server_pref_dict1->SetWithoutPathExpansion( | 186 server_pref_dict1->SetWithoutPathExpansion( |
182 "alternate_protocol", alternate_protocol1); | 187 "alternate_protocol", alternate_protocol1); |
183 | 188 |
| 189 // Set pipelining capability for mail.google.com:80 |
| 190 server_pref_dict1->SetInteger("pipeline_capability", net::PIPELINE_INCAPABLE); |
| 191 |
184 // Set the server preference for mail.google.com:80. | 192 // Set the server preference for mail.google.com:80. |
185 http_server_properties_dict->SetWithoutPathExpansion( | 193 http_server_properties_dict->SetWithoutPathExpansion( |
186 "mail.google.com:80", server_pref_dict1); | 194 "mail.google.com:80", server_pref_dict1); |
187 | 195 |
188 // Set the same value for kHttpServerProperties multiple times. | 196 // Set the same value for kHttpServerProperties multiple times. |
189 pref_service_.SetManagedPref(prefs::kHttpServerProperties, | 197 pref_service_.SetManagedPref(prefs::kHttpServerProperties, |
190 http_server_properties_dict); | 198 http_server_properties_dict); |
191 base::DictionaryValue* http_server_properties_dict2 = | 199 base::DictionaryValue* http_server_properties_dict2 = |
192 http_server_properties_dict->DeepCopy(); | 200 http_server_properties_dict->DeepCopy(); |
193 pref_service_.SetManagedPref(prefs::kHttpServerProperties, | 201 pref_service_.SetManagedPref(prefs::kHttpServerProperties, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 net::PortAlternateProtocolPair port_alternate_protocol = | 239 net::PortAlternateProtocolPair port_alternate_protocol = |
232 http_server_props_manager_->GetAlternateProtocol( | 240 http_server_props_manager_->GetAlternateProtocol( |
233 net::HostPortPair::FromString("www.google.com:80")); | 241 net::HostPortPair::FromString("www.google.com:80")); |
234 EXPECT_EQ(443, port_alternate_protocol.port); | 242 EXPECT_EQ(443, port_alternate_protocol.port); |
235 EXPECT_EQ(net::NPN_SPDY_1, port_alternate_protocol.protocol); | 243 EXPECT_EQ(net::NPN_SPDY_1, port_alternate_protocol.protocol); |
236 port_alternate_protocol = | 244 port_alternate_protocol = |
237 http_server_props_manager_->GetAlternateProtocol( | 245 http_server_props_manager_->GetAlternateProtocol( |
238 net::HostPortPair::FromString("mail.google.com:80")); | 246 net::HostPortPair::FromString("mail.google.com:80")); |
239 EXPECT_EQ(444, port_alternate_protocol.port); | 247 EXPECT_EQ(444, port_alternate_protocol.port); |
240 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); | 248 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); |
| 249 |
| 250 // Verify pipeline capability. |
| 251 EXPECT_EQ(net::PIPELINE_CAPABLE, |
| 252 http_server_props_manager_->GetPipelineCapability( |
| 253 net::HostPortPair::FromString("www.google.com:80"))); |
| 254 EXPECT_EQ(net::PIPELINE_INCAPABLE, |
| 255 http_server_props_manager_->GetPipelineCapability( |
| 256 net::HostPortPair::FromString("mail.google.com:80"))); |
241 } | 257 } |
242 | 258 |
243 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 259 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
244 ExpectPrefsUpdate(); | 260 ExpectPrefsUpdate(); |
245 | 261 |
246 // Post an update task to the IO thread. SetSupportsSpdy calls | 262 // Post an update task to the IO thread. SetSupportsSpdy calls |
247 // ScheduleUpdatePrefsOnIO. | 263 // ScheduleUpdatePrefsOnIO. |
248 | 264 |
249 // Add mail.google.com:443 as a supporting spdy server. | 265 // Add mail.google.com:443 as a supporting spdy server. |
250 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 266 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 315 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
300 | 316 |
301 ASSERT_TRUE( | 317 ASSERT_TRUE( |
302 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 318 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
303 net::PortAlternateProtocolPair port_alternate_protocol = | 319 net::PortAlternateProtocolPair port_alternate_protocol = |
304 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 320 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
305 EXPECT_EQ(443, port_alternate_protocol.port); | 321 EXPECT_EQ(443, port_alternate_protocol.port); |
306 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); | 322 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); |
307 } | 323 } |
308 | 324 |
| 325 TEST_F(HttpServerPropertiesManagerTest, PipelineCapability) { |
| 326 ExpectPrefsUpdate(); |
| 327 |
| 328 net::HostPortPair known_pipeliner("pipeline.com", 8080); |
| 329 net::HostPortPair bad_pipeliner("wordpress.com", 80); |
| 330 EXPECT_EQ(net::PIPELINE_UNKNOWN, |
| 331 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); |
| 332 EXPECT_EQ(net::PIPELINE_UNKNOWN, |
| 333 http_server_props_manager_->GetPipelineCapability(bad_pipeliner)); |
| 334 |
| 335 // Post an update task to the IO thread. SetPipelineCapability calls |
| 336 // ScheduleUpdatePrefsOnIO. |
| 337 http_server_props_manager_->SetPipelineCapability(known_pipeliner, |
| 338 net::PIPELINE_CAPABLE); |
| 339 http_server_props_manager_->SetPipelineCapability(bad_pipeliner, |
| 340 net::PIPELINE_INCAPABLE); |
| 341 |
| 342 // Run the task. |
| 343 loop_.RunAllPending(); |
| 344 |
| 345 EXPECT_EQ(net::PIPELINE_CAPABLE, |
| 346 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); |
| 347 EXPECT_EQ(net::PIPELINE_INCAPABLE, |
| 348 http_server_props_manager_->GetPipelineCapability(bad_pipeliner)); |
| 349 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 350 } |
| 351 |
309 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 352 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
310 ExpectPrefsUpdate(); | 353 ExpectPrefsUpdate(); |
311 | 354 |
312 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 355 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
313 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 356 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
314 http_server_props_manager_->SetAlternateProtocol( | 357 http_server_props_manager_->SetAlternateProtocol( |
315 spdy_server_mail, 443, net::NPN_SPDY_2); | 358 spdy_server_mail, 443, net::NPN_SPDY_2); |
316 | 359 |
317 spdy::SpdySettings spdy_settings; | 360 spdy::SpdySettings spdy_settings; |
318 spdy::SettingsFlagsAndId id1(0); | 361 spdy::SettingsFlagsAndId id1(0); |
319 id1.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | 362 id1.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); |
320 id1.set_id(1234); | 363 id1.set_id(1234); |
321 spdy_settings.push_back(std::make_pair(id1, 31337)); | 364 spdy_settings.push_back(std::make_pair(id1, 31337)); |
322 http_server_props_manager_->SetSpdySettings(spdy_server_mail, spdy_settings); | 365 http_server_props_manager_->SetSpdySettings(spdy_server_mail, spdy_settings); |
323 | 366 |
| 367 net::HostPortPair known_pipeliner("pipeline.com", 8080); |
| 368 http_server_props_manager_->SetPipelineCapability(known_pipeliner, |
| 369 net::PIPELINE_CAPABLE); |
| 370 |
324 // Run the task. | 371 // Run the task. |
325 loop_.RunAllPending(); | 372 loop_.RunAllPending(); |
326 | 373 |
327 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 374 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
328 EXPECT_TRUE( | 375 EXPECT_TRUE( |
329 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 376 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
330 | 377 |
331 spdy::SpdySettings spdy_settings_ret = | 378 spdy::SpdySettings spdy_settings_ret = |
332 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 379 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
333 ASSERT_EQ(1U, spdy_settings_ret.size()); | 380 ASSERT_EQ(1U, spdy_settings_ret.size()); |
334 spdy::SpdySetting spdy_setting1_ret = spdy_settings_ret.front(); | 381 spdy::SpdySetting spdy_setting1_ret = spdy_settings_ret.front(); |
335 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first); | 382 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first); |
336 EXPECT_EQ(1234U, id1_ret.id()); | 383 EXPECT_EQ(1234U, id1_ret.id()); |
337 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags()); | 384 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags()); |
338 EXPECT_EQ(31337U, spdy_setting1_ret.second); | 385 EXPECT_EQ(31337U, spdy_setting1_ret.second); |
339 | 386 |
| 387 EXPECT_EQ(net::PIPELINE_CAPABLE, |
| 388 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); |
| 389 |
340 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 390 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
341 | 391 |
342 ExpectPrefsUpdate(); | 392 ExpectPrefsUpdate(); |
343 // Clear http server data. | 393 // Clear http server data. |
344 http_server_props_manager_->Clear(); | 394 http_server_props_manager_->Clear(); |
345 | 395 |
346 // Run the task. | 396 // Run the task. |
347 loop_.RunAllPending(); | 397 loop_.RunAllPending(); |
348 | 398 |
349 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 399 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
350 EXPECT_FALSE( | 400 EXPECT_FALSE( |
351 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 401 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
352 | 402 |
353 spdy::SpdySettings spdy_settings1_ret = | 403 spdy::SpdySettings spdy_settings1_ret = |
354 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 404 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
355 EXPECT_EQ(0U, spdy_settings1_ret.size()); | 405 EXPECT_EQ(0U, spdy_settings1_ret.size()); |
356 | 406 |
| 407 EXPECT_EQ(net::PIPELINE_UNKNOWN, |
| 408 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); |
| 409 |
357 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 410 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
358 } | 411 } |
359 | 412 |
360 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 413 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
361 // Post an update task to the UI thread. | 414 // Post an update task to the UI thread. |
362 http_server_props_manager_->ScheduleUpdateCacheOnUI(); | 415 http_server_props_manager_->ScheduleUpdateCacheOnUI(); |
363 // Shutdown comes before the task is executed. | 416 // Shutdown comes before the task is executed. |
364 http_server_props_manager_->ShutdownOnUIThread(); | 417 http_server_props_manager_->ShutdownOnUIThread(); |
365 http_server_props_manager_.reset(); | 418 http_server_props_manager_.reset(); |
366 // Run the task after shutdown and deletion. | 419 // Run the task after shutdown and deletion. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 // Run the task after shutdown, but before deletion. | 477 // Run the task after shutdown, but before deletion. |
425 loop_.RunAllPending(); | 478 loop_.RunAllPending(); |
426 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 479 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
427 http_server_props_manager_.reset(); | 480 http_server_props_manager_.reset(); |
428 loop_.RunAllPending(); | 481 loop_.RunAllPending(); |
429 } | 482 } |
430 | 483 |
431 } // namespace | 484 } // namespace |
432 | 485 |
433 } // namespace chrome_browser_net | 486 } // namespace chrome_browser_net |
OLD | NEW |