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

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

Issue 2372493002: Workaround for setComposition styling clobber (Closed)
Patch Set: Address changwan@'s review Created 4 years, 2 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 "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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 108 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
109 controller().setCompositionFromExistingText(underlines, 0, 5); 109 controller().setCompositionFromExistingText(underlines, 0, 5);
110 110
111 Range* range = controller().compositionRange(); 111 Range* range = controller().compositionRange();
112 EXPECT_EQ(0, range->startOffset()); 112 EXPECT_EQ(0, range->startOffset());
113 EXPECT_EQ(5, range->endOffset()); 113 EXPECT_EQ(5, range->endOffset());
114 114
115 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); 115 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range));
116 EXPECT_EQ(0u, plainTextRange.start()); 116 EXPECT_EQ(0u, plainTextRange.start());
117 EXPECT_EQ(5u, plainTextRange.end()); 117 EXPECT_EQ(5u, plainTextRange.end());
118
119 controller().setComposition(String("hellobar"), underlines, 8, 8);
120 range = controller().compositionRange();
121 EXPECT_EQ(0, range->startOffset());
122 EXPECT_EQ(8, range->endOffset());
123 }
124
125 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle)
126 {
127 Element* div = insertHTMLElement(
128 "<div id='sample' contenteditable='true'><b>he</b>llo</div>", "sample");
129
130 Vector<CompositionUnderline> underlines;
131 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
132 controller().setCompositionFromExistingText(underlines, 0, 5);
133
134 controller().setComposition(String("hell"), underlines, 4, 4);
135 EXPECT_STREQ("<b>he</b>ll", div->innerHTML().utf8().data());
136
137 controller().setComposition(String("hello"), underlines, 5, 5);
138 EXPECT_STREQ("<b>he</b>llo", div->innerHTML().utf8().data());
aelias_OOO_until_Jul13 2016/09/28 23:58:29 Please add another test case for backspace.
yabinh 2016/10/11 01:42:23 Line#134 is for backspace(from "hello" to "hell").
139 }
140
141 TEST_F(InputMethodControllerTest, SetCompositionWithMultiCodeTextKeepingStyle)
142 {
143 // U+1F3E0 = 0xF0 0x9F 0x8F 0xA0 (UTF8). It's an emoji character with
144 // surrogate pairs.
145 Element* div = insertHTMLElement(
146 "<div id='sample' contenteditable='true'><b>&#x1f3e0</b></div>", "sample ");
147 Vector<CompositionUnderline> underlines;
148 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
149 controller().setCompositionFromExistingText(underlines, 0, 2);
150
151 // 0xF0 0x9F 0x8F 0xAB is also an emoji character with surrogate pairs.
152 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xAB"), underlines , 2, 2);
153 EXPECT_STREQ("<b>\xF0\x9F\x8F\xAB</b>", div->innerHTML().utf8().data());
154
155 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xA0"), underlines , 2, 2);
156 EXPECT_STREQ("<b>\xF0\x9F\x8F\xA0</b>", div->innerHTML().utf8().data());
157
158 // U+0C03 = 0xE0 0xB0 0x83 (UTF8), a telugu character with 1 code point.
159 div = insertHTMLElement(
160 "<div id='sample' contenteditable='true'><b>&#xc03</b></div>", "sample") ;
161 controller().setCompositionFromExistingText(underlines, 0, 1);
162
163 // 0xE0 0xB0 0x83 0xE0 0xB0 0x83, a telugu character with 2 code points in
164 // 1 grapheme cluster.
165 controller().setComposition(String::fromUTF8("\xE0\xB0\x83\xE0\xB0\x83"), un derlines, 2, 2);
166 EXPECT_STREQ("<b>\xE0\xB0\x83\xE0\xB0\x83</b>", div->innerHTML().utf8().data ());
167
168 controller().setComposition(String::fromUTF8("\xE0\xB0\x83"), underlines, 1, 1);
yabinh 2016/09/27 12:46:47 Note that if we use code point to decide the commo
169 EXPECT_STREQ("<b>\xE0\xB0\x83</b>", div->innerHTML().utf8().data());
118 } 170 }
119 171
120 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) 172 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText)
121 { 173 {
122 insertHTMLElement( 174 insertHTMLElement(
123 "<div id='sample' contenteditable='true'>hello world</div>", "sample"); 175 "<div id='sample' contenteditable='true'>hello world</div>", "sample");
124 176
125 Vector<CompositionUnderline> underlines; 177 Vector<CompositionUnderline> underlines;
126 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 178 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
127 controller().setCompositionFromExistingText(underlines, 0, 5); 179 controller().setCompositionFromExistingText(underlines, 0, 5);
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 Vector<CompositionUnderline> underlines; 530 Vector<CompositionUnderline> underlines;
479 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 531 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
480 editable->focus(); 532 editable->focus();
481 533
482 document().setTitle(emptyString()); 534 document().setTitle(emptyString());
483 controller().setComposition("n", underlines, 0, 1); 535 controller().setComposition("n", underlines, 0, 1);
484 EXPECT_STREQ("beforeinput.data:n;input.data:n;", document().title().utf8().d ata()); 536 EXPECT_STREQ("beforeinput.data:n;input.data:n;", document().title().utf8().d ata());
485 537
486 document().setTitle(emptyString()); 538 document().setTitle(emptyString());
487 controller().setComposition("ni", underlines, 0, 1); 539 controller().setComposition("ni", underlines, 0, 1);
488 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data()); 540 EXPECT_STREQ("beforeinput.data:i;input.data:i;", document().title().utf8().d ata());
489 541
490 document().setTitle(emptyString()); 542 document().setTitle(emptyString());
491 controller().finishComposingText(InputMethodController::KeepSelection); 543 controller().finishComposingText(InputMethodController::KeepSelection);
492 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data()); 544 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data());
493 } 545 }
494 546
495 } // namespace blink 547 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698