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

Side by Side Diff: media/cdm/cenc_utils_unittest.cc

Issue 1199643002: Have GetKeyIds() return the key IDs from the first matching 'pssh' box (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« media/cdm/cenc_utils.cc ('K') | « 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 {
(...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_FALSE(GetKeyIdsForCommonSystemId(std::vector<uint8_t>(), &key_ids)); 183 EXPECT_FALSE(GetKeyIdsFromPsshBoxes(std::vector<uint8_t>(),
184 CommonSystemSystemId(), &key_ids));
184 } 185 }
185 186
186 TEST_F(CencUtilsTest, PSSHVersion0) { 187 TEST_F(CencUtilsTest, PSSHVersion0) {
187 std::vector<uint8_t> box = MakePSSHBox(0); 188 std::vector<uint8_t> box = MakePSSHBox(0);
188 KeyIdList key_ids; 189 KeyIdList key_ids;
189 EXPECT_TRUE(ValidatePsshInput(box)); 190 EXPECT_TRUE(ValidatePsshInput(box));
190 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids)); 191 EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
191 } 192 }
192 193
193 TEST_F(CencUtilsTest, PSSHVersion1WithNoKeys) { 194 TEST_F(CencUtilsTest, PSSHVersion1WithNoKeys) {
194 std::vector<uint8_t> box = MakePSSHBox(1); 195 std::vector<uint8_t> box = MakePSSHBox(1);
195 KeyIdList key_ids; 196 KeyIdList key_ids;
196 EXPECT_TRUE(ValidatePsshInput(box)); 197 EXPECT_TRUE(ValidatePsshInput(box));
197 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids)); 198 EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
198 } 199 }
199 200
200 TEST_F(CencUtilsTest, PSSHVersion1WithOneKey) { 201 TEST_F(CencUtilsTest, PSSHVersion1WithOneKey) {
201 std::vector<uint8_t> box = MakePSSHBox(1, Key1()); 202 std::vector<uint8_t> box = MakePSSHBox(1, Key1());
202 KeyIdList key_ids; 203 KeyIdList key_ids;
203 EXPECT_TRUE(ValidatePsshInput(box)); 204 EXPECT_TRUE(ValidatePsshInput(box));
204 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); 205 EXPECT_TRUE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
205 EXPECT_EQ(1u, key_ids.size()); 206 EXPECT_EQ(1u, key_ids.size());
206 EXPECT_EQ(key_ids[0], Key1()); 207 EXPECT_EQ(key_ids[0], Key1());
207 } 208 }
208 209
209 TEST_F(CencUtilsTest, PSSHVersion1WithTwoKeys) { 210 TEST_F(CencUtilsTest, PSSHVersion1WithTwoKeys) {
210 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 211 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
211 KeyIdList key_ids; 212 KeyIdList key_ids;
212 EXPECT_TRUE(ValidatePsshInput(box)); 213 EXPECT_TRUE(ValidatePsshInput(box));
213 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); 214 EXPECT_TRUE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
214 EXPECT_EQ(2u, key_ids.size()); 215 EXPECT_EQ(2u, key_ids.size());
215 EXPECT_EQ(key_ids[0], Key1()); 216 EXPECT_EQ(key_ids[0], Key1());
216 EXPECT_EQ(key_ids[1], Key2()); 217 EXPECT_EQ(key_ids[1], Key2());
217 } 218 }
218 219
219 TEST_F(CencUtilsTest, PSSHVersion0Plus1) { 220 TEST_F(CencUtilsTest, PSSHVersion0Plus1) {
220 std::vector<uint8_t> box0 = MakePSSHBox(0); 221 std::vector<uint8_t> box0 = MakePSSHBox(0);
221 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); 222 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1());
222 223
223 // Concatentate box1 onto end of box0. 224 // Concatentate box1 onto end of box0.
224 box0.insert(box0.end(), box1.begin(), box1.end()); 225 box0.insert(box0.end(), box1.begin(), box1.end());
226 EXPECT_TRUE(ValidatePsshInput(box0));
225 227
228 // No key IDs returned as only the first 'pssh' box is processed.
226 KeyIdList key_ids; 229 KeyIdList key_ids;
227 EXPECT_TRUE(ValidatePsshInput(box0)); 230 EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box0, CommonSystemSystemId(), &key_ids));
228 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box0, &key_ids));
229 EXPECT_EQ(1u, key_ids.size());
230 EXPECT_EQ(key_ids[0], Key1());
231 } 231 }
232 232
233 TEST_F(CencUtilsTest, PSSHVersion1Plus0) { 233 TEST_F(CencUtilsTest, PSSHVersion1Plus0) {
234 std::vector<uint8_t> box0 = MakePSSHBox(0); 234 std::vector<uint8_t> box0 = MakePSSHBox(0);
235 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); 235 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1());
236 236
237 // Concatentate box0 onto end of box1. 237 // Concatentate box0 onto end of box1.
238 box1.insert(box1.end(), box0.begin(), box0.end()); 238 box1.insert(box1.end(), box0.begin(), box0.end());
239 EXPECT_TRUE(ValidatePsshInput(box1));
239 240
240 KeyIdList key_ids; 241 KeyIdList key_ids;
241 EXPECT_TRUE(ValidatePsshInput(box1)); 242 EXPECT_TRUE(GetKeyIdsFromPsshBoxes(box1, CommonSystemSystemId(), &key_ids));
242 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box1, &key_ids));
243 EXPECT_EQ(1u, key_ids.size()); 243 EXPECT_EQ(1u, key_ids.size());
244 EXPECT_EQ(key_ids[0], Key1()); 244 EXPECT_EQ(key_ids[0], Key1());
245 } 245 }
246 246
247 TEST_F(CencUtilsTest, MultiplePSSHVersion1) { 247 TEST_F(CencUtilsTest, MultiplePSSHVersion1) {
248 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 248 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
249 std::vector<uint8_t> box1 = MakePSSHBox(1, Key3()); 249 std::vector<uint8_t> box1 = MakePSSHBox(1, Key3());
250 std::vector<uint8_t> box2 = MakePSSHBox(1, Key4()); 250 std::vector<uint8_t> box2 = MakePSSHBox(1, Key4());
251 251
252 // Concatentate box1 and box2 onto end of box. 252 // Concatentate box1 and box2 onto end of box.
253 box.insert(box.end(), box1.begin(), box1.end()); 253 box.insert(box.end(), box1.begin(), box1.end());
254 box.insert(box.end(), box2.begin(), box2.end()); 254 box.insert(box.end(), box2.begin(), box2.end());
255 EXPECT_TRUE(ValidatePsshInput(box));
255 256
256 KeyIdList key_ids; 257 KeyIdList key_ids;
257 EXPECT_TRUE(ValidatePsshInput(box)); 258 EXPECT_TRUE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
258 // TODO(jrummell): GetKeyIdsForCommonSystemId() returns the key IDs out of 259 EXPECT_EQ(2u, key_ids.size());
259 // all matching boxes. It should only return the key IDs from the first
260 // matching box.
261 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids));
262 EXPECT_EQ(4u, key_ids.size());
263 EXPECT_EQ(key_ids[0], Key1()); 260 EXPECT_EQ(key_ids[0], Key1());
264 EXPECT_EQ(key_ids[1], Key2()); 261 EXPECT_EQ(key_ids[1], Key2());
265 EXPECT_EQ(key_ids[2], Key3());
266 EXPECT_EQ(key_ids[3], Key4());
267 } 262 }
268 263
269 TEST_F(CencUtilsTest, PsshBoxSmallerThanSize) { 264 TEST_F(CencUtilsTest, PsshBoxSmallerThanSize) {
270 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 265 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
271 KeyIdList key_ids; 266 KeyIdList key_ids;
272 267
273 // Tries every buffer size less than the indicated 'pssh' box size. 268 // Tries every buffer size less than the indicated 'pssh' box size.
274 for (size_t i = 1; i < box.size(); ++i) { 269 for (size_t i = 1; i < box.size(); ++i) {
275 // Truncate the box to be less than the specified box size. 270 // Truncate the box to be less than the specified box size.
276 std::vector<uint8_t> truncated(&box[0], &box[0] + i); 271 std::vector<uint8_t> truncated(&box[0], &box[0] + i);
277 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i; 272 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i;
278 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids)); 273 EXPECT_FALSE(
274 GetKeyIdsFromPsshBoxes(truncated, CommonSystemSystemId(), &key_ids));
279 } 275 }
280 } 276 }
281 277
282 TEST_F(CencUtilsTest, PsshBoxLargerThanSize) { 278 TEST_F(CencUtilsTest, PsshBoxLargerThanSize) {
283 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 279 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
284 KeyIdList key_ids; 280 KeyIdList key_ids;
285 281
286 // Add 20 additional bytes to |box|. 282 // Add 20 additional bytes to |box|.
287 size_t original_size = box.size(); 283 size_t original_size = box.size();
288 for (size_t i = 0; i < 20; ++i) 284 for (size_t i = 0; i < 20; ++i)
289 box.push_back(i); 285 box.push_back(i);
290 286
291 // Tries every size greater than |original_size|. 287 // Tries every size greater than |original_size|.
292 for (size_t i = original_size + 1; i < box.size(); ++i) { 288 for (size_t i = original_size + 1; i < box.size(); ++i) {
293 // Modify size of box passed to be less than current size. 289 // Modify size of box passed to be less than current size.
294 std::vector<uint8_t> truncated(&box[0], &box[0] + i); 290 std::vector<uint8_t> truncated(&box[0], &box[0] + i);
295 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i; 291 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i;
296 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids)); 292 EXPECT_FALSE(
293 GetKeyIdsFromPsshBoxes(truncated, CommonSystemSystemId(), &key_ids));
297 } 294 }
298 } 295 }
299 296
300 TEST_F(CencUtilsTest, UnrecognizedSystemID) { 297 TEST_F(CencUtilsTest, UnrecognizedSystemID) {
298 const uint8_t data[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
299 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
300 std::vector<uint8_t> different_system_id(data, data + arraysize(data));
301 KeyIdList key_ids;
302
301 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 303 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
304 EXPECT_TRUE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
305 EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, different_system_id, &key_ids));
302 306
303 // Modify the System ID. 307 // Modify the System ID and try again.
304 ++box[20]; 308 ++box[20];
309 EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
310 EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, different_system_id, &key_ids));
311 }
305 312
313 TEST_F(CencUtilsTest, DifferentSystemID) {
314 const uint8_t data[] = {
315 0x00, 0x00, 0x00, 0x44, // size
316 'p', 's', 's', 'h',
317 0x01, // version
318 0x00, 0x00, 0x00, // flags
319 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // SystemID
320 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
321 0x00, 0x00, 0x00, 0x02, // key count
322 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
323 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
324 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2
325 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
326 0x00, 0x00, 0x00, 0x00 // datasize
327 };
328 const uint8_t id_data[] = {
329 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
330 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
331 };
306 KeyIdList key_ids; 332 KeyIdList key_ids;
307 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids)); 333
334 EXPECT_FALSE(
335 GetKeyIdsFromPsshBoxes(std::vector<uint8_t>(data, data + arraysize(data)),
336 CommonSystemSystemId(), &key_ids));
337 EXPECT_TRUE(GetKeyIdsFromPsshBoxes(
338 std::vector<uint8_t>(data, data + arraysize(data)),
339 std::vector<uint8_t>(id_data, id_data + arraysize(id_data)), &key_ids));
340 EXPECT_EQ(2u, key_ids.size());
308 } 341 }
309 342
310 TEST_F(CencUtilsTest, InvalidFlags) { 343 TEST_F(CencUtilsTest, InvalidFlags) {
311 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); 344 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2());
312 345
313 // Modify flags. 346 // Modify flags.
314 box[10] = 3; 347 box[10] = 3;
315 348
316 KeyIdList key_ids; 349 KeyIdList key_ids;
317 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids)); 350 EXPECT_FALSE(GetKeyIdsFromPsshBoxes(box, CommonSystemSystemId(), &key_ids));
318 } 351 }
319 352
320 TEST_F(CencUtilsTest, LongSize) { 353 TEST_F(CencUtilsTest, LongSize) {
321 const uint8_t data[] = { 354 const uint8_t data[] = {
322 0x00, 0x00, 0x00, 0x01, // size = 1 355 0x00, 0x00, 0x00, 0x01, // size = 1
323 0x70, 0x73, 0x73, 0x68, // 'pssh' 356 0x70, 0x73, 0x73, 0x68, // 'pssh'
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, // longsize 357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, // longsize
325 0x01, // version 358 0x01, // version
326 0x00, 0x00, 0x00, // flags 359 0x00, 0x00, 0x00, // flags
327 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID 360 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID
328 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 361 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
329 0x00, 0x00, 0x00, 0x02, // key count 362 0x00, 0x00, 0x00, 0x02, // key count
330 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 363 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
331 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 364 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
332 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 365 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2
333 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 366 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
334 0x00, 0x00, 0x00, 0x00 // datasize 367 0x00, 0x00, 0x00, 0x00 // datasize
335 }; 368 };
336 369
337 KeyIdList key_ids; 370 KeyIdList key_ids;
338 EXPECT_TRUE( 371 EXPECT_TRUE(
339 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); 372 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
340 EXPECT_TRUE(GetKeyIdsForCommonSystemId( 373 EXPECT_TRUE(
341 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); 374 GetKeyIdsFromPsshBoxes(std::vector<uint8_t>(data, data + arraysize(data)),
375 CommonSystemSystemId(), &key_ids));
342 EXPECT_EQ(2u, key_ids.size()); 376 EXPECT_EQ(2u, key_ids.size());
343 } 377 }
344 378
345 TEST_F(CencUtilsTest, SizeIsZero) { 379 TEST_F(CencUtilsTest, SizeIsZero) {
346 const uint8_t data[] = { 380 const uint8_t data[] = {
347 0x00, 0x00, 0x00, 0x00, // size = 0 381 0x00, 0x00, 0x00, 0x00, // size = 0
348 0x70, 0x73, 0x73, 0x68, // 'pssh' 382 0x70, 0x73, 0x73, 0x68, // 'pssh'
349 0x01, // version 383 0x01, // version
350 0x00, 0x00, 0x00, // flags 384 0x00, 0x00, 0x00, // flags
351 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID 385 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID
352 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 386 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
353 0x00, 0x00, 0x00, 0x02, // key count 387 0x00, 0x00, 0x00, 0x02, // key count
354 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 388 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
355 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 389 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
356 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 390 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2
357 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 391 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
358 0x00, 0x00, 0x00, 0x00 // datasize 392 0x00, 0x00, 0x00, 0x00 // datasize
359 }; 393 };
360 394
361 KeyIdList key_ids; 395 KeyIdList key_ids;
362 EXPECT_TRUE( 396 EXPECT_TRUE(
363 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); 397 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
364 EXPECT_TRUE(GetKeyIdsForCommonSystemId( 398 EXPECT_TRUE(
365 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); 399 GetKeyIdsFromPsshBoxes(std::vector<uint8_t>(data, data + arraysize(data)),
400 CommonSystemSystemId(), &key_ids));
366 EXPECT_EQ(2u, key_ids.size()); 401 EXPECT_EQ(2u, key_ids.size());
367 } 402 }
368 403
369 TEST_F(CencUtilsTest, HugeSize) { 404 TEST_F(CencUtilsTest, HugeSize) {
370 const uint8_t data[] = { 405 const uint8_t data[] = {
371 0x00, 0x00, 0x00, 0x01, // size = 1 406 0x00, 0x00, 0x00, 0x01, // size = 1
372 0x70, 0x73, 0x73, 0x68, // 'pssh' 407 0x70, 0x73, 0x73, 0x68, // 'pssh'
373 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // longsize = big 408 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // longsize = big
374 0x01, // version 409 0x01, // version
375 0x00, 0x00, 0x00, // flags 410 0x00, 0x00, 0x00, // flags
376 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID 411 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID
377 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, 412 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B,
378 0x00, 0x00, 0x00, 0x02, // key count 413 0x00, 0x00, 0x00, 0x02, // key count
379 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 414 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1
380 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 415 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03,
381 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 416 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2
382 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 417 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04,
383 0x00, 0x00, 0x00, 0x00 // datasize 418 0x00, 0x00, 0x00, 0x00 // datasize
384 }; 419 };
385 420
386 KeyIdList key_ids; 421 KeyIdList key_ids;
387 // These calls fail as the box size is huge (0xffffffffffffffff) and there 422 // These calls fail as the box size is huge (0xffffffffffffffff) and there
388 // is not enough bytes in |data|. 423 // is not enough bytes in |data|.
389 EXPECT_FALSE( 424 EXPECT_FALSE(
390 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); 425 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data))));
391 EXPECT_FALSE(GetKeyIdsForCommonSystemId( 426 EXPECT_FALSE(
392 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); 427 GetKeyIdsFromPsshBoxes(std::vector<uint8_t>(data, data + arraysize(data)),
428 CommonSystemSystemId(), &key_ids));
393 } 429 }
394 430
395 TEST_F(CencUtilsTest, GetPsshData_Version0) { 431 TEST_F(CencUtilsTest, GetPsshData_Version0) {
396 const uint8_t data_bytes[] = {0x01, 0x02, 0x03, 0x04}; 432 const uint8_t data_bytes[] = {0x01, 0x02, 0x03, 0x04};
397 std::vector<uint8_t> pssh_data; 433 std::vector<uint8_t> pssh_data;
398 434
399 std::vector<uint8_t> box = MakePSSHBox(0); 435 std::vector<uint8_t> box = MakePSSHBox(0);
400 EXPECT_TRUE(GetPsshData(box, CommonSystemSystemId(), &pssh_data)); 436 EXPECT_TRUE(GetPsshData(box, CommonSystemSystemId(), &pssh_data));
401 EXPECT_EQ(0u, pssh_data.size()); 437 EXPECT_EQ(0u, pssh_data.size());
402 438
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 486
451 std::vector<uint8_t> box_v1 = MakePSSHBox(1, Key1()); 487 std::vector<uint8_t> box_v1 = MakePSSHBox(1, Key1());
452 std::vector<uint8_t> box_v2 = MakePSSHBox(2, Key2(), Key3()); 488 std::vector<uint8_t> box_v2 = MakePSSHBox(2, Key2(), Key3());
453 489
454 // Concatentate the boxes together (v2 first). 490 // Concatentate the boxes together (v2 first).
455 std::vector<uint8_t> boxes; 491 std::vector<uint8_t> boxes;
456 boxes.insert(boxes.end(), box_v2.begin(), box_v2.end()); 492 boxes.insert(boxes.end(), box_v2.begin(), box_v2.end());
457 boxes.insert(boxes.end(), box_v1.begin(), box_v1.end()); 493 boxes.insert(boxes.end(), box_v1.begin(), box_v1.end());
458 EXPECT_TRUE(GetPsshData(boxes, CommonSystemSystemId(), &pssh_data)); 494 EXPECT_TRUE(GetPsshData(boxes, CommonSystemSystemId(), &pssh_data));
459 495
460 // GetKeyIdsForCommonSystemId() should return the single key from the v1 496 // GetKeyIdsFromPsshBoxes() should return the single key from the v1
ddorwin 2015/06/25 22:49:23 nit: "... v1 box." should fit. Below too.
jrummell 2015/06/30 00:49:12 Back to the old name, need the wrap.
461 // 'pssh' box. 497 // 'pssh' box.
462 KeyIdList key_ids; 498 KeyIdList key_ids;
463 EXPECT_TRUE(GetKeyIdsForCommonSystemId(boxes, &key_ids)); 499 EXPECT_TRUE(GetKeyIdsFromPsshBoxes(boxes, CommonSystemSystemId(), &key_ids));
464 EXPECT_EQ(1u, key_ids.size()); 500 EXPECT_EQ(1u, key_ids.size());
465 EXPECT_EQ(key_ids[0], Key1()); 501 EXPECT_EQ(key_ids[0], Key1());
466 } 502 }
467 503
468 TEST_F(CencUtilsTest, GetPsshData_Version1ThenVersion2) { 504 TEST_F(CencUtilsTest, GetPsshData_Version1ThenVersion2) {
469 std::vector<uint8_t> pssh_data; 505 std::vector<uint8_t> pssh_data;
470 506
471 std::vector<uint8_t> box_v1 = MakePSSHBox(1, Key3()); 507 std::vector<uint8_t> box_v1 = MakePSSHBox(1, Key3());
472 std::vector<uint8_t> box_v2 = MakePSSHBox(2, Key4()); 508 std::vector<uint8_t> box_v2 = MakePSSHBox(2, Key4());
473 509
474 // Concatentate the boxes together (v1 first). 510 // Concatentate the boxes together (v1 first).
475 std::vector<uint8_t> boxes; 511 std::vector<uint8_t> boxes;
476 boxes.insert(boxes.end(), box_v1.begin(), box_v1.end()); 512 boxes.insert(boxes.end(), box_v1.begin(), box_v1.end());
477 boxes.insert(boxes.end(), box_v2.begin(), box_v2.end()); 513 boxes.insert(boxes.end(), box_v2.begin(), box_v2.end());
478 EXPECT_TRUE(GetPsshData(boxes, CommonSystemSystemId(), &pssh_data)); 514 EXPECT_TRUE(GetPsshData(boxes, CommonSystemSystemId(), &pssh_data));
479 515
480 // GetKeyIdsForCommonSystemId() should return the single key from the v1 516 // GetKeyIdsFromPsshBoxes() should return the single key from the v1
481 // 'pssh' box. 517 // 'pssh' box.
482 KeyIdList key_ids; 518 KeyIdList key_ids;
483 EXPECT_TRUE(GetKeyIdsForCommonSystemId(boxes, &key_ids)); 519 EXPECT_TRUE(GetKeyIdsFromPsshBoxes(boxes, CommonSystemSystemId(), &key_ids));
484 EXPECT_EQ(1u, key_ids.size()); 520 EXPECT_EQ(1u, key_ids.size());
485 EXPECT_EQ(key_ids[0], Key3()); 521 EXPECT_EQ(key_ids[0], Key3());
486 } 522 }
487 523
488 TEST_F(CencUtilsTest, GetPsshData_DifferentSystemID) { 524 TEST_F(CencUtilsTest, GetPsshData_DifferentSystemID) {
489 std::vector<uint8_t> unknown_system_id(kKey1Data, 525 std::vector<uint8_t> unknown_system_id(kKey1Data,
490 kKey1Data + arraysize(kKey1Data)); 526 kKey1Data + arraysize(kKey1Data));
491 std::vector<uint8_t> pssh_data; 527 std::vector<uint8_t> pssh_data;
492 528
493 std::vector<uint8_t> box = MakePSSHBox(1, Key1()); 529 std::vector<uint8_t> box = MakePSSHBox(1, Key1());
(...skipping 28 matching lines...) Expand all
522 std::vector<uint8_t> box2 = MakePSSHBox(0); 558 std::vector<uint8_t> box2 = MakePSSHBox(0);
523 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes)); 559 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes));
524 AppendData(box2, data2); 560 AppendData(box2, data2);
525 561
526 box1.insert(box1.end(), box2.begin(), box2.end()); 562 box1.insert(box1.end(), box2.begin(), box2.end());
527 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data)); 563 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data));
528 EXPECT_EQ(data1, pssh_data); 564 EXPECT_EQ(data1, pssh_data);
529 EXPECT_NE(data2, pssh_data); 565 EXPECT_NE(data2, pssh_data);
530 } 566 }
531 } // namespace media 567 } // namespace media
OLDNEW
« media/cdm/cenc_utils.cc ('K') | « media/cdm/cenc_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698