| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/editing/EditingUtilities.h" | 6 #include "core/editing/EditingUtilities.h" |
| 7 | 7 |
| 8 #include "core/editing/EditingTestBase.h" | 8 #include "core/editing/EditingTestBase.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 class EditingUtilitiesTest : public EditingTestBase { | 12 class EditingUtilitiesTest : public EditingTestBase { |
| 13 }; | 13 }; |
| 14 | 14 |
| 15 TEST_F(EditingUtilitiesTest, directionOfEnclosingBlock) | 15 TEST_F(EditingUtilitiesTest, directionOfEnclosingBlock) |
| 16 { | 16 { |
| 17 const char* bodyContent = "<p id='host'><b id='one'></b><b id='two'>22</b></
p>"; | 17 const char* bodyContent = "<p id='host'><b id='one'></b><b id='two'>22</b></
p>"; |
| 18 const char* shadowContent = "<content select=#two></content><p dir=rtl><cont
ent select=#one></content><p>"; | 18 const char* shadowContent = "<content select=#two></content><p dir=rtl><cont
ent select=#one></content><p>"; |
| 19 setBodyContent(bodyContent); | 19 setBodyContent(bodyContent); |
| 20 setShadowContent(shadowContent); | 20 setShadowContent(shadowContent, "host"); |
| 21 updateLayoutAndStyleForPainting(); | 21 updateLayoutAndStyleForPainting(); |
| 22 Node* one = document().getElementById("one"); | 22 Node* one = document().getElementById("one"); |
| 23 | 23 |
| 24 EXPECT_EQ(LTR, directionOfEnclosingBlock(Position(one, 0))); | 24 EXPECT_EQ(LTR, directionOfEnclosingBlock(Position(one, 0))); |
| 25 EXPECT_EQ(RTL, directionOfEnclosingBlock(PositionInComposedTree(one, 0))); | 25 EXPECT_EQ(RTL, directionOfEnclosingBlock(PositionInComposedTree(one, 0))); |
| 26 } | 26 } |
| 27 | 27 |
| 28 TEST_F(EditingUtilitiesTest, firstEditablePositionAfterPositionInRoot) | 28 TEST_F(EditingUtilitiesTest, firstEditablePositionAfterPositionInRoot) |
| 29 { | 29 { |
| 30 const char* bodyContent = "<p id='host' contenteditable><b id='one'></b><b i
d='two'>22</b></p>"; | 30 const char* bodyContent = "<p id='host' contenteditable><b id='one'></b><b i
d='two'>22</b></p>"; |
| 31 const char* shadowContent = "<content select=#two></content><content select=
#one></content><b id='three'>333</b>"; | 31 const char* shadowContent = "<content select=#two></content><content select=
#one></content><b id='three'>333</b>"; |
| 32 setBodyContent(bodyContent); | 32 setBodyContent(bodyContent); |
| 33 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 33 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
| 34 updateLayoutAndStyleForPainting(); | 34 updateLayoutAndStyleForPainting(); |
| 35 Node* host = document().getElementById("host"); | 35 Node* host = document().getElementById("host"); |
| 36 Node* one = document().getElementById("one"); | 36 Node* one = document().getElementById("one"); |
| 37 Node* three = shadowRoot->getElementById("three"); | 37 Node* three = shadowRoot->getElementById("three"); |
| 38 | 38 |
| 39 EXPECT_EQ(Position(one, 0), firstEditablePositionAfterPositionInRoot(Positio
n(one, 0), host)); | 39 EXPECT_EQ(Position(one, 0), firstEditablePositionAfterPositionInRoot(Positio
n(one, 0), host)); |
| 40 | 40 |
| 41 EXPECT_EQ(PositionInComposedTree(one, 0), firstEditablePositionAfterPosition
InRoot(PositionInComposedTree(one, 0), host)); | 41 EXPECT_EQ(PositionInComposedTree(one, 0), firstEditablePositionAfterPosition
InRoot(PositionInComposedTree(one, 0), host)); |
| 42 | 42 |
| 43 EXPECT_EQ(Position::firstPositionInNode(host), firstEditablePositionAfterPos
itionInRoot(Position(three, 0), host)); | 43 EXPECT_EQ(Position::firstPositionInNode(host), firstEditablePositionAfterPos
itionInRoot(Position(three, 0), host)); |
| 44 EXPECT_EQ(PositionInComposedTree::afterNode(host), firstEditablePositionAfte
rPositionInRoot(PositionInComposedTree(three, 0), host)); | 44 EXPECT_EQ(PositionInComposedTree::afterNode(host), firstEditablePositionAfte
rPositionInRoot(PositionInComposedTree(three, 0), host)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 TEST_F(EditingUtilitiesTest, enclosingBlock) | 47 TEST_F(EditingUtilitiesTest, enclosingBlock) |
| 48 { | 48 { |
| 49 const char* bodyContent = "<p id='host'><b id='one'>11</b></p>"; | 49 const char* bodyContent = "<p id='host'><b id='one'>11</b></p>"; |
| 50 const char* shadowContent = "<content select=#two></content><div id='three'>
<content select=#one></content></div>"; | 50 const char* shadowContent = "<content select=#two></content><div id='three'>
<content select=#one></content></div>"; |
| 51 setBodyContent(bodyContent); | 51 setBodyContent(bodyContent); |
| 52 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 52 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
| 53 updateLayoutAndStyleForPainting(); | 53 updateLayoutAndStyleForPainting(); |
| 54 Node* host = document().getElementById("host"); | 54 Node* host = document().getElementById("host"); |
| 55 Node* one = document().getElementById("one"); | 55 Node* one = document().getElementById("one"); |
| 56 Node* three = shadowRoot->getElementById("three"); | 56 Node* three = shadowRoot->getElementById("three"); |
| 57 | 57 |
| 58 EXPECT_EQ(host, enclosingBlock(Position(one, 0), CannotCrossEditingBoundary)
); | 58 EXPECT_EQ(host, enclosingBlock(Position(one, 0), CannotCrossEditingBoundary)
); |
| 59 EXPECT_EQ(three, enclosingBlock(PositionInComposedTree(one, 0), CannotCrossE
ditingBoundary)); | 59 EXPECT_EQ(three, enclosingBlock(PositionInComposedTree(one, 0), CannotCrossE
ditingBoundary)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 TEST_F(EditingUtilitiesTest, enclosingNodeOfType) | 62 TEST_F(EditingUtilitiesTest, enclosingNodeOfType) |
| 63 { | 63 { |
| 64 const char* bodyContent = "<p id='host'><b id='one'>11</b></p>"; | 64 const char* bodyContent = "<p id='host'><b id='one'>11</b></p>"; |
| 65 const char* shadowContent = "<content select=#two></content><div id='three'>
<content select=#one></div></content>"; | 65 const char* shadowContent = "<content select=#two></content><div id='three'>
<content select=#one></div></content>"; |
| 66 setBodyContent(bodyContent); | 66 setBodyContent(bodyContent); |
| 67 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 67 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
| 68 updateLayoutAndStyleForPainting(); | 68 updateLayoutAndStyleForPainting(); |
| 69 Node* host = document().getElementById("host"); | 69 Node* host = document().getElementById("host"); |
| 70 Node* one = document().getElementById("one"); | 70 Node* one = document().getElementById("one"); |
| 71 Node* three = shadowRoot->getElementById("three"); | 71 Node* three = shadowRoot->getElementById("three"); |
| 72 | 72 |
| 73 EXPECT_EQ(host, enclosingNodeOfType(Position(one, 0), isEnclosingBlock)); | 73 EXPECT_EQ(host, enclosingNodeOfType(Position(one, 0), isEnclosingBlock)); |
| 74 EXPECT_EQ(three, enclosingNodeOfType(PositionInComposedTree(one, 0), isEnclo
singBlock)); | 74 EXPECT_EQ(three, enclosingNodeOfType(PositionInComposedTree(one, 0), isEnclo
singBlock)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 TEST_F(EditingUtilitiesTest, NextNodeIndex) | 77 TEST_F(EditingUtilitiesTest, NextNodeIndex) |
| 78 { | 78 { |
| 79 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 79 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
| 80 const char* shadowContent = "<content select=#two></content><content select=
#one></content>"; | 80 const char* shadowContent = "<content select=#two></content><content select=
#one></content>"; |
| 81 setBodyContent(bodyContent); | 81 setBodyContent(bodyContent); |
| 82 setShadowContent(shadowContent); | 82 setShadowContent(shadowContent, "host"); |
| 83 Node* host = document().getElementById("host"); | 83 Node* host = document().getElementById("host"); |
| 84 Node* two = document().getElementById("two"); | 84 Node* two = document().getElementById("two"); |
| 85 | 85 |
| 86 EXPECT_EQ(Position(host, 3), nextPositionOf(Position(two, 2), PositionMoveTy
pe::CodePoint)); | 86 EXPECT_EQ(Position(host, 3), nextPositionOf(Position(two, 2), PositionMoveTy
pe::CodePoint)); |
| 87 EXPECT_EQ(PositionInComposedTree(host, 1), nextPositionOf(PositionInComposed
Tree(two, 2), PositionMoveType::CodePoint)); | 87 EXPECT_EQ(PositionInComposedTree(host, 1), nextPositionOf(PositionInComposed
Tree(two, 2), PositionMoveType::CodePoint)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 TEST_F(EditingUtilitiesTest, NextVisuallyDistinctCandidate) | 90 TEST_F(EditingUtilitiesTest, NextVisuallyDistinctCandidate) |
| 91 { | 91 { |
| 92 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b><b id='three'>33</b></p>"; | 92 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b><b id='three'>33</b></p>"; |
| 93 const char* shadowContent = "<content select=#two></content><content select=
#one></content><content select=#three></content>"; | 93 const char* shadowContent = "<content select=#two></content><content select=
#one></content><content select=#three></content>"; |
| 94 setBodyContent(bodyContent); | 94 setBodyContent(bodyContent); |
| 95 setShadowContent(shadowContent); | 95 setShadowContent(shadowContent, "host"); |
| 96 updateLayoutAndStyleForPainting(); | 96 updateLayoutAndStyleForPainting(); |
| 97 Node* one = document().getElementById("one"); | 97 Node* one = document().getElementById("one"); |
| 98 Node* two = document().getElementById("two"); | 98 Node* two = document().getElementById("two"); |
| 99 Node* three = document().getElementById("three"); | 99 Node* three = document().getElementById("three"); |
| 100 | 100 |
| 101 EXPECT_EQ(Position(two->firstChild(), 1), nextVisuallyDistinctCandidate(Posi
tion(one, 1))); | 101 EXPECT_EQ(Position(two->firstChild(), 1), nextVisuallyDistinctCandidate(Posi
tion(one, 1))); |
| 102 EXPECT_EQ(PositionInComposedTree(three->firstChild(), 1), nextVisuallyDistin
ctCandidate(PositionInComposedTree(one, 1))); | 102 EXPECT_EQ(PositionInComposedTree(three->firstChild(), 1), nextVisuallyDistin
ctCandidate(PositionInComposedTree(one, 1))); |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |