File: test_capture_mode_delegate.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (200 lines) | stat: -rw-r--r-- 8,386 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_CAPTURE_MODE_TEST_CAPTURE_MODE_DELEGATE_H_
#define ASH_CAPTURE_MODE_TEST_CAPTURE_MODE_DELEGATE_H_

#include <limits>
#include <memory>

#include "ash/capture_mode/capture_mode_types.h"
#include "ash/public/cpp/capture_mode/capture_mode_delegate.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/callback.h"
#include "base/functional/callback_forward.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image_skia.h"

namespace recording {
class RecordingServiceTestApi;
}  // namespace recording

namespace ash {

class FakeVideoSourceProvider;

class TestCaptureModeDelegate : public CaptureModeDelegate {
 public:
  TestCaptureModeDelegate();
  TestCaptureModeDelegate(const TestCaptureModeDelegate&) = delete;
  TestCaptureModeDelegate& operator=(const TestCaptureModeDelegate&) = delete;
  ~TestCaptureModeDelegate() override;

  bool is_session_active() const { return is_session_active_; }

  recording::RecordingServiceTestApi* recording_service() const {
    return recording_service_.get();
  }
  FakeVideoSourceProvider* video_source_provider() {
    return video_source_provider_.get();
  }
  void set_on_session_state_changed_callback(base::OnceClosure callback) {
    on_session_state_changed_callback_ = std::move(callback);
  }
  void set_is_allowed_by_dlp(bool value) { is_allowed_by_dlp_ = value; }
  void set_is_allowed_by_policy(bool value) { is_allowed_by_policy_ = value; }
  void set_is_search_allowed_by_policy(bool value) {
    is_search_allowed_by_policy_ = value;
  }
  void set_should_save_after_dlp_check(bool value) {
    should_save_after_dlp_check_ = value;
  }
  void set_is_camera_disabled_by_policy(bool value) {
    is_camera_disabled_by_policy_ = value;
  }
  void set_is_audio_capture_disabled_by_policy(bool value) {
    is_audio_capture_disabled_by_policy_ = value;
  }
  void set_force_lens_web_error(bool value) { force_lens_web_error_ = value; }
  void set_fake_drive_fs_free_bytes(int64_t bytes) {
    fake_drive_fs_free_bytes_ = bytes;
  }
  void set_policy_capture_path(PolicyCapturePath policy_capture_path) {
    policy_capture_path_ = policy_capture_path;
  }
  int num_capture_image_attempts() const { return num_capture_image_attempts_; }
  void set_lens_detected_text(std::string text) {
    lens_detected_text_ = std::move(text);
  }

  // Resets |is_allowed_by_policy_| and |is_allowed_by_dlp_| back to true.
  void ResetAllowancesToDefault();

  // Gets the current frame sink id being captured by the service.
  viz::FrameSinkId GetCurrentFrameSinkId() const;

  // Gets the current size of the frame sink being recorded in pixels.
  gfx::Size GetCurrentFrameSinkSizeInPixels() const;

  // Gets the current video size being captured by the service.
  gfx::Size GetCurrentVideoSize() const;

  // Gets the thumbnail image that will be used by the service to provide it to
  // the client.
  gfx::ImageSkia GetVideoThumbnail() const;

  // Requests a video frame from the video capturer and waits for it to be
  // delivered to the service.
  void RequestAndWaitForVideoFrame();

  // Returns true if there is an ongoing recording and the recording service is
  // currently recording audio.
  bool IsDoingAudioRecording() const;

  // Returns the number of audio capturers owned by the recording service.
  int GetNumberOfAudioCapturers() const;

  // CaptureModeDelegate:
  base::FilePath GetUserDefaultDownloadsFolder() const override;
  void OpenScreenCaptureItem(const base::FilePath& file_path) override;
  void OpenScreenshotInImageEditor(const base::FilePath& file_path) override;
  bool Uses24HourFormat() const override;
  void CheckCaptureModeInitRestrictionByDlp(
      bool shutting_down,
      OnCaptureModeDlpRestrictionChecked callback) override;
  void CheckCaptureOperationRestrictionByDlp(
      const aura::Window* window,
      const gfx::Rect& bounds,
      OnCaptureModeDlpRestrictionChecked callback) override;
  bool IsCaptureAllowedByPolicy() const override;
  bool IsSearchAllowedByPolicy() const override;
  void StartObservingRestrictedContent(
      const aura::Window* window,
      const gfx::Rect& bounds,
      base::OnceClosure stop_callback) override;
  void StopObservingRestrictedContent(
      OnCaptureModeDlpRestrictionChecked callback) override;
  void OnCaptureImageAttempted(aura::Window const*, gfx::Rect const&) override;
  mojo::Remote<recording::mojom::RecordingService> LaunchRecordingService()
      override;
  void BindAudioStreamFactory(
      mojo::PendingReceiver<media::mojom::AudioStreamFactory> receiver)
      override;
  void OnSessionStateChanged(bool started) override;
  void OnServiceRemoteReset() override;
  bool GetDriveFsMountPointPath(base::FilePath* result) const override;
  base::FilePath GetAndroidFilesPath() const override;
  base::FilePath GetLinuxFilesPath() const override;
  base::FilePath GetOneDriveMountPointPath() const override;
  base::FilePath GetOneDriveVirtualPath() const override;
  PolicyCapturePath GetPolicyCapturePath() const override;
  void ConnectToVideoSourceProvider(
      mojo::PendingReceiver<video_capture::mojom::VideoSourceProvider> receiver)
      override;
  void GetDriveFsFreeSpaceBytes(OnGotDriveFsFreeSpace callback) override;
  bool IsCameraDisabledByPolicy() const override;
  bool IsAudioCaptureDisabledByPolicy() const override;
  void RegisterVideoConferenceManagerClient(
      crosapi::mojom::VideoConferenceManagerClient* client,
      const base::UnguessableToken& client_id) override;
  void UnregisterVideoConferenceManagerClient(
      const base::UnguessableToken& client_id) override;
  void UpdateVideoConferenceManager(
      crosapi::mojom::VideoConferenceMediaUsageStatusPtr status) override;
  void NotifyDeviceUsedWhileDisabled(
      crosapi::mojom::VideoConferenceMediaDevice device) override;
  void FinalizeSavedFile(
      base::OnceCallback<void(bool, const base::FilePath&)> callback,
      const base::FilePath& path,
      const gfx::Image& thumbnail,
      bool for_video) override;
  base::FilePath RedirectFilePath(const base::FilePath& path) override;
  std::unique_ptr<AshWebView> CreateSearchResultsView() const override;
  MOCK_METHOD(void,
              DetectTextInImage,
              (const SkBitmap& image, OnTextDetectionComplete callback),
              (override));
  void SendLensWebRegionSearch(
      const gfx::Image& original_image,
      const bool is_standalone_session,
      ash::OnSearchUrlFetchedCallback search_callback,
      ash::OnTextDetectionComplete text_callback,
      base::OnceCallback<void()> error_callback) override;
  MOCK_METHOD(bool, IsNetworkConnectionOffline, (), (const, override));
  void DeleteRemoteFile(const base::FilePath& path,
                        base::OnceCallback<void(bool)> callback) override;
  bool ActiveUserDefaultSearchProviderIsGoogle() const override;

 private:
  std::unique_ptr<recording::RecordingServiceTestApi> recording_service_;
  std::unique_ptr<FakeVideoSourceProvider> video_source_provider_;
  base::ScopedTempDir fake_downloads_dir_;
  base::OnceClosure on_session_state_changed_callback_;
  bool is_session_active_ = false;
  bool is_allowed_by_dlp_ = true;
  bool is_allowed_by_policy_ = true;
  bool is_search_allowed_by_policy_ = true;
  bool should_save_after_dlp_check_ = true;
  bool is_camera_disabled_by_policy_ = false;
  bool is_audio_capture_disabled_by_policy_ = false;
  bool force_lens_web_error_ = false;
  // Counter to track number of times `OnCaptureImageAttempted()` is called, for
  // testing purposes.
  int num_capture_image_attempts_ = 0;
  base::ScopedTempDir fake_drive_fs_mount_path_;
  base::ScopedTempDir fake_android_files_path_;
  base::ScopedTempDir fake_linux_files_path_;
  base::ScopedTempDir fake_one_drive_mount_path_;
  int64_t fake_drive_fs_free_bytes_ = std::numeric_limits<int64_t>::max();
  PolicyCapturePath policy_capture_path_ = {base::FilePath(),
                                            CapturePathEnforcement::kNone};
  std::string lens_detected_text_;
};

}  // namespace ash

#endif  // ASH_CAPTURE_MODE_TEST_CAPTURE_MODE_DELEGATE_H_