| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/filters/pipeline_integration_test_base.h" | 5 #include "media/filters/pipeline_integration_test_base.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 public: | 112 public: |
| 113 // Defines the behavior of the "app" that responds to EME events. | 113 // Defines the behavior of the "app" that responds to EME events. |
| 114 class AppBase { | 114 class AppBase { |
| 115 public: | 115 public: |
| 116 virtual ~AppBase() {} | 116 virtual ~AppBase() {} |
| 117 | 117 |
| 118 virtual void OnSessionMessage(const std::string& web_session_id, | 118 virtual void OnSessionMessage(const std::string& web_session_id, |
| 119 const std::vector<uint8>& message, | 119 const std::vector<uint8>& message, |
| 120 const GURL& destination_url) = 0; | 120 const GURL& destination_url) = 0; |
| 121 | 121 |
| 122 virtual void OnSessionReady(const std::string& web_session_id) = 0; | 122 virtual void OnSessionClosed(const std::string& web_session_id) = 0; |
| 123 | 123 |
| 124 virtual void OnSessionClosed(const std::string& web_session_id) = 0; | 124 virtual void OnSessionKeysChange(const std::string& web_session_id, |
| 125 bool has_additional_usable_key) = 0; |
| 125 | 126 |
| 126 // Errors are not expected unless overridden. | 127 // Errors are not expected unless overridden. |
| 127 virtual void OnSessionError(const std::string& web_session_id, | 128 virtual void OnSessionError(const std::string& web_session_id, |
| 128 const std::string& error_name, | 129 const std::string& error_name, |
| 129 uint32 system_code, | 130 uint32 system_code, |
| 130 const std::string& error_message) { | 131 const std::string& error_message) { |
| 131 FAIL() << "Unexpected Key Error"; | 132 FAIL() << "Unexpected Key Error"; |
| 132 } | 133 } |
| 133 | 134 |
| 134 virtual void NeedKey(const std::string& type, | 135 virtual void NeedKey(const std::string& type, |
| 135 const std::vector<uint8>& init_data, | 136 const std::vector<uint8>& init_data, |
| 136 AesDecryptor* decryptor) = 0; | 137 AesDecryptor* decryptor) = 0; |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 FakeEncryptedMedia(AppBase* app) | 140 FakeEncryptedMedia(AppBase* app) |
| 140 : decryptor_(base::Bind(&FakeEncryptedMedia::OnSessionMessage, | 141 : decryptor_(base::Bind(&FakeEncryptedMedia::OnSessionMessage, |
| 141 base::Unretained(this)), | 142 base::Unretained(this)), |
| 142 base::Bind(&FakeEncryptedMedia::OnSessionClosed, | 143 base::Bind(&FakeEncryptedMedia::OnSessionClosed, |
| 144 base::Unretained(this)), |
| 145 base::Bind(&FakeEncryptedMedia::OnSessionKeysChange, |
| 143 base::Unretained(this))), | 146 base::Unretained(this))), |
| 144 app_(app) {} | 147 app_(app) {} |
| 145 | 148 |
| 146 AesDecryptor* decryptor() { | 149 AesDecryptor* decryptor() { |
| 147 return &decryptor_; | 150 return &decryptor_; |
| 148 } | 151 } |
| 149 | 152 |
| 150 // Callbacks for firing session events. Delegate to |app_|. | 153 // Callbacks for firing session events. Delegate to |app_|. |
| 151 void OnSessionMessage(const std::string& web_session_id, | 154 void OnSessionMessage(const std::string& web_session_id, |
| 152 const std::vector<uint8>& message, | 155 const std::vector<uint8>& message, |
| 153 const GURL& destination_url) { | 156 const GURL& destination_url) { |
| 154 app_->OnSessionMessage(web_session_id, message, destination_url); | 157 app_->OnSessionMessage(web_session_id, message, destination_url); |
| 155 } | 158 } |
| 156 | 159 |
| 157 void OnSessionReady(const std::string& web_session_id) { | |
| 158 app_->OnSessionReady(web_session_id); | |
| 159 } | |
| 160 | |
| 161 void OnSessionClosed(const std::string& web_session_id) { | 160 void OnSessionClosed(const std::string& web_session_id) { |
| 162 app_->OnSessionClosed(web_session_id); | 161 app_->OnSessionClosed(web_session_id); |
| 163 } | 162 } |
| 164 | 163 |
| 164 void OnSessionKeysChange(const std::string& web_session_id, |
| 165 bool has_additional_usable_key) { |
| 166 app_->OnSessionKeysChange(web_session_id, has_additional_usable_key); |
| 167 } |
| 168 |
| 165 void OnSessionError(const std::string& web_session_id, | 169 void OnSessionError(const std::string& web_session_id, |
| 166 const std::string& error_name, | 170 const std::string& error_name, |
| 167 uint32 system_code, | 171 uint32 system_code, |
| 168 const std::string& error_message) { | 172 const std::string& error_message) { |
| 169 app_->OnSessionError( | 173 app_->OnSessionError( |
| 170 web_session_id, error_name, system_code, error_message); | 174 web_session_id, error_name, system_code, error_message); |
| 171 } | 175 } |
| 172 | 176 |
| 173 void NeedKey(const std::string& type, | 177 void NeedKey(const std::string& type, |
| 174 const std::vector<uint8>& init_data) { | 178 const std::vector<uint8>& init_data) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 231 } |
| 228 | 232 |
| 229 virtual void OnSessionMessage(const std::string& web_session_id, | 233 virtual void OnSessionMessage(const std::string& web_session_id, |
| 230 const std::vector<uint8>& message, | 234 const std::vector<uint8>& message, |
| 231 const GURL& destination_url) OVERRIDE { | 235 const GURL& destination_url) OVERRIDE { |
| 232 EXPECT_FALSE(web_session_id.empty()); | 236 EXPECT_FALSE(web_session_id.empty()); |
| 233 EXPECT_FALSE(message.empty()); | 237 EXPECT_FALSE(message.empty()); |
| 234 EXPECT_EQ(current_session_id_, web_session_id); | 238 EXPECT_EQ(current_session_id_, web_session_id); |
| 235 } | 239 } |
| 236 | 240 |
| 237 virtual void OnSessionReady(const std::string& web_session_id) OVERRIDE { | |
| 238 EXPECT_EQ(current_session_id_, web_session_id); | |
| 239 } | |
| 240 | |
| 241 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { | 241 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { |
| 242 EXPECT_EQ(current_session_id_, web_session_id); | 242 EXPECT_EQ(current_session_id_, web_session_id); |
| 243 } | 243 } |
| 244 | 244 |
| 245 virtual void OnSessionKeysChange(const std::string& web_session_id, |
| 246 bool has_additional_usable_key) OVERRIDE { |
| 247 EXPECT_EQ(current_session_id_, web_session_id); |
| 248 EXPECT_EQ(has_additional_usable_key, true); |
| 249 } |
| 250 |
| 245 virtual void NeedKey(const std::string& type, | 251 virtual void NeedKey(const std::string& type, |
| 246 const std::vector<uint8>& init_data, | 252 const std::vector<uint8>& init_data, |
| 247 AesDecryptor* decryptor) OVERRIDE { | 253 AesDecryptor* decryptor) OVERRIDE { |
| 248 if (current_session_id_.empty()) { | 254 if (current_session_id_.empty()) { |
| 249 decryptor->CreateSession(type, | 255 decryptor->CreateSession(type, |
| 250 kInitData, | 256 kInitData, |
| 251 arraysize(kInitData), | 257 arraysize(kInitData), |
| 252 MediaKeys::TEMPORARY_SESSION, | 258 MediaKeys::TEMPORARY_SESSION, |
| 253 CreateSessionPromise(RESOLVED)); | 259 CreateSessionPromise(RESOLVED)); |
| 254 EXPECT_FALSE(current_session_id_.empty()); | 260 EXPECT_FALSE(current_session_id_.empty()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 class NoResponseApp : public FakeEncryptedMedia::AppBase { | 358 class NoResponseApp : public FakeEncryptedMedia::AppBase { |
| 353 public: | 359 public: |
| 354 virtual void OnSessionMessage(const std::string& web_session_id, | 360 virtual void OnSessionMessage(const std::string& web_session_id, |
| 355 const std::vector<uint8>& message, | 361 const std::vector<uint8>& message, |
| 356 const GURL& default_url) OVERRIDE { | 362 const GURL& default_url) OVERRIDE { |
| 357 EXPECT_FALSE(web_session_id.empty()); | 363 EXPECT_FALSE(web_session_id.empty()); |
| 358 EXPECT_FALSE(message.empty()); | 364 EXPECT_FALSE(message.empty()); |
| 359 FAIL() << "Unexpected Message"; | 365 FAIL() << "Unexpected Message"; |
| 360 } | 366 } |
| 361 | 367 |
| 362 virtual void OnSessionReady(const std::string& web_session_id) OVERRIDE { | |
| 363 EXPECT_FALSE(web_session_id.empty()); | |
| 364 FAIL() << "Unexpected Ready"; | |
| 365 } | |
| 366 | |
| 367 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { | 368 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { |
| 368 EXPECT_FALSE(web_session_id.empty()); | 369 EXPECT_FALSE(web_session_id.empty()); |
| 369 FAIL() << "Unexpected Closed"; | 370 FAIL() << "Unexpected Closed"; |
| 370 } | 371 } |
| 371 | 372 |
| 373 virtual void OnSessionKeysChange(const std::string& web_session_id, |
| 374 bool has_additional_usable_key) OVERRIDE { |
| 375 EXPECT_FALSE(web_session_id.empty()); |
| 376 EXPECT_EQ(has_additional_usable_key, true); |
| 377 } |
| 378 |
| 372 virtual void NeedKey(const std::string& type, | 379 virtual void NeedKey(const std::string& type, |
| 373 const std::vector<uint8>& init_data, | 380 const std::vector<uint8>& init_data, |
| 374 AesDecryptor* decryptor) OVERRIDE { | 381 AesDecryptor* decryptor) OVERRIDE { |
| 375 } | 382 } |
| 376 }; | 383 }; |
| 377 | 384 |
| 378 // Helper class that emulates calls made on the ChunkDemuxer by the | 385 // Helper class that emulates calls made on the ChunkDemuxer by the |
| 379 // Media Source API. | 386 // Media Source API. |
| 380 class MockMediaSource { | 387 class MockMediaSource { |
| 381 public: | 388 public: |
| (...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1578 ASSERT_TRUE(Start(GetTestDataFilePath("bear_audio_shorter_than_video.ogv"), | 1585 ASSERT_TRUE(Start(GetTestDataFilePath("bear_audio_shorter_than_video.ogv"), |
| 1579 PIPELINE_OK)); | 1586 PIPELINE_OK)); |
| 1580 // Audio track is 500ms. Video track is 1001ms. Duration should be higher of | 1587 // Audio track is 500ms. Video track is 1001ms. Duration should be higher of |
| 1581 // the two. | 1588 // the two. |
| 1582 EXPECT_EQ(1001, pipeline_->GetMediaDuration().InMilliseconds()); | 1589 EXPECT_EQ(1001, pipeline_->GetMediaDuration().InMilliseconds()); |
| 1583 Play(); | 1590 Play(); |
| 1584 ASSERT_TRUE(WaitUntilOnEnded()); | 1591 ASSERT_TRUE(WaitUntilOnEnded()); |
| 1585 } | 1592 } |
| 1586 | 1593 |
| 1587 } // namespace media | 1594 } // namespace media |
| OLD | NEW |