2017-03-28 19:31:32 +00:00
|
|
|
// Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
|
|
|
#include "packager/media/demuxer/demuxer.h"
|
|
|
|
|
2017-05-31 18:14:11 +00:00
|
|
|
#include <gmock/gmock.h>
|
2017-03-28 19:31:32 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2017-05-31 18:14:11 +00:00
|
|
|
#include "packager/media/base/media_handler_test_base.h"
|
2017-10-17 23:03:08 +00:00
|
|
|
#include "packager/media/base/raw_key_source.h"
|
2017-05-31 18:14:11 +00:00
|
|
|
#include "packager/media/test/test_data_util.h"
|
2017-06-29 22:23:53 +00:00
|
|
|
#include "packager/status_test_util.h"
|
2017-05-31 18:14:11 +00:00
|
|
|
|
2017-03-28 19:31:32 +00:00
|
|
|
namespace shaka {
|
|
|
|
namespace media {
|
2017-05-31 18:14:11 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
using ::testing::_;
|
|
|
|
using ::testing::Return;
|
|
|
|
using ::testing::SetArgPointee;
|
|
|
|
|
2017-10-17 23:03:08 +00:00
|
|
|
class MockKeySource : public RawKeySource {
|
2017-05-31 18:14:11 +00:00
|
|
|
public:
|
|
|
|
MOCK_METHOD2(GetKey,
|
|
|
|
Status(const std::vector<uint8_t>& key_id, EncryptionKey* key));
|
|
|
|
};
|
|
|
|
} // namespace
|
2017-03-28 19:31:32 +00:00
|
|
|
|
2017-09-14 16:23:29 +00:00
|
|
|
class DemuxerTest : public MediaHandlerGraphTestBase {
|
2017-05-31 18:14:11 +00:00
|
|
|
protected:
|
|
|
|
EncryptionKey GetMockEncryptionKey() {
|
|
|
|
const uint8_t kKeyId[]{
|
|
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
|
|
|
0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
|
|
|
|
};
|
|
|
|
const uint8_t kKey[]{
|
|
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
|
|
|
0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
|
|
|
|
};
|
|
|
|
EncryptionKey encryption_key;
|
|
|
|
encryption_key.key_id.assign(kKeyId, kKeyId + sizeof(kKeyId));
|
|
|
|
encryption_key.key.assign(kKey, kKey + sizeof(kKey));
|
|
|
|
return encryption_key;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_F(DemuxerTest, FileNotFound) {
|
2017-03-28 19:31:32 +00:00
|
|
|
Demuxer demuxer("file_not_exist.mp4");
|
|
|
|
EXPECT_EQ(error::FILE_FAILURE, demuxer.Run().error_code());
|
|
|
|
}
|
|
|
|
|
2017-05-31 18:14:11 +00:00
|
|
|
TEST_F(DemuxerTest, EncryptedContentWithoutKeySource) {
|
|
|
|
Demuxer demuxer(
|
|
|
|
GetAppTestDataFilePath("bear-640x360-v-cenc-golden.mp4").AsUTF8Unsafe());
|
|
|
|
ASSERT_OK(demuxer.SetHandler("video", some_handler()));
|
|
|
|
EXPECT_EQ(error::INVALID_ARGUMENT, demuxer.Run().error_code());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(DemuxerTest, EncryptedContentWithKeySource) {
|
|
|
|
std::unique_ptr<MockKeySource> mock_key_source(new MockKeySource);
|
|
|
|
EXPECT_CALL(*mock_key_source, GetKey(_, _))
|
|
|
|
.WillOnce(
|
|
|
|
DoAll(SetArgPointee<1>(GetMockEncryptionKey()), Return(Status::OK)));
|
|
|
|
|
|
|
|
Demuxer demuxer(
|
|
|
|
GetAppTestDataFilePath("bear-640x360-v-cenc-golden.mp4").AsUTF8Unsafe());
|
|
|
|
demuxer.SetKeySource(std::move(mock_key_source));
|
|
|
|
ASSERT_OK(demuxer.SetHandler("video", some_handler()));
|
|
|
|
EXPECT_OK(demuxer.Run());
|
|
|
|
}
|
|
|
|
|
2017-03-28 19:31:32 +00:00
|
|
|
// TODO(kqyang): Add more tests.
|
|
|
|
|
|
|
|
} // namespace media
|
|
|
|
} // namespace shaka
|