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

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

Issue 2530843003: Introduce InsertIncrementalTextCommand to respect existing style for composition (Closed)
Patch Set: Add a test for commitText() Created 4 years 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/editing/InputMethodController.h" 5 #include "core/editing/InputMethodController.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/Element.h" 8 #include "core/dom/Element.h"
9 #include "core/dom/Range.h" 9 #include "core/dom/Range.h"
10 #include "core/editing/Editor.h" 10 #include "core/editing/Editor.h"
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 controller().setComposition(String::fromUTF8("\xE0\xB0\x83\xE0\xB0\x83"), 243 controller().setComposition(String::fromUTF8("\xE0\xB0\x83\xE0\xB0\x83"),
244 underlines, 2, 2); 244 underlines, 2, 2);
245 EXPECT_STREQ("<b>\xE0\xB0\x83\xE0\xB0\x83</b>", 245 EXPECT_STREQ("<b>\xE0\xB0\x83\xE0\xB0\x83</b>",
246 div->innerHTML().utf8().data()); 246 div->innerHTML().utf8().data());
247 247
248 controller().setComposition(String::fromUTF8("\xE0\xB0\x83"), underlines, 1, 248 controller().setComposition(String::fromUTF8("\xE0\xB0\x83"), underlines, 1,
249 1); 249 1);
250 EXPECT_STREQ("<b>\xE0\xB0\x83</b>", div->innerHTML().utf8().data()); 250 EXPECT_STREQ("<b>\xE0\xB0\x83</b>", div->innerHTML().utf8().data());
251 } 251 }
252 252
253 TEST_F(InputMethodControllerTest, FinishComposingTextKeepingStyle) {
254 Element* div = insertHTMLElement(
255 "<div id='sample' "
256 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>",
257 "sample");
258
259 Vector<CompositionUnderline> underlines;
260 underlines.append(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0));
261 controller().setCompositionFromExistingText(underlines, 3, 12);
262
263 controller().setComposition(String("123hello789"), underlines, 11, 11);
264 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9", div->innerHTML().utf8().data());
265
266 controller().finishComposingText(InputMethodController::KeepSelection);
267 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9", div->innerHTML().utf8().data());
268 }
269
270 TEST_F(InputMethodControllerTest, CommitTextKeepingStyle) {
271 Element* div = insertHTMLElement(
272 "<div id='sample' "
273 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>",
274 "sample");
275
276 Vector<CompositionUnderline> underlines;
277 underlines.append(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0));
278 controller().setCompositionFromExistingText(underlines, 3, 12);
279
280 controller().commitText(String("123789"), 0);
281 EXPECT_STREQ("abc1<b>2</b>37<b>8</b>9", div->innerHTML().utf8().data());
282 }
283
253 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { 284 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) {
254 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", 285 insertHTMLElement("<div id='sample' contenteditable>hello world</div>",
255 "sample"); 286 "sample");
256 287
257 Vector<CompositionUnderline> underlines; 288 Vector<CompositionUnderline> underlines;
258 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 289 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
259 controller().setCompositionFromExistingText(underlines, 0, 5); 290 controller().setCompositionFromExistingText(underlines, 0, 5);
260 291
261 controller().finishComposingText(InputMethodController::KeepSelection); 292 controller().finishComposingText(InputMethodController::KeepSelection);
262 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); 293 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode());
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 // Simulate composition in the |contentEditable|. 935 // Simulate composition in the |contentEditable|.
905 Vector<CompositionUnderline> underlines; 936 Vector<CompositionUnderline> underlines;
906 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 937 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
907 938
908 document().setTitle(emptyString()); 939 document().setTitle(emptyString());
909 controller().setComposition("hell", underlines, 4, 4); 940 controller().setComposition("hell", underlines, 4, 4);
910 EXPECT_STREQ("beforeinput.data:hell;input.data:hell;", 941 EXPECT_STREQ("beforeinput.data:hell;input.data:hell;",
911 document().title().utf8().data()); 942 document().title().utf8().data());
912 943
913 // Replace the existing composition. 944 // Replace the existing composition.
914 // TODO(yabinh): should be "beforeinput.data:hello;input.data:hello;".
915 document().setTitle(emptyString()); 945 document().setTitle(emptyString());
916 controller().setComposition("hello", underlines, 0, 0); 946 controller().setComposition("hello", underlines, 0, 0);
917 EXPECT_STREQ("beforeinput.data:o;input.data:o;", 947 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;",
918 document().title().utf8().data()); 948 document().title().utf8().data());
919 } 949 }
920 950
921 TEST_F(InputMethodControllerTest, CompositionInputEventForConfirm) { 951 TEST_F(InputMethodControllerTest, CompositionInputEventForConfirm) {
922 createHTMLWithCompositionInputEventListeners(); 952 createHTMLWithCompositionInputEventListeners();
923 953
924 // Simulate composition in the |contentEditable|. 954 // Simulate composition in the |contentEditable|.
925 Vector<CompositionUnderline> underlines; 955 Vector<CompositionUnderline> underlines;
926 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 956 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
927 957
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 1008
979 // Insert new text with previous composition. 1009 // Insert new text with previous composition.
980 document().setTitle(emptyString()); 1010 document().setTitle(emptyString());
981 document().updateStyleAndLayout(); 1011 document().updateStyleAndLayout();
982 controller().commitText("hello", 1); 1012 controller().commitText("hello", 1);
983 EXPECT_STREQ( 1013 EXPECT_STREQ(
984 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", 1014 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;",
985 document().title().utf8().data()); 1015 document().title().utf8().data());
986 } 1016 }
987 1017
1018 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) {
1019 createHTMLWithCompositionInputEventListeners();
1020
1021 // Simulate composition in the |contentEditable|.
1022 Vector<CompositionUnderline> underlines;
1023 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
1024
1025 // Insert empty text without previous composition.
1026 document().setTitle(emptyString());
1027 document().updateStyleAndLayout();
1028 controller().commitText("", 0);
1029 EXPECT_STREQ("", document().title().utf8().data());
1030
1031 document().setTitle(emptyString());
1032 controller().setComposition("n", underlines, 1, 1);
1033 EXPECT_STREQ("beforeinput.data:n;input.data:n;",
1034 document().title().utf8().data());
1035
1036 // Insert empty text with previous composition.
1037 document().setTitle(emptyString());
1038 document().updateStyleAndLayout();
1039 controller().commitText("", 1);
1040 EXPECT_STREQ("beforeinput.data:;compositionend.data:;",
1041 document().title().utf8().data());
1042 }
1043
988 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) { 1044 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) {
989 createHTMLWithCompositionEndEventListener(CaretSelection); 1045 createHTMLWithCompositionEndEventListener(CaretSelection);
990 1046
991 // Simulate composition in the |contentEditable|. 1047 // Simulate composition in the |contentEditable|.
992 Vector<CompositionUnderline> underlines; 1048 Vector<CompositionUnderline> underlines;
993 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1049 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
994 1050
995 controller().setComposition("hello", underlines, 1, 1); 1051 controller().setComposition("hello", underlines, 1, 1);
996 document().updateStyleAndLayout(); 1052 document().updateStyleAndLayout();
997 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); 1053 EXPECT_EQ(1u, controller().getSelectionOffsets().start());
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 EXPECT_EQ(WebTextInputTypeNone, controller().textInputType()); 1133 EXPECT_EQ(WebTextInputTypeNone, controller().textInputType());
1078 1134
1079 document().getElementById("b")->focus(); 1135 document().getElementById("b")->focus();
1080 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); 1136 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType());
1081 1137
1082 controller().finishComposingText(InputMethodController::KeepSelection); 1138 controller().finishComposingText(InputMethodController::KeepSelection);
1083 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); 1139 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType());
1084 } 1140 }
1085 1141
1086 } // namespace blink 1142 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698