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

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: 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 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 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.
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 // 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.
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. 279 }
280 }
281
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, 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
301 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
302 KeyIdList key_ids;
303
304 // Try every possible starting position.
305 for (size_t i = 1; i < box.size(); ++i) {
306 // Modify starting point of box. This should always fail as the modified
307 // box won't be a properly formatted 'pssh' box.
278 std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i); 308 std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i);
279 EXPECT_FALSE(ValidatePsshInput(changed_offset)) << "Failed for offset " 309 EXPECT_FALSE(ValidatePsshInput(changed_offset)) << "Failed for offset "
280 << i; 310 << i;
281 EXPECT_FALSE(GetKeyIdsForCommonSystemId(changed_offset, &key_ids)); 311 EXPECT_FALSE(GetKeyIdsForCommonSystemId(changed_offset, &key_ids));
282 } 312 }
283 } 313 }
284 314
285 TEST_F(CencUtilsTest, InvalidSystemID) { 315 TEST_F(CencUtilsTest, UnrecognizedSystemID) {
286 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 316 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
287 317
288 // Modify the System ID. 318 // Modify the System ID.
289 ++box[20]; 319 ++box[20];
290 320
291 KeyIdList key_ids; 321 KeyIdList key_ids;
292 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); 322 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
293 EXPECT_EQ(0u, key_ids.size());
294 } 323 }
295 324
296 TEST_F(CencUtilsTest, InvalidFlags) { 325 TEST_F(CencUtilsTest, InvalidFlags) {
297 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 326 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
298 327
299 // Modify flags. 328 // Modify flags.
300 box[10] = 3; 329 box[10] = 3;
301 330
302 KeyIdList key_ids; 331 KeyIdList key_ids;
303 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids)); 332 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
(...skipping 17 matching lines...) Expand all
321 }; 350 };
322 351
323 KeyIdList key_ids; 352 KeyIdList key_ids;
324 EXPECT_TRUE( 353 EXPECT_TRUE(
325 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); 354 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
326 EXPECT_TRUE(GetKeyIdsForCommonSystemId( 355 EXPECT_TRUE(GetKeyIdsForCommonSystemId(
327 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); 356 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids));
328 EXPECT_EQ(2u, key_ids.size()); 357 EXPECT_EQ(2u, key_ids.size());
329 } 358 }
330 359
331 TEST_F(CencUtilsTest, NoSize) { 360 TEST_F(CencUtilsTest, SizeIsZero) {
332 const uint8_t data[] = { 361 const uint8_t data[] = {
333 0x00, 0x00, 0x00, 0x00, // size = 0 362 0x00, 0x00, 0x00, 0x00, // size = 0
334 0x70, 0x73, 0x73, 0x68, // 'pssh' 363 0x70, 0x73, 0x73, 0x68, // 'pssh'
335 0x01, // version 364 0x01, // version
336 0x00, 0x00, 0x00, // flags 365 0x00, 0x00, 0x00, // flags
337 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID 366 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID
338 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 367 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
339 0x00, 0x00, 0x00, 0x02, // key count 368 0x00, 0x00, 0x00, 0x02, // key count
340 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 369 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
341 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 370 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
(...skipping 21 matching lines...) Expand all
363 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 392 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
364 0x00, 0x00, 0x00, 0x02, // key count 393 0x00, 0x00, 0x00, 0x02, // key count
365 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 394 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
366 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 395 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
367 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 396 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2
368 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 397 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
369 0x00, 0x00, 0x00, 0x00 // datasize 398 0x00, 0x00, 0x00, 0x00 // datasize
370 }; 399 };
371 400
372 KeyIdList key_ids; 401 KeyIdList key_ids;
402 // These calls fail as the box size is huge (0xffffffffffffffff) and there
403 // is not enough bytes in |data|.
373 EXPECT_FALSE( 404 EXPECT_FALSE(
374 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); 405 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
375 EXPECT_FALSE(GetKeyIdsForCommonSystemId( 406 EXPECT_FALSE(GetKeyIdsForCommonSystemId(
376 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); 407 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids));
377 } 408 }
378 409
379 TEST_F(CencUtilsTest, GetPsshData_Version0) { 410 TEST_F(CencUtilsTest, GetPsshData_Version0) {
380 const uint8_t data_bytes[] = {0x01, 0x02, 0x03, 0x04}; 411 const uint8_t data_bytes[] = {0x01, 0x02, 0x03, 0x04};
381 std::vector<uint8_t> pssh_data; 412 std::vector<uint8_t> pssh_data;
382 413
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 std::vector<uint8_t> box2 = MakePSSHBox(0); 537 std::vector<uint8_t> box2 = MakePSSHBox(0);
507 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes)); 538 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes));
508 AppendData(box2, data2); 539 AppendData(box2, data2);
509 540
510 box1.insert(box1.end(), box2.begin(), box2.end()); 541 box1.insert(box1.end(), box2.begin(), box2.end());
511 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data)); 542 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data));
512 EXPECT_EQ(data1, pssh_data); 543 EXPECT_EQ(data1, pssh_data);
513 EXPECT_NE(data2, pssh_data); 544 EXPECT_NE(data2, pssh_data);
514 } 545 }
515 } // namespace media 546 } // 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