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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « media/cdm/cenc_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/cdm/cenc_utils.h" 5 #include "media/cdm/cenc_utils.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace media { 10 namespace media {
11 11
12 const uint8_t kKey1Data[] = { 12 const uint8_t kKey1Data[] = {
13 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 13 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
14 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03 14 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03
15 }; 15 };
16 const uint8_t kKey2Data[] = { 16 const uint8_t kKey2Data[] = {
17 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 17 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
18 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 18 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
19 }; 19 };
20 const uint8_t kKey3Data[] = { 20 const uint8_t kKey3Data[] = {
21 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x05, 21 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x05,
22 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x05, 22 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x05,
23 }; 23 };
24 const uint8_t kKey4Data[] = { 24 const uint8_t kKey4Data[] = {
25 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06, 25 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06,
26 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06, 26 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06,
27 }; 27 };
28 const uint8_t kClearKeyUuid[] = {
29 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02,
30 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B
31 };
28 32
29 class CencUtilsTest : public testing::Test { 33 class CencUtilsTest : public testing::Test {
30 public: 34 public:
31 CencUtilsTest() 35 CencUtilsTest()
32 : key1_(kKey1Data, kKey1Data + arraysize(kKey1Data)), 36 : key1_(kKey1Data, kKey1Data + arraysize(kKey1Data)),
33 key2_(kKey2Data, kKey2Data + arraysize(kKey2Data)), 37 key2_(kKey2Data, kKey2Data + arraysize(kKey2Data)),
34 key3_(kKey3Data, kKey3Data + arraysize(kKey3Data)), 38 key3_(kKey3Data, kKey3Data + arraysize(kKey3Data)),
35 key4_(kKey4Data, kKey4Data + arraysize(kKey4Data)) {} 39 key4_(kKey4Data, kKey4Data + arraysize(kKey4Data)) {}
36 40
37 protected: 41 protected:
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 box.push_back(key2[i]); 153 box.push_back(key2[i]);
150 154
151 // Add data_size (= 0). 155 // Add data_size (= 0).
152 box.push_back(0); 156 box.push_back(0);
153 box.push_back(0); 157 box.push_back(0);
154 box.push_back(0); 158 box.push_back(0);
155 box.push_back(0); 159 box.push_back(0);
156 return box; 160 return box;
157 } 161 }
158 162
163 void AppendData(std::vector<uint8_t>& pssh_box,
164 const std::vector<uint8_t>& data) {
165 // This assumes that |pssh_box| has been created using the routines above,
166 // and simply appends the data to the end of it. It updates the box size
167 // and sets the data size.
168 DCHECK(data.size() < 100);
169 pssh_box[3] += data.size();
170 pssh_box.pop_back();
171 pssh_box.push_back(data.size());
172 for (const auto& item : data)
173 pssh_box.push_back(item);
174 }
175
159 const std::vector<uint8_t>& Key1() { return key1_; } 176 const std::vector<uint8_t>& Key1() { return key1_; }
160 const std::vector<uint8_t>& Key2() { return key2_; } 177 const std::vector<uint8_t>& Key2() { return key2_; }
161 const std::vector<uint8_t>& Key3() { return key3_; } 178 const std::vector<uint8_t>& Key3() { return key3_; }
162 const std::vector<uint8_t>& Key4() { return key4_; } 179 const std::vector<uint8_t>& Key4() { return key4_; }
163 180
164 private: 181 private:
165 std::vector<uint8_t> key1_; 182 std::vector<uint8_t> key1_;
166 std::vector<uint8_t> key2_; 183 std::vector<uint8_t> key2_;
167 std::vector<uint8_t> key3_; 184 std::vector<uint8_t> key3_;
168 std::vector<uint8_t> key4_; 185 std::vector<uint8_t> key4_;
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 0x00, 0x00, 0x00, 0x00 // datasize 383 0x00, 0x00, 0x00, 0x00 // datasize
367 }; 384 };
368 385
369 KeyIdList key_ids; 386 KeyIdList key_ids;
370 EXPECT_FALSE( 387 EXPECT_FALSE(
371 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); 388 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
372 EXPECT_FALSE(GetKeyIdsForCommonSystemId( 389 EXPECT_FALSE(GetKeyIdsForCommonSystemId(
373 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); 390 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids));
374 } 391 }
375 392
393 TEST_F(CencUtilsTest, GetPsshDataVersion0) {
394 std::vector<uint8_t> clear_key(kClearKeyUuid,
395 kClearKeyUuid + arraysize(kClearKeyUuid));
396 std::vector<uint8_t> pssh_data;
397
398 std::vector<uint8_t> box = MakePSSHBox(0);
399 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
400 EXPECT_EQ(0u, pssh_data.size());
401
402 std::vector<uint8_t> data = {0x01, 0x02, 0x03, 0x04};
403 AppendData(box, data);
404 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
405 EXPECT_EQ(data, pssh_data);
406 }
407
408 TEST_F(CencUtilsTest, GetPsshDataVersion1NoKeys) {
409 std::vector<uint8_t> clear_key(kClearKeyUuid,
410 kClearKeyUuid + arraysize(kClearKeyUuid));
411 std::vector<uint8_t> pssh_data;
412
413 std::vector<uint8_t> box = MakePSSHBox(1);
414 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
415 EXPECT_EQ(0u, pssh_data.size());
416
417 std::vector<uint8_t> data = {0x05, 0x06, 0x07, 0x08};
418 AppendData(box, data);
419 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
420 EXPECT_EQ(data, pssh_data);
421 }
422
423 TEST_F(CencUtilsTest, GetPsshDataVersion1WithKeys) {
424 std::vector<uint8_t> clear_key(kClearKeyUuid,
425 kClearKeyUuid + arraysize(kClearKeyUuid));
426 std::vector<uint8_t> pssh_data;
427
428 std::vector<uint8_t> box = MakePSSHBox(1, Key1());
429 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
430 EXPECT_EQ(0u, pssh_data.size());
431
432 std::vector<uint8_t> data = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
433 AppendData(box, data);
434 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
435 EXPECT_EQ(data, pssh_data);
436 }
437
438 TEST_F(CencUtilsTest, GetPsshDataVersion2) {
439 std::vector<uint8_t> clear_key(kClearKeyUuid,
440 kClearKeyUuid + arraysize(kClearKeyUuid));
441 std::vector<uint8_t> pssh_data;
442
443 std::vector<uint8_t> box = MakePSSHBox(1, Key1());
444 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
445 // Change the version manually, since we don't know what v2 will contain.
446 box[8] = 2;
447 EXPECT_FALSE(GetPsshData(box, clear_key, &pssh_data));
448 }
449
450 TEST_F(CencUtilsTest, GetPsshDataDifferentSystemID) {
451 std::vector<uint8_t> clear_key(kClearKeyUuid,
452 kClearKeyUuid + arraysize(kClearKeyUuid));
453 std::vector<uint8_t> unknown_system_id(kKey1Data,
454 kKey1Data + arraysize(kKey1Data));
455 std::vector<uint8_t> pssh_data;
456
457 std::vector<uint8_t> box = MakePSSHBox(1, Key1());
458 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
459 EXPECT_FALSE(GetPsshData(box, unknown_system_id, &pssh_data));
460 }
461
462 TEST_F(CencUtilsTest, GetPsshDataMissingData) {
463 std::vector<uint8_t> clear_key(kClearKeyUuid,
464 kClearKeyUuid + arraysize(kClearKeyUuid));
465 std::vector<uint8_t> pssh_data;
466
467 std::vector<uint8_t> box = MakePSSHBox(1, Key1());
468 std::vector<uint8_t> data = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
469 AppendData(box, data);
470 EXPECT_TRUE(GetPsshData(box, clear_key, &pssh_data));
471 // Remove some data from the end, so now the size is incorrect.
472 box.pop_back();
473 box.pop_back();
474 EXPECT_FALSE(GetPsshData(box, clear_key, &pssh_data));
475 }
476
477 TEST_F(CencUtilsTest, GetPsshDataMultiplePssh) {
478 std::vector<uint8_t> clear_key(kClearKeyUuid,
479 kClearKeyUuid + arraysize(kClearKeyUuid));
480 std::vector<uint8_t> pssh_data;
481
482 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1());
483 std::vector<uint8_t> data1 = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
484 AppendData(box1, data1);
485
486 std::vector<uint8_t> box2 = MakePSSHBox(0);
487 std::vector<uint8_t> data2 = {0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8};
488 AppendData(box2, data2);
489
490 box1.insert(box1.end(), box2.begin(), box2.end());
491 EXPECT_TRUE(GetPsshData(box1, clear_key, &pssh_data));
492 EXPECT_EQ(data1, pssh_data);
493 EXPECT_NE(data2, pssh_data);
494 }
495
376 } // namespace media 496 } // namespace media
OLDNEW
« 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