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

Unified Diff: media/cdm/cenc_utils_unittest.cc

Issue 1163713007: Use 'pssh' data to determine key_id properly (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test 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
« no previous file with comments | « media/cdm/cenc_utils.cc ('k') | media/test/data/bear-1280x720-a_frag-cenc.mp4 » ('j') | 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 3bc55ccda7ca37b1f8b16b7a718cf0c4f0190dda..e477243d837ce54052b07855dbcbe0452d28c4c2 100644
--- a/media/cdm/cenc_utils_unittest.cc
+++ b/media/cdm/cenc_utils_unittest.cc
@@ -180,24 +180,21 @@ class CencUtilsTest : public testing::Test {
TEST_F(CencUtilsTest, EmptyPSSH) {
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(std::vector<uint8_t>()));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(std::vector<uint8_t>(), &key_ids));
- EXPECT_EQ(0u, key_ids.size());
+ EXPECT_FALSE(GetKeyIdsForCommonSystemId(std::vector<uint8_t>(), &key_ids));
}
TEST_F(CencUtilsTest, PSSHVersion0) {
std::vector<uint8_t> box = MakePSSHBox(0);
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(box));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
- EXPECT_EQ(0u, key_ids.size());
+ EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
}
TEST_F(CencUtilsTest, PSSHVersion1WithNoKeys) {
std::vector<uint8_t> box = MakePSSHBox(1);
KeyIdList key_ids;
EXPECT_TRUE(ValidatePsshInput(box));
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
- EXPECT_EQ(0u, key_ids.size());
+ EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
}
TEST_F(CencUtilsTest, PSSHVersion1WithOneKey) {
@@ -258,6 +255,9 @@ TEST_F(CencUtilsTest, MultiplePSSHVersion1) {
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_EQ(key_ids[0], Key1());
@@ -266,15 +266,45 @@ TEST_F(CencUtilsTest, MultiplePSSHVersion1) {
EXPECT_EQ(key_ids[3], Key4());
}
-TEST_F(CencUtilsTest, InvalidPSSH) {
+TEST_F(CencUtilsTest, PsshBoxSmallerThanSize) {
std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
KeyIdList key_ids;
+
+ // Tries every size less than the actual size.
ddorwin 2015/06/18 01:02:15 This was my previous interpretation (perhaps based
jrummell 2015/06/18 02:04:12 Modified.
for (size_t i = 1; i < box.size(); ++i) {
- // Modify size of data passed to be less than real size.
+ // Modify size of box passed to be less than real size.
ddorwin 2015/06/18 01:02:15 "Modify size of box" confused me as modifying the
jrummell 2015/06/18 02:04:12 Done.
+ std::vector<uint8_t> truncated(&box[0], &box[0] + i);
+ EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i;
+ EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids));
+ }
+}
+
+TEST_F(CencUtilsTest, PsshBoxLargerThanSize) {
+ std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
+ KeyIdList key_ids;
+
+ // Add 20 additional bytes to |box|.
+ size_t original_size = box.size();
+ for (size_t i = 0; i < 20; ++i)
+ box.push_back(i);
+
+ // Tries every size greater than |original_size|.
+ for (size_t i = original_size + 1; i < box.size(); ++i) {
+ // 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));
- // Modify starting point.
+ }
+}
+
+TEST_F(CencUtilsTest, PsshBoxOffsetFromStart) {
ddorwin 2015/06/18 01:02:14 You could probably just test that anything that do
jrummell 2015/06/18 02:04:12 Removed as testing non-pssh boxes is done in https
+ std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
+ KeyIdList key_ids;
+
+ // Try every possible starting position.
+ for (size_t i = 1; i < box.size(); ++i) {
+ // Modify starting point of box. This should always fail as the modified
+ // box won't be a properly formatted 'pssh' box.
std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i);
EXPECT_FALSE(ValidatePsshInput(changed_offset)) << "Failed for offset "
<< i;
@@ -282,15 +312,14 @@ TEST_F(CencUtilsTest, InvalidPSSH) {
}
}
-TEST_F(CencUtilsTest, InvalidSystemID) {
+TEST_F(CencUtilsTest, UnrecognizedSystemID) {
std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
// Modify the System ID.
++box[20];
KeyIdList key_ids;
- EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
- EXPECT_EQ(0u, key_ids.size());
+ EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
}
TEST_F(CencUtilsTest, InvalidFlags) {
@@ -328,7 +357,7 @@ TEST_F(CencUtilsTest, LongSize) {
EXPECT_EQ(2u, key_ids.size());
}
-TEST_F(CencUtilsTest, NoSize) {
+TEST_F(CencUtilsTest, SizeIsZero) {
const uint8_t data[] = {
0x00, 0x00, 0x00, 0x00, // size = 0
0x70, 0x73, 0x73, 0x68, // 'pssh'
@@ -370,6 +399,8 @@ TEST_F(CencUtilsTest, HugeSize) {
};
KeyIdList key_ids;
+ // These calls fail as the box size is huge (0xffffffffffffffff) and there
+ // is not enough bytes in |data|.
EXPECT_FALSE(
ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
EXPECT_FALSE(GetKeyIdsForCommonSystemId(
« no previous file with comments | « media/cdm/cenc_utils.cc ('k') | media/test/data/bear-1280x720-a_frag-cenc.mp4 » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698