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..31441a801a818d71fff31c3d985dc57e1cefca08 |
--- /dev/null |
+++ b/content/browser/renderer_host/p2p/socket_host_unittest.cc |
@@ -0,0 +1,95 @@ |
+// 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" |
+ |
+namespace content { |
+ |
+class P2PSocketHostForTest : public P2PSocketHost { |
+ public: |
+ P2PSocketHostForTest(IPC::Sender* message_sender, int id) |
+ : P2PSocketHost(message_sender, id) {} |
+ virtual ~P2PSocketHostForTest() {} |
+ |
+ virtual bool Init(const net::IPEndPoint& local_address, |
+ const net::IPEndPoint& remote_address) OVERRIDE { |
+ return true; |
+ } |
+ |
+ virtual void Send(const net::IPEndPoint& to, |
+ const std::vector<char>& data, |
+ const talk_base::PacketOptions& options, |
+ uint64 packet_id) OVERRIDE { |
+ } |
+ |
+ virtual P2PSocketHost* AcceptIncomingTcpConnection( |
+ const net::IPEndPoint& remote_address, int id) OVERRIDE { |
+ return NULL; |
+ } |
+ |
+ virtual bool SetOption(P2PSocketOption option, int value) OVERRIDE { |
+ return true; |
+ } |
+ |
+ using P2PSocketHost::MaybeUpdateRtpSendTimeExtn; |
+ using P2PSocketHost::GetRtpPacketStartPositionAndLength; |
+ using P2PSocketHost::UpdateSendTimeExtnValue; |
+ using P2PSocketHost::MaybeUpdateRtpAuthTag; |
+}; |
+ |
+class P2PSocketHostTest : public testing::Test { |
+ public: |
+ virtual void SetUp() OVERRIDE { |
+ socket_host_.reset(new P2PSocketHostForTest(&sender_, 0)); |
+ } |
+ |
+ MockIPCSender sender_; |
+ scoped_ptr<P2PSocketHostForTest> socket_host_; |
+}; |
+ |
+// Verify parsing of a TURN ChannelMessage and TURN SEND indication. |
+TEST_F(P2PSocketHostTest, TestGetRtpPacketStartPositionAndLength) { |
+ int start_pos, rtp_length; |
+ std::vector<char> rtp_packet; |
+ CreateRtpPacket(&rtp_packet); |
+ EXPECT_TRUE(socket_host_->GetRtpPacketStartPositionAndLength( |
+ &rtp_packet[0], rtp_packet.size(), &start_pos, &rtp_length)); |
+ EXPECT_EQ(0, start_pos); |
+ |
+ // Test against a STUN packet. |
+ std::vector<char> stun_packet; |
+ CreateStunRequest(&stun_packet); |
+ EXPECT_FALSE(socket_host_->GetRtpPacketStartPositionAndLength( |
+ &stun_packet[0], stun_packet.size(), &start_pos, &rtp_length)); |
+ |
+ // Test rtp packet wrapped in a turn channel message. |
+ std::vector<char> turn_channel_packet; |
+ CreateTurnChannelData(&turn_channel_packet); |
+ EXPECT_TRUE(socket_host_->GetRtpPacketStartPositionAndLength( |
+ &turn_channel_packet[0], turn_channel_packet.size(), |
+ &start_pos, &rtp_length)); |
+ EXPECT_EQ(4, start_pos); |
+ |
+ // TODO(mallinath) - Add turn send indication. |
+} |
+ |
+// Verify parsing of a RTP packet and extensions. |
+TEST_F(P2PSocketHostTest, TestUpdateRtpAbsSendTimeExtension) { |
+ std::vector<char> rtp_packet; |
+ CreateRtpPacketWithSendtimeExtension(&rtp_packet, 3); |
+ EXPECT_TRUE(socket_host_->MaybeUpdateRtpSendTimeExtn( |
+ &rtp_packet[0], rtp_packet.size(), 3)); |
+ EXPECT_FALSE(socket_host_->MaybeUpdateRtpSendTimeExtn( |
+ &rtp_packet[0], rtp_packet.size(), 1)); |
+} |
+ |
+} // namespace content |