Chromium Code Reviews| Index: chrome/browser/component_updater/cros_component_installer_unittest.cc |
| diff --git a/chrome/browser/component_updater/cros_component_installer_unittest.cc b/chrome/browser/component_updater/cros_component_installer_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ee794cfdab923d35cb90a7d09b2a11e0f994274e |
| --- /dev/null |
| +++ b/chrome/browser/component_updater/cros_component_installer_unittest.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/component_updater/cros_component_installer.h" |
|
sky
2017/05/24 16:47:20
style guide says newline between 5/6.
xiaochu
2017/05/24 19:56:54
Done.
|
| +#include "base/memory/ptr_util.h" |
| +#include "base/run_loop.h" |
| +#include "base/test/test_simple_task_runner.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| +#include "build/build_config.h" |
| +#include "chrome/test/base/testing_browser_process.h" |
| +#include "components/component_updater/mock_component_updater_service.h" |
| +#include "content/public/test/test_browser_thread_bundle.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "testing/platform_test.h" |
| + |
| +namespace component_updater { |
| + |
| +class CrOSMockComponentUpdateService |
| + : public component_updater::MockComponentUpdateService { |
| + public: |
| + CrOSMockComponentUpdateService() {} |
| + ~CrOSMockComponentUpdateService() override {} |
| + scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override { |
| + return base::ThreadTaskRunnerHandle::Get(); |
| + } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(CrOSMockComponentUpdateService); |
| +}; |
| + |
| +class CrOSComponentInstallerTest : public PlatformTest { |
| + public: |
| + CrOSComponentInstallerTest() {} |
| + void SetUp() override { PlatformTest::SetUp(); } |
| + |
| + private: |
| + content::TestBrowserThreadBundle thread_bundle_; |
| + DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTest); |
| +}; |
| + |
| +class FakeInstallerTraits : public ComponentInstallerTraits { |
| + public: |
| + ~FakeInstallerTraits() override {} |
| + |
| + bool VerifyInstallation(const base::DictionaryValue& manifest, |
| + const base::FilePath& dir) const override { |
| + return true; |
| + } |
| + |
| + bool SupportsGroupPolicyEnabledComponentUpdates() const override { |
| + return true; |
| + } |
| + |
| + bool RequiresNetworkEncryption() const override { return true; } |
| + |
| + update_client::CrxInstaller::Result OnCustomInstall( |
| + const base::DictionaryValue& manifest, |
| + const base::FilePath& install_dir) override { |
| + return update_client::CrxInstaller::Result(0); |
| + } |
| + |
| + void ComponentReady( |
| + const base::Version& version, |
| + const base::FilePath& install_dir, |
| + std::unique_ptr<base::DictionaryValue> manifest) override {} |
| + |
| + base::FilePath GetRelativeInstallDir() const override { |
| + return base::FilePath(FILE_PATH_LITERAL("fake")); |
| + } |
| + |
| + void GetHash(std::vector<uint8_t>* hash) const override {} |
| + |
| + std::string GetName() const override { return "fake name"; } |
| + |
| + update_client::InstallerAttributes GetInstallerAttributes() const override { |
| + update_client::InstallerAttributes installer_attributes; |
| + return installer_attributes; |
| + } |
| + |
| + std::vector<std::string> GetMimeTypes() const override { |
| + return std::vector<std::string>(); |
| + } |
| +}; |
| +#if defined(OS_CHROMEOS) |
|
sky
2017/05/24 16:47:20
Shouldn't this file only be compiled on chromeos?
xiaochu
2017/05/24 19:56:54
Done.
Yes, macro removed.
|
| +TEST_F(CrOSComponentInstallerTest, RegisterComponentSuccess) { |
| + std::unique_ptr<CrOSMockComponentUpdateService> cus = |
| + base::MakeUnique<CrOSMockComponentUpdateService>(); |
| + EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(1); |
| + component_updater::CrOSComponent::InstallCrOSComponent( |
| + "epson-inkjet-printer-escpr", update_client::Callback()); |
| + base::RunLoop().RunUntilIdle(); |
| +} |
| +TEST_F(CrOSComponentInstallerTest, RegisterComponentFail) { |
| + std::unique_ptr<CrOSMockComponentUpdateService> cus = |
| + base::MakeUnique<CrOSMockComponentUpdateService>(); |
| + EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(0); |
| + component_updater::CrOSComponent::InstallCrOSComponent( |
| + "a-component-not-exist", update_client::Callback()); |
| + base::RunLoop().RunUntilIdle(); |
| +} |
| +#endif // defined(OS_CHROMEOS) |
| + |
| +} // namespace component_updater |