Replace MockCDM with Android Smart Pointer to MockCDM
Merge from widevine repo of http://go/wvgerrit/14742 The CDM object can no longer be created on the stack because it inherits from RefBase. This caused some unit tests to hang in the MockCDM destructor. bug: 21881298 Change-Id: Ieeb7863031609f12ad3d9188c4525aa2fa1eb736
This commit is contained in:
@@ -51,7 +51,7 @@ class WVCryptoPluginTest : public Test {
|
||||
};
|
||||
|
||||
TEST_F(WVCryptoPluginTest, CorrectlyReportsSecureBuffers) {
|
||||
StrictMock<MockCDM> cdm;
|
||||
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
|
||||
|
||||
CdmQueryMap l1Map;
|
||||
l1Map[QUERY_KEY_SECURITY_LEVEL] = QUERY_VALUE_SECURITY_LEVEL_L1;
|
||||
@@ -59,17 +59,17 @@ TEST_F(WVCryptoPluginTest, CorrectlyReportsSecureBuffers) {
|
||||
l3Map[QUERY_KEY_SECURITY_LEVEL] = QUERY_VALUE_SECURITY_LEVEL_L3;
|
||||
|
||||
// Provide the expected behavior for IsOpenSession
|
||||
EXPECT_CALL(cdm, IsOpenSession(_))
|
||||
EXPECT_CALL(*cdm, IsOpenSession(_))
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
// Specify the expected calls to QuerySessionStatus
|
||||
EXPECT_CALL(cdm, QuerySessionStatus(_, _))
|
||||
EXPECT_CALL(*cdm, QuerySessionStatus(_, _))
|
||||
.WillOnce(DoAll(SetArgPointee<1>(l1Map),
|
||||
Return(wvcdm::NO_ERROR)))
|
||||
.WillOnce(DoAll(SetArgPointee<1>(l3Map),
|
||||
Return(wvcdm::NO_ERROR)));
|
||||
|
||||
WVCryptoPlugin plugin(sessionId, kSessionIdSize, &cdm);
|
||||
WVCryptoPlugin plugin(sessionId, kSessionIdSize, cdm.get());
|
||||
|
||||
EXPECT_TRUE(plugin.requiresSecureDecoderComponent("video/mp4")) <<
|
||||
"WVCryptoPlugin incorrectly allows an insecure video decoder on L1";
|
||||
@@ -148,7 +148,7 @@ class CDPMatcherFactory {
|
||||
};
|
||||
|
||||
TEST_F(WVCryptoPluginTest, AttemptsToDecrypt) {
|
||||
StrictMock<MockCDM> cdm;
|
||||
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
|
||||
|
||||
uint8_t keyId[KEY_ID_SIZE];
|
||||
uint8_t baseIv[KEY_IV_SIZE];
|
||||
@@ -190,7 +190,7 @@ TEST_F(WVCryptoPluginTest, AttemptsToDecrypt) {
|
||||
CDPMatcherFactory ParamsAre = CDPMatcherFactory(false, keyId, out, kDataSize);
|
||||
|
||||
// Provide the expected behavior for IsOpenSession
|
||||
EXPECT_CALL(cdm, IsOpenSession(_))
|
||||
EXPECT_CALL(*cdm, IsOpenSession(_))
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
// Specify the expected calls to Decrypt
|
||||
@@ -198,55 +198,55 @@ TEST_F(WVCryptoPluginTest, AttemptsToDecrypt) {
|
||||
InSequence calls;
|
||||
|
||||
// SubSample 0
|
||||
EXPECT_CALL(cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
EXPECT_CALL(*cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
true,
|
||||
ParamsAre(true, in, 16, iv[0], 0, 0,
|
||||
OEMCrypto_FirstSubsample)))
|
||||
.Times(1);
|
||||
|
||||
// SubSample 1
|
||||
EXPECT_CALL(cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
EXPECT_CALL(*cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
true,
|
||||
ParamsAre(false, in + 16, 16, iv[1], 0, 16, 0)))
|
||||
.Times(1);
|
||||
|
||||
EXPECT_CALL(cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
EXPECT_CALL(*cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
true,
|
||||
ParamsAre(true, in + 32, 16, iv[1], 0, 32, 0)))
|
||||
.Times(1);
|
||||
|
||||
// SubSample 2
|
||||
EXPECT_CALL(cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
EXPECT_CALL(*cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
true,
|
||||
ParamsAre(true, in + 48, 8, iv[2], 0, 48, 0)))
|
||||
.Times(1);
|
||||
|
||||
// SubSample 3
|
||||
EXPECT_CALL(cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
EXPECT_CALL(*cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
true,
|
||||
ParamsAre(false, in + 56, 29, iv[2], 0, 56, 0)))
|
||||
.Times(1);
|
||||
|
||||
EXPECT_CALL(cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
EXPECT_CALL(*cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
true,
|
||||
ParamsAre(true, in + 85, 24, iv[2], 8, 85, 0)))
|
||||
.Times(1);
|
||||
|
||||
// SubSample 4
|
||||
EXPECT_CALL(cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
EXPECT_CALL(*cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
true,
|
||||
ParamsAre(true, in + 109, 60, iv[3], 0, 109, 0)))
|
||||
.Times(1);
|
||||
|
||||
// SubSample 5
|
||||
EXPECT_CALL(cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
EXPECT_CALL(*cdm, Decrypt(ElementsAreArray(sessionId, kSessionIdSize),
|
||||
true,
|
||||
ParamsAre(true, in + 169, 16, iv[4], 12, 169,
|
||||
OEMCrypto_LastSubsample)))
|
||||
.Times(1);
|
||||
}
|
||||
|
||||
WVCryptoPlugin plugin(sessionId, kSessionIdSize, &cdm);
|
||||
WVCryptoPlugin plugin(sessionId, kSessionIdSize, cdm.get());
|
||||
AString errorDetailMessage;
|
||||
|
||||
ssize_t res = plugin.decrypt(false, keyId, iv[0], CryptoPlugin::kMode_AES_CTR,
|
||||
@@ -260,7 +260,7 @@ TEST_F(WVCryptoPluginTest, AttemptsToDecrypt) {
|
||||
}
|
||||
|
||||
TEST_F(WVCryptoPluginTest, CommunicatesSecureBufferRequest) {
|
||||
StrictMock<MockCDM> cdm;
|
||||
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
|
||||
|
||||
uint8_t keyId[KEY_ID_SIZE];
|
||||
uint8_t iv[KEY_IV_SIZE];
|
||||
@@ -282,7 +282,7 @@ TEST_F(WVCryptoPluginTest, CommunicatesSecureBufferRequest) {
|
||||
subSamples[0].mNumBytesOfEncryptedData = 16;
|
||||
|
||||
// Provide the expected behavior for IsOpenSession
|
||||
EXPECT_CALL(cdm, IsOpenSession(_))
|
||||
EXPECT_CALL(*cdm, IsOpenSession(_))
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
// Specify the expected calls to Decrypt
|
||||
@@ -291,14 +291,14 @@ TEST_F(WVCryptoPluginTest, CommunicatesSecureBufferRequest) {
|
||||
|
||||
typedef CdmDecryptionParameters CDP;
|
||||
|
||||
EXPECT_CALL(cdm, Decrypt(_, _, Field(&CDP::is_secure, false)))
|
||||
EXPECT_CALL(*cdm, Decrypt(_, _, Field(&CDP::is_secure, false)))
|
||||
.Times(2);
|
||||
|
||||
EXPECT_CALL(cdm, Decrypt(_, _, Field(&CDP::is_secure, true)))
|
||||
EXPECT_CALL(*cdm, Decrypt(_, _, Field(&CDP::is_secure, true)))
|
||||
.Times(2);
|
||||
}
|
||||
|
||||
WVCryptoPlugin plugin(sessionId, kSessionIdSize, &cdm);
|
||||
WVCryptoPlugin plugin(sessionId, kSessionIdSize, cdm.get());
|
||||
AString errorDetailMessage;
|
||||
|
||||
ssize_t res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR,
|
||||
@@ -318,7 +318,7 @@ TEST_F(WVCryptoPluginTest, CommunicatesSecureBufferRequest) {
|
||||
}
|
||||
|
||||
TEST_F(WVCryptoPluginTest, SetsFlagsForMinimumSubsampleRuns) {
|
||||
MockCDM cdm;
|
||||
android::sp<MockCDM> cdm = new MockCDM();
|
||||
|
||||
uint8_t keyId[KEY_ID_SIZE];
|
||||
uint8_t iv[KEY_IV_SIZE];
|
||||
@@ -348,7 +348,7 @@ TEST_F(WVCryptoPluginTest, SetsFlagsForMinimumSubsampleRuns) {
|
||||
mixedSubSamples[0].mNumBytesOfEncryptedData = 8;
|
||||
|
||||
// Provide the expected behavior for IsOpenSession
|
||||
EXPECT_CALL(cdm, IsOpenSession(_))
|
||||
EXPECT_CALL(*cdm, IsOpenSession(_))
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
// Specify the expected calls to Decrypt
|
||||
@@ -357,21 +357,21 @@ TEST_F(WVCryptoPluginTest, SetsFlagsForMinimumSubsampleRuns) {
|
||||
|
||||
typedef CdmDecryptionParameters CDP;
|
||||
|
||||
EXPECT_CALL(cdm, Decrypt(_, _, Field(&CDP::subsample_flags,
|
||||
EXPECT_CALL(*cdm, Decrypt(_, _, Field(&CDP::subsample_flags,
|
||||
OEMCrypto_FirstSubsample |
|
||||
OEMCrypto_LastSubsample)))
|
||||
.Times(2);
|
||||
|
||||
EXPECT_CALL(cdm, Decrypt(_, _, Field(&CDP::subsample_flags,
|
||||
EXPECT_CALL(*cdm, Decrypt(_, _, Field(&CDP::subsample_flags,
|
||||
OEMCrypto_FirstSubsample)))
|
||||
.Times(1);
|
||||
|
||||
EXPECT_CALL(cdm, Decrypt(_, _, Field(&CDP::subsample_flags,
|
||||
EXPECT_CALL(*cdm, Decrypt(_, _, Field(&CDP::subsample_flags,
|
||||
OEMCrypto_LastSubsample)))
|
||||
.Times(1);
|
||||
}
|
||||
|
||||
WVCryptoPlugin plugin(sessionId, kSessionIdSize, &cdm);
|
||||
WVCryptoPlugin plugin(sessionId, kSessionIdSize, cdm.get());
|
||||
AString errorDetailMessage;
|
||||
|
||||
ssize_t res = plugin.decrypt(false, keyId, iv, CryptoPlugin::kMode_AES_CTR,
|
||||
@@ -400,7 +400,7 @@ TEST_F(WVCryptoPluginTest, SetsFlagsForMinimumSubsampleRuns) {
|
||||
}
|
||||
|
||||
TEST_F(WVCryptoPluginTest, AllowsSessionIdChanges) {
|
||||
StrictMock<MockCDM> cdm;
|
||||
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
|
||||
|
||||
uint8_t keyId[KEY_ID_SIZE];
|
||||
uint8_t iv[KEY_IV_SIZE];
|
||||
@@ -429,24 +429,24 @@ TEST_F(WVCryptoPluginTest, AllowsSessionIdChanges) {
|
||||
sessionId2Vector.appendArray(sessionId2, kSessionIdSize);
|
||||
|
||||
// Provide the expected behavior for IsOpenSession
|
||||
EXPECT_CALL(cdm, IsOpenSession(_))
|
||||
EXPECT_CALL(*cdm, IsOpenSession(_))
|
||||
.WillRepeatedly(Return(true));
|
||||
|
||||
// Specify the expected calls to Decrypt
|
||||
{
|
||||
InSequence calls;
|
||||
|
||||
EXPECT_CALL(cdm,
|
||||
EXPECT_CALL(*cdm,
|
||||
Decrypt(ElementsAreArray(sessionId, kSessionIdSize), _, _))
|
||||
.Times(2);
|
||||
|
||||
EXPECT_CALL(cdm,
|
||||
EXPECT_CALL(*cdm,
|
||||
Decrypt(ElementsAreArray(sessionId2, kSessionIdSize), _, _))
|
||||
.Times(2);
|
||||
}
|
||||
|
||||
uint8_t blank[1]; // Some compilers will not accept 0.
|
||||
WVCryptoPlugin plugin(blank, 0, &cdm);
|
||||
WVCryptoPlugin plugin(blank, 0, cdm.get());
|
||||
AString errorDetailMessage;
|
||||
ssize_t res;
|
||||
|
||||
@@ -470,7 +470,7 @@ TEST_F(WVCryptoPluginTest, AllowsSessionIdChanges) {
|
||||
}
|
||||
|
||||
TEST_F(WVCryptoPluginTest, DisallowsUnopenedSessionIdChanges) {
|
||||
StrictMock<MockCDM> cdm;
|
||||
android::sp<StrictMock<MockCDM>> cdm = new StrictMock<MockCDM>();
|
||||
|
||||
uint8_t blank[1]; // Some compilers will not accept 0.
|
||||
Vector<uint8_t> sessionIdVector;
|
||||
@@ -480,15 +480,15 @@ TEST_F(WVCryptoPluginTest, DisallowsUnopenedSessionIdChanges) {
|
||||
{
|
||||
InSequence calls;
|
||||
|
||||
EXPECT_CALL(cdm, IsOpenSession(ElementsAreArray(blank, 0)))
|
||||
EXPECT_CALL(*cdm, IsOpenSession(ElementsAreArray(blank, 0)))
|
||||
.WillOnce(Return(false));
|
||||
|
||||
EXPECT_CALL(cdm, IsOpenSession(ElementsAreArray(sessionId, kSessionIdSize)))
|
||||
EXPECT_CALL(*cdm, IsOpenSession(ElementsAreArray(sessionId, kSessionIdSize)))
|
||||
.WillOnce(Return(false))
|
||||
.WillOnce(Return(true));
|
||||
}
|
||||
|
||||
WVCryptoPlugin plugin(blank, 0, &cdm);
|
||||
WVCryptoPlugin plugin(blank, 0, cdm.get());
|
||||
|
||||
ssize_t res;
|
||||
res = plugin.setMediaDrmSession(sessionIdVector);
|
||||
|
||||
Reference in New Issue
Block a user