| 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 "core/editing/VisibleSelection.h" | 5 #include "core/editing/VisibleSelection.h" |
| 6 | 6 |
| 7 #include "core/dom/Range.h" | 7 #include "core/dom/Range.h" |
| 8 #include "core/editing/EditingTestBase.h" | 8 #include "core/editing/EditingTestBase.h" |
| 9 #include "core/editing/SelectionAdjuster.h" | 9 #include "core/editing/SelectionAdjuster.h" |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 Node* one = document().getElementById("one")->firstChild(); | 58 Node* one = document().getElementById("one")->firstChild(); |
| 59 Node* two = document().getElementById("two")->firstChild(); | 59 Node* two = document().getElementById("two")->firstChild(); |
| 60 Node* three = shadowRoot->getElementById("three")->firstChild(); | 60 Node* three = shadowRoot->getElementById("three")->firstChild(); |
| 61 Node* four = shadowRoot->getElementById("four")->firstChild(); | 61 Node* four = shadowRoot->getElementById("four")->firstChild(); |
| 62 Node* five = shadowRoot->getElementById("five")->firstChild(); | 62 Node* five = shadowRoot->getElementById("five")->firstChild(); |
| 63 | 63 |
| 64 VisibleSelection selection; | 64 VisibleSelection selection; |
| 65 VisibleSelectionInFlatTree selectionInFlatTree; | 65 VisibleSelectionInFlatTree selectionInFlatTree; |
| 66 | 66 |
| 67 // From a position at distributed node | 67 // From a position at distributed node |
| 68 selection = VisibleSelection(createVisiblePosition(Position(one, 1))); | 68 selection = createVisibleSelectionDeprecated(createVisiblePosition(Position(
one, 1))); |
| 69 selection.expandUsingGranularity(WordGranularity); | 69 selection.expandUsingGranularity(WordGranularity); |
| 70 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePosition(Posit
ionInFlatTree(one, 1))); | 70 selectionInFlatTree = createVisibleSelectionDeprecated(createVisiblePosition
(PositionInFlatTree(one, 1))); |
| 71 selectionInFlatTree.expandUsingGranularity(WordGranularity); | 71 selectionInFlatTree.expandUsingGranularity(WordGranularity); |
| 72 | 72 |
| 73 EXPECT_EQ(Position(one, 1), selection.base()); | 73 EXPECT_EQ(Position(one, 1), selection.base()); |
| 74 EXPECT_EQ(Position(one, 1), selection.extent()); | 74 EXPECT_EQ(Position(one, 1), selection.extent()); |
| 75 EXPECT_EQ(Position(one, 0), selection.start()); | 75 EXPECT_EQ(Position(one, 0), selection.start()); |
| 76 EXPECT_EQ(Position(two, 2), selection.end()); | 76 EXPECT_EQ(Position(two, 2), selection.end()); |
| 77 | 77 |
| 78 EXPECT_EQ(PositionInFlatTree(one, 1), selectionInFlatTree.base()); | 78 EXPECT_EQ(PositionInFlatTree(one, 1), selectionInFlatTree.base()); |
| 79 EXPECT_EQ(PositionInFlatTree(one, 1), selectionInFlatTree.extent()); | 79 EXPECT_EQ(PositionInFlatTree(one, 1), selectionInFlatTree.extent()); |
| 80 EXPECT_EQ(PositionInFlatTree(one, 0), selectionInFlatTree.start()); | 80 EXPECT_EQ(PositionInFlatTree(one, 0), selectionInFlatTree.start()); |
| 81 EXPECT_EQ(PositionInFlatTree(five, 5), selectionInFlatTree.end()); | 81 EXPECT_EQ(PositionInFlatTree(five, 5), selectionInFlatTree.end()); |
| 82 | 82 |
| 83 // From a position at distributed node | 83 // From a position at distributed node |
| 84 selection = VisibleSelection(createVisiblePosition(Position(two, 1))); | 84 selection = createVisibleSelectionDeprecated(createVisiblePosition(Position(
two, 1))); |
| 85 selection.expandUsingGranularity(WordGranularity); | 85 selection.expandUsingGranularity(WordGranularity); |
| 86 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePosition(Posit
ionInFlatTree(two, 1))); | 86 selectionInFlatTree = createVisibleSelectionDeprecated(createVisiblePosition
(PositionInFlatTree(two, 1))); |
| 87 selectionInFlatTree.expandUsingGranularity(WordGranularity); | 87 selectionInFlatTree.expandUsingGranularity(WordGranularity); |
| 88 | 88 |
| 89 EXPECT_EQ(Position(two, 1), selection.base()); | 89 EXPECT_EQ(Position(two, 1), selection.base()); |
| 90 EXPECT_EQ(Position(two, 1), selection.extent()); | 90 EXPECT_EQ(Position(two, 1), selection.extent()); |
| 91 EXPECT_EQ(Position(one, 0), selection.start()); | 91 EXPECT_EQ(Position(one, 0), selection.start()); |
| 92 EXPECT_EQ(Position(two, 2), selection.end()); | 92 EXPECT_EQ(Position(two, 2), selection.end()); |
| 93 | 93 |
| 94 EXPECT_EQ(PositionInFlatTree(two, 1), selectionInFlatTree.base()); | 94 EXPECT_EQ(PositionInFlatTree(two, 1), selectionInFlatTree.base()); |
| 95 EXPECT_EQ(PositionInFlatTree(two, 1), selectionInFlatTree.extent()); | 95 EXPECT_EQ(PositionInFlatTree(two, 1), selectionInFlatTree.extent()); |
| 96 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); | 96 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); |
| 97 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); | 97 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); |
| 98 | 98 |
| 99 // From a position at node in shadow tree | 99 // From a position at node in shadow tree |
| 100 selection = VisibleSelection(createVisiblePosition(Position(three, 1))); | 100 selection = createVisibleSelectionDeprecated(createVisiblePosition(Position(
three, 1))); |
| 101 selection.expandUsingGranularity(WordGranularity); | 101 selection.expandUsingGranularity(WordGranularity); |
| 102 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePosition(Posit
ionInFlatTree(three, 1))); | 102 selectionInFlatTree = createVisibleSelectionDeprecated(createVisiblePosition
(PositionInFlatTree(three, 1))); |
| 103 selectionInFlatTree.expandUsingGranularity(WordGranularity); | 103 selectionInFlatTree.expandUsingGranularity(WordGranularity); |
| 104 | 104 |
| 105 EXPECT_EQ(Position(three, 1), selection.base()); | 105 EXPECT_EQ(Position(three, 1), selection.base()); |
| 106 EXPECT_EQ(Position(three, 1), selection.extent()); | 106 EXPECT_EQ(Position(three, 1), selection.extent()); |
| 107 EXPECT_EQ(Position(three, 0), selection.start()); | 107 EXPECT_EQ(Position(three, 0), selection.start()); |
| 108 EXPECT_EQ(Position(four, 4), selection.end()); | 108 EXPECT_EQ(Position(four, 4), selection.end()); |
| 109 | 109 |
| 110 EXPECT_EQ(PositionInFlatTree(three, 1), selectionInFlatTree.base()); | 110 EXPECT_EQ(PositionInFlatTree(three, 1), selectionInFlatTree.base()); |
| 111 EXPECT_EQ(PositionInFlatTree(three, 1), selectionInFlatTree.extent()); | 111 EXPECT_EQ(PositionInFlatTree(three, 1), selectionInFlatTree.extent()); |
| 112 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); | 112 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); |
| 113 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); | 113 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); |
| 114 | 114 |
| 115 // From a position at node in shadow tree | 115 // From a position at node in shadow tree |
| 116 selection = VisibleSelection(createVisiblePosition(Position(four, 1))); | 116 selection = createVisibleSelectionDeprecated(createVisiblePosition(Position(
four, 1))); |
| 117 selection.expandUsingGranularity(WordGranularity); | 117 selection.expandUsingGranularity(WordGranularity); |
| 118 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePosition(Posit
ionInFlatTree(four, 1))); | 118 selectionInFlatTree = createVisibleSelectionDeprecated(createVisiblePosition
(PositionInFlatTree(four, 1))); |
| 119 selectionInFlatTree.expandUsingGranularity(WordGranularity); | 119 selectionInFlatTree.expandUsingGranularity(WordGranularity); |
| 120 | 120 |
| 121 EXPECT_EQ(Position(four, 1), selection.base()); | 121 EXPECT_EQ(Position(four, 1), selection.base()); |
| 122 EXPECT_EQ(Position(four, 1), selection.extent()); | 122 EXPECT_EQ(Position(four, 1), selection.extent()); |
| 123 EXPECT_EQ(Position(three, 0), selection.start()); | 123 EXPECT_EQ(Position(three, 0), selection.start()); |
| 124 EXPECT_EQ(Position(four, 4), selection.end()); | 124 EXPECT_EQ(Position(four, 4), selection.end()); |
| 125 | 125 |
| 126 EXPECT_EQ(PositionInFlatTree(four, 1), selectionInFlatTree.base()); | 126 EXPECT_EQ(PositionInFlatTree(four, 1), selectionInFlatTree.base()); |
| 127 EXPECT_EQ(PositionInFlatTree(four, 1), selectionInFlatTree.extent()); | 127 EXPECT_EQ(PositionInFlatTree(four, 1), selectionInFlatTree.extent()); |
| 128 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); | 128 EXPECT_EQ(PositionInFlatTree(three, 0), selectionInFlatTree.start()); |
| 129 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); | 129 EXPECT_EQ(PositionInFlatTree(four, 4), selectionInFlatTree.end()); |
| 130 | 130 |
| 131 // From a position at node in shadow tree | 131 // From a position at node in shadow tree |
| 132 selection = VisibleSelection(createVisiblePosition(Position(five, 1))); | 132 selection = createVisibleSelectionDeprecated(createVisiblePosition(Position(
five, 1))); |
| 133 selection.expandUsingGranularity(WordGranularity); | 133 selection.expandUsingGranularity(WordGranularity); |
| 134 selectionInFlatTree = VisibleSelectionInFlatTree(createVisiblePosition(Posit
ionInFlatTree(five, 1))); | 134 selectionInFlatTree = createVisibleSelectionDeprecated(createVisiblePosition
(PositionInFlatTree(five, 1))); |
| 135 selectionInFlatTree.expandUsingGranularity(WordGranularity); | 135 selectionInFlatTree.expandUsingGranularity(WordGranularity); |
| 136 | 136 |
| 137 EXPECT_EQ(Position(five, 1), selection.base()); | 137 EXPECT_EQ(Position(five, 1), selection.base()); |
| 138 EXPECT_EQ(Position(five, 1), selection.extent()); | 138 EXPECT_EQ(Position(five, 1), selection.extent()); |
| 139 EXPECT_EQ(Position(five, 0), selection.start()); | 139 EXPECT_EQ(Position(five, 0), selection.start()); |
| 140 EXPECT_EQ(Position(five, 5), selection.end()); | 140 EXPECT_EQ(Position(five, 5), selection.end()); |
| 141 | 141 |
| 142 EXPECT_EQ(PositionInFlatTree(five, 1), selectionInFlatTree.base()); | 142 EXPECT_EQ(PositionInFlatTree(five, 1), selectionInFlatTree.base()); |
| 143 EXPECT_EQ(PositionInFlatTree(five, 1), selectionInFlatTree.extent()); | 143 EXPECT_EQ(PositionInFlatTree(five, 1), selectionInFlatTree.extent()); |
| 144 EXPECT_EQ(PositionInFlatTree(one, 0), selectionInFlatTree.start()); | 144 EXPECT_EQ(PositionInFlatTree(one, 0), selectionInFlatTree.start()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 171 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 171 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
| 172 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>"; | 172 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>"; |
| 173 setBodyContent(bodyContent); | 173 setBodyContent(bodyContent); |
| 174 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 174 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| 175 | 175 |
| 176 Element* body = document().body(); | 176 Element* body = document().body(); |
| 177 Element* host = body->querySelector("#host"); | 177 Element* host = body->querySelector("#host"); |
| 178 Element* one = body->querySelector("#one"); | 178 Element* one = body->querySelector("#one"); |
| 179 Element* six = shadowRoot->querySelector("#s6"); | 179 Element* six = shadowRoot->querySelector("#s6"); |
| 180 | 180 |
| 181 VisibleSelection selection(Position::firstPositionInNode(one), Position::las
tPositionInNode(shadowRoot)); | 181 VisibleSelection selection = createVisibleSelectionDeprecated(Position::firs
tPositionInNode(one), Position::lastPositionInNode(shadowRoot)); |
| 182 VisibleSelectionInFlatTree selectionInFlatTree(PositionInFlatTree::firstPosi
tionInNode(one), PositionInFlatTree::lastPositionInNode(host)); | 182 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelectionDepre
cated(PositionInFlatTree::firstPositionInNode(one), PositionInFlatTree::lastPosi
tionInNode(host)); |
| 183 | 183 |
| 184 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), selection.start(
)); | 184 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), selection.start(
)); |
| 185 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); | 185 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); |
| 186 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0), selectionInFlatTree.star
t()); | 186 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0), selectionInFlatTree.star
t()); |
| 187 EXPECT_EQ(PositionInFlatTree(six->firstChild(), 2), selectionInFlatTree.end(
)); | 187 EXPECT_EQ(PositionInFlatTree(six->firstChild(), 2), selectionInFlatTree.end(
)); |
| 188 } | 188 } |
| 189 | 189 |
| 190 TEST_F(VisibleSelectionTest, ShadowV0DistributedNodes) | 190 TEST_F(VisibleSelectionTest, ShadowV0DistributedNodes) |
| 191 { | 191 { |
| 192 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 192 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
| 193 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>"; | 193 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>"; |
| 194 setBodyContent(bodyContent); | 194 setBodyContent(bodyContent); |
| 195 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 195 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| 196 | 196 |
| 197 Element* body = document().body(); | 197 Element* body = document().body(); |
| 198 Element* one = body->querySelector("#one"); | 198 Element* one = body->querySelector("#one"); |
| 199 Element* two = body->querySelector("#two"); | 199 Element* two = body->querySelector("#two"); |
| 200 Element* five = shadowRoot->querySelector("#s5"); | 200 Element* five = shadowRoot->querySelector("#s5"); |
| 201 | 201 |
| 202 VisibleSelection selection(Position::firstPositionInNode(one), Position::las
tPositionInNode(two)); | 202 VisibleSelection selection = createVisibleSelectionDeprecated(Position::firs
tPositionInNode(one), Position::lastPositionInNode(two)); |
| 203 VisibleSelectionInFlatTree selectionInFlatTree(PositionInFlatTree::firstPosi
tionInNode(one), PositionInFlatTree::lastPositionInNode(two)); | 203 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelectionDepre
cated(PositionInFlatTree::firstPositionInNode(one), PositionInFlatTree::lastPosi
tionInNode(two)); |
| 204 | 204 |
| 205 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); | 205 EXPECT_EQ(Position(one->firstChild(), 0), selection.start()); |
| 206 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); | 206 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); |
| 207 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0), selectionInFlatTree.sta
rt()); | 207 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0), selectionInFlatTree.sta
rt()); |
| 208 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2), selectionInFlatTree.end
()); | 208 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2), selectionInFlatTree.end
()); |
| 209 } | 209 } |
| 210 | 210 |
| 211 TEST_F(VisibleSelectionTest, ShadowNested) | 211 TEST_F(VisibleSelectionTest, ShadowNested) |
| 212 { | 212 { |
| 213 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; | 213 const char* bodyContent = "<p id='host'>00<b id='one'>11</b><b id='two'>22</
b>33</p>"; |
| 214 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>"; | 214 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>"; |
| 215 const char* shadowContent2 = "<span id='s7'>77</span><content></content><spa
n id='s8'>88</span>"; | 215 const char* shadowContent2 = "<span id='s7'>77</span><content></content><spa
n id='s8'>88</span>"; |
| 216 setBodyContent(bodyContent); | 216 setBodyContent(bodyContent); |
| 217 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 217 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| 218 ShadowRoot* shadowRoot2 = createShadowRootForElementWithIDAndSetInnerHTML(*s
hadowRoot, "s5", shadowContent2); | 218 ShadowRoot* shadowRoot2 = createShadowRootForElementWithIDAndSetInnerHTML(*s
hadowRoot, "s5", shadowContent2); |
| 219 | 219 |
| 220 // Flat tree is something like below: | 220 // Flat tree is something like below: |
| 221 // <p id="host"> | 221 // <p id="host"> |
| 222 // <span id="s4">44</span> | 222 // <span id="s4">44</span> |
| 223 // <b id="two">22</b> | 223 // <b id="two">22</b> |
| 224 // <span id="s5"><span id="s7">77>55</span id="s8">88</span> | 224 // <span id="s5"><span id="s7">77>55</span id="s8">88</span> |
| 225 // <b id="one">11</b> | 225 // <b id="one">11</b> |
| 226 // <span id="s6">66</span> | 226 // <span id="s6">66</span> |
| 227 // </p> | 227 // </p> |
| 228 Element* body = document().body(); | 228 Element* body = document().body(); |
| 229 Element* host = body->querySelector("#host"); | 229 Element* host = body->querySelector("#host"); |
| 230 Element* one = body->querySelector("#one"); | 230 Element* one = body->querySelector("#one"); |
| 231 Element* eight = shadowRoot2->querySelector("#s8"); | 231 Element* eight = shadowRoot2->querySelector("#s8"); |
| 232 | 232 |
| 233 VisibleSelection selection(Position::firstPositionInNode(one), Position::las
tPositionInNode(shadowRoot2)); | 233 VisibleSelection selection = createVisibleSelectionDeprecated(Position::firs
tPositionInNode(one), Position::lastPositionInNode(shadowRoot2)); |
| 234 VisibleSelectionInFlatTree selectionInFlatTree(PositionInFlatTree::firstPosi
tionInNode(one), PositionInFlatTree::afterNode(eight)); | 234 VisibleSelectionInFlatTree selectionInFlatTree = createVisibleSelectionDepre
cated(PositionInFlatTree::firstPositionInNode(one), PositionInFlatTree::afterNod
e(eight)); |
| 235 | 235 |
| 236 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), selection.start(
)); | 236 EXPECT_EQ(Position(host, PositionAnchorType::BeforeAnchor), selection.start(
)); |
| 237 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); | 237 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); |
| 238 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), selectionInFlatTree.st
art()); | 238 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), selectionInFlatTree.st
art()); |
| 239 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), selectionInFlatTree.en
d()); | 239 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), selectionInFlatTree.en
d()); |
| 240 } | 240 } |
| 241 | 241 |
| 242 TEST_F(VisibleSelectionTest, WordGranularity) | 242 TEST_F(VisibleSelectionTest, WordGranularity) |
| 243 { | 243 { |
| 244 setBodyContent(LOREM_IPSUM); | 244 setBodyContent(LOREM_IPSUM); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 | 353 |
| 354 // This is for crbug.com/627783, simulating restoring selection | 354 // This is for crbug.com/627783, simulating restoring selection |
| 355 // in undo stack. | 355 // in undo stack. |
| 356 TEST_F(VisibleSelectionTest, validatePositionsIfNeededWithShadowHost) | 356 TEST_F(VisibleSelectionTest, validatePositionsIfNeededWithShadowHost) |
| 357 { | 357 { |
| 358 setBodyContent("<div id=host></div><div id=sample>foo</div>"); | 358 setBodyContent("<div id=host></div><div id=sample>foo</div>"); |
| 359 setShadowContent("<content>", "host"); | 359 setShadowContent("<content>", "host"); |
| 360 Element* sample = document().getElementById("sample"); | 360 Element* sample = document().getElementById("sample"); |
| 361 | 361 |
| 362 // Simulates saving selection in undo stack. | 362 // Simulates saving selection in undo stack. |
| 363 VisibleSelection selection(Position(sample->firstChild(), 0)); | 363 VisibleSelection selection = createVisibleSelectionDeprecated(Position(sampl
e->firstChild(), 0)); |
| 364 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); | 364 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); |
| 365 | 365 |
| 366 // Simulates modifying DOM tree to invalidate distribution. | 366 // Simulates modifying DOM tree to invalidate distribution. |
| 367 Element* host = document().getElementById("host"); | 367 Element* host = document().getElementById("host"); |
| 368 host->appendChild(sample); | 368 host->appendChild(sample); |
| 369 | 369 |
| 370 // Simulates to restore selection from undo stack. | 370 // Simulates to restore selection from undo stack. |
| 371 selection.validatePositionsIfNeeded(); | 371 selection.validatePositionsIfNeeded(); |
| 372 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); | 372 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); |
| 373 | 373 |
| 374 VisibleSelectionInFlatTree selectionInFlatTree; | 374 VisibleSelectionInFlatTree selectionInFlatTree; |
| 375 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection
); | 375 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection
); |
| 376 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), selectionInFlatTree.s
tart()); | 376 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), selectionInFlatTree.s
tart()); |
| 377 } | 377 } |
| 378 | 378 |
| 379 } // namespace blink | 379 } // namespace blink |
| OLD | NEW |