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..4fbcf6dfb794c42d97ac2dc65917bfac4f06d8ac 100644 |
| --- a/media/filters/pipeline_integration_test.cc |
| +++ b/media/filters/pipeline_integration_test.cc |
| @@ -6,15 +6,14 @@ |
| #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" |
| namespace media { |
| -// 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"; |
| - |
| static const char* kSourceId = "SourceId"; |
| // Helper class that emulates calls made on the ChunkDemuxer by the |
| @@ -33,11 +32,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 +84,12 @@ class MockMediaSource : public ChunkDemuxerClient { |
| chunk_demuxer_ = NULL; |
| } |
| - virtual void KeyNeeded(scoped_array<uint8> init_data, int init_data_size) { |
| + virtual void DemuxerKeyNeeded(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_->KeyNeeded("", "", init_data.Pass(), init_data_size); |
| } |
| private: |
| @@ -104,6 +98,31 @@ class MockMediaSource : public ChunkDemuxerClient { |
| int current_position_; |
| int initial_append_size_; |
| scoped_refptr<ChunkDemuxer> chunk_demuxer_; |
| + DecryptorClient* decryptor_client_; |
| +}; |
| + |
| +class MockEncryptedMedia : public MockDecryptorClient { |
|
ddorwin
2012/06/11 21:02:40
The class name is not very descriptive.
xhwang
2012/06/12 19:01:15
Agreed, but I haven't found a good name for this.
|
| + public: |
| + MockEncryptedMedia() {} |
| + virtual ~MockEncryptedMedia() {} |
| + |
| + void set_decryptor(AesDecryptor* decryptor) { |
| + decryptor_ = decryptor; |
| + } |
| + |
| + // DecryptorClient implementation. |
| + virtual void KeyNeeded(const std::string& key_system, |
| + const std::string& session_id, |
| + scoped_array<uint8> init_data, |
| + int init_data_length) { |
| + // In test file bear-320x240-encrypted.webm, the decryption key is equal to |
| + // |init_data|. |
| + DCHECK(decryptor_); |
| + decryptor_->AddKey(key_system, init_data.get(), init_data_length, |
|
ddorwin
2012/06/11 21:02:40
key_system and session_id will be empty on keyneed
xhwang
2012/06/12 19:01:15
Done.
|
| + init_data.get(), init_data_length, session_id); |
| + } |
| + |
| + private: |
| AesDecryptor* decryptor_; |
| }; |
| @@ -111,15 +130,33 @@ class PipelineIntegrationTest |
| : public testing::Test, |
| public PipelineIntegrationTestBase { |
| public: |
| - void StartPipelineWithMediaSource(MockMediaSource& source) { |
| + void StartPipelineWithMediaSource(MockMediaSource* source) { |
| 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()); |
| + |
| + message_loop_.Run(); |
| + } |
| + |
| + void StartPipelineWithEncryptedMedia(MockMediaSource* source, |
| + MockEncryptedMedia* encrypted_media) { |
| + 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()); |
| + ASSERT_TRUE(decryptor_.get()); |
| + encrypted_media->set_decryptor(decryptor_.get()); |
| + decryptor_->Init(encrypted_media); |
| + source->set_decryptor_client(encrypted_media); |
| + |
| + EXPECT_CALL(*encrypted_media, KeyAdded("", "")); |
| message_loop_.Run(); |
| } |
| @@ -134,7 +171,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 +214,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_); |