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

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

Issue 11359100: Add RunCallback to invoke a callback parameter in unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename Created 8 years, 1 month 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
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"
11 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "media/base/decoder_buffer.h" 13 #include "media/base/decoder_buffer.h"
14 #include "media/base/decrypt_config.h" 14 #include "media/base/decrypt_config.h"
15 #include "media/base/gmock_callback_support.h"
15 #include "media/base/limits.h" 16 #include "media/base/limits.h"
16 #include "media/base/mock_callback.h" 17 #include "media/base/mock_callback.h"
17 #include "media/base/mock_filters.h" 18 #include "media/base/mock_filters.h"
18 #include "media/base/test_data_util.h" 19 #include "media/base/test_data_util.h"
19 #include "media/base/video_decoder.h" 20 #include "media/base/video_decoder.h"
20 #include "media/base/video_frame.h" 21 #include "media/base/video_frame.h"
21 #include "media/base/video_util.h" 22 #include "media/base/video_util.h"
22 #include "media/ffmpeg/ffmpeg_common.h" 23 #include "media/ffmpeg/ffmpeg_common.h"
23 #include "media/filters/ffmpeg_decoder_unittest.h" 24 #include "media/filters/ffmpeg_decoder_unittest.h"
24 #include "media/filters/ffmpeg_glue.h" 25 #include "media/filters/ffmpeg_glue.h"
(...skipping 30 matching lines...) Expand all
55 DecryptConfig::kDecryptionKeySize), 56 DecryptConfig::kDecryptionKeySize),
56 encrypted_frame_offset, 57 encrypted_frame_offset,
57 std::vector<SubsampleEntry>()))); 58 std::vector<SubsampleEntry>())));
58 return buffer; 59 return buffer;
59 } 60 }
60 61
61 ACTION_P(ReturnBuffer, buffer) { 62 ACTION_P(ReturnBuffer, buffer) {
62 arg0.Run(buffer ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); 63 arg0.Run(buffer ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer);
63 } 64 }
64 65
65 ACTION_P2(RunDecryptCB, status, buffer) {
66 arg2.Run(status, buffer);
67 }
68
69 class FFmpegVideoDecoderTest : public testing::Test { 66 class FFmpegVideoDecoderTest : public testing::Test {
70 public: 67 public:
71 FFmpegVideoDecoderTest() 68 FFmpegVideoDecoderTest()
72 : decryptor_(new MockDecryptor()), 69 : decryptor_(new MockDecryptor()),
73 decoder_(NULL), 70 decoder_(NULL),
74 demuxer_(new StrictMock<MockDemuxerStream>()), 71 demuxer_(new StrictMock<MockDemuxerStream>()),
75 read_cb_(base::Bind(&FFmpegVideoDecoderTest::FrameReady, 72 read_cb_(base::Bind(&FFmpegVideoDecoderTest::FrameReady,
76 base::Unretained(this))) { 73 base::Unretained(this))) {
77 FFmpegGlue::InitializeFFmpeg(); 74 FFmpegGlue::InitializeFFmpeg();
78 75
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_SmallerHeight) { 459 TEST_F(FFmpegVideoDecoderTest, DecodeFrame_SmallerHeight) {
463 DecodeIFrameThenTestFile("vp8-I-frame-320x120", 320, 120); 460 DecodeIFrameThenTestFile("vp8-I-frame-320x120", 320, 120);
464 } 461 }
465 462
466 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_Normal) { 463 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_Normal) {
467 InitializeWithEncryptedConfig(); 464 InitializeWithEncryptedConfig();
468 465
469 // Simulate decoding a single encrypted frame. 466 // Simulate decoding a single encrypted frame.
470 EXPECT_CALL(*decryptor_, 467 EXPECT_CALL(*decryptor_,
471 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _)) 468 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _))
472 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, i_frame_buffer_)); 469 .WillRepeatedly(RunCallback<2>(Decryptor::kSuccess, i_frame_buffer_));
473 470
474 VideoDecoder::Status status; 471 VideoDecoder::Status status;
475 scoped_refptr<VideoFrame> video_frame; 472 scoped_refptr<VideoFrame> video_frame;
476 DecodeSingleFrame(encrypted_i_frame_buffer_, &status, &video_frame); 473 DecodeSingleFrame(encrypted_i_frame_buffer_, &status, &video_frame);
477 474
478 EXPECT_EQ(VideoDecoder::kOk, status); 475 EXPECT_EQ(VideoDecoder::kOk, status);
479 ASSERT_TRUE(video_frame); 476 ASSERT_TRUE(video_frame);
480 EXPECT_FALSE(video_frame->IsEndOfStream()); 477 EXPECT_FALSE(video_frame->IsEndOfStream());
481 } 478 }
482 479
483 // Test the case that the decryptor fails to decrypt the encrypted buffer. 480 // Test the case that the decryptor fails to decrypt the encrypted buffer.
484 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_DecryptError) { 481 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_DecryptError) {
485 InitializeWithEncryptedConfig(); 482 InitializeWithEncryptedConfig();
486 483
487 // Simulate decoding a single encrypted frame. 484 // Simulate decoding a single encrypted frame.
488 EXPECT_CALL(*demuxer_, Read(_)) 485 EXPECT_CALL(*demuxer_, Read(_))
489 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 486 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
490 EXPECT_CALL(*decryptor_, 487 EXPECT_CALL(*decryptor_,
491 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _)) 488 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _))
492 .WillRepeatedly(RunDecryptCB(Decryptor::kError, 489 .WillRepeatedly(RunCallback<2>(Decryptor::kError,
493 scoped_refptr<media::DecoderBuffer>())); 490 scoped_refptr<media::DecoderBuffer>()));
494 491
495 // Our read should still get satisfied with end of stream frame during an 492 // Our read should still get satisfied with end of stream frame during an
496 // error. 493 // error.
497 VideoDecoder::Status status; 494 VideoDecoder::Status status;
498 scoped_refptr<VideoFrame> video_frame; 495 scoped_refptr<VideoFrame> video_frame;
499 Read(&status, &video_frame); 496 Read(&status, &video_frame);
500 EXPECT_EQ(VideoDecoder::kDecryptError, status); 497 EXPECT_EQ(VideoDecoder::kDecryptError, status);
501 EXPECT_FALSE(video_frame); 498 EXPECT_FALSE(video_frame);
502 499
503 message_loop_.RunAllPending(); 500 message_loop_.RunAllPending();
504 } 501 }
505 502
506 // Test the case that the decryptor has no key to decrypt the encrypted buffer. 503 // Test the case that the decryptor has no key to decrypt the encrypted buffer.
507 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_NoDecryptionKey) { 504 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_NoDecryptionKey) {
508 InitializeWithEncryptedConfig(); 505 InitializeWithEncryptedConfig();
509 506
510 // Simulate decoding a single encrypted frame. 507 // Simulate decoding a single encrypted frame.
511 EXPECT_CALL(*demuxer_, Read(_)) 508 EXPECT_CALL(*demuxer_, Read(_))
512 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 509 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
513 EXPECT_CALL(*decryptor_, 510 EXPECT_CALL(*decryptor_,
514 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _)) 511 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _))
515 .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey, 512 .WillRepeatedly(RunCallback<2>(Decryptor::kNoKey,
516 scoped_refptr<media::DecoderBuffer>())); 513 scoped_refptr<media::DecoderBuffer>()));
517 514
518 // Our read should still get satisfied with end of stream frame during an 515 // Our read should still get satisfied with end of stream frame during an
519 // error. 516 // error.
520 VideoDecoder::Status status; 517 VideoDecoder::Status status;
521 scoped_refptr<VideoFrame> video_frame; 518 scoped_refptr<VideoFrame> video_frame;
522 Read(&status, &video_frame); 519 Read(&status, &video_frame);
523 EXPECT_EQ(VideoDecoder::kDecryptError, status); 520 EXPECT_EQ(VideoDecoder::kDecryptError, status);
524 EXPECT_FALSE(video_frame); 521 EXPECT_FALSE(video_frame);
525 522
526 message_loop_.RunAllPending(); 523 message_loop_.RunAllPending();
527 } 524 }
528 525
529 // Test the case that the decryptor fails to decrypt the encrypted buffer but 526 // Test the case that the decryptor fails to decrypt the encrypted buffer but
530 // cannot detect the decryption error and returns a corrupted buffer. 527 // cannot detect the decryption error and returns a corrupted buffer.
531 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_CorruptedBufferReturned) { 528 TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_CorruptedBufferReturned) {
532 InitializeWithEncryptedConfig(); 529 InitializeWithEncryptedConfig();
533 530
534 // Simulate decoding a single encrypted frame. 531 // Simulate decoding a single encrypted frame.
535 EXPECT_CALL(*demuxer_, Read(_)) 532 EXPECT_CALL(*demuxer_, Read(_))
536 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); 533 .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_));
537 EXPECT_CALL(*decryptor_, 534 EXPECT_CALL(*decryptor_,
538 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _)) 535 Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _))
539 .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, 536 .WillRepeatedly(RunCallback<2>(Decryptor::kSuccess,
540 corrupt_i_frame_buffer_)); 537 corrupt_i_frame_buffer_));
541 // The decoder only detects the error at the second decoding call. So 538 // The decoder only detects the error at the second decoding call. So
542 // |statistics_cb_| still gets called once. 539 // |statistics_cb_| still gets called once.
543 EXPECT_CALL(statistics_cb_, OnStatistics(_)); 540 EXPECT_CALL(statistics_cb_, OnStatistics(_));
544 541
545 // Our read should still get satisfied with end of stream frame during an 542 // Our read should still get satisfied with end of stream frame during an
546 // error. 543 // error.
547 VideoDecoder::Status status; 544 VideoDecoder::Status status;
548 scoped_refptr<VideoFrame> video_frame; 545 scoped_refptr<VideoFrame> video_frame;
549 Read(&status, &video_frame); 546 Read(&status, &video_frame);
550 EXPECT_EQ(VideoDecoder::kDecodeError, status); 547 EXPECT_EQ(VideoDecoder::kDecodeError, status);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 713
717 // Signal an aborted demuxer read. 714 // Signal an aborted demuxer read.
718 read_cb.Run(DemuxerStream::kAborted, NULL); 715 read_cb.Run(DemuxerStream::kAborted, NULL);
719 716
720 // Make sure we get a NULL video frame returned. 717 // Make sure we get a NULL video frame returned.
721 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull())); 718 EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, IsNull()));
722 message_loop_.RunAllPending(); 719 message_loop_.RunAllPending();
723 } 720 }
724 721
725 } // namespace media 722 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/decrypting_video_decoder_unittest.cc ('k') | media/filters/video_renderer_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698