Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1410)

Unified Diff: media/cdm/cenc_utils_unittest.cc

Issue 1199643002: Have GetKeyIds() return the key IDs from the first matching 'pssh' box (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« media/cdm/cenc_utils.cc ('K') | « media/cdm/cenc_utils.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/cdm/cenc_utils_unittest.cc
diff --git a/media/cdm/cenc_utils_unittest.cc b/media/cdm/cenc_utils_unittest.cc
index af6066a03f78b4af9f9bd6db02cf07944ee23779..2b1076953e081bb0c886adc8e5f6e7307c156e18 100644
--- a/media/cdm/cenc_utils_unittest.cc
+++ b/media/cdm/cenc_utils_unittest.cc
@@ -180,28 +180,29 @@ class CencUtilsTest : public testing::Test {
TEST_F(CencUtilsTest, EmptyPSSH) {
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(std::vector<uint8_t>()));
- EXPECT_FALSE(GetKeyIdsForCommonSystemId(std::vector<uint8_t>(), &key_ids));
+ EXPECT_FALSE(GetKeyIdsFromPsshBoxes(std::vector<uint8_t>(),
+ CommonSystemSystemId(), &key_ids));
}
TEST_F(CencUtilsTest, PSSHVersion0) {
std::vector<uint8_t> box = MakePSSHBox(0);
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(box));
- EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
+ EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
}
TEST_F(CencUtilsTest, PSSHVersion1WithNoKeys) {
std::vector<uint8_t> box = MakePSSHBox(1);
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(box));
- EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
+ EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
}
TEST_F(CencUtilsTest, PSSHVersion1WithOneKey) {
std::vector<uint8_t> box = MakePSSHBox(1, Key1());
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(box));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
+ EXPECT_TRUE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
EXPECT_EQ(1u, key_ids.size());
EXPECT_EQ(key_ids[0], Key1());
}
@@ -210,7 +211,7 @@ TEST_F(CencUtilsTest, PSSHVersion1WithTwoKeys) {
std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(box));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
+ EXPECT_TRUE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
EXPECT_EQ(2u, key_ids.size());
EXPECT_EQ(key_ids[0], Key1());
EXPECT_EQ(key_ids[1], Key2());
@@ -222,12 +223,11 @@ TEST_F(CencUtilsTest, PSSHVersion0Plus1) {
// Concatentate box1 onto end of box0.
box0.insert(box0.end(), box1.begin(), box1.end());
+ EXPECT_TRUE(ValidatePsshInput(box0));
+ // No key IDs returned as only the first 'pssh' box is processed.
KeyIdList key_ids;
- EXPECT_TRUE(ValidatePsshInput(box0));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(box0, &key_ids));
- EXPECT_EQ(1u, key_ids.size());
- EXPECT_EQ(key_ids[0], Key1());
+ EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box0, CommonSystemSystemId(), &key_ids));
}
TEST_F(CencUtilsTest, PSSHVersion1Plus0) {
@@ -236,10 +236,10 @@ TEST_F(CencUtilsTest, PSSHVersion1Plus0) {
// Concatentate box0 onto end of box1.
box1.insert(box1.end(), box0.begin(), box0.end());
+ EXPECT_TRUE(ValidatePsshInput(box1));
KeyIdList key_ids;
- EXPECT_TRUE(ValidatePsshInput(box1));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(box1, &key_ids));
+ EXPECT_TRUE(GetKeyIdsFromPsshBoxes(box1, CommonSystemSystemId(), &key_ids));
EXPECT_EQ(1u, key_ids.size());
EXPECT_EQ(key_ids[0], Key1());
}
@@ -252,18 +252,13 @@ TEST_F(CencUtilsTest, MultiplePSSHVersion1) {
// Concatentate box1 and box2 onto end of box.
box.insert(box.end(), box1.begin(), box1.end());
box.insert(box.end(), box2.begin(), box2.end());
+ EXPECT_TRUE(ValidatePsshInput(box));
KeyIdList key_ids;
- EXPECT_TRUE(ValidatePsshInput(box));
- // TODO(jrummell): GetKeyIdsForCommonSystemId() returns the key IDs out of
- // all matching boxes. It should only return the key IDs from the first
- // matching box.
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
- EXPECT_EQ(4u, key_ids.size());
+ EXPECT_TRUE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
+ EXPECT_EQ(2u, key_ids.size());
EXPECT_EQ(key_ids[0], Key1());
EXPECT_EQ(key_ids[1], Key2());
- EXPECT_EQ(key_ids[2], Key3());
- EXPECT_EQ(key_ids[3], Key4());
}
TEST_F(CencUtilsTest, PsshBoxSmallerThanSize) {
@@ -275,7 +270,8 @@ TEST_F(CencUtilsTest, PsshBoxSmallerThanSize) {
// Truncate the box to be less than the specified box size.
std::vector<uint8_t> truncated(&box[0], &box[0] + i);
EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i;
- EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids));
+ EXPECT_FALSE(
+ GetKeyIdsFromPsshBoxes(truncated, CommonSystemSystemId(), &key_ids));
}
}
@@ -293,18 +289,55 @@ TEST_F(CencUtilsTest, PsshBoxLargerThanSize) {
// Modify size of box passed to be less than current size.
std::vector<uint8_t> truncated(&box[0], &box[0] + i);
EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i;
- EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids));
+ EXPECT_FALSE(
+ GetKeyIdsFromPsshBoxes(truncated, CommonSystemSystemId(), &key_ids));
}
}
TEST_F(CencUtilsTest, UnrecognizedSystemID) {
+ const uint8_t data[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
+ std::vector<uint8_t> different_system_id(data, data + arraysize(data));
+ KeyIdList key_ids;
+
std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
+ EXPECT_TRUE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
+ EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, different_system_id, &key_ids));
- // Modify the System ID.
+ // Modify the System ID and try again.
++box[20];
+ EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
+ EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, different_system_id, &key_ids));
+}
+TEST_F(CencUtilsTest, DifferentSystemID) {
+ const uint8_t data[] = {
+ 0x00, 0x00, 0x00, 0x44, // size
+ 'p', 's', 's', 'h',
+ 0x01, // version
+ 0x00, 0x00, 0x00, // flags
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // SystemID
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+ 0x00, 0x00, 0x00, 0x02, // key count
+ 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
+ 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
+ 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2
+ 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
+ 0x00, 0x00, 0x00, 0x00 // datasize
+ };
+ const uint8_t id_data[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
+ };
KeyIdList key_ids;
- EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
+
+ EXPECT_FALSE(
+ GetKeyIdsFromPsshBoxes(std::vector<uint8_t>(data, data + arraysize(data)),
+ CommonSystemSystemId(), &key_ids));
+ EXPECT_TRUE(GetKeyIdsFromPsshBoxes(
+ std::vector<uint8_t>(data, data + arraysize(data)),
+ std::vector<uint8_t>(id_data, id_data + arraysize(id_data)), &key_ids));
+ EXPECT_EQ(2u, key_ids.size());
}
TEST_F(CencUtilsTest, InvalidFlags) {
@@ -314,7 +347,7 @@ TEST_F(CencUtilsTest, InvalidFlags) {
box[10] = 3;
KeyIdList key_ids;
- EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
+ EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
}
TEST_F(CencUtilsTest, LongSize) {
@@ -337,8 +370,9 @@ TEST_F(CencUtilsTest, LongSize) {
KeyIdList key_ids;
EXPECT_TRUE(
ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(
- std::vector<uint8_t>(data, data + arraysize(data)), &key_ids));
+ EXPECT_TRUE(
+ GetKeyIdsFromPsshBoxes(std::vector<uint8_t>(data, data + arraysize(data)),
+ CommonSystemSystemId(), &key_ids));
EXPECT_EQ(2u, key_ids.size());
}
@@ -361,8 +395,9 @@ TEST_F(CencUtilsTest, SizeIsZero) {
KeyIdList key_ids;
EXPECT_TRUE(
ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(
- std::vector<uint8_t>(data, data + arraysize(data)), &key_ids));
+ EXPECT_TRUE(
+ GetKeyIdsFromPsshBoxes(std::vector<uint8_t>(data, data + arraysize(data)),
+ CommonSystemSystemId(), &key_ids));
EXPECT_EQ(2u, key_ids.size());
}
@@ -388,8 +423,9 @@ TEST_F(CencUtilsTest, HugeSize) {
// is not enough bytes in |data|.
EXPECT_FALSE(
ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
- EXPECT_FALSE(GetKeyIdsForCommonSystemId(
- std::vector<uint8_t>(data, data + arraysize(data)), &key_ids));
+ EXPECT_FALSE(
+ GetKeyIdsFromPsshBoxes(std::vector<uint8_t>(data, data + arraysize(data)),
+ CommonSystemSystemId(), &key_ids));
}
TEST_F(CencUtilsTest, GetPsshData_Version0) {
@@ -457,10 +493,10 @@ TEST_F(CencUtilsTest, GetPsshData_Version2ThenVersion1) {
boxes.insert(boxes.end(), box_v1.begin(), box_v1.end());
EXPECT_TRUE(GetPsshData(boxes, CommonSystemSystemId(), &pssh_data));
- // GetKeyIdsForCommonSystemId() should return the single key from the v1
+ // GetKeyIdsFromPsshBoxes() should return the single key from the v1
ddorwin 2015/06/25 22:49:23 nit: "... v1 box." should fit. Below too.
jrummell 2015/06/30 00:49:12 Back to the old name, need the wrap.
// 'pssh' box.
KeyIdList key_ids;
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(boxes, &key_ids));
+ EXPECT_TRUE(GetKeyIdsFromPsshBoxes(boxes, CommonSystemSystemId(), &key_ids));
EXPECT_EQ(1u, key_ids.size());
EXPECT_EQ(key_ids[0], Key1());
}
@@ -477,10 +513,10 @@ TEST_F(CencUtilsTest, GetPsshData_Version1ThenVersion2) {
boxes.insert(boxes.end(), box_v2.begin(), box_v2.end());
EXPECT_TRUE(GetPsshData(boxes, CommonSystemSystemId(), &pssh_data));
- // GetKeyIdsForCommonSystemId() should return the single key from the v1
+ // GetKeyIdsFromPsshBoxes() should return the single key from the v1
// 'pssh' box.
KeyIdList key_ids;
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(boxes, &key_ids));
+ EXPECT_TRUE(GetKeyIdsFromPsshBoxes(boxes, CommonSystemSystemId(), &key_ids));
EXPECT_EQ(1u, key_ids.size());
EXPECT_EQ(key_ids[0], Key3());
}
« media/cdm/cenc_utils.cc ('K') | « media/cdm/cenc_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698