| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/p2p/socket_host.h" | 5 #include "content/browser/renderer_host/p2p/socket_host.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" | 10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 0x32, 0xaa, 0xbb, 0xcc, | 145 0x32, 0xaa, 0xbb, 0xcc, |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 // Index of AbsSendTimeExtn data in message |kRtpMsgWithAbsSendTimeExtension|. | 148 // Index of AbsSendTimeExtn data in message |kRtpMsgWithAbsSendTimeExtension|. |
| 149 static const int kAstIndexInRtpMsg = 21; | 149 static const int kAstIndexInRtpMsg = 21; |
| 150 | 150 |
| 151 namespace content { | 151 namespace content { |
| 152 | 152 |
| 153 // This test verifies parsing of all invalid raw packets. | 153 // This test verifies parsing of all invalid raw packets. |
| 154 TEST(P2PSocketHostTest, TestInvalidRawRtpMessages) { | 154 TEST(P2PSocketHostTest, TestInvalidRawRtpMessages) { |
| 155 int start_pos = INT_MAX, rtp_length = INT_MAX; | 155 size_t start_pos = SIZE_MAX, rtp_length = SIZE_MAX; |
| 156 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 156 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 157 reinterpret_cast<char*>(kRtpMsgWithInvalidLength), | 157 reinterpret_cast<char*>(kRtpMsgWithInvalidLength), |
| 158 sizeof(kRtpMsgWithInvalidLength), | 158 sizeof(kRtpMsgWithInvalidLength), |
| 159 &start_pos, &rtp_length)); | 159 &start_pos, &rtp_length)); |
| 160 EXPECT_EQ(INT_MAX, start_pos); | 160 EXPECT_EQ(SIZE_MAX, start_pos); |
| 161 EXPECT_EQ(INT_MAX, rtp_length); | 161 EXPECT_EQ(SIZE_MAX, rtp_length); |
| 162 | 162 |
| 163 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 163 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 164 reinterpret_cast<char*>(kRtpMsgWithInvalidExtnLength), | 164 reinterpret_cast<char*>(kRtpMsgWithInvalidExtnLength), |
| 165 sizeof(kRtpMsgWithInvalidExtnLength), | 165 sizeof(kRtpMsgWithInvalidExtnLength), |
| 166 &start_pos, &rtp_length)); | 166 &start_pos, &rtp_length)); |
| 167 EXPECT_EQ(INT_MAX, start_pos); | 167 EXPECT_EQ(SIZE_MAX, start_pos); |
| 168 EXPECT_EQ(INT_MAX, rtp_length); | 168 EXPECT_EQ(SIZE_MAX, rtp_length); |
| 169 } | 169 } |
| 170 | 170 |
| 171 // Verify invalid TURN send indication messages. Messages are proper STUN | 171 // Verify invalid TURN send indication messages. Messages are proper STUN |
| 172 // messages with incorrect values in attributes. | 172 // messages with incorrect values in attributes. |
| 173 TEST(P2PSocketHostTest, TestInvalidTurnSendIndicationMessages) { | 173 TEST(P2PSocketHostTest, TestInvalidTurnSendIndicationMessages) { |
| 174 // Initializing out params to very large value. | 174 // Initializing out params to very large value. |
| 175 int start_pos = INT_MAX, rtp_length = INT_MAX; | 175 size_t start_pos = SIZE_MAX, rtp_length = SIZE_MAX; |
| 176 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 176 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 177 reinterpret_cast<char*>(kTurnSendIndicationMsgWithNoAttributes), | 177 reinterpret_cast<char*>(kTurnSendIndicationMsgWithNoAttributes), |
| 178 sizeof(kTurnSendIndicationMsgWithNoAttributes), | 178 sizeof(kTurnSendIndicationMsgWithNoAttributes), |
| 179 &start_pos, &rtp_length)); | 179 &start_pos, &rtp_length)); |
| 180 EXPECT_EQ(INT_MAX, start_pos); | 180 EXPECT_EQ(SIZE_MAX, start_pos); |
| 181 EXPECT_EQ(INT_MAX, rtp_length); | 181 EXPECT_EQ(SIZE_MAX, rtp_length); |
| 182 | 182 |
| 183 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 183 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 184 reinterpret_cast<char*>(kTurnSendIndicationMsgWithInvalidLength), | 184 reinterpret_cast<char*>(kTurnSendIndicationMsgWithInvalidLength), |
| 185 sizeof(kTurnSendIndicationMsgWithInvalidLength), | 185 sizeof(kTurnSendIndicationMsgWithInvalidLength), |
| 186 &start_pos, &rtp_length)); | 186 &start_pos, &rtp_length)); |
| 187 EXPECT_EQ(INT_MAX, start_pos); | 187 EXPECT_EQ(SIZE_MAX, start_pos); |
| 188 EXPECT_EQ(INT_MAX, rtp_length); | 188 EXPECT_EQ(SIZE_MAX, rtp_length); |
| 189 | 189 |
| 190 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 190 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 191 reinterpret_cast<char*>(kTurnSendIndicatinMsgWithNoDataAttribute), | 191 reinterpret_cast<char*>(kTurnSendIndicatinMsgWithNoDataAttribute), |
| 192 sizeof(kTurnSendIndicatinMsgWithNoDataAttribute), | 192 sizeof(kTurnSendIndicatinMsgWithNoDataAttribute), |
| 193 &start_pos, &rtp_length)); | 193 &start_pos, &rtp_length)); |
| 194 EXPECT_EQ(INT_MAX, start_pos); | 194 EXPECT_EQ(SIZE_MAX, start_pos); |
| 195 EXPECT_EQ(INT_MAX, rtp_length); | 195 EXPECT_EQ(SIZE_MAX, rtp_length); |
| 196 } | 196 } |
| 197 | 197 |
| 198 // This test verifies incorrectly formed TURN channel messages. | 198 // This test verifies incorrectly formed TURN channel messages. |
| 199 TEST(P2PSocketHostTest, TestInvalidTurnChannelMessages) { | 199 TEST(P2PSocketHostTest, TestInvalidTurnChannelMessages) { |
| 200 int start_pos = INT_MAX, rtp_length = INT_MAX; | 200 size_t start_pos = SIZE_MAX, rtp_length = SIZE_MAX; |
| 201 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 201 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 202 reinterpret_cast<char*>(kTurnChannelMsgNoRtpPacket), | 202 reinterpret_cast<char*>(kTurnChannelMsgNoRtpPacket), |
| 203 sizeof(kTurnChannelMsgNoRtpPacket), | 203 sizeof(kTurnChannelMsgNoRtpPacket), |
| 204 &start_pos, &rtp_length)); | 204 &start_pos, &rtp_length)); |
| 205 EXPECT_EQ(INT_MAX, start_pos); | 205 EXPECT_EQ(SIZE_MAX, start_pos); |
| 206 EXPECT_EQ(INT_MAX, rtp_length); | 206 EXPECT_EQ(SIZE_MAX, rtp_length); |
| 207 | 207 |
| 208 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 208 EXPECT_FALSE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 209 reinterpret_cast<char*>(kTurnChannelMsgWithZeroLength), | 209 reinterpret_cast<char*>(kTurnChannelMsgWithZeroLength), |
| 210 sizeof(kTurnChannelMsgWithZeroLength), | 210 sizeof(kTurnChannelMsgWithZeroLength), |
| 211 &start_pos, &rtp_length)); | 211 &start_pos, &rtp_length)); |
| 212 EXPECT_EQ(INT_MAX, start_pos); | 212 EXPECT_EQ(SIZE_MAX, start_pos); |
| 213 EXPECT_EQ(INT_MAX, rtp_length); | 213 EXPECT_EQ(SIZE_MAX, rtp_length); |
| 214 } | 214 } |
| 215 | 215 |
| 216 // This test verifies parsing of a valid RTP packet which has 2byte header | 216 // This test verifies parsing of a valid RTP packet which has 2byte header |
| 217 // extension instead of a 1 byte header extension. | 217 // extension instead of a 1 byte header extension. |
| 218 TEST(P2PSocketHostTest, TestValid2ByteExtnHdrRtpMessage) { | 218 TEST(P2PSocketHostTest, TestValid2ByteExtnHdrRtpMessage) { |
| 219 int start_pos = INT_MAX, rtp_length = INT_MAX; | 219 size_t start_pos = SIZE_MAX, rtp_length = SIZE_MAX; |
| 220 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 220 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 221 reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader), | 221 reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader), |
| 222 sizeof(kRtpMsgWith2ByteExtnHeader), | 222 sizeof(kRtpMsgWith2ByteExtnHeader), |
| 223 &start_pos, &rtp_length)); | 223 &start_pos, &rtp_length)); |
| 224 EXPECT_EQ(20, rtp_length); | 224 EXPECT_EQ(20U, rtp_length); |
| 225 EXPECT_EQ(0, start_pos); | 225 EXPECT_EQ(0U, start_pos); |
| 226 } | 226 } |
| 227 | 227 |
| 228 // This test verifies parsing of a valid RTP packet which has 1 byte header | 228 // This test verifies parsing of a valid RTP packet which has 1 byte header |
| 229 // AbsSendTime extension in it. | 229 // AbsSendTime extension in it. |
| 230 TEST(P2PSocketHostTest, TestValidRtpPacketWithAbsSendTimeExtension) { | 230 TEST(P2PSocketHostTest, TestValidRtpPacketWithAbsSendTimeExtension) { |
| 231 int start_pos = INT_MAX, rtp_length = INT_MAX; | 231 size_t start_pos = SIZE_MAX, rtp_length = SIZE_MAX; |
| 232 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 232 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 233 reinterpret_cast<char*>(kRtpMsgWithAbsSendTimeExtension), | 233 reinterpret_cast<char*>(kRtpMsgWithAbsSendTimeExtension), |
| 234 sizeof(kRtpMsgWithAbsSendTimeExtension), | 234 sizeof(kRtpMsgWithAbsSendTimeExtension), |
| 235 &start_pos, &rtp_length)); | 235 &start_pos, &rtp_length)); |
| 236 EXPECT_EQ(24, rtp_length); | 236 EXPECT_EQ(24U, rtp_length); |
| 237 EXPECT_EQ(0, start_pos); | 237 EXPECT_EQ(0U, start_pos); |
| 238 } | 238 } |
| 239 | 239 |
| 240 // This test verifies parsing of a valid TURN Send Indication messages. | 240 // This test verifies parsing of a valid TURN Send Indication messages. |
| 241 TEST(P2PSocketHostTest, TestValidTurnSendIndicationMessages) { | 241 TEST(P2PSocketHostTest, TestValidTurnSendIndicationMessages) { |
| 242 int start_pos = INT_MAX, rtp_length = INT_MAX; | 242 size_t start_pos = SIZE_MAX, rtp_length = SIZE_MAX; |
| 243 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 243 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 244 reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension), | 244 reinterpret_cast<char*>(kTurnSendIndicationMsgWithoutRtpExtension), |
| 245 sizeof(kTurnSendIndicationMsgWithoutRtpExtension), | 245 sizeof(kTurnSendIndicationMsgWithoutRtpExtension), |
| 246 &start_pos, &rtp_length)); | 246 &start_pos, &rtp_length)); |
| 247 EXPECT_EQ(12, rtp_length); | 247 EXPECT_EQ(12U, rtp_length); |
| 248 EXPECT_EQ(32, start_pos); | 248 EXPECT_EQ(32U, start_pos); |
| 249 | 249 |
| 250 start_pos = INT_MAX, rtp_length = INT_MAX; | 250 start_pos = SIZE_MAX, rtp_length = SIZE_MAX; |
| 251 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 251 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 252 reinterpret_cast<char*>(kTurnSendIndicationMsgWithAbsSendTimeExtension), | 252 reinterpret_cast<char*>(kTurnSendIndicationMsgWithAbsSendTimeExtension), |
| 253 sizeof(kTurnSendIndicationMsgWithAbsSendTimeExtension), | 253 sizeof(kTurnSendIndicationMsgWithAbsSendTimeExtension), |
| 254 &start_pos, &rtp_length)); | 254 &start_pos, &rtp_length)); |
| 255 EXPECT_EQ(24, rtp_length); | 255 EXPECT_EQ(24U, rtp_length); |
| 256 EXPECT_EQ(32, start_pos); | 256 EXPECT_EQ(32U, start_pos); |
| 257 } | 257 } |
| 258 | 258 |
| 259 // This test verifies parsing of valid TURN Channel Messages. | 259 // This test verifies parsing of valid TURN Channel Messages. |
| 260 TEST(P2PSocketHostTest, TestValidTurnChannelMessages) { | 260 TEST(P2PSocketHostTest, TestValidTurnChannelMessages) { |
| 261 int start_pos = -1, rtp_length = -1; | 261 size_t start_pos = 0, rtp_length = 0; |
| 262 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 262 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 263 reinterpret_cast<char*>(kTurnChannelMsgWithRtpPacket), | 263 reinterpret_cast<char*>(kTurnChannelMsgWithRtpPacket), |
| 264 sizeof(kTurnChannelMsgWithRtpPacket), &start_pos, &rtp_length)); | 264 sizeof(kTurnChannelMsgWithRtpPacket), &start_pos, &rtp_length)); |
| 265 EXPECT_EQ(12, rtp_length); | 265 EXPECT_EQ(12U, rtp_length); |
| 266 EXPECT_EQ(4, start_pos); | 266 EXPECT_EQ(4U, start_pos); |
| 267 | 267 |
| 268 start_pos = -1, rtp_length = -1; | 268 start_pos = 0, rtp_length = 0; |
| 269 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( | 269 EXPECT_TRUE(packet_processing_helpers::GetRtpPacketStartPositionAndLength( |
| 270 reinterpret_cast<char*>(kTurnChannelMsgWithAbsSendTimeExtension), | 270 reinterpret_cast<char*>(kTurnChannelMsgWithAbsSendTimeExtension), |
| 271 sizeof(kTurnChannelMsgWithAbsSendTimeExtension), | 271 sizeof(kTurnChannelMsgWithAbsSendTimeExtension), |
| 272 &start_pos, &rtp_length)); | 272 &start_pos, &rtp_length)); |
| 273 EXPECT_EQ(20, rtp_length); | 273 EXPECT_EQ(20U, rtp_length); |
| 274 EXPECT_EQ(4, start_pos); | 274 EXPECT_EQ(4U, start_pos); |
| 275 } | 275 } |
| 276 | 276 |
| 277 // Verify handling of a 2 byte extension header RTP messsage. Currently we don't | 277 // Verify handling of a 2 byte extension header RTP messsage. Currently we don't |
| 278 // handle this kind of message. | 278 // handle this kind of message. |
| 279 TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionIn2ByteHeaderExtn) { | 279 TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionIn2ByteHeaderExtn) { |
| 280 EXPECT_FALSE(packet_processing_helpers::UpdateRtpAbsSendTimeExtn( | 280 EXPECT_FALSE(packet_processing_helpers::UpdateRtpAbsSendTimeExtn( |
| 281 reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader), | 281 reinterpret_cast<char*>(kRtpMsgWith2ByteExtnHeader), |
| 282 sizeof(kRtpMsgWith2ByteExtnHeader), 3, 0)); | 282 sizeof(kRtpMsgWith2ByteExtnHeader), 3, 0)); |
| 283 } | 283 } |
| 284 | 284 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 EXPECT_NE(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], | 367 EXPECT_NE(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], |
| 368 kFakeTag, sizeof(kFakeTag))); | 368 kFakeTag, sizeof(kFakeTag))); |
| 369 | 369 |
| 370 // ApplyPackets should have the new timestamp passed as input. | 370 // ApplyPackets should have the new timestamp passed as input. |
| 371 unsigned char timestamp_array[3] = { 0xcc, 0xbb, 0xaa }; | 371 unsigned char timestamp_array[3] = { 0xcc, 0xbb, 0xaa }; |
| 372 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], | 372 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], |
| 373 timestamp_array, sizeof(timestamp_array))); | 373 timestamp_array, sizeof(timestamp_array))); |
| 374 } | 374 } |
| 375 | 375 |
| 376 } // namespace content | 376 } // namespace content |
| OLD | NEW |