chromium/net/dns/mdns_client_unittest.cc

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

#include <memory>
#include <utility>
#include <vector>

#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/run_loop.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/simple_test_clock.h"
#include "base/time/clock.h"
#include "base/time/default_clock.h"
#include "base/timer/mock_timer.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
#include "net/base/address_family.h"
#include "net/base/completion_repeating_callback.h"
#include "net/base/ip_address.h"
#include "net/base/rand_callback.h"
#include "net/base/test_completion_callback.h"
#include "net/dns/mdns_client_impl.h"
#include "net/dns/mock_mdns_socket_factory.h"
#include "net/dns/record_rdata.h"
#include "net/log/net_log.h"
#include "net/socket/udp_client_socket.h"
#include "net/test/gtest_util.h"
#include "net/test/test_with_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

_;
Assign;
AtMost;
DoAll;
Exactly;
IgnoreResult;
Invoke;
InvokeWithoutArgs;
NiceMock;
Return;
SaveArg;
StrictMock;

namespace net {

namespace {

const uint8_t kSamplePacket1[] =;

const uint8_t kSamplePacket1WithCapitalization[] =;

const uint8_t kCorruptedPacketBadQuestion[] =;

const uint8_t kCorruptedPacketUnsalvagable[] =;

const uint8_t kCorruptedPacketDoubleRecord[] =;

const uint8_t kCorruptedPacketSalvagable[] =;

const uint8_t kSamplePacket2[] =;

const uint8_t kSamplePacket3[] =;

const uint8_t kQueryPacketPrivet[] =;

const uint8_t kQueryPacketPrivetWithCapitalization[] =;

const uint8_t kQueryPacketPrivetA[] =;

const uint8_t kSamplePacketAdditionalOnly[] =;

const uint8_t kSamplePacketNsec[] =;

const uint8_t kSamplePacketAPrivet[] =;

const uint8_t kSamplePacketGoodbye[] =;

std::string MakeString(const uint8_t* data, unsigned size) {}

class PtrRecordCopyContainer {};

class MockClock : public base::Clock {};

class MockTimer : public base::MockOneShotTimer {};

}  // namespace

class MDnsTest : public TestWithTaskEnvironment {};

class MockListenerDelegate : public MDnsListener::Delegate {};

void MDnsTest::SetUp() {}

void MDnsTest::SimulatePacketReceive(const uint8_t* packet, unsigned size) {}

void MDnsTest::ExpectPacket(const uint8_t* packet, unsigned size) {}

void MDnsTest::DeleteTransaction() {}

void MDnsTest::DeleteBothListeners() {}

void MDnsTest::RunFor(base::TimeDelta time_period) {}

void MDnsTest::Stop() {}

TEST_F(MDnsTest, PassiveListeners) {}

TEST_F(MDnsTest, PassiveListenersWithCapitalization) {}

TEST_F(MDnsTest, PassiveListenersCacheCleanup) {}

// Ensure that the cleanup task scheduler won't schedule cleanup tasks in the
// past if the system clock creeps past the expiration time while in the
// cleanup dispatcher.
TEST_F(MDnsTest, CacheCleanupWithShortTTL) {}

TEST_F(MDnsTest, StopListening) {}

TEST_F(MDnsTest, StopListening_CacheCleanupScheduled) {}

TEST_F(MDnsTest, MalformedPacket) {}

TEST_F(MDnsTest, TransactionWithEmptyCache) {}

TEST_F(MDnsTest, TransactionWithEmptyCacheAndCapitalization) {}

TEST_F(MDnsTest, TransactionCacheOnlyNoResult) {}

TEST_F(MDnsTest, TransactionWithCache) {}

TEST_F(MDnsTest, AdditionalRecords) {}

TEST_F(MDnsTest, TransactionTimeout) {}

TEST_F(MDnsTest, TransactionMultipleRecords) {}

TEST_F(MDnsTest, TransactionReentrantDelete) {}

TEST_F(MDnsTest, TransactionReentrantDeleteFromCache) {}

TEST_F(MDnsTest, TransactionReentrantCacheLookupStart) {}

TEST_F(MDnsTest, GoodbyePacketNotification) {}

TEST_F(MDnsTest, GoodbyePacketRemoval) {}

// In order to reliably test reentrant listener deletes, we create two listeners
// and have each of them delete both, so we're guaranteed to try and deliver a
// callback to at least one deleted listener.

TEST_F(MDnsTest, ListenerReentrantDelete) {}

ACTION_P(SaveIPAddress, ip_container) {}

TEST_F(MDnsTest, DoubleRecordDisagreeing) {}

TEST_F(MDnsTest, NsecWithListener) {}

TEST_F(MDnsTest, NsecWithTransactionFromNetwork) {}

TEST_F(MDnsTest, NsecWithTransactionFromCache) {}

TEST_F(MDnsTest, NsecConflictRemoval) {}

// TODO(crbug.com/40807339): Flaky on fuchsia.
#if BUILDFLAG(IS_FUCHSIA)
#define MAYBE_RefreshQuery
#else
#define MAYBE_RefreshQuery
#endif
TEST_F(MDnsTest, MAYBE_RefreshQuery) {}

// MDnsSocketFactory implementation that creates a single socket that will
// always fail on RecvFrom. Passing this to MdnsClient is expected to result in
// the client failing to start listening.
class FailingSocketFactory : public MDnsSocketFactory {};

TEST_F(MDnsTest, StartListeningFailure) {}

// Test that the cache is cleared when it gets filled to unreasonable sizes.
TEST_F(MDnsTest, ClearOverfilledCache) {}

// Note: These tests assume that the ipv4 socket will always be created first.
// This is a simplifying assumption based on the way the code works now.
class SimpleMockSocketFactory : public MDnsSocketFactory {};

class MockMDnsConnectionDelegate : public MDnsConnection::Delegate {};

class MDnsConnectionTest : public TestWithTaskEnvironment {};

TEST_F(MDnsConnectionTest, ReceiveSynchronous) {}

TEST_F(MDnsConnectionTest, ReceiveAsynchronous) {}

TEST_F(MDnsConnectionTest, Error) {}

class MDnsConnectionSendTest : public MDnsConnectionTest {};

TEST_F(MDnsConnectionSendTest, Send) {}

TEST_F(MDnsConnectionSendTest, SendError) {}

TEST_F(MDnsConnectionSendTest, SendQueued) {}

TEST(MDnsSocketTest, CreateSocket) {}

}  // namespace net