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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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_METHOD3(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)); |
ramant (doing other things)
2011/12/03 00:31:43
shouldn't we add PipelineCapability to UpdateCache
James Simonsen
2011/12/03 03:16:00
Done.
It's disconcerting that this compiled and a
| |
67 MOCK_METHOD3(UpdatePrefsOnUI, | 67 MOCK_METHOD3(UpdatePrefsOnUI, |
68 void(base::ListValue* spdy_server_list, | 68 void(base::ListValue* spdy_server_list, |
69 net::SpdySettingsMap* spdy_settings_map, | 69 net::SpdySettingsMap* spdy_settings_map, |
70 net::AlternateProtocolMap* alternate_protocol_map)); | 70 net::AlternateProtocolMap* alternate_protocol_map)); |
ramant (doing other things)
2011/12/03 00:31:43
shouldn't we add PipelineCapability to UpdateCache
James Simonsen
2011/12/03 03:16:00
Done.
| |
71 | 71 |
72 private: | 72 private: |
73 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); | 73 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); |
74 }; | 74 }; |
75 | 75 |
76 class HttpServerPropertiesManagerTest : public testing::Test { | 76 class HttpServerPropertiesManagerTest : public testing::Test { |
77 protected: | 77 protected: |
78 HttpServerPropertiesManagerTest() | 78 HttpServerPropertiesManagerTest() |
79 : ui_thread_(BrowserThread::UI, &loop_), | 79 : ui_thread_(BrowserThread::UI, &loop_), |
80 io_thread_(BrowserThread::IO, &loop_) { | 80 io_thread_(BrowserThread::IO, &loop_) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 net::PortAlternateProtocolPair port_alternate_protocol = | 231 net::PortAlternateProtocolPair port_alternate_protocol = |
232 http_server_props_manager_->GetAlternateProtocol( | 232 http_server_props_manager_->GetAlternateProtocol( |
233 net::HostPortPair::FromString("www.google.com:80")); | 233 net::HostPortPair::FromString("www.google.com:80")); |
234 EXPECT_EQ(443, port_alternate_protocol.port); | 234 EXPECT_EQ(443, port_alternate_protocol.port); |
235 EXPECT_EQ(net::NPN_SPDY_1, port_alternate_protocol.protocol); | 235 EXPECT_EQ(net::NPN_SPDY_1, port_alternate_protocol.protocol); |
236 port_alternate_protocol = | 236 port_alternate_protocol = |
237 http_server_props_manager_->GetAlternateProtocol( | 237 http_server_props_manager_->GetAlternateProtocol( |
238 net::HostPortPair::FromString("mail.google.com:80")); | 238 net::HostPortPair::FromString("mail.google.com:80")); |
239 EXPECT_EQ(444, port_alternate_protocol.port); | 239 EXPECT_EQ(444, port_alternate_protocol.port); |
240 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); | 240 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); |
241 } | 241 } |
ramant (doing other things)
2011/12/03 00:31:43
nit: please consider adding a test for PipelineCap
James Simonsen
2011/12/03 03:16:00
Done.
| |
242 | 242 |
243 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 243 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
244 ExpectPrefsUpdate(); | 244 ExpectPrefsUpdate(); |
245 | 245 |
246 // Post an update task to the IO thread. SetSupportsSpdy calls | 246 // Post an update task to the IO thread. SetSupportsSpdy calls |
247 // ScheduleUpdatePrefsOnIO. | 247 // ScheduleUpdatePrefsOnIO. |
248 | 248 |
249 // Add mail.google.com:443 as a supporting spdy server. | 249 // Add mail.google.com:443 as a supporting spdy server. |
250 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 250 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
251 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 251 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 299 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
300 | 300 |
301 ASSERT_TRUE( | 301 ASSERT_TRUE( |
302 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 302 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
303 net::PortAlternateProtocolPair port_alternate_protocol = | 303 net::PortAlternateProtocolPair port_alternate_protocol = |
304 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 304 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
305 EXPECT_EQ(443, port_alternate_protocol.port); | 305 EXPECT_EQ(443, port_alternate_protocol.port); |
306 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); | 306 EXPECT_EQ(net::NPN_SPDY_2, port_alternate_protocol.protocol); |
307 } | 307 } |
308 | 308 |
309 TEST_F(HttpServerPropertiesManagerTest, PipelineCapability) { | |
310 ExpectPrefsUpdate(); | |
311 | |
312 // Post an update task to the IO thread. SetPipelineCapability calls | |
313 // ScheduleUpdatePrefsOnIO. | |
mmenke
2011/12/02 21:52:10
Think it's a little clearer if you put this just a
James Simonsen
2011/12/03 03:16:00
Done.
| |
314 | |
315 net::HostPortPair known_pipeliner("pipeline.com", 8080); | |
316 net::HostPortPair bad_pipeliner("wordpress.com", 80); | |
317 EXPECT_EQ(net::HttpPipelinedHost::UNKNOWN, | |
318 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); | |
319 EXPECT_EQ(net::HttpPipelinedHost::UNKNOWN, | |
320 http_server_props_manager_->GetPipelineCapability(bad_pipeliner)); | |
321 http_server_props_manager_->SetPipelineCapability( | |
322 known_pipeliner, net::HttpPipelinedHost::CAPABLE); | |
323 http_server_props_manager_->SetPipelineCapability( | |
324 bad_pipeliner, net::HttpPipelinedHost::INCAPABLE); | |
325 | |
326 // Run the task. | |
327 loop_.RunAllPending(); | |
328 | |
329 EXPECT_EQ(net::HttpPipelinedHost::CAPABLE, | |
330 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); | |
331 EXPECT_EQ(net::HttpPipelinedHost::INCAPABLE, | |
332 http_server_props_manager_->GetPipelineCapability(bad_pipeliner)); | |
333 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | |
334 } | |
335 | |
309 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 336 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
310 ExpectPrefsUpdate(); | 337 ExpectPrefsUpdate(); |
311 | 338 |
312 net::HostPortPair spdy_server_mail("mail.google.com", 443); | 339 net::HostPortPair spdy_server_mail("mail.google.com", 443); |
313 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 340 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
314 http_server_props_manager_->SetAlternateProtocol( | 341 http_server_props_manager_->SetAlternateProtocol( |
315 spdy_server_mail, 443, net::NPN_SPDY_2); | 342 spdy_server_mail, 443, net::NPN_SPDY_2); |
316 | 343 |
317 spdy::SpdySettings spdy_settings; | 344 spdy::SpdySettings spdy_settings; |
318 spdy::SettingsFlagsAndId id1(0); | 345 spdy::SettingsFlagsAndId id1(0); |
319 id1.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | 346 id1.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); |
320 id1.set_id(1234); | 347 id1.set_id(1234); |
321 spdy_settings.push_back(std::make_pair(id1, 31337)); | 348 spdy_settings.push_back(std::make_pair(id1, 31337)); |
322 http_server_props_manager_->SetSpdySettings(spdy_server_mail, spdy_settings); | 349 http_server_props_manager_->SetSpdySettings(spdy_server_mail, spdy_settings); |
323 | 350 |
351 net::HostPortPair known_pipeliner("pipeline.com", 8080); | |
352 http_server_props_manager_->SetPipelineCapability( | |
353 known_pipeliner, net::HttpPipelinedHost::CAPABLE); | |
354 | |
324 // Run the task. | 355 // Run the task. |
325 loop_.RunAllPending(); | 356 loop_.RunAllPending(); |
326 | 357 |
327 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 358 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
328 EXPECT_TRUE( | 359 EXPECT_TRUE( |
329 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 360 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
330 | 361 |
331 spdy::SpdySettings spdy_settings_ret = | 362 spdy::SpdySettings spdy_settings_ret = |
332 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 363 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
333 ASSERT_EQ(1U, spdy_settings_ret.size()); | 364 ASSERT_EQ(1U, spdy_settings_ret.size()); |
334 spdy::SpdySetting spdy_setting1_ret = spdy_settings_ret.front(); | 365 spdy::SpdySetting spdy_setting1_ret = spdy_settings_ret.front(); |
335 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first); | 366 spdy::SettingsFlagsAndId id1_ret(spdy_setting1_ret.first); |
336 EXPECT_EQ(1234U, id1_ret.id()); | 367 EXPECT_EQ(1234U, id1_ret.id()); |
337 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags()); | 368 EXPECT_EQ(spdy::SETTINGS_FLAG_PERSISTED, id1_ret.flags()); |
338 EXPECT_EQ(31337U, spdy_setting1_ret.second); | 369 EXPECT_EQ(31337U, spdy_setting1_ret.second); |
339 | 370 |
371 EXPECT_EQ(net::HttpPipelinedHost::CAPABLE, | |
372 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); | |
373 | |
340 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 374 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
341 | 375 |
342 ExpectPrefsUpdate(); | 376 ExpectPrefsUpdate(); |
343 // Clear http server data. | 377 // Clear http server data. |
344 http_server_props_manager_->Clear(); | 378 http_server_props_manager_->Clear(); |
345 | 379 |
346 // Run the task. | 380 // Run the task. |
347 loop_.RunAllPending(); | 381 loop_.RunAllPending(); |
348 | 382 |
349 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); | 383 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); |
350 EXPECT_FALSE( | 384 EXPECT_FALSE( |
351 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 385 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
352 | 386 |
353 spdy::SpdySettings spdy_settings1_ret = | 387 spdy::SpdySettings spdy_settings1_ret = |
354 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 388 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
355 EXPECT_EQ(0U, spdy_settings1_ret.size()); | 389 EXPECT_EQ(0U, spdy_settings1_ret.size()); |
356 | 390 |
391 EXPECT_EQ(net::HttpPipelinedHost::UNKNOWN, | |
392 http_server_props_manager_->GetPipelineCapability(known_pipeliner)); | |
393 | |
357 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 394 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
358 } | 395 } |
359 | 396 |
360 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 397 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
361 // Post an update task to the UI thread. | 398 // Post an update task to the UI thread. |
362 http_server_props_manager_->ScheduleUpdateCacheOnUI(); | 399 http_server_props_manager_->ScheduleUpdateCacheOnUI(); |
363 // Shutdown comes before the task is executed. | 400 // Shutdown comes before the task is executed. |
364 http_server_props_manager_->ShutdownOnUIThread(); | 401 http_server_props_manager_->ShutdownOnUIThread(); |
365 http_server_props_manager_.reset(); | 402 http_server_props_manager_.reset(); |
366 // Run the task after shutdown and deletion. | 403 // 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. | 461 // Run the task after shutdown, but before deletion. |
425 loop_.RunAllPending(); | 462 loop_.RunAllPending(); |
426 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 463 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
427 http_server_props_manager_.reset(); | 464 http_server_props_manager_.reset(); |
428 loop_.RunAllPending(); | 465 loop_.RunAllPending(); |
429 } | 466 } |
430 | 467 |
431 } // namespace | 468 } // namespace |
432 | 469 |
433 } // namespace chrome_browser_net | 470 } // namespace chrome_browser_net |
OLD | NEW |