| 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 <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 base::DictionaryValue prefs_; | 73 base::DictionaryValue prefs_; |
| 74 base::Closure prefs_changed_callback_; | 74 base::Closure prefs_changed_callback_; |
| 75 | 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(MockPrefDelegate); | 76 DISALLOW_COPY_AND_ASSIGN(MockPrefDelegate); |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { | 79 class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { |
| 80 public: | 80 public: |
| 81 TestingHttpServerPropertiesManager( | 81 TestingHttpServerPropertiesManager( |
| 82 HttpServerPropertiesManager::PrefDelegate* pref_delegate, | 82 HttpServerPropertiesManager::PrefDelegate* pref_delegate, |
| 83 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | 83 scoped_refptr<base::SingleThreadTaskRunner> pref_task_runner, |
| 84 : HttpServerPropertiesManager(pref_delegate, io_task_runner) { | 84 scoped_refptr<base::SingleThreadTaskRunner> net_task_runner) |
| 85 : HttpServerPropertiesManager(pref_delegate, |
| 86 pref_task_runner, |
| 87 net_task_runner) { |
| 85 InitializeOnNetworkThread(); | 88 InitializeOnNetworkThread(); |
| 86 } | 89 } |
| 87 | 90 |
| 88 ~TestingHttpServerPropertiesManager() override {} | 91 ~TestingHttpServerPropertiesManager() override {} |
| 89 | 92 |
| 90 // Make these methods public for testing. | 93 // Make these methods public for testing. |
| 91 using HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread; | 94 using HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread; |
| 92 | 95 |
| 93 // Post tasks without a delay during tests. | 96 // Post tasks without a delay during tests. |
| 94 void StartPrefsUpdateTimerOnNetworkThread(base::TimeDelta delay) override { | 97 void StartPrefsUpdateTimerOnNetworkThread(base::TimeDelta delay) override { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> { | 155 class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> { |
| 153 protected: | 156 protected: |
| 154 HttpServerPropertiesManagerTest() | 157 HttpServerPropertiesManagerTest() |
| 155 : net_test_task_runner_(new TestMockTimeTaskRunner()) {} | 158 : net_test_task_runner_(new TestMockTimeTaskRunner()) {} |
| 156 | 159 |
| 157 void SetUp() override { | 160 void SetUp() override { |
| 158 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1); | 161 one_day_from_now_ = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 159 pref_delegate_ = new MockPrefDelegate; | 162 pref_delegate_ = new MockPrefDelegate; |
| 160 http_server_props_manager_.reset( | 163 http_server_props_manager_.reset( |
| 161 new StrictMock<TestingHttpServerPropertiesManager>( | 164 new StrictMock<TestingHttpServerPropertiesManager>( |
| 162 pref_delegate_, net_test_task_runner_)); | 165 pref_delegate_, base::ThreadTaskRunnerHandle::Get(), |
| 166 net_test_task_runner_)); |
| 163 | 167 |
| 164 ExpectCacheUpdate(); | 168 ExpectCacheUpdate(); |
| 165 base::RunLoop().RunUntilIdle(); | 169 base::RunLoop().RunUntilIdle(); |
| 166 } | 170 } |
| 167 | 171 |
| 168 void TearDown() override { | 172 void TearDown() override { |
| 169 if (http_server_props_manager_.get()) | 173 if (http_server_props_manager_.get()) |
| 170 http_server_props_manager_->ShutdownOnPrefThread(); | 174 http_server_props_manager_->ShutdownOnPrefThread(); |
| 171 base::RunLoop().RunUntilIdle(); | 175 base::RunLoop().RunUntilIdle(); |
| 172 http_server_props_manager_.reset(); | 176 http_server_props_manager_.reset(); |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 // Shutdown comes before the task is executed. | 1291 // Shutdown comes before the task is executed. |
| 1288 http_server_props_manager_->ShutdownOnPrefThread(); | 1292 http_server_props_manager_->ShutdownOnPrefThread(); |
| 1289 // Run the task after shutdown, but before deletion. | 1293 // Run the task after shutdown, but before deletion. |
| 1290 base::RunLoop().RunUntilIdle(); | 1294 base::RunLoop().RunUntilIdle(); |
| 1291 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1295 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 1292 http_server_props_manager_.reset(); | 1296 http_server_props_manager_.reset(); |
| 1293 base::RunLoop().RunUntilIdle(); | 1297 base::RunLoop().RunUntilIdle(); |
| 1294 } | 1298 } |
| 1295 | 1299 |
| 1296 } // namespace net | 1300 } // namespace net |
| OLD | NEW |