This source file includes following definitions.
- observerContext
- unobserverContext
- m_contextDestroyedCalled
- contextDestroyed
- unobserve
- TEST
- TEST
#include "config.h"
#include "platform/LifecycleContext.h"
#include "platform/LifecycleNotifier.h"
#include <gtest/gtest.h>
using namespace WebCore;
namespace {
class DummyContext : public LifecycleContext<DummyContext> {
};
}
namespace WebCore {
template<> void observerContext(DummyContext* context, LifecycleObserver<DummyContext>* observer)
{
context->wasObservedBy(observer);
}
template<> void unobserverContext(DummyContext* context, LifecycleObserver<DummyContext>* observer)
{
context->wasUnobservedBy(observer);
}
}
namespace {
class TestingObserver : public LifecycleObserver<DummyContext> {
public:
TestingObserver(DummyContext* context)
: LifecycleObserver<DummyContext>(context)
, m_contextDestroyedCalled(false)
{ }
virtual void contextDestroyed() OVERRIDE
{
LifecycleObserver<DummyContext>::contextDestroyed();
m_contextDestroyedCalled = true;
}
bool m_contextDestroyedCalled;
void unobserve() { observeContext(0); }
};
TEST(LifecycleContextTest, shouldObserveContextDestroyed)
{
OwnPtr<DummyContext> context = adoptPtr(new DummyContext());
OwnPtr<TestingObserver> observer = adoptPtr(new TestingObserver(context.get()));
EXPECT_EQ(observer->lifecycleContext(), context.get());
EXPECT_FALSE(observer->m_contextDestroyedCalled);
context.clear();
EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0));
EXPECT_TRUE(observer->m_contextDestroyedCalled);
}
TEST(LifecycleContextTest, shouldNotObserveContextDestroyedIfUnobserve)
{
OwnPtr<DummyContext> context = adoptPtr(new DummyContext());
OwnPtr<TestingObserver> observer = adoptPtr(new TestingObserver(context.get()));
observer->unobserve();
context.clear();
EXPECT_EQ(observer->lifecycleContext(), static_cast<DummyContext*>(0));
EXPECT_FALSE(observer->m_contextDestroyedCalled);
}
}