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

Unified Diff: third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp

Issue 2020973002: Reland: Fix setComposingText with empty text when newCursorPosition != 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reland. Add a parameter. Created 4 years, 4 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/InputMethodController.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/InputMethodControllerTest.cpp
diff --git a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
index e4d8b525c61a00a0358427e834ec7883f05444ef..daba680b7a4724ae155f8fbbbebd3beeb1c1ca97 100644
--- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
+++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp
@@ -7,6 +7,7 @@
#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/dom/Range.h"
+#include "core/editing/Editor.h"
#include "core/editing/FrameSelection.h"
#include "core/events/MouseEvent.h"
#include "core/frame/FrameView.h"
@@ -349,6 +350,74 @@ TEST_F(InputMethodControllerTest, SetCompositionForContentEditableWithDifferentN
EXPECT_EQ(24u, controller().getSelectionOffsets().end());
}
+TEST_F(InputMethodControllerTest, SetCompositionWithEmptyText)
+{
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable='true'>hello</div>",
+ "sample");
+
+ controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().end());
+
+ Vector<CompositionUnderline> underlines0;
+ underlines0.append(CompositionUnderline(0, 0, Color(255, 0, 0), false, 0));
+ Vector<CompositionUnderline> underlines2;
+ underlines2.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
+
+ controller().setComposition("AB", underlines2, 2, 2);
+ // With previous composition.
+ controller().setComposition("", underlines0, 2, 2);
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(4u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(4u, controller().getSelectionOffsets().end());
+
+ // Without previous composition.
+ controller().setComposition("", underlines0, -1, -1);
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(3u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(3u, controller().getSelectionOffsets().end());
+}
+
+TEST_F(InputMethodControllerTest, InsertLineBreakWhileComposingText)
+{
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable='true'></div>",
+ "sample");
+
+ Vector<CompositionUnderline> underlines;
+ underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
+ controller().setComposition("hello", underlines, 5, 5);
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+ EXPECT_EQ(5u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(5u, controller().getSelectionOffsets().end());
+
+ frame().editor().insertLineBreak();
+ EXPECT_STREQ("\n\n", div->innerText().utf8().data());
+ EXPECT_EQ(1u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(1u, controller().getSelectionOffsets().end());
+}
+
+TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText)
+{
+ Element* div = insertHTMLElement(
+ "<div id='sample' contenteditable='true'></div>",
+ "sample");
+
+ controller().confirmCompositionOrInsertText("hello", InputMethodController::ConfirmCompositionBehavior::KeepSelection);
+ EXPECT_STREQ("hello", div->innerText().utf8().data());
+
+ controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
+ EXPECT_EQ(2u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(2u, controller().getSelectionOffsets().end());
+
+ frame().editor().insertLineBreak();
+ EXPECT_STREQ("he\nllo", div->innerText().utf8().data());
+ EXPECT_EQ(3u, controller().getSelectionOffsets().start());
+ EXPECT_EQ(3u, controller().getSelectionOffsets().end());
+}
+
TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing)
{
document().settings()->setScriptEnabled(true);
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698