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 |
| index b723d52f6198195136c9c99f9d42f0a5c2546cfb..c32d05c1b6a86696c4dc6d5c473bbaf50d2933f6 100644 |
| --- a/chrome/browser/component_updater/cros_component_installer_unittest.cc |
| +++ b/chrome/browser/component_updater/cros_component_installer_unittest.cc |
| @@ -40,48 +40,11 @@ class CrOSComponentInstallerTest : public PlatformTest { |
| DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTest); |
| }; |
| -class FakeInstallerTraits : public ComponentInstallerTraits { |
| +class MockCrOSComponentInstallerTraits : public CrOSComponentInstallerTraits { |
| 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>(); |
| - } |
| + explicit MockCrOSComponentInstallerTraits(const ComponentConfig& config) |
| + : CrOSComponentInstallerTraits(config) {} |
| + MOCK_METHOD2(IsCompatible, bool(const std::string&, const std::string&)); |
| }; |
| void install_callback(update_client::Error error) {} |
| @@ -93,13 +56,46 @@ TEST_F(CrOSComponentInstallerTest, BPPPCompatibleCrOSComponent) { |
| ASSERT_EQ(bppp.IsCompatibleCrOSComponent("a"), true); |
| } |
| +TEST_F(CrOSComponentInstallerTest, RegisterComponentSuccess) { |
| + std::unique_ptr<CrOSMockComponentUpdateService> cus = |
| + base::MakeUnique<CrOSMockComponentUpdateService>(); |
| + EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(1); |
| + component_updater::CrOSComponent::InstallCrOSComponent( |
| + cus.get(), "epson-inkjet-printer-escpr", base::Bind(install_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", base::Bind(install_callback)); |
| + cus.get(), "a-component-not-exist", base::Bind(install_callback)); |
| base::RunLoop().RunUntilIdle(); |
| } |
| +TEST_F(CrOSComponentInstallerTest, ComponentReadyIsCompatible) { |
|
waffles
2017/05/26 17:28:26
This appears to be failing.
xiaochu
2017/05/26 19:44:02
Done.
I forgot to update the env_version number.
|
| + ComponentConfig config("epson-inkjet-printer-escpr", "", ""); |
| + std::unique_ptr<MockCrOSComponentInstallerTraits> traits( |
| + new MockCrOSComponentInstallerTraits(config)); |
| + base::Version version; |
| + base::FilePath path; |
| + std::unique_ptr<base::DictionaryValue> manifest(new base::DictionaryValue()); |
| + manifest->SetString("min_env_version", "1.0"); |
| + traits->ComponentReady(version, path, std::move(manifest)); |
| + EXPECT_CALL(*traits, IsCompatible(testing::_, "1.0")).Times(1); |
| +} |
| + |
| +TEST_F(CrOSComponentInstallerTest, IsCompatibleOrNot) { |
| + ComponentConfig config("", "", ""); |
| + std::unique_ptr<CrOSComponentInstallerTraits> traits( |
| + new CrOSComponentInstallerTraits(config)); |
| + EXPECT_TRUE(traits->IsCompatible("1.0", "1.0")); |
| + EXPECT_TRUE(traits->IsCompatible("1.0", "1.1")); |
| + EXPECT_FALSE(traits->IsCompatible("1.0", "2.0")); |
| + EXPECT_FALSE(traits->IsCompatible("1.c", "1.1")); |
| + EXPECT_FALSE(traits->IsCompatible("1", "1.1")); |
| + EXPECT_FALSE(traits->IsCompatible("1.1.1", "1.1")); |
| +} |
| + |
| } // namespace component_updater |