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 088d991cac98b4bfb44b777271028cee039184e0..69b1963ffff6eb9d9a9f5d03d63e5e2eef91bd8f 100644 | 
| --- a/media/filters/pipeline_integration_test.cc | 
| +++ b/media/filters/pipeline_integration_test.cc | 
| @@ -7,7 +7,6 @@ | 
| #include "base/bind.h" | 
| #include "base/string_util.h" | 
| #include "media/base/decoder_buffer.h" | 
| -#include "media/base/decryptor_client.h" | 
| #include "media/base/test_data_util.h" | 
| #include "media/crypto/aes_decryptor.h" | 
| @@ -32,6 +31,76 @@ static const uint8 kSecretKey[] = { | 
| static const int kAppendWholeFile = -1; | 
| +class FakeEncryptedMedia { | 
| 
 
xhwang
2012/12/20 00:06:01
moved from old code, renamed, and removed "virtual
 
 | 
| + public: | 
| + FakeEncryptedMedia() | 
| + : decryptor_(base::Bind(&FakeEncryptedMedia::KeyAdded, | 
| + base::Unretained(this)), | 
| + base::Bind(&FakeEncryptedMedia::KeyError, | 
| + base::Unretained(this)), | 
| + base::Bind(&FakeEncryptedMedia::KeyMessage, | 
| + base::Unretained(this)), | 
| + base::Bind(&FakeEncryptedMedia::NeedKey, | 
| + base::Unretained(this))) { | 
| + } | 
| + | 
| + AesDecryptor* decryptor() { | 
| + return &decryptor_; | 
| + } | 
| + | 
| + // DecryptorClient implementation. | 
| 
 
scherkus (not reviewing)
2012/12/20 15:18:55
class doesn't exist anymore
 
xhwang
2012/12/20 18:06:31
Done.
 
 | 
| + void KeyAdded(const std::string& key_system, const std::string& session_id) { | 
| + EXPECT_EQ(kClearKeySystem, key_system); | 
| + EXPECT_FALSE(session_id.empty()); | 
| + } | 
| + | 
| + void KeyError(const std::string& key_system, | 
| + const std::string& session_id, | 
| + AesDecryptor::KeyError error_code, | 
| + int system_code) { | 
| + NOTIMPLEMENTED(); | 
| + } | 
| + | 
| + 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()); | 
| + | 
| + current_key_system_ = key_system; | 
| + current_session_id_ = session_id; | 
| + } | 
| + | 
| + 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) { | 
| + current_key_system_ = key_system; | 
| + current_session_id_ = session_id; | 
| + | 
| + // When NeedKey is called from the demuxer, the |key_system| will be empty. | 
| + // In this case, we need to call GenerateKeyRequest() to initialize a | 
| + // session (which will call KeyMessage). | 
| + if (current_key_system_.empty()) { | 
| + DCHECK(current_session_id_.empty()); | 
| + 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), | 
| + init_data.get(), init_data_length, current_session_id_); | 
| + } | 
| + | 
| + private: | 
| + AesDecryptor decryptor_; | 
| + std::string current_key_system_; | 
| + std::string current_session_id_; | 
| +}; | 
| + | 
| // Helper class that emulates calls made on the ChunkDemuxer by the | 
| // Media Source API. | 
| class MockMediaSource { | 
| @@ -59,8 +128,8 @@ class MockMediaSource { | 
| virtual ~MockMediaSource() {} | 
| const scoped_refptr<ChunkDemuxer>& demuxer() const { return chunk_demuxer_; } | 
| - void set_decryptor_client(DecryptorClient* decryptor_client) { | 
| - decryptor_client_ = decryptor_client; | 
| + void set_encrypted_media(FakeEncryptedMedia* encrypted_media) { | 
| + encrypted_media_ = encrypted_media; | 
| } | 
| void Seek(int new_position, int seek_append_size) { | 
| @@ -125,8 +194,8 @@ class MockMediaSource { | 
| scoped_array<uint8> init_data, int init_data_size) { | 
| DCHECK(init_data.get()); | 
| DCHECK_GT(init_data_size, 0); | 
| - DCHECK(decryptor_client_); | 
| - decryptor_client_->NeedKey("", "", type, init_data.Pass(), init_data_size); | 
| + DCHECK(encrypted_media_); | 
| + encrypted_media_->NeedKey("", "", type, init_data.Pass(), init_data_size); | 
| 
 
scherkus (not reviewing)
2012/12/20 15:18:55
nit: this pointer could get replaced with a NeedKe
 
xhwang
2012/12/20 18:06:31
Done.
 
 | 
| } | 
| private: | 
| @@ -136,70 +205,7 @@ class MockMediaSource { | 
| int initial_append_size_; | 
| std::string mimetype_; | 
| scoped_refptr<ChunkDemuxer> chunk_demuxer_; | 
| - DecryptorClient* decryptor_client_; | 
| -}; | 
| - | 
| -class FakeDecryptorClient : public DecryptorClient { | 
| - public: | 
| - FakeDecryptorClient() : decryptor_(this) {} | 
| - | 
| - AesDecryptor* decryptor() { | 
| - return &decryptor_; | 
| - } | 
| - | 
| - // DecryptorClient implementation. | 
| - virtual void KeyAdded(const std::string& key_system, | 
| - const std::string& session_id) { | 
| - EXPECT_EQ(kClearKeySystem, key_system); | 
| - EXPECT_FALSE(session_id.empty()); | 
| - } | 
| - | 
| - virtual void KeyError(const std::string& key_system, | 
| - const std::string& session_id, | 
| - AesDecryptor::KeyError error_code, | 
| - int system_code) { | 
| - NOTIMPLEMENTED(); | 
| - } | 
| - | 
| - 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()); | 
| - | 
| - current_key_system_ = key_system; | 
| - current_session_id_ = session_id; | 
| - } | 
| - | 
| - 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) { | 
| - current_key_system_ = key_system; | 
| - current_session_id_ = session_id; | 
| - | 
| - // When NeedKey is called from the demuxer, the |key_system| will be empty. | 
| - // In this case, we need to call GenerateKeyRequest() to initialize a | 
| - // session (which will call KeyMessage). | 
| - if (current_key_system_.empty()) { | 
| - DCHECK(current_session_id_.empty()); | 
| - 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), | 
| - init_data.get(), init_data_length, current_session_id_); | 
| - } | 
| - | 
| - private: | 
| - AesDecryptor decryptor_; | 
| - std::string current_key_system_; | 
| - std::string current_session_id_; | 
| + FakeEncryptedMedia* encrypted_media_; | 
| }; | 
| class PipelineIntegrationTest | 
| @@ -224,7 +230,7 @@ class PipelineIntegrationTest | 
| void StartPipelineWithEncryptedMedia( | 
| MockMediaSource* source, | 
| - FakeDecryptorClient* encrypted_media) { | 
| + FakeEncryptedMedia* encrypted_media) { | 
| EXPECT_CALL(*this, OnBufferingState(Pipeline::kHaveMetadata)) | 
| .Times(AtMost(1)); | 
| EXPECT_CALL(*this, OnBufferingState(Pipeline::kPrerollCompleted)) | 
| @@ -237,7 +243,7 @@ class PipelineIntegrationTest | 
| base::Bind(&PipelineIntegrationTest::OnBufferingState, | 
| base::Unretained(this))); | 
| - source->set_decryptor_client(encrypted_media); | 
| + source->set_encrypted_media(encrypted_media); | 
| message_loop_.Run(); | 
| } | 
| @@ -274,7 +280,6 @@ class PipelineIntegrationTest | 
| } | 
| }; | 
| - | 
| TEST_F(PipelineIntegrationTest, BasicPlayback) { | 
| ASSERT_TRUE(Start(GetTestDataFilePath("bear-320x240.webm"), PIPELINE_OK)); | 
| @@ -372,7 +377,7 @@ TEST_F(PipelineIntegrationTest, BasicPlayback_16x9AspectRatio) { | 
| TEST_F(PipelineIntegrationTest, EncryptedPlayback) { | 
| MockMediaSource source("bear-320x240-encrypted.webm", kWebM, 219816); | 
| - FakeDecryptorClient encrypted_media; | 
| + FakeEncryptedMedia encrypted_media; | 
| StartPipelineWithEncryptedMedia(&source, &encrypted_media); | 
| source.EndOfStream(); |