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..90e1da59aba4f08e6ddb7e17d78f6e99d43fa453 100644 |
--- a/media/cdm/aes_decryptor_unittest.cc |
+++ b/media/cdm/aes_decryptor_unittest.cc |
@@ -231,6 +231,14 @@ class AesDecryptorTest : public testing::Test { |
EXPECT_EQ(expected, RESOLVED); |
} |
+ void OnResolveWithUsableKeyIds(PromiseResult expected, |
ddorwin
2014/08/08 23:36:24
_result
jrummell
2014/08/11 18:59:03
Done.
|
+ uint32 expected_count, |
+ const KeyIdsVector& useable_key_ids) { |
+ EXPECT_EQ(expected, RESOLVED); |
ddorwin
2014/08/08 23:36:24
This was confusing at first. Maybe add:
<< "Unexpe
jrummell
2014/08/11 18:59:03
Done.
|
+ EXPECT_EQ(expected_count, useable_key_ids.size()); |
+ useable_key_ids_ = useable_key_ids; |
+ } |
+ |
void OnReject(PromiseResult expected, |
MediaKeys::Exception exception_code, |
uint32 system_code, |
@@ -258,6 +266,18 @@ class AesDecryptorTest : public testing::Test { |
return promise.Pass(); |
} |
+ scoped_ptr<KeyIdsPromise> CreateUsableKeyIdsPromise(uint32 expected_count, |
+ PromiseResult expected) { |
ddorwin
2014/08/08 23:36:24
ditto
Also, keep the order consistent. (Plus it ma
jrummell
2014/08/11 18:59:03
Done.
|
+ scoped_ptr<KeyIdsPromise> promise(new KeyIdsPromise( |
+ base::Bind(&AesDecryptorTest::OnResolveWithUsableKeyIds, |
+ base::Unretained(this), |
+ expected, |
+ expected_count), |
+ base::Bind( |
+ &AesDecryptorTest::OnReject, base::Unretained(this), expected))); |
+ return promise.Pass(); |
+ } |
+ |
// Creates a new session using |key_id|. Returns the session ID. |
std::string CreateSession(const std::vector<uint8>& key_id) { |
DCHECK(!key_id.empty()); |
@@ -292,6 +312,23 @@ class AesDecryptorTest : public testing::Test { |
CreatePromise(result)); |
} |
+ void GetUsableKeyIdsAndExpect(const std::string& session_id, |
+ uint32 expected_count, |
ddorwin
2014/08/08 23:36:24
ditto on order
jrummell
2014/08/11 18:59:03
Done.
|
+ PromiseResult result) { |
ddorwin
2014/08/08 23:36:24
expected_result?
jrummell
2014/08/11 18:59:03
Done.
|
+ decryptor_.GetUsableKeyIds( |
+ session_id, CreateUsableKeyIdsPromise(expected_count, result)); |
+ } |
+ |
+ bool UsableKeyIdsContains(std::vector<uint8> expected) { |
+ for (KeyIdsVector::iterator it = useable_key_ids_.begin(); |
ddorwin
2014/08/08 23:36:24
Maybe DCHECK(!useable_key_ids_.empty()) to catch t
jrummell
2014/08/11 18:59:03
Can't as the test calls it before any keys are add
|
+ it != useable_key_ids_.end(); |
+ ++it) { |
+ if (*it == expected) |
+ return true; |
+ } |
+ return false; |
+ } |
+ |
MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status, |
const scoped_refptr<DecoderBuffer>&)); |
@@ -360,6 +397,7 @@ class AesDecryptorTest : public testing::Test { |
AesDecryptor decryptor_; |
AesDecryptor::DecryptCB decrypt_cb_; |
std::string web_session_id_; |
+ KeyIdsVector useable_key_ids_; |
ddorwin
2014/08/08 23:36:24
// Copy of the vector from the last successful cal
jrummell
2014/08/11 18:59:03
Done.
|
// Constants for testing. |
const std::vector<uint8> original_data_; |
@@ -789,4 +827,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)); |
+ |
ddorwin
2014/08/08 23:36:24
Though it should never happen in real life, as par
jrummell
2014/08/11 18:59:03
Added DCHECK for this.
|
+ std::string session_id = CreateSession(key_id_); |
+ GetUsableKeyIdsAndExpect(session_id, 0, RESOLVED); |
+ 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, 1, RESOLVED); |
+ 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, 2, RESOLVED); |
+ EXPECT_TRUE(UsableKeyIdsContains(key_id1)); |
+ EXPECT_TRUE(UsableKeyIdsContains(key_id2)); |
+} |
+ |
} // namespace media |