| Index: media/cdm/aes_decryptor_unittest.cc
|
| diff --git a/media/cdm/aes_decryptor_unittest.cc b/media/cdm/aes_decryptor_unittest.cc
|
| index d2d7ee0c8e584aa69db5fb64340763fdd702569a..91cd6ac365d39f844b8883861149494b1d7ffffd 100644
|
| --- a/media/cdm/aes_decryptor_unittest.cc
|
| +++ b/media/cdm/aes_decryptor_unittest.cc
|
| @@ -220,41 +220,66 @@ class AesDecryptorTest : public testing::Test {
|
| }
|
|
|
| protected:
|
| - void OnResolveWithSession(PromiseResult expected,
|
| + void OnResolveWithSession(PromiseResult expected_result,
|
| const std::string& web_session_id) {
|
| - EXPECT_EQ(expected, RESOLVED);
|
| + EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved.";
|
| EXPECT_GT(web_session_id.length(), 0ul);
|
| web_session_id_ = web_session_id;
|
| }
|
|
|
| - void OnResolve(PromiseResult expected) {
|
| - EXPECT_EQ(expected, RESOLVED);
|
| + void OnResolve(PromiseResult expected_result) {
|
| + EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved.";
|
| }
|
|
|
| - void OnReject(PromiseResult expected,
|
| + void OnResolveWithUsableKeyIds(PromiseResult expected_result,
|
| + uint32 expected_count,
|
| + const KeyIdsVector& useable_key_ids) {
|
| + EXPECT_EQ(expected_result, RESOLVED) << "Unexpectedly resolved.";
|
| + EXPECT_EQ(expected_count, useable_key_ids.size());
|
| + useable_key_ids_ = useable_key_ids;
|
| + }
|
| +
|
| + void OnReject(PromiseResult expected_result,
|
| MediaKeys::Exception exception_code,
|
| uint32 system_code,
|
| const std::string& error_message) {
|
| - EXPECT_EQ(expected, REJECTED);
|
| + EXPECT_EQ(expected_result, REJECTED) << "Unexpectedly rejected.";
|
| }
|
|
|
| - scoped_ptr<SimpleCdmPromise> CreatePromise(PromiseResult expected) {
|
| - scoped_ptr<SimpleCdmPromise> promise(new SimpleCdmPromise(
|
| - base::Bind(
|
| - &AesDecryptorTest::OnResolve, base::Unretained(this), expected),
|
| - base::Bind(
|
| - &AesDecryptorTest::OnReject, base::Unretained(this), expected)));
|
| + scoped_ptr<SimpleCdmPromise> CreatePromise(PromiseResult expected_result) {
|
| + scoped_ptr<SimpleCdmPromise> promise(
|
| + new SimpleCdmPromise(base::Bind(&AesDecryptorTest::OnResolve,
|
| + base::Unretained(this),
|
| + expected_result),
|
| + base::Bind(&AesDecryptorTest::OnReject,
|
| + base::Unretained(this),
|
| + expected_result)));
|
| return promise.Pass();
|
| }
|
|
|
| scoped_ptr<NewSessionCdmPromise> CreateSessionPromise(
|
| - PromiseResult expected) {
|
| + PromiseResult expected_result) {
|
| scoped_ptr<NewSessionCdmPromise> promise(new NewSessionCdmPromise(
|
| base::Bind(&AesDecryptorTest::OnResolveWithSession,
|
| base::Unretained(this),
|
| - expected),
|
| - base::Bind(
|
| - &AesDecryptorTest::OnReject, base::Unretained(this), expected)));
|
| + expected_result),
|
| + base::Bind(&AesDecryptorTest::OnReject,
|
| + base::Unretained(this),
|
| + expected_result)));
|
| + return promise.Pass();
|
| + }
|
| +
|
| + scoped_ptr<KeyIdsPromise> CreateUsableKeyIdsPromise(
|
| + PromiseResult expected_result,
|
| + uint32 expected_count) {
|
| + scoped_ptr<KeyIdsPromise> promise(new KeyIdsPromise(
|
| + base::Bind(&AesDecryptorTest::OnResolveWithUsableKeyIds,
|
| + base::Unretained(this),
|
| + expected_result,
|
| + expected_count),
|
| + base::Bind(&AesDecryptorTest::OnReject,
|
| + base::Unretained(this),
|
| + expected_result)));
|
| return promise.Pass();
|
| }
|
|
|
| @@ -292,6 +317,23 @@ class AesDecryptorTest : public testing::Test {
|
| CreatePromise(result));
|
| }
|
|
|
| + void GetUsableKeyIdsAndExpect(const std::string& session_id,
|
| + PromiseResult expected_result,
|
| + uint32 expected_count) {
|
| + decryptor_.GetUsableKeyIds(
|
| + session_id, CreateUsableKeyIdsPromise(expected_result, expected_count));
|
| + }
|
| +
|
| + bool UsableKeyIdsContains(std::vector<uint8> expected) {
|
| + for (KeyIdsVector::iterator it = useable_key_ids_.begin();
|
| + it != useable_key_ids_.end();
|
| + ++it) {
|
| + if (*it == expected)
|
| + return true;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status,
|
| const scoped_refptr<DecoderBuffer>&));
|
|
|
| @@ -361,6 +403,10 @@ class AesDecryptorTest : public testing::Test {
|
| AesDecryptor::DecryptCB decrypt_cb_;
|
| std::string web_session_id_;
|
|
|
| + // Copy of the vector from the last successful call to
|
| + // OnResolveWithUsableKeyIds().
|
| + KeyIdsVector useable_key_ids_;
|
| +
|
| // Constants for testing.
|
| const std::vector<uint8> original_data_;
|
| const std::vector<uint8> encrypted_data_;
|
| @@ -789,4 +835,26 @@ TEST_F(AesDecryptorTest, JWKKey) {
|
| ReleaseSession(session_id);
|
| }
|
|
|
| +TEST_F(AesDecryptorTest, GetKeyIds) {
|
| + std::vector<uint8> key_id1(kKeyId, kKeyId + arraysize(kKeyId));
|
| + std::vector<uint8> key_id2(kKeyId2, kKeyId2 + arraysize(kKeyId2));
|
| +
|
| + std::string session_id = CreateSession(key_id_);
|
| + GetUsableKeyIdsAndExpect(session_id, RESOLVED, 0);
|
| + EXPECT_FALSE(UsableKeyIdsContains(key_id1));
|
| + EXPECT_FALSE(UsableKeyIdsContains(key_id2));
|
| +
|
| + // Add 1 key, verify ID is returned.
|
| + UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
|
| + GetUsableKeyIdsAndExpect(session_id, RESOLVED, 1);
|
| + EXPECT_TRUE(UsableKeyIdsContains(key_id1));
|
| + EXPECT_FALSE(UsableKeyIdsContains(key_id2));
|
| +
|
| + // Add second key, verify both IDs returned.
|
| + UpdateSessionAndExpect(session_id, kKey2AsJWK, RESOLVED);
|
| + GetUsableKeyIdsAndExpect(session_id, RESOLVED, 2);
|
| + EXPECT_TRUE(UsableKeyIdsContains(key_id1));
|
| + EXPECT_TRUE(UsableKeyIdsContains(key_id2));
|
| +}
|
| +
|
| } // namespace media
|
|
|