OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_udp.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_udp.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 // This packet will be dropped, as limit only for a single packet. | 366 // This packet will be dropped, as limit only for a single packet. |
367 socket_host_->Send(dest3, packet1, options, 0); | 367 socket_host_->Send(dest3, packet1, options, 0); |
368 net::IPEndPoint dest4 = ParseAddress(kTestIpAddress1, 2224); | 368 net::IPEndPoint dest4 = ParseAddress(kTestIpAddress1, 2224); |
369 // This packet should also be dropped. | 369 // This packet should also be dropped. |
370 socket_host_->Send(dest4, packet1, options, 0); | 370 socket_host_->Send(dest4, packet1, options, 0); |
371 // |dest1| is known, we can send as many packets to it. | 371 // |dest1| is known, we can send as many packets to it. |
372 socket_host_->Send(dest1_, packet1, options, 0); | 372 socket_host_->Send(dest1_, packet1, options, 0); |
373 ASSERT_EQ(sent_packets_.size(), 4U); | 373 ASSERT_EQ(sent_packets_.size(), 4U); |
374 } | 374 } |
375 | 375 |
| 376 TEST_F(P2PSocketHostUdpTest, PackUnpackCallRecord) { |
| 377 uint64 packet_id_result; |
| 378 uint64 ticks_diff; |
| 379 uint64 random_prefix = 0xabcd1234uLL << 32; |
| 380 ASSERT_EQ(random_prefix & ((1uLL << 32) - 1), 0uL); |
| 381 |
| 382 uint64 packet_id = 12; |
| 383 uint64 ticks_now = 12345; |
| 384 uint64 call_record = |
| 385 P2PSocketHostUdp::PackCallRecord(random_prefix + packet_id, ticks_now); |
| 386 EXPECT_EQ(call_record, (ticks_now << 32) + packet_id); |
| 387 |
| 388 // Increment the tick by 2. |
| 389 P2PSocketHostUdp::UnpackCallRecord(call_record, |
| 390 random_prefix, |
| 391 ticks_now + 2, |
| 392 &packet_id_result, |
| 393 &ticks_diff); |
| 394 EXPECT_EQ(packet_id_result, random_prefix + packet_id); |
| 395 EXPECT_EQ(ticks_diff, 2uL); |
| 396 |
| 397 // Try a large packet id and the tick is rounding over 2^32. |
| 398 packet_id = 0xffffffff; |
| 399 ticks_now = 0xffffff00; |
| 400 call_record = |
| 401 P2PSocketHostUdp::PackCallRecord(random_prefix + packet_id, ticks_now); |
| 402 EXPECT_EQ(call_record, (ticks_now << 32) + 0xffffffff); |
| 403 P2PSocketHostUdp::UnpackCallRecord(call_record, |
| 404 random_prefix, |
| 405 ticks_now + 0x150, |
| 406 &packet_id_result, |
| 407 &ticks_diff); |
| 408 EXPECT_EQ(packet_id_result, random_prefix + packet_id); |
| 409 EXPECT_EQ(ticks_diff, 0x150uL); |
| 410 } |
| 411 |
376 } // namespace content | 412 } // namespace content |
OLD | NEW |