OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/chromeos/extensions/device_local_account_external_polic y_loader.h" | 5 #include "chrome/browser/chromeos/extensions/device_local_account_external_polic y_loader.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/message_loop/message_loop_proxy.h" | |
14 #include "base/path_service.h" | 13 #include "base/path_service.h" |
15 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/single_thread_task_runner.h" | |
benwells
2015/05/07 00:05:26
Nit: this include isn't needed.
Pranay
2015/05/07 03:16:50
Done.
| |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/thread_task_runner_handle.h" | |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "base/version.h" | 19 #include "base/version.h" |
19 #include "chrome/browser/extensions/external_provider_impl.h" | 20 #include "chrome/browser/extensions/external_provider_impl.h" |
20 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/test/base/testing_browser_process.h" | 22 #include "chrome/test/base/testing_browser_process.h" |
22 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" | 23 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" |
23 #include "components/policy/core/common/policy_map.h" | 24 #include "components/policy/core/common/policy_map.h" |
24 #include "components/policy/core/common/policy_types.h" | 25 #include "components/policy/core/common/policy_types.h" |
25 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/notification_source.h" | 27 #include "content/public/browser/notification_source.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 | 136 |
136 DeviceLocalAccountExternalPolicyLoaderTest:: | 137 DeviceLocalAccountExternalPolicyLoaderTest:: |
137 ~DeviceLocalAccountExternalPolicyLoaderTest() { | 138 ~DeviceLocalAccountExternalPolicyLoaderTest() { |
138 } | 139 } |
139 | 140 |
140 void DeviceLocalAccountExternalPolicyLoaderTest::SetUp() { | 141 void DeviceLocalAccountExternalPolicyLoaderTest::SetUp() { |
141 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 142 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
142 cache_dir_ = temp_dir_.path().Append(kCacheDir); | 143 cache_dir_ = temp_dir_.path().Append(kCacheDir); |
143 ASSERT_TRUE(base::CreateDirectoryAndGetError(cache_dir_, NULL)); | 144 ASSERT_TRUE(base::CreateDirectoryAndGetError(cache_dir_, NULL)); |
144 request_context_getter_ = | 145 request_context_getter_ = |
145 new net::TestURLRequestContextGetter(base::MessageLoopProxy::current()); | 146 new net::TestURLRequestContextGetter(base::ThreadTaskRunnerHandle::Get()); |
146 TestingBrowserProcess::GetGlobal()->SetSystemRequestContext( | 147 TestingBrowserProcess::GetGlobal()->SetSystemRequestContext( |
147 request_context_getter_.get()); | 148 request_context_getter_.get()); |
148 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); | 149 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); |
149 | 150 |
150 loader_ = new DeviceLocalAccountExternalPolicyLoader(&store_, cache_dir_); | 151 loader_ = new DeviceLocalAccountExternalPolicyLoader(&store_, cache_dir_); |
151 provider_.reset(new extensions::ExternalProviderImpl( | 152 provider_.reset(new extensions::ExternalProviderImpl( |
152 &visitor_, | 153 &visitor_, |
153 loader_, | 154 loader_, |
154 NULL, | 155 NULL, |
155 extensions::Manifest::EXTERNAL_POLICY, | 156 extensions::Manifest::EXTERNAL_POLICY, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 } | 205 } |
205 | 206 |
206 // Verifies that the cache can be started and stopped correctly. | 207 // Verifies that the cache can be started and stopped correctly. |
207 TEST_F(DeviceLocalAccountExternalPolicyLoaderTest, ForceInstallListEmpty) { | 208 TEST_F(DeviceLocalAccountExternalPolicyLoaderTest, ForceInstallListEmpty) { |
208 // Set an empty force-install list policy. | 209 // Set an empty force-install list policy. |
209 store_.NotifyStoreLoaded(); | 210 store_.NotifyStoreLoaded(); |
210 | 211 |
211 // Start the cache. Verify that the loader announces an empty extension list. | 212 // Start the cache. Verify that the loader announces an empty extension list. |
212 EXPECT_CALL(visitor_, OnExternalProviderReady(provider_.get())) | 213 EXPECT_CALL(visitor_, OnExternalProviderReady(provider_.get())) |
213 .Times(1); | 214 .Times(1); |
214 loader_->StartCache(base::MessageLoopProxy::current()); | 215 loader_->StartCache(base::ThreadTaskRunnerHandle::Get()); |
215 base::RunLoop().RunUntilIdle(); | 216 base::RunLoop().RunUntilIdle(); |
216 VerifyAndResetVisitorCallExpectations(); | 217 VerifyAndResetVisitorCallExpectations(); |
217 | 218 |
218 // Stop the cache. Verify that the loader announces an empty extension list. | 219 // Stop the cache. Verify that the loader announces an empty extension list. |
219 EXPECT_CALL(visitor_, OnExternalProviderReady(provider_.get())) | 220 EXPECT_CALL(visitor_, OnExternalProviderReady(provider_.get())) |
220 .Times(1); | 221 .Times(1); |
221 base::RunLoop run_loop; | 222 base::RunLoop run_loop; |
222 loader_->StopCache(run_loop.QuitClosure()); | 223 loader_->StopCache(run_loop.QuitClosure()); |
223 VerifyAndResetVisitorCallExpectations(); | 224 VerifyAndResetVisitorCallExpectations(); |
224 | 225 |
225 // Spin the loop until the cache shutdown callback is invoked. Verify that at | 226 // Spin the loop until the cache shutdown callback is invoked. Verify that at |
226 // that point, no further file I/O tasks are pending. | 227 // that point, no further file I/O tasks are pending. |
227 run_loop.Run(); | 228 run_loop.Run(); |
228 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 229 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
229 } | 230 } |
230 | 231 |
231 // Verifies that when a force-install list policy referencing an extension is | 232 // Verifies that when a force-install list policy referencing an extension is |
232 // set and the cache is started, the loader downloads, caches and serves the | 233 // set and the cache is started, the loader downloads, caches and serves the |
233 // extension. | 234 // extension. |
234 TEST_F(DeviceLocalAccountExternalPolicyLoaderTest, ForceInstallListSet) { | 235 TEST_F(DeviceLocalAccountExternalPolicyLoaderTest, ForceInstallListSet) { |
235 // Set a force-install list policy that contains an invalid entry (which | 236 // Set a force-install list policy that contains an invalid entry (which |
236 // should be ignored) and a valid reference to an extension. | 237 // should be ignored) and a valid reference to an extension. |
237 SetForceInstallListPolicy(); | 238 SetForceInstallListPolicy(); |
238 | 239 |
239 // Start the cache. | 240 // Start the cache. |
240 loader_->StartCache(base::MessageLoopProxy::current()); | 241 loader_->StartCache(base::ThreadTaskRunnerHandle::Get()); |
241 | 242 |
242 // Spin the loop, allowing the loader to process the force-install list. | 243 // Spin the loop, allowing the loader to process the force-install list. |
243 // Verify that the loader announces an empty extension list. | 244 // Verify that the loader announces an empty extension list. |
244 net::TestURLFetcherFactory factory; | 245 net::TestURLFetcherFactory factory; |
245 EXPECT_CALL(visitor_, OnExternalProviderReady(provider_.get())) | 246 EXPECT_CALL(visitor_, OnExternalProviderReady(provider_.get())) |
246 .Times(1); | 247 .Times(1); |
247 base::MessageLoop::current()->RunUntilIdle(); | 248 base::MessageLoop::current()->RunUntilIdle(); |
248 | 249 |
249 // Verify that a downloader has started and is attempting to download an | 250 // Verify that a downloader has started and is attempting to download an |
250 // update manifest. | 251 // update manifest. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 loader_->StopCache(shutdown_run_loop.QuitClosure()); | 313 loader_->StopCache(shutdown_run_loop.QuitClosure()); |
313 VerifyAndResetVisitorCallExpectations(); | 314 VerifyAndResetVisitorCallExpectations(); |
314 | 315 |
315 // Spin the loop until the cache shutdown callback is invoked. Verify that at | 316 // Spin the loop until the cache shutdown callback is invoked. Verify that at |
316 // that point, no further file I/O tasks are pending. | 317 // that point, no further file I/O tasks are pending. |
317 shutdown_run_loop.Run(); | 318 shutdown_run_loop.Run(); |
318 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 319 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
319 } | 320 } |
320 | 321 |
321 } // namespace chromeos | 322 } // namespace chromeos |
OLD | NEW |