fake_drivefs.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // Copyright 2018 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_COMPONENTS_DRIVEFS_FAKE_DRIVEFS_H_
  5. #define ASH_COMPONENTS_DRIVEFS_FAKE_DRIVEFS_H_
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include <vector>
  10. #include "ash/components/drivefs/drivefs_bootstrap.h"
  11. #include "ash/components/drivefs/drivefs_host.h"
  12. #include "ash/components/drivefs/mojom/drivefs.mojom.h"
  13. #include "base/files/file_path.h"
  14. #include "base/memory/weak_ptr.h"
  15. #include "mojo/public/cpp/bindings/pending_receiver.h"
  16. #include "mojo/public/cpp/bindings/pending_remote.h"
  17. #include "mojo/public/cpp/bindings/receiver.h"
  18. #include "mojo/public/cpp/bindings/remote.h"
  19. #include "testing/gmock/include/gmock/gmock.h"
  20. namespace drivefs {
  21. class FakeDriveFsBootstrapListener : public DriveFsBootstrapListener {
  22. public:
  23. explicit FakeDriveFsBootstrapListener(
  24. mojo::PendingRemote<drivefs::mojom::DriveFsBootstrap> bootstrap);
  25. FakeDriveFsBootstrapListener(const FakeDriveFsBootstrapListener&) = delete;
  26. FakeDriveFsBootstrapListener& operator=(const FakeDriveFsBootstrapListener&) =
  27. delete;
  28. ~FakeDriveFsBootstrapListener() override;
  29. private:
  30. void SendInvitationOverPipe(base::ScopedFD) override;
  31. mojo::PendingRemote<mojom::DriveFsBootstrap> bootstrap() override;
  32. mojo::PendingRemote<drivefs::mojom::DriveFsBootstrap> bootstrap_;
  33. };
  34. class FakeDriveFs : public drivefs::mojom::DriveFs,
  35. public drivefs::mojom::DriveFsBootstrap {
  36. public:
  37. explicit FakeDriveFs(const base::FilePath& mount_path);
  38. FakeDriveFs(const FakeDriveFs&) = delete;
  39. FakeDriveFs& operator=(const FakeDriveFs&) = delete;
  40. ~FakeDriveFs() override;
  41. void RegisterMountingForAccountId(
  42. base::RepeatingCallback<std::string()> account_id_getter);
  43. std::unique_ptr<drivefs::DriveFsBootstrapListener> CreateMojoListener();
  44. void SetMetadata(const base::FilePath& path,
  45. const std::string& mime_type,
  46. const std::string& original_name,
  47. bool pinned,
  48. bool shared,
  49. const mojom::Capabilities& capabilities,
  50. const mojom::FolderFeature& folder_feature,
  51. const std::string& doc_id,
  52. const std::string& alternate_url);
  53. void DisplayConfirmDialog(
  54. drivefs::mojom::DialogReasonPtr reason,
  55. drivefs::mojom::DriveFsDelegate::DisplayConfirmDialogCallback callback);
  56. mojo::Remote<drivefs::mojom::DriveFsDelegate>& delegate() {
  57. return delegate_;
  58. }
  59. MOCK_METHOD(void,
  60. GetSyncingPaths,
  61. (drivefs::mojom::DriveFs::GetSyncingPathsCallback callback),
  62. (override));
  63. const base::FilePath& mount_path() { return mount_path_; }
  64. private:
  65. struct FileMetadata;
  66. class SearchQuery;
  67. // drivefs::mojom::DriveFsBootstrap:
  68. void Init(
  69. drivefs::mojom::DriveFsConfigurationPtr config,
  70. mojo::PendingReceiver<drivefs::mojom::DriveFs> receiver,
  71. mojo::PendingRemote<drivefs::mojom::DriveFsDelegate> delegate) override;
  72. // drivefs::mojom::DriveFs:
  73. void GetMetadata(const base::FilePath& path,
  74. GetMetadataCallback callback) override;
  75. void SetPinned(const base::FilePath& path,
  76. bool pinned,
  77. SetPinnedCallback callback) override;
  78. void UpdateNetworkState(bool pause_syncing, bool is_offline) override;
  79. void ResetCache(ResetCacheCallback callback) override;
  80. void GetThumbnail(const base::FilePath& path,
  81. bool crop_to_square,
  82. GetThumbnailCallback callback) override;
  83. void CopyFile(const base::FilePath& source,
  84. const base::FilePath& target,
  85. CopyFileCallback callback) override;
  86. void StartSearchQuery(
  87. mojo::PendingReceiver<drivefs::mojom::SearchQuery> receiver,
  88. drivefs::mojom::QueryParametersPtr query_params) override;
  89. void FetchAllChangeLogs() override;
  90. void FetchChangeLog(
  91. std::vector<mojom::FetchChangeLogOptionsPtr> options) override;
  92. void SendNativeMessageRequest(
  93. const std::string& request,
  94. SendNativeMessageRequestCallback callback) override;
  95. void SetStartupArguments(const std::string& arguments,
  96. SetStartupArgumentsCallback callback) override;
  97. void GetStartupArguments(GetStartupArgumentsCallback callback) override;
  98. void SetTracingEnabled(bool enabled) override;
  99. void SetNetworkingEnabled(bool enabled) override;
  100. void ForcePauseSyncing(bool enable) override;
  101. void DumpAccountSettings() override;
  102. void LoadAccountSettings() override;
  103. void CreateNativeHostSession(
  104. drivefs::mojom::ExtensionConnectionParamsPtr params,
  105. mojo::PendingReceiver<drivefs::mojom::NativeMessagingHost> session,
  106. mojo::PendingRemote<drivefs::mojom::NativeMessagingPort> port) override;
  107. void LocateFilesByItemIds(
  108. const std::vector<std::string>& item_ids,
  109. drivefs::mojom::DriveFs::LocateFilesByItemIdsCallback callback) override;
  110. void GetQuotaUsage(
  111. drivefs::mojom::DriveFs::GetQuotaUsageCallback callback) override;
  112. void GetPooledQuotaUsage(
  113. drivefs::mojom::DriveFs::GetPooledQuotaUsageCallback callback) override;
  114. void ToggleMirroring(
  115. bool enabled,
  116. drivefs::mojom::DriveFs::ToggleMirroringCallback callback) override;
  117. void ToggleSyncForPath(
  118. const base::FilePath& path,
  119. drivefs::mojom::MirrorPathStatus status,
  120. drivefs::mojom::DriveFs::ToggleSyncForPathCallback callback) override;
  121. void PollHostedFilePinStates() override;
  122. const base::FilePath mount_path_;
  123. int64_t next_stable_id_ = 1;
  124. std::map<base::FilePath, FileMetadata> metadata_;
  125. mojo::Receiver<drivefs::mojom::DriveFs> receiver_{this};
  126. mojo::Remote<drivefs::mojom::DriveFsDelegate> delegate_;
  127. mojo::Receiver<drivefs::mojom::DriveFsBootstrap> bootstrap_receiver_{this};
  128. mojo::PendingReceiver<drivefs::mojom::DriveFsDelegate>
  129. pending_delegate_receiver_;
  130. std::vector<base::FilePath> syncing_paths_;
  131. base::WeakPtrFactory<FakeDriveFs> weak_factory_{this};
  132. };
  133. } // namespace drivefs
  134. #endif // ASH_COMPONENTS_DRIVEFS_FAKE_DRIVEFS_H_