Source release v2.1.3-2-789 + third_party libs
Change-Id: I8648756dab3fe1f53d6da18b83cd1294581d1abe
This commit is contained in:
@@ -7,49 +7,37 @@
|
||||
|
||||
// Review the TestHost class below to observe how the CDM interfaces with
|
||||
// the host application.
|
||||
//
|
||||
#include <set>
|
||||
|
||||
#include <queue>
|
||||
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "clock.h"
|
||||
#include "config_test_env.h"
|
||||
#include "content_decryption_module.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "license_request.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "scoped_ptr.h"
|
||||
#include "string_conversions.h"
|
||||
#include "url_request.h"
|
||||
#include "wv_cdm_types.h"
|
||||
|
||||
#include "wv_cdm_common.h"
|
||||
|
||||
using ::testing::_;
|
||||
using ::testing::AtLeast;
|
||||
using ::testing::Invoke;
|
||||
using ::testing::Return;
|
||||
using wvcdm::scoped_ptr;
|
||||
|
||||
static const int kTestPolicyRenewalDelaySeconds = 60;
|
||||
static const int kDelayWaitToForRenewalMessageSeconds = 2;
|
||||
// Linux based get time for host.
|
||||
// This can be tailored if required.
|
||||
double GetCurrentTestTime() {
|
||||
|
||||
static double GetCurrentTime() {
|
||||
struct timeval tv;
|
||||
tv.tv_sec = tv.tv_usec = 0;
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec;
|
||||
}
|
||||
|
||||
using wvcdm::StringPairs;
|
||||
using wvcdm::VectorPairs;
|
||||
|
||||
// These classes below are naive implementation of the abstract classes defined
|
||||
// in the CDM interface (content_decryptiom_module.h), which are used for tests
|
||||
// only.
|
||||
@@ -77,192 +65,11 @@ class TestBuffer : public cdm::Buffer {
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(TestBuffer);
|
||||
};
|
||||
|
||||
class TestHostFile {
|
||||
public:
|
||||
TestHostFile() : fname_(""), file_(NULL) {}
|
||||
virtual ~TestHostFile() { if (file_) fclose(file_); }
|
||||
virtual bool Init(const std::string& name);
|
||||
virtual bool Exists();
|
||||
virtual bool Remove();
|
||||
virtual size_t Size();
|
||||
virtual size_t Read(char* buffer, size_t bytes);
|
||||
virtual size_t Write(const char* buffer, size_t bytes);
|
||||
virtual std::string GetFileName() { return fname_;}
|
||||
|
||||
private:
|
||||
std::string fname_;
|
||||
FILE* file_;
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(TestHostFile);
|
||||
};
|
||||
|
||||
bool TestHostFile::Init(const std::string& name) {
|
||||
fname_ = name;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TestHostFile::Exists() {
|
||||
file_ = fopen(fname_.c_str(), "rb");
|
||||
bool exists = file_;
|
||||
if (file_) {
|
||||
fclose(file_);
|
||||
file_ = NULL;
|
||||
}
|
||||
return (exists);
|
||||
}
|
||||
|
||||
bool TestHostFile::Remove() {
|
||||
if (Exists()) {
|
||||
if (remove(fname_.c_str())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t TestHostFile::Size() {
|
||||
file_ = fopen(fname_.c_str(), "rb");
|
||||
if (file_) {
|
||||
fseek (file_, 0, SEEK_END);
|
||||
size_t size = ftell (file_);
|
||||
rewind (file_);
|
||||
|
||||
if (file_) {
|
||||
fclose(file_);
|
||||
file_ = NULL;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t TestHostFile::Read(char* buffer, size_t bytes) {
|
||||
file_ = fopen(fname_.c_str(), "rb");
|
||||
if (file_) {
|
||||
fseek (file_, 0, SEEK_END);
|
||||
size_t size = ftell (file_);
|
||||
rewind (file_);
|
||||
size_t check = fread (buffer,1,size,file_);
|
||||
if (file_) {
|
||||
fclose(file_);
|
||||
file_ = NULL;
|
||||
}
|
||||
return check;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t TestHostFile::Write(const char* buffer, size_t bytes) {
|
||||
FILE* file_ = fopen(fname_.c_str(), "w+");
|
||||
if (file_) {
|
||||
size_t check = fwrite (buffer,1,bytes,file_);
|
||||
if (file_) {
|
||||
fclose(file_);
|
||||
file_ = NULL;
|
||||
}
|
||||
return check;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
class IHostTime {
|
||||
public:
|
||||
virtual double GetCurrentTestTime() = 0;
|
||||
};
|
||||
|
||||
class SimplePThread {
|
||||
public:
|
||||
SimplePThread();
|
||||
~SimplePThread();
|
||||
void Start(uint64_t periodicity, void* host_ptr, void* context);
|
||||
void Stop();
|
||||
uint32_t GetTickCount();
|
||||
|
||||
private:
|
||||
static bool is_running_;
|
||||
pthread_t simple_timer_thread_;
|
||||
|
||||
typedef void* (*TimeThreadFunc)(void *arg_list);
|
||||
static void* Tthread_function(void *arg_list);
|
||||
TimeThreadFunc time_thread_function_;
|
||||
struct arg_list_struct {
|
||||
uint64_t periodicity;
|
||||
void* host_ptr;
|
||||
void* context;
|
||||
};
|
||||
static uint32_t tick_count_;
|
||||
};
|
||||
|
||||
bool SimplePThread::is_running_ = false;
|
||||
uint32_t SimplePThread::tick_count_ = 0;
|
||||
|
||||
SimplePThread::SimplePThread() : simple_timer_thread_(0) {
|
||||
}
|
||||
|
||||
SimplePThread::~SimplePThread() {
|
||||
LOGI("SimplePThread DTOR: calling Stop() to shutdown thread.");
|
||||
Stop();
|
||||
}
|
||||
|
||||
void SimplePThread::Stop() {
|
||||
if (is_running_) {
|
||||
void* result = NULL;
|
||||
LOGI("SimplePThread is running and now it will be cancelled\n");
|
||||
pthread_cancel(simple_timer_thread_);
|
||||
pthread_join(simple_timer_thread_, &result);
|
||||
is_running_ = false;
|
||||
tick_count_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SimplePThread::Start(uint64_t periodicity, void* host_ptr, void* context) {
|
||||
struct arg_list_struct* arg_list = new(struct arg_list_struct);
|
||||
|
||||
arg_list->periodicity = periodicity;
|
||||
arg_list->host_ptr = host_ptr;
|
||||
arg_list->context = context;
|
||||
|
||||
time_thread_function_ = &Tthread_function;
|
||||
Stop();
|
||||
is_running_ = true;
|
||||
if(pthread_create(&simple_timer_thread_, NULL, time_thread_function_,
|
||||
arg_list)) {
|
||||
LOGI("Error creating pthread\n");
|
||||
return;
|
||||
}
|
||||
LOGI("Created the Simple thread to support the timer callback\n");
|
||||
}
|
||||
|
||||
void* SimplePThread::Tthread_function(void *arg_list) {
|
||||
LOGI("Entered the SimplePThread::Tthread_function\n");
|
||||
|
||||
uint64_t periodicity = (static_cast<arg_list_struct*>(arg_list))->periodicity;
|
||||
void* host_ptr = (static_cast<arg_list_struct*>(arg_list))->host_ptr;
|
||||
void* context = (static_cast<arg_list_struct*>(arg_list))->context;
|
||||
delete static_cast<struct arg_list_struct*>(arg_list);
|
||||
|
||||
LOGI("starting the while loop in the secondary thread\n");
|
||||
|
||||
while (is_running_) {
|
||||
usleep(static_cast<uint64_t>(periodicity * 1000));
|
||||
if (is_running_) {
|
||||
((cdm::ContentDecryptionModule*)host_ptr)->TimerExpired(context);
|
||||
tick_count_++;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t SimplePThread::GetTickCount() {
|
||||
return tick_count_;
|
||||
}
|
||||
|
||||
class TestHost : public cdm::Host, public IHostTime {
|
||||
class TestHost : public cdm::Host {
|
||||
public:
|
||||
// These structs are used to store the KeyMessages and KeyErrors passed to
|
||||
// this class' objects.
|
||||
struct KeyMessage {
|
||||
KeyMessage() {}
|
||||
std::string session_id;
|
||||
std::string message;
|
||||
std::string default_url;
|
||||
@@ -281,11 +88,9 @@ class TestHost : public cdm::Host, public IHostTime {
|
||||
// cdm::Host implementation.
|
||||
virtual cdm::Buffer* Allocate(int32_t capacity) OVERRIDE;
|
||||
|
||||
MOCK_METHOD2(SetTimer, void(int64_t, void*));
|
||||
virtual void DoSetTimer(int64_t delay_ms, void* context);
|
||||
// Returns the current "global" time from the GetCurrentTestTime() function
|
||||
// unless the time is manually set using TestHost::SetCurrentTime()().
|
||||
MOCK_METHOD0(GetCurrentWallTimeInSeconds, double(void));
|
||||
virtual void SetTimer(int64_t delay_ms, void* context) OVERRIDE;
|
||||
|
||||
virtual double GetCurrentWallTimeInSeconds() OVERRIDE;
|
||||
|
||||
virtual void SendKeyMessage(const char* session_id, int32_t session_id_length,
|
||||
const char* message, int32_t message_length,
|
||||
@@ -296,30 +101,14 @@ class TestHost : public cdm::Host, public IHostTime {
|
||||
cdm::MediaKeyError error_code,
|
||||
uint32_t system_code) OVERRIDE;
|
||||
|
||||
virtual void GetPrivateData(int32_t* instance,
|
||||
GetPrivateInterface* get_interface) OVERRIDE;
|
||||
virtual void GetPlatformString(const std::string& name,
|
||||
std::string* value) OVERRIDE;
|
||||
|
||||
virtual int GetPlatformString(const std::string& name,
|
||||
std::string* value) OVERRIDE;
|
||||
|
||||
virtual int SetPlatformString(const std::string& name,
|
||||
const std::string& value) OVERRIDE;;
|
||||
|
||||
virtual int PersistPlatformString(const std::string& name,
|
||||
const std::string& value) OVERRIDE;;
|
||||
|
||||
virtual int GetPlatformByteArray(const std::string& name,
|
||||
std::vector<uint8_t>* value) OVERRIDE;
|
||||
|
||||
virtual int SetPlatformByteArray(const std::string& name,
|
||||
const std::vector<uint8_t>& value) OVERRIDE;
|
||||
|
||||
virtual int PersistPlatformByteArray(const std::string& name,
|
||||
const std::vector<uint8_t>& value) OVERRIDE;
|
||||
virtual void SetPlatformString(const std::string& name,
|
||||
const std::string& value) OVERRIDE;
|
||||
|
||||
// Methods only for this test.
|
||||
void SetCurrentTime(double current_time);
|
||||
void FastForwardTimeForNextTimerEvent();
|
||||
void FastForwardTime(double seconds);
|
||||
int KeyMessagesSize() const;
|
||||
int KeyErrorsSize() const;
|
||||
|
||||
@@ -333,17 +122,23 @@ class TestHost : public cdm::Host, public IHostTime {
|
||||
KeyMessage GetKeyMessage(int index) const;
|
||||
KeyError GetKeyError(int index) const;
|
||||
|
||||
void* context() { return context_; }
|
||||
void SetCdmPtr(cdm::ContentDecryptionModule* host_cdm_ptr);
|
||||
|
||||
virtual double GetCurrentTestTime();
|
||||
uint32_t GetTickCount();
|
||||
void SetCdmPtr(cdm::ContentDecryptionModule* cdm);
|
||||
|
||||
private:
|
||||
// This is used in GetCurrentWallTimeInSeconds(). This field is used to
|
||||
// control the "current time".
|
||||
struct Timer {
|
||||
Timer(double expiry_time, void* context)
|
||||
: expiry_time(expiry_time), context(context) {}
|
||||
|
||||
bool operator<(const Timer& other) const {
|
||||
return expiry_time < other.expiry_time;
|
||||
}
|
||||
|
||||
double expiry_time;
|
||||
void* context;
|
||||
};
|
||||
|
||||
double current_time_;
|
||||
bool current_time_is_set_;
|
||||
std::priority_queue<Timer> timers_;
|
||||
|
||||
std::vector<KeyMessage> key_messages_;
|
||||
std::vector<KeyError> key_errors_;
|
||||
@@ -351,29 +146,13 @@ class TestHost : public cdm::Host, public IHostTime {
|
||||
bool has_new_key_message_;
|
||||
bool has_new_key_error_;
|
||||
|
||||
void* context_;
|
||||
int64_t delay_ms_;
|
||||
std::map<std::string, std::string> platform_strings_;
|
||||
|
||||
cdm::ContentDecryptionModule* host_cdm_ptr_;
|
||||
|
||||
// These are containers for the platform sharing data.
|
||||
std::set<StringPairs> platform_strings_set_;
|
||||
std::set<VectorPairs> platform_vectors_set_;
|
||||
TestHostFile test_host_file_;
|
||||
void LoadPersistentValues();
|
||||
SimplePThread simple_thread_;
|
||||
cdm::ContentDecryptionModule* cdm_;
|
||||
|
||||
CORE_DISALLOW_COPY_AND_ASSIGN(TestHost);
|
||||
};
|
||||
|
||||
class TestHostFactory {
|
||||
public:
|
||||
TestHost* GetTestHost();
|
||||
|
||||
private:
|
||||
scoped_ptr<TestHost> test_host_;
|
||||
};
|
||||
|
||||
TestBuffer* TestBuffer::Create(uint32_t capacity) {
|
||||
return new TestBuffer(capacity);
|
||||
}
|
||||
@@ -395,37 +174,34 @@ void TestBuffer::SetSize(int32_t size) { size_ = size; }
|
||||
int32_t TestBuffer::Size() const { return size_; }
|
||||
|
||||
TestBuffer::TestBuffer(uint32_t capacity)
|
||||
: buffer_(new uint8_t[capacity]), capacity_(capacity) {}
|
||||
: buffer_(new uint8_t[capacity]),
|
||||
capacity_(capacity) {}
|
||||
|
||||
TestBuffer::~TestBuffer() {}
|
||||
|
||||
TestHost::TestHost()
|
||||
: current_time_(::GetCurrentTestTime()),
|
||||
current_time_is_set_(false),
|
||||
: current_time_(GetCurrentTime()),
|
||||
has_new_key_message_(false),
|
||||
has_new_key_error_(false),
|
||||
context_(NULL),
|
||||
delay_ms_(0),
|
||||
host_cdm_ptr_(NULL) {
|
||||
LoadPersistentValues();
|
||||
cdm_(NULL) {
|
||||
}
|
||||
|
||||
TestHost::~TestHost() {}
|
||||
TestHost::~TestHost() {
|
||||
if (cdm_)
|
||||
cdm_->Destroy();
|
||||
}
|
||||
|
||||
cdm::Buffer* TestHost::Allocate(int32_t capacity) {
|
||||
return TestBuffer::Create(capacity);
|
||||
}
|
||||
|
||||
// SetTimer is a mock method mapping to DoSetTimer(). The cdm::Host
|
||||
// calls back to the TimerExpired callback
|
||||
// every delay_ms. Zero delay_ms means WV is requesting
|
||||
// termination of timer services.
|
||||
void TestHost::DoSetTimer(int64_t delay_ms, void* context) {
|
||||
if (delay_ms == 0) {
|
||||
simple_thread_.Stop();
|
||||
return;
|
||||
}
|
||||
simple_thread_.Start(delay_ms, (void*)host_cdm_ptr_, context);
|
||||
void TestHost::SetTimer(int64_t delay_ms, void* context) {
|
||||
double expiry_time = current_time_ + (delay_ms / 1000.0);
|
||||
timers_.push(Timer(expiry_time, context));
|
||||
}
|
||||
|
||||
double TestHost::GetCurrentWallTimeInSeconds() {
|
||||
return current_time_;
|
||||
}
|
||||
|
||||
void TestHost::SendKeyMessage(const char* session_id, int32_t session_id_length,
|
||||
@@ -451,131 +227,34 @@ void TestHost::SendKeyError(const char* session_id, int32_t session_id_length,
|
||||
has_new_key_error_ = true;
|
||||
}
|
||||
|
||||
void TestHost::SetCurrentTime(double current_time) {
|
||||
current_time_is_set_ = true;
|
||||
current_time_ = current_time;
|
||||
}
|
||||
|
||||
void TestHost::FastForwardTimeForNextTimerEvent() {
|
||||
current_time_is_set_ = true;
|
||||
current_time_ += (delay_ms_ / 1000.0);
|
||||
delay_ms_ = 0;
|
||||
}
|
||||
|
||||
void TestHost::GetPrivateData(int32_t* instance,
|
||||
GetPrivateInterface* get_interface) {
|
||||
LOGI("NOTIMPLEMENTED()");
|
||||
}
|
||||
|
||||
// The Platform methods below are implemented to fill and retrieve
|
||||
// platform specific information. The host application takes responsibility for
|
||||
// this interface.
|
||||
|
||||
int TestHost::GetPlatformString(const std::string& name,
|
||||
std::string* value) {
|
||||
std::set<StringPairs>::iterator it;
|
||||
|
||||
for (it = platform_strings_set_.begin();
|
||||
it != platform_strings_set_.end(); ++it) {
|
||||
|
||||
StringPairs sp = *it;
|
||||
std::string x = sp.first;
|
||||
std::string y = sp.second;
|
||||
if (x == name) {
|
||||
*value = y;
|
||||
return 1;
|
||||
void TestHost::FastForwardTime(double seconds) {
|
||||
double goal_time = current_time_ + seconds;
|
||||
while (current_time_ < goal_time) {
|
||||
if (timers_.empty()) {
|
||||
current_time_ = goal_time;
|
||||
} else {
|
||||
Timer t = timers_.top();
|
||||
timers_.pop();
|
||||
current_time_ = t.expiry_time;
|
||||
cdm_->TimerExpired(t.context);
|
||||
}
|
||||
}
|
||||
*value = "Not Found!";
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TestHost::SetPlatformString(const std::string& name,
|
||||
const std::string& value) {
|
||||
StringPairs sp(name, value);
|
||||
platform_strings_set_.insert(sp);
|
||||
return 1;
|
||||
void TestHost::GetPlatformString(const std::string& name,
|
||||
std::string* value) {
|
||||
*value = platform_strings_[name];
|
||||
}
|
||||
|
||||
int TestHost::PersistPlatformString(const std::string& name,
|
||||
const std::string& value) {
|
||||
StringPairs sp(name, value);
|
||||
// Write the pairs to a file such that they can be retrieved by
|
||||
// GetPlatformString() even after a power cycle.
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TestHost::SetPlatformByteArray(const std::string& name,
|
||||
const std::vector<uint8_t>& value) {
|
||||
// A zero value pair is an erase only.
|
||||
std::set<VectorPairs>::iterator it;
|
||||
for (it = platform_vectors_set_.begin();
|
||||
it != platform_vectors_set_.end(); ++it) {
|
||||
VectorPairs vp = *it;
|
||||
if (vp.first == name) {
|
||||
platform_vectors_set_.erase(vp);
|
||||
}
|
||||
}
|
||||
|
||||
if (value.size() > 0) {
|
||||
VectorPairs vp(name, value);
|
||||
platform_vectors_set_.insert(vp);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TestHost::PersistPlatformByteArray(const std::string& name,
|
||||
const std::vector<uint8_t>& value) {
|
||||
|
||||
// Assume input name = "DeviceCertificate" and
|
||||
// test_host_file.fname_ == "cert.bin"
|
||||
// No other cases are currently needed or supported.
|
||||
if (value.size() == 0) {
|
||||
remove(test_host_file_.GetFileName().c_str());
|
||||
|
||||
} else {
|
||||
std::string string_buffer;
|
||||
string_buffer.resize(value.size());
|
||||
memcpy(&string_buffer[0], &value[0], value.size());
|
||||
test_host_file_.Write(&string_buffer[0], value.size());
|
||||
}
|
||||
VectorPairs vp(name, value);
|
||||
|
||||
SetPlatformByteArray(name, value);
|
||||
// open file and persist this so that it can be retrieved as a string/vector
|
||||
// correlated pair. Vendor needs to implement this!
|
||||
return 1;
|
||||
}
|
||||
|
||||
int TestHost::GetPlatformByteArray(const std::string& name,
|
||||
std::vector<uint8_t>* value) {
|
||||
std::set<VectorPairs>::iterator it;
|
||||
for (it = platform_vectors_set_.begin();
|
||||
it != platform_vectors_set_.end(); ++it) {
|
||||
|
||||
VectorPairs vp = *it;
|
||||
std::string x = vp.first;
|
||||
if (x == name) {
|
||||
*value = vp.second;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
value = NULL;
|
||||
return 0;
|
||||
void TestHost::SetPlatformString(const std::string& name,
|
||||
const std::string& value) {
|
||||
platform_strings_[name] = value;
|
||||
}
|
||||
|
||||
int TestHost::KeyMessagesSize() const { return key_messages_.size(); }
|
||||
|
||||
int TestHost::KeyErrorsSize() const { return key_errors_.size(); }
|
||||
|
||||
double TestHost::GetCurrentTestTime() {
|
||||
current_time_is_set_ = true;
|
||||
FastForwardTimeForNextTimerEvent();
|
||||
return current_time_;
|
||||
}
|
||||
|
||||
TestHost::KeyMessage TestHost::GetLastKeyMessage() {
|
||||
if (!has_new_key_message_) {
|
||||
LOGD("No NEW");
|
||||
@@ -609,40 +288,8 @@ TestHost::KeyError TestHost::GetKeyError(int index) const {
|
||||
return key_errors_[index];
|
||||
}
|
||||
|
||||
void TestHost::SetCdmPtr(cdm::ContentDecryptionModule* host_cdm_ptr) {
|
||||
host_cdm_ptr_ = host_cdm_ptr;
|
||||
}
|
||||
|
||||
uint32_t TestHost::GetTickCount() {
|
||||
return simple_thread_.GetTickCount();
|
||||
}
|
||||
|
||||
TestHost* TestHostFactory::GetTestHost() {
|
||||
|
||||
if (!test_host_.get()) test_host_.reset(new TestHost());
|
||||
|
||||
return test_host_.get();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// The CDM::Host object is responsible for storing and retrieving items
|
||||
// that are accessed via GetPlatformByteArray. Currently, support for
|
||||
// the device certificate is all that is required.
|
||||
|
||||
void TestHost::LoadPersistentValues() {
|
||||
test_host_file_.Init("cert.bin");
|
||||
if (test_host_file_.Exists()) {
|
||||
size_t size = test_host_file_.Size();
|
||||
std::string string_buffer;
|
||||
string_buffer.resize(size);
|
||||
test_host_file_.Read(&string_buffer[0], size);
|
||||
|
||||
std::vector<uint8_t> vector_buffer(size);
|
||||
memcpy(&vector_buffer[0], &string_buffer[0], size);
|
||||
SetPlatformByteArray("DeviceCertificate", vector_buffer);
|
||||
|
||||
}
|
||||
void TestHost::SetCdmPtr(cdm::ContentDecryptionModule* cdm) {
|
||||
cdm_ = cdm;
|
||||
}
|
||||
|
||||
class TestDecryptedBlock : public cdm::DecryptedBlock {
|
||||
@@ -686,6 +333,7 @@ void TestDecryptedBlock::SetTimestamp(int64_t timestamp) {
|
||||
int64_t TestDecryptedBlock::Timestamp() const { return timestamp_; }
|
||||
|
||||
namespace {
|
||||
|
||||
// Default license server, can be configured using --server command line option
|
||||
// Default key id (pssh), can be configured using --keyid command line option
|
||||
const char kKeySystemWidevine[] = "com.widevine.alpha";
|
||||
@@ -694,53 +342,49 @@ wvcdm::KeyId g_key_id;
|
||||
wvcdm::CdmKeySystem g_key_system;
|
||||
std::string g_license_server;
|
||||
wvcdm::KeyId g_wrong_key_id;
|
||||
int g_use_full_path = 0; // cannot use boolean in getopt_long
|
||||
|
||||
void* GetCdmHost(int host_interface_version, void* user_data) {
|
||||
if (host_interface_version != cdm::kHostInterfaceVersion)
|
||||
return NULL;
|
||||
return user_data;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace wvcdm {
|
||||
|
||||
void* GetCdmHost(int host_interface_version, void* user_data);
|
||||
|
||||
class WvCdmApiTest : public testing::Test {
|
||||
public:
|
||||
WvCdmApiTest() : cdm_(NULL) {}
|
||||
~WvCdmApiTest() {
|
||||
if (cdm_) cdm_->Destroy();
|
||||
}
|
||||
~WvCdmApiTest() {}
|
||||
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
cdm_ = reinterpret_cast<cdm::ContentDecryptionModule*>(::CreateCdmInstance(
|
||||
cdm::kCdmInterfaceVersion, kKeySystemWidevine,
|
||||
strlen(kKeySystemWidevine), GetCdmHost, &host_factory_));
|
||||
host_ = host_factory_.GetTestHost();
|
||||
host_->SetCdmPtr(cdm_);
|
||||
// Create the Host.
|
||||
host_.reset(new TestHost());
|
||||
|
||||
// Set various parameters that the CDM will query.
|
||||
host_->SetPlatformString("SecurityLevel", "L1");
|
||||
host_->SetPlatformString("PrivacyOn", "False");
|
||||
host_->SetPlatformString("UsesServiceCertificates", "False");
|
||||
|
||||
// By default we allow the timer to fire twice; once
|
||||
// when the addkey comes, and once when the wvcdm destructs and
|
||||
// disables the timer.
|
||||
EXPECT_CALL(*host_, SetTimer(_,_))
|
||||
.Times(AtLeast(2))
|
||||
.WillRepeatedly(Invoke(host_, &TestHost::DoSetTimer));
|
||||
|
||||
EXPECT_CALL(*host_, GetCurrentWallTimeInSeconds())
|
||||
.Times(AtLeast(1))
|
||||
.WillRepeatedly(Invoke(host_, &TestHost::GetCurrentTestTime));
|
||||
|
||||
// emulate pulling a certificate out of persistent storage.
|
||||
// Put a phony service certificate into persistent storage.
|
||||
static const size_t kPrivacyCertSize = 256;
|
||||
VectorBytes cert(kPrivacyCertSize);
|
||||
std::string cert(kPrivacyCertSize, '\0');
|
||||
for (size_t i = 0; i < cert.size(); i++) {
|
||||
cert[i] = i;
|
||||
}
|
||||
host_->SetPlatformString("ServiceCertificate", cert);
|
||||
|
||||
host_->SetPlatformByteArray("ServiceCertificate", cert);
|
||||
// Initialize the CDM module before creating a CDM instance.
|
||||
INITIALIZE_CDM_MODULE();
|
||||
|
||||
// Create the CDM.
|
||||
cdm_ = reinterpret_cast<cdm::ContentDecryptionModule*>(::CreateCdmInstance(
|
||||
cdm::kCdmInterfaceVersion, kKeySystemWidevine,
|
||||
strlen(kKeySystemWidevine), GetCdmHost, host_.get()));
|
||||
|
||||
// Tell the Host about the CDM.
|
||||
host_->SetCdmPtr(cdm_);
|
||||
}
|
||||
|
||||
void GenerateKeyRequest(const std::string& key_system,
|
||||
@@ -781,7 +425,6 @@ class WvCdmApiTest : public testing::Test {
|
||||
std::string GetKeyRequestResponse(const std::string& server_url,
|
||||
const std::string& client_auth,
|
||||
int expected_response) {
|
||||
// Use secure connection and chunk transfer coding.
|
||||
UrlRequest url_request(server_url + client_auth);
|
||||
if (!url_request.is_connected()) {
|
||||
return "";
|
||||
@@ -790,8 +433,6 @@ class WvCdmApiTest : public testing::Test {
|
||||
url_request.PostRequest(key_msg_);
|
||||
std::string response;
|
||||
int resp_bytes = url_request.GetResponse(&response);
|
||||
LOGD("response:\r\n%s", response.c_str());
|
||||
LOGD("end %d bytes response dump", resp_bytes);
|
||||
|
||||
// Some license servers return 400 for invalid message, some
|
||||
// return 500; treat anything other than 200 as an invalid message.
|
||||
@@ -809,7 +450,7 @@ class WvCdmApiTest : public testing::Test {
|
||||
std::string drm_msg;
|
||||
LicenseRequest lic_request;
|
||||
lic_request.GetDrmMessage(response, drm_msg);
|
||||
LOGV("drm msg: %u bytes\r\n%s", drm_msg.size(),
|
||||
LOGV("drm msg: %u bytes\n%s", drm_msg.size(),
|
||||
HexEncode(reinterpret_cast<const uint8_t*>(drm_msg.data()),
|
||||
drm_msg.size()).c_str());
|
||||
return drm_msg;
|
||||
@@ -1310,15 +951,12 @@ class WvCdmApiTest : public testing::Test {
|
||||
EXPECT_EQ(cdm::kDecryptError, status);
|
||||
}
|
||||
|
||||
void TimerTest(void* session_id) { host_->SetTimer(1000, session_id); }
|
||||
|
||||
std::string key_msg_;
|
||||
std::string session_id_;
|
||||
std::string server_url_;
|
||||
|
||||
cdm::ContentDecryptionModule* cdm_;
|
||||
TestHostFactory host_factory_;
|
||||
TestHost* host_;
|
||||
cdm::ContentDecryptionModule* cdm_; // owned by host_
|
||||
scoped_ptr<TestHost> host_;
|
||||
};
|
||||
|
||||
// Note that these tests, BaseMessageTest, NormalDecryption and TimeTest,
|
||||
@@ -1328,8 +966,7 @@ class WvCdmApiTest : public testing::Test {
|
||||
// and works in your test environment.
|
||||
|
||||
TEST_F(WvCdmApiTest, DeviceCertificateTest) {
|
||||
std::vector<uint8_t> value(0);
|
||||
host_->PersistPlatformByteArray("DeviceCertificate", value);
|
||||
host_->SetPlatformString("DeviceCertificate", "");
|
||||
GenerateKeyRequest(g_key_system, g_key_id); // It will have to provision -
|
||||
// in here.
|
||||
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
|
||||
@@ -1352,25 +989,6 @@ TEST_F(WvCdmApiTest, BaseMessageTest) {
|
||||
CancelKeyRequest(session_id_);
|
||||
}
|
||||
|
||||
TEST_F(WvCdmApiTest, BaseTimerTest) {
|
||||
GenerateKeyRequest(g_key_system, g_key_id);
|
||||
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
|
||||
session_id_ = key_msg.session_id;
|
||||
key_msg_ = key_msg.message;
|
||||
std::string drm_msg = GetKeyRequestResponse(g_license_server,
|
||||
g_client_auth, 200);
|
||||
AddKey(key_msg.session_id, drm_msg);
|
||||
|
||||
LOGI("Sleeping and allowing the time expirations to increment");
|
||||
uint32_t sleep_period = static_cast<uint32_t>(12000 / 1000);
|
||||
sleep(sleep_period);
|
||||
LOGI("Tick count is %ld\n", host_->GetTickCount());
|
||||
// We should have close to, maybe slightly less than sleep_period ticks.
|
||||
// If it ticked at all then we pass as the timer must be expriring.
|
||||
EXPECT_GE(host_->GetTickCount(), 1U);
|
||||
CancelKeyRequest(session_id_);
|
||||
}
|
||||
|
||||
TEST_F(WvCdmApiTest, NormalDecryption) {
|
||||
GenerateKeyRequest(g_key_system, g_key_id);
|
||||
TestHost::KeyMessage key_msg = host_->GetLastKeyMessage();
|
||||
@@ -1410,8 +1028,8 @@ TEST_F(WvCdmApiTest, TimeTest) {
|
||||
g_client_auth, 200);
|
||||
AddKey(key_msg.session_id, drm_msg);
|
||||
|
||||
host_->SetCurrentTime(host_->GetCurrentTestTime() + kTestPolicyRenewalDelaySeconds);
|
||||
sleep(kDelayWaitToForRenewalMessageSeconds);
|
||||
host_->FastForwardTime(kTestPolicyRenewalDelaySeconds +
|
||||
kDelayWaitToForRenewalMessageSeconds);
|
||||
|
||||
// When the timer expired, we should have sent a renewal, so we can
|
||||
// add this renewed key now, assuming things are working as expected.
|
||||
@@ -1419,7 +1037,10 @@ TEST_F(WvCdmApiTest, TimeTest) {
|
||||
session_id_ = key_msg2.session_id;
|
||||
key_msg_ = key_msg2.message;
|
||||
|
||||
drm_msg = GetKeyRequestResponse(key_msg2.default_url, g_client_auth, 200);
|
||||
// Note that the client auth string is not appended when the CDM tells
|
||||
// us what URL to use.
|
||||
EXPECT_FALSE(key_msg2.default_url.empty());
|
||||
drm_msg = GetKeyRequestResponse(key_msg2.default_url, "", 200);
|
||||
AddKey(key_msg2.session_id, drm_msg);
|
||||
}
|
||||
|
||||
@@ -1453,15 +1074,6 @@ TEST_F(WvCdmApiTest, SecureDecryptionLevel1WithMissingSubsampleInfo) {
|
||||
WithMissingSubsampleInfoTest();
|
||||
}
|
||||
|
||||
void* GetCdmHost(int host_interface_version, void* user_data) {
|
||||
if (!host_interface_version || !user_data) return NULL;
|
||||
|
||||
if (host_interface_version != cdm::kHostInterfaceVersion) return NULL;
|
||||
|
||||
TestHostFactory* host_factory = reinterpret_cast<TestHostFactory*>(user_data);
|
||||
return host_factory->GetTestHost();
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
@@ -1480,16 +1092,13 @@ int main(int argc, char** argv) {
|
||||
|
||||
int show_usage = 0;
|
||||
static const struct option long_options[] = {
|
||||
{"use_full_path", no_argument, &g_use_full_path, 0},
|
||||
{"keyid", required_argument, NULL, 'k'},
|
||||
{"server", required_argument, NULL, 's'},
|
||||
{"vmodule", required_argument, NULL, 0},
|
||||
{"v", required_argument, NULL, 0},
|
||||
{NULL, 0, NULL, '\0'}};
|
||||
|
||||
int option_index = 0;
|
||||
int opt = 0;
|
||||
while ((opt = getopt_long(argc, argv, "k:p:s:u:v", long_options,
|
||||
while ((opt = getopt_long(argc, argv, "k:s:v", long_options,
|
||||
&option_index)) != -1) {
|
||||
switch (opt) {
|
||||
case 'k': {
|
||||
@@ -1502,15 +1111,19 @@ int main(int argc, char** argv) {
|
||||
g_license_server.assign(optarg);
|
||||
break;
|
||||
}
|
||||
case 'u': {
|
||||
g_use_full_path = 1;
|
||||
case 'v': {
|
||||
// This option has already been consumed by wvcdm::InitLogging() above.
|
||||
// We only tell getopt about it so that it is not an error. We ignore
|
||||
// the option here when seen.
|
||||
// TODO: Stop passing argv to InitLogging, and instead set the log
|
||||
// level here through the logging API. We should keep all command-line
|
||||
// parsing at the application level, rather than split between various
|
||||
// apps and various platform-specific logging implementations.
|
||||
break;
|
||||
}
|
||||
case '?': {
|
||||
show_usage = 1;
|
||||
break;
|
||||
case 'v':
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1518,10 +1131,6 @@ int main(int argc, char** argv) {
|
||||
if (show_usage) {
|
||||
std::cout << std::endl;
|
||||
std::cout << "usage: " << argv[0] << " [options]" << std::endl << std::endl;
|
||||
std::cout << " enclose multiple arguments in '' when using adb shell"
|
||||
<< std::endl;
|
||||
std::cout << " e.g. adb shell '" << argv[0] << " --server=\"url\"'"
|
||||
<< std::endl << std::endl;
|
||||
|
||||
std::cout << std::setw(30) << std::left << " --server=<server_url>";
|
||||
std::cout
|
||||
@@ -1534,10 +1143,6 @@ int main(int argc, char** argv) {
|
||||
std::cout << "configure the key id or pssh, in hex format" << std::endl;
|
||||
std::cout << std::setw(30) << std::left << " default keyid:";
|
||||
std::cout << g_key_id << std::endl;
|
||||
|
||||
std::cout << std::setw(30) << std::left << " --use_full_path";
|
||||
std::cout << "specify server url is not a proxy server" << std::endl;
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user