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

Unified Diff: media/cdm/aes_decryptor_unittest.cc

Issue 555223004: Update MediaKeys interface for EME (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: helpers Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: media/cdm/aes_decryptor_unittest.cc
diff --git a/media/cdm/aes_decryptor_unittest.cc b/media/cdm/aes_decryptor_unittest.cc
index a40867e7d1b5a6d212df41d4a12ac6686018f93e..de52d69c18f492b74944865bc2778a1feea69315 100644
--- a/media/cdm/aes_decryptor_unittest.cc
+++ b/media/cdm/aes_decryptor_unittest.cc
@@ -211,6 +211,8 @@ class AesDecryptorTest : public testing::Test {
: decryptor_(base::Bind(&AesDecryptorTest::OnSessionMessage,
base::Unretained(this)),
base::Bind(&AesDecryptorTest::OnSessionClosed,
+ base::Unretained(this)),
+ base::Bind(&AesDecryptorTest::OnSessionKeysChange,
base::Unretained(this))),
decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted,
base::Unretained(this))),
@@ -307,23 +309,38 @@ class AesDecryptorTest : public testing::Test {
return web_session_id_;
}
- // Releases the session specified by |session_id|.
- void ReleaseSession(const std::string& session_id) {
+ // Closes the session specified by |session_id|.
+ void CloseSession(const std::string& session_id) {
EXPECT_CALL(*this, OnSessionClosed(session_id));
- decryptor_.ReleaseSession(session_id, CreatePromise(RESOLVED));
+ decryptor_.CloseSession(session_id, CreatePromise(RESOLVED));
+ }
+
+ // Removes the session specified by |session_id|. This should simply do a
+ // CloseSession().
+ // TODO(jrummell): Clean this up when the prefixed API is removed.
+ // http://crbug.com/249976.
+ void RemoveSession(const std::string& session_id) {
+ EXPECT_CALL(*this, OnSessionClosed(session_id));
+ decryptor_.RemoveSession(session_id, CreatePromise(RESOLVED));
}
// Updates the session specified by |session_id| with |key|. |result|
// tests that the update succeeds or generates an error.
void UpdateSessionAndExpect(std::string session_id,
const std::string& key,
- PromiseResult result) {
+ PromiseResult expected_result) {
DCHECK(!key.empty());
+ if (expected_result == RESOLVED) {
+ EXPECT_CALL(*this, OnSessionKeysChange(session_id, true));
+ } else {
+ EXPECT_CALL(*this, OnSessionKeysChange(_, _)).Times(0);
+ }
+
decryptor_.UpdateSession(session_id,
reinterpret_cast<const uint8*>(key.c_str()),
key.length(),
- CreatePromise(result));
+ CreatePromise(expected_result));
}
void GetUsableKeyIdsAndExpect(const std::string& session_id,
@@ -406,6 +423,9 @@ class AesDecryptorTest : public testing::Test {
void(const std::string& web_session_id,
const std::vector<uint8>& message,
const GURL& destination_url));
+ MOCK_METHOD2(OnSessionKeysChange,
+ void(const std::string& web_session_id,
+ bool has_additional_usable_key));
MOCK_METHOD1(OnSessionClosed, void(const std::string& web_session_id));
AesDecryptor decryptor_;
@@ -647,7 +667,21 @@ TEST_F(AesDecryptorTest, SubsampleCypherBytesOnly) {
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS);
}
-TEST_F(AesDecryptorTest, ReleaseSession) {
+TEST_F(AesDecryptorTest, CloseSession) {
+ std::string session_id = CreateSession(key_id_);
+ scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
+ encrypted_data_, key_id_, iv_, no_subsample_entries_);
+
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
+ ASSERT_NO_FATAL_FAILURE(
+ DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
+
+ CloseSession(session_id);
+}
+
+TEST_F(AesDecryptorTest, RemoveSession) {
+ // TODO(jrummell): Clean this up when the prefixed API is removed.
+ // http://crbug.com/249976.
std::string session_id = CreateSession(key_id_);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
encrypted_data_, key_id_, iv_, no_subsample_entries_);
@@ -656,10 +690,10 @@ TEST_F(AesDecryptorTest, ReleaseSession) {
ASSERT_NO_FATAL_FAILURE(
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
- ReleaseSession(session_id);
+ RemoveSession(session_id);
}
-TEST_F(AesDecryptorTest, NoKeyAfterReleaseSession) {
+TEST_F(AesDecryptorTest, NoKeyAfterCloseSession) {
std::string session_id = CreateSession(key_id_);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
encrypted_data_, key_id_, iv_, no_subsample_entries_);
@@ -668,7 +702,7 @@ TEST_F(AesDecryptorTest, NoKeyAfterReleaseSession) {
ASSERT_NO_FATAL_FAILURE(
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
- ReleaseSession(session_id);
+ CloseSession(session_id);
ASSERT_NO_FATAL_FAILURE(
DecryptAndExpect(encrypted_buffer, original_data_, NO_KEY));
}
@@ -692,7 +726,7 @@ TEST_F(AesDecryptorTest, LatestKeyUsed) {
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
}
-TEST_F(AesDecryptorTest, LatestKeyUsedAfterReleaseSession) {
+TEST_F(AesDecryptorTest, LatestKeyUsedAfterCloseSession) {
std::string session_id1 = CreateSession(key_id_);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
encrypted_data_, key_id_, iv_, no_subsample_entries_);
@@ -709,7 +743,7 @@ TEST_F(AesDecryptorTest, LatestKeyUsedAfterReleaseSession) {
DecryptAndExpect(encrypted_buffer, original_data_, DATA_MISMATCH));
// Close second session, should revert to original key.
- ReleaseSession(session_id2);
+ CloseSession(session_id2);
ASSERT_NO_FATAL_FAILURE(
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
}
@@ -841,7 +875,7 @@ TEST_F(AesDecryptorTest, JWKKey) {
" ]"
"}";
UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, REJECTED);
- ReleaseSession(session_id);
+ CloseSession(session_id);
}
TEST_F(AesDecryptorTest, GetKeyIds) {

Powered by Google App Engine
This is Rietveld 408576698