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

Side by Side 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: change comment 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 unified diff | 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 »
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 {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 std::vector<uint8_t> key1_; 173 std::vector<uint8_t> key1_;
174 std::vector<uint8_t> key2_; 174 std::vector<uint8_t> key2_;
175 std::vector<uint8_t> key3_; 175 std::vector<uint8_t> key3_;
176 std::vector<uint8_t> key4_; 176 std::vector<uint8_t> key4_;
177 std::vector<uint8_t> common_system_system_id_; 177 std::vector<uint8_t> common_system_system_id_;
178 }; 178 };
179 179
180 TEST_F(CencUtilsTest, EmptyPSSH) { 180 TEST_F(CencUtilsTest, EmptyPSSH) {
181 KeyIdList key_ids; 181 KeyIdList key_ids;
182 EXPECT_TRUE(ValidatePsshInput(std::vector<uint8_t>())); 182 EXPECT_TRUE(ValidatePsshInput(std::vector<uint8_t>()));
183 EXPECT_TRUE(GetKeyIdsForCommonSystemId(std::vector<uint8_t>(), &key_ids)); 183 EXPECT_FALSE(GetKeyIdsForCommonSystemId(std::vector<uint8_t>(), &key_ids));
184 EXPECT_EQ(0u, key_ids.size());
185 } 184 }
186 185
187 TEST_F(CencUtilsTest, PSSHVersion0) { 186 TEST_F(CencUtilsTest, PSSHVersion0) {
188 std::vector<uint8_t> box = MakePSSHBox(0); 187 std::vector<uint8_t> box = MakePSSHBox(0);
189 KeyIdList key_ids; 188 KeyIdList key_ids;
190 EXPECT_TRUE(ValidatePsshInput(box)); 189 EXPECT_TRUE(ValidatePsshInput(box));
191 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); 190 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
192 EXPECT_EQ(0u, key_ids.size());
193 } 191 }
194 192
195 TEST_F(CencUtilsTest, PSSHVersion1WithNoKeys) { 193 TEST_F(CencUtilsTest, PSSHVersion1WithNoKeys) {
196 std::vector<uint8_t> box = MakePSSHBox(1); 194 std::vector<uint8_t> box = MakePSSHBox(1);
197 KeyIdList key_ids; 195 KeyIdList key_ids;
198 EXPECT_TRUE(ValidatePsshInput(box)); 196 EXPECT_TRUE(ValidatePsshInput(box));
199 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); 197 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
200 EXPECT_EQ(0u, key_ids.size());
201 } 198 }
202 199
203 TEST_F(CencUtilsTest, PSSHVersion1WithOneKey) { 200 TEST_F(CencUtilsTest, PSSHVersion1WithOneKey) {
204 std::vector<uint8_t> box = MakePSSHBox(1, Key1()); 201 std::vector<uint8_t> box = MakePSSHBox(1, Key1());
205 KeyIdList key_ids; 202 KeyIdList key_ids;
206 EXPECT_TRUE(ValidatePsshInput(box)); 203 EXPECT_TRUE(ValidatePsshInput(box));
207 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); 204 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
208 EXPECT_EQ(1u, key_ids.size()); 205 EXPECT_EQ(1u, key_ids.size());
209 EXPECT_EQ(key_ids[0], Key1()); 206 EXPECT_EQ(key_ids[0], Key1());
210 } 207 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 248 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
252 std::vector<uint8_t> box1 = MakePSSHBox(1, Key3()); 249 std::vector<uint8_t> box1 = MakePSSHBox(1, Key3());
253 std::vector<uint8_t> box2 = MakePSSHBox(1, Key4()); 250 std::vector<uint8_t> box2 = MakePSSHBox(1, Key4());
254 251
255 // Concatentate box1 and box2 onto end of box. 252 // Concatentate box1 and box2 onto end of box.
256 box.insert(box.end(), box1.begin(), box1.end()); 253 box.insert(box.end(), box1.begin(), box1.end());
257 box.insert(box.end(), box2.begin(), box2.end()); 254 box.insert(box.end(), box2.begin(), box2.end());
258 255
259 KeyIdList key_ids; 256 KeyIdList key_ids;
260 EXPECT_TRUE(ValidatePsshInput(box)); 257 EXPECT_TRUE(ValidatePsshInput(box));
258 // TODO(jrummell): GetKeyIdsForCommonSystemId() returns the key IDs out of
259 // all matching boxes. It should only return the key IDs from the first
260 // matching box.
261 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); 261 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
262 EXPECT_EQ(4u, key_ids.size()); 262 EXPECT_EQ(4u, key_ids.size());
263 EXPECT_EQ(key_ids[0], Key1()); 263 EXPECT_EQ(key_ids[0], Key1());
264 EXPECT_EQ(key_ids[1], Key2()); 264 EXPECT_EQ(key_ids[1], Key2());
265 EXPECT_EQ(key_ids[2], Key3()); 265 EXPECT_EQ(key_ids[2], Key3());
266 EXPECT_EQ(key_ids[3], Key4()); 266 EXPECT_EQ(key_ids[3], Key4());
267 } 267 }
268 268
269 TEST_F(CencUtilsTest, InvalidPSSH) { 269 TEST_F(CencUtilsTest, PsshBoxSmallerThanSize) {
270 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 270 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
271 KeyIdList key_ids; 271 KeyIdList key_ids;
272
273 // Tries every buffer size less than the indicated 'pssh' box size.
272 for (size_t i = 1; i < box.size(); ++i) { 274 for (size_t i = 1; i < box.size(); ++i) {
273 // Modify size of data passed to be less than real size. 275 // Truncate the box to be less than the specified box size.
274 std::vector<uint8_t> truncated(&box[0], &box[0] + i); 276 std::vector<uint8_t> truncated(&box[0], &box[0] + i);
275 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i; 277 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i;
276 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids)); 278 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids));
277 // Modify starting point.
278 std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i);
279 EXPECT_FALSE(ValidatePsshInput(changed_offset)) << "Failed for offset "
280 << i;
281 EXPECT_FALSE(GetKeyIdsForCommonSystemId(changed_offset, &key_ids));
282 } 279 }
283 } 280 }
284 281
285 TEST_F(CencUtilsTest, InvalidSystemID) { 282 TEST_F(CencUtilsTest, PsshBoxLargerThanSize) {
283 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
284 KeyIdList key_ids;
285
286 // Add 20 additional bytes to |box|.
287 size_t original_size = box.size();
288 for (size_t i = 0; i < 20; ++i)
289 box.push_back(i);
290
291 // Tries every size greater than |original_size|.
292 for (size_t i = original_size + 1; i < box.size(); ++i) {
293 // Modify size of box passed to be less than current size.
294 std::vector<uint8_t> truncated(&box[0], &box[0] + i);
295 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i;
296 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids));
297 }
298 }
299
300 TEST_F(CencUtilsTest, UnrecognizedSystemID) {
286 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 301 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
287 302
288 // Modify the System ID. 303 // Modify the System ID.
289 ++box[20]; 304 ++box[20];
290 305
291 KeyIdList key_ids; 306 KeyIdList key_ids;
292 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); 307 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
293 EXPECT_EQ(0u, key_ids.size());
294 } 308 }
295 309
296 TEST_F(CencUtilsTest, InvalidFlags) { 310 TEST_F(CencUtilsTest, InvalidFlags) {
297 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 311 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
298 312
299 // Modify flags. 313 // Modify flags.
300 box[10] = 3; 314 box[10] = 3;
301 315
302 KeyIdList key_ids; 316 KeyIdList key_ids;
303 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids)); 317 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
(...skipping 17 matching lines...) Expand all
321 }; 335 };
322 336
323 KeyIdList key_ids; 337 KeyIdList key_ids;
324 EXPECT_TRUE( 338 EXPECT_TRUE(
325 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); 339 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
326 EXPECT_TRUE(GetKeyIdsForCommonSystemId( 340 EXPECT_TRUE(GetKeyIdsForCommonSystemId(
327 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); 341 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids));
328 EXPECT_EQ(2u, key_ids.size()); 342 EXPECT_EQ(2u, key_ids.size());
329 } 343 }
330 344
331 TEST_F(CencUtilsTest, NoSize) { 345 TEST_F(CencUtilsTest, SizeIsZero) {
332 const uint8_t data[] = { 346 const uint8_t data[] = {
333 0x00, 0x00, 0x00, 0x00, // size = 0 347 0x00, 0x00, 0x00, 0x00, // size = 0
334 0x70, 0x73, 0x73, 0x68, // 'pssh' 348 0x70, 0x73, 0x73, 0x68, // 'pssh'
335 0x01, // version 349 0x01, // version
336 0x00, 0x00, 0x00, // flags 350 0x00, 0x00, 0x00, // flags
337 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID 351 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID
338 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 352 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
339 0x00, 0x00, 0x00, 0x02, // key count 353 0x00, 0x00, 0x00, 0x02, // key count
340 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 354 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
341 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 355 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
(...skipping 21 matching lines...) Expand all
363 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 377 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
364 0x00, 0x00, 0x00, 0x02, // key count 378 0x00, 0x00, 0x00, 0x02, // key count
365 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 379 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
366 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 380 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
367 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 381 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2
368 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 382 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
369 0x00, 0x00, 0x00, 0x00 // datasize 383 0x00, 0x00, 0x00, 0x00 // datasize
370 }; 384 };
371 385
372 KeyIdList key_ids; 386 KeyIdList key_ids;
387 // These calls fail as the box size is huge (0xffffffffffffffff) and there
388 // is not enough bytes in |data|.
373 EXPECT_FALSE( 389 EXPECT_FALSE(
374 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); 390 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
375 EXPECT_FALSE(GetKeyIdsForCommonSystemId( 391 EXPECT_FALSE(GetKeyIdsForCommonSystemId(
376 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); 392 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids));
377 } 393 }
378 394
379 TEST_F(CencUtilsTest, GetPsshData_Version0) { 395 TEST_F(CencUtilsTest, GetPsshData_Version0) {
380 const uint8_t data_bytes[] = {0x01, 0x02, 0x03, 0x04}; 396 const uint8_t data_bytes[] = {0x01, 0x02, 0x03, 0x04};
381 std::vector<uint8_t> pssh_data; 397 std::vector<uint8_t> pssh_data;
382 398
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 std::vector<uint8_t> box2 = MakePSSHBox(0); 522 std::vector<uint8_t> box2 = MakePSSHBox(0);
507 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes)); 523 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes));
508 AppendData(box2, data2); 524 AppendData(box2, data2);
509 525
510 box1.insert(box1.end(), box2.begin(), box2.end()); 526 box1.insert(box1.end(), box2.begin(), box2.end());
511 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data)); 527 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data));
512 EXPECT_EQ(data1, pssh_data); 528 EXPECT_EQ(data1, pssh_data);
513 EXPECT_NE(data2, pssh_data); 529 EXPECT_NE(data2, pssh_data);
514 } 530 }
515 } // namespace media 531 } // namespace media
OLDNEW
« 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