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
3 // found in the LICENSE file.
5 #include "chromecast/media/cdm/chromecast_init_data.h"
9 #include "testing/gtest/include/gtest/gtest.h"
11 namespace chromecast
{
14 TEST(ChromecastInitDataTest
, TestPsshCustomData
) {
15 const uint8_t kInitDataBlob
[] = {
16 0x00, 0x00, 0x00, 0x32, // length
17 0x70, 0x73, 0x73, 0x68, // 'pssh'
18 0x00, 0x00, 0x00, 0x00, // version / flags
19 0x2B, 0xF8, 0x66, 0x80, 0xC6, 0xE5, 0x4E, 0x24, 0xBE,
20 0x23, 0x0F, 0x81, 0x5A, 0x60, 0x6E, 0xB2, // UUID
21 0x00, 0x00, 0x00, 0x12, // data size
22 0x00, 0x01, // message type (CUSTOM_DATA)
23 0x54, 0x65, 0x73, 0x74, 0x20, 0x63, 0x75, 0x73, 0x74,
24 0x6F, 0x6D, 0x20, 0x64, 0x61, 0x74, 0x61 // 'Test custom data'
27 ChromecastInitData init_data
;
28 EXPECT_TRUE(FindChromecastInitData(
29 std::vector
<uint8_t>(kInitDataBlob
,
30 kInitDataBlob
+ sizeof(kInitDataBlob
)),
31 InitDataMessageType::CUSTOM_DATA
, &init_data
));
33 EXPECT_EQ(InitDataMessageType::CUSTOM_DATA
, init_data
.type
);
34 EXPECT_EQ(16u, init_data
.data
.size());
35 EXPECT_EQ("Test custom data",
36 std::string(init_data
.data
.begin(), init_data
.data
.end()));
39 TEST(ChromecastInitDataTest
, TestPsshCustomData_NoSize
) {
40 const uint8_t kInitDataBlob
[] = {
41 0x00, 0x00, 0x00, 0x2E, // length
42 0x70, 0x73, 0x73, 0x68, // 'pssh'
43 0x00, 0x00, 0x00, 0x00, // version / flags
44 0x2B, 0xF8, 0x66, 0x80, 0xC6, 0xE5, 0x4E, 0x24, 0xBE,
45 0x23, 0x0F, 0x81, 0x5A, 0x60, 0x6E, 0xB2, // UUID
46 // [missing size should be present here].
47 0x00, 0x01, // message type (CUSTOM_DATA)
48 0x54, 0x65, 0x73, 0x74, 0x20, 0x63, 0x75, 0x73, 0x74,
49 0x6F, 0x6D, 0x20, 0x64, 0x61, 0x74, 0x61 // 'Test custom data'
52 ChromecastInitData init_data
;
53 EXPECT_FALSE(FindChromecastInitData(
54 std::vector
<uint8_t>(kInitDataBlob
,
55 kInitDataBlob
+ sizeof(kInitDataBlob
)),
56 InitDataMessageType::CUSTOM_DATA
, &init_data
));
59 TEST(ChromecastInitDataTest
, TestPsshSecureStop
) {
60 const uint8_t kInitDataBlob
[] = {
61 0x00, 0x00, 0x00, 0x22, // length
62 0x70, 0x73, 0x73, 0x68, // 'pssh'
63 0x00, 0x00, 0x00, 0x00, // version / flags
64 0x2B, 0xF8, 0x66, 0x80, 0xC6, 0xE5, 0x4E, 0x24,
65 0xBE, 0x23, 0x0F, 0x81, 0x5A, 0x60, 0x6E, 0xB2, // UUID
66 0x00, 0x00, 0x00, 0x02, // data size
67 0x00, 0x02, // message type (ENABLE_SECURE_STOP)
70 ChromecastInitData init_data
;
71 EXPECT_TRUE(FindChromecastInitData(
72 std::vector
<uint8_t>(kInitDataBlob
,
73 kInitDataBlob
+ sizeof(kInitDataBlob
)),
74 InitDataMessageType::ENABLE_SECURE_STOP
, &init_data
));
76 EXPECT_EQ(InitDataMessageType::ENABLE_SECURE_STOP
, init_data
.type
);
77 EXPECT_EQ(0u, init_data
.data
.size());
80 TEST(ChromecastInitDataTest
, TestPsshSecureStop_NoSize
) {
81 const uint8_t kInitDataBlob
[] = {
82 0x00, 0x00, 0x00, 0x1E, // length
83 0x70, 0x73, 0x73, 0x68, // 'pssh'
84 0x00, 0x00, 0x00, 0x00, // version / flags
85 0x2B, 0xF8, 0x66, 0x80, 0xC6, 0xE5, 0x4E, 0x24,
86 0xBE, 0x23, 0x0F, 0x81, 0x5A, 0x60, 0x6E, 0xB2, // UUID
87 // [missing size should be present here].
88 0x00, 0x02, // message type (ENABLE_SECURE_STOP)
91 ChromecastInitData init_data
;
92 EXPECT_FALSE(FindChromecastInitData(
93 std::vector
<uint8_t>(kInitDataBlob
,
94 kInitDataBlob
+ sizeof(kInitDataBlob
)),
95 InitDataMessageType::ENABLE_SECURE_STOP
, &init_data
));
99 } // namespace chromecast