mock_external_provider.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifndef EXTENSIONS_BROWSER_MOCK_EXTERNAL_PROVIDER_H_
  5. #define EXTENSIONS_BROWSER_MOCK_EXTERNAL_PROVIDER_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include <utility>
  10. #include "base/files/file_path.h"
  11. #include "base/memory/raw_ptr.h"
  12. #include "extensions/browser/external_provider_interface.h"
  13. #include "extensions/common/extension_id.h"
  14. #include "extensions/common/manifest.h"
  15. namespace base {
  16. class Version;
  17. }
  18. namespace extensions {
  19. class MockExternalProvider : public ExternalProviderInterface {
  20. public:
  21. MockExternalProvider(VisitorInterface* visitor,
  22. mojom::ManifestLocation location);
  23. MockExternalProvider(const MockExternalProvider&) = delete;
  24. MockExternalProvider& operator=(const MockExternalProvider&) = delete;
  25. ~MockExternalProvider() override;
  26. void UpdateOrAddExtension(const ExtensionId& id,
  27. const std::string& version,
  28. const base::FilePath& path);
  29. void UpdateOrAddExtension(std::unique_ptr<ExternalInstallInfoFile> info);
  30. void UpdateOrAddExtension(std::unique_ptr<ExternalInstallInfoUpdateUrl> info);
  31. void RemoveExtension(const ExtensionId& id);
  32. // ExternalProviderInterface implementation:
  33. void VisitRegisteredExtension() override;
  34. bool HasExtension(const std::string& id) const override;
  35. bool GetExtensionDetails(
  36. const std::string& id,
  37. mojom::ManifestLocation* location,
  38. std::unique_ptr<base::Version>* version) const override;
  39. void TriggerOnExternalExtensionFound() override;
  40. bool IsReady() const override;
  41. void ServiceShutdown() override {}
  42. int visit_count() const { return visit_count_; }
  43. void set_visit_count(int visit_count) { visit_count_ = visit_count; }
  44. private:
  45. using FileDataMap =
  46. std::map<ExtensionId, std::unique_ptr<ExternalInstallInfoFile>>;
  47. using UrlDataMap =
  48. std::map<ExtensionId, std::unique_ptr<ExternalInstallInfoUpdateUrl>>;
  49. FileDataMap file_extension_map_;
  50. UrlDataMap url_extension_map_;
  51. mojom::ManifestLocation location_;
  52. raw_ptr<VisitorInterface> visitor_;
  53. // visit_count_ tracks the number of calls to VisitRegisteredExtension().
  54. // Mutable because it must be incremented on each call to
  55. // VisitRegisteredExtension(), which must be a const method to inherit
  56. // from the class being mocked.
  57. mutable int visit_count_;
  58. };
  59. } // namespace extensions
  60. #endif // EXTENSIONS_BROWSER_MOCK_EXTERNAL_PROVIDER_H_