Merge "Restore WVCryptoPlugin Unit Tests" into nyc-dev
This commit is contained in:
@@ -86,8 +86,10 @@ class CDPMatcherFactory {
|
||||
// Some values do not change over the course of the test. To avoid having
|
||||
// to re-specify them at every call site, we pass them into the factory
|
||||
// constructor.
|
||||
CDPMatcherFactory(bool isSecure, uint8_t* keyId, void* out, size_t outLen)
|
||||
: mIsSecure(isSecure), mKeyId(keyId), mOut(out), mOutLen(outLen) {}
|
||||
CDPMatcherFactory(bool isSecure, CdmCipherMode cipherMode, uint8_t* keyId,
|
||||
void* out, size_t outLen)
|
||||
: mIsSecure(isSecure), mCipherMode(cipherMode), mKeyId(keyId),
|
||||
mOut(out), mOutLen(outLen) {}
|
||||
|
||||
Matcher<const CdmDecryptionParameters&> operator()(bool isEncrypted,
|
||||
uint8_t* in,
|
||||
@@ -96,8 +98,9 @@ class CDPMatcherFactory {
|
||||
size_t blockOffset,
|
||||
size_t outOffset,
|
||||
uint8_t flags) const {
|
||||
return Truly(CDPMatcher(mIsSecure, mKeyId, mOut, mOutLen, isEncrypted,
|
||||
in, inLen, iv, blockOffset, outOffset, flags));
|
||||
return Truly(CDPMatcher(mIsSecure, mCipherMode, mKeyId, mOut, mOutLen,
|
||||
isEncrypted, in, inLen, iv, blockOffset,
|
||||
outOffset, flags));
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -106,15 +109,18 @@ class CDPMatcherFactory {
|
||||
// time.
|
||||
class CDPMatcher {
|
||||
public:
|
||||
CDPMatcher(bool isSecure, uint8_t* keyId, void* out, size_t outLen,
|
||||
bool isEncrypted, uint8_t* in, size_t inLen, uint8_t* iv,
|
||||
size_t blockOffset, size_t outOffset, uint8_t flags)
|
||||
: mIsSecure(isSecure), mKeyId(keyId), mOut(out), mOutLen(outLen),
|
||||
mIsEncrypted(isEncrypted), mIn(in), mInLen(inLen), mIv(iv),
|
||||
mBlockOffset(blockOffset), mOutOffset(outOffset), mFlags(flags) {}
|
||||
CDPMatcher(bool isSecure, CdmCipherMode cipherMode, uint8_t* keyId,
|
||||
void* out, size_t outLen, bool isEncrypted, uint8_t* in,
|
||||
size_t inLen, uint8_t* iv, size_t blockOffset,
|
||||
size_t outOffset, uint8_t flags)
|
||||
: mIsSecure(isSecure), mCipherMode(cipherMode), mKeyId(keyId),
|
||||
mOut(out), mOutLen(outLen), mIsEncrypted(isEncrypted), mIn(in),
|
||||
mInLen(inLen), mIv(iv), mBlockOffset(blockOffset),
|
||||
mOutOffset(outOffset), mFlags(flags) {}
|
||||
|
||||
bool operator()(const CdmDecryptionParameters& params) const {
|
||||
return params.is_secure == mIsSecure &&
|
||||
params.cipher_mode == mCipherMode &&
|
||||
Value(*params.key_id, ElementsAreArray(mKeyId, KEY_ID_SIZE)) &&
|
||||
params.decrypt_buffer == mOut &&
|
||||
params.decrypt_buffer_length == mOutLen &&
|
||||
@@ -129,6 +135,7 @@ class CDPMatcherFactory {
|
||||
|
||||
private:
|
||||
bool mIsSecure;
|
||||
CdmCipherMode mCipherMode;
|
||||
uint8_t* mKeyId;
|
||||
void* mOut;
|
||||
size_t mOutLen;
|
||||
@@ -142,13 +149,12 @@ class CDPMatcherFactory {
|
||||
};
|
||||
|
||||
bool mIsSecure;
|
||||
CdmCipherMode mCipherMode;
|
||||
uint8_t* mKeyId;
|
||||
void* mOut;
|
||||
size_t mOutLen;
|
||||
};
|
||||
|
||||
#if 0 // FIXME - handle pattern
|
||||
|
||||
TEST_F(WVCryptoPluginTest, AttemptsToDecrypt) {
|
||||
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
|
||||
|
||||
@@ -189,7 +195,8 @@ TEST_F(WVCryptoPluginTest, AttemptsToDecrypt) {
|
||||
memcpy(iv[4], baseIv, sizeof(baseIv));
|
||||
iv[4][15] = 7;
|
||||
|
||||
CDPMatcherFactory ParamsAre = CDPMatcherFactory(false, keyId, out, kDataSize);
|
||||
CDPMatcherFactory ParamsAre =
|
||||
CDPMatcherFactory(false, kCipherModeCtr, keyId, out, kDataSize);
|
||||
|
||||
// Provide the expected behavior for IsOpenSession
|
||||
EXPECT_CALL(*cdm, IsOpenSession(_))
|
||||
@@ -249,11 +256,12 @@ TEST_F(WVCryptoPluginTest, AttemptsToDecrypt) {
|
||||
}
|
||||
|
||||
WVCryptoPlugin plugin(sessionId, kSessionIdSize, cdm.get());
|
||||
android::CryptoPlugin::Pattern noPattern = {0};
|
||||
AString errorDetailMessage;
|
||||
|
||||
ssize_t res = plugin.decrypt(false, keyId, iv[0], CryptoPlugin::kMode_AES_CTR,
|
||||
in, subSamples, kSubSampleCount, out,
|
||||
&errorDetailMessage);
|
||||
noPattern, in, subSamples, kSubSampleCount,
|
||||
out, &errorDetailMessage);
|
||||
|
||||
EXPECT_EQ(static_cast<ssize_t>(kDataSize), res) <<
|
||||
"WVCryptoPlugin decrypted the wrong number of bytes";
|
||||
@@ -302,18 +310,20 @@ TEST_F(WVCryptoPluginTest, CommunicatesSecureBufferRequest) {
|
||||
}
|
||||
|
||||
WVCryptoPlugin plugin(sessionId, kSessionIdSize, cdm.get());
|
||||
android::CryptoPlugin::Pattern noPattern = {0};
|
||||
AString errorDetailMessage;
|
||||
|
||||
ssize_t res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR,
|
||||
in, subSamples, kSubSampleCount, out,
|
||||
&errorDetailMessage);
|
||||
noPattern, in, subSamples, kSubSampleCount,
|
||||
out, &errorDetailMessage);
|
||||
ASSERT_GE(res, 0) <<
|
||||
"WVCryptoPlugin returned an error";
|
||||
EXPECT_EQ(0u, errorDetailMessage.size()) <<
|
||||
"WVCryptoPlugin reported a detailed error message.";
|
||||
|
||||
res = plugin.decrypt(true, keyId, iv, CryptoPlugin::kMode_AES_CTR, in,
|
||||
subSamples, kSubSampleCount, out, &errorDetailMessage);
|
||||
res = plugin.decrypt(true, keyId, iv, CryptoPlugin::kMode_AES_CTR,
|
||||
noPattern, in, subSamples, kSubSampleCount, out,
|
||||
&errorDetailMessage);
|
||||
ASSERT_GE(res, 0) <<
|
||||
"WVCryptoPlugin returned an error";
|
||||
EXPECT_EQ(0u, errorDetailMessage.size()) <<
|
||||
@@ -375,26 +385,27 @@ TEST_F(WVCryptoPluginTest, SetsFlagsForMinimumSubsampleRuns) {
|
||||
}
|
||||
|
||||
WVCryptoPlugin plugin(sessionId, kSessionIdSize, cdm.get());
|
||||
android::CryptoPlugin::Pattern noPattern = {0};
|
||||
AString errorDetailMessage;
|
||||
|
||||
ssize_t res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR,
|
||||
in, clearSubSamples, kSubSampleCount, out,
|
||||
&errorDetailMessage);
|
||||
noPattern, in, clearSubSamples,
|
||||
kSubSampleCount, out, &errorDetailMessage);
|
||||
ASSERT_GE(res, 0) <<
|
||||
"WVCryptoPlugin returned an error";
|
||||
EXPECT_EQ(0u, errorDetailMessage.size()) <<
|
||||
"WVCryptoPlugin reported a detailed error message.";
|
||||
|
||||
res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR, in,
|
||||
encryptedSubSamples, kSubSampleCount, out,
|
||||
&errorDetailMessage);
|
||||
res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR,
|
||||
noPattern, in, encryptedSubSamples, kSubSampleCount,
|
||||
out, &errorDetailMessage);
|
||||
ASSERT_GE(res, 0) <<
|
||||
"WVCryptoPlugin returned an error";
|
||||
EXPECT_EQ(0u, errorDetailMessage.size()) <<
|
||||
"WVCryptoPlugin reported a detailed error message.";
|
||||
|
||||
res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR, in,
|
||||
mixedSubSamples, kSubSampleCount, out,
|
||||
res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR,
|
||||
noPattern, in, mixedSubSamples, kSubSampleCount, out,
|
||||
&errorDetailMessage);
|
||||
ASSERT_GE(res, 0) <<
|
||||
"WVCryptoPlugin returned an error";
|
||||
@@ -450,13 +461,15 @@ TEST_F(WVCryptoPluginTest, AllowsSessionIdChanges) {
|
||||
|
||||
uint8_t blank[1]; // Some compilers will not accept 0.
|
||||
WVCryptoPlugin plugin(blank, 0, cdm.get());
|
||||
android::CryptoPlugin::Pattern noPattern = {0};
|
||||
AString errorDetailMessage;
|
||||
ssize_t res;
|
||||
|
||||
res = plugin.setMediaDrmSession(sessionIdVector);
|
||||
EXPECT_EQ(android::NO_ERROR, res);
|
||||
res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR, in,
|
||||
subSamples, kSubSampleCount, out, &errorDetailMessage);
|
||||
res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR,
|
||||
noPattern, in, subSamples, kSubSampleCount, out,
|
||||
&errorDetailMessage);
|
||||
EXPECT_GE(res, 0) <<
|
||||
"WVCryptoPlugin returned an error";
|
||||
EXPECT_EQ(0u, errorDetailMessage.size()) <<
|
||||
@@ -464,16 +477,15 @@ TEST_F(WVCryptoPluginTest, AllowsSessionIdChanges) {
|
||||
|
||||
res = plugin.setMediaDrmSession(sessionId2Vector);
|
||||
EXPECT_EQ(android::NO_ERROR, res);
|
||||
res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR, in,
|
||||
subSamples, kSubSampleCount, out, &errorDetailMessage);
|
||||
res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR,
|
||||
noPattern, in, subSamples, kSubSampleCount, out,
|
||||
&errorDetailMessage);
|
||||
EXPECT_GE(res, 0) <<
|
||||
"WVCryptoPlugin returned an error";
|
||||
EXPECT_EQ(0u, errorDetailMessage.size()) <<
|
||||
"WVCryptoPlugin reported a detailed error message.";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
TEST_F(WVCryptoPluginTest, DisallowsUnopenedSessionIdChanges) {
|
||||
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user