TEST_F(DocumentMarkerControllerTest, NodeWillBeRemovedByRemoveMarked)
{
    setBodyInnerHTML("<b><i>foo</i></b>");
    {
        Element* parent = toElement(document().body()->firstChild()->firstChild());
        markNodeContents(parent);
        EXPECT_EQ(1u, markerController().markers().size());
        parent->removeChild(parent->firstChild());
    }
    // No more reference to marked node.
    ThreadHeap::collectAllGarbage();
    EXPECT_EQ(0u, markerController().markers().size());
}
Example #2
0
TEST_F(DocumentMarkerControllerTest, NodeWillBeRemovedBySetInnerHTML)
{
    setBodyInnerHTML("<b><i>foo</i></b>");
    {
        RefPtrWillBeRawPtr<Element> parent = toElement(document().body()->firstChild()->firstChild());
        markNodeContents(parent);
        EXPECT_EQ(1u, markerController().markers().size());
        setBodyInnerHTML("");
    }
    // No more reference to marked node.
    Heap::collectAllGarbage();
    EXPECT_EQ(0u, markerController().markers().size());
}
Example #3
0
TEST_F(DocumentMarkerControllerTest, NodeWillBeRemovedMarkedByReplaceChild)
{
    setBodyInnerHTML("<b><i>foo</i></b>");
    {
        RefPtrWillBeRawPtr<Element> parent = toElement(document().body()->firstChild()->firstChild());
        markNodeContents(parent.get());
        EXPECT_EQ(1u, markerController().markers().size());
        parent->replaceChild(createTextNode("bar").get(), parent->firstChild());
    }
    // No more reference to marked node.
    Heap::collectAllGarbage();
    EXPECT_EQ(0u, markerController().markers().size());
}
TEST_F(DocumentMarkerControllerTest, DidMoveToNewDocument)
{
    setBodyInnerHTML("<b><i>foo</i></b>");
    RefPtrWillBeRawPtr<Element> parent = toElement(document().body()->firstChild()->firstChild());
    markNodeContents(parent.get());
    EXPECT_EQ(1u, markerController().markers().size());
    RefPtrWillBePersistent<Document> anotherDocument = Document::create();
    anotherDocument->adoptNode(parent.get(), ASSERT_NO_EXCEPTION);

    // No more reference to marked node.
    Heap::collectAllGarbage();
    EXPECT_EQ(0u, markerController().markers().size());
    EXPECT_EQ(0u, anotherDocument->markers().markers().size());
}
TEST_F(DocumentMarkerControllerTest, UpdateRenderedRectsForComposition)
{
    setBodyInnerHTML("<div style='margin: 100px'>foo</div>");
    Element* div = toElement(document().body()->firstChild());
    markNodeContentsWithComposition(div);
    Vector<IntRect> renderedRects = markerController().renderedRectsForMarkers(DocumentMarker::Composition);
    EXPECT_EQ(1u, renderedRects.size());

    div->setAttribute(HTMLNames::styleAttr, "margin: 200px");
    document().updateStyleAndLayout();
    Vector<IntRect> newRenderedRects = markerController().renderedRectsForMarkers(DocumentMarker::Composition);
    EXPECT_EQ(1u, newRenderedRects.size());
    EXPECT_NE(renderedRects[0], newRenderedRects[0]);
}
TEST_F(DocumentMarkerControllerTest, NodeWillBeRemovedMarkedByNormalize)
{
    setBodyInnerHTML("<b><i>foo</i></b>");
    {
        Element* parent = toElement(document().body()->firstChild()->firstChild());
        parent->appendChild(createTextNode("bar"));
        markNodeContents(parent);
        EXPECT_EQ(2u, markerController().markers().size());
        parent->normalize();
    }
    // No more reference to marked node.
    ThreadHeap::collectAllGarbage();
    EXPECT_EQ(1u, markerController().markers().size());
}
TEST_F(DocumentMarkerControllerTest, SetMarkerActiveTest)
{
    setBodyInnerHTML("<b>foo</b>");
    Element* bElement = toElement(document().body()->firstChild());
    EphemeralRange ephemeralRange = EphemeralRange::rangeOfContents(*bElement);
    Position startBElement = toPositionInDOMTree(ephemeralRange.startPosition());
    Position endBElement = toPositionInDOMTree(ephemeralRange.endPosition());
    Range* range = Range::create(document(), startBElement, endBElement);
    // Try to make active a marker that doesn't exist.
    EXPECT_FALSE(markerController().setMarkersActive(range, true));

    // Add a marker and try it once more.
    markerController().addTextMatchMarker(range, false);
    EXPECT_EQ(1u, markerController().markers().size());
    EXPECT_TRUE(markerController().setMarkersActive(range, true));
}
void DocumentMarkerControllerTest::markNodeContents(PassRefPtrWillBeRawPtr<Node> node)
{
    // Force layoutObjects to be created; TextIterator, which is used in
    // DocumentMarkerControllerTest::addMarker(), needs them.
    document().updateLayout();
    auto range = EphemeralRange::rangeOfContents(*node);
    markerController().addMarker(range.startPosition(), range.endPosition(), DocumentMarker::Spelling);
}
TEST_F(DocumentMarkerControllerTest, UpdateRenderedRects)
{
    LayoutRect invalidRect = RenderedDocumentMarker::create(DocumentMarker(0, 0, false))->renderedRect();

    setBodyInnerHTML("<div style='margin: 100px'>foo</div>");
    RefPtrWillBeRawPtr<Element> div = toElement(document().body()->firstChild());
    markNodeContents(div);
    Vector<IntRect> renderedRects = markerController().renderedRectsForMarkers(DocumentMarker::Spelling);
    EXPECT_EQ(1u, renderedRects.size());
    EXPECT_NE(invalidRect, renderedRects[0]);

    div->setAttribute(HTMLNames::styleAttr, "margin: 200px");
    document().updateLayout();
    Vector<IntRect> newRenderedRects = markerController().renderedRectsForMarkers(DocumentMarker::Spelling);
    EXPECT_EQ(1u, newRenderedRects.size());
    EXPECT_NE(renderedRects[0], newRenderedRects[0]);
}
void DocumentMarkerControllerTest::markNodeContentsWithComposition(Node* node)
{
    // Force layoutObjects to be created; TextIterator, which is used in
    // DocumentMarkerControllerTest::addMarker(), needs them.
    document().updateStyleAndLayout();
    auto range = EphemeralRange::rangeOfContents(*node);
    markerController().addCompositionMarker(range.startPosition(), range.endPosition(), Color::black, false, Color::black);
}