clang-format core/test files

[ Merge of http://go/wvgerrit/88006 ]

Certain test files have yet to be formatted since we introduced
clang-formatting.

Test: android unit/integration tests
Bug: 134365840
Change-Id: I2d30ad367d76a9dfbf389614e1b31ed39fa17c72
This commit is contained in:
Rahul Frias
2019-10-16 16:48:50 -07:00
parent 0acde10d1a
commit 2e22e2321e
18 changed files with 776 additions and 946 deletions

View File

@@ -114,10 +114,7 @@ const std::string kLicenseRequestSignature = a2bs_hex(
"9BEDB6CF3D8713F9E11675DF1F5DB9038DBBECAB9D1683F8722CAF6E18EC8C04AEE5");
const CryptoSession::SupportedCertificateTypes kDefaultSupportedCertTypes = {
true,
true,
true
};
true, true, true};
const std::string kFakeEntitlementKeyId =
a2bs_hex("2a538231c616c67143032a645f9c545d");
@@ -125,9 +122,9 @@ const std::string kFakeEntitledKeyId =
a2bs_hex("f93c7a81e62d4e9a988ff20bca60f52d");
const std::string kFakeUnpaddedKey =
a2bs_hex("b2047e7fab08b3a4dac76b7b82e8cd4d");
const std::string kFakePaddedKey =
a2bs_hex("42f804e9ce0fa693692e1c4ffaeb0e14"
"10101010101010101010101010101010");
const std::string kFakePaddedKey = a2bs_hex(
"42f804e9ce0fa693692e1c4ffaeb0e14"
"10101010101010101010101010101010");
const std::string kFakeKeyTooLong =
a2bs_hex("d4bc8605d662878a46adb2adb6bf3c0b30a54a0c2f");
const std::string kFakeKeyTooShort = a2bs_hex("06e247e7f924208011");
@@ -136,7 +133,7 @@ const std::string kFakeIv = a2bs_hex("3d515a3ee0be1687080ac59da9e0d69a");
class MockCryptoSession : public TestCryptoSession {
public:
MockCryptoSession(metrics::CryptoMetrics* crypto_metrics)
: TestCryptoSession(crypto_metrics) { }
: TestCryptoSession(crypto_metrics) {}
MOCK_METHOD0(IsOpen, bool());
MOCK_METHOD0(request_id, const std::string&());
MOCK_METHOD1(UsageInformationSupport, bool(bool*));
@@ -156,7 +153,8 @@ class MockPolicyEngine : public PolicyEngine {
public:
MockPolicyEngine(CryptoSession* crypto)
: PolicyEngine("mock_session_id", nullptr, crypto) {}
MOCK_METHOD1(SetEntitledLicenseKeys,
MOCK_METHOD1(
SetEntitledLicenseKeys,
void(const std::vector<video_widevine::WidevinePsshData_EntitledKey>&));
};
@@ -176,11 +174,11 @@ class MockInitializationData : public InitializationData {
} // namespace
// Protobuf generated classes
using video_widevine::LicenseRequest_ContentIdentification;
using video_widevine::ClientIdentification;
using video_widevine::License;
using video_widevine::License_KeyContainer;
using video_widevine::LicenseRequest;
using video_widevine::LicenseRequest_ContentIdentification;
using video_widevine::SignedMessage;
using video_widevine::WidevinePsshData_EntitledKey;
@@ -311,8 +309,7 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidation) {
CryptoSession::HdcpCapability max_hdcp_version = HDCP_V2_1;
uint32_t crypto_session_api_version = 9;
EXPECT_CALL(*crypto_session_, IsOpen())
.WillOnce(Return(true));
EXPECT_CALL(*crypto_session_, IsOpen()).WillOnce(Return(true));
EXPECT_CALL(*crypto_session_, request_id())
.WillOnce(ReturnRef(kCryptoRequestId));
EXPECT_CALL(*crypto_session_, UsageInformationSupport(NotNull()))
@@ -334,16 +331,17 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidation) {
DoAll(SetArgPointee<2>(kLicenseRequestSignature), Return(NO_ERROR)));
CreateCdmLicense();
EXPECT_TRUE(cdm_license_->Init(
kToken, kClientTokenDrmCert, kEmptyString, true,
kDefaultServiceCertificate, crypto_session_, policy_engine_));
EXPECT_TRUE(cdm_license_->Init(kToken, kClientTokenDrmCert, kEmptyString,
true, kDefaultServiceCertificate,
crypto_session_, policy_engine_));
CdmAppParameterMap app_parameters;
CdmKeyMessage signed_request;
std::string server_url;
EXPECT_EQ(cdm_license_->PrepareKeyRequest(
*init_data_, kLicenseTypeStreaming, app_parameters,
&signed_request, &server_url), KEY_MESSAGE);
EXPECT_EQ(cdm_license_->PrepareKeyRequest(*init_data_, kLicenseTypeStreaming,
app_parameters, &signed_request,
&server_url),
KEY_MESSAGE);
EXPECT_TRUE(!signed_request.empty());
@@ -363,16 +361,16 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidation) {
// Verify Client Identification
const ClientIdentification& client_id = license_request.client_id();
EXPECT_EQ(video_widevine::
ClientIdentification_TokenType_DRM_DEVICE_CERTIFICATE,
client_id.type());
EXPECT_EQ(
video_widevine::ClientIdentification_TokenType_DRM_DEVICE_CERTIFICATE,
client_id.type());
EXPECT_TRUE(std::equal(client_id.token().begin(), client_id.token().end(),
kToken.begin()));
EXPECT_LT(0, client_id.client_info_size());
for (int i = 0; i < client_id.client_info_size(); ++i) {
const ::video_widevine::ClientIdentification_NameValue&
name_value = client_id.client_info(i);
const ::video_widevine::ClientIdentification_NameValue& name_value =
client_id.client_info(i);
EXPECT_TRUE(!name_value.name().empty());
EXPECT_TRUE(!name_value.value().empty());
}
@@ -419,8 +417,7 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidation) {
EXPECT_EQ(::video_widevine::LicenseRequest_RequestType_NEW,
license_request.type());
EXPECT_EQ(kLicenseStartTime, license_request.request_time());
EXPECT_EQ(video_widevine::VERSION_2_1,
license_request.protocol_version());
EXPECT_EQ(video_widevine::VERSION_2_1, license_request.protocol_version());
EXPECT_EQ(kNonce, license_request.key_control_nonce());
}
@@ -431,8 +428,7 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidationV15) {
uint32_t crypto_session_api_version = 15;
uint32_t resource_rating_tier = RESOURCE_RATING_TIER_LOW;
EXPECT_CALL(*crypto_session_, IsOpen())
.WillOnce(Return(true));
EXPECT_CALL(*crypto_session_, IsOpen()).WillOnce(Return(true));
EXPECT_CALL(*crypto_session_, request_id())
.WillOnce(ReturnRef(kCryptoRequestId));
EXPECT_CALL(*crypto_session_, UsageInformationSupport(NotNull()))
@@ -447,8 +443,7 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidationV15) {
.WillRepeatedly(
DoAll(SetArgPointee<0>(crypto_session_api_version), Return(true)));
EXPECT_CALL(*crypto_session_, GetResourceRatingTier(NotNull()))
.WillOnce(
DoAll(SetArgPointee<0>(resource_rating_tier), Return(true)));
.WillOnce(DoAll(SetArgPointee<0>(resource_rating_tier), Return(true)));
EXPECT_CALL(*clock_, GetCurrentTime()).WillOnce(Return(kLicenseStartTime));
EXPECT_CALL(*crypto_session_, GenerateNonce(NotNull()))
.WillOnce(DoAll(SetArgPointee<0>(kNonce), Return(NO_ERROR)));
@@ -457,16 +452,17 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidationV15) {
DoAll(SetArgPointee<2>(kLicenseRequestSignature), Return(NO_ERROR)));
CreateCdmLicense();
EXPECT_TRUE(cdm_license_->Init(
kToken, kClientTokenDrmCert, kEmptyString, true,
kDefaultServiceCertificate, crypto_session_, policy_engine_));
EXPECT_TRUE(cdm_license_->Init(kToken, kClientTokenDrmCert, kEmptyString,
true, kDefaultServiceCertificate,
crypto_session_, policy_engine_));
CdmAppParameterMap app_parameters;
CdmKeyMessage signed_request;
std::string server_url;
EXPECT_EQ(cdm_license_->PrepareKeyRequest(
*init_data_, kLicenseTypeStreaming, app_parameters,
&signed_request, &server_url), KEY_MESSAGE);
EXPECT_EQ(cdm_license_->PrepareKeyRequest(*init_data_, kLicenseTypeStreaming,
app_parameters, &signed_request,
&server_url),
KEY_MESSAGE);
EXPECT_TRUE(!signed_request.empty());
@@ -486,16 +482,16 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidationV15) {
// Verify Client Identification
const ClientIdentification& client_id = license_request.client_id();
EXPECT_EQ(video_widevine::
ClientIdentification_TokenType_DRM_DEVICE_CERTIFICATE,
client_id.type());
EXPECT_EQ(
video_widevine::ClientIdentification_TokenType_DRM_DEVICE_CERTIFICATE,
client_id.type());
EXPECT_TRUE(std::equal(client_id.token().begin(), client_id.token().end(),
kToken.begin()));
EXPECT_LT(0, client_id.client_info_size());
for (int i = 0; i < client_id.client_info_size(); ++i) {
const ::video_widevine::ClientIdentification_NameValue&
name_value = client_id.client_info(i);
const ::video_widevine::ClientIdentification_NameValue& name_value =
client_id.client_info(i);
EXPECT_TRUE(!name_value.name().empty());
EXPECT_TRUE(!name_value.value().empty());
}
@@ -521,8 +517,7 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidationV15) {
ClientIdentification_ClientCapabilities_CertificateKeyType_RSA_2048,
video_widevine::
ClientIdentification_ClientCapabilities_CertificateKeyType_RSA_3072));
EXPECT_EQ(resource_rating_tier,
client_capabilities.resource_rating_tier());
EXPECT_EQ(resource_rating_tier, client_capabilities.resource_rating_tier());
// Verify Content Identification
const LicenseRequest_ContentIdentification& content_id =
@@ -543,17 +538,14 @@ TEST_F(CdmLicenseTest, PrepareKeyRequestValidationV15) {
EXPECT_EQ(::video_widevine::LicenseRequest_RequestType_NEW,
license_request.type());
EXPECT_EQ(kLicenseStartTime, license_request.request_time());
EXPECT_EQ(video_widevine::VERSION_2_1,
license_request.protocol_version());
EXPECT_EQ(video_widevine::VERSION_2_1, license_request.protocol_version());
EXPECT_EQ(kNonce, license_request.key_control_nonce());
}
struct EntitledKeyVariant {
EntitledKeyVariant(const char* name, const std::string& key,
bool should_succeed)
: name(name),
key(key),
should_succeed(should_succeed) {}
: name(name), key(key), should_succeed(should_succeed) {}
const std::string name;
const std::string key;
const bool should_succeed;
@@ -586,26 +578,22 @@ TEST_P(CdmLicenseEntitledKeyTest, LoadsEntitledKeys) {
padded_key.set_iv(kFakeIv);
// Set the expected downstream calls
EXPECT_CALL(*crypto_session_, IsOpen())
.WillOnce(Return(true));
EXPECT_CALL(*crypto_session_, IsOpen()).WillOnce(Return(true));
if (variant.should_succeed) {
EXPECT_CALL(*crypto_session_, LoadEntitledContentKeys(_))
.WillOnce(Return(KEY_ADDED));
EXPECT_CALL(*policy_engine_, SetEntitledLicenseKeys(_))
.Times(1);
.WillOnce(Return(KEY_ADDED));
EXPECT_CALL(*policy_engine_, SetEntitledLicenseKeys(_)).Times(1);
} else {
EXPECT_CALL(*crypto_session_, LoadEntitledContentKeys(_))
.Times(0);
EXPECT_CALL(*policy_engine_, SetEntitledLicenseKeys(_))
.Times(0);
EXPECT_CALL(*crypto_session_, LoadEntitledContentKeys(_)).Times(0);
EXPECT_CALL(*policy_engine_, SetEntitledLicenseKeys(_)).Times(0);
}
// Set up the CdmLicense with the mocks and fake entitlement key
CreateCdmLicense();
EXPECT_TRUE(cdm_license_->Init(
kToken, kClientTokenDrmCert, kEmptyString, true,
kDefaultServiceCertificate, crypto_session_, policy_engine_));
EXPECT_TRUE(cdm_license_->Init(kToken, kClientTokenDrmCert, kEmptyString,
true, kDefaultServiceCertificate,
crypto_session_, policy_engine_));
cdm_license_->set_entitlement_keys(entitlement_license);
// Call the function under test and check its return value
@@ -620,11 +608,10 @@ TEST_P(CdmLicenseEntitledKeyTest, LoadsEntitledKeys) {
INSTANTIATE_TEST_CASE_P(
EntitledKeyTests, CdmLicenseEntitledKeyTest,
Values(
EntitledKeyVariant("UnpaddedKey", kFakeUnpaddedKey, true),
EntitledKeyVariant("PaddedKey", kFakePaddedKey, true),
EntitledKeyVariant("KeyTooLong", kFakeKeyTooLong, true),
EntitledKeyVariant("KeyTooShort", kFakeKeyTooShort, false)),
Values(EntitledKeyVariant("UnpaddedKey", kFakeUnpaddedKey, true),
EntitledKeyVariant("PaddedKey", kFakePaddedKey, true),
EntitledKeyVariant("KeyTooLong", kFakeKeyTooLong, true),
EntitledKeyVariant("KeyTooShort", kFakeKeyTooShort, false)),
PrintToStringParamName());
} // namespace wvcdm