| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 static void TestFlatTreePositionsToEqualToDOMTreePositions( | 48 static void TestFlatTreePositionsToEqualToDOMTreePositions( |
| 49 const VisibleSelection& selection, | 49 const VisibleSelection& selection, |
| 50 const VisibleSelectionInFlatTree& selection_in_flat_tree) { | 50 const VisibleSelectionInFlatTree& selection_in_flat_tree) { |
| 51 // Since DOM tree positions can't be map to flat tree version, e.g. | 51 // Since DOM tree positions can't be map to flat tree version, e.g. |
| 52 // shadow root, not distributed node, we map a position in flat tree | 52 // shadow root, not distributed node, we map a position in flat tree |
| 53 // to DOM tree position. | 53 // to DOM tree position. |
| 54 EXPECT_EQ(selection.Start(), | 54 EXPECT_EQ(selection.Start(), |
| 55 ToPositionInDOMTree(selection_in_flat_tree.Start())); | 55 ToPositionInDOMTree(selection_in_flat_tree.Start())); |
| 56 EXPECT_EQ(selection.end(), ToPositionInDOMTree(selection_in_flat_tree.end())); | 56 EXPECT_EQ(selection.End(), ToPositionInDOMTree(selection_in_flat_tree.End())); |
| 57 EXPECT_EQ(selection.Base(), | 57 EXPECT_EQ(selection.Base(), |
| 58 ToPositionInDOMTree(selection_in_flat_tree.Base())); | 58 ToPositionInDOMTree(selection_in_flat_tree.Base())); |
| 59 EXPECT_EQ(selection.Extent(), | 59 EXPECT_EQ(selection.Extent(), |
| 60 ToPositionInDOMTree(selection_in_flat_tree.Extent())); | 60 ToPositionInDOMTree(selection_in_flat_tree.Extent())); |
| 61 } | 61 } |
| 62 | 62 |
| 63 template <typename Strategy> | 63 template <typename Strategy> |
| 64 VisibleSelectionTemplate<Strategy> ExpandUsingGranularity( | 64 VisibleSelectionTemplate<Strategy> ExpandUsingGranularity( |
| 65 const VisibleSelectionTemplate<Strategy>& selection, | 65 const VisibleSelectionTemplate<Strategy>& selection, |
| 66 TextGranularity granularity) { | 66 TextGranularity granularity) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 84 // compute selection. | 84 // compute selection. |
| 85 VisibleSelection selection = | 85 VisibleSelection selection = |
| 86 CreateVisibleSelection(SelectionInDOMTree::Builder() | 86 CreateVisibleSelection(SelectionInDOMTree::Builder() |
| 87 .Collapse(Position::BeforeNode(input)) | 87 .Collapse(Position::BeforeNode(input)) |
| 88 .Extend(Position::AfterNode(input)) | 88 .Extend(Position::AfterNode(input)) |
| 89 .SetGranularity(kWordGranularity) | 89 .SetGranularity(kWordGranularity) |
| 90 .Build()); | 90 .Build()); |
| 91 selection.AppendTrailingWhitespace(); | 91 selection.AppendTrailingWhitespace(); |
| 92 | 92 |
| 93 EXPECT_EQ(Position::BeforeNode(input), selection.Start()); | 93 EXPECT_EQ(Position::BeforeNode(input), selection.Start()); |
| 94 EXPECT_EQ(Position::AfterNode(input), selection.end()); | 94 EXPECT_EQ(Position::AfterNode(input), selection.End()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 TEST_F(VisibleSelectionTest, expandUsingGranularity) { | 97 TEST_F(VisibleSelectionTest, expandUsingGranularity) { |
| 98 const char* body_content = | 98 const char* body_content = |
| 99 "<span id=host><a id=one>1</a><a id=two>22</a></span>"; | 99 "<span id=host><a id=one>1</a><a id=two>22</a></span>"; |
| 100 const char* shadow_content = | 100 const char* shadow_content = |
| 101 "<p><b id=three>333</b><content select=#two></content><b " | 101 "<p><b id=three>333</b><content select=#two></content><b " |
| 102 "id=four>4444</b><span id=space> </span><content " | 102 "id=four>4444</b><span id=space> </span><content " |
| 103 "select=#one></content><b id=five>55555</b></p>"; | 103 "select=#one></content><b id=five>55555</b></p>"; |
| 104 SetBodyContent(body_content); | 104 SetBodyContent(body_content); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 120 selection_in_flat_tree = | 120 selection_in_flat_tree = |
| 121 CreateVisibleSelection(SelectionInFlatTree::Builder() | 121 CreateVisibleSelection(SelectionInFlatTree::Builder() |
| 122 .Collapse(PositionInFlatTree(one, 1)) | 122 .Collapse(PositionInFlatTree(one, 1)) |
| 123 .Build()); | 123 .Build()); |
| 124 selection_in_flat_tree = | 124 selection_in_flat_tree = |
| 125 ExpandUsingGranularity(selection_in_flat_tree, kWordGranularity); | 125 ExpandUsingGranularity(selection_in_flat_tree, kWordGranularity); |
| 126 | 126 |
| 127 EXPECT_EQ(Position(one, 1), selection.Base()); | 127 EXPECT_EQ(Position(one, 1), selection.Base()); |
| 128 EXPECT_EQ(Position(one, 1), selection.Extent()); | 128 EXPECT_EQ(Position(one, 1), selection.Extent()); |
| 129 EXPECT_EQ(Position(one, 0), selection.Start()); | 129 EXPECT_EQ(Position(one, 0), selection.Start()); |
| 130 EXPECT_EQ(Position(two, 2), selection.end()); | 130 EXPECT_EQ(Position(two, 2), selection.End()); |
| 131 | 131 |
| 132 EXPECT_EQ(PositionInFlatTree(one, 1), selection_in_flat_tree.Base()); | 132 EXPECT_EQ(PositionInFlatTree(one, 1), selection_in_flat_tree.Base()); |
| 133 EXPECT_EQ(PositionInFlatTree(one, 1), selection_in_flat_tree.Extent()); | 133 EXPECT_EQ(PositionInFlatTree(one, 1), selection_in_flat_tree.Extent()); |
| 134 EXPECT_EQ(PositionInFlatTree(one, 0), selection_in_flat_tree.Start()); | 134 EXPECT_EQ(PositionInFlatTree(one, 0), selection_in_flat_tree.Start()); |
| 135 EXPECT_EQ(PositionInFlatTree(five, 5), selection_in_flat_tree.end()); | 135 EXPECT_EQ(PositionInFlatTree(five, 5), selection_in_flat_tree.End()); |
| 136 | 136 |
| 137 // From a position at distributed node | 137 // From a position at distributed node |
| 138 selection = CreateVisibleSelection( | 138 selection = CreateVisibleSelection( |
| 139 SelectionInDOMTree::Builder().Collapse(Position(two, 1)).Build()); | 139 SelectionInDOMTree::Builder().Collapse(Position(two, 1)).Build()); |
| 140 selection = ExpandUsingGranularity(selection, kWordGranularity); | 140 selection = ExpandUsingGranularity(selection, kWordGranularity); |
| 141 selection_in_flat_tree = | 141 selection_in_flat_tree = |
| 142 CreateVisibleSelection(SelectionInFlatTree::Builder() | 142 CreateVisibleSelection(SelectionInFlatTree::Builder() |
| 143 .Collapse(PositionInFlatTree(two, 1)) | 143 .Collapse(PositionInFlatTree(two, 1)) |
| 144 .Build()); | 144 .Build()); |
| 145 selection_in_flat_tree = | 145 selection_in_flat_tree = |
| 146 ExpandUsingGranularity(selection_in_flat_tree, kWordGranularity); | 146 ExpandUsingGranularity(selection_in_flat_tree, kWordGranularity); |
| 147 | 147 |
| 148 EXPECT_EQ(Position(two, 1), selection.Base()); | 148 EXPECT_EQ(Position(two, 1), selection.Base()); |
| 149 EXPECT_EQ(Position(two, 1), selection.Extent()); | 149 EXPECT_EQ(Position(two, 1), selection.Extent()); |
| 150 EXPECT_EQ(Position(one, 0), selection.Start()); | 150 EXPECT_EQ(Position(one, 0), selection.Start()); |
| 151 EXPECT_EQ(Position(two, 2), selection.end()); | 151 EXPECT_EQ(Position(two, 2), selection.End()); |
| 152 | 152 |
| 153 EXPECT_EQ(PositionInFlatTree(two, 1), selection_in_flat_tree.Base()); | 153 EXPECT_EQ(PositionInFlatTree(two, 1), selection_in_flat_tree.Base()); |
| 154 EXPECT_EQ(PositionInFlatTree(two, 1), selection_in_flat_tree.Extent()); | 154 EXPECT_EQ(PositionInFlatTree(two, 1), selection_in_flat_tree.Extent()); |
| 155 EXPECT_EQ(PositionInFlatTree(three, 0), selection_in_flat_tree.Start()); | 155 EXPECT_EQ(PositionInFlatTree(three, 0), selection_in_flat_tree.Start()); |
| 156 EXPECT_EQ(PositionInFlatTree(four, 4), selection_in_flat_tree.end()); | 156 EXPECT_EQ(PositionInFlatTree(four, 4), selection_in_flat_tree.End()); |
| 157 | 157 |
| 158 // From a position at node in shadow tree | 158 // From a position at node in shadow tree |
| 159 selection = CreateVisibleSelection( | 159 selection = CreateVisibleSelection( |
| 160 SelectionInDOMTree::Builder().Collapse(Position(three, 1)).Build()); | 160 SelectionInDOMTree::Builder().Collapse(Position(three, 1)).Build()); |
| 161 selection = ExpandUsingGranularity(selection, kWordGranularity); | 161 selection = ExpandUsingGranularity(selection, kWordGranularity); |
| 162 selection_in_flat_tree = | 162 selection_in_flat_tree = |
| 163 CreateVisibleSelection(SelectionInFlatTree::Builder() | 163 CreateVisibleSelection(SelectionInFlatTree::Builder() |
| 164 .Collapse(PositionInFlatTree(three, 1)) | 164 .Collapse(PositionInFlatTree(three, 1)) |
| 165 .Build()); | 165 .Build()); |
| 166 selection_in_flat_tree = | 166 selection_in_flat_tree = |
| 167 ExpandUsingGranularity(selection_in_flat_tree, kWordGranularity); | 167 ExpandUsingGranularity(selection_in_flat_tree, kWordGranularity); |
| 168 | 168 |
| 169 EXPECT_EQ(Position(three, 1), selection.Base()); | 169 EXPECT_EQ(Position(three, 1), selection.Base()); |
| 170 EXPECT_EQ(Position(three, 1), selection.Extent()); | 170 EXPECT_EQ(Position(three, 1), selection.Extent()); |
| 171 EXPECT_EQ(Position(three, 0), selection.Start()); | 171 EXPECT_EQ(Position(three, 0), selection.Start()); |
| 172 EXPECT_EQ(Position(four, 4), selection.end()); | 172 EXPECT_EQ(Position(four, 4), selection.End()); |
| 173 | 173 |
| 174 EXPECT_EQ(PositionInFlatTree(three, 1), selection_in_flat_tree.Base()); | 174 EXPECT_EQ(PositionInFlatTree(three, 1), selection_in_flat_tree.Base()); |
| 175 EXPECT_EQ(PositionInFlatTree(three, 1), selection_in_flat_tree.Extent()); | 175 EXPECT_EQ(PositionInFlatTree(three, 1), selection_in_flat_tree.Extent()); |
| 176 EXPECT_EQ(PositionInFlatTree(three, 0), selection_in_flat_tree.Start()); | 176 EXPECT_EQ(PositionInFlatTree(three, 0), selection_in_flat_tree.Start()); |
| 177 EXPECT_EQ(PositionInFlatTree(four, 4), selection_in_flat_tree.end()); | 177 EXPECT_EQ(PositionInFlatTree(four, 4), selection_in_flat_tree.End()); |
| 178 | 178 |
| 179 // From a position at node in shadow tree | 179 // From a position at node in shadow tree |
| 180 selection = CreateVisibleSelection( | 180 selection = CreateVisibleSelection( |
| 181 SelectionInDOMTree::Builder().Collapse(Position(four, 1)).Build()); | 181 SelectionInDOMTree::Builder().Collapse(Position(four, 1)).Build()); |
| 182 selection = ExpandUsingGranularity(selection, kWordGranularity); | 182 selection = ExpandUsingGranularity(selection, kWordGranularity); |
| 183 selection_in_flat_tree = | 183 selection_in_flat_tree = |
| 184 CreateVisibleSelection(SelectionInFlatTree::Builder() | 184 CreateVisibleSelection(SelectionInFlatTree::Builder() |
| 185 .Collapse(PositionInFlatTree(four, 1)) | 185 .Collapse(PositionInFlatTree(four, 1)) |
| 186 .Build()); | 186 .Build()); |
| 187 selection_in_flat_tree = | 187 selection_in_flat_tree = |
| 188 ExpandUsingGranularity(selection_in_flat_tree, kWordGranularity); | 188 ExpandUsingGranularity(selection_in_flat_tree, kWordGranularity); |
| 189 | 189 |
| 190 EXPECT_EQ(Position(four, 1), selection.Base()); | 190 EXPECT_EQ(Position(four, 1), selection.Base()); |
| 191 EXPECT_EQ(Position(four, 1), selection.Extent()); | 191 EXPECT_EQ(Position(four, 1), selection.Extent()); |
| 192 EXPECT_EQ(Position(three, 0), selection.Start()); | 192 EXPECT_EQ(Position(three, 0), selection.Start()); |
| 193 EXPECT_EQ(Position(four, 4), selection.end()); | 193 EXPECT_EQ(Position(four, 4), selection.End()); |
| 194 | 194 |
| 195 EXPECT_EQ(PositionInFlatTree(four, 1), selection_in_flat_tree.Base()); | 195 EXPECT_EQ(PositionInFlatTree(four, 1), selection_in_flat_tree.Base()); |
| 196 EXPECT_EQ(PositionInFlatTree(four, 1), selection_in_flat_tree.Extent()); | 196 EXPECT_EQ(PositionInFlatTree(four, 1), selection_in_flat_tree.Extent()); |
| 197 EXPECT_EQ(PositionInFlatTree(three, 0), selection_in_flat_tree.Start()); | 197 EXPECT_EQ(PositionInFlatTree(three, 0), selection_in_flat_tree.Start()); |
| 198 EXPECT_EQ(PositionInFlatTree(four, 4), selection_in_flat_tree.end()); | 198 EXPECT_EQ(PositionInFlatTree(four, 4), selection_in_flat_tree.End()); |
| 199 | 199 |
| 200 // From a position at node in shadow tree | 200 // From a position at node in shadow tree |
| 201 selection = CreateVisibleSelection( | 201 selection = CreateVisibleSelection( |
| 202 SelectionInDOMTree::Builder().Collapse(Position(five, 1)).Build()); | 202 SelectionInDOMTree::Builder().Collapse(Position(five, 1)).Build()); |
| 203 selection = ExpandUsingGranularity(selection, kWordGranularity); | 203 selection = ExpandUsingGranularity(selection, kWordGranularity); |
| 204 selection_in_flat_tree = | 204 selection_in_flat_tree = |
| 205 CreateVisibleSelection(SelectionInFlatTree::Builder() | 205 CreateVisibleSelection(SelectionInFlatTree::Builder() |
| 206 .Collapse(PositionInFlatTree(five, 1)) | 206 .Collapse(PositionInFlatTree(five, 1)) |
| 207 .Build()); | 207 .Build()); |
| 208 selection_in_flat_tree = | 208 selection_in_flat_tree = |
| 209 ExpandUsingGranularity(selection_in_flat_tree, kWordGranularity); | 209 ExpandUsingGranularity(selection_in_flat_tree, kWordGranularity); |
| 210 | 210 |
| 211 EXPECT_EQ(Position(five, 1), selection.Base()); | 211 EXPECT_EQ(Position(five, 1), selection.Base()); |
| 212 EXPECT_EQ(Position(five, 1), selection.Extent()); | 212 EXPECT_EQ(Position(five, 1), selection.Extent()); |
| 213 EXPECT_EQ(Position(five, 0), selection.Start()); | 213 EXPECT_EQ(Position(five, 0), selection.Start()); |
| 214 EXPECT_EQ(Position(five, 5), selection.end()); | 214 EXPECT_EQ(Position(five, 5), selection.End()); |
| 215 | 215 |
| 216 EXPECT_EQ(PositionInFlatTree(five, 1), selection_in_flat_tree.Base()); | 216 EXPECT_EQ(PositionInFlatTree(five, 1), selection_in_flat_tree.Base()); |
| 217 EXPECT_EQ(PositionInFlatTree(five, 1), selection_in_flat_tree.Extent()); | 217 EXPECT_EQ(PositionInFlatTree(five, 1), selection_in_flat_tree.Extent()); |
| 218 EXPECT_EQ(PositionInFlatTree(one, 0), selection_in_flat_tree.Start()); | 218 EXPECT_EQ(PositionInFlatTree(one, 0), selection_in_flat_tree.Start()); |
| 219 EXPECT_EQ(PositionInFlatTree(five, 5), selection_in_flat_tree.end()); | 219 EXPECT_EQ(PositionInFlatTree(five, 5), selection_in_flat_tree.End()); |
| 220 } | 220 } |
| 221 | 221 |
| 222 TEST_F(VisibleSelectionTest, Initialisation) { | 222 TEST_F(VisibleSelectionTest, Initialisation) { |
| 223 SetBodyContent(LOREM_IPSUM); | 223 SetBodyContent(LOREM_IPSUM); |
| 224 | 224 |
| 225 VisibleSelection selection; | 225 VisibleSelection selection; |
| 226 VisibleSelectionInFlatTree selection_in_flat_tree; | 226 VisibleSelectionInFlatTree selection_in_flat_tree; |
| 227 SetSelection(selection, 0); | 227 SetSelection(selection, 0); |
| 228 SetSelection(selection_in_flat_tree, 0); | 228 SetSelection(selection_in_flat_tree, 0); |
| 229 | 229 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 .Extend(Position::LastPositionInNode(shadow_root)) | 296 .Extend(Position::LastPositionInNode(shadow_root)) |
| 297 .Build()); | 297 .Build()); |
| 298 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection( | 298 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection( |
| 299 SelectionInFlatTree::Builder() | 299 SelectionInFlatTree::Builder() |
| 300 .Collapse(PositionInFlatTree::FirstPositionInNode(one)) | 300 .Collapse(PositionInFlatTree::FirstPositionInNode(one)) |
| 301 .Extend(PositionInFlatTree::LastPositionInNode(host)) | 301 .Extend(PositionInFlatTree::LastPositionInNode(host)) |
| 302 .Build()); | 302 .Build()); |
| 303 | 303 |
| 304 EXPECT_EQ(Position(host, PositionAnchorType::kBeforeAnchor), | 304 EXPECT_EQ(Position(host, PositionAnchorType::kBeforeAnchor), |
| 305 selection.Start()); | 305 selection.Start()); |
| 306 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); | 306 EXPECT_EQ(Position(one->firstChild(), 0), selection.End()); |
| 307 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0), | 307 EXPECT_EQ(PositionInFlatTree(one->firstChild(), 0), |
| 308 selection_in_flat_tree.Start()); | 308 selection_in_flat_tree.Start()); |
| 309 EXPECT_EQ(PositionInFlatTree(six->firstChild(), 2), | 309 EXPECT_EQ(PositionInFlatTree(six->firstChild(), 2), |
| 310 selection_in_flat_tree.end()); | 310 selection_in_flat_tree.End()); |
| 311 } | 311 } |
| 312 | 312 |
| 313 TEST_F(VisibleSelectionTest, ShadowV0DistributedNodes) { | 313 TEST_F(VisibleSelectionTest, ShadowV0DistributedNodes) { |
| 314 const char* body_content = | 314 const char* body_content = |
| 315 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; | 315 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; |
| 316 const char* shadow_content = | 316 const char* shadow_content = |
| 317 "<a><span id='s4'>44</span><content select=#two></content><span " | 317 "<a><span id='s4'>44</span><content select=#two></content><span " |
| 318 "id='s5'>55</span><content select=#one></content><span " | 318 "id='s5'>55</span><content select=#one></content><span " |
| 319 "id='s6'>66</span></a>"; | 319 "id='s6'>66</span></a>"; |
| 320 SetBodyContent(body_content); | 320 SetBodyContent(body_content); |
| 321 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host"); | 321 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host"); |
| 322 | 322 |
| 323 Element* body = GetDocument().body(); | 323 Element* body = GetDocument().body(); |
| 324 Element* one = body->QuerySelector("#one"); | 324 Element* one = body->QuerySelector("#one"); |
| 325 Element* two = body->QuerySelector("#two"); | 325 Element* two = body->QuerySelector("#two"); |
| 326 Element* five = shadow_root->QuerySelector("#s5"); | 326 Element* five = shadow_root->QuerySelector("#s5"); |
| 327 | 327 |
| 328 VisibleSelection selection = | 328 VisibleSelection selection = |
| 329 CreateVisibleSelection(SelectionInDOMTree::Builder() | 329 CreateVisibleSelection(SelectionInDOMTree::Builder() |
| 330 .Collapse(Position::FirstPositionInNode(one)) | 330 .Collapse(Position::FirstPositionInNode(one)) |
| 331 .Extend(Position::LastPositionInNode(two)) | 331 .Extend(Position::LastPositionInNode(two)) |
| 332 .Build()); | 332 .Build()); |
| 333 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection( | 333 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection( |
| 334 SelectionInFlatTree::Builder() | 334 SelectionInFlatTree::Builder() |
| 335 .Collapse(PositionInFlatTree::FirstPositionInNode(one)) | 335 .Collapse(PositionInFlatTree::FirstPositionInNode(one)) |
| 336 .Extend(PositionInFlatTree::LastPositionInNode(two)) | 336 .Extend(PositionInFlatTree::LastPositionInNode(two)) |
| 337 .Build()); | 337 .Build()); |
| 338 | 338 |
| 339 EXPECT_EQ(Position(one->firstChild(), 0), selection.Start()); | 339 EXPECT_EQ(Position(one->firstChild(), 0), selection.Start()); |
| 340 EXPECT_EQ(Position(two->firstChild(), 2), selection.end()); | 340 EXPECT_EQ(Position(two->firstChild(), 2), selection.End()); |
| 341 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0), | 341 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 0), |
| 342 selection_in_flat_tree.Start()); | 342 selection_in_flat_tree.Start()); |
| 343 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2), | 343 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 2), |
| 344 selection_in_flat_tree.end()); | 344 selection_in_flat_tree.End()); |
| 345 } | 345 } |
| 346 | 346 |
| 347 TEST_F(VisibleSelectionTest, ShadowNested) { | 347 TEST_F(VisibleSelectionTest, ShadowNested) { |
| 348 const char* body_content = | 348 const char* body_content = |
| 349 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; | 349 "<p id='host'>00<b id='one'>11</b><b id='two'>22</b>33</p>"; |
| 350 const char* shadow_content = | 350 const char* shadow_content = |
| 351 "<a><span id='s4'>44</span><content select=#two></content><span " | 351 "<a><span id='s4'>44</span><content select=#two></content><span " |
| 352 "id='s5'>55</span><content select=#one></content><span " | 352 "id='s5'>55</span><content select=#one></content><span " |
| 353 "id='s6'>66</span></a>"; | 353 "id='s6'>66</span></a>"; |
| 354 const char* shadow_content2 = | 354 const char* shadow_content2 = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 377 .Extend(Position::LastPositionInNode(shadow_root2)) | 377 .Extend(Position::LastPositionInNode(shadow_root2)) |
| 378 .Build()); | 378 .Build()); |
| 379 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection( | 379 VisibleSelectionInFlatTree selection_in_flat_tree = CreateVisibleSelection( |
| 380 SelectionInFlatTree::Builder() | 380 SelectionInFlatTree::Builder() |
| 381 .Collapse(PositionInFlatTree::FirstPositionInNode(one)) | 381 .Collapse(PositionInFlatTree::FirstPositionInNode(one)) |
| 382 .Extend(PositionInFlatTree::AfterNode(eight)) | 382 .Extend(PositionInFlatTree::AfterNode(eight)) |
| 383 .Build()); | 383 .Build()); |
| 384 | 384 |
| 385 EXPECT_EQ(Position(host, PositionAnchorType::kBeforeAnchor), | 385 EXPECT_EQ(Position(host, PositionAnchorType::kBeforeAnchor), |
| 386 selection.Start()); | 386 selection.Start()); |
| 387 EXPECT_EQ(Position(one->firstChild(), 0), selection.end()); | 387 EXPECT_EQ(Position(one->firstChild(), 0), selection.End()); |
| 388 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), | 388 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), |
| 389 selection_in_flat_tree.Start()); | 389 selection_in_flat_tree.Start()); |
| 390 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), | 390 EXPECT_EQ(PositionInFlatTree(eight->firstChild(), 2), |
| 391 selection_in_flat_tree.end()); | 391 selection_in_flat_tree.End()); |
| 392 } | 392 } |
| 393 | 393 |
| 394 TEST_F(VisibleSelectionTest, WordGranularity) { | 394 TEST_F(VisibleSelectionTest, WordGranularity) { |
| 395 SetBodyContent(LOREM_IPSUM); | 395 SetBodyContent(LOREM_IPSUM); |
| 396 | 396 |
| 397 VisibleSelection selection; | 397 VisibleSelection selection; |
| 398 VisibleSelectionInFlatTree selection_in_flat_tree; | 398 VisibleSelectionInFlatTree selection_in_flat_tree; |
| 399 | 399 |
| 400 // Beginning of a word. | 400 // Beginning of a word. |
| 401 { | 401 { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 Element* host = GetDocument().getElementById("host"); | 532 Element* host = GetDocument().getElementById("host"); |
| 533 host->AppendChild(sample); | 533 host->AppendChild(sample); |
| 534 GetDocument().UpdateStyleAndLayout(); | 534 GetDocument().UpdateStyleAndLayout(); |
| 535 | 535 |
| 536 // Simulates to restore selection from undo stack. | 536 // Simulates to restore selection from undo stack. |
| 537 selection = CreateVisibleSelection(selection.AsSelection()); | 537 selection = CreateVisibleSelection(selection.AsSelection()); |
| 538 EXPECT_EQ(Position(sample->firstChild(), 0), selection.Start()); | 538 EXPECT_EQ(Position(sample->firstChild(), 0), selection.Start()); |
| 539 } | 539 } |
| 540 | 540 |
| 541 } // namespace blink | 541 } // namespace blink |
| OLD | NEW |