| Index: Source/core/editing/iterators/TextIteratorTest.cpp
|
| diff --git a/Source/core/editing/iterators/TextIteratorTest.cpp b/Source/core/editing/iterators/TextIteratorTest.cpp
|
| index a91da6483b17970e3f43667b439e5c5df79355b2..797ba51509ae3a32e9eb46f2b5ca8ba398b5d10c 100644
|
| --- a/Source/core/editing/iterators/TextIteratorTest.cpp
|
| +++ b/Source/core/editing/iterators/TextIteratorTest.cpp
|
| @@ -31,25 +31,8 @@
|
| #include "config.h"
|
| #include "core/editing/iterators/TextIterator.h"
|
|
|
| -#include "bindings/core/v8/ExceptionStatePlaceholder.h"
|
| -#include "core/dom/Document.h"
|
| -#include "core/dom/Element.h"
|
| -#include "core/dom/Node.h"
|
| -#include "core/dom/Range.h"
|
| -#include "core/dom/shadow/ShadowRoot.h"
|
| +#include "core/editing/EditingTestBase.h"
|
| #include "core/frame/FrameView.h"
|
| -#include "core/html/HTMLDocument.h"
|
| -#include "core/html/HTMLElement.h"
|
| -#include "core/testing/DummyPageHolder.h"
|
| -#include "platform/geometry/IntSize.h"
|
| -#include "wtf/Compiler.h"
|
| -#include "wtf/OwnPtr.h"
|
| -#include "wtf/PassRefPtr.h"
|
| -#include "wtf/RefPtr.h"
|
| -#include "wtf/StdLibExtras.h"
|
| -#include "wtf/testing/WTFTestHelpers.h"
|
| -#include <gtest/gtest.h>
|
| -#include <string>
|
|
|
| namespace blink {
|
|
|
| @@ -63,38 +46,21 @@ struct ComposedTree : ComposedTreeTraversal {
|
| using TextIteratorType = TextIteratorInComposedTree;
|
| };
|
|
|
| -class TextIteratorTest : public ::testing::Test {
|
| +class TextIteratorTest : public EditingTestBase {
|
| protected:
|
| - void SetUp() override;
|
| -
|
| - HTMLDocument& document() const { return *m_document; }
|
| -
|
| template <typename Tree>
|
| std::string iterate(TextIteratorBehavior = TextIteratorDefaultBehavior);
|
|
|
| template <typename Tree>
|
| std::string iteratePartial(const typename Tree::PositionType& start, const typename Tree::PositionType& end, TextIteratorBehavior = TextIteratorDefaultBehavior);
|
|
|
| - void setBodyInnerHTML(const char*);
|
| -
|
| PassRefPtrWillBeRawPtr<Range> getBodyRange() const;
|
|
|
| private:
|
| template <typename Tree>
|
| std::string iterateWithIterator(typename Tree::TextIteratorType&);
|
| -
|
| - OwnPtr<DummyPageHolder> m_dummyPageHolder;
|
| -
|
| - HTMLDocument* m_document;
|
| };
|
|
|
| -void TextIteratorTest::SetUp()
|
| -{
|
| - m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600));
|
| - m_document = toHTMLDocument(&m_dummyPageHolder->document());
|
| - ASSERT(m_document);
|
| -}
|
| -
|
| template <typename Tree>
|
| std::string TextIteratorTest::iterate(TextIteratorBehavior iteratorBehavior)
|
| {
|
| @@ -125,11 +91,6 @@ std::string TextIteratorTest::iterateWithIterator(typename Tree::TextIteratorTyp
|
| return std::string(textChunks.utf8().data());
|
| }
|
|
|
| -void TextIteratorTest::setBodyInnerHTML(const char* bodyContent)
|
| -{
|
| - document().body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXCEPTION);
|
| -}
|
| -
|
| PassRefPtrWillBeRawPtr<Range> TextIteratorTest::getBodyRange() const
|
| {
|
| RefPtrWillBeRawPtr<Range> range(Range::create(document()));
|
| @@ -137,13 +98,6 @@ PassRefPtrWillBeRawPtr<Range> TextIteratorTest::getBodyRange() const
|
| return range.release();
|
| }
|
|
|
| -static PassRefPtrWillBeRawPtr<ShadowRoot> createShadowRootForElementWithIDAndSetInnerHTML(TreeScope& scope, const char* hostElementID, const char* shadowRootContent)
|
| -{
|
| - RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicString::fromUTF8(hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION);
|
| - shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCEPTION);
|
| - return shadowRoot.release();
|
| -}
|
| -
|
| TEST_F(TextIteratorTest, BitStackOverflow)
|
| {
|
| const unsigned bitsInWord = sizeof(unsigned) * 8;
|
| @@ -160,7 +114,7 @@ TEST_F(TextIteratorTest, BitStackOverflow)
|
| TEST_F(TextIteratorTest, BasicIteration)
|
| {
|
| static const char* input = "<p>Hello, \ntext</p><p>iterator.</p>";
|
| - setBodyInnerHTML(input);
|
| + setBodyContent(input);
|
| EXPECT_EQ("[Hello, ][text][\n][\n][iterator.]", iterate<DOMTree>());
|
| EXPECT_EQ("[Hello, ][text][\n][\n][iterator.]", iterate<ComposedTree>());
|
| }
|
| @@ -168,7 +122,7 @@ TEST_F(TextIteratorTest, BasicIteration)
|
| TEST_F(TextIteratorTest, IgnoreAltTextInTextControls)
|
| {
|
| static const char* input = "<p>Hello <input type='text' value='value'>!</p>";
|
| - setBodyInnerHTML(input);
|
| + setBodyContent(input);
|
| EXPECT_EQ("[Hello ][][!]", iterate<DOMTree>(TextIteratorEmitsImageAltText));
|
| EXPECT_EQ("[Hello ][][\n][value][\n][!]", iterate<ComposedTree>(TextIteratorEmitsImageAltText));
|
| }
|
| @@ -176,7 +130,7 @@ TEST_F(TextIteratorTest, IgnoreAltTextInTextControls)
|
| TEST_F(TextIteratorTest, DisplayAltTextInImageControls)
|
| {
|
| static const char* input = "<p>Hello <input type='image' alt='alt'>!</p>";
|
| - setBodyInnerHTML(input);
|
| + setBodyContent(input);
|
| EXPECT_EQ("[Hello ][alt][!]", iterate<DOMTree>(TextIteratorEmitsImageAltText));
|
| EXPECT_EQ("[Hello ][alt][!]", iterate<ComposedTree>(TextIteratorEmitsImageAltText));
|
| }
|
| @@ -184,7 +138,7 @@ TEST_F(TextIteratorTest, DisplayAltTextInImageControls)
|
| TEST_F(TextIteratorTest, NotEnteringTextControls)
|
| {
|
| static const char* input = "<p>Hello <input type='text' value='input'>!</p>";
|
| - setBodyInnerHTML(input);
|
| + setBodyContent(input);
|
| EXPECT_EQ("[Hello ][][!]", iterate<DOMTree>());
|
| EXPECT_EQ("[Hello ][][\n][input][\n][!]", iterate<ComposedTree>());
|
| }
|
| @@ -192,7 +146,7 @@ TEST_F(TextIteratorTest, NotEnteringTextControls)
|
| TEST_F(TextIteratorTest, EnteringTextControlsWithOption)
|
| {
|
| static const char* input = "<p>Hello <input type='text' value='input'>!</p>";
|
| - setBodyInnerHTML(input);
|
| + setBodyContent(input);
|
| EXPECT_EQ("[Hello ][\n][input][!]", iterate<DOMTree>(TextIteratorEntersTextControls));
|
| EXPECT_EQ("[Hello ][][\n][input][\n][!]", iterate<ComposedTree>(TextIteratorEntersTextControls));
|
| }
|
| @@ -200,7 +154,7 @@ TEST_F(TextIteratorTest, EnteringTextControlsWithOption)
|
| TEST_F(TextIteratorTest, EnteringTextControlsWithOptionComplex)
|
| {
|
| static const char* input = "<input type='text' value='Beginning of range'><div><div><input type='text' value='Under DOM nodes'></div></div><input type='text' value='End of range'>";
|
| - setBodyInnerHTML(input);
|
| + setBodyContent(input);
|
| EXPECT_EQ("[\n][Beginning of range][\n][Under DOM nodes][\n][End of range]", iterate<DOMTree>(TextIteratorEntersTextControls));
|
| EXPECT_EQ("[][\n][Beginning of range][\n][][\n][Under DOM nodes][\n][][\n][End of range]", iterate<ComposedTree>(TextIteratorEntersTextControls));
|
| }
|
| @@ -211,7 +165,7 @@ TEST_F(TextIteratorTest, NotEnteringTextControlHostingShadowTreeEvenWithOption)
|
| static const char* shadowContent = "<span>shadow</span>";
|
| // TextIterator doesn't emit "input" nor "shadow" since (1) the layoutObject for <input> is not created; and
|
| // (2) we don't (yet) recurse into shadow trees.
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| createShadowRootForElementWithIDAndSetInnerHTML(document(), "input", shadowContent);
|
| // FIXME: Why is an empty string emitted here?
|
| EXPECT_EQ("[Hello, ][][ iterator.]", iterate<DOMTree>());
|
| @@ -222,7 +176,7 @@ TEST_F(TextIteratorTest, NotEnteringShadowTree)
|
| {
|
| static const char* bodyContent = "<div>Hello, <span id='host'>text</span> iterator.</div>";
|
| static const char* shadowContent = "<span>shadow</span>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent);
|
| // TextIterator doesn't emit "text" since its layoutObject is not created. The shadow tree is ignored.
|
| EXPECT_EQ("[Hello, ][ iterator.]", iterate<DOMTree>());
|
| @@ -234,7 +188,7 @@ TEST_F(TextIteratorTest, NotEnteringShadowTreeWithMultipleShadowTrees)
|
| static const char* bodyContent = "<div>Hello, <span id='host'>text</span> iterator.</div>";
|
| static const char* shadowContent1 = "<span>first shadow</span>";
|
| static const char* shadowContent2 = "<span>second shadow</span>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent1);
|
| createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent2);
|
| EXPECT_EQ("[Hello, ][ iterator.]", iterate<DOMTree>());
|
| @@ -246,7 +200,7 @@ TEST_F(TextIteratorTest, NotEnteringShadowTreeWithNestedShadowTrees)
|
| static const char* bodyContent = "<div>Hello, <span id='host-in-document'>text</span> iterator.</div>";
|
| static const char* shadowContent1 = "<span>first <span id='host-in-shadow'>shadow</span></span>";
|
| static const char* shadowContent2 = "<span>second shadow</span>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = createShadowRootForElementWithIDAndSetInnerHTML(document(), "host-in-document", shadowContent1);
|
| createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host-in-shadow", shadowContent2);
|
| EXPECT_EQ("[Hello, ][ iterator.]", iterate<DOMTree>());
|
| @@ -257,7 +211,7 @@ TEST_F(TextIteratorTest, NotEnteringShadowTreeWithContentInsertionPoint)
|
| {
|
| static const char* bodyContent = "<div>Hello, <span id='host'>text</span> iterator.</div>";
|
| static const char* shadowContent = "<span>shadow <content>content</content></span>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent);
|
| // In this case a layoutObject for "text" is created, so it shows up here.
|
| EXPECT_EQ("[Hello, ][text][ iterator.]", iterate<DOMTree>());
|
| @@ -268,7 +222,7 @@ TEST_F(TextIteratorTest, EnteringShadowTreeWithOption)
|
| {
|
| static const char* bodyContent = "<div>Hello, <span id='host'>text</span> iterator.</div>";
|
| static const char* shadowContent = "<span>shadow</span>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent);
|
| // TextIterator emits "shadow" since TextIteratorEntersOpenShadowRoots is specified.
|
| EXPECT_EQ("[Hello, ][shadow][ iterator.]", iterate<DOMTree>(TextIteratorEntersOpenShadowRoots));
|
| @@ -280,7 +234,7 @@ TEST_F(TextIteratorTest, EnteringShadowTreeWithMultipleShadowTreesWithOption)
|
| static const char* bodyContent = "<div>Hello, <span id='host'>text</span> iterator.</div>";
|
| static const char* shadowContent1 = "<span>first shadow</span>";
|
| static const char* shadowContent2 = "<span>second shadow</span>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent1);
|
| createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent2);
|
| // The first isn't emitted because a layoutObject for the first is not created.
|
| @@ -293,7 +247,7 @@ TEST_F(TextIteratorTest, EnteringShadowTreeWithNestedShadowTreesWithOption)
|
| static const char* bodyContent = "<div>Hello, <span id='host-in-document'>text</span> iterator.</div>";
|
| static const char* shadowContent1 = "<span>first <span id='host-in-shadow'>shadow</span></span>";
|
| static const char* shadowContent2 = "<span>second shadow</span>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = createShadowRootForElementWithIDAndSetInnerHTML(document(), "host-in-document", shadowContent1);
|
| createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host-in-shadow", shadowContent2);
|
| EXPECT_EQ("[Hello, ][first ][second shadow][ iterator.]", iterate<DOMTree>(TextIteratorEntersOpenShadowRoots));
|
| @@ -307,7 +261,7 @@ TEST_F(TextIteratorTest, EnteringShadowTreeWithContentInsertionPointWithOption)
|
| // In this case a layoutObject for "text" is created, and emitted AFTER any nodes in the shadow tree.
|
| // This order does not match the order of the rendered texts, but at this moment it's the expected behavior.
|
| // FIXME: Fix this. We probably need pure-renderer-based implementation of TextIterator to achieve this.
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent);
|
| EXPECT_EQ("[Hello, ][ shadow][text][ iterator.]", iterate<DOMTree>(TextIteratorEntersOpenShadowRoots));
|
| EXPECT_EQ("[Hello, ][text][ shadow][ iterator.]", iterate<ComposedTree>(TextIteratorEntersOpenShadowRoots));
|
| @@ -317,7 +271,7 @@ TEST_F(TextIteratorTest, StartingAtNodeInShadowRoot)
|
| {
|
| static const char* bodyContent = "<div id='outer'>Hello, <span id='host'>text</span> iterator.</div>";
|
| static const char* shadowContent = "<span><content>content</content> shadow</span>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent);
|
| Node* outerDiv = document().getElementById("outer");
|
| Node* spanInShadow = shadowRoot->firstChild();
|
| @@ -334,7 +288,7 @@ TEST_F(TextIteratorTest, FinishingAtNodeInShadowRoot)
|
| {
|
| static const char* bodyContent = "<div id='outer'>Hello, <span id='host'>text</span> iterator.</div>";
|
| static const char* shadowContent = "<span><content>content</content> shadow</span>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent);
|
| Node* outerDiv = document().getElementById("outer");
|
| Node* spanInShadow = shadowRoot->firstChild();
|
| @@ -353,7 +307,7 @@ TEST_F(TextIteratorTest, FullyClipsContents)
|
| "<div style='overflow: hidden; width: 200px; height: 0;'>"
|
| "I'm invisible"
|
| "</div>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| EXPECT_EQ("", iterate<DOMTree>());
|
| EXPECT_EQ("", iterate<ComposedTree>());
|
| }
|
| @@ -367,7 +321,7 @@ TEST_F(TextIteratorTest, IgnoresContainerClip)
|
| "but I am!"
|
| "</div>"
|
| "</div>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| EXPECT_EQ("[but I am!]", iterate<DOMTree>());
|
| EXPECT_EQ("[but I am!]", iterate<ComposedTree>());
|
| }
|
| @@ -382,7 +336,7 @@ TEST_F(TextIteratorTest, FullyClippedContentsDistributed)
|
| "<div style='overflow: hidden; width: 200px; height: 0;'>"
|
| "<content></content>"
|
| "</div>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent);
|
| // FIXME: The text below is actually invisible but TextIterator currently thinks it's visible.
|
| EXPECT_EQ("[\n][Am I visible?]", iterate<DOMTree>(TextIteratorEntersOpenShadowRoots));
|
| @@ -399,7 +353,7 @@ TEST_F(TextIteratorTest, IgnoresContainersClipDistributed)
|
| "<div style='position: absolute; width: 200px; height: 200px; top: 0; right: 0;'>"
|
| "<content></content>"
|
| "</div>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowContent);
|
| // FIXME: The text below is actually visible but TextIterator currently thinks it's invisible.
|
| // [\n][Nobody can find me!]
|
| @@ -410,7 +364,7 @@ TEST_F(TextIteratorTest, IgnoresContainersClipDistributed)
|
| TEST_F(TextIteratorTest, FindPlainTextInvalidTarget)
|
| {
|
| static const char* bodyContent = "<div>foo bar test</div>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| RefPtrWillBeRawPtr<Range> range = getBodyRange();
|
|
|
| RefPtrWillBeRawPtr<Range> expectedRange = range->cloneRange();
|
| @@ -449,7 +403,7 @@ TEST_F(TextIteratorTest, EmitsReplacementCharForInput)
|
| "<img src='foo.png'>"
|
| "After"
|
| "</div>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| EXPECT_EQ("[Before][\xEF\xBF\xBC][After]", iterate<DOMTree>(TextIteratorEmitsObjectReplacementCharacter));
|
| EXPECT_EQ("[Before][\xEF\xBF\xBC][After]", iterate<ComposedTree>(TextIteratorEmitsObjectReplacementCharacter));
|
| }
|
| @@ -458,7 +412,7 @@ TEST_F(TextIteratorTest, RangeLengthWithReplacedElements)
|
| {
|
| static const char* bodyContent =
|
| "<div id='div' contenteditable='true'>1<img src='foo.png'>3</div>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| document().view()->updateLayoutAndStyleForPainting();
|
|
|
| Node* divNode = document().getElementById("div");
|
| @@ -471,7 +425,7 @@ TEST_F(TextIteratorTest, SubrangeWithReplacedElements)
|
| {
|
| static const char* bodyContent =
|
| "<div id='div' contenteditable='true'>1<img src='foo.png'>345</div>";
|
| - setBodyInnerHTML(bodyContent);
|
| + setBodyContent(bodyContent);
|
| document().view()->updateLayoutAndStyleForPainting();
|
|
|
| Node* divNode = document().getElementById("div");
|
|
|