This source file includes following definitions.
- document
- markerController
- SetUp
- createTextNode
- markNodeContents
- setBodyInnerHTML
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "config.h"
#include "core/dom/DocumentMarkerController.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/dom/Document.h"
#include "core/dom/Range.h"
#include "core/dom/Text.h"
#include "core/html/HTMLElement.h"
#include "core/testing/DummyPageHolder.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefPtr.h"
#include "wtf/testing/WTFTestHelpers.h"
#include <gtest/gtest.h>
using namespace WebCore;
namespace {
class DocumentMarkerControllerTest : public ::testing::Test {
protected:
virtual void SetUp() OVERRIDE;
Document& document() const { return *m_document; }
DocumentMarkerController& markerController() const { return m_document->markers(); }
PassRefPtr<Text> createTextNode(const char*);
void markNodeContents(PassRefPtr<Node>);
void setBodyInnerHTML(const char*);
private:
OwnPtr<DummyPageHolder> m_dummyPageHolder;
Document* m_document;
};
void DocumentMarkerControllerTest::SetUp()
{
m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
m_document = &m_dummyPageHolder->document();
ASSERT(m_document);
}
PassRefPtr<Text> DocumentMarkerControllerTest::createTextNode(const char* textContents)
{
return document().createTextNode(String::fromUTF8(textContents));
}
void DocumentMarkerControllerTest::markNodeContents(PassRefPtr<Node> node)
{
document().updateLayout();
RefPtrWillBeRawPtr<Range> range = rangeOfContents(node.get());
markerController().addMarker(range.get(), DocumentMarker::Spelling);
}
void DocumentMarkerControllerTest::setBodyInnerHTML(const char* bodyContent)
{
document().body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXCEPTION);
}
TEST_F(DocumentMarkerControllerTest, NodeWillBeRemovedMarkedByNormalize)
{
setBodyInnerHTML("<b><i>foo</i></b>");
{
RefPtr<Element> parent = toElement(document().body()->firstChild()->firstChild());
parent->appendChild(createTextNode("bar").get());
markNodeContents(parent.get());
EXPECT_EQ(2u, markerController().markers().size());
parent->normalize();
}
Heap::collectAllGarbage(WebCore::ThreadState::NoHeapPointersOnStack);
EXPECT_EQ(1u, markerController().markers().size());
}
TEST_F(DocumentMarkerControllerTest, NodeWillBeRemovedMarkedByRemoveChildren)
{
setBodyInnerHTML("<b><i>foo</i></b>");
RefPtr<Element> parent = toElement(document().body()->firstChild()->firstChild());
markNodeContents(parent.get());
EXPECT_EQ(1u, markerController().markers().size());
parent->removeChildren();
Heap::collectAllGarbage(WebCore::ThreadState::NoHeapPointersOnStack);
EXPECT_EQ(0u, markerController().markers().size());
}
TEST_F(DocumentMarkerControllerTest, NodeWillBeRemovedByRemoveMarked)
{
setBodyInnerHTML("<b><i>foo</i></b>");
{
RefPtr<Element> parent = toElement(document().body()->firstChild()->firstChild());
markNodeContents(parent);
EXPECT_EQ(1u, markerController().markers().size());
parent->removeChild(parent->firstChild());
}
Heap::collectAllGarbage(WebCore::ThreadState::NoHeapPointersOnStack);
EXPECT_EQ(0u, markerController().markers().size());
}
TEST_F(DocumentMarkerControllerTest, NodeWillBeRemovedMarkedByRemoveAncestor)
{
setBodyInnerHTML("<b><i>foo</i></b>");
{
RefPtr<Element> parent = toElement(document().body()->firstChild()->firstChild());
markNodeContents(parent);
EXPECT_EQ(1u, markerController().markers().size());
parent->parentNode()->parentNode()->removeChild(parent->parentNode());
}
Heap::collectAllGarbage(WebCore::ThreadState::NoHeapPointersOnStack);
EXPECT_EQ(0u, markerController().markers().size());
}
TEST_F(DocumentMarkerControllerTest, NodeWillBeRemovedMarkedByRemoveParent)
{
setBodyInnerHTML("<b><i>foo</i></b>");
{
RefPtr<Element> parent = toElement(document().body()->firstChild()->firstChild());
markNodeContents(parent);
EXPECT_EQ(1u, markerController().markers().size());
parent->parentNode()->removeChild(parent.get());
}
Heap::collectAllGarbage(WebCore::ThreadState::NoHeapPointersOnStack);
EXPECT_EQ(0u, markerController().markers().size());
}
TEST_F(DocumentMarkerControllerTest, NodeWillBeRemovedMarkedByReplaceChild)
{
setBodyInnerHTML("<b><i>foo</i></b>");
{
RefPtr<Element> parent = toElement(document().body()->firstChild()->firstChild());
markNodeContents(parent.get());
EXPECT_EQ(1u, markerController().markers().size());
parent->replaceChild(createTextNode("bar").get(), parent->firstChild());
}
Heap::collectAllGarbage(WebCore::ThreadState::NoHeapPointersOnStack);
EXPECT_EQ(0u, markerController().markers().size());
}
TEST_F(DocumentMarkerControllerTest, NodeWillBeRemovedBySetInnerHTML)
{
setBodyInnerHTML("<b><i>foo</i></b>");
{
RefPtr<Element> parent = toElement(document().body()->firstChild()->firstChild());
markNodeContents(parent);
EXPECT_EQ(1u, markerController().markers().size());
setBodyInnerHTML("");
}
Heap::collectAllGarbage(WebCore::ThreadState::NoHeapPointersOnStack);
EXPECT_EQ(0u, markerController().markers().size());
}
}