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 3 // found in the LICENSE file. 4 5 #include "net/http/http_server_properties_manager.h" 6 7 #include "base/basictypes.h" 8 #include "base/message_loop/message_loop.h" 9 #include "base/prefs/pref_registry_simple.h" 10 #include "base/prefs/testing_pref_service.h" 11 #include "base/run_loop.h" 12 #include "base/test/test_simple_task_runner.h" 13 #include "base/values.h" 14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "url/gurl.h" 17 18 namespace net { 19 20 namespace { 21 22 using ::testing::_; 23 using ::testing::Invoke; 24 using ::testing::Mock; 25 using ::testing::StrictMock; 26 27 const char kTestHttpServerProperties[] = "TestHttpServerProperties"; 28 29 class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { 30 public: 31 TestingHttpServerPropertiesManager( 32 PrefService* pref_service, 33 const char* pref_path, 34 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) 35 : HttpServerPropertiesManager(pref_service, pref_path, io_task_runner) { 36 InitializeOnNetworkThread(); 37 } 38 39 virtual ~TestingHttpServerPropertiesManager() {} 40 41 // Make these methods public for testing. 42 using HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread; 43 using HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread; 44 45 // Post tasks without a delay during tests. 46 virtual void StartPrefsUpdateTimerOnNetworkThread( 47 base::TimeDelta delay) OVERRIDE { 48 HttpServerPropertiesManager::StartPrefsUpdateTimerOnNetworkThread( 49 base::TimeDelta()); 50 } 51 52 void UpdateCacheFromPrefsOnUIConcrete() { 53 HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread(); 54 } 55 56 // Post tasks without a delay during tests. 57 virtual void StartCacheUpdateTimerOnPrefThread( 58 base::TimeDelta delay) OVERRIDE { 59 HttpServerPropertiesManager::StartCacheUpdateTimerOnPrefThread( 60 base::TimeDelta()); 61 } 62 63 void UpdatePrefsFromCacheOnNetworkThreadConcrete( 64 const base::Closure& callback) { 65 HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); 66 } 67 68 MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); 69 MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); 70 MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread, 71 void(std::vector<std::string>* spdy_servers, 72 net::SpdySettingsMap* spdy_settings_map, 73 net::AlternateProtocolMap* alternate_protocol_map, 74 net::AlternateProtocolExperiment experiment, 75 net::SupportsQuicMap* supports_quic_map, 76 bool detected_corrupted_prefs)); 77 MOCK_METHOD4(UpdatePrefsOnPref, 78 void(base::ListValue* spdy_server_list, 79 net::SpdySettingsMap* spdy_settings_map, 80 net::AlternateProtocolMap* alternate_protocol_map, 81 net::SupportsQuicMap* supports_quic_map)); 82 83 private: 84 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); 85 }; 86 87 class HttpServerPropertiesManagerTest : public testing::Test { 88 protected: 89 HttpServerPropertiesManagerTest() {} 90 91 virtual void SetUp() OVERRIDE { 92 pref_service_.registry()->RegisterDictionaryPref(kTestHttpServerProperties); 93 http_server_props_manager_.reset( 94 new StrictMock<TestingHttpServerPropertiesManager>( 95 &pref_service_, 96 kTestHttpServerProperties, 97 base::MessageLoop::current()->message_loop_proxy())); 98 ExpectCacheUpdate(); 99 base::RunLoop().RunUntilIdle(); 100 } 101 102 virtual void TearDown() OVERRIDE { 103 if (http_server_props_manager_.get()) 104 http_server_props_manager_->ShutdownOnPrefThread(); 105 base::RunLoop().RunUntilIdle(); 106 http_server_props_manager_.reset(); 107 } 108 109 void ExpectCacheUpdate() { 110 EXPECT_CALL(*http_server_props_manager_, UpdateCacheFromPrefsOnPrefThread()) 111 .WillOnce(Invoke(http_server_props_manager_.get(), 112 &TestingHttpServerPropertiesManager:: 113 UpdateCacheFromPrefsOnUIConcrete)); 114 } 115 116 void ExpectPrefsUpdate() { 117 EXPECT_CALL(*http_server_props_manager_, 118 UpdatePrefsFromCacheOnNetworkThread(_)) 119 .WillOnce(Invoke(http_server_props_manager_.get(), 120 &TestingHttpServerPropertiesManager:: 121 UpdatePrefsFromCacheOnNetworkThreadConcrete)); 122 } 123 124 void ExpectPrefsUpdateRepeatedly() { 125 EXPECT_CALL(*http_server_props_manager_, 126 UpdatePrefsFromCacheOnNetworkThread(_)) 127 .WillRepeatedly( 128 Invoke(http_server_props_manager_.get(), 129 &TestingHttpServerPropertiesManager:: 130 UpdatePrefsFromCacheOnNetworkThreadConcrete)); 131 } 132 133 //base::RunLoop loop_; 134 TestingPrefServiceSimple pref_service_; 135 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; 136 137 private: 138 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); 139 }; 140 141 TEST_F(HttpServerPropertiesManagerTest, 142 SingleUpdateForTwoSpdyServerPrefChanges) { 143 ExpectCacheUpdate(); 144 145 // Set up the prefs for www.google.com:80 and mail.google.com:80 and then set 146 // it twice. Only expect a single cache update. 147 148 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 149 150 // Set supports_spdy for www.google.com:80. 151 server_pref_dict->SetBoolean("supports_spdy", true); 152 153 // Set up alternate_protocol for www.google.com:80. 154 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; 155 alternate_protocol->SetInteger("port", 443); 156 alternate_protocol->SetString("protocol_str", "npn-spdy/3"); 157 server_pref_dict->SetWithoutPathExpansion("alternate_protocol", 158 alternate_protocol); 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 166 // Set the server preference for www.google.com:80. 167 base::DictionaryValue* servers_dict = new base::DictionaryValue; 168 servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); 169 170 // Set the preference for mail.google.com server. 171 base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue; 172 173 // Set supports_spdy for mail.google.com:80 174 server_pref_dict1->SetBoolean("supports_spdy", true); 175 176 // Set up alternate_protocol for mail.google.com:80 177 base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; 178 alternate_protocol1->SetInteger("port", 444); 179 alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); 180 181 server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", 182 alternate_protocol1); 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 190 // Set the server preference for mail.google.com:80. 191 servers_dict->SetWithoutPathExpansion("mail.google.com:80", 192 server_pref_dict1); 193 194 base::DictionaryValue* http_server_properties_dict = 195 new base::DictionaryValue; 196 HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); 197 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); 198 199 // Set the same value for kHttpServerProperties multiple times. 200 pref_service_.SetManagedPref(kTestHttpServerProperties, 201 http_server_properties_dict); 202 base::DictionaryValue* http_server_properties_dict2 = 203 http_server_properties_dict->DeepCopy(); 204 pref_service_.SetManagedPref(kTestHttpServerProperties, 205 http_server_properties_dict2); 206 207 base::RunLoop().RunUntilIdle(); 208 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 209 210 // Verify SupportsSpdy. 211 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( 212 net::HostPortPair::FromString("www.google.com:80"))); 213 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy( 214 net::HostPortPair::FromString("mail.google.com:80"))); 215 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( 216 net::HostPortPair::FromString("foo.google.com:1337"))); 217 218 // Verify AlternateProtocol. 219 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( 220 net::HostPortPair::FromString("www.google.com:80"))); 221 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( 222 net::HostPortPair::FromString("mail.google.com:80"))); 223 net::AlternateProtocolInfo port_alternate_protocol = 224 http_server_props_manager_->GetAlternateProtocol( 225 net::HostPortPair::FromString("www.google.com:80")); 226 EXPECT_EQ(443, port_alternate_protocol.port); 227 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); 228 port_alternate_protocol = http_server_props_manager_->GetAlternateProtocol( 229 net::HostPortPair::FromString("mail.google.com:80")); 230 EXPECT_EQ(444, port_alternate_protocol.port); 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); 243 } 244 245 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { 246 ExpectPrefsUpdate(); 247 248 // Post an update task to the network thread. SetSupportsSpdy calls 249 // ScheduleUpdatePrefsOnNetworkThread. 250 251 // Add mail.google.com:443 as a supporting spdy server. 252 net::HostPortPair spdy_server_mail("mail.google.com", 443); 253 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 254 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 255 256 // Run the task. 257 base::RunLoop().RunUntilIdle(); 258 259 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 260 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 261 } 262 263 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { 264 ExpectPrefsUpdate(); 265 266 // Add SpdySetting for mail.google.com:443. 267 net::HostPortPair spdy_server_mail("mail.google.com", 443); 268 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; 269 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; 270 const uint32 value1 = 31337; 271 http_server_props_manager_->SetSpdySetting( 272 spdy_server_mail, id1, flags1, value1); 273 274 // Run the task. 275 base::RunLoop().RunUntilIdle(); 276 277 const net::SettingsMap& settings_map1_ret = 278 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 279 ASSERT_EQ(1U, settings_map1_ret.size()); 280 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 281 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 282 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 283 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 284 EXPECT_EQ(value1, flags_and_value1_ret.second); 285 286 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 287 } 288 289 TEST_F(HttpServerPropertiesManagerTest, ClearSpdySetting) { 290 ExpectPrefsUpdateRepeatedly(); 291 292 // Add SpdySetting for mail.google.com:443. 293 net::HostPortPair spdy_server_mail("mail.google.com", 443); 294 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; 295 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; 296 const uint32 value1 = 31337; 297 http_server_props_manager_->SetSpdySetting( 298 spdy_server_mail, id1, flags1, value1); 299 300 // Run the task. 301 base::RunLoop().RunUntilIdle(); 302 303 const net::SettingsMap& settings_map1_ret = 304 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 305 ASSERT_EQ(1U, settings_map1_ret.size()); 306 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 307 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 308 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 309 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 310 EXPECT_EQ(value1, flags_and_value1_ret.second); 311 312 // Clear SpdySetting for mail.google.com:443. 313 http_server_props_manager_->ClearSpdySettings(spdy_server_mail); 314 315 // Run the task. 316 base::RunLoop().RunUntilIdle(); 317 318 // Verify that there are no entries in the settings map for 319 // mail.google.com:443. 320 const net::SettingsMap& settings_map2_ret = 321 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 322 ASSERT_EQ(0U, settings_map2_ret.size()); 323 324 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 325 } 326 327 TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { 328 ExpectPrefsUpdateRepeatedly(); 329 330 // Add SpdySetting for mail.google.com:443. 331 net::HostPortPair spdy_server_mail("mail.google.com", 443); 332 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; 333 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; 334 const uint32 value1 = 31337; 335 http_server_props_manager_->SetSpdySetting( 336 spdy_server_mail, id1, flags1, value1); 337 338 // Run the task. 339 base::RunLoop().RunUntilIdle(); 340 341 const net::SettingsMap& settings_map1_ret = 342 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 343 ASSERT_EQ(1U, settings_map1_ret.size()); 344 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 345 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 346 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 347 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 348 EXPECT_EQ(value1, flags_and_value1_ret.second); 349 350 // Clear All SpdySettings. 351 http_server_props_manager_->ClearAllSpdySettings(); 352 353 // Run the task. 354 base::RunLoop().RunUntilIdle(); 355 356 // Verify that there are no entries in the settings map. 357 const net::SpdySettingsMap& spdy_settings_map2_ret = 358 http_server_props_manager_->spdy_settings_map(); 359 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); 360 361 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 362 } 363 364 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { 365 ExpectPrefsUpdate(); 366 367 net::HostPortPair spdy_server_mail("mail.google.com", 80); 368 EXPECT_FALSE( 369 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 370 http_server_props_manager_->SetAlternateProtocol( 371 spdy_server_mail, 443, net::NPN_SPDY_3, 1); 372 373 // Run the task. 374 base::RunLoop().RunUntilIdle(); 375 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 376 377 ASSERT_TRUE( 378 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); 379 net::AlternateProtocolInfo port_alternate_protocol = 380 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); 381 EXPECT_EQ(443, port_alternate_protocol.port); 382 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); 383 } 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 405 TEST_F(HttpServerPropertiesManagerTest, Clear) { 406 ExpectPrefsUpdate(); 407 408 net::HostPortPair spdy_server_mail("mail.google.com", 443); 409 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 410 http_server_props_manager_->SetAlternateProtocol( 411 spdy_server_mail, 443, net::NPN_SPDY_3, 1); 412 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); 413 414 const net::SpdySettingsIds id1 = net::SETTINGS_UPLOAD_BANDWIDTH; 415 const net::SpdySettingsFlags flags1 = net::SETTINGS_FLAG_PLEASE_PERSIST; 416 const uint32 value1 = 31337; 417 http_server_props_manager_->SetSpdySetting( 418 spdy_server_mail, id1, flags1, value1); 419 420 // Run the task. 421 base::RunLoop().RunUntilIdle(); 422 423 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 424 EXPECT_TRUE( 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); 430 431 // Check SPDY settings values. 432 const net::SettingsMap& settings_map1_ret = 433 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 434 ASSERT_EQ(1U, settings_map1_ret.size()); 435 net::SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); 436 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); 437 net::SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; 438 EXPECT_EQ(net::SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); 439 EXPECT_EQ(value1, flags_and_value1_ret.second); 440 441 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 442 443 ExpectPrefsUpdate(); 444 445 // Clear http server data, time out if we do not get a completion callback. 446 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); 447 base::RunLoop().Run(); 448 449 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy(spdy_server_mail)); 450 EXPECT_FALSE( 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); 456 457 const net::SettingsMap& settings_map2_ret = 458 http_server_props_manager_->GetSpdySettings(spdy_server_mail); 459 EXPECT_EQ(0U, settings_map2_ret.size()); 460 461 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 462 } 463 464 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { 465 // Post an update task to the UI thread. 466 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 467 // Shutdown comes before the task is executed. 468 http_server_props_manager_->ShutdownOnPrefThread(); 469 http_server_props_manager_.reset(); 470 // Run the task after shutdown and deletion. 471 base::RunLoop().RunUntilIdle(); 472 } 473 474 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache1) { 475 // Post an update task. 476 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 477 // Shutdown comes before the task is executed. 478 http_server_props_manager_->ShutdownOnPrefThread(); 479 // Run the task after shutdown, but before deletion. 480 base::RunLoop().RunUntilIdle(); 481 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 482 http_server_props_manager_.reset(); 483 base::RunLoop().RunUntilIdle(); 484 } 485 486 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache2) { 487 http_server_props_manager_->UpdateCacheFromPrefsOnUIConcrete(); 488 // Shutdown comes before the task is executed. 489 http_server_props_manager_->ShutdownOnPrefThread(); 490 // Run the task after shutdown, but before deletion. 491 base::RunLoop().RunUntilIdle(); 492 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 493 http_server_props_manager_.reset(); 494 base::RunLoop().RunUntilIdle(); 495 } 496 497 // 498 // Tests for shutdown when updating prefs. 499 // 500 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs0) { 501 // Post an update task to the IO thread. 502 http_server_props_manager_->ScheduleUpdatePrefsOnNetworkThread(); 503 // Shutdown comes before the task is executed. 504 http_server_props_manager_->ShutdownOnPrefThread(); 505 http_server_props_manager_.reset(); 506 // Run the task after shutdown and deletion. 507 base::RunLoop().RunUntilIdle(); 508 } 509 510 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs1) { 511 ExpectPrefsUpdate(); 512 // Post an update task. 513 http_server_props_manager_->ScheduleUpdatePrefsOnNetworkThread(); 514 // Shutdown comes before the task is executed. 515 http_server_props_manager_->ShutdownOnPrefThread(); 516 // Run the task after shutdown, but before deletion. 517 base::RunLoop().RunUntilIdle(); 518 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 519 http_server_props_manager_.reset(); 520 base::RunLoop().RunUntilIdle(); 521 } 522 523 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdatePrefs2) { 524 // This posts a task to the UI thread. 525 http_server_props_manager_->UpdatePrefsFromCacheOnNetworkThreadConcrete( 526 base::Closure()); 527 // Shutdown comes before the task is executed. 528 http_server_props_manager_->ShutdownOnPrefThread(); 529 // Run the task after shutdown, but before deletion. 530 base::RunLoop().RunUntilIdle(); 531 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 532 http_server_props_manager_.reset(); 533 base::RunLoop().RunUntilIdle(); 534 } 535 536 } // namespace 537 538 } // namespace net 539