This source file includes following definitions.
- parser_
- ParseAndExpectToFail
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "base/bind.h"
#include "media/formats/webm/webm_constants.h"
#include "media/formats/webm/webm_content_encodings_client.h"
#include "media/formats/webm/webm_parser.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
class WebMContentEncodingsClientTest : public testing::Test {
public:
WebMContentEncodingsClientTest()
: client_(LogCB()),
parser_(kWebMIdContentEncodings, &client_) {}
void ParseAndExpectToFail(const uint8* buf, int size) {
int result = parser_.Parse(buf, size);
EXPECT_EQ(-1, result);
}
protected:
WebMContentEncodingsClient client_;
WebMListParser parser_;
};
TEST_F(WebMContentEncodingsClientTest, EmptyContentEncodings) {
const uint8 kContentEncodings[] = {
0x6D, 0x80, 0x80,
};
int size = sizeof(kContentEncodings);
ParseAndExpectToFail(kContentEncodings, size);
}
TEST_F(WebMContentEncodingsClientTest, EmptyContentEncoding) {
const uint8 kContentEncodings[] = {
0x6D, 0x80, 0x83,
0x63, 0x40, 0x80,
};
int size = sizeof(kContentEncodings);
ParseAndExpectToFail(kContentEncodings, size);
}
TEST_F(WebMContentEncodingsClientTest, SingleContentEncoding) {
const uint8 kContentEncodings[] = {
0x6D, 0x80, 0xA1,
0x62, 0x40, 0x9e,
0x50, 0x31, 0x81, 0x00,
0x50, 0x32, 0x81, 0x01,
0x50, 0x33, 0x81, 0x01,
0x50, 0x35, 0x8F,
0x47, 0xE1, 0x81, 0x05,
0x47, 0xE2, 0x88,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
};
int size = sizeof(kContentEncodings);
int result = parser_.Parse(kContentEncodings, size);
ASSERT_EQ(size, result);
const ContentEncodings& content_encodings = client_.content_encodings();
ASSERT_EQ(1u, content_encodings.size());
ASSERT_TRUE(content_encodings[0]);
EXPECT_EQ(0, content_encodings[0]->order());
EXPECT_EQ(ContentEncoding::kScopeAllFrameContents,
content_encodings[0]->scope());
EXPECT_EQ(ContentEncoding::kTypeEncryption, content_encodings[0]->type());
EXPECT_EQ(ContentEncoding::kEncAlgoAes,
content_encodings[0]->encryption_algo());
EXPECT_EQ(8u, content_encodings[0]->encryption_key_id().size());
}
TEST_F(WebMContentEncodingsClientTest, MultipleContentEncoding) {
const uint8 kContentEncodings[] = {
0x6D, 0x80, 0xC2,
0x62, 0x40, 0x9e,
0x50, 0x31, 0x81, 0x00,
0x50, 0x32, 0x81, 0x03,
0x50, 0x33, 0x81, 0x01,
0x50, 0x35, 0x8F,
0x47, 0xE1, 0x81, 0x05,
0x47, 0xE2, 0x88,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
0x62, 0x40, 0x9e,
0x50, 0x31, 0x81, 0x01,
0x50, 0x32, 0x81, 0x03,
0x50, 0x33, 0x81, 0x01,
0x50, 0x35, 0x8F,
0x47, 0xE1, 0x81, 0x01,
0x47, 0xE2, 0x88,
0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB, 0xBB,
};
int size = sizeof(kContentEncodings);
int result = parser_.Parse(kContentEncodings, size);
ASSERT_EQ(size, result);
const ContentEncodings& content_encodings = client_.content_encodings();
ASSERT_EQ(2u, content_encodings.size());
for (int i = 0; i < 2; ++i) {
ASSERT_TRUE(content_encodings[i]);
EXPECT_EQ(i, content_encodings[i]->order());
EXPECT_EQ(ContentEncoding::kScopeAllFrameContents |
ContentEncoding::kScopeTrackPrivateData,
content_encodings[i]->scope());
EXPECT_EQ(ContentEncoding::kTypeEncryption, content_encodings[i]->type());
EXPECT_EQ(!i ? ContentEncoding::kEncAlgoAes : ContentEncoding::kEncAlgoDes,
content_encodings[i]->encryption_algo());
EXPECT_EQ(8u, content_encodings[i]->encryption_key_id().size());
}
}
TEST_F(WebMContentEncodingsClientTest, DefaultValues) {
const uint8 kContentEncodings[] = {
0x6D, 0x80, 0x8A,
0x62, 0x40, 0x87,
0x50, 0x33, 0x81, 0x01,
0x50, 0x35, 0x80,
};
int size = sizeof(kContentEncodings);
int result = parser_.Parse(kContentEncodings, size);
ASSERT_EQ(size, result);
const ContentEncodings& content_encodings = client_.content_encodings();
ASSERT_EQ(1u, content_encodings.size());
ASSERT_TRUE(content_encodings[0]);
EXPECT_EQ(0, content_encodings[0]->order());
EXPECT_EQ(ContentEncoding::kScopeAllFrameContents,
content_encodings[0]->scope());
EXPECT_EQ(ContentEncoding::kTypeEncryption, content_encodings[0]->type());
EXPECT_EQ(ContentEncoding::kEncAlgoNotEncrypted,
content_encodings[0]->encryption_algo());
EXPECT_TRUE(content_encodings[0]->encryption_key_id().empty());
}
TEST_F(WebMContentEncodingsClientTest, ContentEncodingsClientReuse) {
const uint8 kContentEncodings[] = {
0x6D, 0x80, 0xA1,
0x62, 0x40, 0x9e,
0x50, 0x31, 0x81, 0x00,
0x50, 0x32, 0x81, 0x01,
0x50, 0x33, 0x81, 0x01,
0x50, 0x35, 0x8F,
0x47, 0xE1, 0x81, 0x05,
0x47, 0xE2, 0x88,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
};
int size = sizeof(kContentEncodings);
int result = parser_.Parse(kContentEncodings, size);
ASSERT_EQ(size, result);
parser_.Reset();
result = parser_.Parse(kContentEncodings, size);
ASSERT_EQ(size, result);
const ContentEncodings& content_encodings = client_.content_encodings();
ASSERT_EQ(1u, content_encodings.size());
ASSERT_TRUE(content_encodings[0]);
EXPECT_EQ(0, content_encodings[0]->order());
EXPECT_EQ(ContentEncoding::kScopeAllFrameContents,
content_encodings[0]->scope());
EXPECT_EQ(ContentEncoding::kTypeEncryption, content_encodings[0]->type());
EXPECT_EQ(ContentEncoding::kEncAlgoAes,
content_encodings[0]->encryption_algo());
EXPECT_EQ(8u, content_encodings[0]->encryption_key_id().size());
}
TEST_F(WebMContentEncodingsClientTest, InvalidContentEncodingOrder) {
const uint8 kContentEncodings[] = {
0x6D, 0x80, 0x8E,
0x62, 0x40, 0x8B,
0x50, 0x31, 0x81, 0xEE,
0x50, 0x33, 0x81, 0x01,
0x50, 0x35, 0x80,
};
int size = sizeof(kContentEncodings);
ParseAndExpectToFail(kContentEncodings, size);
}
TEST_F(WebMContentEncodingsClientTest, InvalidContentEncodingScope) {
const uint8 kContentEncodings[] = {
0x6D, 0x80, 0x8E,
0x62, 0x40, 0x8B,
0x50, 0x32, 0x81, 0xEE,
0x50, 0x33, 0x81, 0x01,
0x50, 0x35, 0x80,
};
int size = sizeof(kContentEncodings);
ParseAndExpectToFail(kContentEncodings, size);
}
TEST_F(WebMContentEncodingsClientTest, InvalidContentEncodingType) {
const uint8 kContentEncodings[] = {
0x6D, 0x80, 0x8E,
0x62, 0x40, 0x8B,
0x50, 0x33, 0x81, 0x00,
0x50, 0x35, 0x80,
};
int size = sizeof(kContentEncodings);
ParseAndExpectToFail(kContentEncodings, size);
}
TEST_F(WebMContentEncodingsClientTest, MissingContentEncryption) {
const uint8 kContentEncodings[] = {
0x6D, 0x80, 0x87,
0x62, 0x40, 0x84,
0x50, 0x33, 0x81, 0x01,
};
int size = sizeof(kContentEncodings);
ParseAndExpectToFail(kContentEncodings, size);
}
TEST_F(WebMContentEncodingsClientTest, InvalidContentEncAlgo) {
const uint8 kContentEncodings[] = {
0x6D, 0x80, 0x99,
0x62, 0x40, 0x96,
0x50, 0x33, 0x81, 0x01,
0x50, 0x35, 0x8F,
0x47, 0xE1, 0x81, 0xEE,
0x47, 0xE2, 0x88,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
};
int size = sizeof(kContentEncodings);
ParseAndExpectToFail(kContentEncodings, size);
}
}