Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_test_utils.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" |
| 6 | 6 |
| 7 #include "base/sys_byteorder.h" | 7 #include "base/sys_byteorder.h" |
| 8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| 11 | 11 |
| 12 const int kStunHeaderSize = 20; | 12 const int kStunHeaderSize = 20; |
| 13 const uint16 kStunBindingRequest = 0x0001; | 13 const uint16 kStunBindingRequest = 0x0001; |
| 14 const uint16 kStunBindingResponse = 0x0102; | 14 const uint16 kStunBindingResponse = 0x0102; |
| 15 const uint16 kStunBindingError = 0x0111; | 15 const uint16 kStunBindingError = 0x0111; |
| 16 const uint32 kStunMagicCookie = 0x2112A442; | 16 const uint32 kStunMagicCookie = 0x2112A442; |
| 17 const int kRtpHeaderSize = 12; | |
| 18 const int kTurnChannelDataHdr = 4; | |
| 17 | 19 |
| 18 MockIPCSender::MockIPCSender() { } | 20 MockIPCSender::MockIPCSender() { } |
| 19 MockIPCSender::~MockIPCSender() { } | 21 MockIPCSender::~MockIPCSender() { } |
| 20 | 22 |
| 21 FakeSocket::FakeSocket(std::string* written_data) | 23 FakeSocket::FakeSocket(std::string* written_data) |
| 22 : read_pending_(false), | 24 : read_pending_(false), |
| 23 input_pos_(0), | 25 input_pos_(0), |
| 24 written_data_(written_data), | 26 written_data_(written_data), |
| 25 async_write_(false), | 27 async_write_(false), |
| 26 write_pending_(false) { | 28 write_pending_(false) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 } | 194 } |
| 193 | 195 |
| 194 void CreateStunRequest(std::vector<char>* packet) { | 196 void CreateStunRequest(std::vector<char>* packet) { |
| 195 CreateStunPacket(packet, kStunBindingRequest); | 197 CreateStunPacket(packet, kStunBindingRequest); |
| 196 } | 198 } |
| 197 | 199 |
| 198 void CreateStunResponse(std::vector<char>* packet) { | 200 void CreateStunResponse(std::vector<char>* packet) { |
| 199 CreateStunPacket(packet, kStunBindingResponse); | 201 CreateStunPacket(packet, kStunBindingResponse); |
| 200 } | 202 } |
| 201 | 203 |
| 204 | |
| 202 void CreateStunError(std::vector<char>* packet) { | 205 void CreateStunError(std::vector<char>* packet) { |
| 203 CreateStunPacket(packet, kStunBindingError); | 206 CreateStunPacket(packet, kStunBindingError); |
| 204 } | 207 } |
| 205 | 208 |
| 209 void CreateRtpPacket(std::vector<char>* packet) { | |
| 210 CreateRandomPacket(packet); // Minimum length is 20 bytes. | |
| 211 *reinterpret_cast<uint8*>(&*packet->begin()) = 0x80; | |
| 212 // Extension bit not set. | |
| 213 } | |
| 214 | |
| 215 void CreateRtpPacketWithSendtimeExtension(std::vector<char>* packet, | |
|
juberti2
2014/02/25 00:48:24
SendTime->SendTime
Mallinath (Gone from Chromium)
2014/02/25 22:56:44
Done.
| |
| 216 int extension_id) { | |
| 217 CreateRandomPacket(packet); | |
| 218 *reinterpret_cast<uint8*>(&*packet->begin()) = 0x90; | |
| 219 *reinterpret_cast<uint16*>(&*packet->begin() + kRtpHeaderSize) = | |
| 220 base::HostToNet16(0xBEDE); | |
| 221 *reinterpret_cast<uint16*>(&*packet->begin() + kRtpHeaderSize + 2) = | |
| 222 base::HostToNet16(2); | |
| 223 *reinterpret_cast<uint8*>(&*packet->begin() + kRtpHeaderSize + 4) = | |
| 224 (extension_id << 4) + 2; | |
| 225 } | |
| 226 | |
| 227 void CreateTurnChannelData(std::vector<char>* packet) { | |
| 228 size_t size = kRtpHeaderSize + kTurnChannelDataHdr + rand() % 1000; | |
|
juberti2
2014/02/25 00:48:24
instead of checking random sizes, i think we shoul
Mallinath (Gone from Chromium)
2014/02/25 22:56:44
Yea, removing these methods and adding test vector
| |
| 229 packet->resize(size); | |
| 230 *reinterpret_cast<uint16*>(&*packet->begin()) = base::HostToNet16(0x4000); | |
| 231 *reinterpret_cast<uint16*>(&*packet->begin() + 2) = | |
| 232 base::HostToNet16(size - 4); | |
| 233 // Write RTP header | |
| 234 *reinterpret_cast<uint8*>(&*packet->begin() + 4) = 0x80; | |
|
juberti2
2014/02/25 00:48:24
this should call CreateRtpPacketWithSendTimeExtens
Mallinath (Gone from Chromium)
2014/02/25 22:56:44
As above.
On 2014/02/25 00:48:24, juberti2 wrote:
| |
| 235 } | |
| 236 | |
| 206 net::IPEndPoint ParseAddress(const std::string ip_str, int port) { | 237 net::IPEndPoint ParseAddress(const std::string ip_str, int port) { |
| 207 net::IPAddressNumber ip; | 238 net::IPAddressNumber ip; |
| 208 EXPECT_TRUE(net::ParseIPLiteralToNumber(ip_str, &ip)); | 239 EXPECT_TRUE(net::ParseIPLiteralToNumber(ip_str, &ip)); |
| 209 return net::IPEndPoint(ip, port); | 240 return net::IPEndPoint(ip, port); |
| 210 } | 241 } |
| OLD | NEW |