OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/component_updater/cros_component_installer.h" | 5 #include "chrome/browser/component_updater/cros_component_installer.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/test/test_simple_task_runner.h" | 9 #include "base/test/test_simple_task_runner.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 class CrOSComponentInstallerTest : public PlatformTest { | 33 class CrOSComponentInstallerTest : public PlatformTest { |
34 public: | 34 public: |
35 CrOSComponentInstallerTest() {} | 35 CrOSComponentInstallerTest() {} |
36 void SetUp() override { PlatformTest::SetUp(); } | 36 void SetUp() override { PlatformTest::SetUp(); } |
37 | 37 |
38 private: | 38 private: |
39 content::TestBrowserThreadBundle thread_bundle_; | 39 content::TestBrowserThreadBundle thread_bundle_; |
40 DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTest); | 40 DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTest); |
41 }; | 41 }; |
42 | 42 |
43 class FakeInstallerTraits : public ComponentInstallerTraits { | 43 class MockCrOSComponentInstallerTraits : public CrOSComponentInstallerTraits { |
44 public: | 44 public: |
45 ~FakeInstallerTraits() override {} | 45 explicit MockCrOSComponentInstallerTraits(const ComponentConfig& config) |
46 | 46 : CrOSComponentInstallerTraits(config) {} |
47 bool VerifyInstallation(const base::DictionaryValue& manifest, | 47 MOCK_METHOD2(IsCompatible, |
48 const base::FilePath& dir) const override { | 48 bool(const std::string& env_version_str, |
49 return true; | 49 const std::string& min_env_version_str)); |
50 } | |
51 | |
52 bool SupportsGroupPolicyEnabledComponentUpdates() const override { | |
53 return true; | |
54 } | |
55 | |
56 bool RequiresNetworkEncryption() const override { return true; } | |
57 | |
58 update_client::CrxInstaller::Result OnCustomInstall( | |
59 const base::DictionaryValue& manifest, | |
60 const base::FilePath& install_dir) override { | |
61 return update_client::CrxInstaller::Result(0); | |
62 } | |
63 | |
64 void ComponentReady( | |
65 const base::Version& version, | |
66 const base::FilePath& install_dir, | |
67 std::unique_ptr<base::DictionaryValue> manifest) override {} | |
68 | |
69 base::FilePath GetRelativeInstallDir() const override { | |
70 return base::FilePath(FILE_PATH_LITERAL("fake")); | |
71 } | |
72 | |
73 void GetHash(std::vector<uint8_t>* hash) const override {} | |
74 | |
75 std::string GetName() const override { return "fake name"; } | |
76 | |
77 update_client::InstallerAttributes GetInstallerAttributes() const override { | |
78 update_client::InstallerAttributes installer_attributes; | |
79 return installer_attributes; | |
80 } | |
81 | |
82 std::vector<std::string> GetMimeTypes() const override { | |
83 return std::vector<std::string>(); | |
84 } | |
85 }; | 50 }; |
86 | 51 |
87 void install_callback(update_client::Error error) {} | 52 void load_callback(const std::string& result) {} |
88 | 53 |
89 TEST_F(CrOSComponentInstallerTest, BPPPCompatibleCrOSComponent) { | 54 TEST_F(CrOSComponentInstallerTest, BPPPCompatibleCrOSComponent) { |
90 BrowserProcessPlatformPart bppp; | 55 BrowserProcessPlatformPart bppp; |
91 ASSERT_EQ(bppp.IsCompatibleCrOSComponent("a"), false); | 56 ASSERT_EQ(bppp.IsCompatibleCrOSComponent("a"), false); |
92 bppp.AddCompatibleCrOSComponent("a"); | 57 bppp.AddCompatibleCrOSComponent("a"); |
93 ASSERT_EQ(bppp.IsCompatibleCrOSComponent("a"), true); | 58 ASSERT_EQ(bppp.IsCompatibleCrOSComponent("a"), true); |
94 } | 59 } |
95 | 60 |
96 TEST_F(CrOSComponentInstallerTest, RegisterComponentFail) { | 61 TEST_F(CrOSComponentInstallerTest, RegisterComponentSuccess) { |
97 std::unique_ptr<CrOSMockComponentUpdateService> cus = | 62 CrOSMockComponentUpdateService cus; |
98 base::MakeUnique<CrOSMockComponentUpdateService>(); | 63 EXPECT_CALL(cus, RegisterComponent(testing::_)).Times(1); |
99 EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(0); | 64 component_updater::CrOSComponent::InstallComponent( |
100 component_updater::CrOSComponent::InstallCrOSComponent( | 65 &cus, "epson-inkjet-printer-escpr", base::Bind(load_callback)); |
101 "a-component-not-exist", base::Bind(install_callback)); | |
102 base::RunLoop().RunUntilIdle(); | 66 base::RunLoop().RunUntilIdle(); |
103 } | 67 } |
104 | 68 |
| 69 TEST_F(CrOSComponentInstallerTest, RegisterComponentFail) { |
| 70 CrOSMockComponentUpdateService cus; |
| 71 EXPECT_CALL(cus, RegisterComponent(testing::_)).Times(0); |
| 72 component_updater::CrOSComponent::InstallComponent( |
| 73 &cus, "a-component-not-exist", base::Bind(load_callback)); |
| 74 base::RunLoop().RunUntilIdle(); |
| 75 } |
| 76 |
| 77 TEST_F(CrOSComponentInstallerTest, ComponentReadyCorrectManifest) { |
| 78 ComponentConfig config("a", "2.1", ""); |
| 79 MockCrOSComponentInstallerTraits traits(config); |
| 80 EXPECT_CALL(traits, IsCompatible(testing::_, testing::_)).Times(1); |
| 81 base::Version version; |
| 82 base::FilePath path; |
| 83 std::unique_ptr<base::DictionaryValue> manifest = |
| 84 base::MakeUnique<base::DictionaryValue>(); |
| 85 manifest->SetString("min_env_version", "2.1"); |
| 86 traits.ComponentReady(version, path, std::move(manifest)); |
| 87 base::RunLoop().RunUntilIdle(); |
| 88 } |
| 89 |
| 90 TEST_F(CrOSComponentInstallerTest, ComponentReadyWrongManifest) { |
| 91 ComponentConfig config("a", "2.1", ""); |
| 92 MockCrOSComponentInstallerTraits traits(config); |
| 93 EXPECT_CALL(traits, IsCompatible(testing::_, testing::_)).Times(0); |
| 94 base::Version version; |
| 95 base::FilePath path; |
| 96 std::unique_ptr<base::DictionaryValue> manifest = |
| 97 base::MakeUnique<base::DictionaryValue>(); |
| 98 traits.ComponentReady(version, path, std::move(manifest)); |
| 99 base::RunLoop().RunUntilIdle(); |
| 100 } |
| 101 |
| 102 TEST_F(CrOSComponentInstallerTest, IsCompatibleOrNot) { |
| 103 ComponentConfig config("", "", ""); |
| 104 CrOSComponentInstallerTraits traits(config); |
| 105 EXPECT_TRUE(traits.IsCompatible("1.0", "1.0")); |
| 106 EXPECT_TRUE(traits.IsCompatible("1.1", "1.0")); |
| 107 EXPECT_FALSE(traits.IsCompatible("1.0", "1.1")); |
| 108 EXPECT_FALSE(traits.IsCompatible("1.0", "2.0")); |
| 109 EXPECT_FALSE(traits.IsCompatible("1.c", "1.c")); |
| 110 EXPECT_FALSE(traits.IsCompatible("1", "1.1")); |
| 111 EXPECT_TRUE(traits.IsCompatible("1.1.1", "1.1")); |
| 112 } |
| 113 |
105 } // namespace component_updater | 114 } // namespace component_updater |
OLD | NEW |