Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Side by Side Diff: media/cdm/aes_decryptor_unittest.cc

Issue 448893002: Update ClearKey to support CDM_6 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cdm6
Patch Set: rebase Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/cdm/aes_decryptor.cc ('k') | media/cdm/ppapi/external_clear_key/clear_key_cdm.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "media/base/cdm_promise.h" 10 #include "media/base/cdm_promise.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 kSubsampleEncryptedData, 213 kSubsampleEncryptedData,
214 kSubsampleEncryptedData + arraysize(kSubsampleEncryptedData)), 214 kSubsampleEncryptedData + arraysize(kSubsampleEncryptedData)),
215 key_id_(kKeyId, kKeyId + arraysize(kKeyId)), 215 key_id_(kKeyId, kKeyId + arraysize(kKeyId)),
216 iv_(kIv, kIv + arraysize(kIv)), 216 iv_(kIv, kIv + arraysize(kIv)),
217 normal_subsample_entries_( 217 normal_subsample_entries_(
218 kSubsampleEntriesNormal, 218 kSubsampleEntriesNormal,
219 kSubsampleEntriesNormal + arraysize(kSubsampleEntriesNormal)) { 219 kSubsampleEntriesNormal + arraysize(kSubsampleEntriesNormal)) {
220 } 220 }
221 221
222 protected: 222 protected:
223 void OnResolveWithSession(PromiseResult expected, 223 void OnResolveWithSession(PromiseResult expected_result,
224 const std::string& web_session_id) { 224 const std::string& web_session_id) {
225 EXPECT_EQ(expected, RESOLVED); 225 EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved.";
226 EXPECT_GT(web_session_id.length(), 0ul); 226 EXPECT_GT(web_session_id.length(), 0ul);
227 web_session_id_ = web_session_id; 227 web_session_id_ = web_session_id;
228 } 228 }
229 229
230 void OnResolve(PromiseResult expected) { 230 void OnResolve(PromiseResult expected_result) {
231 EXPECT_EQ(expected, RESOLVED); 231 EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved.";
232 } 232 }
233 233
234 void OnReject(PromiseResult expected, 234 void OnResolveWithUsableKeyIds(PromiseResult expected_result,
235 uint32 expected_count,
236 const KeyIdsVector& useable_key_ids) {
237 EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved.";
238 EXPECT_EQ(expected_count, useable_key_ids.size());
239 useable_key_ids_ = useable_key_ids;
240 }
241
242 void OnReject(PromiseResult expected_result,
235 MediaKeys::Exception exception_code, 243 MediaKeys::Exception exception_code,
236 uint32 system_code, 244 uint32 system_code,
237 const std::string& error_message) { 245 const std::string& error_message) {
238 EXPECT_EQ(expected, REJECTED); 246 EXPECT_EQ(expected_result, REJECTED) << "Unexpectedly rejected.";
239 } 247 }
240 248
241 scoped_ptr<SimpleCdmPromise> CreatePromise(PromiseResult expected) { 249 scoped_ptr<SimpleCdmPromise> CreatePromise(PromiseResult expected_result) {
242 scoped_ptr<SimpleCdmPromise> promise(new SimpleCdmPromise( 250 scoped_ptr<SimpleCdmPromise> promise(
243 base::Bind( 251 new SimpleCdmPromise(base::Bind(&AesDecryptorTest::OnResolve,
244 &AesDecryptorTest::OnResolve, base::Unretained(this), expected), 252 base::Unretained(this),
245 base::Bind( 253 expected_result),
246 &AesDecryptorTest::OnReject, base::Unretained(this), expected))); 254 base::Bind(&AesDecryptorTest::OnReject,
255 base::Unretained(this),
256 expected_result)));
247 return promise.Pass(); 257 return promise.Pass();
248 } 258 }
249 259
250 scoped_ptr<NewSessionCdmPromise> CreateSessionPromise( 260 scoped_ptr<NewSessionCdmPromise> CreateSessionPromise(
251 PromiseResult expected) { 261 PromiseResult expected_result) {
252 scoped_ptr<NewSessionCdmPromise> promise(new NewSessionCdmPromise( 262 scoped_ptr<NewSessionCdmPromise> promise(new NewSessionCdmPromise(
253 base::Bind(&AesDecryptorTest::OnResolveWithSession, 263 base::Bind(&AesDecryptorTest::OnResolveWithSession,
254 base::Unretained(this), 264 base::Unretained(this),
255 expected), 265 expected_result),
256 base::Bind( 266 base::Bind(&AesDecryptorTest::OnReject,
257 &AesDecryptorTest::OnReject, base::Unretained(this), expected))); 267 base::Unretained(this),
268 expected_result)));
258 return promise.Pass(); 269 return promise.Pass();
259 } 270 }
260 271
272 scoped_ptr<KeyIdsPromise> CreateUsableKeyIdsPromise(
273 PromiseResult expected_result,
274 uint32 expected_count) {
275 scoped_ptr<KeyIdsPromise> promise(new KeyIdsPromise(
276 base::Bind(&AesDecryptorTest::OnResolveWithUsableKeyIds,
277 base::Unretained(this),
278 expected_result,
279 expected_count),
280 base::Bind(&AesDecryptorTest::OnReject,
281 base::Unretained(this),
282 expected_result)));
283 return promise.Pass();
284 }
285
261 // Creates a new session using |key_id|. Returns the session ID. 286 // Creates a new session using |key_id|. Returns the session ID.
262 std::string CreateSession(const std::vector<uint8>& key_id) { 287 std::string CreateSession(const std::vector<uint8>& key_id) {
263 DCHECK(!key_id.empty()); 288 DCHECK(!key_id.empty());
264 EXPECT_CALL(*this, 289 EXPECT_CALL(*this,
265 OnSessionMessage(IsNotEmpty(), key_id, GURL::EmptyGURL())); 290 OnSessionMessage(IsNotEmpty(), key_id, GURL::EmptyGURL()));
266 decryptor_.CreateSession(std::string(), 291 decryptor_.CreateSession(std::string(),
267 &key_id[0], 292 &key_id[0],
268 key_id.size(), 293 key_id.size(),
269 MediaKeys::TEMPORARY_SESSION, 294 MediaKeys::TEMPORARY_SESSION,
270 CreateSessionPromise(RESOLVED)); 295 CreateSessionPromise(RESOLVED));
(...skipping 14 matching lines...) Expand all
285 const std::string& key, 310 const std::string& key,
286 PromiseResult result) { 311 PromiseResult result) {
287 DCHECK(!key.empty()); 312 DCHECK(!key.empty());
288 313
289 decryptor_.UpdateSession(session_id, 314 decryptor_.UpdateSession(session_id,
290 reinterpret_cast<const uint8*>(key.c_str()), 315 reinterpret_cast<const uint8*>(key.c_str()),
291 key.length(), 316 key.length(),
292 CreatePromise(result)); 317 CreatePromise(result));
293 } 318 }
294 319
320 void GetUsableKeyIdsAndExpect(const std::string& session_id,
321 PromiseResult expected_result,
322 uint32 expected_count) {
323 decryptor_.GetUsableKeyIds(
324 session_id, CreateUsableKeyIdsPromise(expected_result, expected_count));
325 }
326
327 bool UsableKeyIdsContains(std::vector<uint8> expected) {
328 for (KeyIdsVector::iterator it = useable_key_ids_.begin();
329 it != useable_key_ids_.end();
330 ++it) {
331 if (*it == expected)
332 return true;
333 }
334 return false;
335 }
336
295 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, 337 MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status,
296 const scoped_refptr<DecoderBuffer>&)); 338 const scoped_refptr<DecoderBuffer>&));
297 339
298 enum DecryptExpectation { 340 enum DecryptExpectation {
299 SUCCESS, 341 SUCCESS,
300 DATA_MISMATCH, 342 DATA_MISMATCH,
301 DATA_AND_SIZE_MISMATCH, 343 DATA_AND_SIZE_MISMATCH,
302 DECRYPT_ERROR, 344 DECRYPT_ERROR,
303 NO_KEY 345 NO_KEY
304 }; 346 };
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 MOCK_METHOD3(OnSessionMessage, 396 MOCK_METHOD3(OnSessionMessage,
355 void(const std::string& web_session_id, 397 void(const std::string& web_session_id,
356 const std::vector<uint8>& message, 398 const std::vector<uint8>& message,
357 const GURL& destination_url)); 399 const GURL& destination_url));
358 MOCK_METHOD1(OnSessionClosed, void(const std::string& web_session_id)); 400 MOCK_METHOD1(OnSessionClosed, void(const std::string& web_session_id));
359 401
360 AesDecryptor decryptor_; 402 AesDecryptor decryptor_;
361 AesDecryptor::DecryptCB decrypt_cb_; 403 AesDecryptor::DecryptCB decrypt_cb_;
362 std::string web_session_id_; 404 std::string web_session_id_;
363 405
406 // Copy of the vector from the last successful call to
407 // OnResolveWithUsableKeyIds().
408 KeyIdsVector useable_key_ids_;
409
364 // Constants for testing. 410 // Constants for testing.
365 const std::vector<uint8> original_data_; 411 const std::vector<uint8> original_data_;
366 const std::vector<uint8> encrypted_data_; 412 const std::vector<uint8> encrypted_data_;
367 const std::vector<uint8> subsample_encrypted_data_; 413 const std::vector<uint8> subsample_encrypted_data_;
368 const std::vector<uint8> key_id_; 414 const std::vector<uint8> key_id_;
369 const std::vector<uint8> iv_; 415 const std::vector<uint8> iv_;
370 const std::vector<SubsampleEntry> normal_subsample_entries_; 416 const std::vector<SubsampleEntry> normal_subsample_entries_;
371 const std::vector<SubsampleEntry> no_subsample_entries_; 417 const std::vector<SubsampleEntry> no_subsample_entries_;
372 }; 418 };
373 419
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 " \"kty\": \"oct\"," 828 " \"kty\": \"oct\","
783 " \"kid\": \"\"," 829 " \"kid\": \"\","
784 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\"" 830 " \"k\": \"BAUGBwgJCgsMDQ4PEBESEw\""
785 " }" 831 " }"
786 " ]" 832 " ]"
787 "}"; 833 "}";
788 UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, REJECTED); 834 UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, REJECTED);
789 ReleaseSession(session_id); 835 ReleaseSession(session_id);
790 } 836 }
791 837
838 TEST_F(AesDecryptorTest, GetKeyIds) {
839 std::vector<uint8> key_id1(kKeyId, kKeyId + arraysize(kKeyId));
840 std::vector<uint8> key_id2(kKeyId2, kKeyId2 + arraysize(kKeyId2));
841
842 std::string session_id = CreateSession(key_id_);
843 GetUsableKeyIdsAndExpect(session_id, RESOLVED, 0);
844 EXPECT_FALSE(UsableKeyIdsContains(key_id1));
845 EXPECT_FALSE(UsableKeyIdsContains(key_id2));
846
847 // Add 1 key, verify ID is returned.
848 UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
849 GetUsableKeyIdsAndExpect(session_id, RESOLVED, 1);
850 EXPECT_TRUE(UsableKeyIdsContains(key_id1));
851 EXPECT_FALSE(UsableKeyIdsContains(key_id2));
852
853 // Add second key, verify both IDs returned.
854 UpdateSessionAndExpect(session_id, kKey2AsJWK, RESOLVED);
855 GetUsableKeyIdsAndExpect(session_id, RESOLVED, 2);
856 EXPECT_TRUE(UsableKeyIdsContains(key_id1));
857 EXPECT_TRUE(UsableKeyIdsContains(key_id2));
858 }
859
792 } // namespace media 860 } // namespace media
OLDNEW
« no previous file with comments | « media/cdm/aes_decryptor.cc ('k') | media/cdm/ppapi/external_clear_key/clear_key_cdm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698