OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #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.
| |
6 #include "base/memory/ptr_util.h" | |
7 #include "base/run_loop.h" | |
8 #include "base/test/test_simple_task_runner.h" | |
9 #include "base/threading/thread_task_runner_handle.h" | |
10 #include "build/build_config.h" | |
11 #include "chrome/test/base/testing_browser_process.h" | |
12 #include "components/component_updater/mock_component_updater_service.h" | |
13 #include "content/public/test/test_browser_thread_bundle.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 #include "testing/platform_test.h" | |
16 | |
17 namespace component_updater { | |
18 | |
19 class CrOSMockComponentUpdateService | |
20 : public component_updater::MockComponentUpdateService { | |
21 public: | |
22 CrOSMockComponentUpdateService() {} | |
23 ~CrOSMockComponentUpdateService() override {} | |
24 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override { | |
25 return base::ThreadTaskRunnerHandle::Get(); | |
26 } | |
27 | |
28 private: | |
29 DISALLOW_COPY_AND_ASSIGN(CrOSMockComponentUpdateService); | |
30 }; | |
31 | |
32 class CrOSComponentInstallerTest : public PlatformTest { | |
33 public: | |
34 CrOSComponentInstallerTest() {} | |
35 void SetUp() override { PlatformTest::SetUp(); } | |
36 | |
37 private: | |
38 content::TestBrowserThreadBundle thread_bundle_; | |
39 DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTest); | |
40 }; | |
41 | |
42 class FakeInstallerTraits : public ComponentInstallerTraits { | |
43 public: | |
44 ~FakeInstallerTraits() override {} | |
45 | |
46 bool VerifyInstallation(const base::DictionaryValue& manifest, | |
47 const base::FilePath& dir) const override { | |
48 return true; | |
49 } | |
50 | |
51 bool SupportsGroupPolicyEnabledComponentUpdates() const override { | |
52 return true; | |
53 } | |
54 | |
55 bool RequiresNetworkEncryption() const override { return true; } | |
56 | |
57 update_client::CrxInstaller::Result OnCustomInstall( | |
58 const base::DictionaryValue& manifest, | |
59 const base::FilePath& install_dir) override { | |
60 return update_client::CrxInstaller::Result(0); | |
61 } | |
62 | |
63 void ComponentReady( | |
64 const base::Version& version, | |
65 const base::FilePath& install_dir, | |
66 std::unique_ptr<base::DictionaryValue> manifest) override {} | |
67 | |
68 base::FilePath GetRelativeInstallDir() const override { | |
69 return base::FilePath(FILE_PATH_LITERAL("fake")); | |
70 } | |
71 | |
72 void GetHash(std::vector<uint8_t>* hash) const override {} | |
73 | |
74 std::string GetName() const override { return "fake name"; } | |
75 | |
76 update_client::InstallerAttributes GetInstallerAttributes() const override { | |
77 update_client::InstallerAttributes installer_attributes; | |
78 return installer_attributes; | |
79 } | |
80 | |
81 std::vector<std::string> GetMimeTypes() const override { | |
82 return std::vector<std::string>(); | |
83 } | |
84 }; | |
85 #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.
| |
86 TEST_F(CrOSComponentInstallerTest, RegisterComponentSuccess) { | |
87 std::unique_ptr<CrOSMockComponentUpdateService> cus = | |
88 base::MakeUnique<CrOSMockComponentUpdateService>(); | |
89 EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(1); | |
90 component_updater::CrOSComponent::InstallCrOSComponent( | |
91 "epson-inkjet-printer-escpr", update_client::Callback()); | |
92 base::RunLoop().RunUntilIdle(); | |
93 } | |
94 TEST_F(CrOSComponentInstallerTest, RegisterComponentFail) { | |
95 std::unique_ptr<CrOSMockComponentUpdateService> cus = | |
96 base::MakeUnique<CrOSMockComponentUpdateService>(); | |
97 EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(0); | |
98 component_updater::CrOSComponent::InstallCrOSComponent( | |
99 "a-component-not-exist", update_client::Callback()); | |
100 base::RunLoop().RunUntilIdle(); | |
101 } | |
102 #endif // defined(OS_CHROMEOS) | |
103 | |
104 } // namespace component_updater | |
OLD | NEW |