Index: content/browser/renderer_host/p2p/socket_host_unittest.cc |
diff --git a/content/browser/renderer_host/p2p/socket_host_unittest.cc b/content/browser/renderer_host/p2p/socket_host_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bdcc1cb78c6c9b979cec67e72e8d7caf841f2e76 |
--- /dev/null |
+++ b/content/browser/renderer_host/p2p/socket_host_unittest.cc |
@@ -0,0 +1,339 @@ |
+// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#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" |
+ |
+// Rtp message with invalid length. |
+static unsigned char kRtpMsgWithInvalidLength[] = { |
+ 0x94, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0xAA, 0xBB, 0xCC, 0XDD, // SSRC |
+ 0xDD, 0xCC, 0xBB, 0xAA // Only 1 CSRC, but CC count is 4. |
+}; |
+ |
+// Rtp message with single byte header extension, invalid extension length. |
+static unsigned char kRtpMessageWithInvalidExtnLength[] = { |
Solis
2014/03/03 10:22:29
Stick to either Msg or Message.
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
Done.
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
Sticking to Msg
On 2014/03/03 10:22:29, Solis wro
|
+ 0x90, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0xBE, 0xDE, 0x0A, 0x00 // Extn length - 0x0A00 |
+}; |
+ |
+// Valid rtp Message with 2 byte header extension. |
+static unsigned char kRtpMsgWith2ByteExtnHeader[] = { |
+ 0x90, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0xAA, 0xBB, 0xCC, 0XDD, // SSRC |
+ 0x10, 0x00, 0x00, 0x01, // 2 Byte header extension |
+ 0x01, 0x00, 0x00, 0x00 |
+}; |
+ |
+// Stun Indication message with Zero length |
+static unsigned char kTurnSendIndicationMsgWithNoAttributes[] = { |
+ 0x00, 0x16, 0x00, 0x00, // Zero length |
+ 0x21, 0x12, 0xA4, 0x42, // magic cookie |
+ '0', '1', '2', '3', // transaction id |
+ '4', '5', '6', '7', |
+ '8', '9', 'a', 'b', |
+}; |
+ |
+// Stun Send Indication message with invalid length in stun header. |
+static unsigned char kTurnSendIndicationMsgWithInvalidLength[] = { |
+ 0x00, 0x16, 0xFF, 0x00, // length of 0xFF00 |
+ 0x21, 0x12, 0xA4, 0x42, // magic cookie |
+ '0', '1', '2', '3', // transaction id |
+ '4', '5', '6', '7', |
+ '8', '9', 'a', 'b', |
+}; |
+ |
+// Stun Send Indication message with no DATA attribute in message. |
+static unsigned char kTurnSendIndicatinMsgWithNoDataAttribute[] = { |
+ 0x00, 0x16, 0x00, 0x08, // length of |
+ 0x21, 0x12, 0xA4, 0x42, // magic cookie |
+ '0', '1', '2', '3', // transaction id |
+ '4', '5', '6', '7', |
+ '8', '9', 'a', 'b', |
+ 0x00, 0x20, 0x00, 0x04, // Mapped address. |
+ 0x00, 0x00, 0x00, 0x00 |
+}; |
+ |
+// A valid STUN indication message with a valid RTP header in data attribute |
+// payload field and no extension bit set. |
+static unsigned char kTurnSendIndicationMsgWithoutRtpExtension[] = { |
+ 0x00, 0x16, 0x00, 0x18, // length of |
+ 0x21, 0x12, 0xA4, 0x42, // magic cookie |
+ '0', '1', '2', '3', // transaction id |
+ '4', '5', '6', '7', |
+ '8', '9', 'a', 'b', |
+ 0x00, 0x20, 0x00, 0x04, // Mapped address. |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x13, 0x00, 0x0C, // Data attribute. |
+ 0x80, 0x00, 0x00, 0x00, // RTP packet. |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, |
+}; |
+ |
+// A valid STUN indication message with a valid RTP header and a extension |
+// header. |
+static unsigned char kTurnSendIndicationMsgWithAbsSendTimeExtension[] = { |
+ 0x00, 0x16, 0x00, 0x20, // length of |
+ 0x21, 0x12, 0xA4, 0x42, // magic cookie |
+ '0', '1', '2', '3', // transaction id |
+ '4', '5', '6', '7', |
+ '8', '9', 'a', 'b', |
+ 0x00, 0x20, 0x00, 0x04, // Mapped address. |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x13, 0x00, 0x14, // Data attribute. |
+ 0x90, 0x00, 0x00, 0x00, // RTP packet. |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0xBE, 0xDE, 0x00, 0x01, |
+ 0x32, 0xaa, 0xbb, 0xcc, |
+}; |
+ |
+// A valid TURN channel header, but not RTP packet. |
+static unsigned char kTurnChannelMessageNoRtpPacket[] = { |
+ 0x40, 0x00, 0x00, 0x04, |
+ 0xaa, 0xbb, 0xcc, 0xdd, |
+}; |
+ |
+// Turn ChannelMessage with zero length of payload. |
+static unsigned char kTurnChannelMessageWithZeroLength[] = { |
+ 0x40, 0x00, 0x00, 0x00 |
+}; |
+ |
+// Turn ChannelMessage, wrapping a RTP packet without extension. |
+static unsigned char kTurnChannelMessageWithRtpPacket[] = { |
+ 0x40, 0x00, 0x00, 0x0C, |
+ 0x80, 0x00, 0x00, 0x00, // RTP packet. |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, |
+}; |
+ |
+// Turn ChannelMessage, wrapping a RTP packet with AbsSendTime Extension. |
+static unsigned char kTurnChannelMessageWithAbsSendTimeExtension[] = { |
+ 0x40, 0x00, 0x00, 0x14, |
+ 0x90, 0x00, 0x00, 0x00, // RTP packet. |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0xBE, 0xDE, 0x00, 0x01, |
+ 0x32, 0xaa, 0xbb, 0xcc, |
+}; |
+ |
+// RTP packet with single byte extension header of length 4 bytes. |
+// Extension id = 3 and length = 3 |
+static unsigned char kRtpPacketWithAbsSendTimeExtension[] = { |
+ 0x90, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, |
+ 0xBE, 0xDE, 0x00, 0x01, |
+ 0x32, 0xaa, 0xbb, 0xcc, |
+}; |
+ |
+namespace content { |
+ |
+// This test verifies parsing of all invalid raw packets. |
+TEST(P2PSocketHostTest, TestInvalidRawRtpMessages) { |
+ int start_pos = -1, rtp_length = -1; |
+ EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
+ reinterpret_cast<char*>(kRtpMsgWithInvalidLength), |
+ sizeof(kRtpMsgWithInvalidLength), |
+ &start_pos, &rtp_length)); |
+ EXPECT_EQ(-1, start_pos); |
+ EXPECT_EQ(-1, rtp_length); |
+ |
+ EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
+ reinterpret_cast<char*>(kRtpMessageWithInvalidExtnLength), |
+ sizeof(kRtpMessageWithInvalidExtnLength), |
+ &start_pos, &rtp_length)); |
+ EXPECT_EQ(-1, start_pos); |
+ EXPECT_EQ(-1, rtp_length); |
+} |
+ |
+// Verify invalid TURN send indication messages. Messages are proper STUN |
+// messages with incorrect values in attributes. |
+TEST(P2PSocketHostTest, TestInvalidTurnSendIndicationMessages) { |
+ int start_pos = -1, rtp_length = -1; |
+ EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
+ reinterpret_cast<char*>(kTurnSendIndicationMsgWithNoAttributes), |
+ sizeof(kTurnSendIndicationMsgWithNoAttributes), |
+ &start_pos, &rtp_length)); |
+ EXPECT_EQ(-1, start_pos); |
+ EXPECT_EQ(-1, rtp_length); |
+ |
+ EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
+ reinterpret_cast<char*>(kTurnSendIndicationMsgWithInvalidLength), |
+ sizeof(kTurnSendIndicationMsgWithInvalidLength), |
+ &start_pos, &rtp_length)); |
+ EXPECT_EQ(-1, start_pos); |
+ EXPECT_EQ(-1, rtp_length); |
+ |
+ EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
+ reinterpret_cast<char*>(kTurnSendIndicatinMsgWithNoDataAttribute), |
+ sizeof(kTurnSendIndicatinMsgWithNoDataAttribute), |
+ &start_pos, &rtp_length)); |
+ EXPECT_EQ(-1, start_pos); |
+ EXPECT_EQ(-1, rtp_length); |
+ |
+ // Initializing out params to very large value. |
Solis
2014/03/03 10:22:29
You should only need one test per message. Pick a
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
Done.
|
+ 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); |
+} |
+ |
+// This test verifies incorrectly formed TURN channel messages. |
+TEST(P2PSocketHostTest, TestInvalidTurnChannelMessages) { |
+ int start_pos = -1, rtp_length = -1; |
+ EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
+ reinterpret_cast<char*>(kTurnChannelMessageNoRtpPacket), |
+ sizeof(kTurnChannelMessageNoRtpPacket), |
+ &start_pos, &rtp_length)); |
+ |
Solis
2014/03/03 10:22:29
EXPECT_EQ(-1, ...) here as well
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
Done.
|
+ EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
+ reinterpret_cast<char*>(kTurnChannelMessageWithZeroLength), |
+ sizeof(kTurnChannelMessageWithZeroLength), |
+ &start_pos, &rtp_length)); |
+} |
+ |
+// This test verifies parsing of a valid RTP packet which has 2byte header |
+// extension instead of a 1 byte header extension. |
+TEST(P2PSocketHostTest, TestValid2ByteExtnHdrRtpMessage) { |
+ int start_pos = -1, rtp_length = -1; |
+ 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); |
+} |
+ |
+// This test verifies parsing of a valid RTP packet which has 1 byte header |
+// AbsSendTime extension in it. |
+TEST(P2PSocketHostTest, TestValidRtpPacketWithAbsSendTimeExtension) { |
+ int start_pos = -1, rtp_length = -1; |
+ EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
+ reinterpret_cast<char*>(kRtpPacketWithAbsSendTimeExtension), |
Solis
2014/03/03 10:22:29
Why is this in a separate test case here, and anot
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
It was by mistake.
On 2014/03/03 10:22:29, Solis
|
+ sizeof(kRtpPacketWithAbsSendTimeExtension), |
+ &start_pos, &rtp_length)); |
+ EXPECT_EQ(20, rtp_length); |
+ EXPECT_EQ(0, start_pos); |
+} |
+ |
+// This test verifies parsing of a valid TURN Send Indication messages. |
+TEST(P2PSocketHostTest, TestValidTurnSendIndicationMessages) { |
+ int start_pos = -1, rtp_length = -1; |
+ 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 = -1, rtp_length = -1; |
+ EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
+ reinterpret_cast<char*>(kTurnSendIndicationMsgWithAbsSendTimeExtension), |
+ sizeof(kTurnSendIndicationMsgWithAbsSendTimeExtension), |
+ &start_pos, &rtp_length)); |
+ EXPECT_EQ(20, rtp_length); |
+ EXPECT_EQ(32, start_pos); |
+ |
+ // Initializing out params to very large value. |
+ 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(20, rtp_length); |
+ EXPECT_EQ(32, start_pos); |
+ |
+ start_pos = INT_MAX, rtp_length = INT_MAX; |
+ EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
+ reinterpret_cast<char*>(kRtpPacketWithAbsSendTimeExtension), |
+ sizeof(kRtpPacketWithAbsSendTimeExtension), |
+ &start_pos, &rtp_length)); |
+ EXPECT_EQ(20, rtp_length); |
+ EXPECT_EQ(0, start_pos); |
+} |
+ |
+// This test verifies parsing of valid TURN Channel Messages. |
+TEST(P2PSocketHostTest, TestValidTurnChannelMessages) { |
+ int start_pos = -1, rtp_length = -1; |
+ EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
+ reinterpret_cast<char*>(kTurnChannelMessageWithRtpPacket), |
+ sizeof(kTurnChannelMessageWithRtpPacket), &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*>(kTurnChannelMessageWithAbsSendTimeExtension), |
+ sizeof(kTurnChannelMessageWithAbsSendTimeExtension), |
+ &start_pos, &rtp_length)); |
+ EXPECT_EQ(20, rtp_length); |
+ EXPECT_EQ(4, start_pos); |
+} |
+ |
+// This test verifies seraching of RTP exension ID supplied as input in a |
Solis
2014/03/03 10:22:29
spelling
it looks to me the comment is wrong btw.
Mallinath (Gone from Chromium)
2014/03/04 00:15:46
Done.
|
+// RTP packet. If it finds it will be update the the timestamp. |
+TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionIn2ByteHeaderExtn) { |
+ EXPECT_FALSE(packet_processing_helpers::MaybeUpdateRtpAbsSendTimeExtn( |
+ reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader), |
+ sizeof(kRtpMsgWith2ByteExtnHeader), 3)); |
+} |
+ |
+// This test verifies updating AbsSendTime extension in a Turn Send Indication |
+// message. |
+TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionInTurnSendIndication) { |
+ EXPECT_TRUE(packet_processing_helpers::MaybeUpdateRtpAbsSendTimeExtn( |
+ reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension), |
+ sizeof(kTurnSendIndicationMsgWithoutRtpExtension), 3)); |
+ |
+ EXPECT_TRUE(packet_processing_helpers::MaybeUpdateRtpAbsSendTimeExtn( |
+ reinterpret_cast<char*>(kTurnSendIndicationMsgWithAbsSendTimeExtension), |
+ sizeof(kTurnSendIndicationMsgWithAbsSendTimeExtension), 3)); |
+} |
+ |
+// This test verifies updating AbsSendTime extension in a raw rtp message. |
+TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionInRtpPacket) { |
+ EXPECT_TRUE(packet_processing_helpers::MaybeUpdateRtpAbsSendTimeExtn( |
+ reinterpret_cast<char*>(kRtpPacketWithAbsSendTimeExtension), |
+ sizeof(kRtpPacketWithAbsSendTimeExtension), 3)); |
+} |
+ |
+} // namespace content |