#include <stdint.h>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/unique_receiver_set.h"
#include "mojo/public/cpp/system/data_pipe_utils.h"
#include "mojo/public/cpp/system/simple_watcher.h"
#include "net/base/completion_once_callback.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/socket/server_socket.h"
#include "net/socket/socket_test_util.h"
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_builder.h"
#include "net/url_request/url_request_test_util.h"
#include "services/network/mojo_socket_test_util.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/tcp_socket.mojom-forward.h"
#include "services/network/public/mojom/tcp_socket.mojom.h"
#include "services/network/public/mojom/tls_socket.mojom.h"
#include "services/network/public/mojom/udp_socket.mojom.h"
#include "services/network/socket_factory.h"
#include "services/network/tcp_connected_socket.h"
#include "services/network/tcp_server_socket.h"
#include "services/network/test/test_socket_broker_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
#if BUILDFLAG(IS_MAC)
#include "base/mac/mac_util.h"
#endif
namespace network {
namespace {
class MockServerSocket : public net::ServerSocket { … };
class FailingServerSocket : public MockServerSocket { … };
class TestServer { … };
}
class TCPSocketTest : public testing::Test { … };
#if BUILDFLAG(IS_WIN)
TEST_F(TCPSocketTest, BrokerCreateTCPServerSocketSuccess) {
TestServer server;
server.StartWithBroker(1 , false );
}
TEST_F(TCPSocketTest, BrokerCreateTCPServerSocketFailure) {
TestServer server;
server.StartWithBroker(1 , true );
}
#endif
TEST_F(TCPSocketTest, ReadAndWrite) { … }
TEST_F(TCPSocketTest, CannotConnectToWrongInterface) { … }
TEST_F(TCPSocketTest, ServerReceivesMultipleAccept) { … }
TEST_F(TCPSocketTest, AcceptedSocketCantUpgradeToTLS) { … }
TEST_F(TCPSocketTest, SocketClosed) { … }
TEST_F(TCPSocketTest, ReadPipeClosed) { … }
TEST_F(TCPSocketTest, WritePipeClosed) { … }
TEST_F(TCPSocketTest, ServerSocketClosedAcceptedSocketAlive) { … }
class TCPSocketWithMockSocketTest
: public TCPSocketTest,
public ::testing::WithParamInterface<net::IoMode> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(TCPSocketWithMockSocketTest,
ServerAcceptClientConnectionWithMockSocket) { … }
TEST_P(TCPSocketWithMockSocketTest, ServerAcceptWithObserverReadError) { … }
TEST_P(TCPSocketWithMockSocketTest, ServerAcceptWithObserverWriteError) { … }
TEST_P(TCPSocketWithMockSocketTest, ReadAndWriteMultiple) { … }
TEST_P(TCPSocketWithMockSocketTest, PartialStreamSocketWrite) { … }
TEST_P(TCPSocketWithMockSocketTest, ReadError) { … }
TEST_P(TCPSocketWithMockSocketTest, WriteError) { … }
TEST_P(TCPSocketWithMockSocketTest, InitialTCPConnectedSocketOptions) { … }
TEST_P(TCPSocketWithMockSocketTest, InitialTCPConnectedSocketOptionsFails) { … }
TEST_P(TCPSocketWithMockSocketTest,
InitialTCPConnectedSocketSucceedsOnSecondAttempt) { … }
TEST_P(TCPSocketWithMockSocketTest, SetBufferSizes) { … }
TEST_P(TCPSocketWithMockSocketTest, SetBufferSizesFails) { … }
TEST_F(TCPSocketWithMockSocketTest, SetNoDelayAndKeepAlive) { … }
TEST_F(TCPSocketWithMockSocketTest, SetNoDelayFails) { … }
TEST_F(TCPSocketWithMockSocketTest, SetOptionsAfterTLSUpgrade) { … }
TEST_F(TCPSocketWithMockSocketTest, SocketDestroyedBeforeConnectCompletes) { … }
TEST(TCPServerSocketTest, GetLocalAddressFailedInListen) { … }
}