test_installer.h 3.4 KB

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