Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: media/filters/decrypting_demuxer_stream_unittest.cc

Issue 416333011: Allow setContentDecryptionModule() to get called when setting is done. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: const & Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // times across multiple test files. Sadly we can't use static for them. 46 // times across multiple test files. Sadly we can't use static for them.
47 namespace { 47 namespace {
48 48
49 ACTION_P(ReturnBuffer, buffer) { 49 ACTION_P(ReturnBuffer, buffer) {
50 arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); 50 arg0.Run(buffer.get() ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer);
51 } 51 }
52 52
53 // Sets the |decryptor| if the DecryptorReadyCB (arg0) is not null. Sets 53 // Sets the |decryptor| if the DecryptorReadyCB (arg0) is not null. Sets
54 // |is_decryptor_set| to true if a non-NULL |decryptor| has been set through the 54 // |is_decryptor_set| to true if a non-NULL |decryptor| has been set through the
55 // callback. 55 // callback.
56 ACTION_P2(SetDecryptorIfNotNull, decryptor, is_decryptor_set) { 56 ACTION_P3(SetDecryptorIfNotNull, decryptor, done_cb, is_decryptor_set) {
57 if (!arg0.is_null()) 57 if (!arg0.is_null())
58 arg0.Run(decryptor); 58 arg0.Run(decryptor, done_cb);
59 59
60 *is_decryptor_set = !arg0.is_null() && decryptor; 60 *is_decryptor_set = !arg0.is_null() && decryptor;
61 } 61 }
62 62
63 ACTION_P2(ResetAndRunCallback, callback, param) { 63 ACTION_P2(ResetAndRunCallback, callback, param) {
64 base::ResetAndReturn(callback).Run(param); 64 base::ResetAndReturn(callback).Run(param);
65 } 65 }
66 66
67 MATCHER(IsEndOfStream, "end of stream") { 67 MATCHER(IsEndOfStream, "end of stream") {
68 return arg->end_of_stream(); 68 return arg->end_of_stream();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 message_loop_.RunUntilIdle(); 112 message_loop_.RunUntilIdle();
113 } 113 }
114 114
115 // The following functions are used to test stream-type-neutral logic in 115 // The following functions are used to test stream-type-neutral logic in
116 // DecryptingDemuxerStream. Therefore, we don't specify audio or video in the 116 // DecryptingDemuxerStream. Therefore, we don't specify audio or video in the
117 // function names. But for testing purpose, they all use an audio input 117 // function names. But for testing purpose, they all use an audio input
118 // demuxer stream. 118 // demuxer stream.
119 119
120 void Initialize() { 120 void Initialize() {
121 EXPECT_CALL(*this, RequestDecryptorNotification(_)) 121 EXPECT_CALL(*this, RequestDecryptorNotification(_))
122 .WillOnce(SetDecryptorIfNotNull(decryptor_.get(), &is_decryptor_set_)); 122 .WillOnce(SetDecryptorIfNotNull(decryptor_.get(),
123 base::Bind(&base::DoNothing),
ddorwin 2014/07/30 22:35:46 ditto
124 &is_decryptor_set_));
123 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _)) 125 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kAudio, _))
124 .WillOnce(SaveArg<1>(&key_added_cb_)); 126 .WillOnce(SaveArg<1>(&key_added_cb_));
125 127
126 AudioDecoderConfig input_config( 128 AudioDecoderConfig input_config(
127 kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100, 129 kCodecVorbis, kSampleFormatPlanarF32, CHANNEL_LAYOUT_STEREO, 44100,
128 NULL, 0, true); 130 NULL, 0, true);
129 InitializeAudioAndExpectStatus(input_config, PIPELINE_OK); 131 InitializeAudioAndExpectStatus(input_config, PIPELINE_OK);
130 132
131 const AudioDecoderConfig& output_config = 133 const AudioDecoderConfig& output_config =
132 demuxer_stream_->audio_decoder_config(); 134 demuxer_stream_->audio_decoder_config();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 private: 272 private:
271 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStreamTest); 273 DISALLOW_COPY_AND_ASSIGN(DecryptingDemuxerStreamTest);
272 }; 274 };
273 275
274 TEST_F(DecryptingDemuxerStreamTest, Initialize_NormalAudio) { 276 TEST_F(DecryptingDemuxerStreamTest, Initialize_NormalAudio) {
275 Initialize(); 277 Initialize();
276 } 278 }
277 279
278 TEST_F(DecryptingDemuxerStreamTest, Initialize_NormalVideo) { 280 TEST_F(DecryptingDemuxerStreamTest, Initialize_NormalVideo) {
279 EXPECT_CALL(*this, RequestDecryptorNotification(_)) 281 EXPECT_CALL(*this, RequestDecryptorNotification(_))
280 .WillOnce(SetDecryptorIfNotNull(decryptor_.get(), &is_decryptor_set_)); 282 .WillOnce(SetDecryptorIfNotNull(
283 decryptor_.get(), base::Bind(&base::DoNothing), &is_decryptor_set_));
281 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kVideo, _)) 284 EXPECT_CALL(*decryptor_, RegisterNewKeyCB(Decryptor::kVideo, _))
282 .WillOnce(SaveArg<1>(&key_added_cb_)); 285 .WillOnce(SaveArg<1>(&key_added_cb_));
283 286
284 VideoDecoderConfig input_config = TestVideoConfig::NormalEncrypted(); 287 VideoDecoderConfig input_config = TestVideoConfig::NormalEncrypted();
285 InitializeVideoAndExpectStatus(input_config, PIPELINE_OK); 288 InitializeVideoAndExpectStatus(input_config, PIPELINE_OK);
286 289
287 const VideoDecoderConfig& output_config = 290 const VideoDecoderConfig& output_config =
288 demuxer_stream_->video_decoder_config(); 291 demuxer_stream_->video_decoder_config();
289 EXPECT_EQ(DemuxerStream::VIDEO, demuxer_stream_->type()); 292 EXPECT_EQ(DemuxerStream::VIDEO, demuxer_stream_->type());
290 EXPECT_FALSE(output_config.is_encrypted()); 293 EXPECT_FALSE(output_config.is_encrypted());
291 EXPECT_EQ(input_config.codec(), output_config.codec()); 294 EXPECT_EQ(input_config.codec(), output_config.codec());
292 EXPECT_EQ(input_config.format(), output_config.format()); 295 EXPECT_EQ(input_config.format(), output_config.format());
293 EXPECT_EQ(input_config.profile(), output_config.profile()); 296 EXPECT_EQ(input_config.profile(), output_config.profile());
294 EXPECT_EQ(input_config.coded_size(), output_config.coded_size()); 297 EXPECT_EQ(input_config.coded_size(), output_config.coded_size());
295 EXPECT_EQ(input_config.visible_rect(), output_config.visible_rect()); 298 EXPECT_EQ(input_config.visible_rect(), output_config.visible_rect());
296 EXPECT_EQ(input_config.natural_size(), output_config.natural_size()); 299 EXPECT_EQ(input_config.natural_size(), output_config.natural_size());
297 ASSERT_EQ(input_config.extra_data_size(), output_config.extra_data_size()); 300 ASSERT_EQ(input_config.extra_data_size(), output_config.extra_data_size());
298 if (input_config.extra_data_size() > 0) { 301 if (input_config.extra_data_size() > 0) {
299 EXPECT_FALSE(output_config.extra_data()); 302 EXPECT_FALSE(output_config.extra_data());
300 EXPECT_EQ(0, memcmp(output_config.extra_data(), input_config.extra_data(), 303 EXPECT_EQ(0, memcmp(output_config.extra_data(), input_config.extra_data(),
301 input_config.extra_data_size())); 304 input_config.extra_data_size()));
302 } 305 }
303 } 306 }
304 307
305 TEST_F(DecryptingDemuxerStreamTest, Initialize_NullDecryptor) { 308 TEST_F(DecryptingDemuxerStreamTest, Initialize_NullDecryptor) {
306 EXPECT_CALL(*this, RequestDecryptorNotification(_)) 309 EXPECT_CALL(*this, RequestDecryptorNotification(_))
307 .WillRepeatedly(SetDecryptorIfNotNull(static_cast<Decryptor*>(NULL), 310 .WillRepeatedly(SetDecryptorIfNotNull(static_cast<Decryptor*>(NULL),
311 base::Bind(&base::DoNothing),
308 &is_decryptor_set_)); 312 &is_decryptor_set_));
309 313
310 AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32, 314 AudioDecoderConfig input_config(kCodecVorbis, kSampleFormatPlanarF32,
311 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true); 315 CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true);
312 InitializeAudioAndExpectStatus(input_config, DECODER_ERROR_NOT_SUPPORTED); 316 InitializeAudioAndExpectStatus(input_config, DECODER_ERROR_NOT_SUPPORTED);
313 } 317 }
314 318
315 // Test normal read case where the buffer is encrypted. 319 // Test normal read case where the buffer is encrypted.
316 TEST_F(DecryptingDemuxerStreamTest, Read_Normal) { 320 TEST_F(DecryptingDemuxerStreamTest, Read_Normal) {
317 Initialize(); 321 Initialize();
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 } 549 }
546 550
547 // Test destruction after reset. 551 // Test destruction after reset.
548 TEST_F(DecryptingDemuxerStreamTest, Destroy_AfterReset) { 552 TEST_F(DecryptingDemuxerStreamTest, Destroy_AfterReset) {
549 Initialize(); 553 Initialize();
550 EnterNormalReadingState(); 554 EnterNormalReadingState();
551 Reset(); 555 Reset();
552 } 556 }
553 557
554 } // namespace media 558 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698