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

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: 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
253 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { 270 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) {
254 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", 271 insertHTMLElement("<div id='sample' contenteditable>hello world</div>",
255 "sample"); 272 "sample");
256 273
257 Vector<CompositionUnderline> underlines; 274 Vector<CompositionUnderline> underlines;
258 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 275 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
259 controller().setCompositionFromExistingText(underlines, 0, 5); 276 controller().setCompositionFromExistingText(underlines, 0, 5);
260 277
261 controller().finishComposingText(InputMethodController::KeepSelection); 278 controller().finishComposingText(InputMethodController::KeepSelection);
262 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); 279 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|. 921 // Simulate composition in the |contentEditable|.
905 Vector<CompositionUnderline> underlines; 922 Vector<CompositionUnderline> underlines;
906 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 923 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
907 924
908 document().setTitle(emptyString()); 925 document().setTitle(emptyString());
909 controller().setComposition("hell", underlines, 4, 4); 926 controller().setComposition("hell", underlines, 4, 4);
910 EXPECT_STREQ("beforeinput.data:hell;input.data:hell;", 927 EXPECT_STREQ("beforeinput.data:hell;input.data:hell;",
911 document().title().utf8().data()); 928 document().title().utf8().data());
912 929
913 // Replace the existing composition. 930 // Replace the existing composition.
914 // TODO(yabinh): should be "beforeinput.data:hello;input.data:hello;".
915 document().setTitle(emptyString()); 931 document().setTitle(emptyString());
916 controller().setComposition("hello", underlines, 0, 0); 932 controller().setComposition("hello", underlines, 0, 0);
917 EXPECT_STREQ("beforeinput.data:o;input.data:o;", 933 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;",
918 document().title().utf8().data()); 934 document().title().utf8().data());
919 } 935 }
920 936
921 TEST_F(InputMethodControllerTest, CompositionInputEventForConfirm) { 937 TEST_F(InputMethodControllerTest, CompositionInputEventForConfirm) {
922 createHTMLWithCompositionInputEventListeners(); 938 createHTMLWithCompositionInputEventListeners();
923 939
924 // Simulate composition in the |contentEditable|. 940 // Simulate composition in the |contentEditable|.
925 Vector<CompositionUnderline> underlines; 941 Vector<CompositionUnderline> underlines;
926 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 942 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
927 943
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 document().title().utf8().data()); 993 document().title().utf8().data());
978 994
979 // Insert new text with previous composition. 995 // Insert new text with previous composition.
980 document().setTitle(emptyString()); 996 document().setTitle(emptyString());
981 document().updateStyleAndLayout(); 997 document().updateStyleAndLayout();
982 controller().commitText("hello", 1); 998 controller().commitText("hello", 1);
983 EXPECT_STREQ( 999 EXPECT_STREQ(
984 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", 1000 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;",
985 document().title().utf8().data()); 1001 document().title().utf8().data());
986 } 1002 }
987 1003
yabinh 2016/11/25 04:36:27 It's better to have a test for inserting empty tex
1004 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) {
1005 createHTMLWithCompositionInputEventListeners();
1006
1007 // Simulate composition in the |contentEditable|.
1008 Vector<CompositionUnderline> underlines;
1009 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
1010
1011 // Insert empty text without previous composition.
1012 document().setTitle(emptyString());
1013 document().updateStyleAndLayout();
1014 controller().commitText("", 0);
1015 EXPECT_STREQ("", document().title().utf8().data());
1016
1017 document().setTitle(emptyString());
1018 controller().setComposition("n", underlines, 1, 1);
1019 EXPECT_STREQ("beforeinput.data:n;input.data:n;",
1020 document().title().utf8().data());
1021
1022 // Insert empty text with previous composition.
1023 document().setTitle(emptyString());
1024 document().updateStyleAndLayout();
1025 controller().commitText("", 1);
1026 EXPECT_STREQ("beforeinput.data:;compositionend.data:;",
1027 document().title().utf8().data());
1028 }
1029
988 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) { 1030 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) {
989 createHTMLWithCompositionEndEventListener(CaretSelection); 1031 createHTMLWithCompositionEndEventListener(CaretSelection);
990 1032
991 // Simulate composition in the |contentEditable|. 1033 // Simulate composition in the |contentEditable|.
992 Vector<CompositionUnderline> underlines; 1034 Vector<CompositionUnderline> underlines;
993 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1035 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
994 1036
995 controller().setComposition("hello", underlines, 1, 1); 1037 controller().setComposition("hello", underlines, 1, 1);
996 document().updateStyleAndLayout(); 1038 document().updateStyleAndLayout();
997 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); 1039 EXPECT_EQ(1u, controller().getSelectionOffsets().start());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); 1098 EXPECT_EQ(1u, controller().getSelectionOffsets().end());
1057 1099
1058 // Confirm the ongoing composition. Note that it moves the caret to the end of 1100 // Confirm the ongoing composition. Note that it moves the caret to the end of
1059 // text [5,5] before firing 'compositonend' event. 1101 // text [5,5] before firing 'compositonend' event.
1060 controller().finishComposingText(InputMethodController::DoNotKeepSelection); 1102 controller().finishComposingText(InputMethodController::DoNotKeepSelection);
1061 document().updateStyleAndLayout(); 1103 document().updateStyleAndLayout();
1062 EXPECT_TRUE(controller().getSelectionOffsets().isNull()); 1104 EXPECT_TRUE(controller().getSelectionOffsets().isNull());
1063 } 1105 }
1064 1106
1065 } // namespace blink 1107 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698