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

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

Issue 2926043002: Rename PlainText::end() to PlainText::End() (Closed)
Patch Set: Created 3 years, 6 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 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 <memory> 7 #include <memory>
8 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h" 9 #include "core/dom/Element.h"
10 #include "core/dom/Range.h" 10 #include "core/dom/Range.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 Vector<CompositionUnderline> underlines; 174 Vector<CompositionUnderline> underlines;
175 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 175 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
176 Controller().SetCompositionFromExistingText(underlines, 0, 5); 176 Controller().SetCompositionFromExistingText(underlines, 0, 5);
177 177
178 Range* range = Controller().CompositionRange(); 178 Range* range = Controller().CompositionRange();
179 EXPECT_EQ(0u, range->startOffset()); 179 EXPECT_EQ(0u, range->startOffset());
180 EXPECT_EQ(5u, range->endOffset()); 180 EXPECT_EQ(5u, range->endOffset());
181 181
182 PlainTextRange plain_text_range(PlainTextRange::Create(*div, *range)); 182 PlainTextRange plain_text_range(PlainTextRange::Create(*div, *range));
183 EXPECT_EQ(0u, plain_text_range.Start()); 183 EXPECT_EQ(0u, plain_text_range.Start());
184 EXPECT_EQ(5u, plain_text_range.end()); 184 EXPECT_EQ(5u, plain_text_range.End());
185 } 185 }
186 186
187 TEST_F(InputMethodControllerTest, SetCompositionAfterEmoji) { 187 TEST_F(InputMethodControllerTest, SetCompositionAfterEmoji) {
188 // "trophy" = U+1F3C6 = 0xF0 0x9F 0x8F 0x86 (UTF8). 188 // "trophy" = U+1F3C6 = 0xF0 0x9F 0x8F 0x86 (UTF8).
189 Element* div = InsertHTMLElement( 189 Element* div = InsertHTMLElement(
190 "<div id='sample' contenteditable>&#x1f3c6</div>", "sample"); 190 "<div id='sample' contenteditable>&#x1f3c6</div>", "sample");
191 191
192 Vector<CompositionUnderline> underlines; 192 Vector<CompositionUnderline> underlines;
193 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); 193 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
194 194
(...skipping 23 matching lines...) Expand all
218 Vector<CompositionUnderline> underlines; 218 Vector<CompositionUnderline> underlines;
219 underlines.push_back(CompositionUnderline(6, 6, Color(255, 0, 0), false, 0)); 219 underlines.push_back(CompositionUnderline(6, 6, Color(255, 0, 0), false, 0));
220 GetDocument().UpdateStyleAndLayout(); 220 GetDocument().UpdateStyleAndLayout();
221 221
222 // UTF16 = 0x0939 0x0947 0x0932 0x0932. Note that 0x0932 0x0932 is a grapheme 222 // UTF16 = 0x0939 0x0947 0x0932 0x0932. Note that 0x0932 0x0932 is a grapheme
223 // cluster. 223 // cluster.
224 Controller().SetComposition( 224 Controller().SetComposition(
225 String::FromUTF8("\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA4\xB2"), 225 String::FromUTF8("\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA4\xB2"),
226 underlines, 4, 4); 226 underlines, 4, 4);
227 EXPECT_EQ(4u, Controller().GetSelectionOffsets().Start()); 227 EXPECT_EQ(4u, Controller().GetSelectionOffsets().Start());
228 EXPECT_EQ(4u, Controller().GetSelectionOffsets().end()); 228 EXPECT_EQ(4u, Controller().GetSelectionOffsets().End());
229 229
230 // UTF16 = 0x0939 0x0947 0x0932 0x094D 0x0932 0x094B. 230 // UTF16 = 0x0939 0x0947 0x0932 0x094D 0x0932 0x094B.
231 Controller().SetComposition( 231 Controller().SetComposition(
232 String::FromUTF8("\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0" 232 String::FromUTF8("\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0"
233 "\xA4\xB2\xE0\xA5\x8B"), 233 "\xA4\xB2\xE0\xA5\x8B"),
234 underlines, 6, 6); 234 underlines, 6, 6);
235 EXPECT_EQ(6u, Controller().GetSelectionOffsets().Start()); 235 EXPECT_EQ(6u, Controller().GetSelectionOffsets().Start());
236 EXPECT_EQ(6u, Controller().GetSelectionOffsets().end()); 236 EXPECT_EQ(6u, Controller().GetSelectionOffsets().End());
237 } 237 }
238 238
239 TEST_F(InputMethodControllerTest, 239 TEST_F(InputMethodControllerTest,
240 SetCompositionWithGraphemeClusterAndMultipleNodes) { 240 SetCompositionWithGraphemeClusterAndMultipleNodes) {
241 Element* div = 241 Element* div =
242 InsertHTMLElement("<div id='sample' contenteditable></div>", "sample"); 242 InsertHTMLElement("<div id='sample' contenteditable></div>", "sample");
243 243
244 Vector<CompositionUnderline> underlines; 244 Vector<CompositionUnderline> underlines;
245 underlines.push_back( 245 underlines.push_back(
246 CompositionUnderline(12, 12, Color(255, 0, 0), false, 0)); 246 CompositionUnderline(12, 12, Color(255, 0, 0), false, 0));
247 GetDocument().UpdateStyleAndLayout(); 247 GetDocument().UpdateStyleAndLayout();
248 248
249 // UTF16 = 0x0939 0x0947 0x0932 0x094D 0x0932 0x094B. 0x0939 0x0947 0x0932 is 249 // UTF16 = 0x0939 0x0947 0x0932 0x094D 0x0932 0x094B. 0x0939 0x0947 0x0932 is
250 // a grapheme cluster, so is the remainding 0x0932 0x094B. 250 // a grapheme cluster, so is the remainding 0x0932 0x094B.
251 Controller().CommitText( 251 Controller().CommitText(
252 String::FromUTF8("\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0" 252 String::FromUTF8("\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0"
253 "\xA4\xB2\xE0\xA5\x8B"), 253 "\xA4\xB2\xE0\xA5\x8B"),
254 underlines, 1); 254 underlines, 1);
255 Controller().CommitText("\nab ", underlines, 1); 255 Controller().CommitText("\nab ", underlines, 1);
256 Controller().SetComposition(String("c"), underlines, 1, 1); 256 Controller().SetComposition(String("c"), underlines, 1, 1);
257 EXPECT_STREQ( 257 EXPECT_STREQ(
258 "\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0\xA4\xB2\xE0\xA5" 258 "\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0\xA4\xB2\xE0\xA5"
259 "\x8B\nab c", 259 "\x8B\nab c",
260 div->innerText().Utf8().data()); 260 div->innerText().Utf8().data());
261 EXPECT_EQ(11u, Controller().GetSelectionOffsets().Start()); 261 EXPECT_EQ(11u, Controller().GetSelectionOffsets().Start());
262 EXPECT_EQ(11u, Controller().GetSelectionOffsets().end()); 262 EXPECT_EQ(11u, Controller().GetSelectionOffsets().End());
263 263
264 Controller().SetComposition(String("cd"), underlines, 2, 2); 264 Controller().SetComposition(String("cd"), underlines, 2, 2);
265 EXPECT_STREQ( 265 EXPECT_STREQ(
266 "\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0\xA4\xB2\xE0\xA5" 266 "\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0\xA4\xB2\xE0\xA5"
267 "\x8B\nab cd", 267 "\x8B\nab cd",
268 div->innerText().Utf8().data()); 268 div->innerText().Utf8().data());
269 EXPECT_EQ(12u, Controller().GetSelectionOffsets().Start()); 269 EXPECT_EQ(12u, Controller().GetSelectionOffsets().Start());
270 EXPECT_EQ(12u, Controller().GetSelectionOffsets().end()); 270 EXPECT_EQ(12u, Controller().GetSelectionOffsets().End());
271 } 271 }
272 272
273 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) { 273 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) {
274 Element* div = InsertHTMLElement( 274 Element* div = InsertHTMLElement(
275 "<div id='sample' " 275 "<div id='sample' "
276 "contenteditable>abc1<b>2</b>34567<b>8</b>9d<b>e</b>f</div>", 276 "contenteditable>abc1<b>2</b>34567<b>8</b>9d<b>e</b>f</div>",
277 "sample"); 277 "sample");
278 278
279 Vector<CompositionUnderline> underlines; 279 Vector<CompositionUnderline> underlines;
280 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); 280 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0));
281 Controller().SetCompositionFromExistingText(underlines, 3, 12); 281 Controller().SetCompositionFromExistingText(underlines, 3, 12);
282 282
283 // Subtract a character. 283 // Subtract a character.
284 Controller().SetComposition(String("12345789"), underlines, 8, 8); 284 Controller().SetComposition(String("12345789"), underlines, 8, 8);
285 EXPECT_STREQ("abc1<b>2</b>3457<b>8</b>9d<b>e</b>f", 285 EXPECT_STREQ("abc1<b>2</b>3457<b>8</b>9d<b>e</b>f",
286 div->innerHTML().Utf8().data()); 286 div->innerHTML().Utf8().data());
287 EXPECT_EQ(11u, Controller().GetSelectionOffsets().Start()); 287 EXPECT_EQ(11u, Controller().GetSelectionOffsets().Start());
288 EXPECT_EQ(11u, Controller().GetSelectionOffsets().end()); 288 EXPECT_EQ(11u, Controller().GetSelectionOffsets().End());
289 289
290 // Append a character. 290 // Append a character.
291 Controller().SetComposition(String("123456789"), underlines, 9, 9); 291 Controller().SetComposition(String("123456789"), underlines, 9, 9);
292 EXPECT_STREQ("abc1<b>2</b>34567<b>8</b>9d<b>e</b>f", 292 EXPECT_STREQ("abc1<b>2</b>34567<b>8</b>9d<b>e</b>f",
293 div->innerHTML().Utf8().data()); 293 div->innerHTML().Utf8().data());
294 EXPECT_EQ(12u, Controller().GetSelectionOffsets().Start()); 294 EXPECT_EQ(12u, Controller().GetSelectionOffsets().Start());
295 EXPECT_EQ(12u, Controller().GetSelectionOffsets().end()); 295 EXPECT_EQ(12u, Controller().GetSelectionOffsets().End());
296 296
297 // Subtract and append characters. 297 // Subtract and append characters.
298 Controller().SetComposition(String("123hello789"), underlines, 11, 11); 298 Controller().SetComposition(String("123hello789"), underlines, 11, 11);
299 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9d<b>e</b>f", 299 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9d<b>e</b>f",
300 div->innerHTML().Utf8().data()); 300 div->innerHTML().Utf8().data());
301 } 301 }
302 302
303 TEST_F(InputMethodControllerTest, SetCompositionWithEmojiKeepingStyle) { 303 TEST_F(InputMethodControllerTest, SetCompositionWithEmojiKeepingStyle) {
304 // U+1F3E0 = 0xF0 0x9F 0x8F 0xA0 (UTF8). It's an emoji character. 304 // U+1F3E0 = 0xF0 0x9F 0x8F 0xA0 (UTF8). It's an emoji character.
305 Element* div = InsertHTMLElement( 305 Element* div = InsertHTMLElement(
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 Vector<CompositionUnderline> underlines; 457 Vector<CompositionUnderline> underlines;
458 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 458 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
459 Controller().SetCompositionFromExistingText(underlines, 0, 5); 459 Controller().SetCompositionFromExistingText(underlines, 0, 5);
460 460
461 Range* range = Controller().CompositionRange(); 461 Range* range = Controller().CompositionRange();
462 EXPECT_EQ(1u, range->startOffset()); 462 EXPECT_EQ(1u, range->startOffset());
463 EXPECT_EQ(6u, range->endOffset()); 463 EXPECT_EQ(6u, range->endOffset());
464 464
465 PlainTextRange plain_text_range(PlainTextRange::Create(*div, *range)); 465 PlainTextRange plain_text_range(PlainTextRange::Create(*div, *range));
466 EXPECT_EQ(0u, plain_text_range.Start()); 466 EXPECT_EQ(0u, plain_text_range.Start());
467 EXPECT_EQ(5u, plain_text_range.end()); 467 EXPECT_EQ(5u, plain_text_range.End());
468 } 468 }
469 469
470 TEST_F(InputMethodControllerTest, 470 TEST_F(InputMethodControllerTest,
471 SetCompositionFromExistingTextWithInvalidOffsets) { 471 SetCompositionFromExistingTextWithInvalidOffsets) {
472 InsertHTMLElement("<div id='sample' contenteditable>test</div>", "sample"); 472 InsertHTMLElement("<div id='sample' contenteditable>test</div>", "sample");
473 473
474 Vector<CompositionUnderline> underlines; 474 Vector<CompositionUnderline> underlines;
475 underlines.push_back(CompositionUnderline(7, 8, Color(255, 0, 0), false, 0)); 475 underlines.push_back(CompositionUnderline(7, 8, Color(255, 0, 0), false, 0));
476 Controller().SetCompositionFromExistingText(underlines, 7, 8); 476 Controller().SetCompositionFromExistingText(underlines, 7, 8);
477 477
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 "<div id='sample2' contenteditable>bbb" 780 "<div id='sample2' contenteditable>bbb"
781 "<div id='sample3' contenteditable>ccc" 781 "<div id='sample3' contenteditable>ccc"
782 "<div id='sample4' contenteditable>ddd" 782 "<div id='sample4' contenteditable>ddd"
783 "<div id='sample5' contenteditable>eee" 783 "<div id='sample5' contenteditable>eee"
784 "</div></div></div></div></div>", 784 "</div></div></div></div></div>",
785 "sample"); 785 "sample");
786 786
787 Controller().SetEditableSelectionOffsets(PlainTextRange(8, 8)); 787 Controller().SetEditableSelectionOffsets(PlainTextRange(8, 8));
788 EXPECT_STREQ("aaa\nbbb\nccc\nddd\neee", div->innerText().Utf8().data()); 788 EXPECT_STREQ("aaa\nbbb\nccc\nddd\neee", div->innerText().Utf8().data());
789 EXPECT_EQ(8u, Controller().GetSelectionOffsets().Start()); 789 EXPECT_EQ(8u, Controller().GetSelectionOffsets().Start());
790 EXPECT_EQ(8u, Controller().GetSelectionOffsets().end()); 790 EXPECT_EQ(8u, Controller().GetSelectionOffsets().End());
791 791
792 Controller().DeleteSurroundingText(1, 0); 792 Controller().DeleteSurroundingText(1, 0);
793 EXPECT_STREQ("aaa\nbbbccc\nddd\neee", div->innerText().Utf8().data()); 793 EXPECT_STREQ("aaa\nbbbccc\nddd\neee", div->innerText().Utf8().data());
794 EXPECT_EQ(7u, Controller().GetSelectionOffsets().Start()); 794 EXPECT_EQ(7u, Controller().GetSelectionOffsets().Start());
795 EXPECT_EQ(7u, Controller().GetSelectionOffsets().end()); 795 EXPECT_EQ(7u, Controller().GetSelectionOffsets().End());
796 796
797 Controller().DeleteSurroundingText(0, 4); 797 Controller().DeleteSurroundingText(0, 4);
798 EXPECT_STREQ("aaa\nbbbddd\neee", div->innerText().Utf8().data()); 798 EXPECT_STREQ("aaa\nbbbddd\neee", div->innerText().Utf8().data());
799 EXPECT_EQ(7u, Controller().GetSelectionOffsets().Start()); 799 EXPECT_EQ(7u, Controller().GetSelectionOffsets().Start());
800 EXPECT_EQ(7u, Controller().GetSelectionOffsets().end()); 800 EXPECT_EQ(7u, Controller().GetSelectionOffsets().End());
801 801
802 Controller().DeleteSurroundingText(5, 5); 802 Controller().DeleteSurroundingText(5, 5);
803 EXPECT_STREQ("aaee", div->innerText().Utf8().data()); 803 EXPECT_STREQ("aaee", div->innerText().Utf8().data());
804 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start()); 804 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start());
805 EXPECT_EQ(2u, Controller().GetSelectionOffsets().end()); 805 EXPECT_EQ(2u, Controller().GetSelectionOffsets().End());
806 } 806 }
807 807
808 TEST_F(InputMethodControllerTest, 808 TEST_F(InputMethodControllerTest,
809 DeleteSurroundingTextInCodePointsWithMultiCodeTextOnTheLeft) { 809 DeleteSurroundingTextInCodePointsWithMultiCodeTextOnTheLeft) {
810 HTMLInputElement* input = 810 HTMLInputElement* input =
811 toHTMLInputElement(InsertHTMLElement("<input id='sample'>", "sample")); 811 toHTMLInputElement(InsertHTMLElement("<input id='sample'>", "sample"));
812 812
813 // 'a' + "black star" + SPACE + "trophy" + SPACE + composed text (U+0E01 813 // 'a' + "black star" + SPACE + "trophy" + SPACE + composed text (U+0E01
814 // "ka kai" + U+0E49 "mai tho"). 814 // "ka kai" + U+0E49 "mai tho").
815 // A "black star" is 1 grapheme cluster. It has 1 code point, and its length 815 // A "black star" is 1 grapheme cluster. It has 1 code point, and its length
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 TEST_F(InputMethodControllerTest, DeleteSurroundingTextInCodePointsWithImage) { 876 TEST_F(InputMethodControllerTest, DeleteSurroundingTextInCodePointsWithImage) {
877 Element* div = InsertHTMLElement( 877 Element* div = InsertHTMLElement(
878 "<div id='sample' contenteditable>aaa" 878 "<div id='sample' contenteditable>aaa"
879 "<img src='empty.png'>bbb</div>", 879 "<img src='empty.png'>bbb</div>",
880 "sample"); 880 "sample");
881 881
882 Controller().SetEditableSelectionOffsets(PlainTextRange(4, 4)); 882 Controller().SetEditableSelectionOffsets(PlainTextRange(4, 4));
883 Controller().DeleteSurroundingTextInCodePoints(1, 1); 883 Controller().DeleteSurroundingTextInCodePoints(1, 1);
884 EXPECT_STREQ("aaabb", div->innerText().Utf8().data()); 884 EXPECT_STREQ("aaabb", div->innerText().Utf8().data());
885 EXPECT_EQ(3u, Controller().GetSelectionOffsets().Start()); 885 EXPECT_EQ(3u, Controller().GetSelectionOffsets().Start());
886 EXPECT_EQ(3u, Controller().GetSelectionOffsets().end()); 886 EXPECT_EQ(3u, Controller().GetSelectionOffsets().End());
887 } 887 }
888 888
889 TEST_F(InputMethodControllerTest, 889 TEST_F(InputMethodControllerTest,
890 DeleteSurroundingTextInCodePointsWithInvalidSurrogatePair) { 890 DeleteSurroundingTextInCodePointsWithInvalidSurrogatePair) {
891 HTMLInputElement* input = 891 HTMLInputElement* input =
892 toHTMLInputElement(InsertHTMLElement("<input id='sample'>", "sample")); 892 toHTMLInputElement(InsertHTMLElement("<input id='sample'>", "sample"));
893 893
894 // 'a' + high surrogate of "trophy" + "black star" + low surrogate of "trophy" 894 // 'a' + high surrogate of "trophy" + "black star" + low surrogate of "trophy"
895 // + SPACE 895 // + SPACE
896 const UChar kUText[] = {'a', 0xD83C, 0x2605, 0xDFC6, ' ', '\0'}; 896 const UChar kUText[] = {'a', 0xD83C, 0x2605, 0xDFC6, ' ', '\0'};
(...skipping 29 matching lines...) Expand all
926 926
927 TEST_F(InputMethodControllerTest, SetCompositionForInputWithNewCaretPositions) { 927 TEST_F(InputMethodControllerTest, SetCompositionForInputWithNewCaretPositions) {
928 HTMLInputElement* input = 928 HTMLInputElement* input =
929 toHTMLInputElement(InsertHTMLElement("<input id='sample'>", "sample")); 929 toHTMLInputElement(InsertHTMLElement("<input id='sample'>", "sample"));
930 930
931 input->setValue("hello"); 931 input->setValue("hello");
932 GetDocument().UpdateStyleAndLayout(); 932 GetDocument().UpdateStyleAndLayout();
933 Controller().SetEditableSelectionOffsets(PlainTextRange(2, 2)); 933 Controller().SetEditableSelectionOffsets(PlainTextRange(2, 2));
934 EXPECT_STREQ("hello", input->value().Utf8().data()); 934 EXPECT_STREQ("hello", input->value().Utf8().data());
935 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start()); 935 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start());
936 EXPECT_EQ(2u, Controller().GetSelectionOffsets().end()); 936 EXPECT_EQ(2u, Controller().GetSelectionOffsets().End());
937 937
938 Vector<CompositionUnderline> underlines; 938 Vector<CompositionUnderline> underlines;
939 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); 939 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
940 940
941 // The caret exceeds left boundary. 941 // The caret exceeds left boundary.
942 // "*heABllo", where * stands for caret. 942 // "*heABllo", where * stands for caret.
943 Controller().SetComposition("AB", underlines, -100, -100); 943 Controller().SetComposition("AB", underlines, -100, -100);
944 EXPECT_STREQ("heABllo", input->value().Utf8().data()); 944 EXPECT_STREQ("heABllo", input->value().Utf8().data());
945 EXPECT_EQ(0u, Controller().GetSelectionOffsets().Start()); 945 EXPECT_EQ(0u, Controller().GetSelectionOffsets().Start());
946 EXPECT_EQ(0u, Controller().GetSelectionOffsets().end()); 946 EXPECT_EQ(0u, Controller().GetSelectionOffsets().End());
947 947
948 // The caret is on left boundary. 948 // The caret is on left boundary.
949 // "*heABllo". 949 // "*heABllo".
950 Controller().SetComposition("AB", underlines, -2, -2); 950 Controller().SetComposition("AB", underlines, -2, -2);
951 EXPECT_STREQ("heABllo", input->value().Utf8().data()); 951 EXPECT_STREQ("heABllo", input->value().Utf8().data());
952 EXPECT_EQ(0u, Controller().GetSelectionOffsets().Start()); 952 EXPECT_EQ(0u, Controller().GetSelectionOffsets().Start());
953 EXPECT_EQ(0u, Controller().GetSelectionOffsets().end()); 953 EXPECT_EQ(0u, Controller().GetSelectionOffsets().End());
954 954
955 // The caret is before the composing text. 955 // The caret is before the composing text.
956 // "he*ABllo". 956 // "he*ABllo".
957 Controller().SetComposition("AB", underlines, 0, 0); 957 Controller().SetComposition("AB", underlines, 0, 0);
958 EXPECT_STREQ("heABllo", input->value().Utf8().data()); 958 EXPECT_STREQ("heABllo", input->value().Utf8().data());
959 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start()); 959 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start());
960 EXPECT_EQ(2u, Controller().GetSelectionOffsets().end()); 960 EXPECT_EQ(2u, Controller().GetSelectionOffsets().End());
961 961
962 // The caret is after the composing text. 962 // The caret is after the composing text.
963 // "heAB*llo". 963 // "heAB*llo".
964 Controller().SetComposition("AB", underlines, 2, 2); 964 Controller().SetComposition("AB", underlines, 2, 2);
965 EXPECT_STREQ("heABllo", input->value().Utf8().data()); 965 EXPECT_STREQ("heABllo", input->value().Utf8().data());
966 EXPECT_EQ(4u, Controller().GetSelectionOffsets().Start()); 966 EXPECT_EQ(4u, Controller().GetSelectionOffsets().Start());
967 EXPECT_EQ(4u, Controller().GetSelectionOffsets().end()); 967 EXPECT_EQ(4u, Controller().GetSelectionOffsets().End());
968 968
969 // The caret is on right boundary. 969 // The caret is on right boundary.
970 // "heABllo*". 970 // "heABllo*".
971 Controller().SetComposition("AB", underlines, 5, 5); 971 Controller().SetComposition("AB", underlines, 5, 5);
972 EXPECT_STREQ("heABllo", input->value().Utf8().data()); 972 EXPECT_STREQ("heABllo", input->value().Utf8().data());
973 EXPECT_EQ(7u, Controller().GetSelectionOffsets().Start()); 973 EXPECT_EQ(7u, Controller().GetSelectionOffsets().Start());
974 EXPECT_EQ(7u, Controller().GetSelectionOffsets().end()); 974 EXPECT_EQ(7u, Controller().GetSelectionOffsets().End());
975 975
976 // The caret exceeds right boundary. 976 // The caret exceeds right boundary.
977 // "heABllo*". 977 // "heABllo*".
978 Controller().SetComposition("AB", underlines, 100, 100); 978 Controller().SetComposition("AB", underlines, 100, 100);
979 EXPECT_STREQ("heABllo", input->value().Utf8().data()); 979 EXPECT_STREQ("heABllo", input->value().Utf8().data());
980 EXPECT_EQ(7u, Controller().GetSelectionOffsets().Start()); 980 EXPECT_EQ(7u, Controller().GetSelectionOffsets().Start());
981 EXPECT_EQ(7u, Controller().GetSelectionOffsets().end()); 981 EXPECT_EQ(7u, Controller().GetSelectionOffsets().End());
982 } 982 }
983 983
984 TEST_F(InputMethodControllerTest, 984 TEST_F(InputMethodControllerTest,
985 SetCompositionForContentEditableWithNewCaretPositions) { 985 SetCompositionForContentEditableWithNewCaretPositions) {
986 // There are 7 nodes and 5+1+5+1+3+4+3 characters: "hello", '\n', "world", 986 // There are 7 nodes and 5+1+5+1+3+4+3 characters: "hello", '\n', "world",
987 // "\n", "012", "3456", "789". 987 // "\n", "012", "3456", "789".
988 Element* div = InsertHTMLElement( 988 Element* div = InsertHTMLElement(
989 "<div id='sample' contenteditable>" 989 "<div id='sample' contenteditable>"
990 "hello" 990 "hello"
991 "<div id='sample2' contenteditable>world" 991 "<div id='sample2' contenteditable>world"
992 "<p>012<b>3456</b><i>789</i></p>" 992 "<p>012<b>3456</b><i>789</i></p>"
993 "</div>" 993 "</div>"
994 "</div>", 994 "</div>",
995 "sample"); 995 "sample");
996 996
997 Controller().SetEditableSelectionOffsets(PlainTextRange(17, 17)); 997 Controller().SetEditableSelectionOffsets(PlainTextRange(17, 17));
998 EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().Utf8().data()); 998 EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().Utf8().data());
999 EXPECT_EQ(17u, Controller().GetSelectionOffsets().Start()); 999 EXPECT_EQ(17u, Controller().GetSelectionOffsets().Start());
1000 EXPECT_EQ(17u, Controller().GetSelectionOffsets().end()); 1000 EXPECT_EQ(17u, Controller().GetSelectionOffsets().End());
1001 1001
1002 Vector<CompositionUnderline> underlines; 1002 Vector<CompositionUnderline> underlines;
1003 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); 1003 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
1004 1004
1005 // The caret exceeds left boundary. 1005 // The caret exceeds left boundary.
1006 // "*hello\nworld\n01234AB56789", where * stands for caret. 1006 // "*hello\nworld\n01234AB56789", where * stands for caret.
1007 Controller().SetComposition("AB", underlines, -100, -100); 1007 Controller().SetComposition("AB", underlines, -100, -100);
1008 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data()); 1008 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data());
1009 EXPECT_EQ(0u, Controller().GetSelectionOffsets().Start()); 1009 EXPECT_EQ(0u, Controller().GetSelectionOffsets().Start());
1010 EXPECT_EQ(0u, Controller().GetSelectionOffsets().end()); 1010 EXPECT_EQ(0u, Controller().GetSelectionOffsets().End());
1011 1011
1012 // The caret is on left boundary. 1012 // The caret is on left boundary.
1013 // "*hello\nworld\n01234AB56789". 1013 // "*hello\nworld\n01234AB56789".
1014 Controller().SetComposition("AB", underlines, -17, -17); 1014 Controller().SetComposition("AB", underlines, -17, -17);
1015 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data()); 1015 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data());
1016 EXPECT_EQ(0u, Controller().GetSelectionOffsets().Start()); 1016 EXPECT_EQ(0u, Controller().GetSelectionOffsets().Start());
1017 EXPECT_EQ(0u, Controller().GetSelectionOffsets().end()); 1017 EXPECT_EQ(0u, Controller().GetSelectionOffsets().End());
1018 1018
1019 // The caret is in the 1st node. 1019 // The caret is in the 1st node.
1020 // "he*llo\nworld\n01234AB56789". 1020 // "he*llo\nworld\n01234AB56789".
1021 Controller().SetComposition("AB", underlines, -15, -15); 1021 Controller().SetComposition("AB", underlines, -15, -15);
1022 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data()); 1022 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data());
1023 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start()); 1023 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start());
1024 EXPECT_EQ(2u, Controller().GetSelectionOffsets().end()); 1024 EXPECT_EQ(2u, Controller().GetSelectionOffsets().End());
1025 1025
1026 // The caret is on right boundary of the 1st node. 1026 // The caret is on right boundary of the 1st node.
1027 // "hello*\nworld\n01234AB56789". 1027 // "hello*\nworld\n01234AB56789".
1028 Controller().SetComposition("AB", underlines, -12, -12); 1028 Controller().SetComposition("AB", underlines, -12, -12);
1029 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data()); 1029 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data());
1030 EXPECT_EQ(5u, Controller().GetSelectionOffsets().Start()); 1030 EXPECT_EQ(5u, Controller().GetSelectionOffsets().Start());
1031 EXPECT_EQ(5u, Controller().GetSelectionOffsets().end()); 1031 EXPECT_EQ(5u, Controller().GetSelectionOffsets().End());
1032 1032
1033 // The caret is on right boundary of the 2nd node. 1033 // The caret is on right boundary of the 2nd node.
1034 // "hello\n*world\n01234AB56789". 1034 // "hello\n*world\n01234AB56789".
1035 Controller().SetComposition("AB", underlines, -11, -11); 1035 Controller().SetComposition("AB", underlines, -11, -11);
1036 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data()); 1036 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data());
1037 EXPECT_EQ(6u, Controller().GetSelectionOffsets().Start()); 1037 EXPECT_EQ(6u, Controller().GetSelectionOffsets().Start());
1038 EXPECT_EQ(6u, Controller().GetSelectionOffsets().end()); 1038 EXPECT_EQ(6u, Controller().GetSelectionOffsets().End());
1039 1039
1040 // The caret is on right boundary of the 3rd node. 1040 // The caret is on right boundary of the 3rd node.
1041 // "hello\nworld*\n01234AB56789". 1041 // "hello\nworld*\n01234AB56789".
1042 Controller().SetComposition("AB", underlines, -6, -6); 1042 Controller().SetComposition("AB", underlines, -6, -6);
1043 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data()); 1043 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data());
1044 EXPECT_EQ(11u, Controller().GetSelectionOffsets().Start()); 1044 EXPECT_EQ(11u, Controller().GetSelectionOffsets().Start());
1045 EXPECT_EQ(11u, Controller().GetSelectionOffsets().end()); 1045 EXPECT_EQ(11u, Controller().GetSelectionOffsets().End());
1046 1046
1047 // The caret is on right boundary of the 4th node. 1047 // The caret is on right boundary of the 4th node.
1048 // "hello\nworld\n*01234AB56789". 1048 // "hello\nworld\n*01234AB56789".
1049 Controller().SetComposition("AB", underlines, -5, -5); 1049 Controller().SetComposition("AB", underlines, -5, -5);
1050 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data()); 1050 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data());
1051 EXPECT_EQ(12u, Controller().GetSelectionOffsets().Start()); 1051 EXPECT_EQ(12u, Controller().GetSelectionOffsets().Start());
1052 EXPECT_EQ(12u, Controller().GetSelectionOffsets().end()); 1052 EXPECT_EQ(12u, Controller().GetSelectionOffsets().End());
1053 1053
1054 // The caret is before the composing text. 1054 // The caret is before the composing text.
1055 // "hello\nworld\n01234*AB56789". 1055 // "hello\nworld\n01234*AB56789".
1056 Controller().SetComposition("AB", underlines, 0, 0); 1056 Controller().SetComposition("AB", underlines, 0, 0);
1057 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data()); 1057 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data());
1058 EXPECT_EQ(17u, Controller().GetSelectionOffsets().Start()); 1058 EXPECT_EQ(17u, Controller().GetSelectionOffsets().Start());
1059 EXPECT_EQ(17u, Controller().GetSelectionOffsets().end()); 1059 EXPECT_EQ(17u, Controller().GetSelectionOffsets().End());
1060 1060
1061 // The caret is after the composing text. 1061 // The caret is after the composing text.
1062 // "hello\nworld\n01234AB*56789". 1062 // "hello\nworld\n01234AB*56789".
1063 Controller().SetComposition("AB", underlines, 2, 2); 1063 Controller().SetComposition("AB", underlines, 2, 2);
1064 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data()); 1064 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data());
1065 EXPECT_EQ(19u, Controller().GetSelectionOffsets().Start()); 1065 EXPECT_EQ(19u, Controller().GetSelectionOffsets().Start());
1066 EXPECT_EQ(19u, Controller().GetSelectionOffsets().end()); 1066 EXPECT_EQ(19u, Controller().GetSelectionOffsets().End());
1067 1067
1068 // The caret is on right boundary. 1068 // The caret is on right boundary.
1069 // "hello\nworld\n01234AB56789*". 1069 // "hello\nworld\n01234AB56789*".
1070 Controller().SetComposition("AB", underlines, 7, 7); 1070 Controller().SetComposition("AB", underlines, 7, 7);
1071 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data()); 1071 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data());
1072 EXPECT_EQ(24u, Controller().GetSelectionOffsets().Start()); 1072 EXPECT_EQ(24u, Controller().GetSelectionOffsets().Start());
1073 EXPECT_EQ(24u, Controller().GetSelectionOffsets().end()); 1073 EXPECT_EQ(24u, Controller().GetSelectionOffsets().End());
1074 1074
1075 // The caret exceeds right boundary. 1075 // The caret exceeds right boundary.
1076 // "hello\nworld\n01234AB56789*". 1076 // "hello\nworld\n01234AB56789*".
1077 Controller().SetComposition("AB", underlines, 100, 100); 1077 Controller().SetComposition("AB", underlines, 100, 100);
1078 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data()); 1078 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().Utf8().data());
1079 EXPECT_EQ(24u, Controller().GetSelectionOffsets().Start()); 1079 EXPECT_EQ(24u, Controller().GetSelectionOffsets().Start());
1080 EXPECT_EQ(24u, Controller().GetSelectionOffsets().end()); 1080 EXPECT_EQ(24u, Controller().GetSelectionOffsets().End());
1081 } 1081 }
1082 1082
1083 TEST_F(InputMethodControllerTest, SetCompositionWithEmptyText) { 1083 TEST_F(InputMethodControllerTest, SetCompositionWithEmptyText) {
1084 Element* div = InsertHTMLElement( 1084 Element* div = InsertHTMLElement(
1085 "<div id='sample' contenteditable>hello</div>", "sample"); 1085 "<div id='sample' contenteditable>hello</div>", "sample");
1086 1086
1087 Controller().SetEditableSelectionOffsets(PlainTextRange(2, 2)); 1087 Controller().SetEditableSelectionOffsets(PlainTextRange(2, 2));
1088 EXPECT_STREQ("hello", div->innerText().Utf8().data()); 1088 EXPECT_STREQ("hello", div->innerText().Utf8().data());
1089 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start()); 1089 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start());
1090 EXPECT_EQ(2u, Controller().GetSelectionOffsets().end()); 1090 EXPECT_EQ(2u, Controller().GetSelectionOffsets().End());
1091 1091
1092 Vector<CompositionUnderline> underlines0; 1092 Vector<CompositionUnderline> underlines0;
1093 underlines0.push_back(CompositionUnderline(0, 0, Color(255, 0, 0), false, 0)); 1093 underlines0.push_back(CompositionUnderline(0, 0, Color(255, 0, 0), false, 0));
1094 Vector<CompositionUnderline> underlines2; 1094 Vector<CompositionUnderline> underlines2;
1095 underlines2.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); 1095 underlines2.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
1096 1096
1097 Controller().SetComposition("AB", underlines2, 2, 2); 1097 Controller().SetComposition("AB", underlines2, 2, 2);
1098 // With previous composition. 1098 // With previous composition.
1099 Controller().SetComposition("", underlines0, 2, 2); 1099 Controller().SetComposition("", underlines0, 2, 2);
1100 EXPECT_STREQ("hello", div->innerText().Utf8().data()); 1100 EXPECT_STREQ("hello", div->innerText().Utf8().data());
1101 EXPECT_EQ(4u, Controller().GetSelectionOffsets().Start()); 1101 EXPECT_EQ(4u, Controller().GetSelectionOffsets().Start());
1102 EXPECT_EQ(4u, Controller().GetSelectionOffsets().end()); 1102 EXPECT_EQ(4u, Controller().GetSelectionOffsets().End());
1103 1103
1104 // Without previous composition. 1104 // Without previous composition.
1105 Controller().SetComposition("", underlines0, -1, -1); 1105 Controller().SetComposition("", underlines0, -1, -1);
1106 EXPECT_STREQ("hello", div->innerText().Utf8().data()); 1106 EXPECT_STREQ("hello", div->innerText().Utf8().data());
1107 EXPECT_EQ(3u, Controller().GetSelectionOffsets().Start()); 1107 EXPECT_EQ(3u, Controller().GetSelectionOffsets().Start());
1108 EXPECT_EQ(3u, Controller().GetSelectionOffsets().end()); 1108 EXPECT_EQ(3u, Controller().GetSelectionOffsets().End());
1109 } 1109 }
1110 1110
1111 TEST_F(InputMethodControllerTest, InsertLineBreakWhileComposingText) { 1111 TEST_F(InputMethodControllerTest, InsertLineBreakWhileComposingText) {
1112 Element* div = 1112 Element* div =
1113 InsertHTMLElement("<div id='sample' contenteditable></div>", "sample"); 1113 InsertHTMLElement("<div id='sample' contenteditable></div>", "sample");
1114 1114
1115 Vector<CompositionUnderline> underlines; 1115 Vector<CompositionUnderline> underlines;
1116 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1116 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
1117 Controller().SetComposition("hello", underlines, 5, 5); 1117 Controller().SetComposition("hello", underlines, 5, 5);
1118 EXPECT_STREQ("hello", div->innerText().Utf8().data()); 1118 EXPECT_STREQ("hello", div->innerText().Utf8().data());
1119 EXPECT_EQ(5u, Controller().GetSelectionOffsets().Start()); 1119 EXPECT_EQ(5u, Controller().GetSelectionOffsets().Start());
1120 EXPECT_EQ(5u, Controller().GetSelectionOffsets().end()); 1120 EXPECT_EQ(5u, Controller().GetSelectionOffsets().End());
1121 1121
1122 GetFrame().GetEditor().InsertLineBreak(); 1122 GetFrame().GetEditor().InsertLineBreak();
1123 EXPECT_STREQ("\n\n", div->innerText().Utf8().data()); 1123 EXPECT_STREQ("\n\n", div->innerText().Utf8().data());
1124 EXPECT_EQ(1u, Controller().GetSelectionOffsets().Start()); 1124 EXPECT_EQ(1u, Controller().GetSelectionOffsets().Start());
1125 EXPECT_EQ(1u, Controller().GetSelectionOffsets().end()); 1125 EXPECT_EQ(1u, Controller().GetSelectionOffsets().End());
1126 } 1126 }
1127 1127
1128 TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText) { 1128 TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText) {
1129 Element* div = 1129 Element* div =
1130 InsertHTMLElement("<div id='sample' contenteditable></div>", "sample"); 1130 InsertHTMLElement("<div id='sample' contenteditable></div>", "sample");
1131 1131
1132 Vector<CompositionUnderline> underlines; 1132 Vector<CompositionUnderline> underlines;
1133 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); 1133 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
1134 Controller().CommitText("hello", underlines, 0); 1134 Controller().CommitText("hello", underlines, 0);
1135 EXPECT_STREQ("hello", div->innerText().Utf8().data()); 1135 EXPECT_STREQ("hello", div->innerText().Utf8().data());
1136 1136
1137 Controller().SetEditableSelectionOffsets(PlainTextRange(2, 2)); 1137 Controller().SetEditableSelectionOffsets(PlainTextRange(2, 2));
1138 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start()); 1138 EXPECT_EQ(2u, Controller().GetSelectionOffsets().Start());
1139 EXPECT_EQ(2u, Controller().GetSelectionOffsets().end()); 1139 EXPECT_EQ(2u, Controller().GetSelectionOffsets().End());
1140 1140
1141 GetFrame().GetEditor().InsertLineBreak(); 1141 GetFrame().GetEditor().InsertLineBreak();
1142 EXPECT_STREQ("he\nllo", div->innerText().Utf8().data()); 1142 EXPECT_STREQ("he\nllo", div->innerText().Utf8().data());
1143 EXPECT_EQ(3u, Controller().GetSelectionOffsets().Start()); 1143 EXPECT_EQ(3u, Controller().GetSelectionOffsets().Start());
1144 EXPECT_EQ(3u, Controller().GetSelectionOffsets().end()); 1144 EXPECT_EQ(3u, Controller().GetSelectionOffsets().End());
1145 } 1145 }
1146 1146
1147 TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing) { 1147 TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing) {
1148 GetDocument().GetSettings()->SetScriptEnabled(true); 1148 GetDocument().GetSettings()->SetScriptEnabled(true);
1149 Element* editable = 1149 Element* editable =
1150 InsertHTMLElement("<div id='sample' contenteditable></div>", "sample"); 1150 InsertHTMLElement("<div id='sample' contenteditable></div>", "sample");
1151 Element* script = GetDocument().createElement("script"); 1151 Element* script = GetDocument().createElement("script");
1152 script->setInnerHTML( 1152 script->setInnerHTML(
1153 "document.getElementById('sample').addEventListener('beforeinput', " 1153 "document.getElementById('sample').addEventListener('beforeinput', "
1154 " event => document.title = " 1154 " event => document.title = "
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 TEST_F(InputMethodControllerTest, CompositionEndEventWithNoSelection) { 1290 TEST_F(InputMethodControllerTest, CompositionEndEventWithNoSelection) {
1291 CreateHTMLWithCompositionEndEventListener(kNoSelection); 1291 CreateHTMLWithCompositionEndEventListener(kNoSelection);
1292 1292
1293 // Simulate composition in the |contentEditable|. 1293 // Simulate composition in the |contentEditable|.
1294 Vector<CompositionUnderline> underlines; 1294 Vector<CompositionUnderline> underlines;
1295 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1295 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
1296 1296
1297 Controller().SetComposition("hello", underlines, 1, 1); 1297 Controller().SetComposition("hello", underlines, 1, 1);
1298 GetDocument().UpdateStyleAndLayout(); 1298 GetDocument().UpdateStyleAndLayout();
1299 EXPECT_EQ(1u, Controller().GetSelectionOffsets().Start()); 1299 EXPECT_EQ(1u, Controller().GetSelectionOffsets().Start());
1300 EXPECT_EQ(1u, Controller().GetSelectionOffsets().end()); 1300 EXPECT_EQ(1u, Controller().GetSelectionOffsets().End());
1301 1301
1302 // Confirm the ongoing composition. Note that it moves the caret to the end of 1302 // Confirm the ongoing composition. Note that it moves the caret to the end of
1303 // text [5,5] before firing 'compositonend' event. 1303 // text [5,5] before firing 'compositonend' event.
1304 Controller().FinishComposingText(InputMethodController::kDoNotKeepSelection); 1304 Controller().FinishComposingText(InputMethodController::kDoNotKeepSelection);
1305 GetDocument().UpdateStyleAndLayout(); 1305 GetDocument().UpdateStyleAndLayout();
1306 EXPECT_TRUE(Controller().GetSelectionOffsets().IsNull()); 1306 EXPECT_TRUE(Controller().GetSelectionOffsets().IsNull());
1307 } 1307 }
1308 1308
1309 TEST_F(InputMethodControllerTest, FinishCompositionRemovedRange) { 1309 TEST_F(InputMethodControllerTest, FinishCompositionRemovedRange) {
1310 Element* input_a = 1310 Element* input_a =
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 // Set selection before BODY(editable). 1813 // Set selection before BODY(editable).
1814 GetFrame().Selection().SetSelection( 1814 GetFrame().Selection().SetSelection(
1815 SelectionInDOMTree::Builder() 1815 SelectionInDOMTree::Builder()
1816 .Collapse(Position(GetDocument().documentElement(), 0)) 1816 .Collapse(Position(GetDocument().documentElement(), 0))
1817 .Build()); 1817 .Build());
1818 1818
1819 EXPECT_EQ(kWebTextInputTypeContentEditable, Controller().TextInputType()); 1819 EXPECT_EQ(kWebTextInputTypeContentEditable, Controller().TextInputType());
1820 } 1820 }
1821 1821
1822 } // namespace blink 1822 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698