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

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

Issue 2568093003: Support parsing BackgroundSpans and UnderlineSpans in Android IME's commitText() (Closed)
Patch Set: Attempt to fix dependency error with target 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"
11 #include "core/editing/FrameSelection.h" 11 #include "core/editing/FrameSelection.h"
12 #include "core/events/MouseEvent.h" 12 #include "core/events/MouseEvent.h"
13 #include "core/frame/FrameView.h" 13 #include "core/frame/FrameView.h"
14 #include "core/frame/LocalFrame.h" 14 #include "core/frame/LocalFrame.h"
15 #include "core/frame/Settings.h" 15 #include "core/frame/Settings.h"
16 #include "core/html/HTMLInputElement.h" 16 #include "core/html/HTMLInputElement.h"
17 #include "core/testing/DummyPageHolder.h" 17 #include "core/testing/DummyPageHolder.h"
18 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
19 #include "third_party/WebKit/Source/core/editing/markers/DocumentMarkerControlle r.h"
Yuta Kitamura 2016/12/20 07:09:14 You should write this as: #include "core/editing/.
rlanday 2016/12/20 20:34:42 Ah, that seems to resolve the issue. Thanks! I sup
19 #include <memory> 20 #include <memory>
20 21
21 namespace blink { 22 namespace blink {
22 23
23 class InputMethodControllerTest : public ::testing::Test { 24 class InputMethodControllerTest : public ::testing::Test {
24 protected: 25 protected:
25 InputMethodController& controller() { 26 InputMethodController& controller() {
26 return frame().inputMethodController(); 27 return frame().inputMethodController();
27 } 28 }
28 Document& document() const { return *m_document; } 29 Document& document() const { return *m_document; }
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 TEST_F(InputMethodControllerTest, CommitTextKeepingStyle) { 278 TEST_F(InputMethodControllerTest, CommitTextKeepingStyle) {
278 Element* div = insertHTMLElement( 279 Element* div = insertHTMLElement(
279 "<div id='sample' " 280 "<div id='sample' "
280 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>", 281 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>",
281 "sample"); 282 "sample");
282 283
283 Vector<CompositionUnderline> underlines; 284 Vector<CompositionUnderline> underlines;
284 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); 285 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0));
285 controller().setCompositionFromExistingText(underlines, 3, 12); 286 controller().setCompositionFromExistingText(underlines, 3, 12);
286 287
287 controller().commitText(String("123789"), 0); 288 controller().commitText(String("123789"), underlines, 0);
288 EXPECT_STREQ("abc1<b>2</b>37<b>8</b>9", div->innerHTML().utf8().data()); 289 EXPECT_STREQ("abc1<b>2</b>37<b>8</b>9", div->innerHTML().utf8().data());
289 } 290 }
290 291
291 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { 292 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) {
292 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", 293 insertHTMLElement("<div id='sample' contenteditable>hello world</div>",
293 "sample"); 294 "sample");
294 295
295 Vector<CompositionUnderline> underlines; 296 Vector<CompositionUnderline> underlines;
296 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 297 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
297 controller().setCompositionFromExistingText(underlines, 0, 5); 298 controller().setCompositionFromExistingText(underlines, 0, 5);
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 frame().editor().insertLineBreak(); 885 frame().editor().insertLineBreak();
885 EXPECT_STREQ("\n\n", div->innerText().utf8().data()); 886 EXPECT_STREQ("\n\n", div->innerText().utf8().data());
886 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); 887 EXPECT_EQ(1u, controller().getSelectionOffsets().start());
887 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); 888 EXPECT_EQ(1u, controller().getSelectionOffsets().end());
888 } 889 }
889 890
890 TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText) { 891 TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText) {
891 Element* div = 892 Element* div =
892 insertHTMLElement("<div id='sample' contenteditable></div>", "sample"); 893 insertHTMLElement("<div id='sample' contenteditable></div>", "sample");
893 894
894 controller().commitText("hello", 0); 895 Vector<CompositionUnderline> underlines;
896 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
897 controller().commitText("hello", underlines, 0);
895 EXPECT_STREQ("hello", div->innerText().utf8().data()); 898 EXPECT_STREQ("hello", div->innerText().utf8().data());
896 899
897 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); 900 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
898 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); 901 EXPECT_EQ(2u, controller().getSelectionOffsets().start());
899 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); 902 EXPECT_EQ(2u, controller().getSelectionOffsets().end());
900 903
901 frame().editor().insertLineBreak(); 904 frame().editor().insertLineBreak();
902 EXPECT_STREQ("he\nllo", div->innerText().utf8().data()); 905 EXPECT_STREQ("he\nllo", div->innerText().utf8().data());
903 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); 906 EXPECT_EQ(3u, controller().getSelectionOffsets().start());
904 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); 907 EXPECT_EQ(3u, controller().getSelectionOffsets().end());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 TEST_F(InputMethodControllerTest, CompositionInputEventForInsert) { 1000 TEST_F(InputMethodControllerTest, CompositionInputEventForInsert) {
998 createHTMLWithCompositionInputEventListeners(); 1001 createHTMLWithCompositionInputEventListeners();
999 1002
1000 // Simulate composition in the |contentEditable|. 1003 // Simulate composition in the |contentEditable|.
1001 Vector<CompositionUnderline> underlines; 1004 Vector<CompositionUnderline> underlines;
1002 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1005 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
1003 1006
1004 // Insert new text without previous composition. 1007 // Insert new text without previous composition.
1005 document().setTitle(emptyString()); 1008 document().setTitle(emptyString());
1006 document().updateStyleAndLayout(); 1009 document().updateStyleAndLayout();
1007 controller().commitText("hello", 0); 1010 controller().commitText("hello", underlines, 0);
1008 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", 1011 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;",
1009 document().title().utf8().data()); 1012 document().title().utf8().data());
1010 1013
1011 document().setTitle(emptyString()); 1014 document().setTitle(emptyString());
1012 controller().setComposition("n", underlines, 1, 1); 1015 controller().setComposition("n", underlines, 1, 1);
1013 EXPECT_STREQ("beforeinput.data:n;input.data:n;", 1016 EXPECT_STREQ("beforeinput.data:n;input.data:n;",
1014 document().title().utf8().data()); 1017 document().title().utf8().data());
1015 1018
1016 // Insert new text with previous composition. 1019 // Insert new text with previous composition.
1017 document().setTitle(emptyString()); 1020 document().setTitle(emptyString());
1018 document().updateStyleAndLayout(); 1021 document().updateStyleAndLayout();
1019 controller().commitText("hello", 1); 1022 controller().commitText("hello", underlines, 1);
1020 EXPECT_STREQ( 1023 EXPECT_STREQ(
1021 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", 1024 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;",
1022 document().title().utf8().data()); 1025 document().title().utf8().data());
1023 } 1026 }
1024 1027
1025 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) { 1028 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) {
1026 createHTMLWithCompositionInputEventListeners(); 1029 createHTMLWithCompositionInputEventListeners();
1027 1030
1028 // Simulate composition in the |contentEditable|. 1031 // Simulate composition in the |contentEditable|.
1029 Vector<CompositionUnderline> underlines; 1032 Vector<CompositionUnderline> underlines;
1030 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1033 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
1031 1034
1032 // Insert empty text without previous composition. 1035 // Insert empty text without previous composition.
1033 document().setTitle(emptyString()); 1036 document().setTitle(emptyString());
1034 document().updateStyleAndLayout(); 1037 document().updateStyleAndLayout();
1035 controller().commitText("", 0); 1038 controller().commitText("", underlines, 0);
1036 EXPECT_STREQ("", document().title().utf8().data()); 1039 EXPECT_STREQ("", document().title().utf8().data());
1037 1040
1038 document().setTitle(emptyString()); 1041 document().setTitle(emptyString());
1039 controller().setComposition("n", underlines, 1, 1); 1042 controller().setComposition("n", underlines, 1, 1);
1040 EXPECT_STREQ("beforeinput.data:n;input.data:n;", 1043 EXPECT_STREQ("beforeinput.data:n;input.data:n;",
1041 document().title().utf8().data()); 1044 document().title().utf8().data());
1042 1045
1043 // Insert empty text with previous composition. 1046 // Insert empty text with previous composition.
1044 document().setTitle(emptyString()); 1047 document().setTitle(emptyString());
1045 document().updateStyleAndLayout(); 1048 document().updateStyleAndLayout();
1046 controller().commitText("", 1); 1049 controller().commitText("", underlines, 1);
1047 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", 1050 EXPECT_STREQ("beforeinput.data:;compositionend.data:;",
1048 document().title().utf8().data()); 1051 document().title().utf8().data());
1049 } 1052 }
1050 1053
1051 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) { 1054 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) {
1052 createHTMLWithCompositionEndEventListener(CaretSelection); 1055 createHTMLWithCompositionEndEventListener(CaretSelection);
1053 1056
1054 // Simulate composition in the |contentEditable|. 1057 // Simulate composition in the |contentEditable|.
1055 Vector<CompositionUnderline> underlines; 1058 Vector<CompositionUnderline> underlines;
1056 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1059 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
(...skipping 16 matching lines...) Expand all
1073 1076
1074 // Simulate composition in the |contentEditable|. 1077 // Simulate composition in the |contentEditable|.
1075 Vector<CompositionUnderline> underlines; 1078 Vector<CompositionUnderline> underlines;
1076 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1079 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
1077 1080
1078 controller().setComposition("n", underlines, 1, 1); 1081 controller().setComposition("n", underlines, 1, 1);
1079 1082
1080 // Insert new text with previous composition. Note that it moves the caret to 1083 // Insert new text with previous composition. Note that it moves the caret to
1081 // [4,4] before firing 'compositonend' event. 1084 // [4,4] before firing 'compositonend' event.
1082 document().updateStyleAndLayout(); 1085 document().updateStyleAndLayout();
1083 controller().commitText("hello", -1); 1086 controller().commitText("hello", underlines, -1);
1084 document().updateStyleAndLayout(); 1087 document().updateStyleAndLayout();
1085 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); 1088 EXPECT_EQ(3u, controller().getSelectionOffsets().start());
1086 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); 1089 EXPECT_EQ(3u, controller().getSelectionOffsets().end());
1087 } 1090 }
1088 1091
1089 TEST_F(InputMethodControllerTest, CompositionEndEventWithRangeSelection) { 1092 TEST_F(InputMethodControllerTest, CompositionEndEventWithRangeSelection) {
1090 createHTMLWithCompositionEndEventListener(RangeSelection); 1093 createHTMLWithCompositionEndEventListener(RangeSelection);
1091 1094
1092 // Simulate composition in the |contentEditable|. 1095 // Simulate composition in the |contentEditable|.
1093 Vector<CompositionUnderline> underlines; 1096 Vector<CompositionUnderline> underlines;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 inputA->setOuterHTML("", ASSERT_NO_EXCEPTION); 1142 inputA->setOuterHTML("", ASSERT_NO_EXCEPTION);
1140 EXPECT_EQ(WebTextInputTypeNone, controller().textInputType()); 1143 EXPECT_EQ(WebTextInputTypeNone, controller().textInputType());
1141 1144
1142 document().getElementById("b")->focus(); 1145 document().getElementById("b")->focus();
1143 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); 1146 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType());
1144 1147
1145 controller().finishComposingText(InputMethodController::KeepSelection); 1148 controller().finishComposingText(InputMethodController::KeepSelection);
1146 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); 1149 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType());
1147 } 1150 }
1148 1151
1152 TEST_F(InputMethodControllerTest, CommitPlainTextWithUnderlineInsert) {
1153 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>",
1154 "sample");
1155
1156 Vector<CompositionUnderline> underlines;
1157
1158 controller().setEditableSelectionOffsets(PlainTextRange(8, 8));
1159
1160 underlines.push_back(CompositionUnderline(1, 11, Color(255, 0, 0), false, 0));
1161
1162 controller().commitText(String("underlined"), underlines, 0);
1163
1164 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset());
1165 EXPECT_EQ(19u, document().markers().markers()[0]->endOffset());
1166 }
1167
1168 TEST_F(InputMethodControllerTest, CommitPlainTextWithUnderlineReplace) {
1169 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>",
1170 "sample");
1171
1172 Vector<CompositionUnderline> underlines;
1173
1174 controller().setCompositionFromExistingText(underlines, 8, 12);
1175
1176 underlines.push_back(CompositionUnderline(1, 11, Color(255, 0, 0), false, 0));
1177
1178 controller().commitText(String("string"), underlines, 0);
1179
1180 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset());
1181 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset());
1182 }
1183
1149 } // namespace blink 1184 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698