| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/editing/iterators/TextIterator.h" | 32 #include "core/editing/iterators/TextIterator.h" |
| 33 | 33 |
| 34 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 34 #include "core/editing/EditingTestBase.h" |
| 35 #include "core/dom/Document.h" | |
| 36 #include "core/dom/Element.h" | |
| 37 #include "core/dom/Node.h" | |
| 38 #include "core/dom/Range.h" | |
| 39 #include "core/dom/shadow/ShadowRoot.h" | |
| 40 #include "core/frame/FrameView.h" | 35 #include "core/frame/FrameView.h" |
| 41 #include "core/html/HTMLDocument.h" | |
| 42 #include "core/html/HTMLElement.h" | |
| 43 #include "core/testing/DummyPageHolder.h" | |
| 44 #include "platform/geometry/IntSize.h" | |
| 45 #include "wtf/Compiler.h" | |
| 46 #include "wtf/OwnPtr.h" | |
| 47 #include "wtf/PassRefPtr.h" | |
| 48 #include "wtf/RefPtr.h" | |
| 49 #include "wtf/StdLibExtras.h" | |
| 50 #include "wtf/testing/WTFTestHelpers.h" | |
| 51 #include <gtest/gtest.h> | |
| 52 #include <string> | |
| 53 | 36 |
| 54 namespace blink { | 37 namespace blink { |
| 55 | 38 |
| 56 struct DOMTree : NodeTraversal { | 39 struct DOMTree : NodeTraversal { |
| 57 using PositionType = Position; | 40 using PositionType = Position; |
| 58 using TextIteratorType = TextIterator; | 41 using TextIteratorType = TextIterator; |
| 59 }; | 42 }; |
| 60 | 43 |
| 61 struct ComposedTree : ComposedTreeTraversal { | 44 struct ComposedTree : ComposedTreeTraversal { |
| 62 using PositionType = PositionInComposedTree; | 45 using PositionType = PositionInComposedTree; |
| 63 using TextIteratorType = TextIteratorInComposedTree; | 46 using TextIteratorType = TextIteratorInComposedTree; |
| 64 }; | 47 }; |
| 65 | 48 |
| 66 class TextIteratorTest : public ::testing::Test { | 49 class TextIteratorTest : public EditingTestBase { |
| 67 protected: | 50 protected: |
| 68 void SetUp() override; | |
| 69 | |
| 70 HTMLDocument& document() const { return *m_document; } | |
| 71 | |
| 72 template <typename Tree> | 51 template <typename Tree> |
| 73 std::string iterate(TextIteratorBehavior = TextIteratorDefaultBehavior); | 52 std::string iterate(TextIteratorBehavior = TextIteratorDefaultBehavior); |
| 74 | 53 |
| 75 template <typename Tree> | 54 template <typename Tree> |
| 76 std::string iteratePartial(const typename Tree::PositionType& start, const t
ypename Tree::PositionType& end, TextIteratorBehavior = TextIteratorDefaultBehav
ior); | 55 std::string iteratePartial(const typename Tree::PositionType& start, const t
ypename Tree::PositionType& end, TextIteratorBehavior = TextIteratorDefaultBehav
ior); |
| 77 | 56 |
| 78 void setBodyInnerHTML(const char*); | |
| 79 | |
| 80 PassRefPtrWillBeRawPtr<Range> getBodyRange() const; | 57 PassRefPtrWillBeRawPtr<Range> getBodyRange() const; |
| 81 | 58 |
| 82 private: | 59 private: |
| 83 template <typename Tree> | 60 template <typename Tree> |
| 84 std::string iterateWithIterator(typename Tree::TextIteratorType&); | 61 std::string iterateWithIterator(typename Tree::TextIteratorType&); |
| 85 | |
| 86 OwnPtr<DummyPageHolder> m_dummyPageHolder; | |
| 87 | |
| 88 HTMLDocument* m_document; | |
| 89 }; | 62 }; |
| 90 | 63 |
| 91 void TextIteratorTest::SetUp() | |
| 92 { | |
| 93 m_dummyPageHolder = DummyPageHolder::create(IntSize(800, 600)); | |
| 94 m_document = toHTMLDocument(&m_dummyPageHolder->document()); | |
| 95 ASSERT(m_document); | |
| 96 } | |
| 97 | |
| 98 template <typename Tree> | 64 template <typename Tree> |
| 99 std::string TextIteratorTest::iterate(TextIteratorBehavior iteratorBehavior) | 65 std::string TextIteratorTest::iterate(TextIteratorBehavior iteratorBehavior) |
| 100 { | 66 { |
| 101 RefPtrWillBeRawPtr<Element> body = document().body(); | 67 RefPtrWillBeRawPtr<Element> body = document().body(); |
| 102 using PositionType = typename Tree::PositionType; | 68 using PositionType = typename Tree::PositionType; |
| 103 auto start = PositionType(body, 0, PositionType::PositionIsOffsetInAnchor); | 69 auto start = PositionType(body, 0, PositionType::PositionIsOffsetInAnchor); |
| 104 auto end = PositionType(body, Tree::countChildren(*body), PositionType::Posi
tionIsOffsetInAnchor); | 70 auto end = PositionType(body, Tree::countChildren(*body), PositionType::Posi
tionIsOffsetInAnchor); |
| 105 typename Tree::TextIteratorType iterator(start, end, iteratorBehavior); | 71 typename Tree::TextIteratorType iterator(start, end, iteratorBehavior); |
| 106 return iterateWithIterator<Tree>(iterator); | 72 return iterateWithIterator<Tree>(iterator); |
| 107 } | 73 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 118 { | 84 { |
| 119 String textChunks; | 85 String textChunks; |
| 120 for (; !iterator.atEnd(); iterator.advance()) { | 86 for (; !iterator.atEnd(); iterator.advance()) { |
| 121 textChunks.append('['); | 87 textChunks.append('['); |
| 122 textChunks.append(iterator.text().substring(0, iterator.text().length())
); | 88 textChunks.append(iterator.text().substring(0, iterator.text().length())
); |
| 123 textChunks.append(']'); | 89 textChunks.append(']'); |
| 124 } | 90 } |
| 125 return std::string(textChunks.utf8().data()); | 91 return std::string(textChunks.utf8().data()); |
| 126 } | 92 } |
| 127 | 93 |
| 128 void TextIteratorTest::setBodyInnerHTML(const char* bodyContent) | |
| 129 { | |
| 130 document().body()->setInnerHTML(String::fromUTF8(bodyContent), ASSERT_NO_EXC
EPTION); | |
| 131 } | |
| 132 | |
| 133 PassRefPtrWillBeRawPtr<Range> TextIteratorTest::getBodyRange() const | 94 PassRefPtrWillBeRawPtr<Range> TextIteratorTest::getBodyRange() const |
| 134 { | 95 { |
| 135 RefPtrWillBeRawPtr<Range> range(Range::create(document())); | 96 RefPtrWillBeRawPtr<Range> range(Range::create(document())); |
| 136 range->selectNode(document().body()); | 97 range->selectNode(document().body()); |
| 137 return range.release(); | 98 return range.release(); |
| 138 } | 99 } |
| 139 | 100 |
| 140 static PassRefPtrWillBeRawPtr<ShadowRoot> createShadowRootForElementWithIDAndSet
InnerHTML(TreeScope& scope, const char* hostElementID, const char* shadowRootCon
tent) | |
| 141 { | |
| 142 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = scope.getElementById(AtomicStrin
g::fromUTF8(hostElementID))->createShadowRoot(ASSERT_NO_EXCEPTION); | |
| 143 shadowRoot->setInnerHTML(String::fromUTF8(shadowRootContent), ASSERT_NO_EXCE
PTION); | |
| 144 return shadowRoot.release(); | |
| 145 } | |
| 146 | |
| 147 TEST_F(TextIteratorTest, BitStackOverflow) | 101 TEST_F(TextIteratorTest, BitStackOverflow) |
| 148 { | 102 { |
| 149 const unsigned bitsInWord = sizeof(unsigned) * 8; | 103 const unsigned bitsInWord = sizeof(unsigned) * 8; |
| 150 BitStack bs; | 104 BitStack bs; |
| 151 | 105 |
| 152 for (unsigned i = 0; i < bitsInWord + 1u; i++) | 106 for (unsigned i = 0; i < bitsInWord + 1u; i++) |
| 153 bs.push(true); | 107 bs.push(true); |
| 154 | 108 |
| 155 bs.pop(); | 109 bs.pop(); |
| 156 | 110 |
| 157 EXPECT_TRUE(bs.top()); | 111 EXPECT_TRUE(bs.top()); |
| 158 } | 112 } |
| 159 | 113 |
| 160 TEST_F(TextIteratorTest, BasicIteration) | 114 TEST_F(TextIteratorTest, BasicIteration) |
| 161 { | 115 { |
| 162 static const char* input = "<p>Hello, \ntext</p><p>iterator.</p>"; | 116 static const char* input = "<p>Hello, \ntext</p><p>iterator.</p>"; |
| 163 setBodyInnerHTML(input); | 117 setBodyContent(input); |
| 164 EXPECT_EQ("[Hello, ][text][\n][\n][iterator.]", iterate<DOMTree>()); | 118 EXPECT_EQ("[Hello, ][text][\n][\n][iterator.]", iterate<DOMTree>()); |
| 165 EXPECT_EQ("[Hello, ][text][\n][\n][iterator.]", iterate<ComposedTree>()); | 119 EXPECT_EQ("[Hello, ][text][\n][\n][iterator.]", iterate<ComposedTree>()); |
| 166 } | 120 } |
| 167 | 121 |
| 168 TEST_F(TextIteratorTest, IgnoreAltTextInTextControls) | 122 TEST_F(TextIteratorTest, IgnoreAltTextInTextControls) |
| 169 { | 123 { |
| 170 static const char* input = "<p>Hello <input type='text' value='value'>!</p>"
; | 124 static const char* input = "<p>Hello <input type='text' value='value'>!</p>"
; |
| 171 setBodyInnerHTML(input); | 125 setBodyContent(input); |
| 172 EXPECT_EQ("[Hello ][][!]", iterate<DOMTree>(TextIteratorEmitsImageAltText)); | 126 EXPECT_EQ("[Hello ][][!]", iterate<DOMTree>(TextIteratorEmitsImageAltText)); |
| 173 EXPECT_EQ("[Hello ][][\n][value][\n][!]", iterate<ComposedTree>(TextIterator
EmitsImageAltText)); | 127 EXPECT_EQ("[Hello ][][\n][value][\n][!]", iterate<ComposedTree>(TextIterator
EmitsImageAltText)); |
| 174 } | 128 } |
| 175 | 129 |
| 176 TEST_F(TextIteratorTest, DisplayAltTextInImageControls) | 130 TEST_F(TextIteratorTest, DisplayAltTextInImageControls) |
| 177 { | 131 { |
| 178 static const char* input = "<p>Hello <input type='image' alt='alt'>!</p>"; | 132 static const char* input = "<p>Hello <input type='image' alt='alt'>!</p>"; |
| 179 setBodyInnerHTML(input); | 133 setBodyContent(input); |
| 180 EXPECT_EQ("[Hello ][alt][!]", iterate<DOMTree>(TextIteratorEmitsImageAltText
)); | 134 EXPECT_EQ("[Hello ][alt][!]", iterate<DOMTree>(TextIteratorEmitsImageAltText
)); |
| 181 EXPECT_EQ("[Hello ][alt][!]", iterate<ComposedTree>(TextIteratorEmitsImageAl
tText)); | 135 EXPECT_EQ("[Hello ][alt][!]", iterate<ComposedTree>(TextIteratorEmitsImageAl
tText)); |
| 182 } | 136 } |
| 183 | 137 |
| 184 TEST_F(TextIteratorTest, NotEnteringTextControls) | 138 TEST_F(TextIteratorTest, NotEnteringTextControls) |
| 185 { | 139 { |
| 186 static const char* input = "<p>Hello <input type='text' value='input'>!</p>"
; | 140 static const char* input = "<p>Hello <input type='text' value='input'>!</p>"
; |
| 187 setBodyInnerHTML(input); | 141 setBodyContent(input); |
| 188 EXPECT_EQ("[Hello ][][!]", iterate<DOMTree>()); | 142 EXPECT_EQ("[Hello ][][!]", iterate<DOMTree>()); |
| 189 EXPECT_EQ("[Hello ][][\n][input][\n][!]", iterate<ComposedTree>()); | 143 EXPECT_EQ("[Hello ][][\n][input][\n][!]", iterate<ComposedTree>()); |
| 190 } | 144 } |
| 191 | 145 |
| 192 TEST_F(TextIteratorTest, EnteringTextControlsWithOption) | 146 TEST_F(TextIteratorTest, EnteringTextControlsWithOption) |
| 193 { | 147 { |
| 194 static const char* input = "<p>Hello <input type='text' value='input'>!</p>"
; | 148 static const char* input = "<p>Hello <input type='text' value='input'>!</p>"
; |
| 195 setBodyInnerHTML(input); | 149 setBodyContent(input); |
| 196 EXPECT_EQ("[Hello ][\n][input][!]", iterate<DOMTree>(TextIteratorEntersTextC
ontrols)); | 150 EXPECT_EQ("[Hello ][\n][input][!]", iterate<DOMTree>(TextIteratorEntersTextC
ontrols)); |
| 197 EXPECT_EQ("[Hello ][][\n][input][\n][!]", iterate<ComposedTree>(TextIterator
EntersTextControls)); | 151 EXPECT_EQ("[Hello ][][\n][input][\n][!]", iterate<ComposedTree>(TextIterator
EntersTextControls)); |
| 198 } | 152 } |
| 199 | 153 |
| 200 TEST_F(TextIteratorTest, EnteringTextControlsWithOptionComplex) | 154 TEST_F(TextIteratorTest, EnteringTextControlsWithOptionComplex) |
| 201 { | 155 { |
| 202 static const char* input = "<input type='text' value='Beginning of range'><d
iv><div><input type='text' value='Under DOM nodes'></div></div><input type='text
' value='End of range'>"; | 156 static const char* input = "<input type='text' value='Beginning of range'><d
iv><div><input type='text' value='Under DOM nodes'></div></div><input type='text
' value='End of range'>"; |
| 203 setBodyInnerHTML(input); | 157 setBodyContent(input); |
| 204 EXPECT_EQ("[\n][Beginning of range][\n][Under DOM nodes][\n][End of range]",
iterate<DOMTree>(TextIteratorEntersTextControls)); | 158 EXPECT_EQ("[\n][Beginning of range][\n][Under DOM nodes][\n][End of range]",
iterate<DOMTree>(TextIteratorEntersTextControls)); |
| 205 EXPECT_EQ("[][\n][Beginning of range][\n][][\n][Under DOM nodes][\n][][\n][E
nd of range]", iterate<ComposedTree>(TextIteratorEntersTextControls)); | 159 EXPECT_EQ("[][\n][Beginning of range][\n][][\n][Under DOM nodes][\n][][\n][E
nd of range]", iterate<ComposedTree>(TextIteratorEntersTextControls)); |
| 206 } | 160 } |
| 207 | 161 |
| 208 TEST_F(TextIteratorTest, NotEnteringTextControlHostingShadowTreeEvenWithOption) | 162 TEST_F(TextIteratorTest, NotEnteringTextControlHostingShadowTreeEvenWithOption) |
| 209 { | 163 { |
| 210 static const char* bodyContent = "<div>Hello, <input type='text' value='inpu
t' id='input'> iterator.</div>"; | 164 static const char* bodyContent = "<div>Hello, <input type='text' value='inpu
t' id='input'> iterator.</div>"; |
| 211 static const char* shadowContent = "<span>shadow</span>"; | 165 static const char* shadowContent = "<span>shadow</span>"; |
| 212 // TextIterator doesn't emit "input" nor "shadow" since (1) the layoutObject
for <input> is not created; and | 166 // TextIterator doesn't emit "input" nor "shadow" since (1) the layoutObject
for <input> is not created; and |
| 213 // (2) we don't (yet) recurse into shadow trees. | 167 // (2) we don't (yet) recurse into shadow trees. |
| 214 setBodyInnerHTML(bodyContent); | 168 setBodyContent(bodyContent); |
| 215 createShadowRootForElementWithIDAndSetInnerHTML(document(), "input", shadowC
ontent); | 169 createShadowRootForElementWithIDAndSetInnerHTML(document(), "input", shadowC
ontent); |
| 216 // FIXME: Why is an empty string emitted here? | 170 // FIXME: Why is an empty string emitted here? |
| 217 EXPECT_EQ("[Hello, ][][ iterator.]", iterate<DOMTree>()); | 171 EXPECT_EQ("[Hello, ][][ iterator.]", iterate<DOMTree>()); |
| 218 EXPECT_EQ("[Hello, ][][shadow][ iterator.]", iterate<ComposedTree>()); | 172 EXPECT_EQ("[Hello, ][][shadow][ iterator.]", iterate<ComposedTree>()); |
| 219 } | 173 } |
| 220 | 174 |
| 221 TEST_F(TextIteratorTest, NotEnteringShadowTree) | 175 TEST_F(TextIteratorTest, NotEnteringShadowTree) |
| 222 { | 176 { |
| 223 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; | 177 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; |
| 224 static const char* shadowContent = "<span>shadow</span>"; | 178 static const char* shadowContent = "<span>shadow</span>"; |
| 225 setBodyInnerHTML(bodyContent); | 179 setBodyContent(bodyContent); |
| 226 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); | 180 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); |
| 227 // TextIterator doesn't emit "text" since its layoutObject is not created. T
he shadow tree is ignored. | 181 // TextIterator doesn't emit "text" since its layoutObject is not created. T
he shadow tree is ignored. |
| 228 EXPECT_EQ("[Hello, ][ iterator.]", iterate<DOMTree>()); | 182 EXPECT_EQ("[Hello, ][ iterator.]", iterate<DOMTree>()); |
| 229 EXPECT_EQ("[Hello, ][shadow][ iterator.]", iterate<ComposedTree>()); | 183 EXPECT_EQ("[Hello, ][shadow][ iterator.]", iterate<ComposedTree>()); |
| 230 } | 184 } |
| 231 | 185 |
| 232 TEST_F(TextIteratorTest, NotEnteringShadowTreeWithMultipleShadowTrees) | 186 TEST_F(TextIteratorTest, NotEnteringShadowTreeWithMultipleShadowTrees) |
| 233 { | 187 { |
| 234 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; | 188 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; |
| 235 static const char* shadowContent1 = "<span>first shadow</span>"; | 189 static const char* shadowContent1 = "<span>first shadow</span>"; |
| 236 static const char* shadowContent2 = "<span>second shadow</span>"; | 190 static const char* shadowContent2 = "<span>second shadow</span>"; |
| 237 setBodyInnerHTML(bodyContent); | 191 setBodyContent(bodyContent); |
| 238 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent1); | 192 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent1); |
| 239 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent2); | 193 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent2); |
| 240 EXPECT_EQ("[Hello, ][ iterator.]", iterate<DOMTree>()); | 194 EXPECT_EQ("[Hello, ][ iterator.]", iterate<DOMTree>()); |
| 241 EXPECT_EQ("[Hello, ][second shadow][ iterator.]", iterate<ComposedTree>()); | 195 EXPECT_EQ("[Hello, ][second shadow][ iterator.]", iterate<ComposedTree>()); |
| 242 } | 196 } |
| 243 | 197 |
| 244 TEST_F(TextIteratorTest, NotEnteringShadowTreeWithNestedShadowTrees) | 198 TEST_F(TextIteratorTest, NotEnteringShadowTreeWithNestedShadowTrees) |
| 245 { | 199 { |
| 246 static const char* bodyContent = "<div>Hello, <span id='host-in-document'>te
xt</span> iterator.</div>"; | 200 static const char* bodyContent = "<div>Hello, <span id='host-in-document'>te
xt</span> iterator.</div>"; |
| 247 static const char* shadowContent1 = "<span>first <span id='host-in-shadow'>s
hadow</span></span>"; | 201 static const char* shadowContent1 = "<span>first <span id='host-in-shadow'>s
hadow</span></span>"; |
| 248 static const char* shadowContent2 = "<span>second shadow</span>"; | 202 static const char* shadowContent2 = "<span>second shadow</span>"; |
| 249 setBodyInnerHTML(bodyContent); | 203 setBodyContent(bodyContent); |
| 250 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = createShadowRootForElementWithI
DAndSetInnerHTML(document(), "host-in-document", shadowContent1); | 204 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = createShadowRootForElementWithI
DAndSetInnerHTML(document(), "host-in-document", shadowContent1); |
| 251 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host-in-shado
w", shadowContent2); | 205 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host-in-shado
w", shadowContent2); |
| 252 EXPECT_EQ("[Hello, ][ iterator.]", iterate<DOMTree>()); | 206 EXPECT_EQ("[Hello, ][ iterator.]", iterate<DOMTree>()); |
| 253 EXPECT_EQ("[Hello, ][first ][second shadow][ iterator.]", iterate<ComposedTr
ee>()); | 207 EXPECT_EQ("[Hello, ][first ][second shadow][ iterator.]", iterate<ComposedTr
ee>()); |
| 254 } | 208 } |
| 255 | 209 |
| 256 TEST_F(TextIteratorTest, NotEnteringShadowTreeWithContentInsertionPoint) | 210 TEST_F(TextIteratorTest, NotEnteringShadowTreeWithContentInsertionPoint) |
| 257 { | 211 { |
| 258 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; | 212 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; |
| 259 static const char* shadowContent = "<span>shadow <content>content</content><
/span>"; | 213 static const char* shadowContent = "<span>shadow <content>content</content><
/span>"; |
| 260 setBodyInnerHTML(bodyContent); | 214 setBodyContent(bodyContent); |
| 261 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); | 215 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); |
| 262 // In this case a layoutObject for "text" is created, so it shows up here. | 216 // In this case a layoutObject for "text" is created, so it shows up here. |
| 263 EXPECT_EQ("[Hello, ][text][ iterator.]", iterate<DOMTree>()); | 217 EXPECT_EQ("[Hello, ][text][ iterator.]", iterate<DOMTree>()); |
| 264 EXPECT_EQ("[Hello, ][shadow ][text][ iterator.]", iterate<ComposedTree>()); | 218 EXPECT_EQ("[Hello, ][shadow ][text][ iterator.]", iterate<ComposedTree>()); |
| 265 } | 219 } |
| 266 | 220 |
| 267 TEST_F(TextIteratorTest, EnteringShadowTreeWithOption) | 221 TEST_F(TextIteratorTest, EnteringShadowTreeWithOption) |
| 268 { | 222 { |
| 269 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; | 223 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; |
| 270 static const char* shadowContent = "<span>shadow</span>"; | 224 static const char* shadowContent = "<span>shadow</span>"; |
| 271 setBodyInnerHTML(bodyContent); | 225 setBodyContent(bodyContent); |
| 272 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); | 226 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); |
| 273 // TextIterator emits "shadow" since TextIteratorEntersOpenShadowRoots is sp
ecified. | 227 // TextIterator emits "shadow" since TextIteratorEntersOpenShadowRoots is sp
ecified. |
| 274 EXPECT_EQ("[Hello, ][shadow][ iterator.]", iterate<DOMTree>(TextIteratorEnte
rsOpenShadowRoots)); | 228 EXPECT_EQ("[Hello, ][shadow][ iterator.]", iterate<DOMTree>(TextIteratorEnte
rsOpenShadowRoots)); |
| 275 EXPECT_EQ("[Hello, ][shadow][ iterator.]", iterate<ComposedTree>(TextIterato
rEntersOpenShadowRoots)); | 229 EXPECT_EQ("[Hello, ][shadow][ iterator.]", iterate<ComposedTree>(TextIterato
rEntersOpenShadowRoots)); |
| 276 } | 230 } |
| 277 | 231 |
| 278 TEST_F(TextIteratorTest, EnteringShadowTreeWithMultipleShadowTreesWithOption) | 232 TEST_F(TextIteratorTest, EnteringShadowTreeWithMultipleShadowTreesWithOption) |
| 279 { | 233 { |
| 280 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; | 234 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; |
| 281 static const char* shadowContent1 = "<span>first shadow</span>"; | 235 static const char* shadowContent1 = "<span>first shadow</span>"; |
| 282 static const char* shadowContent2 = "<span>second shadow</span>"; | 236 static const char* shadowContent2 = "<span>second shadow</span>"; |
| 283 setBodyInnerHTML(bodyContent); | 237 setBodyContent(bodyContent); |
| 284 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent1); | 238 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent1); |
| 285 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent2); | 239 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent2); |
| 286 // The first isn't emitted because a layoutObject for the first is not creat
ed. | 240 // The first isn't emitted because a layoutObject for the first is not creat
ed. |
| 287 EXPECT_EQ("[Hello, ][second shadow][ iterator.]", iterate<DOMTree>(TextItera
torEntersOpenShadowRoots)); | 241 EXPECT_EQ("[Hello, ][second shadow][ iterator.]", iterate<DOMTree>(TextItera
torEntersOpenShadowRoots)); |
| 288 EXPECT_EQ("[Hello, ][second shadow][ iterator.]", iterate<ComposedTree>(Text
IteratorEntersOpenShadowRoots)); | 242 EXPECT_EQ("[Hello, ][second shadow][ iterator.]", iterate<ComposedTree>(Text
IteratorEntersOpenShadowRoots)); |
| 289 } | 243 } |
| 290 | 244 |
| 291 TEST_F(TextIteratorTest, EnteringShadowTreeWithNestedShadowTreesWithOption) | 245 TEST_F(TextIteratorTest, EnteringShadowTreeWithNestedShadowTreesWithOption) |
| 292 { | 246 { |
| 293 static const char* bodyContent = "<div>Hello, <span id='host-in-document'>te
xt</span> iterator.</div>"; | 247 static const char* bodyContent = "<div>Hello, <span id='host-in-document'>te
xt</span> iterator.</div>"; |
| 294 static const char* shadowContent1 = "<span>first <span id='host-in-shadow'>s
hadow</span></span>"; | 248 static const char* shadowContent1 = "<span>first <span id='host-in-shadow'>s
hadow</span></span>"; |
| 295 static const char* shadowContent2 = "<span>second shadow</span>"; | 249 static const char* shadowContent2 = "<span>second shadow</span>"; |
| 296 setBodyInnerHTML(bodyContent); | 250 setBodyContent(bodyContent); |
| 297 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = createShadowRootForElementWithI
DAndSetInnerHTML(document(), "host-in-document", shadowContent1); | 251 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot1 = createShadowRootForElementWithI
DAndSetInnerHTML(document(), "host-in-document", shadowContent1); |
| 298 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host-in-shado
w", shadowContent2); | 252 createShadowRootForElementWithIDAndSetInnerHTML(*shadowRoot1, "host-in-shado
w", shadowContent2); |
| 299 EXPECT_EQ("[Hello, ][first ][second shadow][ iterator.]", iterate<DOMTree>(T
extIteratorEntersOpenShadowRoots)); | 253 EXPECT_EQ("[Hello, ][first ][second shadow][ iterator.]", iterate<DOMTree>(T
extIteratorEntersOpenShadowRoots)); |
| 300 EXPECT_EQ("[Hello, ][first ][second shadow][ iterator.]", iterate<ComposedTr
ee>(TextIteratorEntersOpenShadowRoots)); | 254 EXPECT_EQ("[Hello, ][first ][second shadow][ iterator.]", iterate<ComposedTr
ee>(TextIteratorEntersOpenShadowRoots)); |
| 301 } | 255 } |
| 302 | 256 |
| 303 TEST_F(TextIteratorTest, EnteringShadowTreeWithContentInsertionPointWithOption) | 257 TEST_F(TextIteratorTest, EnteringShadowTreeWithContentInsertionPointWithOption) |
| 304 { | 258 { |
| 305 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; | 259 static const char* bodyContent = "<div>Hello, <span id='host'>text</span> it
erator.</div>"; |
| 306 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; | 260 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; |
| 307 // In this case a layoutObject for "text" is created, and emitted AFTER any
nodes in the shadow tree. | 261 // In this case a layoutObject for "text" is created, and emitted AFTER any
nodes in the shadow tree. |
| 308 // This order does not match the order of the rendered texts, but at this mo
ment it's the expected behavior. | 262 // This order does not match the order of the rendered texts, but at this mo
ment it's the expected behavior. |
| 309 // FIXME: Fix this. We probably need pure-renderer-based implementation of T
extIterator to achieve this. | 263 // FIXME: Fix this. We probably need pure-renderer-based implementation of T
extIterator to achieve this. |
| 310 setBodyInnerHTML(bodyContent); | 264 setBodyContent(bodyContent); |
| 311 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); | 265 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); |
| 312 EXPECT_EQ("[Hello, ][ shadow][text][ iterator.]", iterate<DOMTree>(TextItera
torEntersOpenShadowRoots)); | 266 EXPECT_EQ("[Hello, ][ shadow][text][ iterator.]", iterate<DOMTree>(TextItera
torEntersOpenShadowRoots)); |
| 313 EXPECT_EQ("[Hello, ][text][ shadow][ iterator.]", iterate<ComposedTree>(Text
IteratorEntersOpenShadowRoots)); | 267 EXPECT_EQ("[Hello, ][text][ shadow][ iterator.]", iterate<ComposedTree>(Text
IteratorEntersOpenShadowRoots)); |
| 314 } | 268 } |
| 315 | 269 |
| 316 TEST_F(TextIteratorTest, StartingAtNodeInShadowRoot) | 270 TEST_F(TextIteratorTest, StartingAtNodeInShadowRoot) |
| 317 { | 271 { |
| 318 static const char* bodyContent = "<div id='outer'>Hello, <span id='host'>tex
t</span> iterator.</div>"; | 272 static const char* bodyContent = "<div id='outer'>Hello, <span id='host'>tex
t</span> iterator.</div>"; |
| 319 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; | 273 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; |
| 320 setBodyInnerHTML(bodyContent); | 274 setBodyContent(bodyContent); |
| 321 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithID
AndSetInnerHTML(document(), "host", shadowContent); | 275 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithID
AndSetInnerHTML(document(), "host", shadowContent); |
| 322 Node* outerDiv = document().getElementById("outer"); | 276 Node* outerDiv = document().getElementById("outer"); |
| 323 Node* spanInShadow = shadowRoot->firstChild(); | 277 Node* spanInShadow = shadowRoot->firstChild(); |
| 324 Position start(spanInShadow, Position::PositionIsBeforeChildren); | 278 Position start(spanInShadow, Position::PositionIsBeforeChildren); |
| 325 Position end(outerDiv, Position::PositionIsAfterChildren); | 279 Position end(outerDiv, Position::PositionIsAfterChildren); |
| 326 EXPECT_EQ("[ shadow][text][ iterator.]", iteratePartial<DOMTree>(start, end,
TextIteratorEntersOpenShadowRoots)); | 280 EXPECT_EQ("[ shadow][text][ iterator.]", iteratePartial<DOMTree>(start, end,
TextIteratorEntersOpenShadowRoots)); |
| 327 | 281 |
| 328 PositionInComposedTree startInComposedTree(spanInShadow, PositionInComposedT
ree::PositionIsBeforeChildren); | 282 PositionInComposedTree startInComposedTree(spanInShadow, PositionInComposedT
ree::PositionIsBeforeChildren); |
| 329 PositionInComposedTree endInComposedTree(outerDiv, PositionInComposedTree::P
ositionIsAfterChildren); | 283 PositionInComposedTree endInComposedTree(outerDiv, PositionInComposedTree::P
ositionIsAfterChildren); |
| 330 EXPECT_EQ("[text][ shadow][ iterator.]", iteratePartial<ComposedTree>(startI
nComposedTree, endInComposedTree, TextIteratorEntersOpenShadowRoots)); | 284 EXPECT_EQ("[text][ shadow][ iterator.]", iteratePartial<ComposedTree>(startI
nComposedTree, endInComposedTree, TextIteratorEntersOpenShadowRoots)); |
| 331 } | 285 } |
| 332 | 286 |
| 333 TEST_F(TextIteratorTest, FinishingAtNodeInShadowRoot) | 287 TEST_F(TextIteratorTest, FinishingAtNodeInShadowRoot) |
| 334 { | 288 { |
| 335 static const char* bodyContent = "<div id='outer'>Hello, <span id='host'>tex
t</span> iterator.</div>"; | 289 static const char* bodyContent = "<div id='outer'>Hello, <span id='host'>tex
t</span> iterator.</div>"; |
| 336 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; | 290 static const char* shadowContent = "<span><content>content</content> shadow<
/span>"; |
| 337 setBodyInnerHTML(bodyContent); | 291 setBodyContent(bodyContent); |
| 338 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithID
AndSetInnerHTML(document(), "host", shadowContent); | 292 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = createShadowRootForElementWithID
AndSetInnerHTML(document(), "host", shadowContent); |
| 339 Node* outerDiv = document().getElementById("outer"); | 293 Node* outerDiv = document().getElementById("outer"); |
| 340 Node* spanInShadow = shadowRoot->firstChild(); | 294 Node* spanInShadow = shadowRoot->firstChild(); |
| 341 Position start(outerDiv, Position::PositionIsBeforeChildren); | 295 Position start(outerDiv, Position::PositionIsBeforeChildren); |
| 342 Position end(spanInShadow, Position::PositionIsAfterChildren); | 296 Position end(spanInShadow, Position::PositionIsAfterChildren); |
| 343 EXPECT_EQ("[Hello, ][ shadow]", iteratePartial<DOMTree>(start, end, TextIter
atorEntersOpenShadowRoots)); | 297 EXPECT_EQ("[Hello, ][ shadow]", iteratePartial<DOMTree>(start, end, TextIter
atorEntersOpenShadowRoots)); |
| 344 | 298 |
| 345 PositionInComposedTree startInComposedTree(outerDiv, PositionInComposedTree:
:PositionIsBeforeChildren); | 299 PositionInComposedTree startInComposedTree(outerDiv, PositionInComposedTree:
:PositionIsBeforeChildren); |
| 346 PositionInComposedTree endInComposedTree(spanInShadow, PositionInComposedTre
e::PositionIsAfterChildren); | 300 PositionInComposedTree endInComposedTree(spanInShadow, PositionInComposedTre
e::PositionIsAfterChildren); |
| 347 EXPECT_EQ("[Hello, ][text][ shadow]", iteratePartial<ComposedTree>(startInCo
mposedTree, endInComposedTree, TextIteratorEntersOpenShadowRoots)); | 301 EXPECT_EQ("[Hello, ][text][ shadow]", iteratePartial<ComposedTree>(startInCo
mposedTree, endInComposedTree, TextIteratorEntersOpenShadowRoots)); |
| 348 } | 302 } |
| 349 | 303 |
| 350 TEST_F(TextIteratorTest, FullyClipsContents) | 304 TEST_F(TextIteratorTest, FullyClipsContents) |
| 351 { | 305 { |
| 352 static const char* bodyContent = | 306 static const char* bodyContent = |
| 353 "<div style='overflow: hidden; width: 200px; height: 0;'>" | 307 "<div style='overflow: hidden; width: 200px; height: 0;'>" |
| 354 "I'm invisible" | 308 "I'm invisible" |
| 355 "</div>"; | 309 "</div>"; |
| 356 setBodyInnerHTML(bodyContent); | 310 setBodyContent(bodyContent); |
| 357 EXPECT_EQ("", iterate<DOMTree>()); | 311 EXPECT_EQ("", iterate<DOMTree>()); |
| 358 EXPECT_EQ("", iterate<ComposedTree>()); | 312 EXPECT_EQ("", iterate<ComposedTree>()); |
| 359 } | 313 } |
| 360 | 314 |
| 361 TEST_F(TextIteratorTest, IgnoresContainerClip) | 315 TEST_F(TextIteratorTest, IgnoresContainerClip) |
| 362 { | 316 { |
| 363 static const char* bodyContent = | 317 static const char* bodyContent = |
| 364 "<div style='overflow: hidden; width: 200px; height: 0;'>" | 318 "<div style='overflow: hidden; width: 200px; height: 0;'>" |
| 365 "<div>I'm not visible</div>" | 319 "<div>I'm not visible</div>" |
| 366 "<div style='position: absolute; width: 200px; height: 200px; top: 0; ri
ght: 0;'>" | 320 "<div style='position: absolute; width: 200px; height: 200px; top: 0; ri
ght: 0;'>" |
| 367 "but I am!" | 321 "but I am!" |
| 368 "</div>" | 322 "</div>" |
| 369 "</div>"; | 323 "</div>"; |
| 370 setBodyInnerHTML(bodyContent); | 324 setBodyContent(bodyContent); |
| 371 EXPECT_EQ("[but I am!]", iterate<DOMTree>()); | 325 EXPECT_EQ("[but I am!]", iterate<DOMTree>()); |
| 372 EXPECT_EQ("[but I am!]", iterate<ComposedTree>()); | 326 EXPECT_EQ("[but I am!]", iterate<ComposedTree>()); |
| 373 } | 327 } |
| 374 | 328 |
| 375 TEST_F(TextIteratorTest, FullyClippedContentsDistributed) | 329 TEST_F(TextIteratorTest, FullyClippedContentsDistributed) |
| 376 { | 330 { |
| 377 static const char* bodyContent = | 331 static const char* bodyContent = |
| 378 "<div id='host'>" | 332 "<div id='host'>" |
| 379 "<div>Am I visible?</div>" | 333 "<div>Am I visible?</div>" |
| 380 "</div>"; | 334 "</div>"; |
| 381 static const char* shadowContent = | 335 static const char* shadowContent = |
| 382 "<div style='overflow: hidden; width: 200px; height: 0;'>" | 336 "<div style='overflow: hidden; width: 200px; height: 0;'>" |
| 383 "<content></content>" | 337 "<content></content>" |
| 384 "</div>"; | 338 "</div>"; |
| 385 setBodyInnerHTML(bodyContent); | 339 setBodyContent(bodyContent); |
| 386 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); | 340 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); |
| 387 // FIXME: The text below is actually invisible but TextIterator currently th
inks it's visible. | 341 // FIXME: The text below is actually invisible but TextIterator currently th
inks it's visible. |
| 388 EXPECT_EQ("[\n][Am I visible?]", iterate<DOMTree>(TextIteratorEntersOpenShad
owRoots)); | 342 EXPECT_EQ("[\n][Am I visible?]", iterate<DOMTree>(TextIteratorEntersOpenShad
owRoots)); |
| 389 EXPECT_EQ("", iterate<ComposedTree>(TextIteratorEntersOpenShadowRoots)); | 343 EXPECT_EQ("", iterate<ComposedTree>(TextIteratorEntersOpenShadowRoots)); |
| 390 } | 344 } |
| 391 | 345 |
| 392 TEST_F(TextIteratorTest, IgnoresContainersClipDistributed) | 346 TEST_F(TextIteratorTest, IgnoresContainersClipDistributed) |
| 393 { | 347 { |
| 394 static const char* bodyContent = | 348 static const char* bodyContent = |
| 395 "<div id='host' style='overflow: hidden; width: 200px; height: 0;'>" | 349 "<div id='host' style='overflow: hidden; width: 200px; height: 0;'>" |
| 396 "<div>Nobody can find me!</div>" | 350 "<div>Nobody can find me!</div>" |
| 397 "</div>"; | 351 "</div>"; |
| 398 static const char* shadowContent = | 352 static const char* shadowContent = |
| 399 "<div style='position: absolute; width: 200px; height: 200px; top: 0; ri
ght: 0;'>" | 353 "<div style='position: absolute; width: 200px; height: 200px; top: 0; ri
ght: 0;'>" |
| 400 "<content></content>" | 354 "<content></content>" |
| 401 "</div>"; | 355 "</div>"; |
| 402 setBodyInnerHTML(bodyContent); | 356 setBodyContent(bodyContent); |
| 403 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); | 357 createShadowRootForElementWithIDAndSetInnerHTML(document(), "host", shadowCo
ntent); |
| 404 // FIXME: The text below is actually visible but TextIterator currently thin
ks it's invisible. | 358 // FIXME: The text below is actually visible but TextIterator currently thin
ks it's invisible. |
| 405 // [\n][Nobody can find me!] | 359 // [\n][Nobody can find me!] |
| 406 EXPECT_EQ("", iterate<DOMTree>(TextIteratorEntersOpenShadowRoots)); | 360 EXPECT_EQ("", iterate<DOMTree>(TextIteratorEntersOpenShadowRoots)); |
| 407 EXPECT_EQ("[Nobody can find me!]", iterate<ComposedTree>(TextIteratorEntersO
penShadowRoots)); | 361 EXPECT_EQ("[Nobody can find me!]", iterate<ComposedTree>(TextIteratorEntersO
penShadowRoots)); |
| 408 } | 362 } |
| 409 | 363 |
| 410 TEST_F(TextIteratorTest, FindPlainTextInvalidTarget) | 364 TEST_F(TextIteratorTest, FindPlainTextInvalidTarget) |
| 411 { | 365 { |
| 412 static const char* bodyContent = "<div>foo bar test</div>"; | 366 static const char* bodyContent = "<div>foo bar test</div>"; |
| 413 setBodyInnerHTML(bodyContent); | 367 setBodyContent(bodyContent); |
| 414 RefPtrWillBeRawPtr<Range> range = getBodyRange(); | 368 RefPtrWillBeRawPtr<Range> range = getBodyRange(); |
| 415 | 369 |
| 416 RefPtrWillBeRawPtr<Range> expectedRange = range->cloneRange(); | 370 RefPtrWillBeRawPtr<Range> expectedRange = range->cloneRange(); |
| 417 expectedRange->collapse(false); | 371 expectedRange->collapse(false); |
| 418 | 372 |
| 419 // A lone lead surrogate (0xDA0A) example taken from fuzz-58. | 373 // A lone lead surrogate (0xDA0A) example taken from fuzz-58. |
| 420 static const UChar invalid1[] = { | 374 static const UChar invalid1[] = { |
| 421 0x1461u, 0x2130u, 0x129bu, 0xd711u, 0xd6feu, 0xccadu, 0x7064u, | 375 0x1461u, 0x2130u, 0x129bu, 0xd711u, 0xd6feu, 0xccadu, 0x7064u, |
| 422 0xd6a0u, 0x4e3bu, 0x03abu, 0x17dcu, 0xb8b7u, 0xbf55u, 0xfca0u, | 376 0xd6a0u, 0x4e3bu, 0x03abu, 0x17dcu, 0xb8b7u, 0xbf55u, 0xfca0u, |
| 423 0x07fau, 0x0427u, 0xda0au, 0 | 377 0x07fau, 0x0427u, 0xda0au, 0 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 442 } | 396 } |
| 443 | 397 |
| 444 TEST_F(TextIteratorTest, EmitsReplacementCharForInput) | 398 TEST_F(TextIteratorTest, EmitsReplacementCharForInput) |
| 445 { | 399 { |
| 446 static const char* bodyContent = | 400 static const char* bodyContent = |
| 447 "<div contenteditable='true'>" | 401 "<div contenteditable='true'>" |
| 448 "Before" | 402 "Before" |
| 449 "<img src='foo.png'>" | 403 "<img src='foo.png'>" |
| 450 "After" | 404 "After" |
| 451 "</div>"; | 405 "</div>"; |
| 452 setBodyInnerHTML(bodyContent); | 406 setBodyContent(bodyContent); |
| 453 EXPECT_EQ("[Before][\xEF\xBF\xBC][After]", iterate<DOMTree>(TextIteratorEmit
sObjectReplacementCharacter)); | 407 EXPECT_EQ("[Before][\xEF\xBF\xBC][After]", iterate<DOMTree>(TextIteratorEmit
sObjectReplacementCharacter)); |
| 454 EXPECT_EQ("[Before][\xEF\xBF\xBC][After]", iterate<ComposedTree>(TextIterato
rEmitsObjectReplacementCharacter)); | 408 EXPECT_EQ("[Before][\xEF\xBF\xBC][After]", iterate<ComposedTree>(TextIterato
rEmitsObjectReplacementCharacter)); |
| 455 } | 409 } |
| 456 | 410 |
| 457 TEST_F(TextIteratorTest, RangeLengthWithReplacedElements) | 411 TEST_F(TextIteratorTest, RangeLengthWithReplacedElements) |
| 458 { | 412 { |
| 459 static const char* bodyContent = | 413 static const char* bodyContent = |
| 460 "<div id='div' contenteditable='true'>1<img src='foo.png'>3</div>"; | 414 "<div id='div' contenteditable='true'>1<img src='foo.png'>3</div>"; |
| 461 setBodyInnerHTML(bodyContent); | 415 setBodyContent(bodyContent); |
| 462 document().view()->updateLayoutAndStyleForPainting(); | 416 document().view()->updateLayoutAndStyleForPainting(); |
| 463 | 417 |
| 464 Node* divNode = document().getElementById("div"); | 418 Node* divNode = document().getElementById("div"); |
| 465 RefPtrWillBeRawPtr<Range> range = Range::create(document(), divNode, 0, divN
ode, 3); | 419 RefPtrWillBeRawPtr<Range> range = Range::create(document(), divNode, 0, divN
ode, 3); |
| 466 | 420 |
| 467 EXPECT_EQ(3, TextIterator::rangeLength(range->startPosition(), range->endPos
ition())); | 421 EXPECT_EQ(3, TextIterator::rangeLength(range->startPosition(), range->endPos
ition())); |
| 468 } | 422 } |
| 469 | 423 |
| 470 TEST_F(TextIteratorTest, SubrangeWithReplacedElements) | 424 TEST_F(TextIteratorTest, SubrangeWithReplacedElements) |
| 471 { | 425 { |
| 472 static const char* bodyContent = | 426 static const char* bodyContent = |
| 473 "<div id='div' contenteditable='true'>1<img src='foo.png'>345</div>"; | 427 "<div id='div' contenteditable='true'>1<img src='foo.png'>345</div>"; |
| 474 setBodyInnerHTML(bodyContent); | 428 setBodyContent(bodyContent); |
| 475 document().view()->updateLayoutAndStyleForPainting(); | 429 document().view()->updateLayoutAndStyleForPainting(); |
| 476 | 430 |
| 477 Node* divNode = document().getElementById("div"); | 431 Node* divNode = document().getElementById("div"); |
| 478 RefPtrWillBeRawPtr<Range> entireRange = Range::create(document(), divNode, 0
, divNode, 3); | 432 RefPtrWillBeRawPtr<Range> entireRange = Range::create(document(), divNode, 0
, divNode, 3); |
| 479 | 433 |
| 480 RefPtrWillBeRawPtr<Range> subrange = TextIterator::subrange(entireRange.get(
), 2, 3); | 434 RefPtrWillBeRawPtr<Range> subrange = TextIterator::subrange(entireRange.get(
), 2, 3); |
| 481 EXPECT_EQ(0, subrange->startOffset()); | 435 EXPECT_EQ(0, subrange->startOffset()); |
| 482 EXPECT_EQ(3, subrange->endOffset()); | 436 EXPECT_EQ(3, subrange->endOffset()); |
| 483 } | 437 } |
| 484 | 438 |
| 485 } // namespace blink | 439 } // namespace blink |
| OLD | NEW |