Enabled WVM test with mocks for WidevineKeySource.
Change-Id: I4b9f8acacca6a334087e10d47b96be15fc3cafec
This commit is contained in:
parent
15ae26e12f
commit
6a1805129d
|
@ -139,17 +139,17 @@ class WidevineKeySource::RefCountedEncryptionKeyMap
|
||||||
WidevineKeySource::WidevineKeySource(
|
WidevineKeySource::WidevineKeySource(
|
||||||
const std::string& server_url,
|
const std::string& server_url,
|
||||||
scoped_ptr<RequestSigner> signer)
|
scoped_ptr<RequestSigner> signer)
|
||||||
: http_fetcher_(new SimpleHttpFetcher(kHttpTimeoutInSeconds)),
|
: key_production_thread_(
|
||||||
|
"KeyProductionThread",
|
||||||
|
base::Bind(&WidevineKeySource::FetchKeysTask,
|
||||||
|
base::Unretained(this))),
|
||||||
|
http_fetcher_(new SimpleHttpFetcher(kHttpTimeoutInSeconds)),
|
||||||
server_url_(server_url),
|
server_url_(server_url),
|
||||||
signer_(signer.Pass()),
|
signer_(signer.Pass()),
|
||||||
crypto_period_count_(kDefaultCryptoPeriodCount),
|
crypto_period_count_(kDefaultCryptoPeriodCount),
|
||||||
key_production_started_(false),
|
key_production_started_(false),
|
||||||
start_key_production_(false, false),
|
start_key_production_(false, false),
|
||||||
first_crypto_period_index_(0),
|
first_crypto_period_index_(0) {
|
||||||
key_production_thread_(
|
|
||||||
"KeyProductionThread",
|
|
||||||
base::Bind(&WidevineKeySource::FetchKeysTask,
|
|
||||||
base::Unretained(this))) {
|
|
||||||
DCHECK(signer_);
|
DCHECK(signer_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ class WidevineKeySource : public KeySource {
|
||||||
virtual Status FetchKeys(const std::vector<uint8_t>& content_id,
|
virtual Status FetchKeys(const std::vector<uint8_t>& content_id,
|
||||||
const std::string& policy) OVERRIDE;
|
const std::string& policy) OVERRIDE;
|
||||||
virtual Status FetchKeys(const std::vector<uint8_t>& pssh_data) OVERRIDE;
|
virtual Status FetchKeys(const std::vector<uint8_t>& pssh_data) OVERRIDE;
|
||||||
Status FetchKeys(uint32_t asset_id);
|
virtual Status FetchKeys(uint32_t asset_id);
|
||||||
|
|
||||||
virtual Status GetKey(TrackType track_type, EncryptionKey* key) OVERRIDE;
|
virtual Status GetKey(TrackType track_type, EncryptionKey* key) OVERRIDE;
|
||||||
virtual Status GetKey(const std::vector<uint8_t>& key_id,
|
virtual Status GetKey(const std::vector<uint8_t>& key_id,
|
||||||
|
@ -51,6 +51,9 @@ class WidevineKeySource : public KeySource {
|
||||||
/// @param http_fetcher points to the @b HttpFetcher object to be injected.
|
/// @param http_fetcher points to the @b HttpFetcher object to be injected.
|
||||||
void set_http_fetcher(scoped_ptr<HttpFetcher> http_fetcher);
|
void set_http_fetcher(scoped_ptr<HttpFetcher> http_fetcher);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ClosureThread key_production_thread_;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map<TrackType, EncryptionKey*> EncryptionKeyMap;
|
typedef std::map<TrackType, EncryptionKey*> EncryptionKeyMap;
|
||||||
class RefCountedEncryptionKeyMap;
|
class RefCountedEncryptionKeyMap;
|
||||||
|
@ -108,7 +111,6 @@ class WidevineKeySource : public KeySource {
|
||||||
bool key_production_started_;
|
bool key_production_started_;
|
||||||
base::WaitableEvent start_key_production_;
|
base::WaitableEvent start_key_production_;
|
||||||
uint32_t first_crypto_period_index_;
|
uint32_t first_crypto_period_index_;
|
||||||
ClosureThread key_production_thread_;
|
|
||||||
scoped_ptr<EncryptionKeyQueue> key_pool_;
|
scoped_ptr<EncryptionKeyQueue> key_pool_;
|
||||||
EncryptionKeyMap encryption_key_map_; // For non key rotation request.
|
EncryptionKeyMap encryption_key_map_; // For non key rotation request.
|
||||||
Status common_encryption_request_status_;
|
Status common_encryption_request_status_;
|
||||||
|
|
|
@ -23,19 +23,18 @@
|
||||||
'../mpeg/mpeg.gyp:mpeg',
|
'../mpeg/mpeg.gyp:mpeg',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
# TODO(ramjic): Re-enable when KeySource::FetchKeys() is mocked.
|
{
|
||||||
#{
|
'target_name': 'wvm_unittest',
|
||||||
#'target_name': 'wvm_unittest',
|
'type': '<(gtest_target_type)',
|
||||||
#'type': '<(gtest_target_type)',
|
'sources': [
|
||||||
#'sources': [
|
'wvm_media_parser_unittest.cc',
|
||||||
# 'wvm_media_parser_unittest.cc',
|
],
|
||||||
#],
|
'dependencies': [
|
||||||
#'dependencies': [
|
'../../../testing/gtest.gyp:gtest',
|
||||||
# '../../../testing/gtest.gyp:gtest',
|
'../../../testing/gmock.gyp:gmock',
|
||||||
# '../../../testing/gmock.gyp:gmock',
|
'../../test/media_test.gyp:media_test_support',
|
||||||
# '../../test/media_test.gyp:media_test_support',
|
'wvm',
|
||||||
# 'wvm',
|
]
|
||||||
#]
|
},
|
||||||
#},
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -21,15 +22,63 @@
|
||||||
#include "packager/media/test/test_data_util.h"
|
#include "packager/media/test/test_data_util.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
const int64_t kNoTimestamp = std::numeric_limits<int64_t>::min();
|
||||||
const char kWvmFile[] = "hb2_4stream_encrypted.wvm";
|
const char kWvmFile[] = "hb2_4stream_encrypted.wvm";
|
||||||
// Constants associated with kWvmFile follows.
|
// Constants associated with kWvmFile follows.
|
||||||
const uint32_t kExpectedStreams = 4;
|
const uint32_t kExpectedStreams = 4;
|
||||||
const int kExpectedVideoFrameCount = 6665;
|
const int kExpectedVideoFrameCount = 6665;
|
||||||
const int kExpectedAudioFrameCount = 11964;
|
const int kExpectedAudioFrameCount = 11964;
|
||||||
}
|
const char kServerUrl[] = "fake_server_url";
|
||||||
|
const char kSigner[] = "fake_signer";
|
||||||
|
const uint8 kExpectedAssetKey[16] = {'\006', static_cast<uint8>('\201'), '\177',
|
||||||
|
'H', 'k', static_cast<uint8>('\362'), '\177', '>', static_cast<uint8>('\307'),
|
||||||
|
'9', static_cast<uint8>('\250'), '?', '\022', '\n',
|
||||||
|
static_cast<uint8>('\322'), static_cast<uint8>('\374')};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
using ::testing::_;
|
||||||
|
using ::testing::DoAll;
|
||||||
|
using ::testing::InSequence;
|
||||||
|
using ::testing::Return;
|
||||||
|
using ::testing::SetArgPointee;
|
||||||
|
|
||||||
namespace edash_packager {
|
namespace edash_packager {
|
||||||
namespace media {
|
namespace media {
|
||||||
|
|
||||||
|
class FakeRequestSigner : public RequestSigner {
|
||||||
|
public:
|
||||||
|
FakeRequestSigner() : RequestSigner(kSigner) {}
|
||||||
|
virtual ~FakeRequestSigner() {}
|
||||||
|
|
||||||
|
virtual bool GenerateSignature(const std::string& message,
|
||||||
|
std::string* signature) OVERRIDE {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(FakeRequestSigner);
|
||||||
|
};
|
||||||
|
|
||||||
|
scoped_ptr<FakeRequestSigner> kFakeRequestSigner(new FakeRequestSigner());
|
||||||
|
|
||||||
|
class MockKeySource : public WidevineKeySource {
|
||||||
|
public:
|
||||||
|
MockKeySource() : WidevineKeySource(
|
||||||
|
kServerUrl, kFakeRequestSigner.PassAs<RequestSigner>()) {
|
||||||
|
// KeyProduction thread started in test because FetchKeys()
|
||||||
|
// is mocked. ~ClosureThread expects to terminate this thread.
|
||||||
|
key_production_thread_.Start();
|
||||||
|
}
|
||||||
|
virtual ~MockKeySource() {}
|
||||||
|
|
||||||
|
MOCK_METHOD1(FetchKeys, Status(uint32_t asset_id));
|
||||||
|
MOCK_METHOD2(GetKey, Status(TrackType track_type,
|
||||||
|
EncryptionKey* key));
|
||||||
|
|
||||||
|
private:
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(MockKeySource);
|
||||||
|
};
|
||||||
|
|
||||||
namespace wvm {
|
namespace wvm {
|
||||||
|
|
||||||
class WvmMediaParserTest : public testing::Test {
|
class WvmMediaParserTest : public testing::Test {
|
||||||
|
@ -40,29 +89,21 @@ class WvmMediaParserTest : public testing::Test {
|
||||||
video_max_dts_(kNoTimestamp),
|
video_max_dts_(kNoTimestamp),
|
||||||
current_track_id_(-1) {
|
current_track_id_(-1) {
|
||||||
parser_.reset(new WvmMediaParser());
|
parser_.reset(new WvmMediaParser());
|
||||||
const std::string server_url =
|
key_source_.reset(new MockKeySource());
|
||||||
"https://license.uat.widevine.com/cenc/getcontentkey/widevine_test";
|
encryption_key_.key.assign(kExpectedAssetKey, kExpectedAssetKey + 16);
|
||||||
const std::string aes_signing_key =
|
|
||||||
"1ae8ccd0e7985cc0b6203a55855a1034afc252980e970ca90e5202689f947ab9";
|
|
||||||
const std::string aes_signing_iv = "d58ce954203b7c9a9a9d467f59839249";
|
|
||||||
const std::string signer = "widevine_test";
|
|
||||||
request_signer_.reset(AesRequestSigner::CreateSigner(
|
|
||||||
signer, aes_signing_key, aes_signing_iv));
|
|
||||||
key_source_.reset(new WidevineKeySource(server_url,
|
|
||||||
request_signer_.Pass()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef std::map<int, scoped_refptr<StreamInfo> > StreamMap;
|
typedef std::map<int, scoped_refptr<StreamInfo> > StreamMap;
|
||||||
|
|
||||||
scoped_ptr<WvmMediaParser> parser_;
|
scoped_ptr<WvmMediaParser> parser_;
|
||||||
scoped_ptr<RequestSigner> request_signer_;
|
scoped_ptr<MockKeySource> key_source_;
|
||||||
scoped_ptr<WidevineKeySource> key_source_;
|
|
||||||
StreamMap stream_map_;
|
StreamMap stream_map_;
|
||||||
int audio_frame_count_;
|
int audio_frame_count_;
|
||||||
int video_frame_count_;
|
int video_frame_count_;
|
||||||
int64_t video_max_dts_;
|
int64_t video_max_dts_;
|
||||||
uint32_t current_track_id_;
|
uint32_t current_track_id_;
|
||||||
|
EncryptionKey encryption_key_;
|
||||||
|
|
||||||
void OnInit(const std::vector<scoped_refptr<StreamInfo> >& stream_infos) {
|
void OnInit(const std::vector<scoped_refptr<StreamInfo> >& stream_infos) {
|
||||||
DVLOG(1) << "OnInit: " << stream_infos.size() << " streams.";
|
DVLOG(1) << "OnInit: " << stream_infos.size() << " streams.";
|
||||||
|
@ -127,21 +168,12 @@ class WvmMediaParserTest : public testing::Test {
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(WvmMediaParserTest, ParseWvm) {
|
TEST_F(WvmMediaParserTest, ParseWvm) {
|
||||||
Parse(kWvmFile);
|
EXPECT_CALL(*key_source_, FetchKeys(_)).WillOnce(Return(Status::OK));
|
||||||
}
|
EXPECT_CALL(*key_source_, GetKey(_,_))
|
||||||
|
.WillOnce(DoAll(SetArgPointee<1>(encryption_key_), Return(Status::OK)));
|
||||||
TEST_F(WvmMediaParserTest, StreamCount) {
|
|
||||||
Parse(kWvmFile);
|
Parse(kWvmFile);
|
||||||
EXPECT_EQ(kExpectedStreams, stream_map_.size());
|
EXPECT_EQ(kExpectedStreams, stream_map_.size());
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(WvmMediaParserTest, VideoFrameCount) {
|
|
||||||
Parse(kWvmFile);
|
|
||||||
EXPECT_EQ(kExpectedVideoFrameCount, video_frame_count_);
|
EXPECT_EQ(kExpectedVideoFrameCount, video_frame_count_);
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(WvmMediaParserTest, AudioFrameCount) {
|
|
||||||
Parse(kWvmFile);
|
|
||||||
EXPECT_EQ(kExpectedAudioFrameCount, audio_frame_count_);
|
EXPECT_EQ(kExpectedAudioFrameCount, audio_frame_count_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue