| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 EXPECT_EQ(key_ids[0], Key1()); | 215 EXPECT_EQ(key_ids[0], Key1()); |
| 216 EXPECT_EQ(key_ids[1], Key2()); | 216 EXPECT_EQ(key_ids[1], Key2()); |
| 217 } | 217 } |
| 218 | 218 |
| 219 TEST_F(CencUtilsTest, PSSHVersion0Plus1) { | 219 TEST_F(CencUtilsTest, PSSHVersion0Plus1) { |
| 220 std::vector<uint8_t> box0 = MakePSSHBox(0); | 220 std::vector<uint8_t> box0 = MakePSSHBox(0); |
| 221 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); | 221 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); |
| 222 | 222 |
| 223 // Concatentate box1 onto end of box0. | 223 // Concatentate box1 onto end of box0. |
| 224 box0.insert(box0.end(), box1.begin(), box1.end()); | 224 box0.insert(box0.end(), box1.begin(), box1.end()); |
| 225 EXPECT_TRUE(ValidatePsshInput(box0)); |
| 225 | 226 |
| 227 // No key IDs returned as only the first 'pssh' box is processed. |
| 226 KeyIdList key_ids; | 228 KeyIdList key_ids; |
| 227 EXPECT_TRUE(ValidatePsshInput(box0)); | 229 EXPECT_FALSE(GetKeyIdsForCommonSystemId(box0, &key_ids)); |
| 228 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box0, &key_ids)); | |
| 229 EXPECT_EQ(1u, key_ids.size()); | |
| 230 EXPECT_EQ(key_ids[0], Key1()); | |
| 231 } | 230 } |
| 232 | 231 |
| 233 TEST_F(CencUtilsTest, PSSHVersion1Plus0) { | 232 TEST_F(CencUtilsTest, PSSHVersion1Plus0) { |
| 234 std::vector<uint8_t> box0 = MakePSSHBox(0); | 233 std::vector<uint8_t> box0 = MakePSSHBox(0); |
| 235 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); | 234 std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); |
| 236 | 235 |
| 237 // Concatentate box0 onto end of box1. | 236 // Concatentate box0 onto end of box1. |
| 238 box1.insert(box1.end(), box0.begin(), box0.end()); | 237 box1.insert(box1.end(), box0.begin(), box0.end()); |
| 239 | 238 |
| 240 KeyIdList key_ids; | 239 KeyIdList key_ids; |
| 241 EXPECT_TRUE(ValidatePsshInput(box1)); | 240 EXPECT_TRUE(ValidatePsshInput(box1)); |
| 242 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box1, &key_ids)); | 241 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box1, &key_ids)); |
| 243 EXPECT_EQ(1u, key_ids.size()); | 242 EXPECT_EQ(1u, key_ids.size()); |
| 244 EXPECT_EQ(key_ids[0], Key1()); | 243 EXPECT_EQ(key_ids[0], Key1()); |
| 245 } | 244 } |
| 246 | 245 |
| 247 TEST_F(CencUtilsTest, MultiplePSSHVersion1) { | 246 TEST_F(CencUtilsTest, MultiplePSSHVersion1) { |
| 248 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 247 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
| 249 std::vector<uint8_t> box1 = MakePSSHBox(1, Key3()); | 248 std::vector<uint8_t> box1 = MakePSSHBox(1, Key3()); |
| 250 std::vector<uint8_t> box2 = MakePSSHBox(1, Key4()); | 249 std::vector<uint8_t> box2 = MakePSSHBox(1, Key4()); |
| 251 | 250 |
| 252 // Concatentate box1 and box2 onto end of box. | 251 // Concatentate box1 and box2 onto end of box. |
| 253 box.insert(box.end(), box1.begin(), box1.end()); | 252 box.insert(box.end(), box1.begin(), box1.end()); |
| 254 box.insert(box.end(), box2.begin(), box2.end()); | 253 box.insert(box.end(), box2.begin(), box2.end()); |
| 255 | 254 |
| 256 KeyIdList key_ids; | 255 KeyIdList key_ids; |
| 257 EXPECT_TRUE(ValidatePsshInput(box)); | 256 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)); | 257 EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); |
| 262 EXPECT_EQ(4u, key_ids.size()); | 258 EXPECT_EQ(2u, key_ids.size()); |
| 263 EXPECT_EQ(key_ids[0], Key1()); | 259 EXPECT_EQ(key_ids[0], Key1()); |
| 264 EXPECT_EQ(key_ids[1], Key2()); | 260 EXPECT_EQ(key_ids[1], Key2()); |
| 265 EXPECT_EQ(key_ids[2], Key3()); | |
| 266 EXPECT_EQ(key_ids[3], Key4()); | |
| 267 } | 261 } |
| 268 | 262 |
| 269 TEST_F(CencUtilsTest, PsshBoxSmallerThanSize) { | 263 TEST_F(CencUtilsTest, PsshBoxSmallerThanSize) { |
| 270 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); | 264 std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); |
| 271 KeyIdList key_ids; | 265 KeyIdList key_ids; |
| 272 | 266 |
| 273 // Tries every buffer size less than the indicated 'pssh' box size. | 267 // Tries every buffer size less than the indicated 'pssh' box size. |
| 274 for (size_t i = 1; i < box.size(); ++i) { | 268 for (size_t i = 1; i < box.size(); ++i) { |
| 275 // Truncate the box to be less than the specified box size. | 269 // Truncate the box to be less than the specified box size. |
| 276 std::vector<uint8_t> truncated(&box[0], &box[0] + i); | 270 std::vector<uint8_t> truncated(&box[0], &box[0] + i); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 std::vector<uint8_t> box2 = MakePSSHBox(0); | 516 std::vector<uint8_t> box2 = MakePSSHBox(0); |
| 523 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes)); | 517 std::vector<uint8_t> data2(data2_bytes, data2_bytes + arraysize(data2_bytes)); |
| 524 AppendData(box2, data2); | 518 AppendData(box2, data2); |
| 525 | 519 |
| 526 box1.insert(box1.end(), box2.begin(), box2.end()); | 520 box1.insert(box1.end(), box2.begin(), box2.end()); |
| 527 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data)); | 521 EXPECT_TRUE(GetPsshData(box1, CommonSystemSystemId(), &pssh_data)); |
| 528 EXPECT_EQ(data1, pssh_data); | 522 EXPECT_EQ(data1, pssh_data); |
| 529 EXPECT_NE(data2, pssh_data); | 523 EXPECT_NE(data2, pssh_data); |
| 530 } | 524 } |
| 531 } // namespace media | 525 } // namespace media |
| OLD | NEW |