Chromium Code Reviews| Index: media/filters/pipeline_integration_test.cc |
| diff --git a/media/filters/pipeline_integration_test.cc b/media/filters/pipeline_integration_test.cc |
| index 54da1d24f0d770b2382ed857294e541e7796b44a..4bd6dc5c00e35dea0c62b463f1a38cae3e26f967 100644 |
| --- a/media/filters/pipeline_integration_test.cc |
| +++ b/media/filters/pipeline_integration_test.cc |
| @@ -6,16 +6,20 @@ |
| #include "base/bind.h" |
| #include "media/base/decoder_buffer.h" |
| +#include "media/base/mock_filters.h" |
| #include "media/base/test_data_util.h" |
| +#include "media/crypto/aes_decryptor.h" |
| +#include "media/crypto/decryptor_client.h" |
| #include "media/filters/chunk_demuxer_client.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| -namespace media { |
| +using ::testing::_; |
| -// Key ID of the video track in test file "bear-320x240-encrypted.webm". |
| -static const unsigned char kKeyId[] = |
| - "\x11\xa5\x18\x37\xc4\x73\x84\x03\xe5\xe6\x57\xed\x8e\x06\xd9\x7c"; |
| +namespace media { |
| -static const char* kSourceId = "SourceId"; |
| +static const char kSourceId[] = "SourceId"; |
| +static const char kClearKeySystem[] = "org.w3.clearkey"; |
| +static const uint8 kInitData[] = { 0x69, 0x6e, 0x69, 0x74 }; |
| // Helper class that emulates calls made on the ChunkDemuxer by the |
| // Media Source API. |
| @@ -33,11 +37,8 @@ class MockMediaSource : public ChunkDemuxerClient { |
| virtual ~MockMediaSource() {} |
| - void set_decryptor(AesDecryptor* decryptor) { |
| - decryptor_ = decryptor; |
| - } |
| - AesDecryptor* decryptor() const { |
| - return decryptor_; |
| + void set_decryptor_client(DecryptorClient* decryptor_client) { |
| + decryptor_client_ = decryptor_client; |
| } |
| const std::string& url() const { return url_; } |
| @@ -88,14 +89,12 @@ class MockMediaSource : public ChunkDemuxerClient { |
| chunk_demuxer_ = NULL; |
| } |
| - virtual void KeyNeeded(scoped_array<uint8> init_data, int init_data_size) { |
| + virtual void DemuxerNeedKey(scoped_array<uint8> init_data, |
| + int init_data_size) { |
| DCHECK(init_data.get()); |
| DCHECK_EQ(init_data_size, 16); |
| - DCHECK(decryptor()); |
| - // In test file bear-320x240-encrypted.webm, the decryption key is equal to |
| - // |init_data|. |
| - decryptor()->AddKey(init_data.get(), init_data_size, |
| - init_data.get(), init_data_size); |
| + DCHECK(decryptor_client_); |
| + decryptor_client_->NeedKey("", "", init_data.Pass(), init_data_size); |
| } |
| private: |
| @@ -104,22 +103,86 @@ class MockMediaSource : public ChunkDemuxerClient { |
| int current_position_; |
| int initial_append_size_; |
| scoped_refptr<ChunkDemuxer> chunk_demuxer_; |
| - AesDecryptor* decryptor_; |
| + DecryptorClient* decryptor_client_; |
| +}; |
| + |
| +class MockEncryptedMedia : public MockDecryptorClient { |
|
scherkus (not reviewing)
2012/06/13 23:35:08
does this need to extend MockDecryptorClient?
if
xhwang
2012/06/15 01:41:04
Done.
|
| + public: |
| + MockEncryptedMedia() : decryptor_(this) {} |
| + |
| + AesDecryptor* decryptor() { |
| + return &decryptor_; |
| + } |
| + |
| + // DecryptorClient implementation. |
| + virtual void KeyMessage(const std::string& key_system, |
| + const std::string& session_id, |
| + scoped_array<uint8> message, |
| + int message_length, |
| + const std::string& default_url) { |
| + EXPECT_TRUE(key_system == kClearKeySystem); |
| + EXPECT_TRUE(!session_id.empty()); |
| + EXPECT_TRUE(message.get()); |
| + EXPECT_GT(message_length, 0); |
|
scherkus (not reviewing)
2012/06/13 23:35:08
do we not care what the message is?
xhwang
2012/06/15 01:41:04
Currently the AesDecryptor just returns the init_d
|
| + key_system_string_ = key_system; |
| + session_id_string_ = session_id; |
| + } |
| + |
| + virtual void NeedKey(const std::string& key_system, |
| + const std::string& session_id, |
| + scoped_array<uint8> init_data, |
| + int init_data_length) { |
| + key_system_string_ = key_system; |
| + session_id_string_ = session_id; |
| + if (key_system_string_.empty()) { |
|
scherkus (not reviewing)
2012/06/13 23:35:08
do we fire need key w/ empty key system today?
xhwang
2012/06/15 01:41:04
Yes. When NeedKey is fired from the demuxer. Added
|
| + DCHECK(session_id_string_.empty()); |
| + decryptor_.GenerateKeyRequest(kClearKeySystem, |
| + kInitData, arraysize(kInitData)); |
| + } |
| + |
| + EXPECT_FALSE(key_system_string_.empty()); |
|
scherkus (not reviewing)
2012/06/13 23:35:08
based on if statement above it looks like key_syst
ddorwin
2012/06/14 21:04:04
This assumes KeyMessage gets called (and that AesD
xhwang
2012/06/15 01:41:04
Done.
|
| + EXPECT_FALSE(session_id_string_.empty()); |
| + // In test file bear-320x240-encrypted.webm, the decryption key is equal to |
| + // |init_data|. |
| + decryptor_.AddKey(key_system_string_, init_data.get(), init_data_length, |
| + init_data.get(), init_data_length, session_id_string_); |
| + } |
| + |
| + private: |
| + AesDecryptor decryptor_; |
| + std::string key_system_string_; |
| + std::string session_id_string_; |
| }; |
| class PipelineIntegrationTest |
| : public testing::Test, |
| public PipelineIntegrationTestBase { |
| public: |
| - void StartPipelineWithMediaSource(MockMediaSource& source) { |
| + void StartPipelineWithMediaSource(MockMediaSource* source) { |
| + pipeline_->Start( |
| + CreateFilterCollection(source), |
| + base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), |
| + base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), |
| + NetworkEventCB(), QuitOnStatusCB(PIPELINE_OK)); |
| + |
| + ASSERT_TRUE(decoder_.get()); |
| + |
| + message_loop_.Run(); |
| + } |
| + |
| + void StartPipelineWithEncryptedMedia(MockMediaSource* source, |
| + MockEncryptedMedia* encrypted_media) { |
| pipeline_->Start( |
| - CreateFilterCollection(&source), |
| + CreateFilterCollection(source), |
| base::Bind(&PipelineIntegrationTest::OnEnded, base::Unretained(this)), |
| base::Bind(&PipelineIntegrationTest::OnError, base::Unretained(this)), |
| NetworkEventCB(), QuitOnStatusCB(PIPELINE_OK)); |
| ASSERT_TRUE(decoder_.get()); |
| - source.set_decryptor(decryptor_.get()); |
| + decoder_->set_decryptor(encrypted_media->decryptor()); |
| + source->set_decryptor_client(encrypted_media); |
| + |
| + EXPECT_CALL(*encrypted_media, KeyAdded(kClearKeySystem, _)); |
| message_loop_.Run(); |
| } |
| @@ -134,7 +197,7 @@ class PipelineIntegrationTest |
| int seek_file_position, |
| int seek_append_size) { |
| MockMediaSource source(filename, initial_append_size); |
| - StartPipelineWithMediaSource(source); |
| + StartPipelineWithMediaSource(&source); |
| if (pipeline_status_ != PIPELINE_OK) |
| return false; |
| @@ -177,7 +240,8 @@ TEST_F(PipelineIntegrationTest, BasicPlaybackHashed) { |
| TEST_F(PipelineIntegrationTest, EncryptedPlayback) { |
| MockMediaSource source("bear-320x240-encrypted.webm", 219726); |
| - StartPipelineWithMediaSource(source); |
| + MockEncryptedMedia encrypted_media; |
| + StartPipelineWithEncryptedMedia(&source, &encrypted_media); |
| source.EndOfStream(); |
| ASSERT_EQ(PIPELINE_OK, pipeline_status_); |