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 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 | 38 |
39 virtual ~TestingHttpServerPropertiesManager() {} | 39 virtual ~TestingHttpServerPropertiesManager() {} |
40 | 40 |
41 // Make these methods public for testing. | 41 // Make these methods public for testing. |
42 using HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread; | 42 using HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread; |
43 using HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread; | 43 using HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread; |
44 | 44 |
45 // Post tasks without a delay during tests. | 45 // Post tasks without a delay during tests. |
46 virtual void StartPrefsUpdateTimerOnNetworkThread( | 46 virtual void StartPrefsUpdateTimerOnNetworkThread( |
47 base::TimeDelta delay) OVERRIDE { | 47 base::TimeDelta delay) override { |
48 HttpServerPropertiesManager::StartPrefsUpdateTimerOnNetworkThread( | 48 HttpServerPropertiesManager::StartPrefsUpdateTimerOnNetworkThread( |
49 base::TimeDelta()); | 49 base::TimeDelta()); |
50 } | 50 } |
51 | 51 |
52 void UpdateCacheFromPrefsOnUIConcrete() { | 52 void UpdateCacheFromPrefsOnUIConcrete() { |
53 HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread(); | 53 HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread(); |
54 } | 54 } |
55 | 55 |
56 // Post tasks without a delay during tests. | 56 // Post tasks without a delay during tests. |
57 virtual void StartCacheUpdateTimerOnPrefThread( | 57 virtual void StartCacheUpdateTimerOnPrefThread( |
58 base::TimeDelta delay) OVERRIDE { | 58 base::TimeDelta delay) override { |
59 HttpServerPropertiesManager::StartCacheUpdateTimerOnPrefThread( | 59 HttpServerPropertiesManager::StartCacheUpdateTimerOnPrefThread( |
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()); |
(...skipping 12 matching lines...) Expand all Loading... |
81 net::SupportsQuicMap* supports_quic_map)); | 81 net::SupportsQuicMap* supports_quic_map)); |
82 | 82 |
83 private: | 83 private: |
84 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); | 84 DISALLOW_COPY_AND_ASSIGN(TestingHttpServerPropertiesManager); |
85 }; | 85 }; |
86 | 86 |
87 class HttpServerPropertiesManagerTest : public testing::Test { | 87 class HttpServerPropertiesManagerTest : public testing::Test { |
88 protected: | 88 protected: |
89 HttpServerPropertiesManagerTest() {} | 89 HttpServerPropertiesManagerTest() {} |
90 | 90 |
91 virtual void SetUp() OVERRIDE { | 91 virtual void SetUp() override { |
92 pref_service_.registry()->RegisterDictionaryPref(kTestHttpServerProperties); | 92 pref_service_.registry()->RegisterDictionaryPref(kTestHttpServerProperties); |
93 http_server_props_manager_.reset( | 93 http_server_props_manager_.reset( |
94 new StrictMock<TestingHttpServerPropertiesManager>( | 94 new StrictMock<TestingHttpServerPropertiesManager>( |
95 &pref_service_, | 95 &pref_service_, |
96 kTestHttpServerProperties, | 96 kTestHttpServerProperties, |
97 base::MessageLoop::current()->message_loop_proxy())); | 97 base::MessageLoop::current()->message_loop_proxy())); |
98 ExpectCacheUpdate(); | 98 ExpectCacheUpdate(); |
99 base::RunLoop().RunUntilIdle(); | 99 base::RunLoop().RunUntilIdle(); |
100 } | 100 } |
101 | 101 |
102 virtual void TearDown() OVERRIDE { | 102 virtual void TearDown() override { |
103 if (http_server_props_manager_.get()) | 103 if (http_server_props_manager_.get()) |
104 http_server_props_manager_->ShutdownOnPrefThread(); | 104 http_server_props_manager_->ShutdownOnPrefThread(); |
105 base::RunLoop().RunUntilIdle(); | 105 base::RunLoop().RunUntilIdle(); |
106 http_server_props_manager_.reset(); | 106 http_server_props_manager_.reset(); |
107 } | 107 } |
108 | 108 |
109 void ExpectCacheUpdate() { | 109 void ExpectCacheUpdate() { |
110 EXPECT_CALL(*http_server_props_manager_, UpdateCacheFromPrefsOnPrefThread()) | 110 EXPECT_CALL(*http_server_props_manager_, UpdateCacheFromPrefsOnPrefThread()) |
111 .WillOnce(Invoke(http_server_props_manager_.get(), | 111 .WillOnce(Invoke(http_server_props_manager_.get(), |
112 &TestingHttpServerPropertiesManager:: | 112 &TestingHttpServerPropertiesManager:: |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 // Run the task after shutdown, but before deletion. | 529 // Run the task after shutdown, but before deletion. |
530 base::RunLoop().RunUntilIdle(); | 530 base::RunLoop().RunUntilIdle(); |
531 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 531 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
532 http_server_props_manager_.reset(); | 532 http_server_props_manager_.reset(); |
533 base::RunLoop().RunUntilIdle(); | 533 base::RunLoop().RunUntilIdle(); |
534 } | 534 } |
535 | 535 |
536 } // namespace | 536 } // namespace |
537 | 537 |
538 } // namespace net | 538 } // namespace net |
OLD | NEW |