chromium/base/message_loop/fd_watch_controller_posix_unittest.cc

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

#include <sys/socket.h>

#include "base/compiler_specific.h"
#include "base/files/file_util.h"
#include "base/files/scoped_file.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_pump_for_io.h"
#include "base/posix/eintr_wrapper.h"
#include "base/run_loop.h"
#include "base/task/current_thread.h"
#include "base/test/gtest_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_ANDROID)
#include "base/message_loop/message_pump_epoll.h"
#endif

namespace base {

#if !BUILDFLAG(IS_NACL)

namespace {

class FdWatchControllerPosixTest : public testing::Test,
                                   public testing::WithParamInterface<bool> {};

class TestHandler : public MessagePumpForIO::FdWatcher {};

// Watcher that calls specified closures when read/write events occur. Verifies
// that each non-null closure passed to this class is called once and only once.
// Also resets the read event by reading from the FD.
class CallClosureHandler : public MessagePumpForIO::FdWatcher {};

TEST_P(FdWatchControllerPosixTest, FileDescriptorWatcherOutlivesMessageLoop) {}

TEST_P(FdWatchControllerPosixTest, FileDescriptorWatcherDoubleStop) {}

TEST_P(FdWatchControllerPosixTest, FileDescriptorWatcherDeleteInCallback) {}

// A watcher that owns its controller and will either delete itself or stop
// watching the FD after observing the specified event type.
class ReaderWriterHandler : public MessagePumpForIO::FdWatcher {};

class MessageLoopForIoPosixReadAndWriteTest
    : public testing::TestWithParam<ReaderWriterHandler::Action> {};

INSTANTIATE_TEST_SUITE_P();

// Test deleting or stopping watch after a read event for a watcher that is
// registered for both read and write.
TEST_P(MessageLoopForIoPosixReadAndWriteTest, AfterRead) {}

// Test deleting or stopping watch after a write event for a watcher that is
// registered for both read and write.
TEST_P(MessageLoopForIoPosixReadAndWriteTest, AfterWrite) {}

INSTANTIATE_TEST_SUITE_P();

// Verify that basic readable notification works.
TEST_P(FdWatchControllerPosixTest, WatchReadable) {}

// Verify that you can re-add the same FD with the same watcher.
TEST_P(FdWatchControllerPosixTest, WatchReadableTwiceSameWatcher) {}

// Verify that you can re-add the same FD with a different watcher.
TEST_P(FdWatchControllerPosixTest, WatchReadableTwiceDifferentWatcher) {}

// Verify that watching a file descriptor for writability succeeds.
TEST_P(FdWatchControllerPosixTest, WatchWritable) {}

// Verify that RunUntilIdle() receives IO notifications.
TEST_P(FdWatchControllerPosixTest, RunUntilIdle) {}

void StopWatching(MessagePumpForIO::FdWatchController* controller,
                  RunLoop* run_loop) {}

// Verify that StopWatchingFileDescriptor() works from an event handler.
TEST_P(FdWatchControllerPosixTest, StopFromHandler) {}

// Verify that non-persistent watcher is called only once.
TEST_P(FdWatchControllerPosixTest, NonPersistentWatcher) {}

// Verify that persistent watcher is called every time the event is triggered.
TEST_P(FdWatchControllerPosixTest, PersistentWatcher) {}

void StopWatchingAndWatchAgain(MessagePumpForIO::FdWatchController* controller,
                               int fd,
                               MessagePumpForIO::FdWatcher* new_handler,
                               RunLoop* run_loop) {}

// Verify that a watcher can be stopped and reused from an event handler.
TEST_P(FdWatchControllerPosixTest, StopAndRestartFromHandler) {}

// Verify that the pump properly handles a delayed task after an IO event.
TEST_P(FdWatchControllerPosixTest, IoEventThenTimer) {}

// Verify that the pipe can handle an IO event after a delayed task.
TEST_P(FdWatchControllerPosixTest, TimerThenIoEvent) {}

}  // namespace

#endif  // !BUILDFLAG(IS_NACL)

}  // namespace base