test_capture_mode_delegate.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright 2020 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_CAPTURE_MODE_TEST_CAPTURE_MODE_DELEGATE_H_
  5. #define ASH_CAPTURE_MODE_TEST_CAPTURE_MODE_DELEGATE_H_
  6. #include <limits>
  7. #include <memory>
  8. #include "ash/public/cpp/capture_mode/capture_mode_delegate.h"
  9. #include "base/callback.h"
  10. #include "base/callback_forward.h"
  11. #include "base/files/file_path.h"
  12. #include "base/files/scoped_temp_dir.h"
  13. #include "components/viz/common/surfaces/frame_sink_id.h"
  14. #include "ui/gfx/geometry/size.h"
  15. #include "ui/gfx/image/image_skia.h"
  16. namespace recording {
  17. class RecordingServiceTestApi;
  18. } // namespace recording
  19. namespace ash {
  20. class FakeVideoSourceProvider;
  21. class TestCaptureModeDelegate : public CaptureModeDelegate {
  22. public:
  23. TestCaptureModeDelegate();
  24. TestCaptureModeDelegate(const TestCaptureModeDelegate&) = delete;
  25. TestCaptureModeDelegate& operator=(const TestCaptureModeDelegate&) = delete;
  26. ~TestCaptureModeDelegate() override;
  27. recording::RecordingServiceTestApi* recording_service() const {
  28. return recording_service_.get();
  29. }
  30. FakeVideoSourceProvider* video_source_provider() {
  31. return video_source_provider_.get();
  32. }
  33. void set_on_session_state_changed_callback(base::OnceClosure callback) {
  34. on_session_state_changed_callback_ = std::move(callback);
  35. }
  36. void set_on_recording_started_callback(base::OnceClosure callback) {
  37. on_recording_started_callback_ = std::move(callback);
  38. }
  39. void set_is_allowed_by_dlp(bool value) { is_allowed_by_dlp_ = value; }
  40. void set_is_allowed_by_policy(bool value) { is_allowed_by_policy_ = value; }
  41. void set_should_save_after_dlp_check(bool value) {
  42. should_save_after_dlp_check_ = value;
  43. }
  44. void set_is_camera_disabled_by_policy(bool value) {
  45. is_camera_disabled_by_policy_ = value;
  46. }
  47. void set_fake_drive_fs_free_bytes(int64_t bytes) {
  48. fake_drive_fs_free_bytes_ = bytes;
  49. }
  50. // Resets |is_allowed_by_policy_| and |is_allowed_by_dlp_| back to true.
  51. void ResetAllowancesToDefault();
  52. // Gets the current frame sink id being captured by the service.
  53. viz::FrameSinkId GetCurrentFrameSinkId() const;
  54. // Gets the current size of the frame sink being recorded in pixels.
  55. gfx::Size GetCurrentFrameSinkSizeInPixels() const;
  56. // Gets the current video size being captured by the service.
  57. gfx::Size GetCurrentVideoSize() const;
  58. // Gets the thumbnail image that will be used by the service to provide it to
  59. // the client.
  60. gfx::ImageSkia GetVideoThumbnail() const;
  61. // Requests a video frame from the video capturer and waits for it to be
  62. // delivered to the service.
  63. void RequestAndWaitForVideoFrame();
  64. // CaptureModeDelegate:
  65. base::FilePath GetUserDefaultDownloadsFolder() const override;
  66. void ShowScreenCaptureItemInFolder(const base::FilePath& file_path) override;
  67. void OpenScreenshotInImageEditor(const base::FilePath& file_path) override;
  68. bool Uses24HourFormat() const override;
  69. void CheckCaptureModeInitRestrictionByDlp(
  70. OnCaptureModeDlpRestrictionChecked callback) override;
  71. void CheckCaptureOperationRestrictionByDlp(
  72. const aura::Window* window,
  73. const gfx::Rect& bounds,
  74. OnCaptureModeDlpRestrictionChecked callback) override;
  75. bool IsCaptureAllowedByPolicy() const override;
  76. void StartObservingRestrictedContent(
  77. const aura::Window* window,
  78. const gfx::Rect& bounds,
  79. base::OnceClosure stop_callback) override;
  80. void StopObservingRestrictedContent(
  81. OnCaptureModeDlpRestrictionChecked callback) override;
  82. void OnCaptureImageAttempted(aura::Window const*, gfx::Rect const&) override;
  83. mojo::Remote<recording::mojom::RecordingService> LaunchRecordingService()
  84. override;
  85. void BindAudioStreamFactory(
  86. mojo::PendingReceiver<media::mojom::AudioStreamFactory> receiver)
  87. override;
  88. void OnSessionStateChanged(bool started) override;
  89. void OnServiceRemoteReset() override;
  90. bool GetDriveFsMountPointPath(base::FilePath* result) const override;
  91. base::FilePath GetAndroidFilesPath() const override;
  92. base::FilePath GetLinuxFilesPath() const override;
  93. std::unique_ptr<RecordingOverlayView> CreateRecordingOverlayView()
  94. const override;
  95. void ConnectToVideoSourceProvider(
  96. mojo::PendingReceiver<video_capture::mojom::VideoSourceProvider> receiver)
  97. override;
  98. void GetDriveFsFreeSpaceBytes(OnGotDriveFsFreeSpace callback) override;
  99. bool IsCameraDisabledByPolicy() const override;
  100. private:
  101. std::unique_ptr<recording::RecordingServiceTestApi> recording_service_;
  102. std::unique_ptr<FakeVideoSourceProvider> video_source_provider_;
  103. base::ScopedTempDir fake_downloads_dir_;
  104. base::OnceClosure on_session_state_changed_callback_;
  105. base::OnceClosure on_recording_started_callback_;
  106. bool is_allowed_by_dlp_ = true;
  107. bool is_allowed_by_policy_ = true;
  108. bool should_save_after_dlp_check_ = true;
  109. bool is_camera_disabled_by_policy_ = false;
  110. base::ScopedTempDir fake_drive_fs_mount_path_;
  111. base::ScopedTempDir fake_android_files_path_;
  112. base::ScopedTempDir fake_linux_files_path_;
  113. int64_t fake_drive_fs_free_bytes_ = std::numeric_limits<int64_t>::max();
  114. };
  115. } // namespace ash
  116. #endif // ASH_CAPTURE_MODE_TEST_CAPTURE_MODE_DELEGATE_H_