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

@@ -47,10 +47,10 @@ class WvCdmEngineTest : public testing::Test {
public:
virtual void SetUp() {
CdmResponseType status =
cdm_engine_.OpenSession(g_key_system, NULL, &session_id_);
cdm_engine_.OpenSession(g_key_system, NULL, NULL, &session_id_);
if (status == NEED_PROVISIONING) {
Provision();
status = cdm_engine_.OpenSession(g_key_system, NULL, &session_id_);
status = cdm_engine_.OpenSession(g_key_system, NULL, NULL, &session_id_);
}
ASSERT_EQ(NO_ERROR, status);
ASSERT_NE("", session_id_) << "Could not open CDM session.";

View File

@@ -5,6 +5,7 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "properties.h"
#include "scoped_ptr.h"
#include "string_conversions.h"
#include "test_printers.h"
@@ -126,25 +127,19 @@ class MockCdmLicense : public CdmLicense {
class CdmSessionTest : public ::testing::Test {
protected:
virtual void SetUp() {
cdm_session_.reset(new CdmSession(NULL, NULL));
// Inject testing mocks.
license_parser_ = new MockCdmLicense();
cdm_session_->set_license_parser(license_parser_);
crypto_session_ = new MockCryptoSession();
cdm_session_->set_crypto_session(crypto_session_);
policy_engine_ = new MockPolicyEngine();
cdm_session_->set_policy_engine(policy_engine_);
file_handle_ = new MockDeviceFiles();
cdm_session_->set_file_handle(file_handle_);
}
virtual void TearDown() {
if (cdm_session_) delete cdm_session_;
}
void CreateSession() { CreateSession(NULL); }
void CreateSession(const CdmClientPropertySet* cdm_client_property_set) {
cdm_session_ =
new CdmSession(license_parser_, crypto_session_, policy_engine_,
file_handle_, cdm_client_property_set);
}
CdmSession* cdm_session_;
scoped_ptr<CdmSession> cdm_session_;
MockCdmLicense* license_parser_;
MockCryptoSession* crypto_session_;
MockPolicyEngine* policy_engine_;
@@ -173,7 +168,6 @@ TEST_F(CdmSessionTest, InitWithCertificate) {
Properties::set_use_certificates_as_identification(true);
CreateSession();
ASSERT_EQ(NO_ERROR, cdm_session_->Init());
}
@@ -195,7 +189,6 @@ TEST_F(CdmSessionTest, InitWithKeybox) {
Properties::set_use_certificates_as_identification(false);
CreateSession();
ASSERT_EQ(NO_ERROR, cdm_session_->Init());
}
@@ -221,7 +214,6 @@ TEST_F(CdmSessionTest, ReInitFail) {
Properties::set_use_certificates_as_identification(true);
CreateSession();
ASSERT_EQ(NO_ERROR, cdm_session_->Init());
ASSERT_EQ(UNKNOWN_ERROR, cdm_session_->Init());
}
@@ -233,7 +225,6 @@ TEST_F(CdmSessionTest, InitFailCryptoError) {
Properties::set_use_certificates_as_identification(true);
CreateSession();
ASSERT_EQ(UNKNOWN_ERROR, cdm_session_->Init());
}
@@ -252,7 +243,6 @@ TEST_F(CdmSessionTest, InitNeedsProvisioning) {
Properties::set_use_certificates_as_identification(true);
CreateSession();
ASSERT_EQ(NEED_PROVISIONING, cdm_session_->Init());
}

View File

@@ -10,6 +10,7 @@
#include "license.h"
#include "mock_clock.h"
#include "policy_engine.h"
#include "scoped_ptr.h"
#include "test_printers.h"
#include "wv_cdm_constants.h"
@@ -58,8 +59,10 @@ using ::testing::AtLeast;
class PolicyEngineTest : public ::testing::Test {
protected:
virtual void SetUp() {
policy_engine_.reset(new PolicyEngine(NULL));
// Inject testing clock.
mock_clock_ = new MockClock();
policy_engine_ = new PolicyEngine(NULL, mock_clock_);
policy_engine_->set_clock(mock_clock_);
license_.set_license_start_time(kLicenseStartTime);
@@ -85,13 +88,6 @@ class PolicyEngineTest : public ::testing::Test {
policy->set_renew_with_usage(false);
}
virtual void TearDown() {
delete policy_engine_;
// Done by policy engine: delete mock_clock_;
policy_engine_ = NULL;
mock_clock_ = NULL;
}
int64_t GetMinOfRentalPlaybackLicenseDurations() {
const License_Policy& policy = license_.policy();
int64_t rental_duration = policy.rental_duration_seconds();
@@ -105,7 +101,7 @@ class PolicyEngineTest : public ::testing::Test {
}
MockClock* mock_clock_;
PolicyEngine* policy_engine_;
scoped_ptr<PolicyEngine> policy_engine_;
License license_;
};