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

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

Issue 1889053003: Fix InputConnection.deleteSurroundingText() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed the type of some parameters, and added some comments. Created 4 years, 8 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/Element.h" 7 #include "core/dom/Element.h"
8 #include "core/dom/Range.h" 8 #include "core/dom/Range.h"
9 #include "core/editing/FrameSelection.h" 9 #include "core/editing/FrameSelection.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 insertHTMLElement("<input id='sample' type='password' size='24'>", "samp le")); 183 insertHTMLElement("<input id='sample' type='password' size='24'>", "samp le"));
184 184
185 Vector<CompositionUnderline> underlines; 185 Vector<CompositionUnderline> underlines;
186 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 186 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
187 controller().setComposition("foo", underlines, 0, 3); 187 controller().setComposition("foo", underlines, 0, 3);
188 controller().confirmComposition(); 188 controller().confirmComposition();
189 189
190 EXPECT_STREQ("foo", input->value().utf8().data()); 190 EXPECT_STREQ("foo", input->value().utf8().data());
191 } 191 }
192 192
193 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithEmptyText)
194 {
195 HTMLInputElement* input = toHTMLInputElement(
196 insertHTMLElement("<input id='sample'>", "sample"));
197
198 input->setValue("");
199 EXPECT_STREQ("", input->value().utf8().data());
200 controller().deleteSurroundingText(0, 0);
201 EXPECT_STREQ("", input->value().utf8().data());
202
203 input->setValue("");
204 EXPECT_STREQ("", input->value().utf8().data());
205 controller().deleteSurroundingText(1, 0);
206 EXPECT_STREQ("", input->value().utf8().data());
207
208 input->setValue("");
209 EXPECT_STREQ("", input->value().utf8().data());
210 controller().deleteSurroundingText(0, 1);
211 EXPECT_STREQ("", input->value().utf8().data());
212 }
213
214 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithRangeSelection)
215 {
216 HTMLInputElement* input = toHTMLInputElement(
217 insertHTMLElement("<input id='sample'>", "sample"));
218
219 input->setValue("hello");
220 EXPECT_STREQ("hello", input->value().utf8().data());
221 controller().setEditableSelectionOffsets(PlainTextRange(1, 4));
222 controller().deleteSurroundingText(0, 0);
223 EXPECT_STREQ("hello", input->value().utf8().data());
224
225 input->setValue("hello");
226 EXPECT_STREQ("hello", input->value().utf8().data());
227 controller().setEditableSelectionOffsets(PlainTextRange(1, 4));
228 controller().deleteSurroundingText(1, 1);
229 EXPECT_STREQ("ell", input->value().utf8().data());
230
231 input->setValue("hello");
232 EXPECT_STREQ("hello", input->value().utf8().data());
233 controller().setEditableSelectionOffsets(PlainTextRange(1, 4));
234 controller().deleteSurroundingText(100, 0);
235 EXPECT_STREQ("ello", input->value().utf8().data());
236
237 input->setValue("hello");
238 EXPECT_STREQ("hello", input->value().utf8().data());
239 controller().setEditableSelectionOffsets(PlainTextRange(1, 4));
240 controller().deleteSurroundingText(0, 100);
241 EXPECT_STREQ("hell", input->value().utf8().data());
242 }
243
244 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithCursorSelection)
245 {
246 HTMLInputElement* input = toHTMLInputElement(
247 insertHTMLElement("<input id='sample'>", "sample"));
248
249 input->setValue("hello");
250 EXPECT_STREQ("hello", input->value().utf8().data());
251 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
252 controller().deleteSurroundingText(0, 0);
253 EXPECT_STREQ("hello", input->value().utf8().data());
254
255 input->setValue("hello");
256 EXPECT_STREQ("hello", input->value().utf8().data());
257 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
258 controller().deleteSurroundingText(1, 1);
259 EXPECT_STREQ("hlo", input->value().utf8().data());
260
261 input->setValue("hello");
262 EXPECT_STREQ("hello", input->value().utf8().data());
263 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
264 controller().deleteSurroundingText(100, 0);
265 EXPECT_STREQ("llo", input->value().utf8().data());
266
267 input->setValue("hello");
268 EXPECT_STREQ("hello", input->value().utf8().data());
269 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
270 controller().deleteSurroundingText(0, 100);
271 EXPECT_STREQ("he", input->value().utf8().data());
272 }
273
274 TEST_F(InputMethodControllerTest, DeleteSurroundingTextForMultiCodeWord)
275 {
276 HTMLInputElement* input = toHTMLInputElement(
277 insertHTMLElement("<input id='sample'>", "sample"));
278
279 input->setValue(String::fromUTF8("foo\xE2\x98\x85")); // U+2605 == "black st ar"
280 controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
281 EXPECT_STREQ("foo\xE2\x98\x85", input->value().utf8().data());
282 controller().deleteSurroundingText(1, 0);
283 EXPECT_STREQ("foo", input->value().utf8().data());
284
285 input->setValue(String::fromUTF8("foo\xF0\x9F\x8F\x86")); // U+1F3C6 == "tro phy"
286 controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
287 EXPECT_STREQ("foo\xF0\x9F\x8F\x86", input->value().utf8().data());
288 controller().deleteSurroundingText(1, 0);
289 EXPECT_STREQ("foo", input->value().utf8().data());
290
291 input->setValue(String::fromUTF8("foo\xE0\xB8\x81\xE0\xB9\x89")); // compose d U+0E01 "ka kai" + U+0E49 "mai tho"
292 controller().setEditableSelectionOffsets(PlainTextRange(4, 4));
293 EXPECT_STREQ("foo\xE0\xB8\x81\xE0\xB9\x89", input->value().utf8().data());
294 controller().deleteSurroundingText(1, 0);
295 EXPECT_STREQ("foo", input->value().utf8().data());
296
297 input->setValue(String::fromUTF8("\xE2\x98\x85 foo")); // U+2605 == "black s tar"
298 controller().setEditableSelectionOffsets(PlainTextRange(0, 0));
299 EXPECT_STREQ("\xE2\x98\x85 foo", input->value().utf8().data());
300 controller().deleteSurroundingText(0, 1);
301 EXPECT_STREQ(" foo", input->value().utf8().data());
302
303 input->setValue(String::fromUTF8("\xF0\x9F\x8F\x86 foo")); // U+1F3C6 == "tr ophy"
304 controller().setEditableSelectionOffsets(PlainTextRange(0, 0));
305 EXPECT_STREQ("\xF0\x9F\x8F\x86 foo", input->value().utf8().data());
306 controller().deleteSurroundingText(0, 1);
307 EXPECT_STREQ(" foo", input->value().utf8().data());
308
309 input->setValue(String::fromUTF8("\xE0\xB8\x81\xE0\xB9\x89 foo")); // compos ed U+0E01 "ka kai" + U+0E49 "mai tho"
310 controller().setEditableSelectionOffsets(PlainTextRange(0, 0));
311 EXPECT_STREQ("\xE0\xB8\x81\xE0\xB9\x89 foo", input->value().utf8().data());
312 controller().deleteSurroundingText(0, 1);
313 EXPECT_STREQ(" foo", input->value().utf8().data());
314
315 input->setValue(String::fromUTF8("\xE2\x98\x85\xF0\x9F\x8F\x86\xE0\xB8\x81\x E0\xB9\x89")); // "black star" + "trophy" + "ka kai" & "mai tho"
316 controller().setEditableSelectionOffsets(PlainTextRange(1, 2));
317 EXPECT_STREQ("\xE2\x98\x85\xF0\x9F\x8F\x86\xE0\xB8\x81\xE0\xB9\x89", input-> value().utf8().data());
318 controller().deleteSurroundingText(1, 1);
319 EXPECT_STREQ("\xF0\x9F\x8F\x86", input->value().utf8().data());
320 }
321
193 } // namespace blink 322 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698