| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 | 290 |
| 291 EXPECT_TRUE(packet_processing_helpers::UpdateRtpAbsSendTimeExtn( | 291 EXPECT_TRUE(packet_processing_helpers::UpdateRtpAbsSendTimeExtn( |
| 292 reinterpret_cast<char*>(kTurnSendIndicationMsgWithAbsSendTimeExtension), | 292 reinterpret_cast<char*>(kTurnSendIndicationMsgWithAbsSendTimeExtension), |
| 293 sizeof(kTurnSendIndicationMsgWithAbsSendTimeExtension), 3, 0)); | 293 sizeof(kTurnSendIndicationMsgWithAbsSendTimeExtension), 3, 0)); |
| 294 } | 294 } |
| 295 | 295 |
| 296 // Test without any packet options variables set. This method should return | 296 // Test without any packet options variables set. This method should return |
| 297 // without HMAC value in the packet. | 297 // without HMAC value in the packet. |
| 298 TEST(P2PSocketHostTest, TestApplyPacketOptionsWithDefaultValues) { | 298 TEST(P2PSocketHostTest, TestApplyPacketOptionsWithDefaultValues) { |
| 299 unsigned char fake_tag[4] = { 0xba, 0xdd, 0xba, 0xdd }; | 299 unsigned char fake_tag[4] = { 0xba, 0xdd, 0xba, 0xdd }; |
| 300 talk_base::PacketOptions options; | 300 rtc::PacketOptions options; |
| 301 std::vector<char> rtp_packet; | 301 std::vector<char> rtp_packet; |
| 302 rtp_packet.resize(sizeof(kRtpMsgWithAbsSendTimeExtension) + 4); // tag length | 302 rtp_packet.resize(sizeof(kRtpMsgWithAbsSendTimeExtension) + 4); // tag length |
| 303 memcpy(&rtp_packet[0], kRtpMsgWithAbsSendTimeExtension, | 303 memcpy(&rtp_packet[0], kRtpMsgWithAbsSendTimeExtension, |
| 304 sizeof(kRtpMsgWithAbsSendTimeExtension)); | 304 sizeof(kRtpMsgWithAbsSendTimeExtension)); |
| 305 memcpy(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], fake_tag, 4); | 305 memcpy(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], fake_tag, 4); |
| 306 EXPECT_TRUE( | 306 EXPECT_TRUE( |
| 307 packet_processing_helpers::ApplyPacketOptions( | 307 packet_processing_helpers::ApplyPacketOptions( |
| 308 &rtp_packet[0], rtp_packet.size(), options, 0)); | 308 &rtp_packet[0], rtp_packet.size(), options, 0)); |
| 309 // Making sure we have't updated the HMAC. | 309 // Making sure we have't updated the HMAC. |
| 310 EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], | 310 EXPECT_EQ(0, memcmp(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], |
| 311 fake_tag, 4)); | 311 fake_tag, 4)); |
| 312 | 312 |
| 313 // Verify AbsouluteSendTime extension field is not modified. | 313 // Verify AbsouluteSendTime extension field is not modified. |
| 314 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], | 314 EXPECT_EQ(0, memcmp(&rtp_packet[kAstIndexInRtpMsg], |
| 315 kTestAstValue, sizeof(kTestAstValue))); | 315 kTestAstValue, sizeof(kTestAstValue))); |
| 316 } | 316 } |
| 317 | 317 |
| 318 // Veirfy HMAC is updated when packet option parameters are set. | 318 // Veirfy HMAC is updated when packet option parameters are set. |
| 319 TEST(P2PSocketHostTest, TestApplyPacketOptionsWithAuthParams) { | 319 TEST(P2PSocketHostTest, TestApplyPacketOptionsWithAuthParams) { |
| 320 talk_base::PacketOptions options; | 320 rtc::PacketOptions options; |
| 321 options.packet_time_params.srtp_auth_key.resize(20); | 321 options.packet_time_params.srtp_auth_key.resize(20); |
| 322 options.packet_time_params.srtp_auth_key.assign( | 322 options.packet_time_params.srtp_auth_key.assign( |
| 323 kTestKey, kTestKey + sizeof(kTestKey)); | 323 kTestKey, kTestKey + sizeof(kTestKey)); |
| 324 options.packet_time_params.srtp_auth_tag_len = 4; | 324 options.packet_time_params.srtp_auth_tag_len = 4; |
| 325 | 325 |
| 326 std::vector<char> rtp_packet; | 326 std::vector<char> rtp_packet; |
| 327 rtp_packet.resize(sizeof(kRtpMsgWithAbsSendTimeExtension) + 4); // tag length | 327 rtp_packet.resize(sizeof(kRtpMsgWithAbsSendTimeExtension) + 4); // tag length |
| 328 memcpy(&rtp_packet[0], kRtpMsgWithAbsSendTimeExtension, | 328 memcpy(&rtp_packet[0], kRtpMsgWithAbsSendTimeExtension, |
| 329 sizeof(kRtpMsgWithAbsSendTimeExtension)); | 329 sizeof(kRtpMsgWithAbsSendTimeExtension)); |
| 330 memcpy(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], kFakeTag, 4); | 330 memcpy(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], kFakeTag, 4); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 341 | 341 |
| 342 // Verify finding an extension ID in a raw rtp message. | 342 // Verify finding an extension ID in a raw rtp message. |
| 343 TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionInRtpPacket) { | 343 TEST(P2PSocketHostTest, TestUpdateAbsSendTimeExtensionInRtpPacket) { |
| 344 EXPECT_TRUE(packet_processing_helpers::UpdateRtpAbsSendTimeExtn( | 344 EXPECT_TRUE(packet_processing_helpers::UpdateRtpAbsSendTimeExtn( |
| 345 reinterpret_cast<char*>(kRtpMsgWithAbsSendTimeExtension), | 345 reinterpret_cast<char*>(kRtpMsgWithAbsSendTimeExtension), |
| 346 sizeof(kRtpMsgWithAbsSendTimeExtension), 3, 0)); | 346 sizeof(kRtpMsgWithAbsSendTimeExtension), 3, 0)); |
| 347 } | 347 } |
| 348 | 348 |
| 349 // Verify we update both AbsSendTime extension header and HMAC. | 349 // Verify we update both AbsSendTime extension header and HMAC. |
| 350 TEST(P2PSocketHostTest, TestApplyPacketOptionsWithAuthParamsAndAbsSendTime) { | 350 TEST(P2PSocketHostTest, TestApplyPacketOptionsWithAuthParamsAndAbsSendTime) { |
| 351 talk_base::PacketOptions options; | 351 rtc::PacketOptions options; |
| 352 options.packet_time_params.srtp_auth_key.resize(20); | 352 options.packet_time_params.srtp_auth_key.resize(20); |
| 353 options.packet_time_params.srtp_auth_key.assign( | 353 options.packet_time_params.srtp_auth_key.assign( |
| 354 kTestKey, kTestKey + sizeof(kTestKey)); | 354 kTestKey, kTestKey + sizeof(kTestKey)); |
| 355 options.packet_time_params.srtp_auth_tag_len = 4; | 355 options.packet_time_params.srtp_auth_tag_len = 4; |
| 356 options.packet_time_params.rtp_sendtime_extension_id = 3; | 356 options.packet_time_params.rtp_sendtime_extension_id = 3; |
| 357 // 3 is also present in the test message. | 357 // 3 is also present in the test message. |
| 358 | 358 |
| 359 std::vector<char> rtp_packet; | 359 std::vector<char> rtp_packet; |
| 360 rtp_packet.resize(sizeof(kRtpMsgWithAbsSendTimeExtension) + 4); // tag length | 360 rtp_packet.resize(sizeof(kRtpMsgWithAbsSendTimeExtension) + 4); // tag length |
| 361 memcpy(&rtp_packet[0], kRtpMsgWithAbsSendTimeExtension, | 361 memcpy(&rtp_packet[0], kRtpMsgWithAbsSendTimeExtension, |
| 362 sizeof(kRtpMsgWithAbsSendTimeExtension)); | 362 sizeof(kRtpMsgWithAbsSendTimeExtension)); |
| 363 memcpy(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], kFakeTag, 4); | 363 memcpy(&rtp_packet[sizeof(kRtpMsgWithAbsSendTimeExtension)], kFakeTag, 4); |
| 364 EXPECT_TRUE(packet_processing_helpers::ApplyPacketOptions( | 364 EXPECT_TRUE(packet_processing_helpers::ApplyPacketOptions( |
| 365 &rtp_packet[0], rtp_packet.size(), options, 0xccbbaa)); | 365 &rtp_packet[0], rtp_packet.size(), options, 0xccbbaa)); |
| 366 // HMAC should be different from fake_tag. | 366 // HMAC should be different from fake_tag. |
| 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 |