Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: third_party/WebKit/Source/core/editing/PositionTest.cpp

Issue 2875253002: Introduce Position::IsEquivalent() (Closed)
Patch Set: 2017-05-12T17:24:00 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/Position.h" 5 #include "core/editing/Position.h"
6 6
7 #include "core/editing/EditingTestBase.h" 7 #include "core/editing/EditingTestBase.h"
8 8
9 namespace blink { 9 namespace blink {
10 10
11 class PositionTest : public EditingTestBase {}; 11 class PositionTest : public EditingTestBase {};
12 12
13 TEST_F(PositionTest, IsEquivalent) {
14 SetBodyContent("<a id=sample>0<b>1</b>2</b>");
hugoh_UTC2 2017/05/12 14:12:14 <b>2</b> ? Missing </a> ?
yosin_UTC9 2017/05/15 04:08:15 Good catch. It should be "</a>"
15
16 Element* sample = GetDocument().getElementById("sample");
17
18 EXPECT_TRUE(Position(sample, 0).IsEquivalent(Position(sample, 0)));
19
20 EXPECT_TRUE(
21 Position(sample, 0).IsEquivalent(Position::FirstPositionInNode(sample)));
22 EXPECT_TRUE(Position(sample, 0).IsEquivalent(
23 Position::BeforeNode(sample->firstChild())));
24 EXPECT_TRUE(Position(sample, 1).IsEquivalent(
25 Position::AfterNode(sample->firstChild())));
26 EXPECT_TRUE(Position(sample, 1).IsEquivalent(
27 Position::BeforeNode(sample->firstChild()->nextSibling())));
28 EXPECT_TRUE(Position(sample, 2).IsEquivalent(
29 Position::BeforeNode(sample->lastChild())));
30 EXPECT_TRUE(Position(sample, 3).IsEquivalent(
31 Position::AfterNode(sample->lastChild())));
32 EXPECT_TRUE(
33 Position(sample, 3).IsEquivalent(Position::LastPositionInNode(sample)));
34
35 EXPECT_FALSE(Position(sample, 0).IsEquivalent(Position(sample, 1)));
36 EXPECT_FALSE(
37 Position(sample, 0).IsEquivalent(Position::LastPositionInNode(sample)));
38 }
39
13 TEST_F(PositionTest, NodeAsRangeLastNodeNull) { 40 TEST_F(PositionTest, NodeAsRangeLastNodeNull) {
14 EXPECT_EQ(nullptr, Position().NodeAsRangeLastNode()); 41 EXPECT_EQ(nullptr, Position().NodeAsRangeLastNode());
15 EXPECT_EQ(nullptr, PositionInFlatTree().NodeAsRangeLastNode()); 42 EXPECT_EQ(nullptr, PositionInFlatTree().NodeAsRangeLastNode());
16 } 43 }
17 44
18 TEST_F(PositionTest, editingPositionOfWithEditingIgnoresContent) { 45 TEST_F(PositionTest, editingPositionOfWithEditingIgnoresContent) {
19 const char* body_content = 46 const char* body_content =
20 "<textarea id=textarea></textarea><a id=child1>1</a><b id=child2>2</b>"; 47 "<textarea id=textarea></textarea><a id=child1>1</a><b id=child2>2</b>";
21 SetBodyContent(body_content); 48 SetBodyContent(body_content);
22 Node* textarea = GetDocument().getElementById("textarea"); 49 Node* textarea = GetDocument().getElementById("textarea");
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 const char* shadow_content = ""; 222 const char* shadow_content = "";
196 SetBodyContent(body_content); 223 SetBodyContent(body_content);
197 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host"); 224 ShadowRoot* shadow_root = SetShadowContent(shadow_content, "host");
198 Element* host = GetDocument().getElementById("host"); 225 Element* host = GetDocument().getElementById("host");
199 226
200 EXPECT_EQ(PositionInFlatTree(host, PositionAnchorType::kAfterChildren), 227 EXPECT_EQ(PositionInFlatTree(host, PositionAnchorType::kAfterChildren),
201 ToPositionInFlatTree(Position(shadow_root, 0))); 228 ToPositionInFlatTree(Position(shadow_root, 0)));
202 } 229 }
203 230
204 } // namespace blink 231 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698