This source file includes following definitions.
- srcDocument
- destDocument
- activeDOMObject
- m_activeDOMObject
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "config.h"
#include "core/dom/Document.h"
#include "core/testing/DummyPageHolder.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using namespace WebCore;
namespace {
class MockActiveDOMObject : public ActiveDOMObject {
public:
MockActiveDOMObject(ExecutionContext* context) : ActiveDOMObject(context) { }
MOCK_METHOD0(suspend, void());
MOCK_METHOD0(resume, void());
MOCK_METHOD0(stop, void());
};
class ActiveDOMObjectTest : public ::testing::Test {
protected:
ActiveDOMObjectTest();
Document& srcDocument() const { return m_srcPageHolder->document(); }
Document& destDocument() const { return m_destPageHolder->document(); }
MockActiveDOMObject& activeDOMObject() { return m_activeDOMObject; }
private:
OwnPtr<DummyPageHolder> m_srcPageHolder;
OwnPtr<DummyPageHolder> m_destPageHolder;
MockActiveDOMObject m_activeDOMObject;
};
ActiveDOMObjectTest::ActiveDOMObjectTest()
: m_srcPageHolder(DummyPageHolder::create(IntSize(800, 600)))
, m_destPageHolder(DummyPageHolder::create(IntSize(800, 600)))
, m_activeDOMObject(&m_srcPageHolder->document())
{
m_activeDOMObject.suspendIfNeeded();
}
TEST_F(ActiveDOMObjectTest, NewContextObserved)
{
unsigned initialSrcCount = srcDocument().activeDOMObjectCount();
unsigned initialDestCount = destDocument().activeDOMObjectCount();
EXPECT_CALL(activeDOMObject(), resume());
activeDOMObject().didMoveToNewExecutionContext(&destDocument());
EXPECT_EQ(initialSrcCount - 1, srcDocument().activeDOMObjectCount());
EXPECT_EQ(initialDestCount + 1, destDocument().activeDOMObjectCount());
}
TEST_F(ActiveDOMObjectTest, MoveToActiveDocument)
{
EXPECT_CALL(activeDOMObject(), resume());
activeDOMObject().didMoveToNewExecutionContext(&destDocument());
}
TEST_F(ActiveDOMObjectTest, MoveToSuspendedDocument)
{
destDocument().suspendScheduledTasks();
EXPECT_CALL(activeDOMObject(), suspend());
activeDOMObject().didMoveToNewExecutionContext(&destDocument());
}
TEST_F(ActiveDOMObjectTest, MoveToStoppedDocument)
{
destDocument().detach();
EXPECT_CALL(activeDOMObject(), stop());
activeDOMObject().didMoveToNewExecutionContext(&destDocument());
}
}