Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: net/udp/udp_socket_unittest.cc

Issue 2333923004: Extracting NetLog inner classes into their own classes. (Closed)
Patch Set: Some nit fixes and better, impl-agnostic naming of net_log_parameters_callback_typedef.h -> net/log… Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/udp/udp_socket_unittest.cc
diff --git a/net/udp/udp_socket_unittest.cc b/net/udp/udp_socket_unittest.cc
index bfb1ec5a04adb6d4ff0adfccaea4093af3d5b2ec..21ac91811f03fb5a7b96194af2b46e3815e82327 100644
--- a/net/udp/udp_socket_unittest.cc
+++ b/net/udp/udp_socket_unittest.cc
@@ -21,6 +21,7 @@
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/log/net_log_event_type.h"
+#include "net/log/net_log_source.h"
#include "net/log/test_net_log.h"
#include "net/log/test_net_log_entry.h"
#include "net/log/test_net_log_util.h"
@@ -170,7 +171,7 @@ void UDPSocketTest::ConnectTest(bool use_nonblocking_io) {
CreateUDPAddress("127.0.0.1", kPort, &bind_address);
TestNetLog server_log;
std::unique_ptr<UDPServerSocket> server(
- new UDPServerSocket(&server_log, NetLog::Source()));
+ new UDPServerSocket(&server_log, NetLogSource()));
if (use_nonblocking_io)
server->UseNonBlockingIO();
server->AllowAddressReuse();
@@ -183,7 +184,7 @@ void UDPSocketTest::ConnectTest(bool use_nonblocking_io) {
TestNetLog client_log;
std::unique_ptr<UDPClientSocket> client(
new UDPClientSocket(DatagramSocket::DEFAULT_BIND, RandIntCallback(),
- &client_log, NetLog::Source()));
+ &client_log, NetLogSource()));
if (use_nonblocking_io)
client->UseNonBlockingIO();
@@ -301,9 +302,9 @@ TEST_F(UDPSocketTest, Broadcast) {
TestNetLog server1_log, server2_log;
std::unique_ptr<UDPServerSocket> server1(
- new UDPServerSocket(&server1_log, NetLog::Source()));
+ new UDPServerSocket(&server1_log, NetLogSource()));
std::unique_ptr<UDPServerSocket> server2(
- new UDPServerSocket(&server2_log, NetLog::Source()));
+ new UDPServerSocket(&server2_log, NetLogSource()));
server1->AllowAddressReuse();
server1->AllowBroadcast();
server2->AllowAddressReuse();
@@ -371,11 +372,8 @@ TEST_F(UDPSocketTest, ConnectRandomBind) {
// Create and connect sockets and save port numbers.
std::deque<int> used_ports;
for (int i = 0; i < kBindRetries; ++i) {
- UDPClientSocket* socket =
- new UDPClientSocket(DatagramSocket::DEFAULT_BIND,
- RandIntCallback(),
- NULL,
- NetLog::Source());
+ UDPClientSocket* socket = new UDPClientSocket(
+ DatagramSocket::DEFAULT_BIND, RandIntCallback(), NULL, NetLogSource());
sockets.push_back(base::WrapUnique(socket));
EXPECT_THAT(socket->Connect(peer_address), IsOk());
@@ -393,7 +391,7 @@ TEST_F(UDPSocketTest, ConnectRandomBind) {
// Create a socket with random binding policy and connect.
std::unique_ptr<UDPClientSocket> test_socket(new UDPClientSocket(
- DatagramSocket::RANDOM_BIND, rand_int_cb, NULL, NetLog::Source()));
+ DatagramSocket::RANDOM_BIND, rand_int_cb, NULL, NetLogSource()));
EXPECT_THAT(test_socket->Connect(peer_address), IsOk());
// Make sure that the last port number in the |used_ports| was used.
@@ -421,7 +419,7 @@ TEST_F(UDPSocketTest, MAYBE_ConnectFail) {
std::unique_ptr<UDPSocket> socket(new UDPSocket(DatagramSocket::RANDOM_BIND,
base::Bind(&PrivilegedRand),
- NULL, NetLog::Source()));
+ NULL, NetLogSource()));
int rv = socket->Open(peer_address.GetFamily());
EXPECT_THAT(rv, IsOk());
rv = socket->Connect(peer_address);
@@ -448,14 +446,14 @@ TEST_F(UDPSocketTest, VerifyConnectBindsAddr) {
// Setup the first server to listen.
IPEndPoint bind_address;
CreateUDPAddress("127.0.0.1", kPort1, &bind_address);
- UDPServerSocket server1(NULL, NetLog::Source());
+ UDPServerSocket server1(NULL, NetLogSource());
server1.AllowAddressReuse();
int rv = server1.Listen(bind_address);
ASSERT_THAT(rv, IsOk());
// Setup the second server to listen.
CreateUDPAddress("127.0.0.1", kPort2, &bind_address);
- UDPServerSocket server2(NULL, NetLog::Source());
+ UDPServerSocket server2(NULL, NetLogSource());
server2.AllowAddressReuse();
rv = server2.Listen(bind_address);
ASSERT_THAT(rv, IsOk());
@@ -463,10 +461,8 @@ TEST_F(UDPSocketTest, VerifyConnectBindsAddr) {
// Setup the client, connected to server 1.
IPEndPoint server_address;
CreateUDPAddress("127.0.0.1", kPort1, &server_address);
- UDPClientSocket client(DatagramSocket::DEFAULT_BIND,
- RandIntCallback(),
- NULL,
- NetLog::Source());
+ UDPClientSocket client(DatagramSocket::DEFAULT_BIND, RandIntCallback(), NULL,
+ NetLogSource());
rv = client.Connect(server_address);
EXPECT_THAT(rv, IsOk());
@@ -523,10 +519,8 @@ TEST_F(UDPSocketTest, ClientGetLocalPeerAddresses) {
EXPECT_TRUE(ip_address.AssignFromIPLiteral(tests[i].local_address));
IPEndPoint local_address(ip_address, 80);
- UDPClientSocket client(DatagramSocket::DEFAULT_BIND,
- RandIntCallback(),
- NULL,
- NetLog::Source());
+ UDPClientSocket client(DatagramSocket::DEFAULT_BIND, RandIntCallback(),
+ NULL, NetLogSource());
int rv = client.Connect(remote_address);
if (tests[i].may_fail && rv == ERR_ADDRESS_UNREACHABLE) {
// Connect() may return ERR_ADDRESS_UNREACHABLE for IPv6
@@ -557,7 +551,7 @@ TEST_F(UDPSocketTest, ClientGetLocalPeerAddresses) {
TEST_F(UDPSocketTest, ServerGetLocalAddress) {
IPEndPoint bind_address;
CreateUDPAddress("127.0.0.1", 0, &bind_address);
- UDPServerSocket server(NULL, NetLog::Source());
+ UDPServerSocket server(NULL, NetLogSource());
int rv = server.Listen(bind_address);
EXPECT_THAT(rv, IsOk());
@@ -573,7 +567,7 @@ TEST_F(UDPSocketTest, ServerGetLocalAddress) {
TEST_F(UDPSocketTest, ServerGetPeerAddress) {
IPEndPoint bind_address;
CreateUDPAddress("127.0.0.1", 0, &bind_address);
- UDPServerSocket server(NULL, NetLog::Source());
+ UDPServerSocket server(NULL, NetLogSource());
int rv = server.Listen(bind_address);
EXPECT_THAT(rv, IsOk());
@@ -586,7 +580,7 @@ TEST_F(UDPSocketTest, ClientSetDoNotFragment) {
for (std::string ip : {"127.0.0.1", "::1"}) {
LOG(INFO) << "ip: " << ip;
UDPClientSocket client(DatagramSocket::DEFAULT_BIND, RandIntCallback(),
- nullptr, NetLog::Source());
+ nullptr, NetLogSource());
IPAddress ip_address;
EXPECT_TRUE(ip_address.AssignFromIPLiteral(ip));
IPEndPoint remote_address(ip_address, 80);
@@ -610,7 +604,7 @@ TEST_F(UDPSocketTest, ServerSetDoNotFragment) {
LOG(INFO) << "ip: " << ip;
IPEndPoint bind_address;
CreateUDPAddress(ip, 0, &bind_address);
- UDPServerSocket server(nullptr, NetLog::Source());
+ UDPServerSocket server(nullptr, NetLogSource());
int rv = server.Listen(bind_address);
// May fail on IPv6 is IPv6 is not configure
if (bind_address.address().IsIPv6() && rv == ERR_ADDRESS_INVALID)
@@ -630,7 +624,7 @@ TEST_F(UDPSocketTest, ServerSetDoNotFragment) {
TEST_F(UDPSocketTest, CloseWithPendingRead) {
IPEndPoint bind_address;
CreateUDPAddress("127.0.0.1", 0, &bind_address);
- UDPServerSocket server(NULL, NetLog::Source());
+ UDPServerSocket server(NULL, NetLogSource());
int rv = server.Listen(bind_address);
EXPECT_THAT(rv, IsOk());
@@ -662,10 +656,8 @@ TEST_F(UDPSocketTest, MAYBE_JoinMulticastGroup) {
IPAddress group_ip;
EXPECT_TRUE(group_ip.AssignFromIPLiteral(kGroup));
- UDPSocket socket(DatagramSocket::DEFAULT_BIND,
- RandIntCallback(),
- NULL,
- NetLog::Source());
+ UDPSocket socket(DatagramSocket::DEFAULT_BIND, RandIntCallback(), NULL,
+ NetLogSource());
EXPECT_THAT(socket.Open(bind_address.GetFamily()), IsOk());
EXPECT_THAT(socket.Bind(bind_address), IsOk());
EXPECT_THAT(socket.JoinGroup(group_ip), IsOk());
@@ -683,10 +675,8 @@ TEST_F(UDPSocketTest, MulticastOptions) {
IPEndPoint bind_address;
CreateUDPAddress("0.0.0.0", kPort, &bind_address);
- UDPSocket socket(DatagramSocket::DEFAULT_BIND,
- RandIntCallback(),
- NULL,
- NetLog::Source());
+ UDPSocket socket(DatagramSocket::DEFAULT_BIND, RandIntCallback(), NULL,
+ NetLogSource());
// Before binding.
EXPECT_THAT(socket.SetMulticastLoopbackMode(false), IsOk());
EXPECT_THAT(socket.SetMulticastLoopbackMode(true), IsOk());
@@ -710,10 +700,8 @@ TEST_F(UDPSocketTest, MulticastOptions) {
TEST_F(UDPSocketTest, SetDSCP) {
// Setup the server to listen.
IPEndPoint bind_address;
- UDPSocket client(DatagramSocket::DEFAULT_BIND,
- RandIntCallback(),
- NULL,
- NetLog::Source());
+ UDPSocket client(DatagramSocket::DEFAULT_BIND, RandIntCallback(), NULL,
+ NetLogSource());
// We need a real IP, but we won't actually send anything to it.
CreateUDPAddress("8.8.8.8", 9999, &bind_address);
int rv = client.Open(bind_address.GetFamily());
@@ -738,7 +726,7 @@ TEST_F(UDPSocketTest, SetDSCP) {
TEST_F(UDPSocketTest, TestBindToNetwork) {
UDPSocket socket(DatagramSocket::RANDOM_BIND, base::Bind(&PrivilegedRand),
- NULL, NetLog::Source());
+ NULL, NetLogSource());
ASSERT_EQ(OK, socket.Open(ADDRESS_FAMILY_IPV4));
// Test unsuccessful binding, by attempting to bind to a bogus NetworkHandle.
int rv = socket.BindToNetwork(65536);
@@ -867,10 +855,8 @@ TEST_F(UDPSocketTest, SetDSCPFake) {
IPEndPoint bind_address;
// We need a real IP, but we won't actually send anything to it.
CreateUDPAddress("8.8.8.8", 9999, &bind_address);
- UDPSocket client(DatagramSocket::DEFAULT_BIND,
- RandIntCallback(),
- NULL,
- NetLog::Source());
+ UDPSocket client(DatagramSocket::DEFAULT_BIND, RandIntCallback(), NULL,
+ NetLogSource());
int rv = client.SetDiffServCodePoint(DSCP_AF41);
EXPECT_THAT(rv, IsError(ERR_SOCKET_NOT_CONNECTED));

Powered by Google App Engine
This is Rietveld 408576698