[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
sorin | b120440b | 2015-04-27 16:34:15 | [diff] [blame] | 5 | #ifndef COMPONENTS_UPDATE_CLIENT_TEST_INSTALLER_H_ |
6 | #define COMPONENTS_UPDATE_CLIENT_TEST_INSTALLER_H_ | ||||
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 7 | |
Sorin Jianu | 990ee14 | 2017-06-02 22:34:08 | [diff] [blame] | 8 | #include <memory> |
[email protected] | 28ea9ac | 2014-05-03 22:07:18 | [diff] [blame] | 9 | #include <string> |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 10 | #include <utility> |
[email protected] | 28ea9ac | 2014-05-03 22:07:18 | [diff] [blame] | 11 | |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 13 | #include "components/update_client/update_client.h" |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 14 | |
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 15 | namespace update_client { |
[email protected] | 055981f | 2014-01-17 20:22:32 | [diff] [blame] | 16 | |
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 17 | // TODO(sorin): consider reducing the number of the installer mocks. |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 18 | // A TestInstaller is an installer that does nothing for installation except |
19 | // increment a counter. | ||||
sorin | 9797aba | 2015-04-17 17:15:03 | [diff] [blame] | 20 | class TestInstaller : public CrxInstaller { |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 21 | public: |
[email protected] | de0fdca2 | 2014-08-19 05:26:09 | [diff] [blame] | 22 | TestInstaller(); |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 23 | |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 24 | void OnUpdateError(int error) override; |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 25 | |
Sorin Jianu | 7aa6d1f | 2017-10-13 20:29:29 | [diff] [blame] | 26 | void Install(const base::FilePath& unpack_path, |
Sorin Jianu | ea5534e9 | 2017-10-27 01:40:28 | [diff] [blame] | 27 | const std::string& public_key, |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 28 | Callback callback) override; |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 29 | |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 30 | bool GetInstalledFile(const std::string& file, |
31 | base::FilePath* installed_file) override; | ||||
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 32 | |
bauerb | 1f6657e7 | 2015-02-09 00:00:27 | [diff] [blame] | 33 | bool Uninstall() override; |
34 | |||||
sorin | b120440b | 2015-04-27 16:34:15 | [diff] [blame] | 35 | int error() const { return error_; } |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 36 | |
sorin | b120440b | 2015-04-27 16:34:15 | [diff] [blame] | 37 | int install_count() const { return install_count_; } |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 38 | |
39 | protected: | ||||
bauerb | 810e60f4 | 2015-02-05 01:09:10 | [diff] [blame] | 40 | ~TestInstaller() override; |
41 | |||||
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 42 | void InstallComplete(Callback callback, const Result& result) const; |
Sorin Jianu | f40ab4b3 | 2017-10-06 22:53:41 | [diff] [blame] | 43 | |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 44 | int error_; |
45 | int install_count_; | ||||
Sorin Jianu | 23f70f75 | 2017-05-30 16:21:58 | [diff] [blame] | 46 | |
47 | private: | ||||
48 | // Contains the |unpack_path| argument of the Install call. | ||||
49 | base::FilePath unpack_path_; | ||||
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 50 | }; |
51 | |||||
52 | // A ReadOnlyTestInstaller is an installer that knows about files in an existing | ||||
53 | // directory. It will not write to the directory. | ||||
54 | class ReadOnlyTestInstaller : public TestInstaller { | ||||
55 | public: | ||||
56 | explicit ReadOnlyTestInstaller(const base::FilePath& installed_path); | ||||
57 | |||||
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 58 | bool GetInstalledFile(const std::string& file, |
59 | base::FilePath* installed_file) override; | ||||
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 60 | |
61 | private: | ||||
bauerb | 810e60f4 | 2015-02-05 01:09:10 | [diff] [blame] | 62 | ~ReadOnlyTestInstaller() override; |
63 | |||||
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 64 | base::FilePath install_directory_; |
65 | }; | ||||
66 | |||||
67 | // A VersionedTestInstaller is an installer that installs files into versioned | ||||
68 | // directories (e.g. somedir/25.23.89.141/<files>). | ||||
69 | class VersionedTestInstaller : public TestInstaller { | ||||
[email protected] | d0c8b8b4 | 2014-05-06 05:11:45 | [diff] [blame] | 70 | public: |
[email protected] | de0fdca2 | 2014-08-19 05:26:09 | [diff] [blame] | 71 | VersionedTestInstaller(); |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 72 | |
Sorin Jianu | 7aa6d1f | 2017-10-13 20:29:29 | [diff] [blame] | 73 | void Install(const base::FilePath& unpack_path, |
Sorin Jianu | ea5534e9 | 2017-10-27 01:40:28 | [diff] [blame] | 74 | const std::string& public_key, |
Sorin Jianu | a8ef73d | 2017-11-02 16:55:17 | [diff] [blame] | 75 | Callback callback) override; |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 76 | |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 77 | bool GetInstalledFile(const std::string& file, |
78 | base::FilePath* installed_file) override; | ||||
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 79 | |
80 | private: | ||||
bauerb | 810e60f4 | 2015-02-05 01:09:10 | [diff] [blame] | 81 | ~VersionedTestInstaller() override; |
82 | |||||
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 83 | base::FilePath install_directory_; |
pwnall | db0b7241 | 2016-08-19 21:39:12 | [diff] [blame] | 84 | base::Version current_version_; |
[email protected] | e3e696d3 | 2013-06-21 20:41:36 | [diff] [blame] | 85 | }; |
86 | |||||
sorin | 52ac088 | 2015-01-24 01:15:00 | [diff] [blame] | 87 | } // namespace update_client |
[email protected] | 055981f | 2014-01-17 20:22:32 | [diff] [blame] | 88 | |
sorin | b120440b | 2015-04-27 16:34:15 | [diff] [blame] | 89 | #endif // COMPONENTS_UPDATE_CLIENT_TEST_INSTALLER_H_ |