| 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 | 10 |
| 10 #define LOREM_IPSUM \ | 11 #define LOREM_IPSUM \ |
| 11 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod te
mpor " \ | 12 "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod te
mpor " \ |
| 12 "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud " \ | 13 "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud " \ |
| 13 "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure " \ | 14 "exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
aute irure " \ |
| 14 "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat null
a pariatur." \ | 15 "dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat null
a pariatur." \ |
| 15 "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia d
eserunt " \ | 16 "Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia d
eserunt " \ |
| 16 "mollit anim id est laborum." | 17 "mollit anim id est laborum." |
| 17 | 18 |
| 18 namespace blink { | 19 namespace blink { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 selectionInFlatTree.expandUsingGranularity(WordGranularity); | 344 selectionInFlatTree.expandUsingGranularity(WordGranularity); |
| 344 | 345 |
| 345 Range* range = firstRangeOf(selection); | 346 Range* range = firstRangeOf(selection); |
| 346 EXPECT_EQ(0, range->startOffset()); | 347 EXPECT_EQ(0, range->startOffset()); |
| 347 EXPECT_EQ(11, range->endOffset()); | 348 EXPECT_EQ(11, range->endOffset()); |
| 348 EXPECT_EQ("Lorem ipsum", range->text()); | 349 EXPECT_EQ("Lorem ipsum", range->text()); |
| 349 testFlatTreePositionsToEqualToDOMTreePositions(selection, selectionInFla
tTree); | 350 testFlatTreePositionsToEqualToDOMTreePositions(selection, selectionInFla
tTree); |
| 350 } | 351 } |
| 351 } | 352 } |
| 352 | 353 |
| 354 // This is for crbug.com/627783, simulating restoring selection |
| 355 // in undo stack. |
| 356 TEST_F(VisibleSelectionTest, validatePositionsIfNeededWithShadowHost) |
| 357 { |
| 358 setBodyContent("<div id=host></div><div id=sample>foo</div>"); |
| 359 setShadowContent("<content>", "host"); |
| 360 Element* sample = document().getElementById("sample"); |
| 361 |
| 362 // Simulates saving selection in undo stack. |
| 363 VisibleSelection selection(Position(sample->firstChild(), 0)); |
| 364 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); |
| 365 |
| 366 // Simulates modifying DOM tree to invalidate distribution. |
| 367 Element* host = document().getElementById("host"); |
| 368 host->appendChild(sample); |
| 369 |
| 370 // Simulates to restore selection from undo stack. |
| 371 selection.validatePositionsIfNeeded(); |
| 372 EXPECT_EQ(Position(sample->firstChild(), 0), selection.start()); |
| 373 |
| 374 VisibleSelectionInFlatTree selectionInFlatTree; |
| 375 SelectionAdjuster::adjustSelectionInFlatTree(&selectionInFlatTree, selection
); |
| 376 EXPECT_EQ(PositionInFlatTree(sample->firstChild(), 0), selectionInFlatTree.s
tart()); |
| 377 } |
| 378 |
| 353 } // namespace blink | 379 } // namespace blink |
| OLD | NEW |