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