| 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/EditingUtilities.h" | 5 #include "core/editing/EditingUtilities.h" |
| 6 | 6 |
| 7 #include "core/dom/StaticNodeList.h" | 7 #include "core/dom/StaticNodeList.h" |
| 8 #include "core/editing/EditingTestBase.h" | 8 #include "core/editing/EditingTestBase.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 const char* shadowContent = | 75 const char* shadowContent = |
| 76 "<content select=#two></content><div id='three'><content " | 76 "<content select=#two></content><div id='three'><content " |
| 77 "select=#one></content></div>"; | 77 "select=#one></content></div>"; |
| 78 setBodyContent(bodyContent); | 78 setBodyContent(bodyContent); |
| 79 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 79 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| 80 Node* host = document().getElementById("host"); | 80 Node* host = document().getElementById("host"); |
| 81 Node* one = document().getElementById("one"); | 81 Node* one = document().getElementById("one"); |
| 82 Node* three = shadowRoot->getElementById("three"); | 82 Node* three = shadowRoot->getElementById("three"); |
| 83 | 83 |
| 84 EXPECT_EQ(host, enclosingBlock(Position(one, 0), CannotCrossEditingBoundary)); | 84 EXPECT_EQ(host, enclosingBlock(Position(one, 0), CannotCrossEditingBoundary)); |
| 85 EXPECT_EQ(three, enclosingBlock(PositionInFlatTree(one, 0), | 85 EXPECT_EQ( |
| 86 CannotCrossEditingBoundary)); | 86 three, |
| 87 enclosingBlock(PositionInFlatTree(one, 0), CannotCrossEditingBoundary)); |
| 87 } | 88 } |
| 88 | 89 |
| 89 TEST_F(EditingUtilitiesTest, enclosingNodeOfType) { | 90 TEST_F(EditingUtilitiesTest, enclosingNodeOfType) { |
| 90 const char* bodyContent = "<p id='host'><b id='one'>11</b></p>"; | 91 const char* bodyContent = "<p id='host'><b id='one'>11</b></p>"; |
| 91 const char* shadowContent = | 92 const char* shadowContent = |
| 92 "<content select=#two></content><div id='three'><content " | 93 "<content select=#two></content><div id='three'><content " |
| 93 "select=#one></div></content>"; | 94 "select=#one></div></content>"; |
| 94 setBodyContent(bodyContent); | 95 setBodyContent(bodyContent); |
| 95 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 96 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| 96 Node* host = document().getElementById("host"); | 97 Node* host = document().getElementById("host"); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 124 "<div contenteditable id=host><table " | 125 "<div contenteditable id=host><table " |
| 125 "id=table><tr><td>1</td></tr></table><b id=two>22</b></div>"; | 126 "id=table><tr><td>1</td></tr></table><b id=two>22</b></div>"; |
| 126 const char* shadowContent = | 127 const char* shadowContent = |
| 127 "<content select=#two></content><content select=#table></content>"; | 128 "<content select=#two></content><content select=#table></content>"; |
| 128 setBodyContent(bodyContent); | 129 setBodyContent(bodyContent); |
| 129 setShadowContent(shadowContent, "host"); | 130 setShadowContent(shadowContent, "host"); |
| 130 Node* host = document().getElementById("host"); | 131 Node* host = document().getElementById("host"); |
| 131 Node* table = document().getElementById("table"); | 132 Node* table = document().getElementById("table"); |
| 132 | 133 |
| 133 EXPECT_EQ(table, tableElementJustBefore(VisiblePosition::afterNode(table))); | 134 EXPECT_EQ(table, tableElementJustBefore(VisiblePosition::afterNode(table))); |
| 134 EXPECT_EQ(table, tableElementJustBefore( | 135 EXPECT_EQ( |
| 135 VisiblePositionInFlatTree::afterNode(table))); | 136 table, |
| 137 tableElementJustBefore(VisiblePositionInFlatTree::afterNode(table))); |
| 136 | 138 |
| 137 EXPECT_EQ(table, | 139 EXPECT_EQ(table, |
| 138 tableElementJustBefore(VisiblePosition::lastPositionInNode(table))); | 140 tableElementJustBefore(VisiblePosition::lastPositionInNode(table))); |
| 139 EXPECT_EQ(table, tableElementJustBefore(createVisiblePosition( | 141 EXPECT_EQ(table, |
| 140 PositionInFlatTree::lastPositionInNode(table)))); | 142 tableElementJustBefore(createVisiblePosition( |
| 143 PositionInFlatTree::lastPositionInNode(table)))); |
| 141 | 144 |
| 142 EXPECT_EQ(nullptr, | 145 EXPECT_EQ(nullptr, |
| 143 tableElementJustBefore(createVisiblePosition(Position(host, 2)))); | 146 tableElementJustBefore(createVisiblePosition(Position(host, 2)))); |
| 144 EXPECT_EQ(table, tableElementJustBefore( | 147 EXPECT_EQ(table, |
| 145 createVisiblePosition(PositionInFlatTree(host, 2)))); | 148 tableElementJustBefore( |
| 149 createVisiblePosition(PositionInFlatTree(host, 2)))); |
| 146 | 150 |
| 147 EXPECT_EQ(nullptr, tableElementJustBefore(VisiblePosition::afterNode(host))); | 151 EXPECT_EQ(nullptr, tableElementJustBefore(VisiblePosition::afterNode(host))); |
| 148 EXPECT_EQ(nullptr, | 152 EXPECT_EQ(nullptr, |
| 149 tableElementJustBefore(VisiblePositionInFlatTree::afterNode(host))); | 153 tableElementJustBefore(VisiblePositionInFlatTree::afterNode(host))); |
| 150 | 154 |
| 151 EXPECT_EQ(nullptr, | 155 EXPECT_EQ(nullptr, |
| 152 tableElementJustBefore(VisiblePosition::lastPositionInNode(host))); | 156 tableElementJustBefore(VisiblePosition::lastPositionInNode(host))); |
| 153 EXPECT_EQ(table, tableElementJustBefore(createVisiblePosition( | 157 EXPECT_EQ(table, |
| 154 PositionInFlatTree::lastPositionInNode(host)))); | 158 tableElementJustBefore(createVisiblePosition( |
| 159 PositionInFlatTree::lastPositionInNode(host)))); |
| 155 } | 160 } |
| 156 | 161 |
| 157 TEST_F(EditingUtilitiesTest, lastEditablePositionBeforePositionInRoot) { | 162 TEST_F(EditingUtilitiesTest, lastEditablePositionBeforePositionInRoot) { |
| 158 const char* bodyContent = | 163 const char* bodyContent = |
| 159 "<p id='host' contenteditable><b id='one'>1</b><b id='two'>22</b></p>"; | 164 "<p id='host' contenteditable><b id='one'>1</b><b id='two'>22</b></p>"; |
| 160 const char* shadowContent = | 165 const char* shadowContent = |
| 161 "<content select=#two></content><content select=#one></content><b " | 166 "<content select=#two></content><content select=#one></content><b " |
| 162 "id='three'>333</b>"; | 167 "id='three'>333</b>"; |
| 163 setBodyContent(bodyContent); | 168 setBodyContent(bodyContent); |
| 164 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); | 169 ShadowRoot* shadowRoot = setShadowContent(shadowContent, "host"); |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 PositionMoveType::BackwardDeletion)); | 903 PositionMoveType::BackwardDeletion)); |
| 899 EXPECT_EQ(Position(node, 2), | 904 EXPECT_EQ(Position(node, 2), |
| 900 previousPositionOf(Position(node, 3), | 905 previousPositionOf(Position(node, 3), |
| 901 PositionMoveType::BackwardDeletion)); | 906 PositionMoveType::BackwardDeletion)); |
| 902 EXPECT_EQ(Position(node, 0), | 907 EXPECT_EQ(Position(node, 0), |
| 903 previousPositionOf(Position(node, 1), | 908 previousPositionOf(Position(node, 1), |
| 904 PositionMoveType::BackwardDeletion)); | 909 PositionMoveType::BackwardDeletion)); |
| 905 } | 910 } |
| 906 | 911 |
| 907 } // namespace blink | 912 } // namespace blink |
| OLD | NEW |