| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/extensions/external_provider_impl.h" | 21 #include "chrome/browser/extensions/external_provider_impl.h" |
| 22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/test/base/testing_browser_process.h" | 23 #include "chrome/test/base/testing_browser_process.h" |
| 24 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" | 24 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h" |
| 25 #include "components/policy/core/common/policy_map.h" | 25 #include "components/policy/core/common/policy_map.h" |
| 26 #include "components/policy/core/common/policy_types.h" | 26 #include "components/policy/core/common/policy_types.h" |
| 27 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/notification_source.h" | 28 #include "content/public/browser/notification_source.h" |
| 29 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
| 30 #include "content/public/test/test_utils.h" | 30 #include "content/public/test/test_utils.h" |
| 31 #include "extensions/browser/external_install_info.h" |
| 31 #include "extensions/browser/external_provider_interface.h" | 32 #include "extensions/browser/external_provider_interface.h" |
| 32 #include "extensions/browser/notification_types.h" | 33 #include "extensions/browser/notification_types.h" |
| 33 #include "extensions/browser/updater/extension_downloader.h" | 34 #include "extensions/browser/updater/extension_downloader.h" |
| 34 #include "extensions/common/extension.h" | 35 #include "extensions/common/extension.h" |
| 35 #include "extensions/common/extension_urls.h" | 36 #include "extensions/common/extension_urls.h" |
| 36 #include "extensions/common/manifest.h" | 37 #include "extensions/common/manifest.h" |
| 37 #include "net/url_request/test_url_fetcher_factory.h" | 38 #include "net/url_request/test_url_fetcher_factory.h" |
| 38 #include "net/url_request/url_fetcher_delegate.h" | 39 #include "net/url_request/url_fetcher_delegate.h" |
| 39 #include "net/url_request/url_request_context_getter.h" | 40 #include "net/url_request/url_request_context_getter.h" |
| 40 #include "net/url_request/url_request_test_util.h" | 41 #include "net/url_request/url_request_test_util.h" |
| 41 #include "policy/policy_constants.h" | 42 #include "policy/policy_constants.h" |
| 42 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
| 43 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 44 #include "url/gurl.h" | 45 #include "url/gurl.h" |
| 45 | 46 |
| 46 #if defined(OS_CHROMEOS) | 47 #if defined(OS_CHROMEOS) |
| 47 #include "chrome/browser/chromeos/settings/cros_settings.h" | 48 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 48 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 49 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 49 #endif // defined(OS_CHROMEOS) | 50 #endif // defined(OS_CHROMEOS) |
| 50 | 51 |
| 52 using ::testing::Field; |
| 51 using ::testing::InvokeWithoutArgs; | 53 using ::testing::InvokeWithoutArgs; |
| 52 using ::testing::Mock; | 54 using ::testing::Mock; |
| 55 using ::testing::StrEq; |
| 53 using ::testing::_; | 56 using ::testing::_; |
| 57 using extensions::ExternalInstallInfoFile; |
| 58 using extensions::ExternalInstallInfoUpdateUrl; |
| 54 | 59 |
| 55 namespace chromeos { | 60 namespace chromeos { |
| 56 | 61 |
| 57 namespace { | 62 namespace { |
| 58 | 63 |
| 59 const char kCacheDir[] = "cache"; | 64 const char kCacheDir[] = "cache"; |
| 60 const char kExtensionId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; | 65 const char kExtensionId[] = "ldnnhddmnhbkjipkidpdiheffobcpfmf"; |
| 61 const char kExtensionUpdateManifest[] = | 66 const char kExtensionUpdateManifest[] = |
| 62 "extensions/good_v1_update_manifest.xml"; | 67 "extensions/good_v1_update_manifest.xml"; |
| 63 const char kExtensionCRXSourceDir[] = "extensions"; | 68 const char kExtensionCRXSourceDir[] = "extensions"; |
| 64 const char kExtensionCRXFile[] = "good.crx"; | 69 const char kExtensionCRXFile[] = "good.crx"; |
| 65 const char kExtensionCRXVersion[] = "1.0.0.0"; | 70 const char kExtensionCRXVersion[] = "1.0.0.0"; |
| 66 | 71 |
| 67 class MockExternalPolicyProviderVisitor | 72 class MockExternalPolicyProviderVisitor |
| 68 : public extensions::ExternalProviderInterface::VisitorInterface { | 73 : public extensions::ExternalProviderInterface::VisitorInterface { |
| 69 public: | 74 public: |
| 70 MockExternalPolicyProviderVisitor(); | 75 MockExternalPolicyProviderVisitor(); |
| 71 virtual ~MockExternalPolicyProviderVisitor(); | 76 virtual ~MockExternalPolicyProviderVisitor(); |
| 72 | 77 |
| 73 MOCK_METHOD7(OnExternalExtensionFileFound, | 78 MOCK_METHOD1(OnExternalExtensionFileFound, |
| 74 bool(const std::string&, | 79 bool(const ExternalInstallInfoFile&)); |
| 75 const base::Version*, | 80 MOCK_METHOD2(OnExternalExtensionUpdateUrlFound, |
| 76 const base::FilePath&, | 81 bool(const ExternalInstallInfoUpdateUrl&, bool)); |
| 77 extensions::Manifest::Location, | |
| 78 int, | |
| 79 bool, | |
| 80 bool)); | |
| 81 MOCK_METHOD6(OnExternalExtensionUpdateUrlFound, | |
| 82 bool(const std::string&, | |
| 83 const std::string&, | |
| 84 const GURL&, | |
| 85 extensions::Manifest::Location, | |
| 86 int, | |
| 87 bool)); | |
| 88 MOCK_METHOD1(OnExternalProviderReady, | 82 MOCK_METHOD1(OnExternalProviderReady, |
| 89 void(const extensions::ExternalProviderInterface* provider)); | 83 void(const extensions::ExternalProviderInterface* provider)); |
| 84 MOCK_METHOD4(OnExternalProviderUpdateComplete, |
| 85 void(const extensions::ExternalProviderInterface*, |
| 86 const ScopedVector<ExternalInstallInfoUpdateUrl>&, |
| 87 const ScopedVector<ExternalInstallInfoFile>&, |
| 88 const std::set<std::string>& removed_extensions)); |
| 90 | 89 |
| 91 private: | 90 private: |
| 92 DISALLOW_COPY_AND_ASSIGN(MockExternalPolicyProviderVisitor); | 91 DISALLOW_COPY_AND_ASSIGN(MockExternalPolicyProviderVisitor); |
| 93 }; | 92 }; |
| 94 | 93 |
| 95 MockExternalPolicyProviderVisitor::MockExternalPolicyProviderVisitor() { | 94 MockExternalPolicyProviderVisitor::MockExternalPolicyProviderVisitor() { |
| 96 } | 95 } |
| 97 | 96 |
| 98 MockExternalPolicyProviderVisitor::~MockExternalPolicyProviderVisitor() { | 97 MockExternalPolicyProviderVisitor::~MockExternalPolicyProviderVisitor() { |
| 99 } | 98 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 VerifyAndResetVisitorCallExpectations(); | 160 VerifyAndResetVisitorCallExpectations(); |
| 162 } | 161 } |
| 163 | 162 |
| 164 void DeviceLocalAccountExternalPolicyLoaderTest::TearDown() { | 163 void DeviceLocalAccountExternalPolicyLoaderTest::TearDown() { |
| 165 TestingBrowserProcess::GetGlobal()->SetSystemRequestContext(NULL); | 164 TestingBrowserProcess::GetGlobal()->SetSystemRequestContext(NULL); |
| 166 } | 165 } |
| 167 | 166 |
| 168 void DeviceLocalAccountExternalPolicyLoaderTest:: | 167 void DeviceLocalAccountExternalPolicyLoaderTest:: |
| 169 VerifyAndResetVisitorCallExpectations() { | 168 VerifyAndResetVisitorCallExpectations() { |
| 170 Mock::VerifyAndClearExpectations(&visitor_); | 169 Mock::VerifyAndClearExpectations(&visitor_); |
| 171 EXPECT_CALL(visitor_, OnExternalExtensionFileFound(_, _, _, _, _, _, _)) | 170 EXPECT_CALL(visitor_, OnExternalExtensionFileFound(_)).Times(0); |
| 172 .Times(0); | 171 EXPECT_CALL(visitor_, OnExternalExtensionUpdateUrlFound(_, _)).Times(0); |
| 173 EXPECT_CALL(visitor_, OnExternalExtensionUpdateUrlFound(_, _, _, _, _, _)) | |
| 174 .Times(0); | |
| 175 EXPECT_CALL(visitor_, OnExternalProviderReady(_)) | 172 EXPECT_CALL(visitor_, OnExternalProviderReady(_)) |
| 176 .Times(0); | 173 .Times(0); |
| 174 EXPECT_CALL(visitor_, OnExternalProviderUpdateComplete(_, _, _, _)).Times(0); |
| 177 } | 175 } |
| 178 | 176 |
| 179 void DeviceLocalAccountExternalPolicyLoaderTest::SetForceInstallListPolicy() { | 177 void DeviceLocalAccountExternalPolicyLoaderTest::SetForceInstallListPolicy() { |
| 180 scoped_ptr<base::ListValue> forcelist(new base::ListValue); | 178 scoped_ptr<base::ListValue> forcelist(new base::ListValue); |
| 181 forcelist->AppendString("invalid"); | 179 forcelist->AppendString("invalid"); |
| 182 forcelist->AppendString(base::StringPrintf( | 180 forcelist->AppendString(base::StringPrintf( |
| 183 "%s;%s", | 181 "%s;%s", |
| 184 kExtensionId, | 182 kExtensionId, |
| 185 extension_urls::GetWebstoreUpdateUrl().spec().c_str())); | 183 extension_urls::GetWebstoreUpdateUrl().spec().c_str())); |
| 186 store_.policy_map_.Set(policy::key::kExtensionInstallForcelist, | 184 store_.policy_map_.Set(policy::key::kExtensionInstallForcelist, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 temp_dir_.path().Append(kExtensionCRXFile))); | 279 temp_dir_.path().Append(kExtensionCRXFile))); |
| 282 fetcher->set_response_code(200); | 280 fetcher->set_response_code(200); |
| 283 fetcher->SetResponseFilePath(temp_dir_.path().Append(kExtensionCRXFile)); | 281 fetcher->SetResponseFilePath(temp_dir_.path().Append(kExtensionCRXFile)); |
| 284 fetcher->delegate()->OnURLFetchComplete(fetcher); | 282 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 285 | 283 |
| 286 // Spin the loop. Verify that the loader announces the presence of a new CRX | 284 // Spin the loop. Verify that the loader announces the presence of a new CRX |
| 287 // file, served from the cache directory. | 285 // file, served from the cache directory. |
| 288 const base::FilePath cached_crx_path = cache_dir_.Append(base::StringPrintf( | 286 const base::FilePath cached_crx_path = cache_dir_.Append(base::StringPrintf( |
| 289 "%s-%s.crx", kExtensionId, kExtensionCRXVersion)); | 287 "%s-%s.crx", kExtensionId, kExtensionCRXVersion)); |
| 290 base::RunLoop cache_run_loop; | 288 base::RunLoop cache_run_loop; |
| 291 EXPECT_CALL(visitor_, OnExternalExtensionFileFound( | 289 EXPECT_CALL( |
| 292 kExtensionId, | 290 visitor_, |
| 293 _, | 291 OnExternalExtensionFileFound(AllOf( |
| 294 cached_crx_path, | 292 Field(&extensions::ExternalInstallInfoFile::extension_id, |
| 295 extensions::Manifest::EXTERNAL_POLICY, | 293 StrEq(kExtensionId)), |
| 296 _, | 294 Field(&extensions::ExternalInstallInfoFile::path, cached_crx_path), |
| 297 _, | 295 Field(&extensions::ExternalInstallInfoFile::crx_location, |
| 298 _)); | 296 extensions::Manifest::EXTERNAL_POLICY)))); |
| 299 EXPECT_CALL(visitor_, OnExternalProviderReady(provider_.get())) | 297 EXPECT_CALL(visitor_, OnExternalProviderReady(provider_.get())) |
| 300 .Times(1) | 298 .Times(1) |
| 301 .WillOnce(InvokeWithoutArgs(&cache_run_loop, &base::RunLoop::Quit)); | 299 .WillOnce(InvokeWithoutArgs(&cache_run_loop, &base::RunLoop::Quit)); |
| 302 cache_run_loop.Run(); | 300 cache_run_loop.Run(); |
| 303 VerifyAndResetVisitorCallExpectations(); | 301 VerifyAndResetVisitorCallExpectations(); |
| 304 | 302 |
| 305 // Verify that the CRX file actually exists in the cache directory and its | 303 // Verify that the CRX file actually exists in the cache directory and its |
| 306 // contents matches the file returned to the downloader. | 304 // contents matches the file returned to the downloader. |
| 307 EXPECT_TRUE(base::ContentsEqual( | 305 EXPECT_TRUE(base::ContentsEqual( |
| 308 test_dir_.Append(kExtensionCRXSourceDir).Append(kExtensionCRXFile), | 306 test_dir_.Append(kExtensionCRXSourceDir).Append(kExtensionCRXFile), |
| 309 cached_crx_path)); | 307 cached_crx_path)); |
| 310 | 308 |
| 311 // Stop the cache. Verify that the loader announces an empty extension list. | 309 // Stop the cache. Verify that the loader announces an empty extension list. |
| 312 EXPECT_CALL(visitor_, OnExternalProviderReady(provider_.get())) | 310 EXPECT_CALL(visitor_, OnExternalProviderReady(provider_.get())) |
| 313 .Times(1); | 311 .Times(1); |
| 314 base::RunLoop shutdown_run_loop; | 312 base::RunLoop shutdown_run_loop; |
| 315 loader_->StopCache(shutdown_run_loop.QuitClosure()); | 313 loader_->StopCache(shutdown_run_loop.QuitClosure()); |
| 316 VerifyAndResetVisitorCallExpectations(); | 314 VerifyAndResetVisitorCallExpectations(); |
| 317 | 315 |
| 318 // 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 |
| 319 // that point, no further file I/O tasks are pending. | 317 // that point, no further file I/O tasks are pending. |
| 320 shutdown_run_loop.Run(); | 318 shutdown_run_loop.Run(); |
| 321 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); | 319 EXPECT_TRUE(base::MessageLoop::current()->IsIdleForTesting()); |
| 322 } | 320 } |
| 323 | 321 |
| 324 } // namespace chromeos | 322 } // namespace chromeos |
| OLD | NEW |