}
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();
}
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>&));
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_;
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