Refactor WvCdmEventListener and some cleanups

Bug: 19771437

It is a merge of below CLs from Widevine CDM repo:

Clean up CdmSession and PolicyEngine testing injection
https://widevine-internal-review.googlesource.com/#/c/13700

Refactor WvCdmEventListener handling
https://widevine-internal-review.googlesource.com/#/c/13702

Change-Id: I356b90000c056113d394926862b859aab380d305
This commit is contained in:
KongQun Yang
2015-03-16 19:46:11 -07:00
parent 69d7ffb22d
commit fddbc89136
16 changed files with 237 additions and 494 deletions

View File

@@ -26,8 +26,9 @@ using namespace wvdrm;
class MockCDM : public WvContentDecryptionModule {
public:
MOCK_METHOD3(OpenSession, CdmResponseType(const CdmKeySystem&,
MOCK_METHOD4(OpenSession, CdmResponseType(const CdmKeySystem&,
CdmClientPropertySet*,
WvCdmEventListener*,
CdmSessionId*));
MOCK_METHOD1(CloseSession, CdmResponseType(const CdmSessionId&));
@@ -79,12 +80,6 @@ class MockCDM : public WvContentDecryptionModule {
MOCK_METHOD1(ReleaseUsageInfo,
CdmResponseType(const CdmUsageInfoReleaseMessage&));
MOCK_METHOD2(AttachEventListener, bool(const CdmSessionId&,
WvCdmEventListener*));
MOCK_METHOD2(DetachEventListener, bool(const CdmSessionId&,
WvCdmEventListener*));
};
class MockCrypto : public WVGenericCryptoInterface {
@@ -158,8 +153,8 @@ TEST_F(WVDrmPluginTest, OpensSessions) {
StrictMock<MockCrypto> crypto;
WVDrmPlugin plugin(&cdm, &crypto);
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
.WillOnce(DoAll(SetArgPointee<2>(cdmSessionId),
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _))
.WillOnce(DoAll(SetArgPointee<3>(cdmSessionId),
Return(wvcdm::NO_ERROR)));
// Provide expected behavior when plugin requests session control info
@@ -167,13 +162,6 @@ TEST_F(WVDrmPluginTest, OpensSessions) {
.Times(AtLeast(1))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
@@ -387,8 +375,8 @@ TEST_F(WVDrmPluginTest, HandlesPrivacyCertCaseOfAddKey) {
// Provide expected behavior in response to OpenSession and store the
// property set
EXPECT_CALL(cdm, OpenSession(_, _, _))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
EXPECT_CALL(cdm, OpenSession(_, _, _, _))
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
SaveArg<1>(&propertySet),
Return(wvcdm::NO_ERROR)));
@@ -396,13 +384,6 @@ TEST_F(WVDrmPluginTest, HandlesPrivacyCertCaseOfAddKey) {
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
@@ -824,22 +805,15 @@ TEST_F(WVDrmPluginTest, FailsGenericMethodsWithoutAnAlgorithmSet) {
bool match;
// Provide expected behavior to support session creation
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _))
.Times(AtLeast(1))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
Return(wvcdm::NO_ERROR)));
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.Times(AtLeast(1))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
@@ -910,22 +884,15 @@ TEST_F(WVDrmPluginTest, CallsGenericEncrypt) {
}
// Provide expected behavior to support session creation
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _))
.Times(AtLeast(1))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
Return(wvcdm::NO_ERROR)));
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.Times(AtLeast(1))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
@@ -977,22 +944,15 @@ TEST_F(WVDrmPluginTest, CallsGenericDecrypt) {
}
// Provide expected behavior to support session creation
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _))
.Times(AtLeast(1))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
Return(wvcdm::NO_ERROR)));
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.Times(AtLeast(1))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
@@ -1046,22 +1006,15 @@ TEST_F(WVDrmPluginTest, CallsGenericSign) {
}
// Provide expected behavior to support session creation
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _))
.Times(AtLeast(1))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
Return(wvcdm::NO_ERROR)));
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.Times(AtLeast(1))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
@@ -1125,22 +1078,15 @@ TEST_F(WVDrmPluginTest, CallsGenericVerify) {
}
// Provide expected behavior to support session creation
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _))
.Times(AtLeast(1))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
Return(wvcdm::NO_ERROR)));
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.Times(AtLeast(1))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
@@ -1164,23 +1110,16 @@ TEST_F(WVDrmPluginTest, RegistersForEvents) {
StrictMock<MockCrypto> crypto;
WVDrmPlugin plugin(&cdm, &crypto);
EXPECT_CALL(cdm, AttachEventListener(cdmSessionId, &plugin))
.Times(1);
// Provide expected behavior to support session creation
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, &plugin, _))
.Times(AtLeast(1))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
Return(wvcdm::NO_ERROR)));
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.Times(AtLeast(1))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know this call will happen but we aren't interested in it.
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
@@ -1205,10 +1144,10 @@ TEST_F(WVDrmPluginTest, UnregistersForAllEventsOnDestruction) {
CdmSessionId cdmSessionId1(sessionIdRaw1, sessionIdRaw1 + kSessionIdSize);
CdmSessionId cdmSessionId2(sessionIdRaw2, sessionIdRaw2 + kSessionIdSize);
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
.WillOnce(DoAll(SetArgPointee<2>(cdmSessionId1),
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _))
.WillOnce(DoAll(SetArgPointee<3>(cdmSessionId1),
Return(wvcdm::NO_ERROR)))
.WillOnce(DoAll(SetArgPointee<2>(cdmSessionId2),
.WillOnce(DoAll(SetArgPointee<3>(cdmSessionId2),
Return(wvcdm::NO_ERROR)));
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId1, _))
@@ -1217,16 +1156,6 @@ TEST_F(WVDrmPluginTest, UnregistersForAllEventsOnDestruction) {
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId2, _))
.WillOnce(Invoke(setSessionIdOnMap<5>));
EXPECT_CALL(cdm, DetachEventListener(cdmSessionId1, &plugin))
.Times(1);
EXPECT_CALL(cdm, DetachEventListener(cdmSessionId2, &plugin))
.Times(1);
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
@@ -1283,18 +1212,11 @@ TEST_F(WVDrmPluginTest, GeneratesProvisioningNeededEvent) {
NULL))
.Times(1);
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _))
EXPECT_CALL(cdm, OpenSession(StrEq("com.widevine"), _, _, _))
.Times(AtLeast(1))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
Return(wvcdm::NEED_PROVISIONING)));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
@@ -1316,8 +1238,8 @@ TEST_F(WVDrmPluginTest, ProvidesExpectedDefaultPropertiesToCdm) {
{
// Provide expected behavior in response to OpenSession and store the
// property set
EXPECT_CALL(cdm, OpenSession(_, _, _))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
EXPECT_CALL(cdm, OpenSession(_, _, _, _))
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
SaveArg<1>(&propertySet),
Return(wvcdm::NO_ERROR)));
@@ -1325,13 +1247,6 @@ TEST_F(WVDrmPluginTest, ProvidesExpectedDefaultPropertiesToCdm) {
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
}
@@ -1357,8 +1272,8 @@ TEST_F(WVDrmPluginTest, CanSetAppId) {
{
// Provide expected behavior in response to OpenSession and store the
// property set
EXPECT_CALL(cdm, OpenSession(_, _, _))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
EXPECT_CALL(cdm, OpenSession(_, _, _, _))
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
SaveArg<1>(&propertySet),
Return(wvcdm::NO_ERROR)));
@@ -1366,13 +1281,6 @@ TEST_F(WVDrmPluginTest, CanSetAppId) {
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
}
@@ -1422,8 +1330,8 @@ TEST_F(WVDrmPluginTest, CanSetSecurityLevel) {
{
// Provide expected behavior in response to OpenSession and store the
// property set
EXPECT_CALL(cdm, OpenSession(_, _, _))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
EXPECT_CALL(cdm, OpenSession(_, _, _, _))
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
SaveArg<1>(&propertySet),
Return(wvcdm::NO_ERROR)));
@@ -1431,13 +1339,6 @@ TEST_F(WVDrmPluginTest, CanSetSecurityLevel) {
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
}
@@ -1514,8 +1415,8 @@ TEST_F(WVDrmPluginTest, CanSetPrivacyMode) {
{
// Provide expected behavior in response to OpenSession and store the
// property set
EXPECT_CALL(cdm, OpenSession(_, _, _))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
EXPECT_CALL(cdm, OpenSession(_, _, _, _))
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
SaveArg<1>(&propertySet),
Return(wvcdm::NO_ERROR)));
@@ -1523,13 +1424,6 @@ TEST_F(WVDrmPluginTest, CanSetPrivacyMode) {
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
}
@@ -1576,8 +1470,8 @@ TEST_F(WVDrmPluginTest, CanSetServiceCertificate) {
{
// Provide expected behavior in response to OpenSession and store the
// property set
EXPECT_CALL(cdm, OpenSession(_, _, _))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
EXPECT_CALL(cdm, OpenSession(_, _, _, _))
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
SaveArg<1>(&propertySet),
Return(wvcdm::NO_ERROR)));
@@ -1585,13 +1479,6 @@ TEST_F(WVDrmPluginTest, CanSetServiceCertificate) {
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
}
@@ -1624,8 +1511,8 @@ TEST_F(WVDrmPluginTest, CanSetSessionSharing) {
{
// Provide expected behavior in response to OpenSession and store the
// property set
EXPECT_CALL(cdm, OpenSession(_, _, _))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
EXPECT_CALL(cdm, OpenSession(_, _, _, _))
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
SaveArg<1>(&propertySet),
Return(wvcdm::NO_ERROR)));
@@ -1633,13 +1520,6 @@ TEST_F(WVDrmPluginTest, CanSetSessionSharing) {
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
}
@@ -1690,8 +1570,8 @@ TEST_F(WVDrmPluginTest, AllowsStoringOfSessionSharingId) {
{
// Provide expected behavior in response to OpenSession and store the
// property set
EXPECT_CALL(cdm, OpenSession(_, _, _))
.WillRepeatedly(DoAll(SetArgPointee<2>(cdmSessionId),
EXPECT_CALL(cdm, OpenSession(_, _, _, _))
.WillRepeatedly(DoAll(SetArgPointee<3>(cdmSessionId),
SaveArg<1>(&propertySet),
Return(wvcdm::NO_ERROR)));
@@ -1699,13 +1579,6 @@ TEST_F(WVDrmPluginTest, AllowsStoringOfSessionSharingId) {
EXPECT_CALL(cdm, QueryKeyControlInfo(cdmSessionId, _))
.WillRepeatedly(Invoke(setSessionIdOnMap<4>));
// Let gMock know these calls will happen but we aren't interested in them.
EXPECT_CALL(cdm, AttachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, DetachEventListener(_, _))
.Times(AtLeast(0));
EXPECT_CALL(cdm, CloseSession(_))
.Times(AtLeast(0));
}