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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/commands/SetCharacterDataCommandTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/SetCharacterDataCommandTest.cpp b/third_party/WebKit/Source/core/editing/commands/SetCharacterDataCommandTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..b8828e1abf431f8b4c05babc10ceebf9b9724f8b
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/commands/SetCharacterDataCommandTest.cpp
@@ -0,0 +1,107 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/editing/commands/SetCharacterDataCommand.h"
+
+#include "core/editing/EditingTestBase.h"
+#include "core/editing/commands/EditingState.h"
+
+namespace blink {
+
+class SetCharacterDataCommandTest : public EditingTestBase {};
+
+TEST_F(SetCharacterDataCommandTest, replaceTextWithSameLength) {
+ setBodyContent("<div contenteditable>This is a good test case</div>");
+
+ SimpleEditCommand* command = SetCharacterDataCommand::create(
+ toText(document().body()->firstChild()->firstChild()), 10, 4, "lame");
+
+ command->doReapply();
+ EXPECT_EQ("This is a lame test case",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+
+ command->doUnapply();
+ EXPECT_EQ("This is a good test case",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+}
+
+TEST_F(SetCharacterDataCommandTest, replaceTextWithLongerText) {
+ setBodyContent("<div contenteditable>This is a good test case</div>");
+
+ SimpleEditCommand* command = SetCharacterDataCommand::create(
+ toText(document().body()->firstChild()->firstChild()), 10, 4, "lousy");
+
+ command->doReapply();
+ EXPECT_EQ("This is a lousy test case",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+
+ command->doUnapply();
+ EXPECT_EQ("This is a good test case",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+}
+
+TEST_F(SetCharacterDataCommandTest, replaceTextWithShorterText) {
+ setBodyContent("<div contenteditable>This is a good test case</div>");
+
+ SimpleEditCommand* command = SetCharacterDataCommand::create(
+ toText(document().body()->firstChild()->firstChild()), 10, 4, "meh");
+
+ command->doReapply();
+ EXPECT_EQ("This is a meh test case",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+
+ command->doUnapply();
+ EXPECT_EQ("This is a good test case",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+}
+
+TEST_F(SetCharacterDataCommandTest, insertTextIntoEmptyNode) {
+ setBodyContent("<div contenteditable />");
+
+ document().body()->firstChild()->appendChild(
+ document().createEditingTextNode(""));
+
+ SimpleEditCommand* command = SetCharacterDataCommand::create(
+ toText(document().body()->firstChild()->firstChild()), 0, 0, "hello");
+
+ command->doReapply();
+ EXPECT_EQ("hello",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+
+ command->doUnapply();
+ EXPECT_EQ("",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+}
+
+TEST_F(SetCharacterDataCommandTest, insertTextAtEndOfNonEmptyNode) {
+ setBodyContent("<div contenteditable>Hello</div>");
+
+ SimpleEditCommand* command = SetCharacterDataCommand::create(
+ toText(document().body()->firstChild()->firstChild()), 5, 0, ", world!");
+
+ command->doReapply();
+ EXPECT_EQ("Hello, world!",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+
+ command->doUnapply();
+ EXPECT_EQ("Hello",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+}
+
+TEST_F(SetCharacterDataCommandTest, replaceEntireNode) {
+ setBodyContent("<div contenteditable>Hello</div>");
+
+ SimpleEditCommand* command = SetCharacterDataCommand::create(
+ toText(document().body()->firstChild()->firstChild()), 0, 5, "Bye");
+
+ command->doReapply();
+ EXPECT_EQ("Bye",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+
+ command->doUnapply();
+ EXPECT_EQ("Hello",
+ toText(document().body()->firstChild()->firstChild())->wholeText());
+}
+
+} // namespace blink
« 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