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 "net/udp/udp_client_socket.h" | 5 #include "net/udp/udp_client_socket.h" |
6 #include "net/udp/udp_server_socket.h" | 6 #include "net/udp/udp_server_socket.h" |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
13 #include "net/base/ip_endpoint.h" | 13 #include "net/base/ip_endpoint.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "net/base/net_log_unittest.h" | 15 #include "net/base/net_log_unittest.h" |
16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
17 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
18 #include "net/test/net_test_suite.h" | 18 #include "net/test/net_test_suite.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "testing/platform_test.h" | 20 #include "testing/platform_test.h" |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 class UDPSocketTest : public PlatformTest { | 26 class UDPSocketTest : public PlatformTest { |
27 public: | 27 public: |
28 UDPSocketTest() | 28 UDPSocketTest() : buffer_(new IOBufferWithSize(kMaxRead)) {} |
29 : buffer_(new IOBufferWithSize(kMaxRead)) { | |
30 } | |
31 | 29 |
32 // Blocks until data is read from the socket. | 30 // Blocks until data is read from the socket. |
33 std::string RecvFromSocket(UDPServerSocket* socket) { | 31 std::string RecvFromSocket(UDPServerSocket* socket) { |
34 TestCompletionCallback callback; | 32 TestCompletionCallback callback; |
35 | 33 |
36 int rv = socket->RecvFrom( | 34 int rv = socket->RecvFrom( |
37 buffer_.get(), kMaxRead, &recv_from_address_, callback.callback()); | 35 buffer_.get(), kMaxRead, &recv_from_address_, callback.callback()); |
38 if (rv == ERR_IO_PENDING) | 36 if (rv == ERR_IO_PENDING) |
39 rv = callback.WaitForResult(); | 37 rv = callback.WaitForResult(); |
40 if (rv < 0) | 38 if (rv < 0) |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 DCHECK(simple_message == str); | 166 DCHECK(simple_message == str); |
169 | 167 |
170 // Delete sockets so they log their final events. | 168 // Delete sockets so they log their final events. |
171 server.reset(); | 169 server.reset(); |
172 client.reset(); | 170 client.reset(); |
173 | 171 |
174 // Check the server's log. | 172 // Check the server's log. |
175 CapturingNetLog::CapturedEntryList server_entries; | 173 CapturingNetLog::CapturedEntryList server_entries; |
176 server_log.GetEntries(&server_entries); | 174 server_log.GetEntries(&server_entries); |
177 EXPECT_EQ(4u, server_entries.size()); | 175 EXPECT_EQ(4u, server_entries.size()); |
178 EXPECT_TRUE(LogContainsBeginEvent( | 176 EXPECT_TRUE( |
179 server_entries, 0, NetLog::TYPE_SOCKET_ALIVE)); | 177 LogContainsBeginEvent(server_entries, 0, NetLog::TYPE_SOCKET_ALIVE)); |
180 EXPECT_TRUE(LogContainsEvent( | 178 EXPECT_TRUE(LogContainsEvent( |
181 server_entries, 1, NetLog::TYPE_UDP_BYTES_RECEIVED, NetLog::PHASE_NONE)); | 179 server_entries, 1, NetLog::TYPE_UDP_BYTES_RECEIVED, NetLog::PHASE_NONE)); |
182 EXPECT_TRUE(LogContainsEvent( | 180 EXPECT_TRUE(LogContainsEvent( |
183 server_entries, 2, NetLog::TYPE_UDP_BYTES_SENT, NetLog::PHASE_NONE)); | 181 server_entries, 2, NetLog::TYPE_UDP_BYTES_SENT, NetLog::PHASE_NONE)); |
184 EXPECT_TRUE(LogContainsEndEvent( | 182 EXPECT_TRUE( |
185 server_entries, 3, NetLog::TYPE_SOCKET_ALIVE)); | 183 LogContainsEndEvent(server_entries, 3, NetLog::TYPE_SOCKET_ALIVE)); |
186 | 184 |
187 // Check the client's log. | 185 // Check the client's log. |
188 CapturingNetLog::CapturedEntryList client_entries; | 186 CapturingNetLog::CapturedEntryList client_entries; |
189 client_log.GetEntries(&client_entries); | 187 client_log.GetEntries(&client_entries); |
190 EXPECT_EQ(6u, client_entries.size()); | 188 EXPECT_EQ(6u, client_entries.size()); |
191 EXPECT_TRUE(LogContainsBeginEvent( | 189 EXPECT_TRUE( |
192 client_entries, 0, NetLog::TYPE_SOCKET_ALIVE)); | 190 LogContainsBeginEvent(client_entries, 0, NetLog::TYPE_SOCKET_ALIVE)); |
193 EXPECT_TRUE(LogContainsBeginEvent( | 191 EXPECT_TRUE( |
194 client_entries, 1, NetLog::TYPE_UDP_CONNECT)); | 192 LogContainsBeginEvent(client_entries, 1, NetLog::TYPE_UDP_CONNECT)); |
195 EXPECT_TRUE(LogContainsEndEvent( | 193 EXPECT_TRUE(LogContainsEndEvent(client_entries, 2, NetLog::TYPE_UDP_CONNECT)); |
196 client_entries, 2, NetLog::TYPE_UDP_CONNECT)); | |
197 EXPECT_TRUE(LogContainsEvent( | 194 EXPECT_TRUE(LogContainsEvent( |
198 client_entries, 3, NetLog::TYPE_UDP_BYTES_SENT, NetLog::PHASE_NONE)); | 195 client_entries, 3, NetLog::TYPE_UDP_BYTES_SENT, NetLog::PHASE_NONE)); |
199 EXPECT_TRUE(LogContainsEvent( | 196 EXPECT_TRUE(LogContainsEvent( |
200 client_entries, 4, NetLog::TYPE_UDP_BYTES_RECEIVED, NetLog::PHASE_NONE)); | 197 client_entries, 4, NetLog::TYPE_UDP_BYTES_RECEIVED, NetLog::PHASE_NONE)); |
201 EXPECT_TRUE(LogContainsEndEvent( | 198 EXPECT_TRUE( |
202 client_entries, 5, NetLog::TYPE_SOCKET_ALIVE)); | 199 LogContainsEndEvent(client_entries, 5, NetLog::TYPE_SOCKET_ALIVE)); |
203 } | 200 } |
204 | 201 |
205 #if defined(OS_MACOSX) | 202 #if defined(OS_MACOSX) |
206 // UDPSocketPrivate_Broadcast is disabled for OSX because it requires | 203 // UDPSocketPrivate_Broadcast is disabled for OSX because it requires |
207 // root permissions on OSX 10.7+. | 204 // root permissions on OSX 10.7+. |
208 TEST_F(UDPSocketTest, DISABLED_Broadcast) { | 205 TEST_F(UDPSocketTest, DISABLED_Broadcast) { |
209 #elif defined(OS_ANDROID) | 206 #elif defined(OS_ANDROID) |
210 // It is also disabled for Android because it is extremely flaky. | 207 // It is also disabled for Android because it is extremely flaky. |
211 // The first call to SendToSocket returns -109 (Address not reachable) | 208 // The first call to SendToSocket returns -109 (Address not reachable) |
212 // in some unpredictable cases. crbug.com/139144. | 209 // in some unpredictable cases. crbug.com/139144. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 270 |
274 class TestPrng { | 271 class TestPrng { |
275 public: | 272 public: |
276 explicit TestPrng(const std::deque<int>& numbers) : numbers_(numbers) {} | 273 explicit TestPrng(const std::deque<int>& numbers) : numbers_(numbers) {} |
277 int GetNext(int /* min */, int /* max */) { | 274 int GetNext(int /* min */, int /* max */) { |
278 DCHECK(!numbers_.empty()); | 275 DCHECK(!numbers_.empty()); |
279 int rv = numbers_.front(); | 276 int rv = numbers_.front(); |
280 numbers_.pop_front(); | 277 numbers_.pop_front(); |
281 return rv; | 278 return rv; |
282 } | 279 } |
| 280 |
283 private: | 281 private: |
284 std::deque<int> numbers_; | 282 std::deque<int> numbers_; |
285 | 283 |
286 DISALLOW_COPY_AND_ASSIGN(TestPrng); | 284 DISALLOW_COPY_AND_ASSIGN(TestPrng); |
287 }; | 285 }; |
288 | 286 |
289 #if defined(OS_ANDROID) | 287 #if defined(OS_ANDROID) |
290 // Disabled on Android for lack of 192.168.1.13. crbug.com/161245 | 288 // Disabled on Android for lack of 192.168.1.13. crbug.com/161245 |
291 TEST_F(UDPSocketTest, DISABLED_ConnectRandomBind) { | 289 TEST_F(UDPSocketTest, DISABLED_ConnectRandomBind) { |
292 #else | 290 #else |
293 TEST_F(UDPSocketTest, ConnectRandomBind) { | 291 TEST_F(UDPSocketTest, ConnectRandomBind) { |
294 #endif | 292 #endif |
295 std::vector<UDPClientSocket*> sockets; | 293 std::vector<UDPClientSocket*> sockets; |
296 IPEndPoint peer_address; | 294 IPEndPoint peer_address; |
297 CreateUDPAddress("192.168.1.13", 53, &peer_address); | 295 CreateUDPAddress("192.168.1.13", 53, &peer_address); |
298 | 296 |
299 // Create and connect sockets and save port numbers. | 297 // Create and connect sockets and save port numbers. |
300 std::deque<int> used_ports; | 298 std::deque<int> used_ports; |
301 for (int i = 0; i < kBindRetries; ++i) { | 299 for (int i = 0; i < kBindRetries; ++i) { |
302 UDPClientSocket* socket = | 300 UDPClientSocket* socket = new UDPClientSocket(DatagramSocket::DEFAULT_BIND, |
303 new UDPClientSocket(DatagramSocket::DEFAULT_BIND, | 301 RandIntCallback(), |
304 RandIntCallback(), | 302 NULL, |
305 NULL, | 303 NetLog::Source()); |
306 NetLog::Source()); | |
307 sockets.push_back(socket); | 304 sockets.push_back(socket); |
308 EXPECT_EQ(OK, socket->Connect(peer_address)); | 305 EXPECT_EQ(OK, socket->Connect(peer_address)); |
309 | 306 |
310 IPEndPoint client_address; | 307 IPEndPoint client_address; |
311 EXPECT_EQ(OK, socket->GetLocalAddress(&client_address)); | 308 EXPECT_EQ(OK, socket->GetLocalAddress(&client_address)); |
312 used_ports.push_back(client_address.port()); | 309 used_ports.push_back(client_address.port()); |
313 } | 310 } |
314 | 311 |
315 // Free the last socket, its local port is still in |used_ports|. | 312 // Free the last socket, its local port is still in |used_ports|. |
316 delete sockets.back(); | 313 delete sockets.back(); |
317 sockets.pop_back(); | 314 sockets.pop_back(); |
318 | 315 |
319 TestPrng test_prng(used_ports); | 316 TestPrng test_prng(used_ports); |
320 RandIntCallback rand_int_cb = | 317 RandIntCallback rand_int_cb = |
321 base::Bind(&TestPrng::GetNext, base::Unretained(&test_prng)); | 318 base::Bind(&TestPrng::GetNext, base::Unretained(&test_prng)); |
322 | 319 |
323 // Create a socket with random binding policy and connect. | 320 // Create a socket with random binding policy and connect. |
324 scoped_ptr<UDPClientSocket> test_socket( | 321 scoped_ptr<UDPClientSocket> test_socket(new UDPClientSocket( |
325 new UDPClientSocket(DatagramSocket::RANDOM_BIND, | 322 DatagramSocket::RANDOM_BIND, rand_int_cb, NULL, NetLog::Source())); |
326 rand_int_cb, | |
327 NULL, | |
328 NetLog::Source())); | |
329 EXPECT_EQ(OK, test_socket->Connect(peer_address)); | 323 EXPECT_EQ(OK, test_socket->Connect(peer_address)); |
330 | 324 |
331 // Make sure that the last port number in the |used_ports| was used. | 325 // Make sure that the last port number in the |used_ports| was used. |
332 IPEndPoint client_address; | 326 IPEndPoint client_address; |
333 EXPECT_EQ(OK, test_socket->GetLocalAddress(&client_address)); | 327 EXPECT_EQ(OK, test_socket->GetLocalAddress(&client_address)); |
334 EXPECT_EQ(used_ports.back(), client_address.port()); | 328 EXPECT_EQ(used_ports.back(), client_address.port()); |
335 | 329 |
336 STLDeleteElements(&sockets); | 330 STLDeleteElements(&sockets); |
337 } | 331 } |
338 | 332 |
339 // Return a privileged port (under 1024) so binding will fail. | 333 // Return a privileged port (under 1024) so binding will fail. |
340 int PrivilegedRand(int min, int max) { | 334 int PrivilegedRand(int min, int max) { |
341 // Chosen by fair dice roll. Guaranteed to be random. | 335 // Chosen by fair dice roll. Guaranteed to be random. |
342 return 4; | 336 return 4; |
343 } | 337 } |
344 | 338 |
345 TEST_F(UDPSocketTest, ConnectFail) { | 339 TEST_F(UDPSocketTest, ConnectFail) { |
346 IPEndPoint peer_address; | 340 IPEndPoint peer_address; |
347 CreateUDPAddress("0.0.0.0", 53, &peer_address); | 341 CreateUDPAddress("0.0.0.0", 53, &peer_address); |
348 | 342 |
349 scoped_ptr<UDPSocket> socket( | 343 scoped_ptr<UDPSocket> socket(new UDPSocket(DatagramSocket::RANDOM_BIND, |
350 new UDPSocket(DatagramSocket::RANDOM_BIND, | 344 base::Bind(&PrivilegedRand), |
351 base::Bind(&PrivilegedRand), | 345 NULL, |
352 NULL, | 346 NetLog::Source())); |
353 NetLog::Source())); | |
354 int rv = socket->Connect(peer_address); | 347 int rv = socket->Connect(peer_address); |
355 // Connect should have failed since we couldn't bind to that port, | 348 // Connect should have failed since we couldn't bind to that port, |
356 EXPECT_NE(OK, rv); | 349 EXPECT_NE(OK, rv); |
357 // Make sure that UDPSocket actually closed the socket. | 350 // Make sure that UDPSocket actually closed the socket. |
358 EXPECT_FALSE(socket->is_connected()); | 351 EXPECT_FALSE(socket->is_connected()); |
359 } | 352 } |
360 | 353 |
361 // In this test, we verify that connect() on a socket will have the effect | 354 // In this test, we verify that connect() on a socket will have the effect |
362 // of filtering reads on this socket only to data read from the destination | 355 // of filtering reads on this socket only to data read from the destination |
363 // we connected to. | 356 // we connected to. |
(...skipping 19 matching lines...) Expand all Loading... |
383 // Setup the second server to listen. | 376 // Setup the second server to listen. |
384 CreateUDPAddress("127.0.0.1", kPort2, &bind_address); | 377 CreateUDPAddress("127.0.0.1", kPort2, &bind_address); |
385 UDPServerSocket server2(NULL, NetLog::Source()); | 378 UDPServerSocket server2(NULL, NetLog::Source()); |
386 server2.AllowAddressReuse(); | 379 server2.AllowAddressReuse(); |
387 rv = server2.Listen(bind_address); | 380 rv = server2.Listen(bind_address); |
388 ASSERT_EQ(OK, rv); | 381 ASSERT_EQ(OK, rv); |
389 | 382 |
390 // Setup the client, connected to server 1. | 383 // Setup the client, connected to server 1. |
391 IPEndPoint server_address; | 384 IPEndPoint server_address; |
392 CreateUDPAddress("127.0.0.1", kPort1, &server_address); | 385 CreateUDPAddress("127.0.0.1", kPort1, &server_address); |
393 UDPClientSocket client(DatagramSocket::DEFAULT_BIND, | 386 UDPClientSocket client( |
394 RandIntCallback(), | 387 DatagramSocket::DEFAULT_BIND, RandIntCallback(), NULL, NetLog::Source()); |
395 NULL, | |
396 NetLog::Source()); | |
397 rv = client.Connect(server_address); | 388 rv = client.Connect(server_address); |
398 EXPECT_EQ(OK, rv); | 389 EXPECT_EQ(OK, rv); |
399 | 390 |
400 // Client sends to server1. | 391 // Client sends to server1. |
401 rv = WriteSocket(&client, simple_message); | 392 rv = WriteSocket(&client, simple_message); |
402 EXPECT_EQ(simple_message.length(), static_cast<size_t>(rv)); | 393 EXPECT_EQ(simple_message.length(), static_cast<size_t>(rv)); |
403 | 394 |
404 // Server1 waits for message. | 395 // Server1 waits for message. |
405 std::string str = RecvFromSocket(&server1); | 396 std::string str = RecvFromSocket(&server1); |
406 DCHECK(simple_message == str); | 397 DCHECK(simple_message == str); |
407 | 398 |
408 // Get the client's address. | 399 // Get the client's address. |
409 IPEndPoint client_address; | 400 IPEndPoint client_address; |
410 rv = client.GetLocalAddress(&client_address); | 401 rv = client.GetLocalAddress(&client_address); |
411 EXPECT_EQ(OK, rv); | 402 EXPECT_EQ(OK, rv); |
412 | 403 |
413 // Server2 sends reply. | 404 // Server2 sends reply. |
414 rv = SendToSocket(&server2, foreign_message, | 405 rv = SendToSocket(&server2, foreign_message, client_address); |
415 client_address); | |
416 EXPECT_EQ(foreign_message.length(), static_cast<size_t>(rv)); | 406 EXPECT_EQ(foreign_message.length(), static_cast<size_t>(rv)); |
417 | 407 |
418 // Server1 sends reply. | 408 // Server1 sends reply. |
419 rv = SendToSocket(&server1, simple_message, | 409 rv = SendToSocket(&server1, simple_message, client_address); |
420 client_address); | |
421 EXPECT_EQ(simple_message.length(), static_cast<size_t>(rv)); | 410 EXPECT_EQ(simple_message.length(), static_cast<size_t>(rv)); |
422 | 411 |
423 // Client waits for response. | 412 // Client waits for response. |
424 str = ReadSocket(&client); | 413 str = ReadSocket(&client); |
425 DCHECK(simple_message == str); | 414 DCHECK(simple_message == str); |
426 } | 415 } |
427 | 416 |
428 TEST_F(UDPSocketTest, ClientGetLocalPeerAddresses) { | 417 TEST_F(UDPSocketTest, ClientGetLocalPeerAddresses) { |
429 struct TestData { | 418 struct TestData { |
430 std::string remote_address; | 419 std::string remote_address; |
431 std::string local_address; | 420 std::string local_address; |
432 bool may_fail; | 421 bool may_fail; |
433 } tests[] = { | 422 } tests[] = { |
434 { "127.0.00.1", "127.0.0.1", false }, | 423 {"127.0.00.1", "127.0.0.1", false}, |
435 { "::1", "::1", true }, | 424 {"::1", "::1", true}, |
436 #if !defined(OS_ANDROID) | 425 #if !defined(OS_ANDROID) |
437 // Addresses below are disabled on Android. See crbug.com/161248 | 426 // Addresses below are disabled on Android. See crbug.com/161248 |
438 { "192.168.1.1", "127.0.0.1", false }, | 427 {"192.168.1.1", "127.0.0.1", false}, |
439 { "2001:db8:0::42", "::1", true }, | 428 {"2001:db8:0::42", "::1", true}, |
440 #endif | 429 #endif |
441 }; | 430 }; |
442 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { | 431 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); i++) { |
443 SCOPED_TRACE(std::string("Connecting from ") + tests[i].local_address + | 432 SCOPED_TRACE(std::string("Connecting from ") + tests[i].local_address + |
444 std::string(" to ") + tests[i].remote_address); | 433 std::string(" to ") + tests[i].remote_address); |
445 | 434 |
446 IPAddressNumber ip_number; | 435 IPAddressNumber ip_number; |
447 ParseIPLiteralToNumber(tests[i].remote_address, &ip_number); | 436 ParseIPLiteralToNumber(tests[i].remote_address, &ip_number); |
448 IPEndPoint remote_address(ip_number, 80); | 437 IPEndPoint remote_address(ip_number, 80); |
449 ParseIPLiteralToNumber(tests[i].local_address, &ip_number); | 438 ParseIPLiteralToNumber(tests[i].local_address, &ip_number); |
450 IPEndPoint local_address(ip_number, 80); | 439 IPEndPoint local_address(ip_number, 80); |
451 | 440 |
452 UDPClientSocket client(DatagramSocket::DEFAULT_BIND, | 441 UDPClientSocket client(DatagramSocket::DEFAULT_BIND, |
453 RandIntCallback(), | 442 RandIntCallback(), |
454 NULL, | 443 NULL, |
455 NetLog::Source()); | 444 NetLog::Source()); |
456 int rv = client.Connect(remote_address); | 445 int rv = client.Connect(remote_address); |
457 if (tests[i].may_fail && rv == ERR_ADDRESS_UNREACHABLE) { | 446 if (tests[i].may_fail && rv == ERR_ADDRESS_UNREACHABLE) { |
458 // Connect() may return ERR_ADDRESS_UNREACHABLE for IPv6 | 447 // Connect() may return ERR_ADDRESS_UNREACHABLE for IPv6 |
459 // addresses if IPv6 is not configured. | 448 // addresses if IPv6 is not configured. |
460 continue; | 449 continue; |
461 } | 450 } |
462 | 451 |
463 EXPECT_LE(ERR_IO_PENDING, rv); | 452 EXPECT_LE(ERR_IO_PENDING, rv); |
464 | 453 |
465 IPEndPoint fetched_local_address; | 454 IPEndPoint fetched_local_address; |
466 rv = client.GetLocalAddress(&fetched_local_address); | 455 rv = client.GetLocalAddress(&fetched_local_address); |
467 EXPECT_EQ(OK, rv); | 456 EXPECT_EQ(OK, rv); |
468 | 457 |
469 // TODO(mbelshe): figure out how to verify the IP and port. | 458 // TODO(mbelshe): figure out how to verify the IP and port. |
470 // The port is dynamically generated by the udp stack. | 459 // The port is dynamically generated by the udp stack. |
471 // The IP is the real IP of the client, not necessarily | 460 // The IP is the real IP of the client, not necessarily |
472 // loopback. | 461 // loopback. |
473 //EXPECT_EQ(local_address.address(), fetched_local_address.address()); | 462 // EXPECT_EQ(local_address.address(), fetched_local_address.address()); |
474 | 463 |
475 IPEndPoint fetched_remote_address; | 464 IPEndPoint fetched_remote_address; |
476 rv = client.GetPeerAddress(&fetched_remote_address); | 465 rv = client.GetPeerAddress(&fetched_remote_address); |
477 EXPECT_EQ(OK, rv); | 466 EXPECT_EQ(OK, rv); |
478 | 467 |
479 EXPECT_EQ(remote_address, fetched_remote_address); | 468 EXPECT_EQ(remote_address, fetched_remote_address); |
480 } | 469 } |
481 } | 470 } |
482 | 471 |
483 TEST_F(UDPSocketTest, ServerGetLocalAddress) { | 472 TEST_F(UDPSocketTest, ServerGetLocalAddress) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 | 526 |
538 TEST_F(UDPSocketTest, MAYBE_JoinMulticastGroup) { | 527 TEST_F(UDPSocketTest, MAYBE_JoinMulticastGroup) { |
539 const int kPort = 9999; | 528 const int kPort = 9999; |
540 const char* const kGroup = "237.132.100.17"; | 529 const char* const kGroup = "237.132.100.17"; |
541 | 530 |
542 IPEndPoint bind_address; | 531 IPEndPoint bind_address; |
543 CreateUDPAddress("0.0.0.0", kPort, &bind_address); | 532 CreateUDPAddress("0.0.0.0", kPort, &bind_address); |
544 IPAddressNumber group_ip; | 533 IPAddressNumber group_ip; |
545 EXPECT_TRUE(ParseIPLiteralToNumber(kGroup, &group_ip)); | 534 EXPECT_TRUE(ParseIPLiteralToNumber(kGroup, &group_ip)); |
546 | 535 |
547 UDPSocket socket(DatagramSocket::DEFAULT_BIND, | 536 UDPSocket socket( |
548 RandIntCallback(), | 537 DatagramSocket::DEFAULT_BIND, RandIntCallback(), NULL, NetLog::Source()); |
549 NULL, | |
550 NetLog::Source()); | |
551 EXPECT_EQ(OK, socket.Bind(bind_address)); | 538 EXPECT_EQ(OK, socket.Bind(bind_address)); |
552 EXPECT_EQ(OK, socket.JoinGroup(group_ip)); | 539 EXPECT_EQ(OK, socket.JoinGroup(group_ip)); |
553 // Joining group multiple times. | 540 // Joining group multiple times. |
554 EXPECT_NE(OK, socket.JoinGroup(group_ip)); | 541 EXPECT_NE(OK, socket.JoinGroup(group_ip)); |
555 EXPECT_EQ(OK, socket.LeaveGroup(group_ip)); | 542 EXPECT_EQ(OK, socket.LeaveGroup(group_ip)); |
556 // Leaving group multiple times. | 543 // Leaving group multiple times. |
557 EXPECT_NE(OK, socket.LeaveGroup(group_ip)); | 544 EXPECT_NE(OK, socket.LeaveGroup(group_ip)); |
558 | 545 |
559 socket.Close(); | 546 socket.Close(); |
560 } | 547 } |
561 | 548 |
562 TEST_F(UDPSocketTest, MulticastOptions) { | 549 TEST_F(UDPSocketTest, MulticastOptions) { |
563 const int kPort = 9999; | 550 const int kPort = 9999; |
564 IPEndPoint bind_address; | 551 IPEndPoint bind_address; |
565 CreateUDPAddress("0.0.0.0", kPort, &bind_address); | 552 CreateUDPAddress("0.0.0.0", kPort, &bind_address); |
566 | 553 |
567 UDPSocket socket(DatagramSocket::DEFAULT_BIND, | 554 UDPSocket socket( |
568 RandIntCallback(), | 555 DatagramSocket::DEFAULT_BIND, RandIntCallback(), NULL, NetLog::Source()); |
569 NULL, | |
570 NetLog::Source()); | |
571 // Before binding. | 556 // Before binding. |
572 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(false)); | 557 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(false)); |
573 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(true)); | 558 EXPECT_EQ(OK, socket.SetMulticastLoopbackMode(true)); |
574 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(0)); | 559 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(0)); |
575 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(3)); | 560 EXPECT_EQ(OK, socket.SetMulticastTimeToLive(3)); |
576 EXPECT_NE(OK, socket.SetMulticastTimeToLive(-1)); | 561 EXPECT_NE(OK, socket.SetMulticastTimeToLive(-1)); |
577 EXPECT_EQ(OK, socket.SetMulticastInterface(0)); | 562 EXPECT_EQ(OK, socket.SetMulticastInterface(0)); |
578 | 563 |
579 EXPECT_EQ(OK, socket.Bind(bind_address)); | 564 EXPECT_EQ(OK, socket.Bind(bind_address)); |
580 | 565 |
581 EXPECT_NE(OK, socket.SetMulticastLoopbackMode(false)); | 566 EXPECT_NE(OK, socket.SetMulticastLoopbackMode(false)); |
582 EXPECT_NE(OK, socket.SetMulticastTimeToLive(0)); | 567 EXPECT_NE(OK, socket.SetMulticastTimeToLive(0)); |
583 EXPECT_NE(OK, socket.SetMulticastInterface(0)); | 568 EXPECT_NE(OK, socket.SetMulticastInterface(0)); |
584 | 569 |
585 socket.Close(); | 570 socket.Close(); |
586 } | 571 } |
587 | 572 |
588 } // namespace | 573 } // namespace |
589 | 574 |
590 } // namespace net | 575 } // namespace net |
OLD | NEW |