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 
5 #ifndef COMPONENTS_UPDATE_CLIENT_TEST_INSTALLER_H_
6 #define COMPONENTS_UPDATE_CLIENT_TEST_INSTALLER_H_
7 
8 #include <memory>
9 #include <string>
10 #include <utility>
11 
12 #include "base/files/file_path.h"
13 #include "components/update_client/update_client.h"
14 
15 namespace update_client {
16 
17 // TODO(sorin): consider reducing the number of the installer mocks.
18 // A TestInstaller is an installer that does nothing for installation except
19 // increment a counter.
20 class TestInstaller : public CrxInstaller {
21  public:
22   TestInstaller();
23 
24   void OnUpdateError(int error) override;
25 
26   void Install(const base::FilePath& unpack_path,
27                const std::string& public_key,
28                std::unique_ptr<InstallParams> install_params,
29                Callback callback) override;
30 
31   bool GetInstalledFile(const std::string& file,
32                         base::FilePath* installed_file) override;
33 
34   bool Uninstall() override;
35 
error()36   int error() const { return error_; }
37 
install_count()38   int install_count() const { return install_count_; }
39 
install_params()40   const InstallParams* install_params() const { return install_params_.get(); }
41 
42  protected:
43   ~TestInstaller() override;
44 
45   void InstallComplete(Callback callback, const Result& result) const;
46 
47   int error_;
48   int install_count_;
49 
50  private:
51   // Contains the |unpack_path| argument of the Install call.
52   base::FilePath unpack_path_;
53 
54   // Contains the |install_params| argument of the Install call.
55   std::unique_ptr<InstallParams> install_params_;
56 };
57 
58 // A ReadOnlyTestInstaller is an installer that knows about files in an existing
59 // directory. It will not write to the directory.
60 class ReadOnlyTestInstaller : public TestInstaller {
61  public:
62   explicit ReadOnlyTestInstaller(const base::FilePath& installed_path);
63 
64   bool GetInstalledFile(const std::string& file,
65                         base::FilePath* installed_file) override;
66 
67  private:
68   ~ReadOnlyTestInstaller() override;
69 
70   base::FilePath install_directory_;
71 };
72 
73 // A VersionedTestInstaller is an installer that installs files into versioned
74 // directories (e.g. somedir/25.23.89.141/<files>).
75 class VersionedTestInstaller : public TestInstaller {
76  public:
77   VersionedTestInstaller();
78 
79   void Install(const base::FilePath& unpack_path,
80                const std::string& public_key,
81                std::unique_ptr<InstallParams> install_params,
82                Callback callback) override;
83 
84   bool GetInstalledFile(const std::string& file,
85                         base::FilePath* installed_file) override;
86 
87  private:
88   ~VersionedTestInstaller() override;
89 
90   base::FilePath install_directory_;
91   base::Version current_version_;
92 };
93 
94 }  // namespace update_client
95 
96 #endif  // COMPONENTS_UPDATE_CLIENT_TEST_INSTALLER_H_
97