OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 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. |
| 4 |
| 5 #include "content/browser/renderer_host/p2p/socket_host.h" |
| 6 |
| 7 #include <vector> |
| 8 |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" |
| 11 #include "net/base/ip_endpoint.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 namespace content { |
| 16 |
| 17 class P2PSocketHostForTest : public P2PSocketHost { |
| 18 public: |
| 19 P2PSocketHostForTest(IPC::Sender* message_sender, int id) |
| 20 : P2PSocketHost(message_sender, id) {} |
| 21 virtual ~P2PSocketHostForTest() {} |
| 22 |
| 23 virtual bool Init(const net::IPEndPoint& local_address, |
| 24 const net::IPEndPoint& remote_address) OVERRIDE { |
| 25 return true; |
| 26 } |
| 27 |
| 28 virtual void Send(const net::IPEndPoint& to, |
| 29 const std::vector<char>& data, |
| 30 const talk_base::PacketOptions& options, |
| 31 uint64 packet_id) OVERRIDE { |
| 32 } |
| 33 |
| 34 virtual P2PSocketHost* AcceptIncomingTcpConnection( |
| 35 const net::IPEndPoint& remote_address, int id) OVERRIDE { |
| 36 return NULL; |
| 37 } |
| 38 |
| 39 virtual bool SetOption(P2PSocketOption option, int value) OVERRIDE { |
| 40 return true; |
| 41 } |
| 42 |
| 43 using P2PSocketHost::MaybeUpdateRtpSendTimeExtn; |
| 44 using P2PSocketHost::GetRtpPacketStartPositionAndLength; |
| 45 using P2PSocketHost::UpdateSendTimeExtnValue; |
| 46 using P2PSocketHost::MaybeUpdateRtpAuthTag; |
| 47 }; |
| 48 |
| 49 class P2PSocketHostTest : public testing::Test { |
| 50 public: |
| 51 virtual void SetUp() OVERRIDE { |
| 52 socket_host_.reset(new P2PSocketHostForTest(&sender_, 0)); |
| 53 } |
| 54 |
| 55 MockIPCSender sender_; |
| 56 scoped_ptr<P2PSocketHostForTest> socket_host_; |
| 57 }; |
| 58 |
| 59 // Verify parsing of a TURN ChannelMessage and TURN SEND indication. |
| 60 TEST_F(P2PSocketHostTest, TestGetRtpPacketStartPositionAndLength) { |
| 61 int start_pos, rtp_length; |
| 62 std::vector<char> rtp_packet; |
| 63 CreateRtpPacket(&rtp_packet); |
| 64 EXPECT_TRUE(socket_host_->GetRtpPacketStartPositionAndLength( |
| 65 &rtp_packet[0], rtp_packet.size(), &start_pos, &rtp_length)); |
| 66 EXPECT_EQ(0, start_pos); |
| 67 |
| 68 // Test against a STUN packet. |
| 69 std::vector<char> stun_packet; |
| 70 CreateStunRequest(&stun_packet); |
| 71 EXPECT_FALSE(socket_host_->GetRtpPacketStartPositionAndLength( |
| 72 &stun_packet[0], stun_packet.size(), &start_pos, &rtp_length)); |
| 73 |
| 74 // Test rtp packet wrapped in a turn channel message. |
| 75 std::vector<char> turn_channel_packet; |
| 76 CreateTurnChannelData(&turn_channel_packet); |
| 77 EXPECT_TRUE(socket_host_->GetRtpPacketStartPositionAndLength( |
| 78 &turn_channel_packet[0], turn_channel_packet.size(), |
| 79 &start_pos, &rtp_length)); |
| 80 EXPECT_EQ(4, start_pos); |
| 81 |
| 82 // TODO(mallinath) - Add turn send indication. |
| 83 } |
| 84 |
| 85 // Verify parsing of a RTP packet and extensions. |
| 86 TEST_F(P2PSocketHostTest, TestUpdateRtpAbsSendTimeExtension) { |
| 87 std::vector<char> rtp_packet; |
| 88 CreateRtpPacketWithSendtimeExtension(&rtp_packet, 3); |
| 89 EXPECT_TRUE(socket_host_->MaybeUpdateRtpSendTimeExtn( |
| 90 &rtp_packet[0], rtp_packet.size(), 3)); |
| 91 EXPECT_FALSE(socket_host_->MaybeUpdateRtpSendTimeExtn( |
| 92 &rtp_packet[0], rtp_packet.size(), 1)); |
| 93 } |
| 94 |
| 95 } // namespace content |
OLD | NEW |