Adjust CDM engine and request license unit tests
Merge of the widevine change: https://widevine-internal-review.googlesource.com/#/c/11632 Several unit tests in cdm_engine_test.cpp and request_license_test.cpp were failing regularly. These were caused by either: 1) The device was not provisioned. This has been fixed by adding a certificate provisioning step in the test setup for the cdm engine tests and changing the existing provision steop in the request license tests to provision for both security levels. 2) The device was hitting a flaky server. This has been fixed by switching from the GooglePlayServer to the Widevine server. 3) A null pointer introduced when testing secure stops with an app id. This has been fixed by directly injecting the app id in the unit tests. 4) Flaky network connections. The unit tests were requesting data from the server and were timing out after 3 seconds. I changed that to 12 seconds. 5) The tests were searching for an end-of-line marker to find the GLS header in the license response message. The end-of-line marker was present in a valid DRM message for almost 1% of the test cases. This code has been replaced by searching for the string "GLS/1" at the begining of the HTML body. I also added test_printers.cpp that defines functions used by GTest to print error codes by name instead of numeric value. This CL changes unit tests only. It does not change any production code. bug: 18316036 Change-Id: I3398580059a03114e782ac7ac59e6b0944012df4
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
// These tests are for the cdm engine, and code below it in the stack. In
|
||||
// particular, we assume that the OEMCrypo layer works, and has a valid keybox.
|
||||
// This is because we need a valid RSA certificate, and will attempt to connect
|
||||
// to the provisioning server to request one if we don't.
|
||||
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
@@ -18,6 +22,7 @@
|
||||
#include "properties.h"
|
||||
#include "scoped_ptr.h"
|
||||
#include "string_conversions.h"
|
||||
#include "test_printers.h"
|
||||
#include "url_request.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
#include "wv_cdm_types.h"
|
||||
@@ -35,60 +40,6 @@ wvcdm::CdmKeySystem g_key_system;
|
||||
std::string g_license_server;
|
||||
wvcdm::KeyId g_wrong_key_id;
|
||||
|
||||
// This is an RSA certificate message from the provisioning server.
|
||||
// The client sends this certificate to a license server for device
|
||||
// authentication by the license server.
|
||||
// This certificate is used to test the CDM engine's provisioning
|
||||
// response handling.
|
||||
static wvcdm::CdmProvisioningResponse kValidJsonProvisioningResponse =
|
||||
"{\"signedResponse\": {"
|
||||
"\"message\": \"CrAJYTyIdLPiA2jBzMskbE_gFQj69wv23VlJ2e3MBKtK4nJwKyNYGyyluqKo"
|
||||
"TP751tvoADf86iLrf73mEzF58eSlaOjCpJRf2R3dojbNeSTy3JICmCc8vKtMjZRX9QWTvJbq_cg"
|
||||
"yMB8FQC8enuYhOaw1yJDYyCFHgik34NrUVUfmvaKKdSKQimqAZmjXi6P0znAn-XdPtz2xJVRxZp"
|
||||
"NH3QCD1bGcH_O1ercBW2JwF9KNalKFsxQrBhIwvyx-q-Ah4vf4r3M2HzY6JTHvcYGGc7dJNA3Xe"
|
||||
"WfCrYIvg0SGCP_z7Y2wICIA36VMwR3gnwNZlKkx6WGCCgsaU6IbLm4HpRBZfajuiOlasoYN4z1R"
|
||||
"lQ14Z32fdaFy8xOqLl-ZukxjWa7wv9zOSveH6JcHap1FS3R-RZ7E5WhfjxSTS0nWWZgmAjS2PkP"
|
||||
"9g4GPNsnpsrVymI39j6R6jPoc3__2EGN6qAvmp4pFKR7lQyslgNn2vYLuE0Ps5mIXVkxNiZOO3T"
|
||||
"jxgZyHaHOm1KmAZKI0EfddMATJCTt-UeLG3haqS_pYaBWcQ_xzWhoEHWU7_6ZaWrWemV8CVCg6s"
|
||||
"OB1SRI5MrkRBBSV0r8UKddLJGthZVjuTG75KK72KE9yhe86mCadvfVYe5keJ5GOC-t1EiFzBo4c"
|
||||
"4oqwkOCkkmYX_BEuZ3pOWztFp1_Br2Tl_fziw4O2vNIPCXB9yEewV6PkYPziTue3x4vRqD_mYjm"
|
||||
"1ia8fxISQnEC0vrqvrFFs9fLAHPlsvaRFnhv_XKpRwFoBdfqWTakb3k6uRz0Oh2SJ8euzFIyQNB"
|
||||
"efesMWk45DSrQjnlwlKXwZSiDKjAss0W2WwIb9F_x5LdB1Aa-CBudLVdxf62ggYaNZ57qx3YeHA"
|
||||
"jkqMGIF7Fq09D4Ox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f79kD45uRRzkVc8GbRIlVyzVC0WgIvtxEkYRKfgF_J7snUe2J2NN"
|
||||
"1FrkK7H3oYhcfPyYZH_SPZJr5HPoBFQTmS5A4l24U1dzQ6Z7_q-oS6uT0DiagTnzWhEg6AEnIkT"
|
||||
"sJtK3cZuKGYq3NDefZ7nslPuLXxdXl6SAEOtrk-RvCY6EBqYOuPUXgxXOEPbyM289R6aHQyPPYw"
|
||||
"qs9Pt9_E4BuMqCsbf5H5mLms9FA-wRx6mK2IaOboT4tf9_YObp3hVeL3WyxzXncETzJdE1GPGlO"
|
||||
"t_x5S_MylgJKbiWQYSdmqs3fzYExunw3wvI4tPHT_O8A_xKjyTEAvE5cBuCkfjwT716qUOzFUzF"
|
||||
"gZYLHnFiQLZekZUbUUlWY_CwU9Cv0UtxqQ6Oa835_Ug8_n1BwX6BPbmbcWe2Y19laSnDWg4JBNl"
|
||||
"F2CyP9N75jPtW9rVfjUSqKEPOwaIgwzNDkyMjM3NDcAAAA=\","
|
||||
"\"signature\": \"r-LpoZcbbr2KtoPaFnuWTVBh4Gup1k8vn0ClW2qm32A=\"}}";
|
||||
|
||||
const std::string kCencMimeType = "video/mp4";
|
||||
const std::string kWebmMimeType = "video/webm";
|
||||
|
||||
@@ -99,14 +50,39 @@ namespace wvcdm {
|
||||
class WvCdmEngineTest : public testing::Test {
|
||||
public:
|
||||
virtual void SetUp() {
|
||||
cdm_engine_.OpenSession(g_key_system, NULL, &session_id_);
|
||||
CdmResponseType status = cdm_engine_.OpenSession(g_key_system, NULL, &session_id_);
|
||||
if (status == NEED_PROVISIONING) {
|
||||
Provision();
|
||||
status = cdm_engine_.OpenSession(g_key_system, NULL, &session_id_);
|
||||
}
|
||||
ASSERT_EQ(NO_ERROR, status);
|
||||
ASSERT_NE("", session_id_) << "Could not open CDM session.";
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
cdm_engine_.CloseSession(session_id_);
|
||||
}
|
||||
virtual void TearDown() { cdm_engine_.CloseSession(session_id_); }
|
||||
|
||||
protected:
|
||||
void Provision() {
|
||||
CdmProvisioningRequest prov_request;
|
||||
std::string provisioning_server_url;
|
||||
CdmCertificateType cert_type = kCertificateWidevine;
|
||||
std::string cert_authority;
|
||||
std::string cert, wrapped_key;
|
||||
ASSERT_EQ(NO_ERROR,
|
||||
cdm_engine_.GetProvisioningRequest(cert_type,
|
||||
cert_authority,
|
||||
&prov_request,
|
||||
&provisioning_server_url));
|
||||
UrlRequest url_request(provisioning_server_url);
|
||||
url_request.PostCertRequestInQueryString(prov_request);
|
||||
std::string message;
|
||||
bool ok = url_request.GetResponse(&message);
|
||||
EXPECT_TRUE(ok);
|
||||
ASSERT_EQ(NO_ERROR,
|
||||
cdm_engine_.HandleProvisioningResponse(message,
|
||||
&cert, &wrapped_key));
|
||||
}
|
||||
|
||||
void GenerateKeyRequest(const std::string& key_id,
|
||||
const std::string& init_data_type_string) {
|
||||
CdmAppParameterMap app_parameters;
|
||||
@@ -132,9 +108,19 @@ class WvCdmEngineTest : public testing::Test {
|
||||
&server_url_));
|
||||
}
|
||||
|
||||
// posts a request and extracts the drm message from the response
|
||||
std::string GetKeyRequestResponse(const std::string& server_url,
|
||||
const std::string& client_auth) {
|
||||
return GetKeyRequestResponse(server_url, client_auth, true);
|
||||
}
|
||||
std::string FailToGetKeyRequestResponse(const std::string& server_url,
|
||||
const std::string& client_auth) {
|
||||
return GetKeyRequestResponse(server_url, client_auth, false);
|
||||
}
|
||||
|
||||
// posts a request and extracts the drm message from the response
|
||||
std::string GetKeyRequestResponse(const std::string& server_url,
|
||||
const std::string& client_auth,
|
||||
bool expect_success) {
|
||||
// Use secure connection and chunk transfer coding.
|
||||
UrlRequest url_request(server_url + client_auth);
|
||||
if (!url_request.is_connected()) {
|
||||
@@ -148,7 +134,7 @@ class WvCdmEngineTest : public testing::Test {
|
||||
EXPECT_TRUE(ok);
|
||||
|
||||
int status_code = url_request.GetStatusCode(response);
|
||||
EXPECT_EQ(kHttpOk, status_code);
|
||||
if (expect_success) EXPECT_EQ(kHttpOk, status_code);
|
||||
|
||||
if (status_code != kHttpOk) {
|
||||
return "";
|
||||
@@ -173,8 +159,7 @@ class WvCdmEngineTest : public testing::Test {
|
||||
|
||||
void VerifyRenewalKeyResponse(const std::string& server_url,
|
||||
const std::string& client_auth) {
|
||||
std::string resp = GetKeyRequestResponse(server_url,
|
||||
client_auth);
|
||||
std::string resp = GetKeyRequestResponse(server_url, client_auth);
|
||||
EXPECT_EQ(wvcdm::KEY_ADDED, cdm_engine_.RenewKey(session_id_, resp));
|
||||
}
|
||||
|
||||
@@ -184,18 +169,9 @@ class WvCdmEngineTest : public testing::Test {
|
||||
std::string server_url_;
|
||||
};
|
||||
|
||||
TEST(WvCdmProvisioningTest, ProvisioningTest) {
|
||||
CdmEngine cdm_engine;
|
||||
CdmProvisioningRequest prov_request;
|
||||
std::string provisioning_server_url;
|
||||
CdmCertificateType cert_type = kCertificateWidevine;
|
||||
std::string cert_authority;
|
||||
std::string cert, wrapped_key;
|
||||
|
||||
cdm_engine.GetProvisioningRequest(cert_type, cert_authority,
|
||||
&prov_request, &provisioning_server_url);
|
||||
cdm_engine.HandleProvisioningResponse(kValidJsonProvisioningResponse,
|
||||
&cert, &wrapped_key);
|
||||
// Test that provisioning works, even if device is already provisioned.
|
||||
TEST_F(WvCdmEngineTest, ProvisioningTest) {
|
||||
Provision();
|
||||
}
|
||||
|
||||
TEST_F(WvCdmEngineTest, BaseIsoBmffMessageTest) {
|
||||
@@ -215,7 +191,7 @@ TEST_F(WvCdmEngineTest, WrongMessageTest) {
|
||||
|
||||
// We should receive a response with no license, i.e. the extracted license
|
||||
// response message should be empty.
|
||||
ASSERT_EQ("", GetKeyRequestResponse(g_license_server, g_client_auth));
|
||||
ASSERT_EQ("", FailToGetKeyRequestResponse(g_license_server, g_client_auth));
|
||||
}
|
||||
|
||||
TEST_F(WvCdmEngineTest, NormalDecryptionIsoBmff) {
|
||||
@@ -244,7 +220,7 @@ int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
wvcdm::InitLogging(argc, argv);
|
||||
|
||||
wvcdm::ConfigTestEnv config(wvcdm::kGooglePlayServer);
|
||||
wvcdm::ConfigTestEnv config(wvcdm::kContentProtectionServer);
|
||||
g_client_auth.assign(config.client_auth());
|
||||
g_key_system.assign(config.key_system());
|
||||
g_wrong_key_id.assign(config.wrong_key_id());
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "gtest/gtest.h"
|
||||
#include "properties.h"
|
||||
#include "string_conversions.h"
|
||||
#include "test_printers.h"
|
||||
|
||||
namespace {
|
||||
const std::string kToken = wvcdm::a2bs_hex(
|
||||
|
||||
@@ -30,20 +30,22 @@ void LicenseRequest::GetDrmMessage(const std::string& response,
|
||||
header_end_pos += kTwoBlankLines.size(); // points to response body
|
||||
|
||||
drm_msg.clear();
|
||||
size_t drm_msg_pos = response.find(kTwoBlankLines, header_end_pos);
|
||||
if (drm_msg_pos != std::string::npos) {
|
||||
drm_msg_pos += kTwoBlankLines.size(); // points to drm message
|
||||
} else {
|
||||
// For backward compatibility, no blank line after error code
|
||||
drm_msg_pos = response.find("\r\n", header_end_pos);
|
||||
// Messages from Google Play server add a GLS wrapper. These start
|
||||
// with "GLS/1.0 <status>".
|
||||
if (response.find("GLS/1.", header_end_pos) == header_end_pos) {
|
||||
// For GLS messages, we should skip past the next blank line, and use
|
||||
// what's left of the message.
|
||||
size_t drm_msg_pos = response.find(kTwoBlankLines, header_end_pos);
|
||||
if (drm_msg_pos != std::string::npos) {
|
||||
drm_msg_pos += 2; // points to drm message
|
||||
drm_msg_pos += kTwoBlankLines.size(); // points to drm message
|
||||
drm_msg = response.substr(drm_msg_pos);
|
||||
} else {
|
||||
LOGE("Message had GLS marker, but did not have extra blank line.");
|
||||
drm_msg = response.substr(header_end_pos);
|
||||
}
|
||||
}
|
||||
|
||||
if (drm_msg_pos != std::string::npos) {
|
||||
drm_msg = response.substr(drm_msg_pos);
|
||||
} else {
|
||||
// For servers that do not use the GLS wrapper, we should just strip of
|
||||
// the headers, and use the rest of the message.
|
||||
drm_msg = response.substr(header_end_pos);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "license.h"
|
||||
#include "mock_clock.h"
|
||||
#include "policy_engine.h"
|
||||
#include "test_printers.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
|
||||
namespace {
|
||||
|
||||
93
libwvdrmengine/cdm/core/test/test_printers.cpp
Normal file
93
libwvdrmengine/cdm/core/test/test_printers.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
// This file adds some print methods so that when unit tests fail, the
|
||||
// will print the name of an enumeration instead of the numeric value.
|
||||
|
||||
#include "test_printers.h"
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
void PrintTo(const enum CdmResponseType& value, ::std::ostream* os) {
|
||||
switch(value) {
|
||||
case NO_ERROR: *os << "NO_ERROR";
|
||||
break;
|
||||
case UNKNOWN_ERROR: *os << "UNKNOWN_ERROR";
|
||||
break;
|
||||
case KEY_ADDED: *os << "KEY_ADDED";
|
||||
break;
|
||||
case KEY_ERROR: *os << "KEY_ERROR";
|
||||
break;
|
||||
case KEY_MESSAGE: *os << "KEY_MESSAGE";
|
||||
break;
|
||||
case NEED_KEY: *os << "NEED_KEY";
|
||||
break;
|
||||
case KEY_CANCELED: *os << "KEY_CANCELED";
|
||||
break;
|
||||
case NEED_PROVISIONING: *os << "NEED_PROVISIONING";
|
||||
break;
|
||||
case DEVICE_REVOKED: *os << "DEVICE_REVOKED";
|
||||
break;
|
||||
case INSUFFICIENT_CRYPTO_RESOURCES: *os << "INSUFFICIENT_CRYPTO_RESOURCES";
|
||||
break;
|
||||
default:
|
||||
*os << "Unknown CdmResponseType";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void PrintTo(const enum CdmEventType& value, ::std::ostream* os) {
|
||||
switch(value) {
|
||||
case LICENSE_EXPIRED_EVENT: *os << "LICENSE_EXPIRED_EVENT";
|
||||
break;
|
||||
case LICENSE_RENEWAL_NEEDED_EVENT: *os << "LICENSE_RENEWAL_NEEDED_EVENT";
|
||||
break;
|
||||
default:
|
||||
*os << "Unknown CdmEventType";
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
void PrintTo(const enum CdmLicenseType& value, ::std::ostream* os) {
|
||||
switch(value) {
|
||||
case kLicenseTypeOffline: *os << "kLicenseTypeOffline";
|
||||
break;
|
||||
case kLicenseTypeStreaming: *os << "kLicenseTypeStreaming";
|
||||
break;
|
||||
case kLicenseTypeRelease: *os << "kLicenseTypeRelease";
|
||||
break;
|
||||
default:
|
||||
*os << "Unknown CdmLicenseType";
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
void PrintTo(const enum CdmSecurityLevel& value, ::std::ostream* os) {
|
||||
switch(value) {
|
||||
case kSecurityLevelUninitialized: *os << "kSecurityLevelUninitialized";
|
||||
break;
|
||||
case kSecurityLevelL1: *os << "kSecurityLevelL1";
|
||||
break;
|
||||
case kSecurityLevelL2: *os << "kSecurityLevelL2";
|
||||
break;
|
||||
case kSecurityLevelL3: *os << "kSecurityLevelL3";
|
||||
break;
|
||||
case kSecurityLevelUnknown: *os << "kSecurityLevelUnknown";
|
||||
break;
|
||||
default:
|
||||
*os << "Unknown CdmSecurityLevel";
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
void PrintTo(const enum CdmCertificateType& value, ::std::ostream* os) {
|
||||
switch(value) {
|
||||
case kCertificateWidevine: *os << "kCertificateWidevine";
|
||||
break;
|
||||
case kCertificateX509: *os << "kCertificateX509";
|
||||
break;
|
||||
default:
|
||||
*os << "Unknown CdmCertificateType";
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
}; // namespace wvcdm
|
||||
19
libwvdrmengine/cdm/core/test/test_printers.h
Normal file
19
libwvdrmengine/cdm/core/test/test_printers.h
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright 2013 Google Inc. All Rights Reserved.
|
||||
// This file adds some print methods so that when unit tests fail, the
|
||||
// will print the name of an enumeration instead of the numeric value.
|
||||
|
||||
#ifndef CDM_TEST_PRINTERS_H_
|
||||
#define CDM_TEST_PRINTERS_H_
|
||||
|
||||
#include <iostream>
|
||||
#include "wv_cdm_types.h"
|
||||
|
||||
namespace wvcdm {
|
||||
void PrintTo(const enum CdmResponseType& value, ::std::ostream* os);
|
||||
void PrintTo(const enum CdmEventType& value, ::std::ostream* os);
|
||||
void PrintTo(const enum CdmLicenseType& value, ::std::ostream* os);
|
||||
void PrintTo(const enum CdmSecurityLevel& value, ::std::ostream* os);
|
||||
void PrintTo(const enum CdmCertificateType& value, ::std::ostream* os);
|
||||
}; // namespace wvcdm
|
||||
|
||||
#endif // CDM_TEST_PRINTERS_H_
|
||||
@@ -12,9 +12,9 @@
|
||||
namespace {
|
||||
|
||||
const int kReadBufferSize = 1024;
|
||||
const int kConnectTimeoutMs = 5000;
|
||||
const int kWriteTimeoutMs = 3000;
|
||||
const int kReadTimeoutMs = 3000;
|
||||
const int kConnectTimeoutMs = 15000;
|
||||
const int kWriteTimeoutMs = 12000;
|
||||
const int kReadTimeoutMs = 12000;
|
||||
|
||||
// Concatenate all chunks into one blob and returns the response with
|
||||
// header information.
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "properties.h"
|
||||
#include "string_conversions.h"
|
||||
#include "url_request.h"
|
||||
#include "test_printers.h"
|
||||
#include "wv_cdm_constants.h"
|
||||
#include "wv_cdm_event_listener.h"
|
||||
#include "wv_content_decryption_module.h"
|
||||
@@ -372,15 +373,18 @@ struct UsageInfoSubSampleInfo {
|
||||
SubSampleInfo* sub_sample;
|
||||
uint32_t usage_info;
|
||||
wvcdm::SecurityLevel security_level;
|
||||
std::string app_id;
|
||||
};
|
||||
|
||||
UsageInfoSubSampleInfo usage_info_sub_sample_info[] = {
|
||||
{&usage_info_sub_samples_icp[0], 1, wvcdm::kLevelDefault},
|
||||
{&usage_info_sub_samples_icp[0], 3, wvcdm::kLevelDefault},
|
||||
{&usage_info_sub_samples_icp[0], 5, wvcdm::kLevelDefault},
|
||||
{&usage_info_sub_samples_icp[0], 1, wvcdm::kLevel3},
|
||||
{&usage_info_sub_samples_icp[0], 3, wvcdm::kLevel3},
|
||||
{&usage_info_sub_samples_icp[0], 5, wvcdm::kLevel3}};
|
||||
{&usage_info_sub_samples_icp[0], 1, wvcdm::kLevelDefault, ""},
|
||||
{&usage_info_sub_samples_icp[0], 3, wvcdm::kLevelDefault, ""},
|
||||
{&usage_info_sub_samples_icp[0], 5, wvcdm::kLevelDefault, ""},
|
||||
{&usage_info_sub_samples_icp[0], 3, wvcdm::kLevelDefault, "other app id"},
|
||||
{&usage_info_sub_samples_icp[0], 1, wvcdm::kLevel3, ""},
|
||||
{&usage_info_sub_samples_icp[0], 3, wvcdm::kLevel3, ""},
|
||||
{&usage_info_sub_samples_icp[0], 5, wvcdm::kLevel3, ""},
|
||||
{&usage_info_sub_samples_icp[0], 3, wvcdm::kLevel3, "other app id"}};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -665,7 +669,11 @@ class WvCdmRequestLicenseTest : public testing::Test {
|
||||
query_info.find(wvcdm::QUERY_KEY_SECURITY_LEVEL);
|
||||
EXPECT_TRUE(itr != query_info.end());
|
||||
decryptor_.CloseSession(session_id_);
|
||||
return itr->second;
|
||||
if (itr != query_info.end()) {
|
||||
return itr->second;
|
||||
} else {
|
||||
return "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -677,7 +685,7 @@ class WvCdmRequestLicenseTest : public testing::Test {
|
||||
} else if (level.compare(wvcdm::QUERY_VALUE_SECURITY_LEVEL_L3) == 0) {
|
||||
security_level = kSecurityLevelL3;
|
||||
} else {
|
||||
EXPECT_TRUE(false);
|
||||
EXPECT_TRUE(false) << "Default Security level is undefined: " << level;
|
||||
}
|
||||
return security_level;
|
||||
}
|
||||
@@ -1198,7 +1206,6 @@ class WvCdmUsageInfoTest
|
||||
|
||||
TEST_P(WvCdmUsageInfoTest, UsageInfo) {
|
||||
Unprovision();
|
||||
Provision(kLevelDefault);
|
||||
|
||||
UsageInfoSubSampleInfo* usage_info_data = GetParam();
|
||||
TestWvCdmClientPropertySet client_property_set;
|
||||
@@ -1206,6 +1213,10 @@ TEST_P(WvCdmUsageInfoTest, UsageInfo) {
|
||||
if (kLevel3 == usage_info_data->security_level) {
|
||||
client_property_set.set_security_level(QUERY_VALUE_SECURITY_LEVEL_L3);
|
||||
property_set = &client_property_set;
|
||||
Provision(kLevel3);
|
||||
Provision(kLevelDefault);
|
||||
} else {
|
||||
Provision(kLevelDefault);
|
||||
}
|
||||
|
||||
CdmSecurityLevel security_level = GetDefaultSecurityLevel();
|
||||
@@ -1213,7 +1224,7 @@ TEST_P(WvCdmUsageInfoTest, UsageInfo) {
|
||||
EXPECT_TRUE(handle.Init(security_level));
|
||||
File file;
|
||||
handle.SetTestFile(&file);
|
||||
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp("")); // default app_id.
|
||||
EXPECT_TRUE(handle.DeleteAllUsageInfoForApp(usage_info_data->app_id));
|
||||
|
||||
for (size_t i = 0; i < usage_info_data->usage_info; ++i) {
|
||||
SubSampleInfo* data = usage_info_data->sub_sample + i;
|
||||
@@ -1248,7 +1259,7 @@ TEST_P(WvCdmUsageInfoTest, UsageInfo) {
|
||||
CdmUsageInfo usage_info;
|
||||
CdmUsageInfoReleaseMessage release_msg;
|
||||
CdmResponseType status =
|
||||
decryptor_.GetUsageInfo(property_set->app_id(), &usage_info);
|
||||
decryptor_.GetUsageInfo(usage_info_data->app_id, &usage_info);
|
||||
EXPECT_EQ(usage_info.empty() ? NO_ERROR : KEY_MESSAGE, status);
|
||||
while (usage_info.size() > 0) {
|
||||
for (size_t i = 0; i < usage_info.size(); ++i) {
|
||||
@@ -1256,7 +1267,7 @@ TEST_P(WvCdmUsageInfoTest, UsageInfo) {
|
||||
GetUsageInfoResponse(g_license_server, g_client_auth, usage_info[i]);
|
||||
EXPECT_EQ(NO_ERROR, decryptor_.ReleaseUsageInfo(release_msg));
|
||||
}
|
||||
status = decryptor_.GetUsageInfo(property_set->app_id(), &usage_info);
|
||||
status = decryptor_.GetUsageInfo(usage_info_data->app_id, &usage_info);
|
||||
switch (status) {
|
||||
case KEY_MESSAGE: EXPECT_FALSE(usage_info.empty()); break;
|
||||
case NO_ERROR: EXPECT_TRUE(usage_info.empty()); break;
|
||||
@@ -1269,7 +1280,12 @@ TEST_P(WvCdmUsageInfoTest, UsageInfo) {
|
||||
INSTANTIATE_TEST_CASE_P(Cdm, WvCdmUsageInfoTest,
|
||||
::testing::Values(&usage_info_sub_sample_info[0],
|
||||
&usage_info_sub_sample_info[1],
|
||||
&usage_info_sub_sample_info[2]));
|
||||
&usage_info_sub_sample_info[2],
|
||||
&usage_info_sub_sample_info[3],
|
||||
&usage_info_sub_sample_info[4],
|
||||
&usage_info_sub_sample_info[5],
|
||||
&usage_info_sub_sample_info[6],
|
||||
&usage_info_sub_sample_info[7]));
|
||||
|
||||
TEST_F(WvCdmRequestLicenseTest, QueryUnmodifiedSessionStatus) {
|
||||
// Test that the global value is returned when no properties are modifying it.
|
||||
|
||||
@@ -14,6 +14,7 @@ LOCAL_SRC_FILES := \
|
||||
../core/test/config_test_env.cpp \
|
||||
../core/test/http_socket.cpp \
|
||||
../core/test/license_request.cpp \
|
||||
../core/test/test_printers.cpp \
|
||||
../core/test/url_request.cpp
|
||||
|
||||
LOCAL_C_INCLUDES := \
|
||||
|
||||
Reference in New Issue
Block a user