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

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: use message event 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, TruncatedAtEndPSSH) {
ddorwin 2015/06/17 22:42:05 is there a test where size is greater than the box
ddorwin 2015/06/17 22:42:05 PsshBoxLessThanSize might be better. Oh, I misunde
ddorwin 2015/06/17 22:42:06 // Tries every size less than the actual size. I'
jrummell 2015/06/17 23:54:10 Done.
jrummell 2015/06/17 23:54:10 Done.
jrummell 2015/06/17 23:54:10 Added.
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 for (size_t i = 1; i < box.size(); ++i) { 272 for (size_t i = 1; i < box.size(); ++i) {
273 // Modify size of data passed to be less than real size. 273 // Modify size of box passed to be less than real size.
274 std::vector<uint8_t> truncated(&box[0], &box[0] + i); 274 std::vector<uint8_t> truncated(&box[0], &box[0] + i);
275 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i; 275 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i;
276 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids)); 276 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids));
277 // Modify starting point. 277 }
278 }
279
280 TEST_F(CencUtilsTest, TruncatedAtStartPSSH) {
ddorwin 2015/06/17 22:42:05 ditto
jrummell 2015/06/17 23:54:10 Done.
281 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
282 KeyIdList key_ids;
283 for (size_t i = 1; i < box.size(); ++i) {
284 // Modify starting point of box.
278 std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i); 285 std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i);
279 EXPECT_FALSE(ValidatePsshInput(changed_offset)) << "Failed for offset " 286 EXPECT_FALSE(ValidatePsshInput(changed_offset)) << "Failed for offset "
280 << i; 287 << i;
281 EXPECT_FALSE(GetKeyIdsForCommonSystemId(changed_offset, &key_ids)); 288 EXPECT_FALSE(GetKeyIdsForCommonSystemId(changed_offset, &key_ids));
282 } 289 }
283 } 290 }
284 291
285 TEST_F(CencUtilsTest, InvalidSystemID) { 292 TEST_F(CencUtilsTest, UnrecognizedSystemID) {
286 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 293 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
287 294
288 // Modify the System ID. 295 // Modify the System ID.
289 ++box[20]; 296 ++box[20];
290 297
291 KeyIdList key_ids; 298 KeyIdList key_ids;
292 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); 299 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
293 EXPECT_EQ(0u, key_ids.size());
294 } 300 }
295 301
296 TEST_F(CencUtilsTest, InvalidFlags) { 302 TEST_F(CencUtilsTest, InvalidFlags) {
297 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 303 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
298 304
299 // Modify flags. 305 // Modify flags.
300 box[10] = 3; 306 box[10] = 3;
301 307
302 KeyIdList key_ids; 308 KeyIdList key_ids;
303 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids)); 309 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids));
(...skipping 17 matching lines...) Expand all
321 }; 327 };
322 328
323 KeyIdList key_ids; 329 KeyIdList key_ids;
324 EXPECT_TRUE( 330 EXPECT_TRUE(
325 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); 331 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
326 EXPECT_TRUE(GetKeyIdsForCommonSystemId( 332 EXPECT_TRUE(GetKeyIdsForCommonSystemId(
327 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); 333 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids));
328 EXPECT_EQ(2u, key_ids.size()); 334 EXPECT_EQ(2u, key_ids.size());
329 } 335 }
330 336
331 TEST_F(CencUtilsTest, NoSize) { 337 TEST_F(CencUtilsTest, SizeIsZero) {
332 const uint8_t data[] = { 338 const uint8_t data[] = {
333 0x00, 0x00, 0x00, 0x00, // size = 0 339 0x00, 0x00, 0x00, 0x00, // size = 0
334 0x70, 0x73, 0x73, 0x68, // 'pssh' 340 0x70, 0x73, 0x73, 0x68, // 'pssh'
335 0x01, // version 341 0x01, // version
336 0x00, 0x00, 0x00, // flags 342 0x00, 0x00, 0x00, // flags
337 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID 343 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID
338 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 344 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
339 0x00, 0x00, 0x00, 0x02, // key count 345 0x00, 0x00, 0x00, 0x02, // key count
340 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 346 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
341 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 347 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
(...skipping 21 matching lines...) Expand all
363 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 369 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
364 0x00, 0x00, 0x00, 0x02, // key count 370 0x00, 0x00, 0x00, 0x02, // key count
365 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 371 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
366 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 372 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
367 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 373 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2
368 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 374 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
369 0x00, 0x00, 0x00, 0x00 // datasize 375 0x00, 0x00, 0x00, 0x00 // datasize
370 }; 376 };
371 377
372 KeyIdList key_ids; 378 KeyIdList key_ids;
379 // These tests fail as the box size is huge (0xffffffffffffffff) and there
ddorwin 2015/06/17 22:42:06 nit: s/tests/calls/ "tests" could be ambiguous.
jrummell 2015/06/17 23:54:10 Done.
380 // is not enough bytes in |data|.
373 EXPECT_FALSE( 381 EXPECT_FALSE(
374 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); 382 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
375 EXPECT_FALSE(GetKeyIdsForCommonSystemId( 383 EXPECT_FALSE(GetKeyIdsForCommonSystemId(
376 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); 384 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids));
377 } 385 }
378 386
379 TEST_F(CencUtilsTest, GetPsshData_Version0) { 387 TEST_F(CencUtilsTest, GetPsshData_Version0) {
380 const uint8_t data_bytes[] = {0x01, 0x02, 0x03, 0x04}; 388 const uint8_t data_bytes[] = {0x01, 0x02, 0x03, 0x04};
381 std::vector<uint8_t> pssh_data; 389 std::vector<uint8_t> pssh_data;
382 390
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 std::vector<uint8_t> box2 = MakePSSHBox(0); 514 std::vector<uint8_t> box2 = MakePSSHBox(0);
507 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes)); 515 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes));
508 AppendData(box2, data2); 516 AppendData(box2, data2);
509 517
510 box1.insert(box1.end(), box2.begin(), box2.end()); 518 box1.insert(box1.end(), box2.begin(), box2.end());
511 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data)); 519 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data));
512 EXPECT_EQ(data1, pssh_data); 520 EXPECT_EQ(data1, pssh_data);
513 EXPECT_NE(data2, pssh_data); 521 EXPECT_NE(data2, pssh_data);
514 } 522 }
515 } // namespace media 523 } // 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