Chromium Code Reviews| 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 // Rtp message with invalid length. | |
| 16 static unsigned char kRtpMsgWithInvalidLength[] = { | |
| 17 0x94, 0x00, 0x00, 0x00, | |
| 18 0x00, 0x00, 0x00, 0x00, | |
| 19 0xAA, 0xBB, 0xCC, 0XDD, // SSRC | |
| 20 0xDD, 0xCC, 0xBB, 0xAA // Only 1 CSRC, but CC count is 4. | |
| 21 }; | |
| 22 | |
| 23 // Rtp message with single byte header extension, invalid extension length. | |
| 24 static unsigned char kRtpMessageWithInvalidExtnLength[] = { | |
| 25 0x90, 0x00, 0x00, 0x00, | |
| 26 0x00, 0x00, 0x00, 0x00, | |
| 27 0x00, 0x00, 0x00, 0x00, | |
| 28 0xBE, 0xDE, 0x0A, 0x00 // Extn length - 0x0A00 | |
| 29 }; | |
| 30 | |
| 31 // Valid rtp Message with 2 byte header extension. | |
| 32 static unsigned char kRtpMsgWith2ByteExtnHeader[] = { | |
| 33 0x90, 0x00, 0x00, 0x00, | |
| 34 0x00, 0x00, 0x00, 0x00, | |
| 35 0xAA, 0xBB, 0xCC, 0XDD, // SSRC | |
| 36 0x10, 0x00, 0x00, 0x01, // 2 Byte header extension | |
| 37 0x01, 0x00, 0x00, 0x00 | |
| 38 }; | |
| 39 | |
| 40 // Stun Indication message with Zero length | |
| 41 static unsigned char kTurnSendIndicationMsgWithNoAttributes[] = { | |
| 42 0x00, 0x16, 0x00, 0x00, // Zero length | |
| 43 0x21, 0x12, 0xA4, 0x42, // magic cookie | |
| 44 '0', '1', '2', '3', // transaction id | |
| 45 '4', '5', '6', '7', | |
| 46 '8', '9', 'a', 'b', | |
| 47 }; | |
| 48 | |
| 49 // Stun Send Indication message with invalid length in stun header. | |
| 50 static unsigned char kTurnSendIndicationMsgWithInvalidLength[] = { | |
| 51 0x00, 0x16, 0xFF, 0x00, // length of 0xFF00 | |
| 52 0x21, 0x12, 0xA4, 0x42, // magic cookie | |
| 53 '0', '1', '2', '3', // transaction id | |
| 54 '4', '5', '6', '7', | |
| 55 '8', '9', 'a', 'b', | |
| 56 }; | |
| 57 | |
| 58 // Stun Send Indication message with no DATA attribute in message. | |
| 59 static unsigned char kTurnSendIndicatinMsgWithNoDataAttribute[] = { | |
| 60 0x00, 0x16, 0x00, 0x08, // length of | |
| 61 0x21, 0x12, 0xA4, 0x42, // magic cookie | |
| 62 '0', '1', '2', '3', // transaction id | |
| 63 '4', '5', '6', '7', | |
| 64 '8', '9', 'a', 'b', | |
| 65 0x00, 0x20, 0x00, 0x04, // Mapped address. | |
| 66 0x00, 0x00, 0x00, 0x00 | |
| 67 }; | |
| 68 | |
| 69 // A valid STUN indication message with a valid RTP header in data attribute | |
| 70 // payload field and no extension bit set. | |
| 71 static unsigned char kTurnSendIndicationMsgWithoutRtpExtension[] = { | |
| 72 0x00, 0x16, 0x00, 0x18, // length of | |
| 73 0x21, 0x12, 0xA4, 0x42, // magic cookie | |
| 74 '0', '1', '2', '3', // transaction id | |
| 75 '4', '5', '6', '7', | |
| 76 '8', '9', 'a', 'b', | |
| 77 0x00, 0x20, 0x00, 0x04, // Mapped address. | |
| 78 0x00, 0x00, 0x00, 0x00, | |
| 79 0x00, 0x13, 0x00, 0x0C, // Data attribute. | |
| 80 0x80, 0x00, 0x00, 0x00, // RTP packet. | |
| 81 0x00, 0x00, 0x00, 0x00, | |
| 82 0x00, 0x00, 0x00, 0x00, | |
| 83 }; | |
| 84 | |
| 85 // A valid STUN indication message with a valid RTP header and a extension | |
| 86 // header. | |
| 87 static unsigned char kTurnSendIndicationMsgWithSendTimeExtension[] = { | |
| 88 0x00, 0x16, 0x00, 0x20, // length of | |
| 89 0x21, 0x12, 0xA4, 0x42, // magic cookie | |
| 90 '0', '1', '2', '3', // transaction id | |
| 91 '4', '5', '6', '7', | |
| 92 '8', '9', 'a', 'b', | |
| 93 0x00, 0x20, 0x00, 0x04, // Mapped address. | |
| 94 0x00, 0x00, 0x00, 0x00, | |
| 95 0x00, 0x13, 0x00, 0x14, // Data attribute. | |
| 96 0x90, 0x00, 0x00, 0x00, // RTP packet. | |
| 97 0x00, 0x00, 0x00, 0x00, | |
| 98 0x00, 0x00, 0x00, 0x00, | |
| 99 0xBE, 0xDE, 0x00, 0x01, | |
| 100 0x32, 0xaa, 0xbb, 0xcc, | |
| 101 }; | |
| 102 | |
| 103 // A valid TURN channel header, but not RTP packet. | |
| 104 static unsigned char kTurnChannelMessage[] = { | |
| 105 0x40, 0x00, 0x00, 0x04, | |
| 106 0xaa, 0xbb, 0xcc, 0xdd, | |
| 107 }; | |
| 108 | |
| 109 // Turn ChannelMessage with zero length of payload. | |
| 110 static unsigned char kTurnChannelMessageWithZeroLength[] = { | |
| 111 0x40, 0x00, 0x00, 0x00 | |
| 112 }; | |
| 113 | |
| 114 // RTP packet with single byte extension header of length 4 bytes. | |
| 115 // Extension id = 3 and length = 3 | |
| 116 static unsigned char kRtpPacketWithSendTimeExtension[] = { | |
| 117 0x90, 0x00, 0x00, 0x00, | |
| 118 0x00, 0x00, 0x00, 0x00, | |
| 119 0x00, 0x00, 0x00, 0x00, | |
| 120 0xBE, 0xDE, 0x00, 0x01, | |
| 121 0x32, 0xaa, 0xbb, 0xcc, | |
| 122 }; | |
| 123 | |
| 124 namespace content { | |
| 125 | |
| 126 // This test verifies parsing of all invalid packets. | |
| 127 TEST(P2PSocketHostTest, TestInvalidRtpMessages) { | |
|
Solis
2014/02/27 09:36:10
Consider breaking this multi-test into several sma
Mallinath (Gone from Chromium)
2014/02/27 19:43:10
Done.
| |
| 128 int start_pos, rtp_length; | |
| 129 EXPECT_FALSE(GetRtpPacketStartPositionAndLength( | |
| 130 reinterpret_cast<char*>(kRtpMsgWithInvalidLength), | |
|
Solis
2014/02/27 09:36:10
Why not change the interface of GetRtpPacketStartP
Mallinath (Gone from Chromium)
2014/02/27 19:43:10
The reason i kept char* because whole pipeline fro
| |
| 131 sizeof(kRtpMsgWithInvalidLength), | |
| 132 &start_pos, &rtp_length)); | |
|
Solis
2014/02/27 09:36:10
You should initialize start_pos and rtp_length to
Mallinath (Gone from Chromium)
2014/02/27 19:43:10
Done.
| |
| 133 | |
| 134 EXPECT_FALSE(GetRtpPacketStartPositionAndLength( | |
| 135 reinterpret_cast<char*>(kRtpMessageWithInvalidExtnLength), | |
| 136 sizeof(kRtpMessageWithInvalidExtnLength), | |
| 137 &start_pos, &rtp_length)); | |
| 138 | |
| 139 EXPECT_FALSE(GetRtpPacketStartPositionAndLength( | |
| 140 reinterpret_cast<char*>(kTurnSendIndicationMsgWithNoAttributes), | |
| 141 sizeof(kTurnSendIndicationMsgWithNoAttributes), | |
| 142 &start_pos, &rtp_length)); | |
| 143 | |
| 144 EXPECT_FALSE(GetRtpPacketStartPositionAndLength( | |
| 145 reinterpret_cast<char*>(kTurnSendIndicationMsgWithInvalidLength), | |
| 146 sizeof(kTurnSendIndicationMsgWithInvalidLength), | |
| 147 &start_pos, &rtp_length)); | |
| 148 | |
| 149 EXPECT_FALSE(GetRtpPacketStartPositionAndLength( | |
| 150 reinterpret_cast<char*>(kTurnSendIndicatinMsgWithNoDataAttribute), | |
| 151 sizeof(kTurnSendIndicatinMsgWithNoDataAttribute), | |
| 152 &start_pos, &rtp_length)); | |
| 153 | |
| 154 EXPECT_FALSE(GetRtpPacketStartPositionAndLength( | |
| 155 reinterpret_cast<char*>(kTurnChannelMessage), | |
| 156 sizeof(kTurnChannelMessage), | |
| 157 &start_pos, &rtp_length)); | |
| 158 | |
| 159 EXPECT_FALSE(GetRtpPacketStartPositionAndLength( | |
| 160 reinterpret_cast<char*>(kTurnChannelMessageWithZeroLength), | |
| 161 sizeof(kTurnChannelMessageWithZeroLength), | |
| 162 &start_pos, &rtp_length)); | |
| 163 } | |
| 164 | |
| 165 // This test verifies seraching of RTP exension ID supplied as input in a | |
| 166 // RTP packet. If it finds it will be update the the timestamp. | |
| 167 TEST(P2PSocketHostTest, TestUpdateRtpAbsSendTimeExtension) { | |
|
Solis
2014/02/27 09:36:10
Likewise, consider splitting up.
| |
| 168 int start_pos, rtp_length; | |
|
Solis
2014/02/27 09:36:10
initialize these
| |
| 169 EXPECT_TRUE(GetRtpPacketStartPositionAndLength( | |
| 170 reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader), | |
| 171 sizeof(kRtpMsgWith2ByteExtnHeader), | |
| 172 &start_pos, &rtp_length)); | |
| 173 EXPECT_EQ(20, rtp_length); | |
| 174 EXPECT_EQ(0, start_pos); | |
| 175 | |
| 176 EXPECT_FALSE(MaybeUpdateRtpAbsSendTimeExtn( | |
| 177 reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader), | |
| 178 sizeof(kRtpMsgWith2ByteExtnHeader), 3)); | |
| 179 | |
| 180 EXPECT_TRUE(GetRtpPacketStartPositionAndLength( | |
| 181 reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension), | |
| 182 sizeof(kTurnSendIndicationMsgWithoutRtpExtension), | |
| 183 &start_pos, &rtp_length)); | |
| 184 EXPECT_EQ(12, rtp_length); | |
| 185 EXPECT_EQ(32, start_pos); | |
| 186 | |
| 187 EXPECT_TRUE(MaybeUpdateRtpAbsSendTimeExtn( | |
| 188 reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension), | |
| 189 sizeof(kTurnSendIndicationMsgWithoutRtpExtension), 3)); | |
| 190 | |
| 191 EXPECT_TRUE(GetRtpPacketStartPositionAndLength( | |
| 192 reinterpret_cast<char*>(kTurnSendIndicationMsgWithSendTimeExtension), | |
| 193 sizeof(kTurnSendIndicationMsgWithSendTimeExtension), | |
| 194 &start_pos, &rtp_length)); | |
| 195 EXPECT_EQ(20, rtp_length); | |
| 196 EXPECT_EQ(32, start_pos); | |
| 197 | |
| 198 EXPECT_TRUE(MaybeUpdateRtpAbsSendTimeExtn( | |
| 199 reinterpret_cast<char*>(kTurnSendIndicationMsgWithSendTimeExtension), | |
| 200 sizeof(kTurnSendIndicationMsgWithSendTimeExtension), 3)); | |
| 201 | |
| 202 EXPECT_TRUE(GetRtpPacketStartPositionAndLength( | |
| 203 reinterpret_cast<char*>(kRtpPacketWithSendTimeExtension), | |
| 204 sizeof(kRtpPacketWithSendTimeExtension), | |
| 205 &start_pos, &rtp_length)); | |
| 206 EXPECT_EQ(20, rtp_length); | |
| 207 EXPECT_EQ(0, start_pos); | |
| 208 | |
| 209 EXPECT_TRUE(MaybeUpdateRtpAbsSendTimeExtn( | |
| 210 reinterpret_cast<char*>(kRtpPacketWithSendTimeExtension), | |
| 211 sizeof(kRtpPacketWithSendTimeExtension), 3)); | |
| 212 } | |
| 213 | |
| 214 } // namespace content | |
| OLD | NEW |