| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/editing/VisibleUnits.h" | 5 #include "core/editing/VisibleUnits.h" |
| 6 | 6 |
| 7 #include "core/dom/Text.h" | 7 #include "core/dom/Text.h" |
| 8 #include "core/editing/EditingTestBase.h" | 8 #include "core/editing/EditingTestBase.h" |
| 9 #include "core/editing/VisiblePosition.h" | 9 #include "core/editing/VisiblePosition.h" |
| 10 #include "core/html/HTMLTextFormControlElement.h" | 10 #include "core/html/HTMLTextFormControlElement.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 TEST_F(VisibleUnitsTest, absoluteCaretBoundsOf) | 51 TEST_F(VisibleUnitsTest, absoluteCaretBoundsOf) |
| 52 { | 52 { |
| 53 const char* bodyContent = "<p id='host'><b id='one'>11</b><b id='two'>22</b>
</p>"; | 53 const char* bodyContent = "<p id='host'><b id='one'>11</b><b id='two'>22</b>
</p>"; |
| 54 const char* shadowContent = "<div><content select=#two></content><content se
lect=#one></content></div>"; | 54 const char* shadowContent = "<div><content select=#two></content><content se
lect=#one></content></div>"; |
| 55 setBodyContent(bodyContent); | 55 setBodyContent(bodyContent); |
| 56 setShadowContent(shadowContent, "host"); | 56 setShadowContent(shadowContent, "host"); |
| 57 | 57 |
| 58 Element* body = document().body(); | 58 Element* body = document().body(); |
| 59 Element* one = body->querySelector("#one", ASSERT_NO_EXCEPTION); | 59 Element* one = body->querySelector("#one"); |
| 60 | 60 |
| 61 IntRect boundsInDOMTree = absoluteCaretBoundsOf(createVisiblePosition(Positi
on(one, 0))); | 61 IntRect boundsInDOMTree = absoluteCaretBoundsOf(createVisiblePosition(Positi
on(one, 0))); |
| 62 IntRect boundsInFlatTree = absoluteCaretBoundsOf(createVisiblePosition(Posit
ionInFlatTree(one, 0))); | 62 IntRect boundsInFlatTree = absoluteCaretBoundsOf(createVisiblePosition(Posit
ionInFlatTree(one, 0))); |
| 63 | 63 |
| 64 EXPECT_FALSE(boundsInDOMTree.isEmpty()); | 64 EXPECT_FALSE(boundsInDOMTree.isEmpty()); |
| 65 EXPECT_EQ(boundsInDOMTree, boundsInFlatTree); | 65 EXPECT_EQ(boundsInDOMTree, boundsInFlatTree); |
| 66 } | 66 } |
| 67 | 67 |
| 68 TEST_F(VisibleUnitsTest, associatedLayoutObjectOfFirstLetterPunctuations) | 68 TEST_F(VisibleUnitsTest, associatedLayoutObjectOfFirstLetterPunctuations) |
| 69 { | 69 { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 157 |
| 158 EXPECT_EQ(0, characterAfter(createVisiblePositionInDOMTree(*two->firstChild(
), 2))); | 158 EXPECT_EQ(0, characterAfter(createVisiblePositionInDOMTree(*two->firstChild(
), 2))); |
| 159 EXPECT_EQ('1', characterAfter(createVisiblePositionInFlatTree(*two->firstChi
ld(), 2))); | 159 EXPECT_EQ('1', characterAfter(createVisiblePositionInFlatTree(*two->firstChi
ld(), 2))); |
| 160 } | 160 } |
| 161 | 161 |
| 162 TEST_F(VisibleUnitsTest, canonicalPositionOfWithHTMLHtmlElement) | 162 TEST_F(VisibleUnitsTest, canonicalPositionOfWithHTMLHtmlElement) |
| 163 { | 163 { |
| 164 const char* bodyContent = "<html><div id=one contenteditable>1</div><span id
=two contenteditable=false>22</span><span id=three contenteditable=false>333</sp
an><span id=four contenteditable=false>333</span></html>"; | 164 const char* bodyContent = "<html><div id=one contenteditable>1</div><span id
=two contenteditable=false>22</span><span id=three contenteditable=false>333</sp
an><span id=four contenteditable=false>333</span></html>"; |
| 165 setBodyContent(bodyContent); | 165 setBodyContent(bodyContent); |
| 166 | 166 |
| 167 Node* one = document().querySelector("#one", ASSERT_NO_EXCEPTION); | 167 Node* one = document().querySelector("#one"); |
| 168 Node* two = document().querySelector("#two", ASSERT_NO_EXCEPTION); | 168 Node* two = document().querySelector("#two"); |
| 169 Node* three = document().querySelector("#three", ASSERT_NO_EXCEPTION); | 169 Node* three = document().querySelector("#three"); |
| 170 Node* four = document().querySelector("#four", ASSERT_NO_EXCEPTION); | 170 Node* four = document().querySelector("#four"); |
| 171 Element* html = document().createElement("html", ASSERT_NO_EXCEPTION); | 171 Element* html = document().createElement("html", ASSERT_NO_EXCEPTION); |
| 172 // Move two, three and four into second html element. | 172 // Move two, three and four into second html element. |
| 173 html->appendChild(two); | 173 html->appendChild(two); |
| 174 html->appendChild(three); | 174 html->appendChild(three); |
| 175 html->appendChild(four); | 175 html->appendChild(four); |
| 176 one->appendChild(html); | 176 one->appendChild(html); |
| 177 updateAllLifecyclePhases(); | 177 updateAllLifecyclePhases(); |
| 178 | 178 |
| 179 EXPECT_EQ(Position(), canonicalPositionOf(Position(document().documentElemen
t(), 0))); | 179 EXPECT_EQ(Position(), canonicalPositionOf(Position(document().documentElemen
t(), 0))); |
| 180 | 180 |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 } | 572 } |
| 573 | 573 |
| 574 TEST_F(VisibleUnitsTest, inSameLine) | 574 TEST_F(VisibleUnitsTest, inSameLine) |
| 575 { | 575 { |
| 576 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 576 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
| 577 const char* shadowContent = "<div><span id='s4'>44</span><content select=#tw
o></content><br><span id='s5'>55</span><br><content select=#one></content><span
id='s6'>66</span></div>"; | 577 const char* shadowContent = "<div><span id='s4'>44</span><content select=#tw
o></content><br><span id='s5'>55</span><br><content select=#one></content><span
id='s6'>66</span></div>"; |
| 578 setBodyContent(bodyContent); | 578 setBodyContent(bodyContent); |
| 579 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 579 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| 580 | 580 |
| 581 Element* body = document().body(); | 581 Element* body = document().body(); |
| 582 Element* one = body->querySelector("#one", ASSERT_NO_EXCEPTION); | 582 Element* one = body->querySelector("#one"); |
| 583 Element* two = body->querySelector("#two", ASSERT_NO_EXCEPTION); | 583 Element* two = body->querySelector("#two"); |
| 584 Element* four = shadowRoot->querySelector("#s4", ASSERT_NO_EXCEPTION); | 584 Element* four = shadowRoot->querySelector("#s4"); |
| 585 Element* five = shadowRoot->querySelector("#s5", ASSERT_NO_EXCEPTION); | 585 Element* five = shadowRoot->querySelector("#s5"); |
| 586 | 586 |
| 587 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one, 0), positionWithA
ffinityInDOMTree(*two, 0))); | 587 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one, 0), positionWithA
ffinityInDOMTree(*two, 0))); |
| 588 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0),
positionWithAffinityInDOMTree(*two->firstChild(), 0))); | 588 EXPECT_TRUE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0),
positionWithAffinityInDOMTree(*two->firstChild(), 0))); |
| 589 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0)
, positionWithAffinityInDOMTree(*five->firstChild(), 0))); | 589 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*one->firstChild(), 0)
, positionWithAffinityInDOMTree(*five->firstChild(), 0))); |
| 590 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*two->firstChild(), 0)
, positionWithAffinityInDOMTree(*four->firstChild(), 0))); | 590 EXPECT_FALSE(inSameLine(positionWithAffinityInDOMTree(*two->firstChild(), 0)
, positionWithAffinityInDOMTree(*four->firstChild(), 0))); |
| 591 | 591 |
| 592 EXPECT_TRUE(inSameLine(createVisiblePositionInDOMTree(*one, 0), createVisibl
ePositionInDOMTree(*two, 0))); | 592 EXPECT_TRUE(inSameLine(createVisiblePositionInDOMTree(*one, 0), createVisibl
ePositionInDOMTree(*two, 0))); |
| 593 EXPECT_TRUE(inSameLine(createVisiblePositionInDOMTree(*one->firstChild(), 0)
, createVisiblePositionInDOMTree(*two->firstChild(), 0))); | 593 EXPECT_TRUE(inSameLine(createVisiblePositionInDOMTree(*one->firstChild(), 0)
, createVisiblePositionInDOMTree(*two->firstChild(), 0))); |
| 594 EXPECT_FALSE(inSameLine(createVisiblePositionInDOMTree(*one->firstChild(), 0
), createVisiblePositionInDOMTree(*five->firstChild(), 0))); | 594 EXPECT_FALSE(inSameLine(createVisiblePositionInDOMTree(*one->firstChild(), 0
), createVisiblePositionInDOMTree(*five->firstChild(), 0))); |
| 595 EXPECT_FALSE(inSameLine(createVisiblePositionInDOMTree(*two->firstChild(), 0
), createVisiblePositionInDOMTree(*four->firstChild(), 0))); | 595 EXPECT_FALSE(inSameLine(createVisiblePositionInDOMTree(*two->firstChild(), 0
), createVisiblePositionInDOMTree(*four->firstChild(), 0))); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 | 698 |
| 699 EXPECT_FALSE(isStartOfParagraph(createVisiblePositionInDOMTree(*three, 0))); | 699 EXPECT_FALSE(isStartOfParagraph(createVisiblePositionInDOMTree(*three, 0))); |
| 700 EXPECT_TRUE(isStartOfParagraph(createVisiblePositionInFlatTree(*three, 0))); | 700 EXPECT_TRUE(isStartOfParagraph(createVisiblePositionInFlatTree(*three, 0))); |
| 701 } | 701 } |
| 702 | 702 |
| 703 TEST_F(VisibleUnitsTest, isVisuallyEquivalentCandidateWithHTMLHtmlElement) | 703 TEST_F(VisibleUnitsTest, isVisuallyEquivalentCandidateWithHTMLHtmlElement) |
| 704 { | 704 { |
| 705 const char* bodyContent = "<html><div id=one contenteditable>1</div><span id
=two contenteditable=false>22</span><span id=three contenteditable=false>333</sp
an><span id=four contenteditable=false>333</span></html>"; | 705 const char* bodyContent = "<html><div id=one contenteditable>1</div><span id
=two contenteditable=false>22</span><span id=three contenteditable=false>333</sp
an><span id=four contenteditable=false>333</span></html>"; |
| 706 setBodyContent(bodyContent); | 706 setBodyContent(bodyContent); |
| 707 | 707 |
| 708 Node* one = document().querySelector("#one", ASSERT_NO_EXCEPTION); | 708 Node* one = document().querySelector("#one"); |
| 709 Node* two = document().querySelector("#two", ASSERT_NO_EXCEPTION); | 709 Node* two = document().querySelector("#two"); |
| 710 Node* three = document().querySelector("#three", ASSERT_NO_EXCEPTION); | 710 Node* three = document().querySelector("#three"); |
| 711 Node* four = document().querySelector("#four", ASSERT_NO_EXCEPTION); | 711 Node* four = document().querySelector("#four"); |
| 712 Element* html = document().createElement("html", ASSERT_NO_EXCEPTION); | 712 Element* html = document().createElement("html", ASSERT_NO_EXCEPTION); |
| 713 // Move two, three and four into second html element. | 713 // Move two, three and four into second html element. |
| 714 html->appendChild(two); | 714 html->appendChild(two); |
| 715 html->appendChild(three); | 715 html->appendChild(three); |
| 716 html->appendChild(four); | 716 html->appendChild(four); |
| 717 one->appendChild(html); | 717 one->appendChild(html); |
| 718 updateAllLifecyclePhases(); | 718 updateAllLifecyclePhases(); |
| 719 | 719 |
| 720 EXPECT_FALSE(isVisuallyEquivalentCandidate(Position(document().documentEleme
nt(), 0))); | 720 EXPECT_FALSE(isVisuallyEquivalentCandidate(Position(document().documentEleme
nt(), 0))); |
| 721 | 721 |
| (...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 EXPECT_EQ(Position(space, 1), startOfWord(createVisiblePositionInDOMTree(*fi
ve, 1)).deepEquivalent()); | 1300 EXPECT_EQ(Position(space, 1), startOfWord(createVisiblePositionInDOMTree(*fi
ve, 1)).deepEquivalent()); |
| 1301 EXPECT_EQ(PositionInFlatTree(space, 1), startOfWord(createVisiblePositionInF
latTree(*five, 1)).deepEquivalent()); | 1301 EXPECT_EQ(PositionInFlatTree(space, 1), startOfWord(createVisiblePositionInF
latTree(*five, 1)).deepEquivalent()); |
| 1302 } | 1302 } |
| 1303 | 1303 |
| 1304 TEST_F(VisibleUnitsTest, endsOfNodeAreVisuallyDistinctPositionsWithInvisibleChil
d) | 1304 TEST_F(VisibleUnitsTest, endsOfNodeAreVisuallyDistinctPositionsWithInvisibleChil
d) |
| 1305 { | 1305 { |
| 1306 // Repro case of crbug.com/582247 | 1306 // Repro case of crbug.com/582247 |
| 1307 const char* bodyContent = "<button> </button><script>document.designMode = '
on'</script>"; | 1307 const char* bodyContent = "<button> </button><script>document.designMode = '
on'</script>"; |
| 1308 setBodyContent(bodyContent); | 1308 setBodyContent(bodyContent); |
| 1309 | 1309 |
| 1310 Node* button = document().querySelector("button", ASSERT_NO_EXCEPTION); | 1310 Node* button = document().querySelector("button"); |
| 1311 EXPECT_TRUE(endsOfNodeAreVisuallyDistinctPositions(button)); | 1311 EXPECT_TRUE(endsOfNodeAreVisuallyDistinctPositions(button)); |
| 1312 } | 1312 } |
| 1313 | 1313 |
| 1314 TEST_F(VisibleUnitsTest, endsOfNodeAreVisuallyDistinctPositionsWithEmptyLayoutCh
ild) | 1314 TEST_F(VisibleUnitsTest, endsOfNodeAreVisuallyDistinctPositionsWithEmptyLayoutCh
ild) |
| 1315 { | 1315 { |
| 1316 // Repro case of crbug.com/584030 | 1316 // Repro case of crbug.com/584030 |
| 1317 const char* bodyContent = "<button><rt><script>document.designMode = 'on'</s
cript></rt></button>"; | 1317 const char* bodyContent = "<button><rt><script>document.designMode = 'on'</s
cript></rt></button>"; |
| 1318 setBodyContent(bodyContent); | 1318 setBodyContent(bodyContent); |
| 1319 | 1319 |
| 1320 Node* button = document().querySelector("button", ASSERT_NO_EXCEPTION); | 1320 Node* button = document().querySelector("button"); |
| 1321 EXPECT_TRUE(endsOfNodeAreVisuallyDistinctPositions(button)); | 1321 EXPECT_TRUE(endsOfNodeAreVisuallyDistinctPositions(button)); |
| 1322 } | 1322 } |
| 1323 | 1323 |
| 1324 } // namespace blink | 1324 } // namespace blink |
| OLD | NEW |