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
ash / public / cpp / capture_mode / capture_mode_test_api.h [blame]
// 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_PUBLIC_CPP_CAPTURE_MODE_CAPTURE_MODE_TEST_API_H_
#define ASH_PUBLIC_CPP_CAPTURE_MODE_CAPTURE_MODE_TEST_API_H_
#include "ash/ash_export.h"
#include "ash/capture_mode/capture_mode_behavior.h"
#include "ash/capture_mode/capture_mode_types.h"
#include "base/files/file_path.h"
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
namespace aura {
class Window;
} // namespace aura
namespace gfx {
class Rect;
} // namespace gfx
namespace media {
class VideoFrame;
} // namespace media
namespace views {
class Widget;
} // namespace views
namespace ash {
class CaptureModeController;
class AnnotationsOverlayController;
// Exposes a very limited API for browser tests, and possible autotest private
// APIs to interact with the capture mode feature.
class ASH_EXPORT CaptureModeTestApi {
public:
CaptureModeTestApi();
CaptureModeTestApi(const CaptureModeTestApi&) = delete;
CaptureModeTestApi& operator=(const CaptureModeTestApi&) = delete;
~CaptureModeTestApi() = default;
// APIs to start capture mode from the three possible sources (fullscreen,
// window, or region). If `for_video` is true, a video will be recorded from
// the chosen source once capture begins, otherwise an image will be
// captured.
void StartForFullscreen(bool for_video);
void StartForWindow(bool for_video);
void StartForRegion(bool for_video);
// API to set the capture mode source with given `source`.
void SetCaptureModeSource(CaptureModeSource source);
// Sets the `recording_type` to use for video captures.
void SetRecordingType(RecordingType recording_type);
// Returns true if a capture mode session is currently active.
bool IsSessionActive() const;
// Sets the user selected region for partial screen capture.
void SetUserSelectedRegion(const gfx::Rect& region);
// Can only be called after one of the above APIs starts capture mode.
// Depending on how capture mode was started from the above APIs, this will
// perform the capture of either an image or a video from the chosen source.
// Note that for video capture, this skips the 3-second count down UIs, and
// starts video recording immediately.
void PerformCapture(bool skip_count_down = true);
// Returns true if there is a video recording currently in progress.
bool IsVideoRecordingInProgress() const;
// Returns true if capture mode is waiting for a reply from the DLP manager to
// check content restrictions.
bool IsPendingDlpCheck() const;
// Returns true if there's an active session in a waiting state for the DLP
// confirmation.
bool IsSessionWaitingForDlpConfirmation() const;
// Returns true if the 3-second countdown animation is in progress.
bool IsInCountDownAnimation() const;
// Sets a callback that will be triggered once the video recording is started.
void SetOnVideoRecordingStartedCallback(base::OnceClosure callback);
// Sets a callback that will be triggered once the image is captured and
// encoded as JPEG bytes.
using OnImageCapturedForSearchCallback =
base::OnceCallback<void(PerformCaptureType capture_type)>;
void SetOnImageCapturedForSearchCallback(
OnImageCapturedForSearchCallback callback);
// Stops the video recording. Can only be called if a video recording was
// in progress.
void StopVideoRecording();
// Sets a callback that will be triggered once the captured file (of an image
// or a video) is saved, providing its path. It will never be triggered if
// capture failed to save a file.
using OnFileSavedCallback = base::OnceCallback<void(const base::FilePath&)>;
void SetOnCaptureFileSavedCallback(OnFileSavedCallback callback);
// Sets a callback that will be triggered once the captured file (of an image
// or a video) is deleted as a result of user action at the end of the video
// (e.g. clicking the "Delete" button in the notification, or in the DLP
// warning dialog). The callback is provided with the file path, and whether
// the deletion was successful or not.
using OnFileDeletedCallback =
base::OnceCallback<void(const base::FilePath& path,
bool delete_successful)>;
void SetOnCaptureFileDeletedCallback(OnFileDeletedCallback callback);
// Sets a callback that will be triggered once the video record countdown is
// finished.
void SetOnVideoRecordCountdownFinishedCallback(base::OnceClosure callback);
// Sets the audio recording mode when capturing a video. Should only be called
// before recording starts, otherwise it has no effect.
void SetAudioRecordingMode(AudioRecordingMode mode);
// Returns the effective mode of audio recording which takes into account the
// `AudioCaptureAllowed` policy.
AudioRecordingMode GetEffectiveAudioRecordingMode() const;
// Flushes the recording service pipe synchronously. Can only be called while
// recording is in progress.
void FlushRecordingServiceForTesting();
// APIs to reset both the recording service remote, and its client receiver in
// order to test that these events are correctly handled.
void ResetRecordingServiceRemote();
void ResetRecordingServiceClientReceiver();
// Returns the `AnnotationsOverlayController` which hosts the overlay widget.
// Can only be called while recording is in progress for a Projector session.
AnnotationsOverlayController* GetAnnotationsOverlayController();
// Simulates the flow taken by users to open the folder selection dialog from
// the settings menu, and waits until this dialog gets added.
void SimulateOpeningFolderSelectionDialog();
// Returns a pointer to the folder selection dialog window or nullptr if no
// such window exists.
aura::Window* GetFolderSelectionDialogWindow();
// If `value` is true, the `kGpuMemoryBuffer` type will be requested even when
// running on linux-chromeos.
void SetForceUseGpuMemoryBufferForCameraFrames(bool value);
// Returns the number of cameras currently connected.
size_t GetNumberOfAvailableCameras() const;
// Sets the camera at `index` of
// `CaptureModeCameraController::available_cameras()` as the selected camera.
void SelectCameraAtIndex(size_t index);
// Unselects the currently selected camera (if any).
void TurnCameraOff();
using CameraVideoFrameCallback =
base::OnceCallback<void(scoped_refptr<media::VideoFrame>)>;
void SetOnCameraVideoFrameRendered(CameraVideoFrameCallback callback);
// Returns the camera preview widget if exists and nullptr otherwise.
views::Widget* GetCameraPreviewWidget();
CaptureModeBehavior* GetBehavior(BehaviorType behavior_type);
private:
// Sets the capture mode type to a video capture if |for_video| is true, or
// image capture otherwise.
void SetType(bool for_video);
const raw_ptr<CaptureModeController> controller_;
};
} // namespace ash
#endif // ASH_PUBLIC_CPP_CAPTURE_MODE_CAPTURE_MODE_TEST_API_H_