summaryrefslogtreecommitdiffstats
path: root/chromium/media/cdm/aes_decryptor_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/media/cdm/aes_decryptor_unittest.cc')
-rw-r--r--chromium/media/cdm/aes_decryptor_unittest.cc341
1 files changed, 180 insertions, 161 deletions
diff --git a/chromium/media/cdm/aes_decryptor_unittest.cc b/chromium/media/cdm/aes_decryptor_unittest.cc
index 3076d5a3f2e..d2d7ee0c8e5 100644
--- a/chromium/media/cdm/aes_decryptor_unittest.cc
+++ b/chromium/media/cdm/aes_decryptor_unittest.cc
@@ -7,11 +7,11 @@
#include "base/basictypes.h"
#include "base/bind.h"
+#include "media/base/cdm_promise.h"
#include "media/base/decoder_buffer.h"
#include "media/base/decrypt_config.h"
#include "media/base/mock_filters.h"
#include "media/cdm/aes_decryptor.h"
-#include "media/webm/webm_constants.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -23,6 +23,9 @@ using ::testing::SaveArg;
using ::testing::StrNe;
MATCHER(IsEmpty, "") { return arg.empty(); }
+MATCHER(IsNotEmpty, "") { return !arg.empty(); }
+
+class GURL;
namespace media {
@@ -177,12 +180,10 @@ static scoped_refptr<DecoderBuffer> CreateEncryptedBuffer(
const std::vector<uint8>& data,
const std::vector<uint8>& key_id,
const std::vector<uint8>& iv,
- int offset,
const std::vector<SubsampleEntry>& subsample_entries) {
DCHECK(!data.empty());
- int padded_size = offset + data.size();
- scoped_refptr<DecoderBuffer> encrypted_buffer(new DecoderBuffer(padded_size));
- memcpy(encrypted_buffer->writable_data() + offset, &data[0], data.size());
+ scoped_refptr<DecoderBuffer> encrypted_buffer(new DecoderBuffer(data.size()));
+ memcpy(encrypted_buffer->writable_data(), &data[0], data.size());
CHECK(encrypted_buffer.get());
std::string key_id_string(
reinterpret_cast<const char*>(key_id.empty() ? NULL : &key_id[0]),
@@ -190,22 +191,18 @@ static scoped_refptr<DecoderBuffer> CreateEncryptedBuffer(
std::string iv_string(
reinterpret_cast<const char*>(iv.empty() ? NULL : &iv[0]), iv.size());
encrypted_buffer->set_decrypt_config(scoped_ptr<DecryptConfig>(
- new DecryptConfig(key_id_string, iv_string, offset, subsample_entries)));
+ new DecryptConfig(key_id_string, iv_string, subsample_entries)));
return encrypted_buffer;
}
+enum PromiseResult { RESOLVED, REJECTED };
+
class AesDecryptorTest : public testing::Test {
public:
AesDecryptorTest()
- : decryptor_(base::Bind(&AesDecryptorTest::OnSessionCreated,
- base::Unretained(this)),
- base::Bind(&AesDecryptorTest::OnSessionMessage,
- base::Unretained(this)),
- base::Bind(&AesDecryptorTest::OnSessionReady,
+ : decryptor_(base::Bind(&AesDecryptorTest::OnSessionMessage,
base::Unretained(this)),
base::Bind(&AesDecryptorTest::OnSessionClosed,
- base::Unretained(this)),
- base::Bind(&AesDecryptorTest::OnSessionError,
base::Unretained(this))),
decrypt_cb_(base::Bind(&AesDecryptorTest::BufferDecrypted,
base::Unretained(this))),
@@ -219,52 +216,80 @@ class AesDecryptorTest : public testing::Test {
iv_(kIv, kIv + arraysize(kIv)),
normal_subsample_entries_(
kSubsampleEntriesNormal,
- kSubsampleEntriesNormal + arraysize(kSubsampleEntriesNormal)),
- next_session_id_(1) {
+ kSubsampleEntriesNormal + arraysize(kSubsampleEntriesNormal)) {
}
protected:
+ void OnResolveWithSession(PromiseResult expected,
+ const std::string& web_session_id) {
+ EXPECT_EQ(expected, RESOLVED);
+ EXPECT_GT(web_session_id.length(), 0ul);
+ web_session_id_ = web_session_id;
+ }
+
+ void OnResolve(PromiseResult expected) {
+ EXPECT_EQ(expected, RESOLVED);
+ }
+
+ void OnReject(PromiseResult expected,
+ MediaKeys::Exception exception_code,
+ uint32 system_code,
+ const std::string& error_message) {
+ EXPECT_EQ(expected, 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)));
+ return promise.Pass();
+ }
+
+ scoped_ptr<NewSessionCdmPromise> CreateSessionPromise(
+ PromiseResult expected) {
+ scoped_ptr<NewSessionCdmPromise> promise(new NewSessionCdmPromise(
+ base::Bind(&AesDecryptorTest::OnResolveWithSession,
+ base::Unretained(this),
+ expected),
+ base::Bind(
+ &AesDecryptorTest::OnReject, base::Unretained(this), expected)));
+ return promise.Pass();
+ }
+
// Creates a new session using |key_id|. Returns the session ID.
- uint32 CreateSession(const std::vector<uint8>& key_id) {
+ std::string CreateSession(const std::vector<uint8>& key_id) {
DCHECK(!key_id.empty());
- uint32 session_id = next_session_id_++;
- EXPECT_CALL(*this, OnSessionCreated(session_id, StrNe(std::string())));
- EXPECT_CALL(*this, OnSessionMessage(session_id, key_id, ""));
- EXPECT_TRUE(decryptor_.CreateSession(
- session_id, std::string(), &key_id[0], key_id.size()));
- return session_id;
+ EXPECT_CALL(*this,
+ OnSessionMessage(IsNotEmpty(), key_id, GURL::EmptyGURL()));
+ decryptor_.CreateSession(std::string(),
+ &key_id[0],
+ key_id.size(),
+ MediaKeys::TEMPORARY_SESSION,
+ CreateSessionPromise(RESOLVED));
+ // This expects the promise to be called synchronously, which is the case
+ // for AesDecryptor.
+ return web_session_id_;
}
// Releases the session specified by |session_id|.
- void ReleaseSession(uint32 session_id) {
+ void ReleaseSession(const std::string& session_id) {
EXPECT_CALL(*this, OnSessionClosed(session_id));
- decryptor_.ReleaseSession(session_id);
+ decryptor_.ReleaseSession(session_id, CreatePromise(RESOLVED));
}
- enum UpdateSessionExpectation {
- SESSION_READY,
- SESSION_ERROR
- };
-
// Updates the session specified by |session_id| with |key|. |result|
// tests that the update succeeds or generates an error.
- void UpdateSessionAndExpect(uint32 session_id,
+ void UpdateSessionAndExpect(std::string session_id,
const std::string& key,
- UpdateSessionExpectation result) {
+ PromiseResult result) {
DCHECK(!key.empty());
- switch (result) {
- case SESSION_READY:
- EXPECT_CALL(*this, OnSessionReady(session_id));
- break;
- case SESSION_ERROR:
- EXPECT_CALL(*this,
- OnSessionError(session_id, MediaKeys::kUnknownError, 0));
- break;
- }
-
- decryptor_.UpdateSession(
- session_id, reinterpret_cast<const uint8*>(key.c_str()), key.length());
+ decryptor_.UpdateSession(session_id,
+ reinterpret_cast<const uint8*>(key.c_str()),
+ key.length(),
+ CreatePromise(result));
}
MOCK_METHOD2(BufferDecrypted, void(Decryptor::Status,
@@ -326,19 +351,15 @@ class AesDecryptorTest : public testing::Test {
}
}
- MOCK_METHOD2(OnSessionCreated,
- void(uint32 session_id, const std::string& web_session_id));
MOCK_METHOD3(OnSessionMessage,
- void(uint32 session_id,
+ void(const std::string& web_session_id,
const std::vector<uint8>& message,
- const std::string& default_url));
- MOCK_METHOD1(OnSessionReady, void(uint32 session_id));
- MOCK_METHOD1(OnSessionClosed, void(uint32 session_id));
- MOCK_METHOD3(OnSessionError,
- void(uint32 session_id, MediaKeys::KeyError, int system_code));
+ const GURL& destination_url));
+ MOCK_METHOD1(OnSessionClosed, void(const std::string& web_session_id));
AesDecryptor decryptor_;
AesDecryptor::DecryptCB decrypt_cb_;
+ std::string web_session_id_;
// Constants for testing.
const std::vector<uint8> original_data_;
@@ -348,101 +369,102 @@ class AesDecryptorTest : public testing::Test {
const std::vector<uint8> iv_;
const std::vector<SubsampleEntry> normal_subsample_entries_;
const std::vector<SubsampleEntry> no_subsample_entries_;
-
- // Generate new session ID every time
- uint32 next_session_id_;
};
TEST_F(AesDecryptorTest, CreateSessionWithNullInitData) {
- uint32 session_id = 8;
- EXPECT_CALL(*this, OnSessionMessage(session_id, IsEmpty(), ""));
- EXPECT_CALL(*this, OnSessionCreated(session_id, StrNe(std::string())));
- EXPECT_TRUE(decryptor_.CreateSession(session_id, std::string(), NULL, 0));
+ EXPECT_CALL(*this,
+ OnSessionMessage(IsNotEmpty(), IsEmpty(), GURL::EmptyGURL()));
+ decryptor_.CreateSession(std::string(),
+ NULL,
+ 0,
+ MediaKeys::TEMPORARY_SESSION,
+ CreateSessionPromise(RESOLVED));
}
TEST_F(AesDecryptorTest, MultipleCreateSession) {
- uint32 session_id1 = 10;
- EXPECT_CALL(*this, OnSessionMessage(session_id1, IsEmpty(), ""));
- EXPECT_CALL(*this, OnSessionCreated(session_id1, StrNe(std::string())));
- EXPECT_TRUE(decryptor_.CreateSession(session_id1, std::string(), NULL, 0));
-
- uint32 session_id2 = 11;
- EXPECT_CALL(*this, OnSessionMessage(session_id2, IsEmpty(), ""));
- EXPECT_CALL(*this, OnSessionCreated(session_id2, StrNe(std::string())));
- EXPECT_TRUE(decryptor_.CreateSession(session_id2, std::string(), NULL, 0));
-
- uint32 session_id3 = 23;
- EXPECT_CALL(*this, OnSessionMessage(session_id3, IsEmpty(), ""));
- EXPECT_CALL(*this, OnSessionCreated(session_id3, StrNe(std::string())));
- EXPECT_TRUE(decryptor_.CreateSession(session_id3, std::string(), NULL, 0));
+ EXPECT_CALL(*this,
+ OnSessionMessage(IsNotEmpty(), IsEmpty(), GURL::EmptyGURL()));
+ decryptor_.CreateSession(std::string(),
+ NULL,
+ 0,
+ MediaKeys::TEMPORARY_SESSION,
+ CreateSessionPromise(RESOLVED));
+
+ EXPECT_CALL(*this,
+ OnSessionMessage(IsNotEmpty(), IsEmpty(), GURL::EmptyGURL()));
+ decryptor_.CreateSession(std::string(),
+ NULL,
+ 0,
+ MediaKeys::TEMPORARY_SESSION,
+ CreateSessionPromise(RESOLVED));
+
+ EXPECT_CALL(*this,
+ OnSessionMessage(IsNotEmpty(), IsEmpty(), GURL::EmptyGURL()));
+ decryptor_.CreateSession(std::string(),
+ NULL,
+ 0,
+ MediaKeys::TEMPORARY_SESSION,
+ CreateSessionPromise(RESOLVED));
}
TEST_F(AesDecryptorTest, NormalDecryption) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, iv_, 0, no_subsample_entries_);
- DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS);
-}
-
-TEST_F(AesDecryptorTest, DecryptionWithOffset) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
- scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, iv_, 23, no_subsample_entries_);
+ encrypted_data_, key_id_, iv_, no_subsample_entries_);
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS);
}
TEST_F(AesDecryptorTest, UnencryptedFrame) {
// An empty iv string signals that the frame is unencrypted.
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- original_data_, key_id_, std::vector<uint8>(), 0, no_subsample_entries_);
+ original_data_, key_id_, std::vector<uint8>(), no_subsample_entries_);
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS);
}
TEST_F(AesDecryptorTest, WrongKey) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kWrongKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kWrongKeyAsJWK, RESOLVED);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, iv_, 0, no_subsample_entries_);
+ encrypted_data_, key_id_, iv_, no_subsample_entries_);
DecryptAndExpect(encrypted_buffer, original_data_, DATA_MISMATCH);
}
TEST_F(AesDecryptorTest, NoKey) {
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, iv_, 0, no_subsample_entries_);
+ encrypted_data_, key_id_, iv_, no_subsample_entries_);
EXPECT_CALL(*this, BufferDecrypted(AesDecryptor::kNoKey, IsNull()));
decryptor_.Decrypt(Decryptor::kVideo, encrypted_buffer, decrypt_cb_);
}
TEST_F(AesDecryptorTest, KeyReplacement) {
- uint32 session_id = CreateSession(key_id_);
+ std::string session_id = CreateSession(key_id_);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, iv_, 0, no_subsample_entries_);
+ encrypted_data_, key_id_, iv_, no_subsample_entries_);
- UpdateSessionAndExpect(session_id, kWrongKeyAsJWK, SESSION_READY);
+ UpdateSessionAndExpect(session_id, kWrongKeyAsJWK, RESOLVED);
ASSERT_NO_FATAL_FAILURE(DecryptAndExpect(
encrypted_buffer, original_data_, DATA_MISMATCH));
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
ASSERT_NO_FATAL_FAILURE(
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
}
TEST_F(AesDecryptorTest, WrongSizedKey) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kWrongSizedKeyAsJWK, SESSION_ERROR);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kWrongSizedKeyAsJWK, REJECTED);
}
TEST_F(AesDecryptorTest, MultipleKeysAndFrames) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, iv_, 10, no_subsample_entries_);
+ encrypted_data_, key_id_, iv_, no_subsample_entries_);
ASSERT_NO_FATAL_FAILURE(
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
- UpdateSessionAndExpect(session_id, kKey2AsJWK, SESSION_READY);
+ UpdateSessionAndExpect(session_id, kKey2AsJWK, RESOLVED);
// The first key is still available after we added a second key.
ASSERT_NO_FATAL_FAILURE(
@@ -454,7 +476,6 @@ TEST_F(AesDecryptorTest, MultipleKeysAndFrames) {
kEncryptedData2 + arraysize(kEncryptedData2)),
std::vector<uint8>(kKeyId2, kKeyId2 + arraysize(kKeyId2)),
std::vector<uint8>(kIv2, kIv2 + arraysize(kIv2)),
- 30,
no_subsample_entries_);
ASSERT_NO_FATAL_FAILURE(DecryptAndExpect(
encrypted_buffer,
@@ -464,43 +485,43 @@ TEST_F(AesDecryptorTest, MultipleKeysAndFrames) {
}
TEST_F(AesDecryptorTest, CorruptedIv) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
std::vector<uint8> bad_iv = iv_;
bad_iv[1]++;
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, bad_iv, 0, no_subsample_entries_);
+ encrypted_data_, key_id_, bad_iv, no_subsample_entries_);
DecryptAndExpect(encrypted_buffer, original_data_, DATA_MISMATCH);
}
TEST_F(AesDecryptorTest, CorruptedData) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
std::vector<uint8> bad_data = encrypted_data_;
bad_data[1]++;
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- bad_data, key_id_, iv_, 0, no_subsample_entries_);
+ bad_data, key_id_, iv_, no_subsample_entries_);
DecryptAndExpect(encrypted_buffer, original_data_, DATA_MISMATCH);
}
TEST_F(AesDecryptorTest, EncryptedAsUnencryptedFailure) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, std::vector<uint8>(), 0, no_subsample_entries_);
+ encrypted_data_, key_id_, std::vector<uint8>(), no_subsample_entries_);
DecryptAndExpect(encrypted_buffer, original_data_, DATA_MISMATCH);
}
TEST_F(AesDecryptorTest, SubsampleDecryption) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- subsample_encrypted_data_, key_id_, iv_, 0, normal_subsample_entries_);
+ subsample_encrypted_data_, key_id_, iv_, normal_subsample_entries_);
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS);
}
@@ -508,29 +529,29 @@ TEST_F(AesDecryptorTest, SubsampleDecryption) {
// expect to encounter this in the wild, but since the DecryptConfig doesn't
// disallow such a configuration, it should be covered.
TEST_F(AesDecryptorTest, SubsampleDecryptionWithOffset) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- subsample_encrypted_data_, key_id_, iv_, 23, normal_subsample_entries_);
+ subsample_encrypted_data_, key_id_, iv_, normal_subsample_entries_);
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS);
}
TEST_F(AesDecryptorTest, SubsampleWrongSize) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
std::vector<SubsampleEntry> subsample_entries_wrong_size(
kSubsampleEntriesWrongSize,
kSubsampleEntriesWrongSize + arraysize(kSubsampleEntriesWrongSize));
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- subsample_encrypted_data_, key_id_, iv_, 0, subsample_entries_wrong_size);
+ subsample_encrypted_data_, key_id_, iv_, subsample_entries_wrong_size);
DecryptAndExpect(encrypted_buffer, original_data_, DATA_MISMATCH);
}
TEST_F(AesDecryptorTest, SubsampleInvalidTotalSize) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
std::vector<SubsampleEntry> subsample_entries_invalid_total_size(
kSubsampleEntriesInvalidTotalSize,
@@ -538,45 +559,45 @@ TEST_F(AesDecryptorTest, SubsampleInvalidTotalSize) {
arraysize(kSubsampleEntriesInvalidTotalSize));
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- subsample_encrypted_data_, key_id_, iv_, 0,
+ subsample_encrypted_data_, key_id_, iv_,
subsample_entries_invalid_total_size);
DecryptAndExpect(encrypted_buffer, original_data_, DECRYPT_ERROR);
}
// No cypher bytes in any of the subsamples.
TEST_F(AesDecryptorTest, SubsampleClearBytesOnly) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
std::vector<SubsampleEntry> clear_only_subsample_entries(
kSubsampleEntriesClearOnly,
kSubsampleEntriesClearOnly + arraysize(kSubsampleEntriesClearOnly));
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- original_data_, key_id_, iv_, 0, clear_only_subsample_entries);
+ original_data_, key_id_, iv_, clear_only_subsample_entries);
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS);
}
// No clear bytes in any of the subsamples.
TEST_F(AesDecryptorTest, SubsampleCypherBytesOnly) {
- uint32 session_id = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ std::string session_id = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
std::vector<SubsampleEntry> cypher_only_subsample_entries(
kSubsampleEntriesCypherOnly,
kSubsampleEntriesCypherOnly + arraysize(kSubsampleEntriesCypherOnly));
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, iv_, 0, cypher_only_subsample_entries);
+ encrypted_data_, key_id_, iv_, cypher_only_subsample_entries);
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS);
}
TEST_F(AesDecryptorTest, ReleaseSession) {
- uint32 session_id = CreateSession(key_id_);
+ std::string session_id = CreateSession(key_id_);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, iv_, 0, no_subsample_entries_);
+ encrypted_data_, key_id_, iv_, no_subsample_entries_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
ASSERT_NO_FATAL_FAILURE(
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
@@ -584,11 +605,11 @@ TEST_F(AesDecryptorTest, ReleaseSession) {
}
TEST_F(AesDecryptorTest, NoKeyAfterReleaseSession) {
- uint32 session_id = CreateSession(key_id_);
+ std::string session_id = CreateSession(key_id_);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, iv_, 0, no_subsample_entries_);
+ encrypted_data_, key_id_, iv_, no_subsample_entries_);
- UpdateSessionAndExpect(session_id, kKeyAsJWK, SESSION_READY);
+ UpdateSessionAndExpect(session_id, kKeyAsJWK, RESOLVED);
ASSERT_NO_FATAL_FAILURE(
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
@@ -598,18 +619,18 @@ TEST_F(AesDecryptorTest, NoKeyAfterReleaseSession) {
}
TEST_F(AesDecryptorTest, LatestKeyUsed) {
- uint32 session_id1 = CreateSession(key_id_);
+ std::string session_id1 = CreateSession(key_id_);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, iv_, 0, no_subsample_entries_);
+ encrypted_data_, key_id_, iv_, no_subsample_entries_);
// Add alternate key, buffer should not be decoded properly.
- UpdateSessionAndExpect(session_id1, kKeyAlternateAsJWK, SESSION_READY);
+ UpdateSessionAndExpect(session_id1, kKeyAlternateAsJWK, RESOLVED);
ASSERT_NO_FATAL_FAILURE(
DecryptAndExpect(encrypted_buffer, original_data_, DATA_MISMATCH));
// Create a second session with a correct key value for key_id_.
- uint32 session_id2 = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id2, kKeyAsJWK, SESSION_READY);
+ std::string session_id2 = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id2, kKeyAsJWK, RESOLVED);
// Should be able to decode with latest key.
ASSERT_NO_FATAL_FAILURE(
@@ -617,16 +638,16 @@ TEST_F(AesDecryptorTest, LatestKeyUsed) {
}
TEST_F(AesDecryptorTest, LatestKeyUsedAfterReleaseSession) {
- uint32 session_id1 = CreateSession(key_id_);
+ std::string session_id1 = CreateSession(key_id_);
scoped_refptr<DecoderBuffer> encrypted_buffer = CreateEncryptedBuffer(
- encrypted_data_, key_id_, iv_, 0, no_subsample_entries_);
- UpdateSessionAndExpect(session_id1, kKeyAsJWK, SESSION_READY);
+ encrypted_data_, key_id_, iv_, no_subsample_entries_);
+ UpdateSessionAndExpect(session_id1, kKeyAsJWK, RESOLVED);
ASSERT_NO_FATAL_FAILURE(
DecryptAndExpect(encrypted_buffer, original_data_, SUCCESS));
// Create a second session with a different key value for key_id_.
- uint32 session_id2 = CreateSession(key_id_);
- UpdateSessionAndExpect(session_id2, kKeyAlternateAsJWK, SESSION_READY);
+ std::string session_id2 = CreateSession(key_id_);
+ UpdateSessionAndExpect(session_id2, kKeyAlternateAsJWK, RESOLVED);
// Should not be able to decode with new key.
ASSERT_NO_FATAL_FAILURE(
@@ -639,7 +660,7 @@ TEST_F(AesDecryptorTest, LatestKeyUsedAfterReleaseSession) {
}
TEST_F(AesDecryptorTest, JWKKey) {
- uint32 session_id = CreateSession(key_id_);
+ std::string session_id = CreateSession(key_id_);
// Try a simple JWK key (i.e. not in a set)
const std::string kJwkSimple =
@@ -648,7 +669,7 @@ TEST_F(AesDecryptorTest, JWKKey) {
" \"kid\": \"AAECAwQFBgcICQoLDA0ODxAREhM\","
" \"k\": \"FBUWFxgZGhscHR4fICEiIw\""
"}";
- UpdateSessionAndExpect(session_id, kJwkSimple, SESSION_ERROR);
+ UpdateSessionAndExpect(session_id, kJwkSimple, REJECTED);
// Try a key list with multiple entries.
const std::string kJwksMultipleEntries =
@@ -666,40 +687,38 @@ TEST_F(AesDecryptorTest, JWKKey) {
" }"
" ]"
"}";
- UpdateSessionAndExpect(session_id, kJwksMultipleEntries, SESSION_READY);
+ UpdateSessionAndExpect(session_id, kJwksMultipleEntries, RESOLVED);
// Try a key with no spaces and some \n plus additional fields.
const std::string kJwksNoSpaces =
"\n\n{\"something\":1,\"keys\":[{\n\n\"kty\":\"oct\",\"alg\":\"A128KW\","
"\"kid\":\"AAECAwQFBgcICQoLDA0ODxAREhM\",\"k\":\"GawgguFyGrWKav7AX4VKUg"
"\",\"foo\":\"bar\"}]}\n\n";
- UpdateSessionAndExpect(session_id, kJwksNoSpaces, SESSION_READY);
+ UpdateSessionAndExpect(session_id, kJwksNoSpaces, RESOLVED);
// Try some non-ASCII characters.
- UpdateSessionAndExpect(session_id,
- "This is not ASCII due to \xff\xfe\xfd in it.",
- SESSION_ERROR);
+ UpdateSessionAndExpect(
+ session_id, "This is not ASCII due to \xff\xfe\xfd in it.", REJECTED);
// Try a badly formatted key. Assume that the JSON parser is fully tested,
// so we won't try a lot of combinations. However, need a test to ensure
// that the code doesn't crash if invalid JSON received.
- UpdateSessionAndExpect(session_id, "This is not a JSON key.", SESSION_ERROR);
+ UpdateSessionAndExpect(session_id, "This is not a JSON key.", REJECTED);
// Try passing some valid JSON that is not a dictionary at the top level.
- UpdateSessionAndExpect(session_id, "40", SESSION_ERROR);
+ UpdateSessionAndExpect(session_id, "40", REJECTED);
// Try an empty dictionary.
- UpdateSessionAndExpect(session_id, "{ }", SESSION_ERROR);
+ UpdateSessionAndExpect(session_id, "{ }", REJECTED);
// Try an empty 'keys' dictionary.
- UpdateSessionAndExpect(session_id, "{ \"keys\": [] }", SESSION_ERROR);
+ UpdateSessionAndExpect(session_id, "{ \"keys\": [] }", REJECTED);
// Try with 'keys' not a dictionary.
- UpdateSessionAndExpect(session_id, "{ \"keys\":\"1\" }", SESSION_ERROR);
+ UpdateSessionAndExpect(session_id, "{ \"keys\":\"1\" }", REJECTED);
// Try with 'keys' a list of integers.
- UpdateSessionAndExpect(
- session_id, "{ \"keys\": [ 1, 2, 3 ] }", SESSION_ERROR);
+ UpdateSessionAndExpect(session_id, "{ \"keys\": [ 1, 2, 3 ] }", REJECTED);
// Try padding(=) at end of 'k' base64 string.
const std::string kJwksWithPaddedKey =
@@ -712,7 +731,7 @@ TEST_F(AesDecryptorTest, JWKKey) {
" }"
" ]"
"}";
- UpdateSessionAndExpect(session_id, kJwksWithPaddedKey, SESSION_ERROR);
+ UpdateSessionAndExpect(session_id, kJwksWithPaddedKey, REJECTED);
// Try padding(=) at end of 'kid' base64 string.
const std::string kJwksWithPaddedKeyId =
@@ -725,7 +744,7 @@ TEST_F(AesDecryptorTest, JWKKey) {
" }"
" ]"
"}";
- UpdateSessionAndExpect(session_id, kJwksWithPaddedKeyId, SESSION_ERROR);
+ UpdateSessionAndExpect(session_id, kJwksWithPaddedKeyId, REJECTED);
// Try a key with invalid base64 encoding.
const std::string kJwksWithInvalidBase64 =
@@ -738,7 +757,7 @@ TEST_F(AesDecryptorTest, JWKKey) {
" }"
" ]"
"}";
- UpdateSessionAndExpect(session_id, kJwksWithInvalidBase64, SESSION_ERROR);
+ UpdateSessionAndExpect(session_id, kJwksWithInvalidBase64, REJECTED);
// Try a 3-byte 'kid' where no base64 padding is required.
// |kJwksMultipleEntries| above has 2 'kid's that require 1 and 2 padding
@@ -753,7 +772,7 @@ TEST_F(AesDecryptorTest, JWKKey) {
" }"
" ]"
"}";
- UpdateSessionAndExpect(session_id, kJwksWithNoPadding, SESSION_READY);
+ UpdateSessionAndExpect(session_id, kJwksWithNoPadding, RESOLVED);
// Empty key id.
const std::string kJwksWithEmptyKeyId =
@@ -766,7 +785,7 @@ TEST_F(AesDecryptorTest, JWKKey) {
" }"
" ]"
"}";
- UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, SESSION_ERROR);
+ UpdateSessionAndExpect(session_id, kJwksWithEmptyKeyId, REJECTED);
ReleaseSession(session_id);
}