Index: media/filters/ffmpeg_video_decoder_unittest.cc |
=================================================================== |
--- media/filters/ffmpeg_video_decoder_unittest.cc (revision 147171) |
+++ media/filters/ffmpeg_video_decoder_unittest.cc (working copy) |
@@ -43,25 +43,18 @@ |
static const gfx::Size kNaturalSize(522, 288); |
static const AVRational kFrameRate = { 100, 1 }; |
static const AVRational kAspectRatio = { 1, 1 }; |
- |
static const char kClearKeySystem[] = "org.w3.clearkey"; |
static const uint8 kInitData[] = { 0x69, 0x6e, 0x69, 0x74 }; |
-static const uint8 kWrongSecret[] = { |
+static const uint8 kRightKey[] = { |
+ 0x41, 0x20, 0x77, 0x6f, 0x6e, 0x64, 0x65, 0x72, |
+ 0x66, 0x75, 0x6c, 0x20, 0x6b, 0x65, 0x79, 0x21 |
+}; |
+static const uint8 kWrongKey[] = { |
0x49, 0x27, 0x6d, 0x20, 0x61, 0x20, 0x77, 0x72, |
0x6f, 0x6e, 0x67, 0x20, 0x6b, 0x65, 0x79, 0x2e |
}; |
static const uint8 kKeyId[] = { 0x4b, 0x65, 0x79, 0x20, 0x49, 0x44 }; |
-static const uint8 kSecretKey[] = { |
- 0xfb, 0x67, 0x8a, 0x91, 0x19, 0x12, 0x7b, 0x6b, |
- 0x0b, 0x63, 0x11, 0xf8, 0x6f, 0xe1, 0xc4, 0x2d |
-}; |
-static const uint64 kIv = 3735928559; |
-static const uint8 kHmac[] = { |
- 0x16, 0xc0, 0x65, 0x1f, 0xf8, 0x0b, 0x36, 0x16, |
- 0xb8, 0x32, 0x35, 0x56 |
-}; |
- |
ACTION_P(ReturnBuffer, buffer) { |
arg0.Run(buffer ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); |
} |
@@ -84,13 +77,8 @@ |
end_of_stream_buffer_ = DecoderBuffer::CreateEOSBuffer(); |
i_frame_buffer_ = ReadTestDataFile("vp8-I-frame-320x240"); |
corrupt_i_frame_buffer_ = ReadTestDataFile("vp8-corrupt-I-frame"); |
- { |
- scoped_refptr<DecoderBuffer> temp_buffer = ReadTestDataFile( |
- "vp8-encrypted-I-frame-320x240"); |
- encrypted_i_frame_buffer_ = DecoderBuffer::CopyFrom( |
- temp_buffer->GetData() + arraysize(kHmac), |
- temp_buffer->GetDataSize() - arraysize(kHmac)); |
- } |
+ encrypted_i_frame_buffer_ = ReadTestDataFile( |
+ "vp8-encrypted-I-frame-320x240"); |
config_.Initialize(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, |
kVideoFormat, kCodedSize, kVisibleRect, |
@@ -219,24 +207,6 @@ |
message_loop_.RunAllPending(); |
} |
- // Generates a 16 byte CTR counter block. The CTR counter block format is a |
- // CTR IV appended with a CTR block counter. |iv| is an 8 byte CTR IV. |
- static scoped_array<uint8> GenerateCounterBlock(uint64 iv) { |
- scoped_array<uint8> counter_block_data( |
- new uint8[DecryptConfig::kDecryptionKeySize]); |
- |
- // Set the IV. |
- memcpy(counter_block_data.get(), &iv, sizeof(iv)); |
- |
- // Set block counter to all 0's. |
- memset(counter_block_data.get() + sizeof(iv), |
- 0, |
- DecryptConfig::kDecryptionKeySize - sizeof(iv)); |
- |
- return counter_block_data.Pass(); |
- } |
- |
- |
MOCK_METHOD2(FrameReady, void(VideoDecoder::DecoderStatus, |
const scoped_refptr<VideoFrame>&)); |
@@ -418,9 +388,7 @@ |
DecodeIFrameThenTestFile("vp8-I-frame-320x120", 320, 120); |
} |
-// TODO(fgalligan): Enable test when encrypted test data is updated and new |
-// decryption code is landed. http://crbug.com/132801 |
-TEST_F(FFmpegVideoDecoderTest, DISABLED_DecodeEncryptedFrame_Normal) { |
+TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_Normal) { |
Initialize(); |
std::string sessing_id_string; |
EXPECT_CALL(decryptor_client_, |
@@ -430,18 +398,12 @@ |
decryptor_->GenerateKeyRequest(kClearKeySystem, |
kInitData, arraysize(kInitData)); |
EXPECT_CALL(decryptor_client_, KeyAdded(kClearKeySystem, sessing_id_string)); |
- decryptor_->AddKey(kClearKeySystem, kSecretKey, arraysize(kSecretKey), |
+ decryptor_->AddKey(kClearKeySystem, kRightKey, arraysize(kRightKey), |
kKeyId, arraysize(kKeyId), sessing_id_string); |
// Simulate decoding a single encrypted frame. |
- scoped_array<uint8> counter_block(GenerateCounterBlock(kIv)); |
encrypted_i_frame_buffer_->SetDecryptConfig(scoped_ptr<DecryptConfig>( |
- new DecryptConfig( |
- kKeyId, arraysize(kKeyId), |
- counter_block.get(), DecryptConfig::kDecryptionKeySize, |
- kHmac, arraysize(kHmac), |
- sizeof(kIv)))); |
- |
+ new DecryptConfig(kKeyId, arraysize(kKeyId)))); |
VideoDecoder::DecoderStatus status; |
scoped_refptr<VideoFrame> video_frame; |
DecodeSingleFrame(encrypted_i_frame_buffer_, &status, &video_frame); |
@@ -456,13 +418,8 @@ |
Initialize(); |
// Simulate decoding a single encrypted frame. |
- scoped_array<uint8> counter_block(GenerateCounterBlock(kIv)); |
encrypted_i_frame_buffer_->SetDecryptConfig(scoped_ptr<DecryptConfig>( |
- new DecryptConfig( |
- kKeyId, arraysize(kKeyId), |
- counter_block.get(), DecryptConfig::kDecryptionKeySize, |
- kHmac, arraysize(kHmac), |
- sizeof(kIv)))); |
+ new DecryptConfig(kKeyId, arraysize(kKeyId)))); |
EXPECT_CALL(*demuxer_, Read(_)) |
.WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); |
@@ -482,27 +439,31 @@ |
TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_WrongKey) { |
Initialize(); |
EXPECT_CALL(decryptor_client_, KeyAdded("", "")); |
- decryptor_->AddKey("", kWrongSecret, arraysize(kWrongSecret), |
+ decryptor_->AddKey("", kWrongKey, arraysize(kWrongKey), |
kKeyId, arraysize(kKeyId), ""); |
- // Simulate decoding a single encrypted frame. |
- scoped_array<uint8> counter_block(GenerateCounterBlock(kIv)); |
encrypted_i_frame_buffer_->SetDecryptConfig(scoped_ptr<DecryptConfig>( |
- new DecryptConfig( |
- kKeyId, arraysize(kKeyId), |
- counter_block.get(), DecryptConfig::kDecryptionKeySize, |
- kHmac, arraysize(kHmac), |
- sizeof(kIv)))); |
- |
+ new DecryptConfig(kKeyId, arraysize(kKeyId)))); |
EXPECT_CALL(*demuxer_, Read(_)) |
.WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); |
+ // Using the wrong key on some platforms doesn't cause an decryption error but |
+ // actually attempts to decode the content, however we're unable to |
+ // distinguish between the two (see http://crbug.com/124434). |
+#if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) |
+ EXPECT_CALL(statistics_cb_, OnStatistics(_)); |
+#endif |
+ |
// Our read should still get satisfied with end of stream frame during an |
// error. |
VideoDecoder::DecoderStatus status; |
scoped_refptr<VideoFrame> video_frame; |
Read(&status, &video_frame); |
+#if defined(USE_NSS) || defined(OS_WIN) || defined(OS_MACOSX) |
+ EXPECT_EQ(VideoDecoder::kDecodeError, status); |
+#else |
EXPECT_EQ(VideoDecoder::kDecryptError, status); |
+#endif |
EXPECT_FALSE(video_frame); |
message_loop_.RunAllPending(); |