OLD | NEW |
---|---|
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 Loading... | |
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( |
184 GetKeyIds(std::vector<uint8_t>(), CommonSystemSystemId(), &key_ids)); | |
sandersd (OOO until July 31)
2015/06/22 20:17:20
Add a test using a different key system ID?
jrummell
2015/06/22 21:01:18
There is one (line 295), but added a second variat
sandersd (OOO until July 31)
2015/06/22 22:23:29
I would also like to see a test were a |key_system
jrummell
2015/06/24 00:18:47
Added.
| |
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(GetKeyIds(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(GetKeyIds(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(GetKeyIds(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(GetKeyIds(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(GetKeyIds(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(GetKeyIds(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(GetKeyIds(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(GetKeyIds(truncated, CommonSystemSystemId(), &key_ids)); |
279 } | 274 } |
280 } | 275 } |
281 | 276 |
282 TEST_F(CencUtilsTest, PsshBoxLargerThanSize) { | 277 TEST_F(CencUtilsTest, PsshBoxLargerThanSize) { |
283 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 278 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
284 KeyIdList key_ids; | 279 KeyIdList key_ids; |
285 | 280 |
286 // Add 20 additional bytes to |box|. | 281 // Add 20 additional bytes to |box|. |
287 size_t original_size = box.size(); | 282 size_t original_size = box.size(); |
288 for (size_t i = 0; i < 20; ++i) | 283 for (size_t i = 0; i < 20; ++i) |
289 box.push_back(i); | 284 box.push_back(i); |
290 | 285 |
291 // Tries every size greater than |original_size|. | 286 // Tries every size greater than |original_size|. |
292 for (size_t i = original_size + 1; i < box.size(); ++i) { | 287 for (size_t i = original_size + 1; i < box.size(); ++i) { |
293 // Modify size of box passed to be less than current size. | 288 // Modify size of box passed to be less than current size. |
294 std::vector<uint8_t> truncated(&box[0], &box[0] + i); | 289 std::vector<uint8_t> truncated(&box[0], &box[0] + i); |
295 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i; | 290 EXPECT_FALSE(ValidatePsshInput(truncated)) << "Failed for length " << i; |
296 EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids)); | 291 EXPECT_FALSE(GetKeyIds(truncated, CommonSystemSystemId(), &key_ids)); |
297 } | 292 } |
298 } | 293 } |
299 | 294 |
300 TEST_F(CencUtilsTest, UnrecognizedSystemID) { | 295 TEST_F(CencUtilsTest, UnrecognizedSystemID) { |
301 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 296 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
302 | 297 |
303 // Modify the System ID. | 298 // Modify the System ID. |
304 ++box[20]; | 299 ++box[20]; |
305 | 300 |
306 KeyIdList key_ids; | 301 KeyIdList key_ids; |
307 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids)); | 302 EXPECT_FALSE(GetKeyIds(box, CommonSystemSystemId(), &key_ids)); |
308 } | 303 } |
309 | 304 |
310 TEST_F(CencUtilsTest, InvalidFlags) { | 305 TEST_F(CencUtilsTest, InvalidFlags) { |
311 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 306 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
312 | 307 |
313 // Modify flags. | 308 // Modify flags. |
314 box[10] = 3; | 309 box[10] = 3; |
315 | 310 |
316 KeyIdList key_ids; | 311 KeyIdList key_ids; |
317 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box, &key_ids)); | 312 EXPECT_FALSE(GetKeyIds(box, CommonSystemSystemId(), &key_ids)); |
318 } | 313 } |
319 | 314 |
320 TEST_F(CencUtilsTest, LongSize) { | 315 TEST_F(CencUtilsTest, LongSize) { |
321 const uint8_t data[] = { | 316 const uint8_t data[] = { |
322 0x00, 0x00, 0x00, 0x01, // size = 1 | 317 0x00, 0x00, 0x00, 0x01, // size = 1 |
323 0x70, 0x73, 0x73, 0x68, // 'pssh' | 318 0x70, 0x73, 0x73, 0x68, // 'pssh' |
324 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, // longsize | 319 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, // longsize |
325 0x01, // version | 320 0x01, // version |
326 0x00, 0x00, 0x00, // flags | 321 0x00, 0x00, 0x00, // flags |
327 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID | 322 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID |
328 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, | 323 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, |
329 0x00, 0x00, 0x00, 0x02, // key count | 324 0x00, 0x00, 0x00, 0x02, // key count |
330 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 | 325 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 |
331 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, | 326 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, |
332 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 | 327 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 |
333 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, | 328 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, |
334 0x00, 0x00, 0x00, 0x00 // datasize | 329 0x00, 0x00, 0x00, 0x00 // datasize |
335 }; | 330 }; |
336 | 331 |
337 KeyIdList key_ids; | 332 KeyIdList key_ids; |
338 EXPECT_TRUE( | 333 EXPECT_TRUE( |
339 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); | 334 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); |
340 EXPECT_TRUE(GetKeyIdsForCommonSystemId( | 335 EXPECT_TRUE(GetKeyIds(std::vector<uint8_t>(data, data + arraysize(data)), |
341 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); | 336 CommonSystemSystemId(), &key_ids)); |
342 EXPECT_EQ(2u, key_ids.size()); | 337 EXPECT_EQ(2u, key_ids.size()); |
343 } | 338 } |
344 | 339 |
345 TEST_F(CencUtilsTest, SizeIsZero) { | 340 TEST_F(CencUtilsTest, SizeIsZero) { |
346 const uint8_t data[] = { | 341 const uint8_t data[] = { |
347 0x00, 0x00, 0x00, 0x00, // size = 0 | 342 0x00, 0x00, 0x00, 0x00, // size = 0 |
348 0x70, 0x73, 0x73, 0x68, // 'pssh' | 343 0x70, 0x73, 0x73, 0x68, // 'pssh' |
349 0x01, // version | 344 0x01, // version |
350 0x00, 0x00, 0x00, // flags | 345 0x00, 0x00, 0x00, // flags |
351 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID | 346 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID |
352 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, | 347 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, |
353 0x00, 0x00, 0x00, 0x02, // key count | 348 0x00, 0x00, 0x00, 0x02, // key count |
354 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 | 349 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 |
355 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, | 350 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, |
356 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 | 351 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 |
357 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, | 352 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, |
358 0x00, 0x00, 0x00, 0x00 // datasize | 353 0x00, 0x00, 0x00, 0x00 // datasize |
359 }; | 354 }; |
360 | 355 |
361 KeyIdList key_ids; | 356 KeyIdList key_ids; |
362 EXPECT_TRUE( | 357 EXPECT_TRUE( |
363 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); | 358 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); |
364 EXPECT_TRUE(GetKeyIdsForCommonSystemId( | 359 EXPECT_TRUE(GetKeyIds(std::vector<uint8_t>(data, data + arraysize(data)), |
365 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); | 360 CommonSystemSystemId(), &key_ids)); |
366 EXPECT_EQ(2u, key_ids.size()); | 361 EXPECT_EQ(2u, key_ids.size()); |
367 } | 362 } |
368 | 363 |
369 TEST_F(CencUtilsTest, HugeSize) { | 364 TEST_F(CencUtilsTest, HugeSize) { |
370 const uint8_t data[] = { | 365 const uint8_t data[] = { |
371 0x00, 0x00, 0x00, 0x01, // size = 1 | 366 0x00, 0x00, 0x00, 0x01, // size = 1 |
372 0x70, 0x73, 0x73, 0x68, // 'pssh' | 367 0x70, 0x73, 0x73, 0x68, // 'pssh' |
373 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // longsize = big | 368 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // longsize = big |
374 0x01, // version | 369 0x01, // version |
375 0x00, 0x00, 0x00, // flags | 370 0x00, 0x00, 0x00, // flags |
376 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID | 371 0x10, 0x77, 0xEF, 0xEC, 0xC0, 0xB2, 0x4D, 0x02, // SystemID |
377 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, | 372 0xAC, 0xE3, 0x3C, 0x1E, 0x52, 0xE2, 0xFB, 0x4B, |
378 0x00, 0x00, 0x00, 0x02, // key count | 373 0x00, 0x00, 0x00, 0x02, // key count |
379 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 | 374 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, // key1 |
380 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, | 375 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, |
381 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 | 376 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, // key2 |
382 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, | 377 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, |
383 0x00, 0x00, 0x00, 0x00 // datasize | 378 0x00, 0x00, 0x00, 0x00 // datasize |
384 }; | 379 }; |
385 | 380 |
386 KeyIdList key_ids; | 381 KeyIdList key_ids; |
387 // These calls fail as the box size is huge (0xffffffffffffffff) and there | 382 // These calls fail as the box size is huge (0xffffffffffffffff) and there |
388 // is not enough bytes in |data|. | 383 // is not enough bytes in |data|. |
389 EXPECT_FALSE( | 384 EXPECT_FALSE( |
390 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); | 385 ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); |
391 EXPECT_FALSE(GetKeyIdsForCommonSystemId( | 386 EXPECT_FALSE(GetKeyIds(std::vector<uint8_t>(data, data + arraysize(data)), |
392 std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); | 387 CommonSystemSystemId(), &key_ids)); |
393 } | 388 } |
394 | 389 |
395 TEST_F(CencUtilsTest, GetPsshData_Version0) { | 390 TEST_F(CencUtilsTest, GetPsshData_Version0) { |
396 const uint8_t data_bytes[] = {0x01, 0x02, 0x03, 0x04}; | 391 const uint8_t data_bytes[] = {0x01, 0x02, 0x03, 0x04}; |
397 std::vector<uint8_t> pssh_data; | 392 std::vector<uint8_t> pssh_data; |
398 | 393 |
399 std::vector<uint8_t> box = MakePSSHBox(0); | 394 std::vector<uint8_t> box = MakePSSHBox(0); |
400 EXPECT_TRUE(GetPsshData(box, CommonSystemSystemId(), &pssh_data)); | 395 EXPECT_TRUE(GetPsshData(box, CommonSystemSystemId(), &pssh_data)); |
401 EXPECT_EQ(0u, pssh_data.size()); | 396 EXPECT_EQ(0u, pssh_data.size()); |
402 | 397 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 | 445 |
451 std::vector<uint8_t> box_v1 = MakePSSHBox(1, Key1()); | 446 std::vector<uint8_t> box_v1 = MakePSSHBox(1, Key1()); |
452 std::vector<uint8_t> box_v2 = MakePSSHBox(2, Key2(), Key3()); | 447 std::vector<uint8_t> box_v2 = MakePSSHBox(2, Key2(), Key3()); |
453 | 448 |
454 // Concatentate the boxes together (v2 first). | 449 // Concatentate the boxes together (v2 first). |
455 std::vector<uint8_t> boxes; | 450 std::vector<uint8_t> boxes; |
456 boxes.insert(boxes.end(), box_v2.begin(), box_v2.end()); | 451 boxes.insert(boxes.end(), box_v2.begin(), box_v2.end()); |
457 boxes.insert(boxes.end(), box_v1.begin(), box_v1.end()); | 452 boxes.insert(boxes.end(), box_v1.begin(), box_v1.end()); |
458 EXPECT_TRUE(GetPsshData(boxes, CommonSystemSystemId(), &pssh_data)); | 453 EXPECT_TRUE(GetPsshData(boxes, CommonSystemSystemId(), &pssh_data)); |
459 | 454 |
460 // GetKeyIdsForCommonSystemId() should return the single key from the v1 | 455 // GetKeyIds() should return the single key from the v1 'pssh' box. |
461 // 'pssh' box. | |
462 KeyIdList key_ids; | 456 KeyIdList key_ids; |
463 EXPECT_TRUE(GetKeyIdsForCommonSystemId(boxes, &key_ids)); | 457 EXPECT_TRUE(GetKeyIds(boxes, CommonSystemSystemId(), &key_ids)); |
464 EXPECT_EQ(1u, key_ids.size()); | 458 EXPECT_EQ(1u, key_ids.size()); |
465 EXPECT_EQ(key_ids[0], Key1()); | 459 EXPECT_EQ(key_ids[0], Key1()); |
466 } | 460 } |
467 | 461 |
468 TEST_F(CencUtilsTest, GetPsshData_Version1ThenVersion2) { | 462 TEST_F(CencUtilsTest, GetPsshData_Version1ThenVersion2) { |
469 std::vector<uint8_t> pssh_data; | 463 std::vector<uint8_t> pssh_data; |
470 | 464 |
471 std::vector<uint8_t> box_v1 = MakePSSHBox(1, Key3()); | 465 std::vector<uint8_t> box_v1 = MakePSSHBox(1, Key3()); |
472 std::vector<uint8_t> box_v2 = MakePSSHBox(2, Key4()); | 466 std::vector<uint8_t> box_v2 = MakePSSHBox(2, Key4()); |
473 | 467 |
474 // Concatentate the boxes together (v1 first). | 468 // Concatentate the boxes together (v1 first). |
475 std::vector<uint8_t> boxes; | 469 std::vector<uint8_t> boxes; |
476 boxes.insert(boxes.end(), box_v1.begin(), box_v1.end()); | 470 boxes.insert(boxes.end(), box_v1.begin(), box_v1.end()); |
477 boxes.insert(boxes.end(), box_v2.begin(), box_v2.end()); | 471 boxes.insert(boxes.end(), box_v2.begin(), box_v2.end()); |
478 EXPECT_TRUE(GetPsshData(boxes, CommonSystemSystemId(), &pssh_data)); | 472 EXPECT_TRUE(GetPsshData(boxes, CommonSystemSystemId(), &pssh_data)); |
479 | 473 |
480 // GetKeyIdsForCommonSystemId() should return the single key from the v1 | 474 // GetKeyIds() should return the single key from the v1 'pssh' box. |
481 // 'pssh' box. | |
482 KeyIdList key_ids; | 475 KeyIdList key_ids; |
483 EXPECT_TRUE(GetKeyIdsForCommonSystemId(boxes, &key_ids)); | 476 EXPECT_TRUE(GetKeyIds(boxes, CommonSystemSystemId(), &key_ids)); |
484 EXPECT_EQ(1u, key_ids.size()); | 477 EXPECT_EQ(1u, key_ids.size()); |
485 EXPECT_EQ(key_ids[0], Key3()); | 478 EXPECT_EQ(key_ids[0], Key3()); |
486 } | 479 } |
487 | 480 |
488 TEST_F(CencUtilsTest, GetPsshData_DifferentSystemID) { | 481 TEST_F(CencUtilsTest, GetPsshData_DifferentSystemID) { |
489 std::vector<uint8_t> unknown_system_id(kKey1Data, | 482 std::vector<uint8_t> unknown_system_id(kKey1Data, |
490 kKey1Data + arraysize(kKey1Data)); | 483 kKey1Data + arraysize(kKey1Data)); |
491 std::vector<uint8_t> pssh_data; | 484 std::vector<uint8_t> pssh_data; |
492 | 485 |
493 std::vector<uint8_t> box = MakePSSHBox(1, Key1()); | 486 std::vector<uint8_t> box = MakePSSHBox(1, Key1()); |
(...skipping 28 matching lines...) Expand all Loading... | |
522 std::vector<uint8_t> box2 = MakePSSHBox(0); | 515 std::vector<uint8_t> box2 = MakePSSHBox(0); |
523 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes)); | 516 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes)); |
524 AppendData(box2, data2); | 517 AppendData(box2, data2); |
525 | 518 |
526 box1.insert(box1.end(), box2.begin(), box2.end()); | 519 box1.insert(box1.end(), box2.begin(), box2.end()); |
527 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data)); | 520 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data)); |
528 EXPECT_EQ(data1, pssh_data); | 521 EXPECT_EQ(data1, pssh_data); |
529 EXPECT_NE(data2, pssh_data); | 522 EXPECT_NE(data2, pssh_data); |
530 } | 523 } |
531 } // namespace media | 524 } // namespace media |
OLD | NEW |