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

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

Issue 2427433002: Workaround for setComposition styling clobber (Closed)
Patch Set: 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 Range* range = controller().compositionRange(); 112 Range* range = controller().compositionRange();
113 EXPECT_EQ(0, range->startOffset()); 113 EXPECT_EQ(0, range->startOffset());
114 EXPECT_EQ(5, range->endOffset()); 114 EXPECT_EQ(5, range->endOffset());
115 115
116 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); 116 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range));
117 EXPECT_EQ(0u, plainTextRange.start()); 117 EXPECT_EQ(0u, plainTextRange.start());
118 EXPECT_EQ(5u, plainTextRange.end()); 118 EXPECT_EQ(5u, plainTextRange.end());
119 } 119 }
120 120
121 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) {
122 Element* div = insertHTMLElement(
123 "<div id='sample' "
124 "contenteditable='true'>abc1<b>2</b>34567<b>8</b>9</div>",
125 "sample");
126
127 Vector<CompositionUnderline> underlines;
128 underlines.append(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0));
129 controller().setCompositionFromExistingText(underlines, 3, 12);
130
131 // Subtract a character.
132 controller().setComposition(String("12345789"), underlines, 8, 8);
133 EXPECT_STREQ("abc1<b>2</b>3457<b>8</b>9", div->innerHTML().utf8().data());
134
135 // Append a character.
136 controller().setComposition(String("123456789"), underlines, 9, 9);
137 EXPECT_STREQ("abc1<b>2</b>34567<b>8</b>9", div->innerHTML().utf8().data());
138
139 // Subtract and append characters.
140 controller().setComposition(String("123hello789"), underlines, 11, 11);
141 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9", div->innerHTML().utf8().data());
142 }
143
144 TEST_F(InputMethodControllerTest, SetCompositionWithEmojiKeepingStyle) {
145 // U+1F3E0 = 0xF0 0x9F 0x8F 0xA0 (UTF8). It's an emoji character.
146 Element* div = insertHTMLElement(
147 "<div id='sample' contenteditable='true'><b>&#x1f3e0</b></div>",
148 "sample");
149
150 Vector<CompositionUnderline> underlines;
151 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
152
153 controller().setCompositionFromExistingText(underlines, 0, 2);
154
155 // 0xF0 0x9F 0x8F 0xAB is also an emoji character, with the same leading
156 // surrogate pair to the previous one.
157 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xAB"), underlines,
158 2, 2);
159 EXPECT_STREQ("<b>\xF0\x9F\x8F\xAB</b>", div->innerHTML().utf8().data());
160
161 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xA0"), underlines,
162 2, 2);
163 EXPECT_STREQ("<b>\xF0\x9F\x8F\xA0</b>", div->innerHTML().utf8().data());
164 }
165
166 TEST_F(InputMethodControllerTest,
167 SetCompositionWithTeluguSignVisargaKeepingStyle) {
168 // U+0C03 = 0xE0 0xB0 0x83 (UTF8), a telugu sign visarga with one code point.
169 // It's one grapheme cluster if separated. It can also form one grapheme
170 // cluster with another code point(e.g, itself).
171 Element* div = insertHTMLElement(
172 "<div id='sample' contenteditable='true'><b>&#xc03</b></div>", "sample");
173
174 Vector<CompositionUnderline> underlines;
175 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
176 controller().setCompositionFromExistingText(underlines, 0, 1);
177
178 // 0xE0 0xB0 0x83 0xE0 0xB0 0x83, a telugu character with 2 code points in
179 // 1 grapheme cluster.
180 controller().setComposition(String::fromUTF8("\xE0\xB0\x83\xE0\xB0\x83"),
181 underlines, 2, 2);
182 EXPECT_STREQ("<b>\xE0\xB0\x83\xE0\xB0\x83</b>",
183 div->innerHTML().utf8().data());
184
185 controller().setComposition(String::fromUTF8("\xE0\xB0\x83"), underlines, 1,
186 1);
187 EXPECT_STREQ("<b>\xE0\xB0\x83</b>", div->innerHTML().utf8().data());
188 }
189
121 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { 190 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) {
122 insertHTMLElement("<div id='sample' contenteditable='true'>hello world</div>", 191 insertHTMLElement("<div id='sample' contenteditable='true'>hello world</div>",
123 "sample"); 192 "sample");
124 193
125 Vector<CompositionUnderline> underlines; 194 Vector<CompositionUnderline> underlines;
126 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 195 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
127 controller().setCompositionFromExistingText(underlines, 0, 5); 196 controller().setCompositionFromExistingText(underlines, 0, 5);
128 197
129 controller().finishComposingText(InputMethodController::KeepSelection); 198 controller().finishComposingText(InputMethodController::KeepSelection);
130 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); 199 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode());
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 547 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
479 editable->focus(); 548 editable->focus();
480 549
481 document().setTitle(emptyString()); 550 document().setTitle(emptyString());
482 controller().setComposition("n", underlines, 0, 1); 551 controller().setComposition("n", underlines, 0, 1);
483 EXPECT_STREQ("beforeinput.data:n;input.data:n;", 552 EXPECT_STREQ("beforeinput.data:n;input.data:n;",
484 document().title().utf8().data()); 553 document().title().utf8().data());
485 554
486 document().setTitle(emptyString()); 555 document().setTitle(emptyString());
487 controller().setComposition("ni", underlines, 0, 1); 556 controller().setComposition("ni", underlines, 0, 1);
488 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", 557 EXPECT_STREQ("beforeinput.data:i;input.data:i;",
489 document().title().utf8().data()); 558 document().title().utf8().data());
490 559
491 document().setTitle(emptyString()); 560 document().setTitle(emptyString());
492 controller().finishComposingText(InputMethodController::KeepSelection); 561 controller().finishComposingText(InputMethodController::KeepSelection);
493 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", 562 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;",
494 document().title().utf8().data()); 563 document().title().utf8().data());
495 } 564 }
496 565
497 } // namespace blink 566 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698