This source file includes following definitions.
- document
- page
- SetUp
- 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 DocumentTest : public ::testing::Test {
protected:
virtual void SetUp() OVERRIDE;
Document& document() const { return m_dummyPageHolder->document(); }
Page& page() const { return m_dummyPageHolder->page(); }
private:
OwnPtr<DummyPageHolder> m_dummyPageHolder;
};
void DocumentTest::SetUp()
{
m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
}
class MockDocumentVisibilityObserver : public DocumentVisibilityObserver {
public:
MockDocumentVisibilityObserver(Document& document) : DocumentVisibilityObserver(document) { }
MOCK_METHOD1(didChangeVisibilityState, void(PageVisibilityState));
};
TEST_F(DocumentTest, VisibilityOberver)
{
page().setVisibilityState(PageVisibilityStateVisible, true);
MockDocumentVisibilityObserver observer1(document());
{
MockDocumentVisibilityObserver observer2(document());
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateHidden)).Times(0);
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateVisible)).Times(0);
EXPECT_CALL(observer2, didChangeVisibilityState(PageVisibilityStateHidden)).Times(0);
EXPECT_CALL(observer2, didChangeVisibilityState(PageVisibilityStateVisible)).Times(0);
::testing::Mock::VerifyAndClearExpectations(&observer1);
::testing::Mock::VerifyAndClearExpectations(&observer2);
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateHidden)).Times(1);
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateVisible)).Times(0);
EXPECT_CALL(observer2, didChangeVisibilityState(PageVisibilityStateHidden)).Times(1);
EXPECT_CALL(observer2, didChangeVisibilityState(PageVisibilityStateVisible)).Times(0);
page().setVisibilityState(PageVisibilityStateHidden, false);
::testing::Mock::VerifyAndClearExpectations(&observer1);
::testing::Mock::VerifyAndClearExpectations(&observer2);
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateHidden)).Times(0);
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateVisible)).Times(0);
EXPECT_CALL(observer2, didChangeVisibilityState(PageVisibilityStateHidden)).Times(0);
EXPECT_CALL(observer2, didChangeVisibilityState(PageVisibilityStateVisible)).Times(0);
page().setVisibilityState(PageVisibilityStateHidden, false);
::testing::Mock::VerifyAndClearExpectations(&observer1);
::testing::Mock::VerifyAndClearExpectations(&observer2);
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateHidden)).Times(0);
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateVisible)).Times(1);
EXPECT_CALL(observer2, didChangeVisibilityState(PageVisibilityStateHidden)).Times(0);
EXPECT_CALL(observer2, didChangeVisibilityState(PageVisibilityStateVisible)).Times(0);
OwnPtr<DummyPageHolder> alternatePage = DummyPageHolder::create(IntSize(800, 600));
Document& alternateDocument = alternatePage->document();
observer2.setObservedDocument(alternateDocument);
page().setVisibilityState(PageVisibilityStateVisible, false);
::testing::Mock::VerifyAndClearExpectations(&observer1);
::testing::Mock::VerifyAndClearExpectations(&observer2);
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateHidden)).Times(1);
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateVisible)).Times(0);
EXPECT_CALL(observer2, didChangeVisibilityState(PageVisibilityStateHidden)).Times(1);
EXPECT_CALL(observer2, didChangeVisibilityState(PageVisibilityStateVisible)).Times(0);
observer2.setObservedDocument(document());
page().setVisibilityState(PageVisibilityStateHidden, false);
::testing::Mock::VerifyAndClearExpectations(&observer1);
::testing::Mock::VerifyAndClearExpectations(&observer2);
}
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateHidden)).Times(0);
EXPECT_CALL(observer1, didChangeVisibilityState(PageVisibilityStateVisible)).Times(1);
page().setVisibilityState(PageVisibilityStateVisible, false);
}
}