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