#include "base/scoped_observation.h"
#include "base/containers/contains.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/scoped_observation_traits.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace {
class TestSourceObserver { … };
class TestSource { … };
void TestSource::AddObserver(TestSourceObserver* observer) { … }
void TestSource::RemoveObserver(TestSourceObserver* observer) { … }
bool TestSource::HasObserver(TestSourceObserver* observer) const { … }
TestScopedObservation;
}
TEST(ScopedObservationTest, RemovesObservationOnDestruction) { … }
TEST(ScopedObservationTest, Reset) { … }
TEST(ScopedObservationTest, IsObserving) { … }
TEST(ScopedObservationTest, IsObservingSource) { … }
namespace {
class TestSourceWithNonDefaultNames { … };
TestScopedObservationWithNonDefaultNames;
}
template <>
struct ScopedObservationTraits<TestSourceWithNonDefaultNames,
TestSourceObserver> { … };
TEST(ScopedObservationTest, NonDefaultNames) { … }
namespace {
class TestSourceFwd;
class ObservationHolder : public TestSourceObserver { … };
class TestSourceFwd : public TestSource { … };
ObservationHolder::ObservationHolder(TestSourceFwd* source) { … }
}
TEST(ScopedObservationTest, ForwardDeclaredSource) { … }
namespace {
class TestSourceWithNonDefaultNamesFwd;
class ObservationWithNonDefaultNamesHolder : public TestSourceObserver { … };
class TestSourceWithNonDefaultNamesFwd : public TestSourceWithNonDefaultNames { … };
}
template <>
struct ScopedObservationTraits<TestSourceWithNonDefaultNamesFwd,
TestSourceObserver> { … };
namespace {
ObservationWithNonDefaultNamesHolder::ObservationWithNonDefaultNamesHolder(
TestSourceWithNonDefaultNamesFwd* source) { … }
}
TEST(ScopedObservationTest, ForwardDeclaredSourceWithNonDefaultNames) { … }
}