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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 public: | 114 public: |
115 // Defines the behavior of the "app" that responds to EME events. | 115 // Defines the behavior of the "app" that responds to EME events. |
116 class AppBase { | 116 class AppBase { |
117 public: | 117 public: |
118 virtual ~AppBase() {} | 118 virtual ~AppBase() {} |
119 | 119 |
120 virtual void OnSessionMessage(const std::string& web_session_id, | 120 virtual void OnSessionMessage(const std::string& web_session_id, |
121 const std::vector<uint8>& message, | 121 const std::vector<uint8>& message, |
122 const GURL& destination_url) = 0; | 122 const GURL& destination_url) = 0; |
123 | 123 |
124 virtual void OnSessionReady(const std::string& web_session_id) = 0; | 124 virtual void OnSessionClosed(const std::string& web_session_id) = 0; |
125 | 125 |
126 virtual void OnSessionClosed(const std::string& web_session_id) = 0; | 126 virtual void OnSessionKeysChange(const std::string& web_session_id, |
| 127 bool has_additional_usable_key) = 0; |
127 | 128 |
128 // Errors are not expected unless overridden. | 129 // Errors are not expected unless overridden. |
129 virtual void OnSessionError(const std::string& web_session_id, | 130 virtual void OnSessionError(const std::string& web_session_id, |
130 const std::string& error_name, | 131 const std::string& error_name, |
131 uint32 system_code, | 132 uint32 system_code, |
132 const std::string& error_message) { | 133 const std::string& error_message) { |
133 FAIL() << "Unexpected Key Error"; | 134 FAIL() << "Unexpected Key Error"; |
134 } | 135 } |
135 | 136 |
136 virtual void NeedKey(const std::string& type, | 137 virtual void NeedKey(const std::string& type, |
137 const std::vector<uint8>& init_data, | 138 const std::vector<uint8>& init_data, |
138 AesDecryptor* decryptor) = 0; | 139 AesDecryptor* decryptor) = 0; |
139 }; | 140 }; |
140 | 141 |
141 FakeEncryptedMedia(AppBase* app) | 142 FakeEncryptedMedia(AppBase* app) |
142 : decryptor_(base::Bind(&FakeEncryptedMedia::OnSessionMessage, | 143 : decryptor_(base::Bind(&FakeEncryptedMedia::OnSessionMessage, |
143 base::Unretained(this)), | 144 base::Unretained(this)), |
144 base::Bind(&FakeEncryptedMedia::OnSessionClosed, | 145 base::Bind(&FakeEncryptedMedia::OnSessionClosed, |
| 146 base::Unretained(this)), |
| 147 base::Bind(&FakeEncryptedMedia::OnSessionKeysChange, |
145 base::Unretained(this))), | 148 base::Unretained(this))), |
146 app_(app) {} | 149 app_(app) {} |
147 | 150 |
148 AesDecryptor* decryptor() { | 151 AesDecryptor* decryptor() { |
149 return &decryptor_; | 152 return &decryptor_; |
150 } | 153 } |
151 | 154 |
152 // Callbacks for firing session events. Delegate to |app_|. | 155 // Callbacks for firing session events. Delegate to |app_|. |
153 void OnSessionMessage(const std::string& web_session_id, | 156 void OnSessionMessage(const std::string& web_session_id, |
154 const std::vector<uint8>& message, | 157 const std::vector<uint8>& message, |
155 const GURL& destination_url) { | 158 const GURL& destination_url) { |
156 app_->OnSessionMessage(web_session_id, message, destination_url); | 159 app_->OnSessionMessage(web_session_id, message, destination_url); |
157 } | 160 } |
158 | 161 |
159 void OnSessionReady(const std::string& web_session_id) { | |
160 app_->OnSessionReady(web_session_id); | |
161 } | |
162 | |
163 void OnSessionClosed(const std::string& web_session_id) { | 162 void OnSessionClosed(const std::string& web_session_id) { |
164 app_->OnSessionClosed(web_session_id); | 163 app_->OnSessionClosed(web_session_id); |
165 } | 164 } |
166 | 165 |
| 166 void OnSessionKeysChange(const std::string& web_session_id, |
| 167 bool has_additional_usable_key) { |
| 168 app_->OnSessionKeysChange(web_session_id, has_additional_usable_key); |
| 169 } |
| 170 |
167 void OnSessionError(const std::string& web_session_id, | 171 void OnSessionError(const std::string& web_session_id, |
168 const std::string& error_name, | 172 const std::string& error_name, |
169 uint32 system_code, | 173 uint32 system_code, |
170 const std::string& error_message) { | 174 const std::string& error_message) { |
171 app_->OnSessionError( | 175 app_->OnSessionError( |
172 web_session_id, error_name, system_code, error_message); | 176 web_session_id, error_name, system_code, error_message); |
173 } | 177 } |
174 | 178 |
175 void NeedKey(const std::string& type, | 179 void NeedKey(const std::string& type, |
176 const std::vector<uint8>& init_data) { | 180 const std::vector<uint8>& init_data) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 233 } |
230 | 234 |
231 virtual void OnSessionMessage(const std::string& web_session_id, | 235 virtual void OnSessionMessage(const std::string& web_session_id, |
232 const std::vector<uint8>& message, | 236 const std::vector<uint8>& message, |
233 const GURL& destination_url) OVERRIDE { | 237 const GURL& destination_url) OVERRIDE { |
234 EXPECT_FALSE(web_session_id.empty()); | 238 EXPECT_FALSE(web_session_id.empty()); |
235 EXPECT_FALSE(message.empty()); | 239 EXPECT_FALSE(message.empty()); |
236 EXPECT_EQ(current_session_id_, web_session_id); | 240 EXPECT_EQ(current_session_id_, web_session_id); |
237 } | 241 } |
238 | 242 |
239 virtual void OnSessionReady(const std::string& web_session_id) OVERRIDE { | |
240 EXPECT_EQ(current_session_id_, web_session_id); | |
241 } | |
242 | |
243 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { | 243 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { |
244 EXPECT_EQ(current_session_id_, web_session_id); | 244 EXPECT_EQ(current_session_id_, web_session_id); |
245 } | 245 } |
246 | 246 |
| 247 virtual void OnSessionKeysChange(const std::string& web_session_id, |
| 248 bool has_additional_usable_key) OVERRIDE { |
| 249 EXPECT_EQ(current_session_id_, web_session_id); |
| 250 EXPECT_EQ(has_additional_usable_key, true); |
| 251 } |
| 252 |
247 virtual void NeedKey(const std::string& type, | 253 virtual void NeedKey(const std::string& type, |
248 const std::vector<uint8>& init_data, | 254 const std::vector<uint8>& init_data, |
249 AesDecryptor* decryptor) OVERRIDE { | 255 AesDecryptor* decryptor) OVERRIDE { |
250 if (current_session_id_.empty()) { | 256 if (current_session_id_.empty()) { |
251 decryptor->CreateSession(type, | 257 decryptor->CreateSession(type, |
252 kInitData, | 258 kInitData, |
253 arraysize(kInitData), | 259 arraysize(kInitData), |
254 MediaKeys::TEMPORARY_SESSION, | 260 MediaKeys::TEMPORARY_SESSION, |
255 CreateSessionPromise(RESOLVED)); | 261 CreateSessionPromise(RESOLVED)); |
256 EXPECT_FALSE(current_session_id_.empty()); | 262 EXPECT_FALSE(current_session_id_.empty()); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 class NoResponseApp : public FakeEncryptedMedia::AppBase { | 360 class NoResponseApp : public FakeEncryptedMedia::AppBase { |
355 public: | 361 public: |
356 virtual void OnSessionMessage(const std::string& web_session_id, | 362 virtual void OnSessionMessage(const std::string& web_session_id, |
357 const std::vector<uint8>& message, | 363 const std::vector<uint8>& message, |
358 const GURL& default_url) OVERRIDE { | 364 const GURL& default_url) OVERRIDE { |
359 EXPECT_FALSE(web_session_id.empty()); | 365 EXPECT_FALSE(web_session_id.empty()); |
360 EXPECT_FALSE(message.empty()); | 366 EXPECT_FALSE(message.empty()); |
361 FAIL() << "Unexpected Message"; | 367 FAIL() << "Unexpected Message"; |
362 } | 368 } |
363 | 369 |
364 virtual void OnSessionReady(const std::string& web_session_id) OVERRIDE { | |
365 EXPECT_FALSE(web_session_id.empty()); | |
366 FAIL() << "Unexpected Ready"; | |
367 } | |
368 | |
369 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { | 370 virtual void OnSessionClosed(const std::string& web_session_id) OVERRIDE { |
370 EXPECT_FALSE(web_session_id.empty()); | 371 EXPECT_FALSE(web_session_id.empty()); |
371 FAIL() << "Unexpected Closed"; | 372 FAIL() << "Unexpected Closed"; |
372 } | 373 } |
373 | 374 |
| 375 virtual void OnSessionKeysChange(const std::string& web_session_id, |
| 376 bool has_additional_usable_key) OVERRIDE { |
| 377 EXPECT_FALSE(web_session_id.empty()); |
| 378 EXPECT_EQ(has_additional_usable_key, true); |
| 379 } |
| 380 |
374 virtual void NeedKey(const std::string& type, | 381 virtual void NeedKey(const std::string& type, |
375 const std::vector<uint8>& init_data, | 382 const std::vector<uint8>& init_data, |
376 AesDecryptor* decryptor) OVERRIDE { | 383 AesDecryptor* decryptor) OVERRIDE { |
377 } | 384 } |
378 }; | 385 }; |
379 | 386 |
380 // Helper class that emulates calls made on the ChunkDemuxer by the | 387 // Helper class that emulates calls made on the ChunkDemuxer by the |
381 // Media Source API. | 388 // Media Source API. |
382 class MockMediaSource { | 389 class MockMediaSource { |
383 public: | 390 public: |
(...skipping 1217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { | 1608 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { |
1602 ASSERT_TRUE( | 1609 ASSERT_TRUE( |
1603 Start(GetTestDataFilePath("nonzero-start-time.webm"), PIPELINE_OK)); | 1610 Start(GetTestDataFilePath("nonzero-start-time.webm"), PIPELINE_OK)); |
1604 Play(); | 1611 Play(); |
1605 ASSERT_TRUE(WaitUntilOnEnded()); | 1612 ASSERT_TRUE(WaitUntilOnEnded()); |
1606 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), | 1613 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), |
1607 demuxer_->GetStartTime()); | 1614 demuxer_->GetStartTime()); |
1608 } | 1615 } |
1609 | 1616 |
1610 } // namespace media | 1617 } // namespace media |
OLD | NEW |