This source file includes following definitions.
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
- TEST
#include "content/browser/renderer_host/p2p/socket_host.h"
#include <vector>
#include "base/memory/scoped_ptr.h"
#include "content/browser/renderer_host/p2p/socket_host_test_utils.h"
#include "net/base/ip_endpoint.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
static unsigned char kFakeTag[4] = { 0xba, 0xdd, 0xba, 0xdd };
static unsigned char kTestKey[] = "12345678901234567890";
static unsigned char kTestAstValue[3] = { 0xaa, 0xbb, 0xcc };
static unsigned char kRtpMsgWithInvalidLength[] = {
0x94, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xAA, 0xBB, 0xCC, 0XDD,
0xDD, 0xCC, 0xBB, 0xAA
};
static unsigned char kRtpMsgWithInvalidExtnLength[] = {
0x90, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xBE, 0xDE, 0x0A, 0x00
};
static unsigned char kRtpMsgWith2ByteExtnHeader[] = {
0x90, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xAA, 0xBB, 0xCC, 0XDD,
0x10, 0x00, 0x00, 0x01,
0x01, 0x00, 0x00, 0x00
};
static unsigned char kTurnSendIndicationMsgWithNoAttributes[] = {
0x00, 0x16, 0x00, 0x00,
0x21, 0x12, 0xA4, 0x42,
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
};
static unsigned char kTurnSendIndicationMsgWithInvalidLength[] = {
0x00, 0x16, 0xFF, 0x00,
0x21, 0x12, 0xA4, 0x42,
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
};
static unsigned char kTurnSendIndicatinMsgWithNoDataAttribute[] = {
0x00, 0x16, 0x00, 0x08,
0x21, 0x12, 0xA4, 0x42,
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
0x00, 0x20, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00
};
static unsigned char kTurnSendIndicationMsgWithoutRtpExtension[] = {
0x00, 0x16, 0x00, 0x18,
0x21, 0x12, 0xA4, 0x42,
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
0x00, 0x20, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00,
0x00, 0x13, 0x00, 0x0C,
0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
static unsigned char kTurnSendIndicationMsgWithAbsSendTimeExtension[] = {
0x00, 0x16, 0x00, 0x24,
0x21, 0x12, 0xA4, 0x42,
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'a', 'b',
0x00, 0x20, 0x00, 0x04,
0x00, 0x00, 0x00, 0x00,
0x00, 0x13, 0x00, 0x18,
0x90, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xBE, 0xDE, 0x00, 0x02,
0x22, 0xaa, 0xbb, 0xcc,
0x32, 0xaa, 0xbb, 0xcc,
};
static unsigned char kTurnChannelMsgNoRtpPacket[] = {
0x40, 0x00, 0x00, 0x04,
0xaa, 0xbb, 0xcc, 0xdd,
};
static unsigned char kTurnChannelMsgWithZeroLength[] = {
0x40, 0x00, 0x00, 0x00
};
static unsigned char kTurnChannelMsgWithRtpPacket[] = {
0x40, 0x00, 0x00, 0x0C,
0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
static unsigned char kTurnChannelMsgWithAbsSendTimeExtension[] = {
0x40, 0x00, 0x00, 0x14,
0x90, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xBE, 0xDE, 0x00, 0x01,
0x32, 0xaa, 0xbb, 0xcc,
};
static unsigned char kRtpMsgWithAbsSendTimeExtension[] = {
0x90, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xBE, 0xDE, 0x00, 0x02,
0x22, 0x00, 0x02, 0x1c,
0x32, 0xaa, 0xbb, 0xcc,
};
static const int kAstIndexInRtpMsg = 21;
namespace content {
TEST(P2PSocketHostTest, TestInvalidRawRtpMessages) {
int start_pos = INT_MAX, rtp_length = INT_MAX;
EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kRtpMsgWithInvalidLength),
sizeof(kRtpMsgWithInvalidLength),
&start_pos, &rtp_length));
EXPECT_EQ(INT_MAX, start_pos);
EXPECT_EQ(INT_MAX, rtp_length);
EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kRtpMsgWithInvalidExtnLength),
sizeof(kRtpMsgWithInvalidExtnLength),
&start_pos, &rtp_length));
EXPECT_EQ(INT_MAX, start_pos);
EXPECT_EQ(INT_MAX, rtp_length);
}
TEST(P2PSocketHostTest, TestInvalidTurnSendIndicationMessages) {
int start_pos = INT_MAX, rtp_length = INT_MAX;
EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kTurnSendIndicationMsgWithNoAttributes),
sizeof(kTurnSendIndicationMsgWithNoAttributes),
&start_pos, &rtp_length));
EXPECT_EQ(INT_MAX, start_pos);
EXPECT_EQ(INT_MAX, rtp_length);
EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kTurnSendIndicationMsgWithInvalidLength),
sizeof(kTurnSendIndicationMsgWithInvalidLength),
&start_pos, &rtp_length));
EXPECT_EQ(INT_MAX, start_pos);
EXPECT_EQ(INT_MAX, rtp_length);
EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kTurnSendIndicatinMsgWithNoDataAttribute),
sizeof(kTurnSendIndicatinMsgWithNoDataAttribute),
&start_pos, &rtp_length));
EXPECT_EQ(INT_MAX, start_pos);
EXPECT_EQ(INT_MAX, rtp_length);
}
TEST(P2PSocketHostTest, TestInvalidTurnChannelMessages) {
int start_pos = INT_MAX, rtp_length = INT_MAX;
EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kTurnChannelMsgNoRtpPacket),
sizeof(kTurnChannelMsgNoRtpPacket),
&start_pos, &rtp_length));
EXPECT_EQ(INT_MAX, start_pos);
EXPECT_EQ(INT_MAX, rtp_length);
EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kTurnChannelMsgWithZeroLength),
sizeof(kTurnChannelMsgWithZeroLength),
&start_pos, &rtp_length));
EXPECT_EQ(INT_MAX, start_pos);
EXPECT_EQ(INT_MAX, rtp_length);
}
TEST(P2PSocketHostTest, TestValid2ByteExtnHdrRtpMessage) {
int start_pos = INT_MAX, rtp_length = INT_MAX;
EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader),
sizeof(kRtpMsgWith2ByteExtnHeader),
&start_pos, &rtp_length));
EXPECT_EQ(20, rtp_length);
EXPECT_EQ(0, start_pos);
}
TEST(P2PSocketHostTest, TestValidRtpPacketWithAbsSendTimeExtension) {
int start_pos = INT_MAX, rtp_length = INT_MAX;
EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kRtpMsgWithAbsSendTimeExtension),
sizeof(kRtpMsgWithAbsSendTimeExtension),
&start_pos, &rtp_length));
EXPECT_EQ(24, rtp_length);
EXPECT_EQ(0, start_pos);
}
TEST(P2PSocketHostTest, TestValidTurnSendIndicationMessages) {
int start_pos = INT_MAX, rtp_length = INT_MAX;
EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension),
sizeof(kTurnSendIndicationMsgWithoutRtpExtension),
&start_pos, &rtp_length));
EXPECT_EQ(12, rtp_length);
EXPECT_EQ(32, start_pos);
start_pos = INT_MAX, rtp_length = INT_MAX;
EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kTurnSendIndicationMsgWithAbsSendTimeExtension),
sizeof(kTurnSendIndicationMsgWithAbsSendTimeExtension),
&start_pos, &rtp_length));
EXPECT_EQ(24, rtp_length);
EXPECT_EQ(32, start_pos);
}
TEST(P2PSocketHostTest, TestValidTurnChannelMessages) {
int start_pos = -1, rtp_length = -1;
EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kTurnChannelMsgWithRtpPacket),
sizeof(kTurnChannelMsgWithRtpPacket), &start_pos, &rtp_length));
EXPECT_EQ(12, rtp_length);
EXPECT_EQ(4, start_pos);
start_pos = -1, rtp_length = -1;
EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength(
reinterpret_cast<char*>(kTurnChannelMsgWithAbsSendTimeExtension),
sizeof(kTurnChannelMsgWithAbsSendTimeExtension),
&start_pos, &rtp_length));
EXPECT_EQ(20, rtp_length);
EXPECT_EQ(4, start_pos);
}
TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionIn2ByteHeaderExtn) {
EXPECT_FALSE(packet_processing_helpers::UpdateRtpAbsSendTimeExtn(
reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader),
sizeof(kRtpMsgWith2ByteExtnHeader), 3, 0));
}
TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionInTurnSendIndication) {
EXPECT_TRUE(packet_processing_helpers::UpdateRtpAbsSendTimeExtn(
reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension),
sizeof(kTurnSendIndicationMsgWithoutRtpExtension), 3, 0));
EXPECT_TRUE(packet_processing_helpers::UpdateRtpAbsSendTimeExtn(
reinterpret_cast<char*>(kTurnSendIndicationMsgWithAbsSendTimeExtension),
sizeof(kTurnSendIndicationMsgWithAbsSendTimeExtension), 3, 0));
}
TEST(P2PSocketHostTest, TestApplyPacketOptionsWithDefaultValues) {
unsigned char fake_tag[4] = { 0xba, 0xdd, 0xba, 0xdd };
talk_base::PacketOptions options;
std::vector<char> rtp_packet;
rtp_packet.resize(sizeof(kRtpMsgWithAbsSendTimeExtension) + 4);
memcpy(&rtp_packet[0], kRtpMsgWithAbsSendTimeExtension,
sizeof(kRtpMsgWithAbsSendTimeExtension));
memcpy(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], fake_tag, 4);
EXPECT_TRUE(
packet_processing_helpers::ApplyPacketOptions(
&rtp_packet[0], rtp_packet.size(), options, 0));
EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)],
fake_tag, 4));
EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg],
kTestAstValue, sizeof(kTestAstValue)));
}
TEST(P2PSocketHostTest, TestApplyPacketOptionsWithAuthParams) {
talk_base::PacketOptions options;
options.packet_time_params.srtp_auth_key.resize(20);
options.packet_time_params.srtp_auth_key.assign(
kTestKey, kTestKey + sizeof(kTestKey));
options.packet_time_params.srtp_auth_tag_len = 4;
std::vector<char> rtp_packet;
rtp_packet.resize(sizeof(kRtpMsgWithAbsSendTimeExtension) + 4);
memcpy(&rtp_packet[0], kRtpMsgWithAbsSendTimeExtension,
sizeof(kRtpMsgWithAbsSendTimeExtension));
memcpy(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], kFakeTag, 4);
EXPECT_TRUE(packet_processing_helpers::ApplyPacketOptions(
&rtp_packet[0], rtp_packet.size(), options, 0));
EXPECT_NE(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)],
kFakeTag, sizeof(kFakeTag)));
EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg],
kTestAstValue, sizeof(kTestAstValue)));
}
TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionInRtpPacket) {
EXPECT_TRUE(packet_processing_helpers::UpdateRtpAbsSendTimeExtn(
reinterpret_cast<char*>(kRtpMsgWithAbsSendTimeExtension),
sizeof(kRtpMsgWithAbsSendTimeExtension), 3, 0));
}
TEST(P2PSocketHostTest, TestApplyPacketOptionsWithAuthParamsAndAbsSendTime) {
talk_base::PacketOptions options;
options.packet_time_params.srtp_auth_key.resize(20);
options.packet_time_params.srtp_auth_key.assign(
kTestKey, kTestKey + sizeof(kTestKey));
options.packet_time_params.srtp_auth_tag_len = 4;
options.packet_time_params.rtp_sendtime_extension_id = 3;
std::vector<char> rtp_packet;
rtp_packet.resize(sizeof(kRtpMsgWithAbsSendTimeExtension) + 4);
memcpy(&rtp_packet[0], kRtpMsgWithAbsSendTimeExtension,
sizeof(kRtpMsgWithAbsSendTimeExtension));
memcpy(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], kFakeTag, 4);
EXPECT_TRUE(packet_processing_helpers::ApplyPacketOptions(
&rtp_packet[0], rtp_packet.size(), options, 0xccbbaa));
EXPECT_NE(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)],
kFakeTag, sizeof(kFakeTag)));
unsigned char timestamp_array[3] = { 0xcc, 0xbb, 0xaa };
EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg],
timestamp_array, sizeof(timestamp_array)));
}
}