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

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

Issue 2805553003: DocumentMarkerList refactor as an interface (Closed)
Patch Set: Rebase on renaming patch, respond to comments Created 3 years, 8 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
(Empty)
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/editing/commands/SplitTextNodeCommand.h"
6
7 #include "core/editing/EditingTestBase.h"
8 #include "core/editing/PlainTextRange.h"
9 #include "core/editing/commands/EditingState.h"
10 #include "core/editing/markers/DocumentMarkerController.h"
11
12 namespace blink {
13
14 class SplitTextNodeCommandTest : public EditingTestBase {};
15
16 TEST_F(SplitTextNodeCommandTest, splitInMarkerInterior) {
17 SetBodyContent("<div contenteditable>test1 test2 test3</div>");
18
19 ContainerNode* div = ToContainerNode(GetDocument().body()->firstChild());
20
21 EphemeralRange range = PlainTextRange(0, 5).CreateRange(*div);
22 GetDocument().Markers().AddTextMatchMarker(
23 range, DocumentMarker::MatchStatus::kInactive);
24
25 range = PlainTextRange(6, 11).CreateRange(*div);
26 GetDocument().Markers().AddTextMatchMarker(
27 range, DocumentMarker::MatchStatus::kInactive);
28
29 range = PlainTextRange(12, 17).CreateRange(*div);
30 GetDocument().Markers().AddTextMatchMarker(
31 range, DocumentMarker::MatchStatus::kInactive);
32
33 SimpleEditCommand* command = SplitTextNodeCommand::Create(
34 ToText(GetDocument().body()->firstChild()->firstChild()), 8);
35
36 EditingState editingState;
37 command->DoApply(&editingState);
38
39 Node* text1 = ToText(div->firstChild());
40 Node* text2 = ToText(text1->nextSibling());
41
42 // The first marker should end up in text1, the second marker should be
43 // truncated and end up text1, the third marker should end up in text2
44 // and its offset shifted to remain on the same piece of text
45
46 EXPECT_EQ(2u, GetDocument().Markers().MarkersFor(text1).size());
47
48 EXPECT_EQ(0u, GetDocument().Markers().MarkersFor(text1)[0]->StartOffset());
49 EXPECT_EQ(5u, GetDocument().Markers().MarkersFor(text1)[0]->EndOffset());
50
51 EXPECT_EQ(6u, GetDocument().Markers().MarkersFor(text1)[1]->StartOffset());
52 EXPECT_EQ(7u, GetDocument().Markers().MarkersFor(text1)[1]->EndOffset());
53
54 EXPECT_EQ(1u, GetDocument().Markers().MarkersFor(text2).size());
55
56 EXPECT_EQ(4u, GetDocument().Markers().MarkersFor(text2)[0]->StartOffset());
57 EXPECT_EQ(9u, GetDocument().Markers().MarkersFor(text2)[0]->EndOffset());
58
59 // Test undo
60 command->DoUnapply();
61
62 Node* text = ToText(div->firstChild());
63
64 EXPECT_EQ(3u, GetDocument().Markers().MarkersFor(text).size());
65
66 EXPECT_EQ(0u, GetDocument().Markers().MarkersFor(text)[0]->StartOffset());
67 EXPECT_EQ(5u, GetDocument().Markers().MarkersFor(text)[0]->EndOffset());
68
69 // TODO(rlanday): the truncated marker that spanned node boundaries is not
70 // restored properly
71 EXPECT_EQ(6u, GetDocument().Markers().MarkersFor(text)[1]->StartOffset());
72 EXPECT_EQ(7u, GetDocument().Markers().MarkersFor(text)[1]->EndOffset());
73
74 EXPECT_EQ(12u, GetDocument().Markers().MarkersFor(text)[2]->StartOffset());
75 EXPECT_EQ(17u, GetDocument().Markers().MarkersFor(text)[2]->EndOffset());
76
77 // Test redo
78 command->DoReapply();
79
80 text1 = ToText(div->firstChild());
81 text2 = ToText(text1->nextSibling());
82
83 EXPECT_EQ(2u, GetDocument().Markers().MarkersFor(text1).size());
84
85 EXPECT_EQ(0u, GetDocument().Markers().MarkersFor(text1)[0]->StartOffset());
86 EXPECT_EQ(5u, GetDocument().Markers().MarkersFor(text1)[0]->EndOffset());
87
88 EXPECT_EQ(6u, GetDocument().Markers().MarkersFor(text1)[1]->StartOffset());
89 EXPECT_EQ(7u, GetDocument().Markers().MarkersFor(text1)[1]->EndOffset());
90
91 EXPECT_EQ(1u, GetDocument().Markers().MarkersFor(text2).size());
92
93 EXPECT_EQ(4u, GetDocument().Markers().MarkersFor(text2)[0]->StartOffset());
94 EXPECT_EQ(9u, GetDocument().Markers().MarkersFor(text2)[0]->EndOffset());
95 }
96
97 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698