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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
media / base / mock_filters.cc [blame]
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/base/mock_filters.h"
#include "base/check_op.h"
#include "media/base/demuxer.h"
using ::testing::_;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::SaveArg;
MATCHER(NotEmpty, "") {
return !arg.empty();
}
namespace media {
MockPipelineClient::MockPipelineClient() = default;
MockPipelineClient::~MockPipelineClient() = default;
MockPipeline::MockPipeline() = default;
MockPipeline::~MockPipeline() = default;
MockMediaResource::MockMediaResource() = default;
MockMediaResource::~MockMediaResource() = default;
MockDemuxer::MockDemuxer() = default;
MockDemuxer::~MockDemuxer() = default;
std::string MockDemuxer::GetDisplayName() const {
return "MockDemuxer";
}
DemuxerType MockDemuxer::GetDemuxerType() const {
return DemuxerType::kMockDemuxer;
}
MockDemuxerStream::MockDemuxerStream(DemuxerStream::Type type) : type_(type) {}
MockDemuxerStream::~MockDemuxerStream() = default;
DemuxerStream::Type MockDemuxerStream::type() const {
return type_;
}
StreamLiveness MockDemuxerStream::liveness() const {
return liveness_;
}
AudioDecoderConfig MockDemuxerStream::audio_decoder_config() {
DCHECK_EQ(type_, DemuxerStream::AUDIO);
return audio_decoder_config_;
}
VideoDecoderConfig MockDemuxerStream::video_decoder_config() {
DCHECK_EQ(type_, DemuxerStream::VIDEO);
return video_decoder_config_;
}
void MockDemuxerStream::set_audio_decoder_config(
const AudioDecoderConfig& config) {
DCHECK_EQ(type_, DemuxerStream::AUDIO);
audio_decoder_config_ = config;
}
void MockDemuxerStream::set_video_decoder_config(
const VideoDecoderConfig& config) {
DCHECK_EQ(type_, DemuxerStream::VIDEO);
video_decoder_config_ = config;
}
void MockDemuxerStream::set_liveness(StreamLiveness liveness) {
liveness_ = liveness;
}
MockVideoDecoder::MockVideoDecoder() : MockVideoDecoder(0) {}
MockVideoDecoder::MockVideoDecoder(int decoder_id)
: MockVideoDecoder(false, false, decoder_id) {}
MockVideoDecoder::MockVideoDecoder(bool is_platform_decoder,
bool supports_decryption,
int decoder_id)
: is_platform_decoder_(is_platform_decoder),
supports_decryption_(supports_decryption),
decoder_id_(decoder_id) {
ON_CALL(*this, CanReadWithoutStalling()).WillByDefault(Return(true));
}
MockVideoDecoder::~MockVideoDecoder() = default;
bool MockVideoDecoder::IsPlatformDecoder() const {
return is_platform_decoder_;
}
bool MockVideoDecoder::SupportsDecryption() const {
return supports_decryption_;
}
MockAudioEncoder::MockAudioEncoder() = default;
MockAudioEncoder::~MockAudioEncoder() {
OnDestruct();
}
MockVideoEncoder::MockVideoEncoder() = default;
MockVideoEncoder::~MockVideoEncoder() {
Dtor();
}
MockAudioDecoder::MockAudioDecoder() : MockAudioDecoder(0) {}
MockAudioDecoder::MockAudioDecoder(int decoder_id)
: MockAudioDecoder(false, false, decoder_id) {}
MockAudioDecoder::MockAudioDecoder(bool is_platform_decoder,
bool supports_decryption,
int decoder_id)
: is_platform_decoder_(is_platform_decoder),
supports_decryption_(supports_decryption),
decoder_id_(decoder_id) {}
MockAudioDecoder::~MockAudioDecoder() = default;
bool MockAudioDecoder::IsPlatformDecoder() const {
return is_platform_decoder_;
}
bool MockAudioDecoder::SupportsDecryption() const {
return supports_decryption_;
}
MockRendererClient::MockRendererClient() = default;
MockRendererClient::~MockRendererClient() = default;
MockVideoRenderer::MockVideoRenderer() = default;
MockVideoRenderer::~MockVideoRenderer() = default;
MockAudioRenderer::MockAudioRenderer() = default;
MockAudioRenderer::~MockAudioRenderer() = default;
MockRenderer::MockRenderer() = default;
MockRenderer::~MockRenderer() = default;
MockRendererFactory::MockRendererFactory() = default;
MockRendererFactory::~MockRendererFactory() = default;
MockTimeSource::MockTimeSource() = default;
MockTimeSource::~MockTimeSource() = default;
MockCdmClient::MockCdmClient() = default;
MockCdmClient::~MockCdmClient() = default;
MockDecryptor::MockDecryptor() = default;
MockDecryptor::~MockDecryptor() = default;
MockCdmContext::MockCdmContext() = default;
MockCdmContext::~MockCdmContext() = default;
std::optional<base::UnguessableToken> MockCdmContext::GetCdmId() const {
return cdm_id_;
}
void MockCdmContext::set_cdm_id(const base::UnguessableToken& cdm_id) {
cdm_id_ = std::make_optional(cdm_id);
}
MockCdmPromise::MockCdmPromise(bool expect_success) {
if (expect_success) {
EXPECT_CALL(*this, resolve());
EXPECT_CALL(*this, reject(_, _, _)).Times(0);
} else {
EXPECT_CALL(*this, resolve()).Times(0);
EXPECT_CALL(*this, reject(_, _, NotEmpty()));
}
}
MockCdmPromise::~MockCdmPromise() {
// The EXPECT calls will verify that the promise is in fact fulfilled.
MarkPromiseSettled();
}
MockCdmSessionPromise::MockCdmSessionPromise(bool expect_success,
std::string* new_session_id) {
if (expect_success) {
EXPECT_CALL(*this, resolve(_)).WillOnce(SaveArg<0>(new_session_id));
EXPECT_CALL(*this, reject(_, _, _)).Times(0);
} else {
EXPECT_CALL(*this, resolve(_)).Times(0);
EXPECT_CALL(*this, reject(_, _, NotEmpty()));
}
}
MockCdmSessionPromise::~MockCdmSessionPromise() {
// The EXPECT calls will verify that the promise is in fact fulfilled.
MarkPromiseSettled();
}
MockCdmKeyStatusPromise::MockCdmKeyStatusPromise(
bool expect_success,
CdmKeyInformation::KeyStatus* key_status,
CdmPromise::Exception* exception) {
if (expect_success) {
EXPECT_CALL(*this, resolve(_)).WillOnce(SaveArg<0>(key_status));
EXPECT_CALL(*this, reject(_, _, _)).Times(0);
} else {
EXPECT_CALL(*this, resolve(_)).Times(0);
if (exception) {
EXPECT_CALL(*this, reject(_, _, NotEmpty()))
.WillOnce(SaveArg<0>(exception));
} else {
EXPECT_CALL(*this, reject(_, _, NotEmpty()));
}
}
}
MockCdmKeyStatusPromise::~MockCdmKeyStatusPromise() {
// The EXPECT calls will verify that the promise is in fact fulfilled.
MarkPromiseSettled();
}
MockCdm::MockCdm() = default;
MockCdm::MockCdm(
const CdmConfig& cdm_config,
const SessionMessageCB& session_message_cb,
const SessionClosedCB& session_closed_cb,
const SessionKeysChangeCB& session_keys_change_cb,
const SessionExpirationUpdateCB& session_expiration_update_cb) {
Initialize(cdm_config, session_message_cb, session_closed_cb,
session_keys_change_cb, session_expiration_update_cb);
}
MockCdm::~MockCdm() = default;
void MockCdm::Initialize(
const CdmConfig& cdm_config,
const SessionMessageCB& session_message_cb,
const SessionClosedCB& session_closed_cb,
const SessionKeysChangeCB& session_keys_change_cb,
const SessionExpirationUpdateCB& session_expiration_update_cb) {
key_system_ = cdm_config.key_system;
session_message_cb_ = session_message_cb;
session_closed_cb_ = session_closed_cb;
session_keys_change_cb_ = session_keys_change_cb;
session_expiration_update_cb_ = session_expiration_update_cb;
}
void MockCdm::CallSessionMessageCB(const std::string& session_id,
CdmMessageType message_type,
const std::vector<uint8_t>& message) {
session_message_cb_.Run(session_id, message_type, message);
}
void MockCdm::CallSessionClosedCB(const std::string& session_id,
CdmSessionClosedReason reason) {
session_closed_cb_.Run(session_id, reason);
}
void MockCdm::CallSessionKeysChangeCB(const std::string& session_id,
bool has_additional_usable_key,
CdmKeysInfo keys_info) {
session_keys_change_cb_.Run(session_id, has_additional_usable_key,
std::move(keys_info));
}
void MockCdm::CallSessionExpirationUpdateCB(const std::string& session_id,
base::Time new_expiry_time) {
session_expiration_update_cb_.Run(session_id, new_expiry_time);
}
MockCdmFactory::MockCdmFactory(scoped_refptr<MockCdm> mock_cdm)
: mock_cdm_(mock_cdm) {}
MockCdmFactory::~MockCdmFactory() = default;
void MockCdmFactory::Create(
const CdmConfig& cdm_config,
const SessionMessageCB& session_message_cb,
const SessionClosedCB& session_closed_cb,
const SessionKeysChangeCB& session_keys_change_cb,
const SessionExpirationUpdateCB& session_expiration_update_cb,
CdmCreatedCB cdm_created_cb) {
// If no key system specified, notify that Create() failed.
if (cdm_config.key_system.empty()) {
std::move(cdm_created_cb)
.Run(nullptr, CreateCdmStatus::kUnsupportedKeySystem);
return;
}
// Since there is a CDM, call |before_creation_cb_| first.
if (before_creation_cb_)
before_creation_cb_.Run();
mock_cdm_->Initialize(cdm_config, session_message_cb, session_closed_cb,
session_keys_change_cb, session_expiration_update_cb);
std::move(cdm_created_cb).Run(mock_cdm_, CreateCdmStatus::kSuccess);
}
void MockCdmFactory::SetBeforeCreationCB(
base::RepeatingClosure before_creation_cb) {
before_creation_cb_ = std::move(before_creation_cb);
}
MockStreamParser::MockStreamParser() = default;
MockStreamParser::~MockStreamParser() = default;
MockMediaClient::MockMediaClient() = default;
MockMediaClient::~MockMediaClient() = default;
MockVideoEncoderMetricsProvider::MockVideoEncoderMetricsProvider() {
DETACH_FROM_SEQUENCE(sequence_checker_);
}
MockVideoEncoderMetricsProvider::~MockVideoEncoderMetricsProvider() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
MockDestroy();
}
} // namespace media