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

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

Issue 2802993007: Add SplitTextNodeCommandTest (Closed)
Patch Set: 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/SplitTextNodeCommand.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(document().body()->firstChild());
20
21 EphemeralRange range = PlainTextRange(0, 5).createRange(*div);
22 document().markers().addTextMatchMarker(
23 range, DocumentMarker::MatchStatus::kInactive);
24
25 range = PlainTextRange(6, 11).createRange(*div);
26 document().markers().addTextMatchMarker(
27 range, DocumentMarker::MatchStatus::kInactive);
28
29 range = PlainTextRange(12, 17).createRange(*div);
30 document().markers().addTextMatchMarker(
31 range, DocumentMarker::MatchStatus::kInactive);
32
33 SimpleEditCommand* command = SplitTextNodeCommand::create(
34 toText(document().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, document().markers().markersFor(text1).size());
47
48 EXPECT_EQ(0u, document().markers().markersFor(text1)[0]->startOffset());
49 EXPECT_EQ(5u, document().markers().markersFor(text1)[0]->endOffset());
50
51 EXPECT_EQ(6u, document().markers().markersFor(text1)[1]->startOffset());
52 EXPECT_EQ(7u, document().markers().markersFor(text1)[1]->endOffset());
53
54 EXPECT_EQ(1u, document().markers().markersFor(text2).size());
55
56 EXPECT_EQ(4u, document().markers().markersFor(text2)[0]->startOffset());
57 EXPECT_EQ(9u, document().markers().markersFor(text2)[0]->endOffset());
58
59 // Test undo
60 command->doUnapply();
61
62 Node* text = toText(div->firstChild());
63
64 EXPECT_EQ(3u, document().markers().markersFor(text).size());
65
66 EXPECT_EQ(0u, document().markers().markersFor(text)[0]->startOffset());
67 EXPECT_EQ(5u, document().markers().markersFor(text)[0]->endOffset());
68
69 // TODO(rlanday): the truncated marker that spanned node boundaries is not
Xiaocheng 2017/04/08 02:38:19 Do you really plan to fix it? I don't see a clean
70 // restored properly
71 EXPECT_EQ(6u, document().markers().markersFor(text)[1]->startOffset());
72 EXPECT_EQ(7u, document().markers().markersFor(text)[1]->endOffset());
73
74 EXPECT_EQ(12u, document().markers().markersFor(text)[2]->startOffset());
75 EXPECT_EQ(17u, document().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, document().markers().markersFor(text1).size());
84
85 EXPECT_EQ(0u, document().markers().markersFor(text1)[0]->startOffset());
86 EXPECT_EQ(5u, document().markers().markersFor(text1)[0]->endOffset());
87
88 EXPECT_EQ(6u, document().markers().markersFor(text1)[1]->startOffset());
89 EXPECT_EQ(7u, document().markers().markersFor(text1)[1]->endOffset());
90
91 EXPECT_EQ(1u, document().markers().markersFor(text2).size());
92
93 EXPECT_EQ(4u, document().markers().markersFor(text2)[0]->startOffset());
94 EXPECT_EQ(9u, document().markers().markersFor(text2)[0]->endOffset());
95 }
96
97 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/SplitTextNodeCommand.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698