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