test_wallpaper_controller_client.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. // Copyright 2021 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 ASH_WALLPAPER_TEST_WALLPAPER_CONTROLLER_CLIENT_H_
  5. #define ASH_WALLPAPER_TEST_WALLPAPER_CONTROLLER_CLIENT_H_
  6. #include <stddef.h>
  7. #include <unordered_map>
  8. #include "ash/public/cpp/wallpaper/wallpaper_controller_client.h"
  9. #include "base/callback_forward.h"
  10. #include "base/containers/flat_map.h"
  11. #include "components/account_id/account_id.h"
  12. namespace ash {
  13. // A test wallpaper controller client class.
  14. class TestWallpaperControllerClient : public WallpaperControllerClient {
  15. public:
  16. // A preconfigured collection of wallpaper variants that will return some
  17. // usable values.
  18. static const std::string kDummyCollectionId;
  19. TestWallpaperControllerClient();
  20. TestWallpaperControllerClient(const TestWallpaperControllerClient&) = delete;
  21. TestWallpaperControllerClient& operator=(
  22. const TestWallpaperControllerClient&) = delete;
  23. virtual ~TestWallpaperControllerClient();
  24. // Add a set of |images| for |collection_id| that will be returned for
  25. // FetchDailyRefreshWallpaper and FetchImagesForCollection.
  26. void AddCollection(const std::string& collection_id,
  27. const std::vector<backdrop::Image>& images);
  28. size_t open_count() const { return open_count_; }
  29. size_t set_default_wallpaper_count() const {
  30. return set_default_wallpaper_count_;
  31. }
  32. size_t migrate_collection_id_from_chrome_app_count() const {
  33. return migrate_collection_id_from_chrome_app_count_;
  34. }
  35. size_t fetch_images_for_collection_count() const {
  36. return fetch_images_for_collection_count_;
  37. }
  38. std::string get_fetch_daily_refresh_wallpaper_param() const {
  39. return fetch_daily_refresh_wallpaper_param_;
  40. }
  41. AccountId get_save_wallpaper_to_drive_fs_account_id() const {
  42. return save_wallpaper_to_drive_fs_account_id_;
  43. }
  44. AccountId get_wallpaper_path_from_drive_fs_account_id() const {
  45. return get_wallpaper_path_from_drive_fs_account_id_;
  46. }
  47. void set_fetch_daily_refresh_info_fails(bool fails) {
  48. fetch_daily_refresh_info_fails_ = fails;
  49. }
  50. void set_fetch_google_photos_photo_fails(bool fails) {
  51. fetch_google_photos_photo_fails_ = fails;
  52. }
  53. void set_google_photo_has_been_deleted(bool deleted) {
  54. google_photo_has_been_deleted_ = deleted;
  55. }
  56. void set_fake_files_id_for_account_id(const AccountId& account_id,
  57. std::string fake_files_id) {
  58. fake_files_ids_[account_id] = fake_files_id;
  59. }
  60. void set_wallpaper_sync_enabled(bool sync_enabled) {
  61. wallpaper_sync_enabled_ = sync_enabled;
  62. }
  63. void ResetCounts();
  64. // WallpaperControllerClient:
  65. void OpenWallpaperPicker() override;
  66. void SetDefaultWallpaper(
  67. const AccountId& account_id,
  68. bool show_wallpaper,
  69. base::OnceCallback<void(bool success)> callback) override;
  70. void MigrateCollectionIdFromChromeApp(
  71. const AccountId& account_id,
  72. base::OnceCallback<void(const std::string&)> result_callback) override;
  73. void FetchDailyRefreshWallpaper(
  74. const std::string& collection_id,
  75. DailyWallpaperUrlFetchedCallback callback) override;
  76. void FetchImagesForCollection(
  77. const std::string& collection_id,
  78. FetchImagesForCollectionCallback callback) override;
  79. void FetchGooglePhotosPhoto(const AccountId& account_id,
  80. const std::string& id,
  81. FetchGooglePhotosPhotoCallback callback) override;
  82. void FetchDailyGooglePhotosPhoto(
  83. const AccountId& account_id,
  84. const std::string& album_id,
  85. FetchGooglePhotosPhotoCallback callback) override;
  86. void FetchGooglePhotosAccessToken(
  87. const AccountId& account_id,
  88. FetchGooglePhotosAccessTokenCallback callback) override;
  89. void SaveWallpaperToDriveFs(
  90. const AccountId& account_id,
  91. const base::FilePath& origin,
  92. base::OnceCallback<void(bool)> wallpaper_saved_callback) override;
  93. base::FilePath GetWallpaperPathFromDriveFs(
  94. const AccountId& account_id) override;
  95. void GetFilesId(const AccountId& account_id,
  96. base::OnceCallback<void(const std::string&)>
  97. files_id_callback) const override;
  98. bool IsWallpaperSyncEnabled(const AccountId& account_id) const override;
  99. private:
  100. size_t open_count_ = 0;
  101. size_t set_default_wallpaper_count_ = 0;
  102. size_t migrate_collection_id_from_chrome_app_count_ = 0;
  103. size_t fetch_images_for_collection_count_ = 0;
  104. std::string fetch_daily_refresh_wallpaper_param_;
  105. bool fetch_daily_refresh_info_fails_ = false;
  106. AccountId get_wallpaper_path_from_drive_fs_account_id_;
  107. AccountId save_wallpaper_to_drive_fs_account_id_;
  108. std::unordered_map<AccountId, std::string> fake_files_ids_;
  109. bool wallpaper_sync_enabled_ = true;
  110. bool fetch_images_for_collection_fails_ = false;
  111. bool fetch_google_photos_photo_fails_ = false;
  112. bool google_photo_has_been_deleted_ = false;
  113. int image_index_ = 0;
  114. base::flat_map<std::string, std::vector<backdrop::Image>> variations_;
  115. };
  116. } // namespace ash
  117. #endif // ASH_WALLPAPER_TEST_WALLPAPER_CONTROLLER_CLIENT_H_