| 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" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "media/base/decoder_buffer.h" | 12 #include "media/base/decoder_buffer.h" |
| 13 #include "media/base/media_keys.h" | 13 #include "media/base/media_keys.h" |
| 14 #include "media/base/media_keys_session_promise.h" |
| 14 #include "media/base/media_switches.h" | 15 #include "media/base/media_switches.h" |
| 15 #include "media/base/test_data_util.h" | 16 #include "media/base/test_data_util.h" |
| 16 #include "media/cdm/aes_decryptor.h" | 17 #include "media/cdm/aes_decryptor.h" |
| 17 #include "media/cdm/json_web_key.h" | 18 #include "media/cdm/json_web_key.h" |
| 18 #include "media/filters/chunk_demuxer.h" | 19 #include "media/filters/chunk_demuxer.h" |
| 19 | 20 |
| 20 using testing::_; | 21 using testing::_; |
| 21 using testing::AnyNumber; | 22 using testing::AnyNumber; |
| 22 using testing::AtMost; | 23 using testing::AtMost; |
| 23 using testing::SaveArg; | 24 using testing::SaveArg; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 108 |
| 108 // Note: Tests using this class only exercise the DecryptingDemuxerStream path. | 109 // Note: Tests using this class only exercise the DecryptingDemuxerStream path. |
| 109 // They do not exercise the Decrypting{Audio|Video}Decoder path. | 110 // They do not exercise the Decrypting{Audio|Video}Decoder path. |
| 110 class FakeEncryptedMedia { | 111 class FakeEncryptedMedia { |
| 111 public: | 112 public: |
| 112 // Defines the behavior of the "app" that responds to EME events. | 113 // Defines the behavior of the "app" that responds to EME events. |
| 113 class AppBase { | 114 class AppBase { |
| 114 public: | 115 public: |
| 115 virtual ~AppBase() {} | 116 virtual ~AppBase() {} |
| 116 | 117 |
| 117 virtual void OnSessionCreated(uint32 session_id, | 118 virtual void OnSessionMessage(const std::string& web_session_id, |
| 118 const std::string& web_session_id) = 0; | |
| 119 | |
| 120 virtual void OnSessionMessage(uint32 session_id, | |
| 121 const std::vector<uint8>& message, | 119 const std::vector<uint8>& message, |
| 122 const std::string& destination_url) = 0; | 120 const std::string& destination_url) = 0; |
| 123 | 121 |
| 124 virtual void OnSessionReady(uint32 session_id) = 0; | 122 virtual void OnSessionReady(const std::string& web_session_id) = 0; |
| 125 | 123 |
| 126 virtual void OnSessionClosed(uint32 session_id) = 0; | 124 virtual void OnSessionClosed(const std::string& web_session_id) = 0; |
| 127 | 125 |
| 128 // Errors are not expected unless overridden. | 126 // Errors are not expected unless overridden. |
| 129 virtual void OnSessionError(uint32 session_id, | 127 virtual void OnSessionError(const std::string& web_session_id, |
| 130 MediaKeys::KeyError error_code, | 128 const std::string& error_name, |
| 131 uint32 system_code) { | 129 uint32 system_code, |
| 130 const std::string& error_message) { |
| 132 FAIL() << "Unexpected Key Error"; | 131 FAIL() << "Unexpected Key Error"; |
| 133 } | 132 } |
| 134 | 133 |
| 135 virtual void NeedKey(const std::string& type, | 134 virtual void NeedKey(const std::string& type, |
| 136 const std::vector<uint8>& init_data, | 135 const std::vector<uint8>& init_data, |
| 137 AesDecryptor* decryptor) = 0; | 136 AesDecryptor* decryptor) = 0; |
| 138 }; | 137 }; |
| 139 | 138 |
| 140 FakeEncryptedMedia(AppBase* app) | 139 FakeEncryptedMedia(AppBase* app) |
| 141 : decryptor_(base::Bind(&FakeEncryptedMedia::OnSessionCreated, | 140 : decryptor_(base::Bind(&FakeEncryptedMedia::OnSessionMessage, |
| 142 base::Unretained(this)), | |
| 143 base::Bind(&FakeEncryptedMedia::OnSessionMessage, | |
| 144 base::Unretained(this)), | |
| 145 base::Bind(&FakeEncryptedMedia::OnSessionReady, | |
| 146 base::Unretained(this)), | |
| 147 base::Bind(&FakeEncryptedMedia::OnSessionClosed, | |
| 148 base::Unretained(this)), | |
| 149 base::Bind(&FakeEncryptedMedia::OnSessionError, | |
| 150 base::Unretained(this))), | 141 base::Unretained(this))), |
| 151 app_(app) {} | 142 app_(app) {} |
| 152 | 143 |
| 153 AesDecryptor* decryptor() { | 144 AesDecryptor* decryptor() { |
| 154 return &decryptor_; | 145 return &decryptor_; |
| 155 } | 146 } |
| 156 | 147 |
| 157 // Callbacks for firing session events. Delegate to |app_|. | 148 // Callbacks for firing session events. Delegate to |app_|. |
| 158 void OnSessionCreated(uint32 session_id, const std::string& web_session_id) { | 149 void OnSessionMessage(const std::string& web_session_id, |
| 159 app_->OnSessionCreated(session_id, web_session_id); | 150 const std::vector<uint8>& message, |
| 151 const std::string& destination_url) { |
| 152 app_->OnSessionMessage(web_session_id, message, destination_url); |
| 160 } | 153 } |
| 161 | 154 |
| 162 void OnSessionMessage(uint32 session_id, | 155 void OnSessionReady(const std::string& web_session_id) { |
| 163 const std::vector<uint8>& message, | 156 app_->OnSessionReady(web_session_id); |
| 164 const std::string& destination_url) { | |
| 165 app_->OnSessionMessage(session_id, message, destination_url); | |
| 166 } | 157 } |
| 167 | 158 |
| 168 void OnSessionReady(uint32 session_id) { | 159 void OnSessionClosed(const std::string& web_session_id) { |
| 169 app_->OnSessionReady(session_id); | 160 app_->OnSessionClosed(web_session_id); |
| 170 } | 161 } |
| 171 | 162 |
| 172 void OnSessionClosed(uint32 session_id) { | 163 void OnSessionError(const std::string& web_session_id, |
| 173 app_->OnSessionClosed(session_id); | 164 const std::string& error_name, |
| 174 } | 165 uint32 system_code, |
| 175 | 166 const std::string& error_message) { |
| 176 void OnSessionError(uint32 session_id, | 167 app_->OnSessionError( |
| 177 MediaKeys::KeyError error_code, | 168 web_session_id, error_name, system_code, error_message); |
| 178 uint32 system_code) { | |
| 179 app_->OnSessionError(session_id, error_code, system_code); | |
| 180 } | 169 } |
| 181 | 170 |
| 182 void NeedKey(const std::string& type, | 171 void NeedKey(const std::string& type, |
| 183 const std::vector<uint8>& init_data) { | 172 const std::vector<uint8>& init_data) { |
| 184 app_->NeedKey(type, init_data, &decryptor_); | 173 app_->NeedKey(type, init_data, &decryptor_); |
| 185 } | 174 } |
| 186 | 175 |
| 187 private: | 176 private: |
| 188 AesDecryptor decryptor_; | 177 AesDecryptor decryptor_; |
| 189 scoped_ptr<AppBase> app_; | 178 scoped_ptr<AppBase> app_; |
| 190 }; | 179 }; |
| 191 | 180 |
| 181 enum PromiseResult { RESOLVED, RESOLVED_WITH_SESSION, REJECTED }; |
| 182 |
| 192 // Provides |kSecretKey| in response to needkey. | 183 // Provides |kSecretKey| in response to needkey. |
| 193 class KeyProvidingApp : public FakeEncryptedMedia::AppBase { | 184 class KeyProvidingApp : public FakeEncryptedMedia::AppBase { |
| 194 public: | 185 public: |
| 195 KeyProvidingApp() : current_session_id_(0) {} | 186 KeyProvidingApp() {} |
| 196 | 187 |
| 197 virtual void OnSessionCreated(uint32 session_id, | 188 void OnResolveWithSession(PromiseResult expected, |
| 198 const std::string& web_session_id) OVERRIDE { | 189 const std::string& web_session_id) { |
| 199 EXPECT_GT(session_id, 0u); | 190 EXPECT_EQ(expected, RESOLVED_WITH_SESSION); |
| 200 EXPECT_FALSE(web_session_id.empty()); | 191 EXPECT_GT(web_session_id.length(), 0ul); |
| 192 current_session_id_ = web_session_id; |
| 201 } | 193 } |
| 202 | 194 |
| 203 virtual void OnSessionMessage(uint32 session_id, | 195 void OnResolve(PromiseResult expected) { |
| 204 const std::vector<uint8>& message, | 196 EXPECT_EQ(expected, RESOLVED); |
| 205 const std::string& default_url) OVERRIDE { | |
| 206 EXPECT_GT(session_id, 0u); | |
| 207 EXPECT_FALSE(message.empty()); | |
| 208 | |
| 209 current_session_id_ = session_id; | |
| 210 } | 197 } |
| 211 | 198 |
| 212 virtual void OnSessionReady(uint32 session_id) OVERRIDE { | 199 void OnReject(PromiseResult expected, |
| 213 EXPECT_GT(session_id, 0u); | 200 const std::string& error_name, |
| 201 uint32 system_code, |
| 202 const std::string& error_message) { |
| 203 EXPECT_EQ(expected, REJECTED); |
| 214 } | 204 } |
| 215 | 205 |
| 216 virtual void OnSessionClosed(uint32 session_id) OVERRIDE { | 206 scoped_ptr<MediaKeysSessionPromise> CreatePromise(PromiseResult expected) { |
| 217 EXPECT_GT(session_id, 0u); | 207 scoped_ptr<media::MediaKeysSessionPromise> promise( |
| 208 new media::MediaKeysSessionPromise( |
| 209 base::Bind(&KeyProvidingApp::OnResolve, |
| 210 base::Unretained(this), |
| 211 expected), |
| 212 base::Bind(&KeyProvidingApp::OnResolveWithSession, |
| 213 base::Unretained(this), |
| 214 expected), |
| 215 base::Bind(&KeyProvidingApp::OnReject, |
| 216 base::Unretained(this), |
| 217 expected))); |
| 218 return promise.Pass(); |
| 219 } |
| 220 |
| 221 virtual void OnSessionMessage(const std::string& web_session_id, |
| 222 const std::vector<uint8>& message, |
| 223 const std::string& destination_url) OVERRIDE { |
| 224 EXPECT_FALSE(web_session_id.empty()); |
| 225 EXPECT_FALSE(message.empty()); |
| 226 EXPECT_EQ(current_session_id_, web_session_id); |
| 227 } |
| 228 |
| 229 virtual void OnSessionReady(const std::string& web_session_id) OVERRIDE { |
| 230 EXPECT_EQ(current_session_id_, web_session_id); |
| 231 } |
| 232 |
| 233 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { |
| 234 EXPECT_EQ(current_session_id_, web_session_id); |
| 218 } | 235 } |
| 219 | 236 |
| 220 virtual void NeedKey(const std::string& type, | 237 virtual void NeedKey(const std::string& type, |
| 221 const std::vector<uint8>& init_data, | 238 const std::vector<uint8>& init_data, |
| 222 AesDecryptor* decryptor) OVERRIDE { | 239 AesDecryptor* decryptor) OVERRIDE { |
| 223 if (current_session_id_ == 0u) { | 240 if (current_session_id_.empty()) { |
| 224 EXPECT_TRUE( | 241 decryptor->CreateSession(type, |
| 225 decryptor->CreateSession(12, type, kInitData, arraysize(kInitData))); | 242 kInitData, |
| 243 arraysize(kInitData), |
| 244 MediaKeys::SessionType::kTemporary, |
| 245 CreatePromise(RESOLVED_WITH_SESSION)); |
| 246 EXPECT_FALSE(current_session_id_.empty()); |
| 226 } | 247 } |
| 227 | 248 |
| 228 EXPECT_EQ(current_session_id_, 12u); | |
| 229 | |
| 230 // Clear Key really needs the key ID in |init_data|. For WebM, they are the | 249 // Clear Key really needs the key ID in |init_data|. For WebM, they are the |
| 231 // same, but this is not the case for ISO CENC. Therefore, provide the | 250 // same, but this is not the case for ISO CENC. Therefore, provide the |
| 232 // correct key ID. | 251 // correct key ID. |
| 233 const uint8* key_id = init_data.empty() ? NULL : &init_data[0]; | 252 const uint8* key_id = init_data.empty() ? NULL : &init_data[0]; |
| 234 size_t key_id_length = init_data.size(); | 253 size_t key_id_length = init_data.size(); |
| 235 if (type == kMP4AudioType || type == kMP4VideoType) { | 254 if (type == kMP4AudioType || type == kMP4VideoType) { |
| 236 key_id = kKeyId; | 255 key_id = kKeyId; |
| 237 key_id_length = arraysize(kKeyId); | 256 key_id_length = arraysize(kKeyId); |
| 238 } | 257 } |
| 239 | 258 |
| 240 // Convert key into a JSON structure and then add it. | 259 // Convert key into a JSON structure and then add it. |
| 241 std::string jwk = GenerateJWKSet( | 260 std::string jwk = GenerateJWKSet( |
| 242 kSecretKey, arraysize(kSecretKey), key_id, key_id_length); | 261 kSecretKey, arraysize(kSecretKey), key_id, key_id_length); |
| 243 decryptor->UpdateSession(current_session_id_, | 262 decryptor->UpdateSession(current_session_id_, |
| 244 reinterpret_cast<const uint8*>(jwk.data()), | 263 reinterpret_cast<const uint8*>(jwk.data()), |
| 245 jwk.size()); | 264 jwk.size(), |
| 265 CreatePromise(RESOLVED)); |
| 246 } | 266 } |
| 247 | 267 |
| 248 uint32 current_session_id_; | 268 std::string current_session_id_; |
| 249 }; | 269 }; |
| 250 | 270 |
| 251 // Ignores needkey and does not perform a license request | 271 // Ignores needkey and does not perform a license request |
| 252 class NoResponseApp : public FakeEncryptedMedia::AppBase { | 272 class NoResponseApp : public FakeEncryptedMedia::AppBase { |
| 253 public: | 273 public: |
| 254 virtual void OnSessionCreated(uint32 session_id, | 274 virtual void OnSessionMessage(const std::string& web_session_id, |
| 255 const std::string& web_session_id) OVERRIDE { | 275 const std::vector<uint8>& message, |
| 256 EXPECT_GT(session_id, 0u); | 276 const std::string& destination_url) OVERRIDE { |
| 257 EXPECT_FALSE(web_session_id.empty()); | 277 EXPECT_FALSE(web_session_id.empty()); |
| 278 EXPECT_FALSE(message.empty()); |
| 279 FAIL() << "Unexpected Message"; |
| 258 } | 280 } |
| 259 | 281 |
| 260 virtual void OnSessionMessage(uint32 session_id, | 282 virtual void OnSessionReady(const std::string& web_session_id) OVERRIDE { |
| 261 const std::vector<uint8>& message, | 283 EXPECT_FALSE(web_session_id.empty()); |
| 262 const std::string& default_url) OVERRIDE { | |
| 263 EXPECT_GT(session_id, 0u); | |
| 264 EXPECT_FALSE(message.empty()); | |
| 265 FAIL() << "Unexpected KeyMessage"; | |
| 266 } | |
| 267 | |
| 268 virtual void OnSessionReady(uint32 session_id) OVERRIDE { | |
| 269 EXPECT_GT(session_id, 0u); | |
| 270 FAIL() << "Unexpected Ready"; | 284 FAIL() << "Unexpected Ready"; |
| 271 } | 285 } |
| 272 | 286 |
| 273 virtual void OnSessionClosed(uint32 session_id) OVERRIDE { | 287 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { |
| 274 EXPECT_GT(session_id, 0u); | 288 EXPECT_FALSE(web_session_id.empty()); |
| 275 FAIL() << "Unexpected Closed"; | 289 FAIL() << "Unexpected Closed"; |
| 276 } | 290 } |
| 277 | 291 |
| 278 virtual void NeedKey(const std::string& type, | 292 virtual void NeedKey(const std::string& type, |
| 279 const std::vector<uint8>& init_data, | 293 const std::vector<uint8>& init_data, |
| 280 AesDecryptor* decryptor) OVERRIDE { | 294 AesDecryptor* decryptor) OVERRIDE { |
| 281 } | 295 } |
| 282 }; | 296 }; |
| 283 | 297 |
| 284 // Helper class that emulates calls made on the ChunkDemuxer by the | 298 // Helper class that emulates calls made on the ChunkDemuxer by the |
| (...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 Play(); | 1296 Play(); |
| 1283 ASSERT_TRUE(WaitUntilOnEnded()); | 1297 ASSERT_TRUE(WaitUntilOnEnded()); |
| 1284 } | 1298 } |
| 1285 | 1299 |
| 1286 // TODO(wolenetz): Enable MSE testing of new frame processor based on this flag, | 1300 // TODO(wolenetz): Enable MSE testing of new frame processor based on this flag, |
| 1287 // once the new processor has landed. See http://crbug.com/249422. | 1301 // once the new processor has landed. See http://crbug.com/249422. |
| 1288 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, PipelineIntegrationTest, | 1302 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, PipelineIntegrationTest, |
| 1289 Values(true)); | 1303 Values(true)); |
| 1290 | 1304 |
| 1291 } // namespace media | 1305 } // namespace media |
| OLD | NEW |