chromium/services/network/udp_socket_unittest.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <stddef.h>
#include <stdint.h>

#include <limits>
#include <utility>

#include "services/network/udp_socket.h"

#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "net/base/net_errors.h"
#include "net/socket/udp_socket.h"
#include "net/traffic_annotation/network_traffic_annotation.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/public/mojom/udp_socket.mojom.h"
#include "services/network/socket_factory.h"
#include "services/network/test/udp_socket_test_util.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace network {

namespace {

const size_t kDatagramSize =;

class SocketWrapperTestImpl : public UDPSocket::SocketWrapper {};

net::IPEndPoint GetLocalHostWithAnyPort() {}

std::vector<uint8_t> CreateTestMessage(uint8_t initial, size_t size) {}

// A Mock UDPSocket that always returns net::ERR_IO_PENDING for SendTo()s.
class HangingUDPSocket : public SocketWrapperTestImpl {};

// A Mock UDPSocket that returns 0 byte read.
class ZeroByteReadUDPSocket : public SocketWrapperTestImpl {};

}  // namespace

class UDPSocketTest : public testing::Test {};

TEST_F(UDPSocketTest, Settings) {}

// Tests that Send() is used after Bind() is not supported. Send() should only
// be used after Connect().
TEST_F(UDPSocketTest, TestSendWithBind) {}

// Tests that when SendTo() is used after Connect() is not supported. SendTo()
// should only be used after Bind().
TEST_F(UDPSocketTest, TestSendToWithConnect) {}

// TODO(crbug.com/40653437): These two tests are very flaky on Fuchsia.
#if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_TestReadSendTo
#define MAYBE_TestUnexpectedSequences
#else
#define MAYBE_TestReadSendTo
#define MAYBE_TestUnexpectedSequences
#endif

// Tests that the sequence of calling Bind()/Connect() and setters is
// important.
TEST_F(UDPSocketTest, MAYBE_TestUnexpectedSequences) {}

// Tests that if the underlying socket implementation's Send() returned
// ERR_IO_PENDING, udp_socket.cc doesn't free the send buffer.
TEST_F(UDPSocketTest, TestBufferValid) {}

// Test that exercises the queuing of send requests and makes sure
// ERR_INSUFFICIENT_RESOURCES is returned appropriately.
TEST_F(UDPSocketTest, TestInsufficientResources) {}

TEST_F(UDPSocketTest, TestReceiveMoreOverflow) {}

TEST_F(UDPSocketTest, TestReadSend) {}

TEST_F(UDPSocketTest, MAYBE_TestReadSendTo) {}

TEST_F(UDPSocketTest, TestReceiveMoreWithBufferSize) {}

// Make sure passing an invalid net::IPEndPoint will be detected by
// serialization/deserialization in mojo.
TEST_F(UDPSocketTest, TestSendToInvalidAddress) {}

// Tests that it is legal for UDPSocketListener::OnReceive() to be called with
// 0 byte payload.
TEST_F(UDPSocketTest, TestReadZeroByte) {}

#if BUILDFLAG(IS_ANDROID)
// Some Android devices do not support multicast socket.
// The ones supporting multicast need WifiManager.MulticastLock to enable it.
// https://developer.android.com/reference/android/net/wifi/WifiManager.MulticastLock.html
#define MAYBE_JoinMulticastGroup
#else
#define MAYBE_JoinMulticastGroup
#endif  // BUILDFLAG(IS_ANDROID)
TEST_F(UDPSocketTest, MAYBE_JoinMulticastGroup) {}

TEST_F(UDPSocketTest, ErrorHappensDuringSocketOptionsConfiguration) {}

}  // namespace network