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

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

Issue 2763873003: Adjust common prefix/suffix correctly for InsertIncrementalTextCommand (Closed)
Patch Set: Created 3 years, 9 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 .end() 205 .end()
206 .computeOffsetInContainerNode()); 206 .computeOffsetInContainerNode());
207 207
208 controller().setComposition(String("a"), underlines, 1, 1); 208 controller().setComposition(String("a"), underlines, 1, 1);
209 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61", div->innerText().utf8().data()); 209 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61", div->innerText().utf8().data());
210 210
211 controller().setComposition(String("ab"), underlines, 2, 2); 211 controller().setComposition(String("ab"), underlines, 2, 2);
212 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61\x62", div->innerText().utf8().data()); 212 EXPECT_STREQ("\xF0\x9F\x8F\x86\x61\x62", div->innerText().utf8().data());
213 } 213 }
214 214
215 TEST_F(InputMethodControllerTest, SetCompositionWithGraphemeCluster) {
216 insertHTMLElement("<div id='sample' contenteditable></div>", "sample");
217
218 Vector<CompositionUnderline> underlines;
219 underlines.push_back(CompositionUnderline(6, 6, Color(255, 0, 0), false, 0));
220 document().updateStyleAndLayout();
221
222 // UTF16 = 0x0939 0x0947 0x0932 0x0932. Note that 0x0932 0x0932 is a grapheme
223 // cluster.
224 controller().setComposition(
225 String::fromUTF8("\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA4\xB2"),
226 underlines, 4, 4);
227 EXPECT_EQ(4u, controller().getSelectionOffsets().start());
228 EXPECT_EQ(4u, controller().getSelectionOffsets().end());
229
230 // UTF16 = 0x0939 0x0947 0x0932 0x094D 0x0932 0x094B.
231 controller().setComposition(
232 String::fromUTF8("\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0"
233 "\xA4\xB2\xE0\xA5\x8B"),
234 underlines, 6, 6);
235 EXPECT_EQ(6u, controller().getSelectionOffsets().start());
236 EXPECT_EQ(6u, controller().getSelectionOffsets().end());
237 }
238
239 TEST_F(InputMethodControllerTest,
240 SetCompositionWithGraphemeClusterAndMultipleNodes) {
241 Element* div =
242 insertHTMLElement("<div id='sample' contenteditable></div>", "sample");
243
244 Vector<CompositionUnderline> underlines;
245 underlines.push_back(
246 CompositionUnderline(12, 12, Color(255, 0, 0), false, 0));
247 document().updateStyleAndLayout();
248
249 // UTF16 = 0x0939 0x0947 0x0932 0x094D 0x0932 0x094B. 0x0939 0x0947 0x0932 is
250 // a grapheme cluster, so is the remainding 0x0932 0x094B.
251 controller().commitText(
252 String::fromUTF8("\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0"
253 "\xA4\xB2\xE0\xA5\x8B"),
254 underlines, 1);
255 controller().commitText("\nab ", underlines, 1);
256 controller().setComposition(String("c"), underlines, 1, 1);
257 EXPECT_STREQ(
258 "\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0\xA4\xB2\xE0\xA5"
259 "\x8B\nab c",
260 div->innerText().utf8().data());
261 EXPECT_EQ(11u, controller().getSelectionOffsets().start());
262 EXPECT_EQ(11u, controller().getSelectionOffsets().end());
263
264 controller().setComposition(String("cd"), underlines, 2, 2);
265 EXPECT_STREQ(
266 "\xE0\xA4\xB9\xE0\xA5\x87\xE0\xA4\xB2\xE0\xA5\x8D\xE0\xA4\xB2\xE0\xA5"
267 "\x8B\nab cd",
268 div->innerText().utf8().data());
269 EXPECT_EQ(12u, controller().getSelectionOffsets().start());
270 EXPECT_EQ(12u, controller().getSelectionOffsets().end());
271 }
272
215 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) { 273 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) {
216 Element* div = insertHTMLElement( 274 Element* div = insertHTMLElement(
217 "<div id='sample' " 275 "<div id='sample' "
218 "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>",
219 "sample"); 277 "sample");
220 278
221 Vector<CompositionUnderline> underlines; 279 Vector<CompositionUnderline> underlines;
222 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));
223 controller().setCompositionFromExistingText(underlines, 3, 12); 281 controller().setCompositionFromExistingText(underlines, 3, 12);
224 282
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 Vector<CompositionUnderline> underlines; 1479 Vector<CompositionUnderline> underlines;
1422 underlines.push_back(CompositionUnderline(0, 3, Color(255, 0, 0), false, 0)); 1480 underlines.push_back(CompositionUnderline(0, 3, Color(255, 0, 0), false, 0));
1423 controller().setComposition(String("def"), underlines, 0, 3); 1481 controller().setComposition(String("def"), underlines, 0, 3);
1424 controller().setComposition(String(""), underlines, 0, 3); 1482 controller().setComposition(String(""), underlines, 0, 3);
1425 controller().commitText(String("def"), underlines, 0); 1483 controller().commitText(String("def"), underlines, 0);
1426 1484
1427 EXPECT_STREQ("abc\ndef", textarea->value().utf8().data()); 1485 EXPECT_STREQ("abc\ndef", textarea->value().utf8().data());
1428 } 1486 }
1429 1487
1430 } // namespace blink 1488 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698