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

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

Issue 2706033007: Add SetCharacterDataCommand (Closed)
Patch Set: Remove updateStyleAndLayout(), add DCHECK, add more tests Created 3 years, 10 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/SetCharacterDataCommand.cpp ('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 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/SetCharacterDataCommand.h"
6
7 #include "core/editing/EditingTestBase.h"
8 #include "core/editing/commands/EditingState.h"
9
10 namespace blink {
11
12 class SetCharacterDataCommandTest : public EditingTestBase {};
13
14 TEST_F(SetCharacterDataCommandTest, replaceTextWithSameLength) {
15 setBodyContent("<div contenteditable>This is a good test case</div>");
16
17 SimpleEditCommand* command = SetCharacterDataCommand::create(
18 toText(document().body()->firstChild()->firstChild()), 10, 4, "lame");
19
20 command->doReapply();
21 EXPECT_EQ("This is a lame test case",
22 toText(document().body()->firstChild()->firstChild())->wholeText());
23
24 command->doUnapply();
25 EXPECT_EQ("This is a good test case",
26 toText(document().body()->firstChild()->firstChild())->wholeText());
27 }
28
29 TEST_F(SetCharacterDataCommandTest, replaceTextWithLongerText) {
30 setBodyContent("<div contenteditable>This is a good test case</div>");
31
32 SimpleEditCommand* command = SetCharacterDataCommand::create(
33 toText(document().body()->firstChild()->firstChild()), 10, 4, "lousy");
34
35 command->doReapply();
36 EXPECT_EQ("This is a lousy test case",
37 toText(document().body()->firstChild()->firstChild())->wholeText());
38
39 command->doUnapply();
40 EXPECT_EQ("This is a good test case",
41 toText(document().body()->firstChild()->firstChild())->wholeText());
42 }
43
44 TEST_F(SetCharacterDataCommandTest, replaceTextWithShorterText) {
45 setBodyContent("<div contenteditable>This is a good test case</div>");
46
47 SimpleEditCommand* command = SetCharacterDataCommand::create(
48 toText(document().body()->firstChild()->firstChild()), 10, 4, "meh");
49
50 command->doReapply();
51 EXPECT_EQ("This is a meh test case",
52 toText(document().body()->firstChild()->firstChild())->wholeText());
53
54 command->doUnapply();
55 EXPECT_EQ("This is a good test case",
56 toText(document().body()->firstChild()->firstChild())->wholeText());
57 }
58
59 TEST_F(SetCharacterDataCommandTest, insertTextIntoEmptyNode) {
60 setBodyContent("<div contenteditable />");
61
62 document().body()->firstChild()->appendChild(
63 document().createEditingTextNode(""));
64
65 SimpleEditCommand* command = SetCharacterDataCommand::create(
66 toText(document().body()->firstChild()->firstChild()), 0, 0, "hello");
67
68 command->doReapply();
69 EXPECT_EQ("hello",
70 toText(document().body()->firstChild()->firstChild())->wholeText());
71
72 command->doUnapply();
73 EXPECT_EQ("",
74 toText(document().body()->firstChild()->firstChild())->wholeText());
75 }
76
77 TEST_F(SetCharacterDataCommandTest, insertTextAtEndOfNonEmptyNode) {
78 setBodyContent("<div contenteditable>Hello</div>");
79
80 SimpleEditCommand* command = SetCharacterDataCommand::create(
81 toText(document().body()->firstChild()->firstChild()), 5, 0, ", world!");
82
83 command->doReapply();
84 EXPECT_EQ("Hello, world!",
85 toText(document().body()->firstChild()->firstChild())->wholeText());
86
87 command->doUnapply();
88 EXPECT_EQ("Hello",
89 toText(document().body()->firstChild()->firstChild())->wholeText());
90 }
91
92 TEST_F(SetCharacterDataCommandTest, replaceEntireNode) {
93 setBodyContent("<div contenteditable>Hello</div>");
94
95 SimpleEditCommand* command = SetCharacterDataCommand::create(
96 toText(document().body()->firstChild()->firstChild()), 0, 5, "Bye");
97
98 command->doReapply();
99 EXPECT_EQ("Bye",
100 toText(document().body()->firstChild()->firstChild())->wholeText());
101
102 command->doUnapply();
103 EXPECT_EQ("Hello",
104 toText(document().body()->firstChild()->firstChild())->wholeText());
105 }
106
107 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/SetCharacterDataCommand.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698