| 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 "core/editing/VisibleUnits.h" | 5 #include "core/editing/VisibleUnits.h" |
| 6 | 6 |
| 7 #include <ostream> // NOLINT | 7 #include <ostream> // NOLINT |
| 8 #include "bindings/core/v8/V8BindingForTesting.h" | 8 #include "bindings/core/v8/V8BindingForTesting.h" |
| 9 #include "core/dom/Text.h" | 9 #include "core/dom/Text.h" |
| 10 #include "core/editing/EditingTestBase.h" | 10 #include "core/editing/EditingTestBase.h" |
| (...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1033 EXPECT_FALSE(IsVisuallyEquivalentCandidate(Position(two, 0))); | 1033 EXPECT_FALSE(IsVisuallyEquivalentCandidate(Position(two, 0))); |
| 1034 EXPECT_FALSE(IsVisuallyEquivalentCandidate(Position(two, 1))); | 1034 EXPECT_FALSE(IsVisuallyEquivalentCandidate(Position(two, 1))); |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 TEST_F(VisibleUnitsTest, isVisuallyEquivalentCandidateWithDocument) { | 1037 TEST_F(VisibleUnitsTest, isVisuallyEquivalentCandidateWithDocument) { |
| 1038 UpdateAllLifecyclePhases(); | 1038 UpdateAllLifecyclePhases(); |
| 1039 | 1039 |
| 1040 EXPECT_FALSE(IsVisuallyEquivalentCandidate(Position(&GetDocument(), 0))); | 1040 EXPECT_FALSE(IsVisuallyEquivalentCandidate(Position(&GetDocument(), 0))); |
| 1041 } | 1041 } |
| 1042 | 1042 |
| 1043 TEST_F(VisibleUnitsTest, leftPositionOf) { | |
| 1044 const char* body_content = | |
| 1045 "<b id=zero>0</b><p id=host><b id=one>1</b><b id=two>22</b></p><b " | |
| 1046 "id=three>333</b>"; | |
| 1047 const char* shadow_content = | |
| 1048 "<b id=four>4444</b><content select=#two></content><content " | |
| 1049 "select=#one></content><b id=five>55555</b>"; | |
| 1050 SetBodyContent(body_content); | |
| 1051 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host"); | |
| 1052 | |
| 1053 Element* one = GetDocument().getElementById("one"); | |
| 1054 Element* two = GetDocument().getElementById("two"); | |
| 1055 Element* three = GetDocument().getElementById("three"); | |
| 1056 Element* four = shadow_root->getElementById("four"); | |
| 1057 Element* five = shadow_root->getElementById("five"); | |
| 1058 | |
| 1059 EXPECT_EQ( | |
| 1060 Position(two->firstChild(), 1), | |
| 1061 LeftPositionOf(CreateVisiblePosition(Position(one, 0))).DeepEquivalent()); | |
| 1062 EXPECT_EQ(PositionInFlatTree(two->firstChild(), 1), | |
| 1063 LeftPositionOf(CreateVisiblePosition(PositionInFlatTree(one, 0))) | |
| 1064 .DeepEquivalent()); | |
| 1065 | |
| 1066 EXPECT_EQ( | |
| 1067 Position(one->firstChild(), 0), | |
| 1068 LeftPositionOf(CreateVisiblePosition(Position(two, 0))).DeepEquivalent()); | |
| 1069 EXPECT_EQ(PositionInFlatTree(four->firstChild(), 3), | |
| 1070 LeftPositionOf(CreateVisiblePosition(PositionInFlatTree(two, 0))) | |
| 1071 .DeepEquivalent()); | |
| 1072 | |
| 1073 EXPECT_EQ(Position(two->firstChild(), 2), | |
| 1074 LeftPositionOf(CreateVisiblePosition(Position(three, 0))) | |
| 1075 .DeepEquivalent()); | |
| 1076 EXPECT_EQ(PositionInFlatTree(five->firstChild(), 5), | |
| 1077 LeftPositionOf(CreateVisiblePosition(PositionInFlatTree(three, 0))) | |
| 1078 .DeepEquivalent()); | |
| 1079 } | |
| 1080 | |
| 1081 TEST_F(VisibleUnitsTest, localCaretRectOfPosition) { | 1043 TEST_F(VisibleUnitsTest, localCaretRectOfPosition) { |
| 1082 const char* body_content = | 1044 const char* body_content = |
| 1083 "<p id='host'><b id='one'>1</b></p><b id='two'>22</b>"; | 1045 "<p id='host'><b id='one'>1</b></p><b id='two'>22</b>"; |
| 1084 const char* shadow_content = | 1046 const char* shadow_content = |
| 1085 "<b id='two'>22</b><content select=#one></content><b id='three'>333</b>"; | 1047 "<b id='two'>22</b><content select=#one></content><b id='three'>333</b>"; |
| 1086 SetBodyContent(body_content); | 1048 SetBodyContent(body_content); |
| 1087 SetShadowContent(shadow_content, "host"); | 1049 SetShadowContent(shadow_content, "host"); |
| 1088 | 1050 |
| 1089 Element* one = GetDocument().getElementById("one"); | 1051 Element* one = GetDocument().getElementById("one"); |
| 1090 | 1052 |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1608 Element* sample2 = GetDocument().getElementById("sample2"); | 1570 Element* sample2 = GetDocument().getElementById("sample2"); |
| 1609 | 1571 |
| 1610 EXPECT_FALSE( | 1572 EXPECT_FALSE( |
| 1611 RendersInDifferentPosition(Position::AfterNode(sample1->firstChild()), | 1573 RendersInDifferentPosition(Position::AfterNode(sample1->firstChild()), |
| 1612 Position(sample2->firstChild(), 0))); | 1574 Position(sample2->firstChild(), 0))); |
| 1613 EXPECT_FALSE(RendersInDifferentPosition( | 1575 EXPECT_FALSE(RendersInDifferentPosition( |
| 1614 Position::LastPositionInNode(sample1->firstChild()), | 1576 Position::LastPositionInNode(sample1->firstChild()), |
| 1615 Position(sample2->firstChild(), 0))); | 1577 Position(sample2->firstChild(), 0))); |
| 1616 } | 1578 } |
| 1617 | 1579 |
| 1618 TEST_F(VisibleUnitsTest, rightPositionOf) { | |
| 1619 const char* body_content = | |
| 1620 "<b id=zero>0</b><p id=host><b id=one>1</b><b id=two>22</b></p><b " | |
| 1621 "id=three>333</b>"; | |
| 1622 const char* shadow_content = | |
| 1623 "<p id=four>4444</p><content select=#two></content><content " | |
| 1624 "select=#one></content><p id=five>55555</p>"; | |
| 1625 SetBodyContent(body_content); | |
| 1626 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host"); | |
| 1627 | |
| 1628 Node* one = GetDocument().getElementById("one")->firstChild(); | |
| 1629 Node* two = GetDocument().getElementById("two")->firstChild(); | |
| 1630 Node* three = GetDocument().getElementById("three")->firstChild(); | |
| 1631 Node* four = shadow_root->getElementById("four")->firstChild(); | |
| 1632 Node* five = shadow_root->getElementById("five")->firstChild(); | |
| 1633 | |
| 1634 EXPECT_EQ(Position(), RightPositionOf(CreateVisiblePosition(Position(one, 1))) | |
| 1635 .DeepEquivalent()); | |
| 1636 EXPECT_EQ(PositionInFlatTree(five, 0), | |
| 1637 RightPositionOf(CreateVisiblePosition(PositionInFlatTree(one, 1))) | |
| 1638 .DeepEquivalent()); | |
| 1639 | |
| 1640 EXPECT_EQ(Position(one, 1), | |
| 1641 RightPositionOf(CreateVisiblePosition(Position(two, 2))) | |
| 1642 .DeepEquivalent()); | |
| 1643 EXPECT_EQ(PositionInFlatTree(one, 1), | |
| 1644 RightPositionOf(CreateVisiblePosition(PositionInFlatTree(two, 2))) | |
| 1645 .DeepEquivalent()); | |
| 1646 | |
| 1647 EXPECT_EQ(Position(five, 0), | |
| 1648 RightPositionOf(CreateVisiblePosition(Position(four, 4))) | |
| 1649 .DeepEquivalent()); | |
| 1650 EXPECT_EQ(PositionInFlatTree(two, 0), | |
| 1651 RightPositionOf(CreateVisiblePosition(PositionInFlatTree(four, 4))) | |
| 1652 .DeepEquivalent()); | |
| 1653 | |
| 1654 EXPECT_EQ(Position(), | |
| 1655 RightPositionOf(CreateVisiblePosition(Position(five, 5))) | |
| 1656 .DeepEquivalent()); | |
| 1657 EXPECT_EQ(PositionInFlatTree(three, 0), | |
| 1658 RightPositionOf(CreateVisiblePosition(PositionInFlatTree(five, 5))) | |
| 1659 .DeepEquivalent()); | |
| 1660 } | |
| 1661 | |
| 1662 TEST_F(VisibleUnitsTest, startOfDocument) { | 1580 TEST_F(VisibleUnitsTest, startOfDocument) { |
| 1663 const char* body_content = "<a id=host><b id=one>1</b><b id=two>22</b></a>"; | 1581 const char* body_content = "<a id=host><b id=one>1</b><b id=two>22</b></a>"; |
| 1664 const char* shadow_content = | 1582 const char* shadow_content = |
| 1665 "<p><content select=#two></content></p><p><content " | 1583 "<p><content select=#two></content></p><p><content " |
| 1666 "select=#one></content></p>"; | 1584 "select=#one></content></p>"; |
| 1667 SetBodyContent(body_content); | 1585 SetBodyContent(body_content); |
| 1668 SetShadowContent(shadow_content, "host"); | 1586 SetShadowContent(shadow_content, "host"); |
| 1669 | 1587 |
| 1670 Node* one = GetDocument().getElementById("one")->firstChild(); | 1588 Node* one = GetDocument().getElementById("one")->firstChild(); |
| 1671 Node* two = GetDocument().getElementById("two")->firstChild(); | 1589 Node* two = GetDocument().getElementById("two")->firstChild(); |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1989 canonicalizationWithCollapsedSpaceAndIsolatedCombiningCharacter) { | 1907 canonicalizationWithCollapsedSpaceAndIsolatedCombiningCharacter) { |
| 1990 SetBodyContent("<p> ⃣</p>"); // Leading space is necessary | 1908 SetBodyContent("<p> ⃣</p>"); // Leading space is necessary |
| 1991 | 1909 |
| 1992 Node* paragraph = GetDocument().QuerySelector("p"); | 1910 Node* paragraph = GetDocument().QuerySelector("p"); |
| 1993 Node* text = paragraph->firstChild(); | 1911 Node* text = paragraph->firstChild(); |
| 1994 Position start = CanonicalPositionOf(Position::BeforeNode(paragraph)); | 1912 Position start = CanonicalPositionOf(Position::BeforeNode(paragraph)); |
| 1995 EXPECT_EQ(Position(text, 2), start); | 1913 EXPECT_EQ(Position(text, 2), start); |
| 1996 } | 1914 } |
| 1997 | 1915 |
| 1998 } // namespace blink | 1916 } // namespace blink |
| OLD | NEW |