Merge CDM LRU change to Android.
[ Merge of http://go/wvgerrit/81903 ] [ Merge of http://go/wvgerrit/87473 ] [ Merge of http://go/wvgerrit/82568 ] [ Merge of http://go/wvgerrit/87266 ] [ Merge of http://go/wvgerrit/87474 ] [ Merge of http://go/wvgerrit/87475 ] Bug: 135046978 Test: GTS and Android unit tests Change-Id: Iff2ff62cea21eeb36d7b56c8bb852fce8447ff89
This commit is contained in:
@@ -122,7 +122,8 @@ class MockUsageTableHeader : public UsageTableHeader {
|
||||
public:
|
||||
MockUsageTableHeader() : UsageTableHeader() {}
|
||||
|
||||
MOCK_METHOD2(UpdateEntry, CdmResponseType(CryptoSession* crypto_session,
|
||||
MOCK_METHOD3(UpdateEntry, CdmResponseType(uint32_t usage_entry_number,
|
||||
CryptoSession* crypto_session,
|
||||
CdmUsageEntry* usage_entry));
|
||||
};
|
||||
|
||||
@@ -345,7 +346,7 @@ TEST_F(CdmSessionTest, UpdateUsageEntry) {
|
||||
DoAll(SetArgPointee<0>(kUsageEntrySupport), Return(NO_ERROR)));
|
||||
EXPECT_CALL(*license_parser_, provider_session_token())
|
||||
.WillRepeatedly(Return("Mock provider session token"));
|
||||
EXPECT_CALL(usage_table_header_, UpdateEntry(NotNull(), NotNull()))
|
||||
EXPECT_CALL(usage_table_header_, UpdateEntry(_, NotNull(), NotNull()))
|
||||
.WillRepeatedly(Return(NO_ERROR));
|
||||
|
||||
EXPECT_EQ(NO_ERROR, cdm_session_->Init(nullptr));
|
||||
|
||||
@@ -1873,42 +1873,17 @@ constexpr size_t kNumberOfHlsAttributes = ArraySize(kHlsAttributesTestData);
|
||||
// kUsageTableInfoTestData are equal.
|
||||
const CdmUsageEntryInfo kUsageEntriesTestData[] = {
|
||||
// usage entry 0
|
||||
{
|
||||
kStorageLicense,
|
||||
"ksid0",
|
||||
"",
|
||||
},
|
||||
{kStorageLicense, "ksid0", "", 1318402800, 1321254000},
|
||||
// usage entry 1
|
||||
{
|
||||
kStorageLicense,
|
||||
"ksid1",
|
||||
"",
|
||||
},
|
||||
{kStorageLicense, "ksid1", "", 1050649200, 1053500400},
|
||||
// usage entry 2
|
||||
{
|
||||
kStorageUsageInfo,
|
||||
"",
|
||||
"app_id_2",
|
||||
},
|
||||
{kStorageUsageInfo, "", "app_id_2", 694252800, 0},
|
||||
// usage entry 3
|
||||
{
|
||||
kStorageUsageInfo,
|
||||
"",
|
||||
"app_id_3",
|
||||
},
|
||||
{kStorageUsageInfo, "", "app_id_3", 983001600, 0},
|
||||
// usage entry 4
|
||||
{
|
||||
kStorageLicense,
|
||||
"ksid4",
|
||||
"",
|
||||
},
|
||||
{kStorageLicense, "ksid4", "", 316166400, 319017600},
|
||||
// usage entry 5
|
||||
{
|
||||
kStorageUsageInfo,
|
||||
"",
|
||||
"app_id_5",
|
||||
},
|
||||
|
||||
{kStorageUsageInfo, "", "app_id_5", 802162800, 0},
|
||||
};
|
||||
|
||||
struct UsageTableTestInfo {
|
||||
@@ -1920,47 +1895,90 @@ const UsageTableTestInfo kUsageTableInfoTestData[] = {
|
||||
// usage table 0
|
||||
|
||||
{a2bs_hex("5574517CCC"),
|
||||
a2bs_hex("0A18080510013A120A055574517CCC1209080112056B73696430122018268E3F"
|
||||
"384F28D04BEE00304089C000463C22E987532855390915FD02C36B5C")},
|
||||
a2bs_hex("0A26080510013A200A055574517CCC1215080112056B7369643020F0F5D4F404"
|
||||
"28F0F882F6041801122055C2834976220A2819445B8D6EF5ADE9D7A050006941"
|
||||
"3EDFB9948F928B317B89")},
|
||||
// usage table 1
|
||||
{a2bs_hex("CA870203010001288001"),
|
||||
a2bs_hex("0A2C080510013A260A0ACA870203010001288001120B080112056B736964301A"
|
||||
"00120B080112056B736964311A00122049A8F3481444A5B64B6C4F05FBCC2EF8"
|
||||
"CB67444A08654763F2F5B80F658D7B38")},
|
||||
a2bs_hex("0A46080510013A400A0ACA8702030100012880011217080112056B736964301A"
|
||||
"0020F0F5D4F40428F0F882F6041217080112056B736964311A0020F0C4FEF403"
|
||||
"28F0C7ACF60318011220B000674E4E24E67384C4631DE05CB3C1E07CDE6B0412"
|
||||
"CACE359DEAED6CF2D566")},
|
||||
// usage table 2
|
||||
{a2bs_hex("7A7D507618A5D3A68F05228E023082010A028201"),
|
||||
a2bs_hex("0A46080510013A400A147A7D507618A5D3A68F05228E023082010A028201120B"
|
||||
"080112056B736964301A00120B080112056B736964311A00120E080212001A08"
|
||||
"6170705F69645F321220783E93A02223BDB94E743856C0F69C35B213ACCDDE91"
|
||||
"93E48E9186AA83B80584")},
|
||||
a2bs_hex("0A66080510013A600A147A7D507618A5D3A68F05228E023082010A0282011217"
|
||||
"080112056B736964301A0020F0F5D4F40428F0F882F6041217080112056B7369"
|
||||
"64311A0020F0C4FEF40328F0C7ACF6031214080212001A086170705F69645F32"
|
||||
"2080EA85CB02180112202701F8F75537EBA12217796401A81E9E0F59A5B10F51"
|
||||
"F6C12E3BE3D8747CB745")},
|
||||
// usage table 3
|
||||
{a2bs_hex("E83A4902772DAFD2740B7748E9C3B1752D6F12859CED07E82969B4EC"),
|
||||
a2bs_hex("0A5E080510013A580A1CE83A4902772DAFD2740B7748E9C3B1752D6F12859CED"
|
||||
"07E82969B4EC120B080112056B736964301A00120B080112056B736964311A00"
|
||||
"120E080212001A086170705F69645F32120E080212001A086170705F69645F33"
|
||||
"122084E67F1338727291BC3D92E28442DC8B0F44CB5AF7B98A799313B7EB7F55"
|
||||
"ED18")},
|
||||
a2bs_hex("0A8401080510013A7E0A1CE83A4902772DAFD2740B7748E9C3B1752D6F12859C"
|
||||
"ED07E82969B4EC1217080112056B736964301A0020F0F5D4F40428F0F882F604"
|
||||
"1217080112056B736964311A0020F0C4FEF40328F0C7ACF6031214080212001A"
|
||||
"086170705F69645F322080EA85CB021214080212001A086170705F69645F3320"
|
||||
"80D4DDD40318011220776BD3D0BBCC573AEC7466A8B0E4F1A013495A3BE492F3"
|
||||
"FF4BA3D15FC9697902")},
|
||||
// usage table 4
|
||||
{a2bs_hex("CA870203010001288001300112800250D1F8B1ECF849B60FF93E37C4DEEF"
|
||||
"52F1CCFC047EF42300131F9C4758F4"),
|
||||
a2bs_hex("0A7C080510013A760A2DCA870203010001288001300112800250D1F8B1ECF849"
|
||||
"B60FF93E37C4DEEF52F1CCFC047EF42300131F9C4758F4120B080112056B7369"
|
||||
"64301A00120B080112056B736964311A00120E080212001A086170705F69645F"
|
||||
"32120E080212001A086170705F69645F33120B080112056B736964341A001220"
|
||||
"1CDFCFED5E58A1DF77E1B335305424E1F0260340F9CC15985684C43A4207652"
|
||||
"1")},
|
||||
a2bs_hex("0AAF01080510013AA8010A2DCA870203010001288001300112800250D1F8B1EC"
|
||||
"F849B60FF93E37C4DEEF52F1CCFC047EF42300131F9C4758F41217080112056B"
|
||||
"736964301A0020F0F5D4F40428F0F882F6041217080112056B736964311A0020"
|
||||
"F0C4FEF40328F0C7ACF6031214080212001A086170705F69645F322080EA85CB"
|
||||
"021214080212001A086170705F69645F332080D4DDD4031217080112056B7369"
|
||||
"64341A002080A2E196012880A58F980118011220E7F0F123E513FCF3BC6BC17B"
|
||||
"1531A8317654C5EF005655348D82FA01FDAD85CB")},
|
||||
// usage table 5
|
||||
{a2bs_hex("EC83A4902772DAFD2740B7748E9C3B1752D6F12859CED07E8882969B433E"
|
||||
"C29AC6FDBE79230B0FAED5D94CF6B829A420BBE3270323941776EE60DD6B"),
|
||||
a2bs_hex("0A9C01080510013A95010A3CEC83A4902772DAFD2740B7748E9C3B1752D6F128"
|
||||
a2bs_hex("0AD401080510013ACD010A3CEC83A4902772DAFD2740B7748E9C3B1752D6F128"
|
||||
"59CED07E8882969B433EC29AC6FDBE79230B0FAED5D94CF6B829A420BBE32703"
|
||||
"23941776EE60DD6B120B080112056B736964301A00120B080112056B73696431"
|
||||
"1A00120E080212001A086170705F69645F32120E080212001A086170705F6964"
|
||||
"5F33120B080112056B736964341A00120E080212001A086170705F69645F3512"
|
||||
"20305C7A27A918268119E1996FC182C153DF805034A387F90C3585749E764731"
|
||||
"32")},
|
||||
"23941776EE60DD6B1217080112056B736964301A0020F0F5D4F40428F0F882F6"
|
||||
"041217080112056B736964311A0020F0C4FEF40328F0C7ACF603121408021200"
|
||||
"1A086170705F69645F322080EA85CB021214080212001A086170705F69645F33"
|
||||
"2080D4DDD4031217080112056B736964341A002080A2E196012880A58F980112"
|
||||
"14080212001A086170705F69645F3520F090C0FE0218011220A35C771A67AECF"
|
||||
"06A72468DC2C380E5CFDCD377A8ADF848F26B7F22D24D23872")},
|
||||
};
|
||||
|
||||
const CdmUsageEntryInfo kUsageEntriesWithoutLruData[] = {
|
||||
{kStorageLicense, "ksid0", "", 0, 0},
|
||||
{kStorageUsageInfo, "", "app_id_1", 0, 0}};
|
||||
|
||||
const std::string kUsageTableWithoutLruData = a2bs_hex(
|
||||
"0A1F080510013A191209080112056B73696430120C08021A086170705F69645F"
|
||||
"31122044C964271799F0631AE388BD150A873C5DD16B35F61BFF0300857AEEB8"
|
||||
"454FA2");
|
||||
|
||||
// DeleteMultipleUsageInfoByKeySetIds test data.
|
||||
|
||||
const std::string kHashedUsageInfoFileWithThreeKeySetIds = a2bs_hex(
|
||||
"0A36080310012A300A0E220C6B65795F7365745F69645F310A0E220C6B65795F"
|
||||
"7365745F69645F320A0E220C6B65795F7365745F69645F331220781BE848CE8A"
|
||||
"0CE84FF563D54D30150A115EAB27F7023C19191EC41BDC4EDAA9");
|
||||
// Only contains key set ID 1 & 2.
|
||||
const std::string kHashedUsageInfoFileWithTwoKeySetIds = a2bs_hex(
|
||||
"0A26080310012A200A0E220C6B65795F7365745F69645F310A0E220C6B65795F"
|
||||
"7365745F69645F321220B693E7142BF263FF51B6F8AF4DD7F20E2701059A841C"
|
||||
"F947995A7B39354E1CA9");
|
||||
const std::string kHashedUsageInfoFileWithKeySet1 = a2bs_hex(
|
||||
"0A16080310012A100A0E220C6B65795F7365745F69645F3112200FBBB47C89DE"
|
||||
"484D02BFB4CB20B19BA43CBCAD6F4A78EFB295ACC66BA0B83B85");
|
||||
const std::string kHashedUsageInfoFileWithKeySet2 = a2bs_hex(
|
||||
"0A16080310012A100A0E220C6B65795F7365745F69645F321220B5F53E5A1D8E"
|
||||
"860196D2B3E027FFB32F11C1B2269784A904A3EA6E59C2A6A96D");
|
||||
const std::string kHashedUsageInfoFileWithKeySet3 = a2bs_hex(
|
||||
"0A16080310012A100A0E220C6B65795F7365745F69645F331220F28C1B20A302"
|
||||
"543F44659D995A58899A03B9D51C65FD6C05AD1E6D2BACACADA7");
|
||||
|
||||
const std::vector<std::string> kHashedUsageInfoFileWithSingleKeySetList = {
|
||||
kHashedUsageInfoFileWithKeySet1, kHashedUsageInfoFileWithKeySet2,
|
||||
kHashedUsageInfoFileWithKeySet3};
|
||||
|
||||
const std::vector<std::string> kHashedUsageInfoFileKeySetList = {
|
||||
"key_set_id_1", "key_set_id_2", "key_set_id_3"};
|
||||
|
||||
class MockFile : public File {
|
||||
public:
|
||||
MockFile() {}
|
||||
@@ -1999,6 +2017,7 @@ using ::testing::_;
|
||||
using ::testing::AllOf;
|
||||
using ::testing::DoAll;
|
||||
using ::testing::Eq;
|
||||
using ::testing::Expectation;
|
||||
using ::testing::Gt;
|
||||
using ::testing::HasSubstr;
|
||||
using ::testing::InSequence;
|
||||
@@ -2078,6 +2097,10 @@ class DeviceFilesHlsAttributesTest
|
||||
class DeviceFilesUsageTableTest : public DeviceFilesTest,
|
||||
public ::testing::WithParamInterface<int> {};
|
||||
|
||||
class DeviceFilesDeleteMultipleUsageInfoTest
|
||||
: public DeviceFilesTest,
|
||||
public ::testing::WithParamInterface<int> {};
|
||||
|
||||
MATCHER(IsCreateFileFlagSet, "") { return FileSystem::kCreate & arg; }
|
||||
MATCHER_P(IsStrEq, str, "") {
|
||||
// Estimating the length of data. We can have gmock provide length
|
||||
@@ -2606,6 +2629,221 @@ TEST_F(DeviceFilesTest, ReserveLicenseIdsDoesNotUseFileSystem) {
|
||||
}
|
||||
}
|
||||
|
||||
// From a usage info file containing 3 provider sessions, 2 will be
|
||||
// deleted using the |key_set_id| associated with them.
|
||||
// It is expected that once the provider sessions are deleted, the
|
||||
// usage info file will be overwritten with only the remaining provider
|
||||
// session token present.
|
||||
TEST_P(DeviceFilesDeleteMultipleUsageInfoTest, DeleteAllButOne) {
|
||||
static const std::string kUsageInfoFileName = "usage_info_file.bin";
|
||||
const int key_set_id_index = GetParam();
|
||||
|
||||
const std::string& result_hashed_usage_info_file =
|
||||
kHashedUsageInfoFileWithSingleKeySetList[key_set_id_index];
|
||||
|
||||
MockFileSystem file_system;
|
||||
DeviceFiles device_files(&file_system);
|
||||
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
std::string file_path;
|
||||
ASSERT_TRUE(Properties::GetDeviceFilesBasePath(kSecurityLevelL1, &file_path));
|
||||
file_path += kUsageInfoFileName;
|
||||
|
||||
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(file_path))
|
||||
.WillOnce(Return(kHashedUsageInfoFileWithThreeKeySetIds.size()));
|
||||
|
||||
// File read expectations.
|
||||
MockFile* file_in = new MockFile();
|
||||
EXPECT_CALL(file_system, DoOpen(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(file_in));
|
||||
Expectation read_original =
|
||||
EXPECT_CALL(*file_in, Read(NotNull(), _))
|
||||
.WillOnce(
|
||||
DoAll(SetArrayArgument<0>(
|
||||
kHashedUsageInfoFileWithThreeKeySetIds.cbegin(),
|
||||
kHashedUsageInfoFileWithThreeKeySetIds.cend()),
|
||||
Return(kHashedUsageInfoFileWithThreeKeySetIds.size())));
|
||||
|
||||
// File write expectations.
|
||||
MockFile* file_out = new MockFile();
|
||||
EXPECT_CALL(file_system,
|
||||
DoOpen(file_path, FileSystem::kCreate | FileSystem::kTruncate))
|
||||
.WillOnce(Return(file_out));
|
||||
EXPECT_CALL(*file_out, Write(StrEq(result_hashed_usage_info_file), _))
|
||||
.After(read_original)
|
||||
.WillOnce(Return(result_hashed_usage_info_file.size()));
|
||||
|
||||
const auto not_current_key_set =
|
||||
[key_set_id_index](const std::string& key_set_id) {
|
||||
return key_set_id != kHashedUsageInfoFileKeySetList[key_set_id_index];
|
||||
};
|
||||
std::vector<std::string> to_remove;
|
||||
std::copy_if(kHashedUsageInfoFileKeySetList.cbegin(),
|
||||
kHashedUsageInfoFileKeySetList.cend(),
|
||||
std::back_inserter(to_remove), not_current_key_set);
|
||||
EXPECT_TRUE(device_files.DeleteMultipleUsageInfoByKeySetIds(
|
||||
kUsageInfoFileName, to_remove));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(DeviceFilesTest, DeviceFilesDeleteMultipleUsageInfoTest,
|
||||
::testing::Range(0, 3));
|
||||
|
||||
// Delete all provider sessions from a usage info file. It is expected
|
||||
// that the usage info file will be deleted (not written back to with
|
||||
// an empty provider session list).
|
||||
TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteAllKeySetIds) {
|
||||
static const std::string kUsageInfoFileName = "usage_info_file.bin";
|
||||
|
||||
// Setup
|
||||
MockFileSystem file_system;
|
||||
DeviceFiles device_files(&file_system);
|
||||
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
std::string file_path;
|
||||
ASSERT_TRUE(Properties::GetDeviceFilesBasePath(kSecurityLevelL1, &file_path));
|
||||
file_path += kUsageInfoFileName;
|
||||
|
||||
// File read expectations.
|
||||
MockFile* file_in = new MockFile();
|
||||
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(file_path))
|
||||
.WillOnce(Return(kHashedUsageInfoFileWithThreeKeySetIds.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(file_in));
|
||||
EXPECT_CALL(*file_in, Read(NotNull(), _))
|
||||
.WillOnce(DoAll(
|
||||
SetArrayArgument<0>(kHashedUsageInfoFileWithThreeKeySetIds.cbegin(),
|
||||
kHashedUsageInfoFileWithThreeKeySetIds.cend()),
|
||||
Return(kHashedUsageInfoFileWithThreeKeySetIds.size())));
|
||||
EXPECT_CALL(file_system, Remove(file_path)).WillOnce(Return(true));
|
||||
|
||||
// Remove all sessions, and the file should be deleted.
|
||||
EXPECT_TRUE(device_files.DeleteMultipleUsageInfoByKeySetIds(
|
||||
kUsageInfoFileName, kHashedUsageInfoFileKeySetList));
|
||||
}
|
||||
|
||||
// If the key set IDs provided cannot be found in the usage info file,
|
||||
// then no action should be taken, and the function returns true.
|
||||
TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteNone) {
|
||||
static const std::string kUsageInfoFileName = "usage_info_file.bin";
|
||||
|
||||
// Setup
|
||||
MockFileSystem file_system;
|
||||
DeviceFiles device_files(&file_system);
|
||||
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
std::string file_path;
|
||||
ASSERT_TRUE(Properties::GetDeviceFilesBasePath(kSecurityLevelL1, &file_path));
|
||||
file_path += kUsageInfoFileName;
|
||||
|
||||
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
|
||||
|
||||
// Call, not providing any key set IDs. Should return true without any
|
||||
// action, assuming the file exists.
|
||||
EXPECT_TRUE(device_files.DeleteMultipleUsageInfoByKeySetIds(
|
||||
kUsageInfoFileName, std::vector<std::string>()));
|
||||
|
||||
MockFile* file_in = new MockFile();
|
||||
EXPECT_CALL(file_system, FileSize(file_path))
|
||||
.WillOnce(Return(kHashedUsageInfoFileWithThreeKeySetIds.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(file_in));
|
||||
EXPECT_CALL(*file_in, Read(NotNull(), _))
|
||||
.WillOnce(DoAll(
|
||||
SetArrayArgument<0>(kHashedUsageInfoFileWithThreeKeySetIds.cbegin(),
|
||||
kHashedUsageInfoFileWithThreeKeySetIds.cend()),
|
||||
Return(kHashedUsageInfoFileWithThreeKeySetIds.size())));
|
||||
|
||||
// Call, providing key set IDs which do not exist in the usage info
|
||||
// file.
|
||||
const std::vector<std::string> key_set_ids = {"fictional_key_set_id_1",
|
||||
"fictional_key_set_id_2",
|
||||
"fictional_key_set_id_3"};
|
||||
EXPECT_TRUE(device_files.DeleteMultipleUsageInfoByKeySetIds(
|
||||
kUsageInfoFileName, key_set_ids));
|
||||
}
|
||||
|
||||
// Delete a single key from the file.
|
||||
// Test will delete "key_set_id_2" from the usage info file containing
|
||||
// "key_set_id_1" & "key_set_id_2".
|
||||
TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, DeleteOne) {
|
||||
static const std::string kUsageInfoFileName = "usage_info_file.bin";
|
||||
|
||||
MockFileSystem file_system;
|
||||
DeviceFiles device_files(&file_system);
|
||||
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
std::string file_path;
|
||||
ASSERT_TRUE(Properties::GetDeviceFilesBasePath(kSecurityLevelL1, &file_path));
|
||||
file_path += kUsageInfoFileName;
|
||||
|
||||
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(file_path))
|
||||
.WillOnce(Return(kHashedUsageInfoFileWithTwoKeySetIds.size()));
|
||||
|
||||
// File read expectations.
|
||||
MockFile* file_in = new MockFile();
|
||||
EXPECT_CALL(file_system, DoOpen(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(file_in));
|
||||
Expectation read_original =
|
||||
EXPECT_CALL(*file_in, Read(NotNull(), _))
|
||||
.WillOnce(DoAll(
|
||||
SetArrayArgument<0>(kHashedUsageInfoFileWithTwoKeySetIds.cbegin(),
|
||||
kHashedUsageInfoFileWithTwoKeySetIds.cend()),
|
||||
Return(kHashedUsageInfoFileWithTwoKeySetIds.size())));
|
||||
|
||||
// File write expectations.
|
||||
MockFile* file_out = new MockFile();
|
||||
EXPECT_CALL(file_system,
|
||||
DoOpen(file_path, FileSystem::kCreate | FileSystem::kTruncate))
|
||||
.WillOnce(Return(file_out));
|
||||
EXPECT_CALL(*file_out, Write(StrEq(kHashedUsageInfoFileWithKeySet1), _))
|
||||
.After(read_original)
|
||||
.WillOnce(Return(kHashedUsageInfoFileWithKeySet1.size()));
|
||||
|
||||
const std::vector<std::string> to_remove = {"key_set_id_2"};
|
||||
EXPECT_TRUE(device_files.DeleteMultipleUsageInfoByKeySetIds(
|
||||
kUsageInfoFileName, to_remove));
|
||||
}
|
||||
|
||||
// There are a few error cases where DeleteMultipleUsageInfoByKeySetIds()
|
||||
// will fail. Such as if the specified file does not exist, or if it
|
||||
// the file is found to have a hash mismatch. In both these cases,
|
||||
// false should be returned.
|
||||
TEST_F(DeviceFilesDeleteMultipleUsageInfoTest, BadFile) {
|
||||
static const std::string kUsageInfoFileName = "usage_info_file.bin";
|
||||
static const std::string kHashlessUsageInfoFile = a2bs_hex(
|
||||
"0A36080310012A300A0E220C6B65795F7365745F69645F310A0E220C6B65795F"
|
||||
"7365745F69645F320A0E220C6B65795F7365745F69645F331220000000000000"
|
||||
"0000000000000000000000000000000000000000000000000000");
|
||||
// Setup
|
||||
MockFileSystem file_system;
|
||||
DeviceFiles device_files(&file_system);
|
||||
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
std::string file_path;
|
||||
ASSERT_TRUE(Properties::GetDeviceFilesBasePath(kSecurityLevelL1, &file_path));
|
||||
file_path += kUsageInfoFileName;
|
||||
|
||||
// File does not exist.
|
||||
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(false));
|
||||
EXPECT_FALSE(device_files.DeleteMultipleUsageInfoByKeySetIds(
|
||||
kUsageInfoFileName, kHashedUsageInfoFileKeySetList));
|
||||
|
||||
// File is missing hash.
|
||||
MockFile* file_in = new MockFile();
|
||||
EXPECT_CALL(file_system, Exists(_)).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(file_path))
|
||||
.WillOnce(Return(kHashlessUsageInfoFile.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(file_path, FileSystem::kReadOnly))
|
||||
.WillOnce(Return(file_in));
|
||||
EXPECT_CALL(*file_in, Read(NotNull(), _))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(kHashlessUsageInfoFile.cbegin(),
|
||||
kHashlessUsageInfoFile.cend()),
|
||||
Return(kHashlessUsageInfoFile.size())));
|
||||
|
||||
EXPECT_CALL(file_system, Remove(file_path)).WillOnce(Return(true));
|
||||
// Remove all sessions, and the file should be deleted.
|
||||
EXPECT_FALSE(device_files.DeleteMultipleUsageInfoByKeySetIds(
|
||||
kUsageInfoFileName, kHashedUsageInfoFileKeySetList));
|
||||
}
|
||||
|
||||
TEST_F(DeviceFilesUsageInfoTest, ListNullParam) {
|
||||
MockFileSystem file_system;
|
||||
|
||||
@@ -3209,8 +3447,9 @@ TEST_P(DeviceFilesUsageTableTest, Read) {
|
||||
|
||||
std::vector<CdmUsageEntryInfo> usage_entry_info;
|
||||
CdmUsageTableHeader usage_table_header;
|
||||
ASSERT_TRUE(device_files.RetrieveUsageTableInfo(&usage_table_header,
|
||||
&usage_entry_info));
|
||||
bool lru_upgrade;
|
||||
ASSERT_TRUE(device_files.RetrieveUsageTableInfo(
|
||||
&usage_table_header, &usage_entry_info, &lru_upgrade));
|
||||
EXPECT_EQ(kUsageTableInfoTestData[index].usage_table_header,
|
||||
usage_table_header);
|
||||
EXPECT_EQ(index + 1u, usage_entry_info.size());
|
||||
@@ -3222,10 +3461,52 @@ TEST_P(DeviceFilesUsageTableTest, Read) {
|
||||
usage_entry_info[i].key_set_id);
|
||||
EXPECT_EQ(kUsageEntriesTestData[i].usage_info_file_name,
|
||||
usage_entry_info[i].usage_info_file_name);
|
||||
EXPECT_EQ(kUsageEntriesTestData[i].last_use_time,
|
||||
usage_entry_info[i].last_use_time);
|
||||
EXPECT_EQ(kUsageEntriesTestData[i].offline_license_expiry_time,
|
||||
usage_entry_info[i].offline_license_expiry_time);
|
||||
}
|
||||
|
||||
EXPECT_FALSE(lru_upgrade);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(UsageInfo, DeviceFilesUsageTableTest,
|
||||
::testing::Range(0, 6));
|
||||
|
||||
TEST_F(DeviceFilesUsageTableTest, ReadWithoutLruData) {
|
||||
// Setup file.
|
||||
MockFile* file = new MockFile();
|
||||
EXPECT_CALL(*file, Read(NotNull(), Eq(kUsageTableWithoutLruData.size())))
|
||||
.WillOnce(DoAll(SetArrayArgument<0>(kUsageTableWithoutLruData.cbegin(),
|
||||
kUsageTableWithoutLruData.cend()),
|
||||
Return(kUsageTableWithoutLruData.size())));
|
||||
// Setup filesystem.
|
||||
const std::string path =
|
||||
device_base_path_ + DeviceFiles::GetUsageTableFileName();
|
||||
MockFileSystem file_system;
|
||||
EXPECT_CALL(file_system, Exists(StrEq(path))).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(file_system, FileSize(StrEq(path)))
|
||||
.WillRepeatedly(Return(kUsageTableWithoutLruData.size()));
|
||||
EXPECT_CALL(file_system, DoOpen(StrEq(path), _)).WillOnce(Return(file));
|
||||
|
||||
DeviceFiles device_files(&file_system);
|
||||
EXPECT_TRUE(device_files.Init(kSecurityLevelL1));
|
||||
|
||||
std::vector<CdmUsageEntryInfo> usage_entry_info;
|
||||
CdmUsageTableHeader usage_table_header;
|
||||
bool lru_upgrade;
|
||||
ASSERT_TRUE(device_files.RetrieveUsageTableInfo(
|
||||
&usage_table_header, &usage_entry_info, &lru_upgrade));
|
||||
|
||||
EXPECT_EQ(ArraySize(kUsageEntriesWithoutLruData), usage_entry_info.size());
|
||||
|
||||
for (size_t i = 0; i < ArraySize(kUsageEntriesWithoutLruData); ++i) {
|
||||
const CdmUsageEntryInfo& expected_entry = kUsageEntriesWithoutLruData[i];
|
||||
const CdmUsageEntryInfo& retrieved_entry = usage_entry_info[i];
|
||||
EXPECT_EQ(expected_entry, retrieved_entry);
|
||||
}
|
||||
|
||||
EXPECT_TRUE(lru_upgrade);
|
||||
}
|
||||
|
||||
} // namespace wvcdm
|
||||
|
||||
@@ -15,6 +15,18 @@ class MockClock : public Clock {
|
||||
MOCK_METHOD0(GetCurrentTime, int64_t());
|
||||
};
|
||||
|
||||
// Frozen clock will always return the same value for the current time.
|
||||
// Intended to be used for testing where using the actual time would
|
||||
// cause flaky tests.
|
||||
class FrozenClock : public Clock {
|
||||
int64_t always_time_;
|
||||
|
||||
public:
|
||||
FrozenClock(int64_t always_time = 0) : always_time_(always_time) {}
|
||||
int64_t GetCurrentTime() override { return always_time_; }
|
||||
void SetTime(int64_t new_time) { always_time_ = new_time; }
|
||||
};
|
||||
|
||||
} // wvcdm
|
||||
|
||||
#endif // CDM_TEST_MOCK_CLOCK_H_
|
||||
|
||||
@@ -884,6 +884,9 @@ void PrintTo(const enum CdmResponseType& value, ::std::ostream* os) {
|
||||
case USAGE_INVALID_PARAMETERS_1:
|
||||
*os << "USAGE_INVALID_PARAMETERS_1";
|
||||
break;
|
||||
case USAGE_INVALID_PARAMETERS_2:
|
||||
*os << "USAGE_INVALID_PARAMETERS_2";
|
||||
break;
|
||||
case USAGE_STORE_ENTRY_RETRIEVE_INVALID_STORAGE_TYPE:
|
||||
*os << "USAGE_STORE_ENTRY_RETRIEVE_INVALID_STORAGE_TYPE";
|
||||
break;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user