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

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

Issue 11189082: Update PluginInstance for audio support for content decryption. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix tests Created 8 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « media/filters/decrypting_audio_decoder.cc ('k') | webkit/media/crypto/ppapi/cdm_wrapper.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 10 #include "base/message_loop.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 DecryptingAudioDecoderTest() 89 DecryptingAudioDecoderTest()
90 : decoder_(new StrictMock<DecryptingAudioDecoder>( 90 : decoder_(new StrictMock<DecryptingAudioDecoder>(
91 base::Bind(&Identity<scoped_refptr<base::MessageLoopProxy> >, 91 base::Bind(&Identity<scoped_refptr<base::MessageLoopProxy> >,
92 message_loop_.message_loop_proxy()), 92 message_loop_.message_loop_proxy()),
93 base::Bind( 93 base::Bind(
94 &DecryptingAudioDecoderTest::RequestDecryptorNotification, 94 &DecryptingAudioDecoderTest::RequestDecryptorNotification,
95 base::Unretained(this)))), 95 base::Unretained(this)))),
96 decryptor_(new StrictMock<MockDecryptor>()), 96 decryptor_(new StrictMock<MockDecryptor>()),
97 demuxer_(new StrictMock<MockDemuxerStream>()), 97 demuxer_(new StrictMock<MockDemuxerStream>()),
98 encrypted_buffer_(CreateFakeEncryptedBuffer()), 98 encrypted_buffer_(CreateFakeEncryptedBuffer()),
99 decoded_frame_(new DataBuffer(kFakeAudioFrameSize)), 99 decoded_frame_(NULL),
100 end_of_stream_frame_(new DataBuffer(0)), 100 end_of_stream_frame_(new DataBuffer(0)),
101 decoded_frame_list_(1, decoded_frame_) { 101 decoded_frame_list_() {
102 // TODO(xhwang): Fix this after DataBuffer(data, size) is public.
103 scoped_refptr<DataBuffer> buffer = new DataBuffer(kFakeAudioFrameSize);
104 buffer->SetDataSize(kFakeAudioFrameSize);
105 decoded_frame_ = buffer;
106 decoded_frame_list_.push_back(decoded_frame_);
102 } 107 }
103 108
104 void InitializeAndExpectStatus(const AudioDecoderConfig& config, 109 void InitializeAndExpectStatus(const AudioDecoderConfig& config,
105 PipelineStatus status) { 110 PipelineStatus status) {
106 EXPECT_CALL(*demuxer_, audio_decoder_config()) 111 EXPECT_CALL(*demuxer_, audio_decoder_config())
107 .WillRepeatedly(ReturnRef(config)); 112 .WillRepeatedly(ReturnRef(config));
108 113
109 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status), 114 decoder_->Initialize(demuxer_, NewExpectedStatusCB(status),
110 base::Bind(&MockStatisticsCB::OnStatistics, 115 base::Bind(&MockStatisticsCB::OnStatistics,
111 base::Unretained(&statistics_cb_))); 116 base::Unretained(&statistics_cb_)));
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 EXPECT_CALL(statistics_cb_, OnStatistics(_)) 323 EXPECT_CALL(statistics_cb_, OnStatistics(_))
319 .Times(2); 324 .Times(2);
320 325
321 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_); 326 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_);
322 } 327 }
323 328
324 // Test the case where the decryptor returns multiple decoded frames. 329 // Test the case where the decryptor returns multiple decoded frames.
325 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFrames) { 330 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFrames) {
326 Initialize(); 331 Initialize();
327 332
328 scoped_refptr<Buffer> decoded_frame_a(new DataBuffer(kFakeAudioFrameSize)); 333 scoped_refptr<DataBuffer> frame_a = new DataBuffer(kFakeAudioFrameSize);
329 scoped_refptr<Buffer> decoded_frame_b(new DataBuffer(kFakeAudioFrameSize)); 334 frame_a->SetDataSize(kFakeAudioFrameSize);
330 decoded_frame_list_.push_back(decoded_frame_a); 335 scoped_refptr<DataBuffer> frame_b = new DataBuffer(kFakeAudioFrameSize);
331 decoded_frame_list_.push_back(decoded_frame_b); 336 frame_b->SetDataSize(kFakeAudioFrameSize);
337 decoded_frame_list_.push_back(frame_a);
338 decoded_frame_list_.push_back(frame_b);
332 339
333 EXPECT_CALL(*demuxer_, Read(_)) 340 EXPECT_CALL(*demuxer_, Read(_))
334 .WillOnce(ReturnBuffer(encrypted_buffer_)); 341 .WillOnce(ReturnBuffer(encrypted_buffer_));
335 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) 342 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
336 .WillOnce(RunCallback2(Decryptor::kSuccess, decoded_frame_list_)); 343 .WillOnce(RunCallback2(Decryptor::kSuccess, decoded_frame_list_));
337 EXPECT_CALL(statistics_cb_, OnStatistics(_)); 344 EXPECT_CALL(statistics_cb_, OnStatistics(_));
338 345
339 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_); 346 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_);
340 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_a); 347 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, frame_a);
341 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_b); 348 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, frame_b);
342 } 349 }
343 350
344 // Test the case where the decryptor receives end-of-stream buffer. 351 // Test the case where the decryptor receives end-of-stream buffer.
345 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_EndOfStream) { 352 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_EndOfStream) {
346 Initialize(); 353 Initialize();
347 EnterNormalDecodingState(); 354 EnterNormalDecodingState();
348 EnterEndOfStreamState(); 355 EnterEndOfStreamState();
349 } 356 }
350 357
351 // Test the case where the decryptor returns multiple decoded frames, the last
352 // of which is end-of-stream frame.
353 TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFramesWithEos) {
354 Initialize();
355
356 scoped_refptr<Buffer> decoded_frame_a(new DataBuffer(kFakeAudioFrameSize));
357 scoped_refptr<Buffer> decoded_frame_b(new DataBuffer(kFakeAudioFrameSize));
358 Decryptor::AudioBuffers second_decoded_frame_list;
359 second_decoded_frame_list.push_back(decoded_frame_a);
360 second_decoded_frame_list.push_back(decoded_frame_b);
361 second_decoded_frame_list.push_back(end_of_stream_frame_);
362
363 EXPECT_CALL(*demuxer_, Read(_))
364 .WillOnce(ReturnBuffer(encrypted_buffer_))
365 .WillOnce(ReturnBuffer(DecoderBuffer::CreateEOSBuffer()));
366 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
367 .WillOnce(RunCallback2(Decryptor::kSuccess, decoded_frame_list_))
368 .WillOnce(RunCallback2(Decryptor::kSuccess, second_decoded_frame_list));
369 // Expect only one OnStatistics() here because EOS input buffer doesn't
370 // trigger statistics reporting.
371 EXPECT_CALL(statistics_cb_, OnStatistics(_));
372
373 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_);
374 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_a);
375 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_b);
376 ReadAndExpectFrameReadyWith(AudioDecoder::kOk, end_of_stream_frame_);
377 }
378
379 // Test the case where the a key is added when the decryptor is in 358 // Test the case where the a key is added when the decryptor is in
380 // kWaitingForKey state. 359 // kWaitingForKey state.
381 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DuringWaitingForKey) { 360 TEST_F(DecryptingAudioDecoderTest, KeyAdded_DuringWaitingForKey) {
382 Initialize(); 361 Initialize();
383 EnterWaitingForKeyState(); 362 EnterWaitingForKeyState();
384 363
385 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) 364 EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _))
386 .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_frame_list_)); 365 .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_frame_list_));
387 EXPECT_CALL(statistics_cb_, OnStatistics(_)); 366 EXPECT_CALL(statistics_cb_, OnStatistics(_));
388 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_)); 367 EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 483
505 EXPECT_CALL(*demuxer_, Read(_)) 484 EXPECT_CALL(*demuxer_, Read(_))
506 .WillOnce(ReturnConfigChanged()); 485 .WillOnce(ReturnConfigChanged());
507 486
508 // TODO(xhwang): Update this test when kConfigChanged is supported in 487 // TODO(xhwang): Update this test when kConfigChanged is supported in
509 // DecryptingAudioDecoder. 488 // DecryptingAudioDecoder.
510 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL); 489 ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL);
511 } 490 }
512 491
513 } // namespace media 492 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/decrypting_audio_decoder.cc ('k') | webkit/media/crypto/ppapi/cdm_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698