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 2ee129751815f7b262c4e6ebf3d45a4838472877..3af1d7b4dca19e2daf3142ddce6c7ca96aa7907e 100644 |
| --- a/media/filters/pipeline_integration_test.cc |
| +++ b/media/filters/pipeline_integration_test.cc |
| @@ -5,6 +5,7 @@ |
| #include "media/filters/pipeline_integration_test_base.h" |
| #include "base/bind.h" |
| +#include "base/memory/scoped_ptr.h" |
| #include "base/string_util.h" |
| #include "build/build_config.h" |
| #include "media/base/decoder_buffer.h" |
| @@ -43,7 +44,45 @@ static const int k1280IsoFileDurationMs = 2736; |
| // They do not exercise the Decrypting{Audio|Video}Decoder path. |
| class FakeEncryptedMedia { |
| public: |
| - FakeEncryptedMedia() |
| + // Defines the behavior of the "app" that responds to EME events. |
| + class AppBase { |
|
xhwang
2013/01/09 21:18:21
Looks like AppBase isn't doing a lot of work and i
ddorwin
2013/01/10 04:44:46
Done.
I left KeyError since that's likely to be co
|
| + public: |
| + virtual ~AppBase() {} |
| + |
| + virtual void KeyAdded(const std::string& key_system, |
| + const std::string& session_id) { |
| + EXPECT_EQ(kClearKeySystem, key_system); |
| + EXPECT_FALSE(session_id.empty()); |
| + FAIL() << "Unexpected KeyAdded"; |
| + } |
| + |
| + virtual void KeyMessage(const std::string& key_system, |
| + const std::string& session_id, |
| + const std::string& message, |
| + const std::string& default_url) { |
| + EXPECT_EQ(kClearKeySystem, key_system); |
| + EXPECT_FALSE(session_id.empty()); |
| + EXPECT_FALSE(message.empty()); |
| + FAIL() << "Unexpected KeyMessage"; |
| + } |
| + |
| + virtual void NeedKey(const std::string& key_system, |
| + const std::string& session_id, |
| + const std::string& type, |
| + scoped_array<uint8> init_data, int init_data_length, |
| + AesDecryptor* decryptor) { |
| + FAIL() << "Unexpected NeedKey"; |
| + } |
| + |
| + virtual void KeyError(const std::string& key_system, |
| + const std::string& session_id, |
| + AesDecryptor::KeyError error_code, |
| + int system_code) { |
| + FAIL() << "Unexpected Key Error"; |
| + } |
| + }; |
| + |
| + FakeEncryptedMedia(AppBase* app) |
| : decryptor_(base::Bind(&FakeEncryptedMedia::KeyAdded, |
| base::Unretained(this)), |
| base::Bind(&FakeEncryptedMedia::KeyError, |
| @@ -51,30 +90,59 @@ class FakeEncryptedMedia { |
| base::Bind(&FakeEncryptedMedia::KeyMessage, |
| base::Unretained(this)), |
| base::Bind(&FakeEncryptedMedia::NeedKey, |
| - base::Unretained(this))) { |
| + base::Unretained(this))), |
| + app_(app) { |
| } |
| AesDecryptor* decryptor() { |
| return &decryptor_; |
| } |
| - // Callbacks for firing key events. |
| + // Callbacks for firing key events. Delegate to |app_|. |
| void KeyAdded(const std::string& key_system, const std::string& session_id) { |
| - EXPECT_EQ(kClearKeySystem, key_system); |
| - EXPECT_FALSE(session_id.empty()); |
| + app_->KeyAdded(key_system, session_id); |
| } |
| void KeyError(const std::string& key_system, |
| const std::string& session_id, |
| AesDecryptor::KeyError error_code, |
| int system_code) { |
| - FAIL() << "Unexpected Key Error"; |
| + app_->KeyError(key_system, session_id, error_code, system_code); |
| } |
| void KeyMessage(const std::string& key_system, |
| const std::string& session_id, |
| const std::string& message, |
| const std::string& default_url) { |
| + app_->KeyMessage(key_system, session_id, message, default_url); |
| + } |
| + |
| + void NeedKey(const std::string& key_system, |
| + const std::string& session_id, |
| + const std::string& type, |
| + scoped_array<uint8> init_data, int init_data_length) { |
| + app_->NeedKey(key_system, session_id, type, |
| + init_data.Pass(), init_data_length, &decryptor_); |
| + } |
| + |
| + private: |
| + AesDecryptor decryptor_; |
| + scoped_ptr<AppBase> app_; |
| +}; |
| + |
| +// Provides |kSecretKey| in response to needkey. |
| +class KeyProvidingApp : public FakeEncryptedMedia::AppBase { |
| + public: |
| + void KeyAdded(const std::string& key_system, |
| + const std::string& session_id) OVERRIDE { |
| + EXPECT_EQ(kClearKeySystem, key_system); |
| + EXPECT_FALSE(session_id.empty()); |
| + } |
| + |
| + void KeyMessage(const std::string& key_system, |
| + const std::string& session_id, |
| + const std::string& message, |
| + const std::string& default_url) OVERRIDE { |
| EXPECT_EQ(kClearKeySystem, key_system); |
| EXPECT_FALSE(session_id.empty()); |
| EXPECT_FALSE(message.empty()); |
| @@ -86,7 +154,8 @@ class FakeEncryptedMedia { |
| void NeedKey(const std::string& key_system, |
| const std::string& session_id, |
| const std::string& type, |
| - scoped_array<uint8> init_data, int init_data_length) { |
| + scoped_array<uint8> init_data, int init_data_length, |
| + AesDecryptor* decryptor) OVERRIDE { |
| current_key_system_ = key_system; |
| current_session_id_ = session_id; |
| @@ -95,22 +164,31 @@ class FakeEncryptedMedia { |
| // session (which will call KeyMessage). |
| if (current_key_system_.empty()) { |
| EXPECT_TRUE(current_session_id_.empty()); |
| - EXPECT_TRUE(decryptor_.GenerateKeyRequest( |
| + EXPECT_TRUE(decryptor->GenerateKeyRequest( |
| kClearKeySystem, type, kInitData, arraysize(kInitData))); |
| } |
| EXPECT_FALSE(current_key_system_.empty()); |
| EXPECT_FALSE(current_session_id_.empty()); |
| - decryptor_.AddKey(current_key_system_, kSecretKey, arraysize(kSecretKey), |
| + decryptor->AddKey(current_key_system_, kSecretKey, arraysize(kSecretKey), |
| init_data.get(), init_data_length, current_session_id_); |
| } |
| - private: |
| - AesDecryptor decryptor_; |
| std::string current_key_system_; |
| std::string current_session_id_; |
| }; |
| +// Ignores needkey and does not perform a license request |
| +class NoResponseApp : public FakeEncryptedMedia::AppBase { |
| + public: |
| + void NeedKey(const std::string& key_system, |
| + const std::string& session_id, |
| + const std::string& type, |
| + scoped_array<uint8> init_data, int init_data_length, |
| + AesDecryptor* decryptor) OVERRIDE { |
| + } |
| +}; |
| + |
| // Helper class that emulates calls made on the ChunkDemuxer by the |
| // Media Source API. |
| class MockMediaSource { |
| @@ -359,7 +437,7 @@ TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_WebM) { |
| TEST_F(PipelineIntegrationTest, MediaSource_ConfigChange_Encrypted_WebM) { |
| MockMediaSource source("bear-320x240-16x9-aspect-av-enc_av.webm", kWebM, |
| kAppendWholeFile); |
| - FakeEncryptedMedia encrypted_media; |
| + FakeEncryptedMedia encrypted_media(new KeyProvidingApp()); |
| StartPipelineWithEncryptedMedia(&source, &encrypted_media); |
| scoped_refptr<DecoderBuffer> second_file = |
| @@ -387,7 +465,7 @@ TEST_F(PipelineIntegrationTest, |
| MediaSource_ConfigChange_ClearThenEncrypted_WebM) { |
| MockMediaSource source("bear-320x240-16x9-aspect.webm", kWebM, |
| kAppendWholeFile); |
| - FakeEncryptedMedia encrypted_media; |
| + FakeEncryptedMedia encrypted_media(new KeyProvidingApp()); |
| StartPipelineWithEncryptedMedia(&source, &encrypted_media); |
| scoped_refptr<DecoderBuffer> second_file = |
| @@ -418,7 +496,7 @@ TEST_F(PipelineIntegrationTest, |
| MediaSource_ConfigChange_EncryptedThenClear_WebM) { |
| MockMediaSource source("bear-320x240-16x9-aspect-av-enc_av.webm", kWebM, |
| kAppendWholeFile); |
| - FakeEncryptedMedia encrypted_media; |
| + FakeEncryptedMedia encrypted_media(new KeyProvidingApp()); |
| StartPipelineWithEncryptedMedia(&source, &encrypted_media); |
| scoped_refptr<DecoderBuffer> second_file = |
| @@ -476,7 +554,23 @@ TEST_F(PipelineIntegrationTest, BasicPlayback_16x9AspectRatio) { |
| TEST_F(PipelineIntegrationTest, EncryptedPlayback) { |
| MockMediaSource source("bear-320x240-encrypted.webm", kWebM, 219816); |
| - FakeEncryptedMedia encrypted_media; |
| + FakeEncryptedMedia encrypted_media(new KeyProvidingApp()); |
| + StartPipelineWithEncryptedMedia(&source, &encrypted_media); |
| + |
| + source.EndOfStream(); |
| + ASSERT_EQ(PIPELINE_OK, pipeline_status_); |
| + |
| + Play(); |
| + |
| + ASSERT_TRUE(WaitUntilOnEnded()); |
| + source.Abort(); |
| + Stop(); |
| +} |
| + |
| +TEST_F(PipelineIntegrationTest, EncryptedPlayback_NoEncryptedFrames) { |
| + MockMediaSource source("bear-320x240-av-enc_av_un-all.webm", |
| + kWebM, kAppendWholeFile); |
| + FakeEncryptedMedia encrypted_media(new NoResponseApp()); |
| StartPipelineWithEncryptedMedia(&source, &encrypted_media); |
| source.EndOfStream(); |