chromium/base/observer_list_threadsafe_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.

#include "base/observer_list_threadsafe.h"

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

#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/task_environment.h"
#include "base/test/test_waitable_event.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread_restrictions.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
namespace {

constexpr int kThreadRunTime =;  // ms to run the multi-threaded test.

class Foo {};

class Adder : public Foo {};

class AddInObserve : public Foo {};

// A task for use in the ThreadSafeObserver test which will add and remove
// itself from the notification list repeatedly.
template <RemoveObserverPolicy RemovePolicy =
              RemoveObserverPolicy::kAnySequence>
class AddRemoveThread : public Foo {};

}  // namespace

TEST(ObserverListThreadSafeTest, BasicTest) {}

TEST(ObserverListThreadSafeTest, RemoveObserver) {}

class FooRemover : public Foo {};

TEST(ObserverListThreadSafeTest, RemoveMultipleObservers) {}

// A test driver for a multi-threaded notification loop.  Runs a number of
// observer threads, each of which constantly adds/removes itself from the
// observer list.  Optionally, if `cross_thread_notifies` is set to true, the
// observer threads will also trigger notifications to all observers, and if
// `cross_thread_removes` is set to true, the observer threads will also remove
// observers added by other threads.
template <
    RemoveObserverPolicy RemovePolicy = RemoveObserverPolicy::kAnySequence>
static void ThreadSafeObserverHarness(int num_threads,
                                      bool cross_thread_notifies = false,
                                      bool cross_thread_removes = false) {}

TEST(ObserverListThreadSafeTest, CrossThreadObserver) {}

TEST(ObserverListThreadSafeTest, CrossThreadNotifications) {}

TEST(ObserverListThreadSafeTest, CrossThreadRemoval) {}

TEST(ObserverListThreadSafeTest, CrossThreadRemovalRestricted) {}

TEST(ObserverListThreadSafeDeathTest, CrossThreadRemovalRestricted) {}

TEST(ObserverListThreadSafeTest, OutlivesTaskEnvironment) {}

TEST(ObserverListThreadSafeTest, OutlivesTaskEnvironmentRemovalRestricted) {}

namespace {

class SequenceVerificationObserver : public Foo {};

}  // namespace

// Verify that observers are notified on the correct sequence.
TEST(ObserverListThreadSafeTest, NotificationOnValidSequence) {}

// Verify that when an observer is added to a NOTIFY_ALL ObserverListThreadSafe
// from a notification, it is itself notified.
TEST(ObserverListThreadSafeTest, AddObserverFromNotificationNotifyAll) {}

namespace {

class RemoveWhileNotificationIsRunningObserver : public Foo {};

}  // namespace

// Verify that there is no crash when an observer is removed while it is being
// notified.
TEST(ObserverListThreadSafeTest, RemoveWhileNotificationIsRunning) {}

TEST(ObserverListThreadSafeTest, AddRemoveWithPendingNotifications) {}

// Same as ObserverListTest.Existing, but for ObserverListThreadSafe
TEST(ObserverListThreadSafeTest, Existing) {}

}  // namespace base