| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/VisibleSelection.h" | 6 #include "core/editing/VisibleSelection.h" |
| 7 | 7 |
| 8 #include "core/dom/Range.h" | 8 #include "core/dom/Range.h" |
| 9 #include "core/editing/EditingTestBase.h" | 9 #include "core/editing/EditingTestBase.h" |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 EXPECT_EQ(0, range->endOffset()); | 66 EXPECT_EQ(0, range->endOffset()); |
| 67 EXPECT_EQ("", range->text()); | 67 EXPECT_EQ("", range->text()); |
| 68 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 68 testComposedTreePositionsToEqualToDOMTreePositions(selection); |
| 69 } | 69 } |
| 70 | 70 |
| 71 TEST_F(VisibleSelectionTest, ShadowCrossing) | 71 TEST_F(VisibleSelectionTest, ShadowCrossing) |
| 72 { | 72 { |
| 73 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 73 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
| 74 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; | 74 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; |
| 75 setBodyContent(bodyContent); | 75 setBodyContent(bodyContent); |
| 76 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 76 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
| 77 | 77 |
| 78 RefPtrWillBeRawPtr<Element> body = document().body(); | 78 RefPtrWillBeRawPtr<Element> body = document().body(); |
| 79 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX
CEPTION); | 79 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX
CEPTION); |
| 80 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); | 80 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); |
| 81 RefPtrWillBeRawPtr<Element> six = shadowRoot->querySelector("#s6", ASSERT_NO
_EXCEPTION); | 81 RefPtrWillBeRawPtr<Element> six = shadowRoot->querySelector("#s6", ASSERT_NO
_EXCEPTION); |
| 82 | 82 |
| 83 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(shadowRoot.get())); | 83 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(shadowRoot.get())); |
| 84 | 84 |
| 85 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection.
start()); | 85 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection.
start()); |
| 86 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); | 86 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); |
| 87 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 0), selection.startInCom
posedTree()); | 87 EXPECT_EQ(PositionInComposedTree(one->firstChild(), 0), selection.startInCom
posedTree()); |
| 88 EXPECT_EQ(PositionInComposedTree(six->firstChild(), 2), selection.endInCompo
sedTree()); | 88 EXPECT_EQ(PositionInComposedTree(six->firstChild(), 2), selection.endInCompo
sedTree()); |
| 89 } | 89 } |
| 90 | 90 |
| 91 TEST_F(VisibleSelectionTest, ShadowDistributedNodes) | 91 TEST_F(VisibleSelectionTest, ShadowDistributedNodes) |
| 92 { | 92 { |
| 93 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 93 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
| 94 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; | 94 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; |
| 95 setBodyContent(bodyContent); | 95 setBodyContent(bodyContent); |
| 96 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 96 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
| 97 | 97 |
| 98 RefPtrWillBeRawPtr<Element> body = document().body(); | 98 RefPtrWillBeRawPtr<Element> body = document().body(); |
| 99 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); | 99 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); |
| 100 RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCE
PTION); | 100 RefPtrWillBeRawPtr<Element> two = body->querySelector("#two", ASSERT_NO_EXCE
PTION); |
| 101 RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_N
O_EXCEPTION); | 101 RefPtrWillBeRawPtr<Element> five = shadowRoot->querySelector("#s5", ASSERT_N
O_EXCEPTION); |
| 102 | 102 |
| 103 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(two.get())); | 103 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(two.get())); |
| 104 | 104 |
| 105 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); | 105 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); |
| 106 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); | 106 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); |
| 107 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 0), selection.startInCo
mposedTree()); | 107 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 0), selection.startInCo
mposedTree()); |
| 108 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 2), selection.endInComp
osedTree()); | 108 EXPECT_EQ(PositionInComposedTree(five->firstChild(), 2), selection.endInComp
osedTree()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 TEST_F(VisibleSelectionTest, ShadowNested) | 111 TEST_F(VisibleSelectionTest, ShadowNested) |
| 112 { | 112 { |
| 113 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 113 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
| 114 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; | 114 const char* shadowContent = "<a><span id='s4'>44</span><content select=#two>
</content><span id='s5'>55</span><content select=#one></content><span id='s6'>66
</span></a>"; |
| 115 const char* shadowContent2 = "<span id='s7'>77</span><content></content><spa
n id='s8'>88</span>"; | 115 const char* shadowContent2 = "<span id='s7'>77</span><content></content><spa
n id='s8'>88</span>"; |
| 116 setBodyContent(bodyContent); | 116 setBodyContent(bodyContent); |
| 117 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent); | 117 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot = setShadowContent(shadowContent,
"host"); |
| 118 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot2 = createShadowRootForElementWithI
DAndSetInnerHTML(*shadowRoot, "s5", shadowContent2); | 118 RefPtrWillBeRawPtr<ShadowRoot> shadowRoot2 = createShadowRootForElementWithI
DAndSetInnerHTML(*shadowRoot, "s5", shadowContent2); |
| 119 | 119 |
| 120 RefPtrWillBeRawPtr<Element> body = document().body(); | 120 RefPtrWillBeRawPtr<Element> body = document().body(); |
| 121 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX
CEPTION); | 121 RefPtrWillBeRawPtr<Element> host = body->querySelector("#host", ASSERT_NO_EX
CEPTION); |
| 122 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); | 122 RefPtrWillBeRawPtr<Element> one = body->querySelector("#one", ASSERT_NO_EXCE
PTION); |
| 123 RefPtrWillBeRawPtr<Element> eight = shadowRoot2->querySelector("#s8", ASSERT
_NO_EXCEPTION); | 123 RefPtrWillBeRawPtr<Element> eight = shadowRoot2->querySelector("#s8", ASSERT
_NO_EXCEPTION); |
| 124 | 124 |
| 125 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(shadowRoot2.get())); | 125 VisibleSelection selection(Position::firstPositionInNode(one.get()), Positio
n::lastPositionInNode(shadowRoot2.get())); |
| 126 | 126 |
| 127 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection.
start()); | 127 EXPECT_EQ(Position(host.get(), PositionAnchorType::BeforeAnchor), selection.
start()); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 221 |
| 222 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); | 222 RefPtrWillBeRawPtr<Range> range = firstRangeOf(selection); |
| 223 EXPECT_EQ(0, range->startOffset()); | 223 EXPECT_EQ(0, range->startOffset()); |
| 224 EXPECT_EQ(11, range->endOffset()); | 224 EXPECT_EQ(11, range->endOffset()); |
| 225 EXPECT_EQ("Lorem ipsum", range->text()); | 225 EXPECT_EQ("Lorem ipsum", range->text()); |
| 226 testComposedTreePositionsToEqualToDOMTreePositions(selection); | 226 testComposedTreePositionsToEqualToDOMTreePositions(selection); |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 | 229 |
| 230 } // namespace blink | 230 } // namespace blink |
| OLD | NEW |