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

Unified Diff: media/cdm/cenc_utils_unittest.cc

Issue 1145853002: DONT REVIEW: Move GetPsshData() into cenc_utils (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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') | 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 992361976d9be450e17bca96ff9fa07dfdcfb8a7..4432069c64823562060dda3d46dc95023f7a7673 100644
--- a/media/cdm/cenc_utils_unittest.cc
+++ b/media/cdm/cenc_utils_unittest.cc
@@ -25,6 +25,10 @@ const uint8_t kKey4Data[] = {
0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06,
0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06,
};
+const uint8_t kClearKeyUuid[] = {
+ 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02,
+ 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B
+};
class CencUtilsTest : public testing::Test {
public:
@@ -156,6 +160,19 @@ class CencUtilsTest : public testing::Test {
return box;
}
+ void AppendData(std::vector<uint8_t>& pssh_box,
+ const std::vector<uint8_t>& data) {
+ // This assumes that |pssh_box| has been created using the routines above,
+ // and simply appends the data to the end of it. It updates the box size
+ // and sets the data size.
+ DCHECK(data.size() < 100);
+ pssh_box[3] += data.size();
+ pssh_box.pop_back();
+ pssh_box.push_back(data.size());
+ for (const auto& item : data)
+ pssh_box.push_back(item);
+ }
+
const std::vector<uint8_t>& Key1() { return key1_; }
const std::vector<uint8_t>& Key2() { return key2_; }
const std::vector<uint8_t>& Key3() { return key3_; }
@@ -373,4 +390,107 @@ TEST_F(CencUtilsTest, HugeSize) {
std::vector<uint8_t>(data, data + arraysize(data)), &key_ids));
}
+TEST_F(CencUtilsTest, GetPsshDataVersion0) {
+ std::vector<uint8_t> clear_key(kClearKeyUuid,
+ kClearKeyUuid + arraysize(kClearKeyUuid));
+ std::vector<uint8_t> pssh_data;
+
+ std::vector<uint8_t> box = MakePSSHBox(0);
+ EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
+ EXPECT_EQ(0u, pssh_data.size());
+
+ std::vector<uint8_t> data = {0x01, 0x02, 0x03, 0x04};
+ AppendData(box, data);
+ EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
+ EXPECT_EQ(data, pssh_data);
+}
+
+TEST_F(CencUtilsTest, GetPsshDataVersion1NoKeys) {
+ std::vector<uint8_t> clear_key(kClearKeyUuid,
+ kClearKeyUuid + arraysize(kClearKeyUuid));
+ std::vector<uint8_t> pssh_data;
+
+ std::vector<uint8_t> box = MakePSSHBox(1);
+ EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
+ EXPECT_EQ(0u, pssh_data.size());
+
+ std::vector<uint8_t> data = {0x05, 0x06, 0x07, 0x08};
+ AppendData(box, data);
+ EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
+ EXPECT_EQ(data, pssh_data);
+}
+
+TEST_F(CencUtilsTest, GetPsshDataVersion1WithKeys) {
+ std::vector<uint8_t> clear_key(kClearKeyUuid,
+ kClearKeyUuid + arraysize(kClearKeyUuid));
+ std::vector<uint8_t> pssh_data;
+
+ std::vector<uint8_t> box = MakePSSHBox(1, Key1());
+ EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
+ EXPECT_EQ(0u, pssh_data.size());
+
+ std::vector<uint8_t> data = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
+ AppendData(box, data);
+ EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
+ EXPECT_EQ(data, pssh_data);
+}
+
+TEST_F(CencUtilsTest, GetPsshDataVersion2) {
+ std::vector<uint8_t> clear_key(kClearKeyUuid,
+ kClearKeyUuid + arraysize(kClearKeyUuid));
+ std::vector<uint8_t> pssh_data;
+
+ std::vector<uint8_t> box = MakePSSHBox(1, Key1());
+ EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
+ // Change the version manually, since we don't know what v2 will contain.
+ box[8] = 2;
+ EXPECT_FALSE(GetPsshData(box, clear_key, &pssh_data));
+}
+
+TEST_F(CencUtilsTest, GetPsshDataDifferentSystemID) {
+ std::vector<uint8_t> clear_key(kClearKeyUuid,
+ kClearKeyUuid + arraysize(kClearKeyUuid));
+ std::vector<uint8_t> unknown_system_id(kKey1Data,
+ kKey1Data + arraysize(kKey1Data));
+ std::vector<uint8_t> pssh_data;
+
+ std::vector<uint8_t> box = MakePSSHBox(1, Key1());
+ EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
+ EXPECT_FALSE(GetPsshData(box, unknown_system_id, &pssh_data));
+}
+
+TEST_F(CencUtilsTest, GetPsshDataMissingData) {
+ std::vector<uint8_t> clear_key(kClearKeyUuid,
+ kClearKeyUuid + arraysize(kClearKeyUuid));
+ std::vector<uint8_t> pssh_data;
+
+ std::vector<uint8_t> box = MakePSSHBox(1, Key1());
+ std::vector<uint8_t> data = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
+ AppendData(box, data);
+ EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
+ // Remove some data from the end, so now the size is incorrect.
+ box.pop_back();
+ box.pop_back();
+ EXPECT_FALSE(GetPsshData(box, clear_key, &pssh_data));
+}
+
+TEST_F(CencUtilsTest, GetPsshDataMultiplePssh) {
+ std::vector<uint8_t> clear_key(kClearKeyUuid,
+ kClearKeyUuid + arraysize(kClearKeyUuid));
+ std::vector<uint8_t> pssh_data;
+
+ std::vector<uint8_t> box1 = MakePSSHBox(1, Key1());
+ std::vector<uint8_t> data1 = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
+ AppendData(box1, data1);
+
+ std::vector<uint8_t> box2 = MakePSSHBox(0);
+ std::vector<uint8_t> data2 = {0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8};
+ AppendData(box2, data2);
+
+ box1.insert(box1.end(), box2.begin(), box2.end());
+ EXPECT_TRUE(GetPsshData(box1, clear_key, &pssh_data));
+ EXPECT_EQ(data1, pssh_data);
+ EXPECT_NE(data2, pssh_data);
+}
+
} // namespace media
« no previous file with comments | « media/cdm/cenc_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698