OLD | NEW |
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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 EXPECT_STREQ("fooX", input->value().utf8().data()); | 164 EXPECT_STREQ("fooX", input->value().utf8().data()); |
165 controller().extendSelectionAndDelete(0, 1); | 165 controller().extendSelectionAndDelete(0, 1); |
166 EXPECT_STREQ("fooX", input->value().utf8().data()); | 166 EXPECT_STREQ("fooX", input->value().utf8().data()); |
167 } | 167 } |
168 | 168 |
169 TEST_F(InputMethodControllerTest, SetCompositionFromExistingText) { | 169 TEST_F(InputMethodControllerTest, SetCompositionFromExistingText) { |
170 Element* div = insertHTMLElement( | 170 Element* div = insertHTMLElement( |
171 "<div id='sample' contenteditable>hello world</div>", "sample"); | 171 "<div id='sample' contenteditable>hello world</div>", "sample"); |
172 | 172 |
173 Vector<CompositionUnderline> underlines; | 173 Vector<CompositionUnderline> underlines; |
174 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 174 underlines.push_back( |
| 175 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
175 controller().setCompositionFromExistingText(underlines, 0, 5); | 176 controller().setCompositionFromExistingText(underlines, 0, 5); |
176 | 177 |
177 Range* range = controller().compositionRange(); | 178 Range* range = controller().compositionRange(); |
178 EXPECT_EQ(0, range->startOffset()); | 179 EXPECT_EQ(0, range->startOffset()); |
179 EXPECT_EQ(5, range->endOffset()); | 180 EXPECT_EQ(5, range->endOffset()); |
180 | 181 |
181 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); | 182 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); |
182 EXPECT_EQ(0u, plainTextRange.start()); | 183 EXPECT_EQ(0u, plainTextRange.start()); |
183 EXPECT_EQ(5u, plainTextRange.end()); | 184 EXPECT_EQ(5u, plainTextRange.end()); |
184 } | 185 } |
185 | 186 |
186 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) { | 187 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) { |
187 Element* div = insertHTMLElement( | 188 Element* div = insertHTMLElement( |
188 "<div id='sample' " | 189 "<div id='sample' " |
189 "contenteditable>abc1<b>2</b>34567<b>8</b>9d<b>e</b>f</div>", | 190 "contenteditable>abc1<b>2</b>34567<b>8</b>9d<b>e</b>f</div>", |
190 "sample"); | 191 "sample"); |
191 | 192 |
192 Vector<CompositionUnderline> underlines; | 193 Vector<CompositionUnderline> underlines; |
193 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); | 194 underlines.push_back( |
| 195 CompositionUnderline(3, 12, Color(255, 0, 0), false, 0, false)); |
194 controller().setCompositionFromExistingText(underlines, 3, 12); | 196 controller().setCompositionFromExistingText(underlines, 3, 12); |
195 | 197 |
196 // Subtract a character. | 198 // Subtract a character. |
197 controller().setComposition(String("12345789"), underlines, 8, 8); | 199 controller().setComposition(String("12345789"), underlines, 8, 8); |
198 EXPECT_STREQ("abc1<b>2</b>3457<b>8</b>9d<b>e</b>f", | 200 EXPECT_STREQ("abc1<b>2</b>3457<b>8</b>9d<b>e</b>f", |
199 div->innerHTML().utf8().data()); | 201 div->innerHTML().utf8().data()); |
200 EXPECT_EQ(11u, controller().getSelectionOffsets().start()); | 202 EXPECT_EQ(11u, controller().getSelectionOffsets().start()); |
201 EXPECT_EQ(11u, controller().getSelectionOffsets().end()); | 203 EXPECT_EQ(11u, controller().getSelectionOffsets().end()); |
202 | 204 |
203 // Append a character. | 205 // Append a character. |
204 controller().setComposition(String("123456789"), underlines, 9, 9); | 206 controller().setComposition(String("123456789"), underlines, 9, 9); |
205 EXPECT_STREQ("abc1<b>2</b>34567<b>8</b>9d<b>e</b>f", | 207 EXPECT_STREQ("abc1<b>2</b>34567<b>8</b>9d<b>e</b>f", |
206 div->innerHTML().utf8().data()); | 208 div->innerHTML().utf8().data()); |
207 EXPECT_EQ(12u, controller().getSelectionOffsets().start()); | 209 EXPECT_EQ(12u, controller().getSelectionOffsets().start()); |
208 EXPECT_EQ(12u, controller().getSelectionOffsets().end()); | 210 EXPECT_EQ(12u, controller().getSelectionOffsets().end()); |
209 | 211 |
210 // Subtract and append characters. | 212 // Subtract and append characters. |
211 controller().setComposition(String("123hello789"), underlines, 11, 11); | 213 controller().setComposition(String("123hello789"), underlines, 11, 11); |
212 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9d<b>e</b>f", | 214 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9d<b>e</b>f", |
213 div->innerHTML().utf8().data()); | 215 div->innerHTML().utf8().data()); |
214 } | 216 } |
215 | 217 |
216 TEST_F(InputMethodControllerTest, SetCompositionWithEmojiKeepingStyle) { | 218 TEST_F(InputMethodControllerTest, SetCompositionWithEmojiKeepingStyle) { |
217 // U+1F3E0 = 0xF0 0x9F 0x8F 0xA0 (UTF8). It's an emoji character. | 219 // U+1F3E0 = 0xF0 0x9F 0x8F 0xA0 (UTF8). It's an emoji character. |
218 Element* div = insertHTMLElement( | 220 Element* div = insertHTMLElement( |
219 "<div id='sample' contenteditable><b>🏠</b></div>", "sample"); | 221 "<div id='sample' contenteditable><b>🏠</b></div>", "sample"); |
220 | 222 |
221 Vector<CompositionUnderline> underlines; | 223 Vector<CompositionUnderline> underlines; |
222 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 224 underlines.push_back( |
| 225 CompositionUnderline(0, 2, Color(255, 0, 0), false, 0, false)); |
223 | 226 |
224 controller().setCompositionFromExistingText(underlines, 0, 2); | 227 controller().setCompositionFromExistingText(underlines, 0, 2); |
225 | 228 |
226 // 0xF0 0x9F 0x8F 0xAB is also an emoji character, with the same leading | 229 // 0xF0 0x9F 0x8F 0xAB is also an emoji character, with the same leading |
227 // surrogate pair to the previous one. | 230 // surrogate pair to the previous one. |
228 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xAB"), underlines, | 231 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xAB"), underlines, |
229 2, 2); | 232 2, 2); |
230 EXPECT_STREQ("<b>\xF0\x9F\x8F\xAB</b>", div->innerHTML().utf8().data()); | 233 EXPECT_STREQ("<b>\xF0\x9F\x8F\xAB</b>", div->innerHTML().utf8().data()); |
231 | 234 |
232 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xA0"), underlines, | 235 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xA0"), underlines, |
233 2, 2); | 236 2, 2); |
234 EXPECT_STREQ("<b>\xF0\x9F\x8F\xA0</b>", div->innerHTML().utf8().data()); | 237 EXPECT_STREQ("<b>\xF0\x9F\x8F\xA0</b>", div->innerHTML().utf8().data()); |
235 } | 238 } |
236 | 239 |
237 TEST_F(InputMethodControllerTest, | 240 TEST_F(InputMethodControllerTest, |
238 SetCompositionWithTeluguSignVisargaKeepingStyle) { | 241 SetCompositionWithTeluguSignVisargaKeepingStyle) { |
239 // U+0C03 = 0xE0 0xB0 0x83 (UTF8), a telugu sign visarga with one code point. | 242 // U+0C03 = 0xE0 0xB0 0x83 (UTF8), a telugu sign visarga with one code point. |
240 // It's one grapheme cluster if separated. It can also form one grapheme | 243 // It's one grapheme cluster if separated. It can also form one grapheme |
241 // cluster with another code point(e.g, itself). | 244 // cluster with another code point(e.g, itself). |
242 Element* div = insertHTMLElement( | 245 Element* div = insertHTMLElement( |
243 "<div id='sample' contenteditable><b>ః</b></div>", "sample"); | 246 "<div id='sample' contenteditable><b>ః</b></div>", "sample"); |
244 | 247 |
245 Vector<CompositionUnderline> underlines; | 248 Vector<CompositionUnderline> underlines; |
246 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 249 underlines.push_back( |
| 250 CompositionUnderline(0, 2, Color(255, 0, 0), false, 0, false)); |
247 controller().setCompositionFromExistingText(underlines, 0, 1); | 251 controller().setCompositionFromExistingText(underlines, 0, 1); |
248 | 252 |
249 // 0xE0 0xB0 0x83 0xE0 0xB0 0x83, a telugu character with 2 code points in | 253 // 0xE0 0xB0 0x83 0xE0 0xB0 0x83, a telugu character with 2 code points in |
250 // 1 grapheme cluster. | 254 // 1 grapheme cluster. |
251 controller().setComposition(String::fromUTF8("\xE0\xB0\x83\xE0\xB0\x83"), | 255 controller().setComposition(String::fromUTF8("\xE0\xB0\x83\xE0\xB0\x83"), |
252 underlines, 2, 2); | 256 underlines, 2, 2); |
253 EXPECT_STREQ("<b>\xE0\xB0\x83\xE0\xB0\x83</b>", | 257 EXPECT_STREQ("<b>\xE0\xB0\x83\xE0\xB0\x83</b>", |
254 div->innerHTML().utf8().data()); | 258 div->innerHTML().utf8().data()); |
255 | 259 |
256 controller().setComposition(String::fromUTF8("\xE0\xB0\x83"), underlines, 1, | 260 controller().setComposition(String::fromUTF8("\xE0\xB0\x83"), underlines, 1, |
257 1); | 261 1); |
258 EXPECT_STREQ("<b>\xE0\xB0\x83</b>", div->innerHTML().utf8().data()); | 262 EXPECT_STREQ("<b>\xE0\xB0\x83</b>", div->innerHTML().utf8().data()); |
259 } | 263 } |
260 | 264 |
261 TEST_F(InputMethodControllerTest, FinishComposingTextKeepingStyle) { | 265 TEST_F(InputMethodControllerTest, FinishComposingTextKeepingStyle) { |
262 Element* div = insertHTMLElement( | 266 Element* div = insertHTMLElement( |
263 "<div id='sample' " | 267 "<div id='sample' " |
264 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>", | 268 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>", |
265 "sample"); | 269 "sample"); |
266 | 270 |
267 Vector<CompositionUnderline> underlines; | 271 Vector<CompositionUnderline> underlines; |
268 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); | 272 underlines.push_back( |
| 273 CompositionUnderline(3, 12, Color(255, 0, 0), false, 0, false)); |
269 controller().setCompositionFromExistingText(underlines, 3, 12); | 274 controller().setCompositionFromExistingText(underlines, 3, 12); |
270 | 275 |
271 controller().setComposition(String("123hello789"), underlines, 11, 11); | 276 controller().setComposition(String("123hello789"), underlines, 11, 11); |
272 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9", div->innerHTML().utf8().data()); | 277 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9", div->innerHTML().utf8().data()); |
273 | 278 |
274 controller().finishComposingText(InputMethodController::KeepSelection); | 279 controller().finishComposingText(InputMethodController::KeepSelection); |
275 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9", div->innerHTML().utf8().data()); | 280 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9", div->innerHTML().utf8().data()); |
276 } | 281 } |
277 | 282 |
278 TEST_F(InputMethodControllerTest, CommitTextKeepingStyle) { | 283 TEST_F(InputMethodControllerTest, CommitTextKeepingStyle) { |
279 Element* div = insertHTMLElement( | 284 Element* div = insertHTMLElement( |
280 "<div id='sample' " | 285 "<div id='sample' " |
281 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>", | 286 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>", |
282 "sample"); | 287 "sample"); |
283 | 288 |
284 Vector<CompositionUnderline> underlines; | 289 Vector<CompositionUnderline> underlines; |
285 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); | 290 underlines.push_back( |
| 291 CompositionUnderline(3, 12, Color(255, 0, 0), false, 0, false)); |
286 controller().setCompositionFromExistingText(underlines, 3, 12); | 292 controller().setCompositionFromExistingText(underlines, 3, 12); |
287 | 293 |
288 controller().commitText(String("123789"), underlines, 0); | 294 controller().commitText(String("123789"), underlines, 0); |
289 EXPECT_STREQ("abc1<b>2</b>37<b>8</b>9", div->innerHTML().utf8().data()); | 295 EXPECT_STREQ("abc1<b>2</b>37<b>8</b>9", div->innerHTML().utf8().data()); |
290 } | 296 } |
291 | 297 |
292 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { | 298 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { |
293 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", | 299 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", |
294 "sample"); | 300 "sample"); |
295 | 301 |
296 Vector<CompositionUnderline> underlines; | 302 Vector<CompositionUnderline> underlines; |
297 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 303 underlines.push_back( |
| 304 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
298 controller().setCompositionFromExistingText(underlines, 0, 5); | 305 controller().setCompositionFromExistingText(underlines, 0, 5); |
299 | 306 |
300 controller().finishComposingText(InputMethodController::KeepSelection); | 307 controller().finishComposingText(InputMethodController::KeepSelection); |
301 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); | 308 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); |
302 EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode()); | 309 EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode()); |
303 } | 310 } |
304 | 311 |
305 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition) { | 312 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition) { |
306 HTMLInputElement* input = | 313 HTMLInputElement* input = |
307 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); | 314 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); |
308 | 315 |
309 input->setValue("foo "); | 316 input->setValue("foo "); |
310 document().updateStyleAndLayout(); | 317 document().updateStyleAndLayout(); |
311 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 318 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
312 EXPECT_STREQ("foo ", input->value().utf8().data()); | 319 EXPECT_STREQ("foo ", input->value().utf8().data()); |
313 controller().extendSelectionAndDelete(0, 0); | 320 controller().extendSelectionAndDelete(0, 0); |
314 EXPECT_STREQ("foo ", input->value().utf8().data()); | 321 EXPECT_STREQ("foo ", input->value().utf8().data()); |
315 | 322 |
316 input->setValue("foo "); | 323 input->setValue("foo "); |
317 document().updateStyleAndLayout(); | 324 document().updateStyleAndLayout(); |
318 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 325 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
319 EXPECT_STREQ("foo ", input->value().utf8().data()); | 326 EXPECT_STREQ("foo ", input->value().utf8().data()); |
320 controller().extendSelectionAndDelete(1, 0); | 327 controller().extendSelectionAndDelete(1, 0); |
321 EXPECT_STREQ("foo", input->value().utf8().data()); | 328 EXPECT_STREQ("foo", input->value().utf8().data()); |
322 | 329 |
323 Vector<CompositionUnderline> underlines; | 330 Vector<CompositionUnderline> underlines; |
324 underlines.push_back(CompositionUnderline(0, 3, Color(255, 0, 0), false, 0)); | 331 underlines.push_back( |
| 332 CompositionUnderline(0, 3, Color(255, 0, 0), false, 0, false)); |
325 controller().setCompositionFromExistingText(underlines, 0, 3); | 333 controller().setCompositionFromExistingText(underlines, 0, 3); |
326 | 334 |
327 controller().setComposition(String(""), underlines, 0, 3); | 335 controller().setComposition(String(""), underlines, 0, 3); |
328 | 336 |
329 EXPECT_STREQ("", input->value().utf8().data()); | 337 EXPECT_STREQ("", input->value().utf8().data()); |
330 } | 338 } |
331 | 339 |
332 TEST_F(InputMethodControllerTest, | 340 TEST_F(InputMethodControllerTest, |
333 SetCompositionFromExistingTextWithCollapsedWhiteSpace) { | 341 SetCompositionFromExistingTextWithCollapsedWhiteSpace) { |
334 // Creates a div with one leading new line char. The new line char is hidden | 342 // Creates a div with one leading new line char. The new line char is hidden |
335 // from the user and IME, but is visible to InputMethodController. | 343 // from the user and IME, but is visible to InputMethodController. |
336 Element* div = insertHTMLElement( | 344 Element* div = insertHTMLElement( |
337 "<div id='sample' contenteditable>\nhello world</div>", "sample"); | 345 "<div id='sample' contenteditable>\nhello world</div>", "sample"); |
338 | 346 |
339 Vector<CompositionUnderline> underlines; | 347 Vector<CompositionUnderline> underlines; |
340 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 348 underlines.push_back( |
| 349 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
341 controller().setCompositionFromExistingText(underlines, 0, 5); | 350 controller().setCompositionFromExistingText(underlines, 0, 5); |
342 | 351 |
343 Range* range = controller().compositionRange(); | 352 Range* range = controller().compositionRange(); |
344 EXPECT_EQ(1, range->startOffset()); | 353 EXPECT_EQ(1, range->startOffset()); |
345 EXPECT_EQ(6, range->endOffset()); | 354 EXPECT_EQ(6, range->endOffset()); |
346 | 355 |
347 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); | 356 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); |
348 EXPECT_EQ(0u, plainTextRange.start()); | 357 EXPECT_EQ(0u, plainTextRange.start()); |
349 EXPECT_EQ(5u, plainTextRange.end()); | 358 EXPECT_EQ(5u, plainTextRange.end()); |
350 } | 359 } |
351 | 360 |
352 TEST_F(InputMethodControllerTest, | 361 TEST_F(InputMethodControllerTest, |
353 SetCompositionFromExistingTextWithInvalidOffsets) { | 362 SetCompositionFromExistingTextWithInvalidOffsets) { |
354 insertHTMLElement("<div id='sample' contenteditable>test</div>", "sample"); | 363 insertHTMLElement("<div id='sample' contenteditable>test</div>", "sample"); |
355 | 364 |
356 Vector<CompositionUnderline> underlines; | 365 Vector<CompositionUnderline> underlines; |
357 underlines.push_back(CompositionUnderline(7, 8, Color(255, 0, 0), false, 0)); | 366 underlines.push_back( |
| 367 CompositionUnderline(7, 8, Color(255, 0, 0), false, 0, false)); |
358 controller().setCompositionFromExistingText(underlines, 7, 8); | 368 controller().setCompositionFromExistingText(underlines, 7, 8); |
359 | 369 |
360 EXPECT_FALSE(controller().compositionRange()); | 370 EXPECT_FALSE(controller().compositionRange()); |
361 } | 371 } |
362 | 372 |
363 TEST_F(InputMethodControllerTest, ConfirmPasswordComposition) { | 373 TEST_F(InputMethodControllerTest, ConfirmPasswordComposition) { |
364 HTMLInputElement* input = toHTMLInputElement(insertHTMLElement( | 374 HTMLInputElement* input = toHTMLInputElement(insertHTMLElement( |
365 "<input id='sample' type='password' size='24'>", "sample")); | 375 "<input id='sample' type='password' size='24'>", "sample")); |
366 | 376 |
367 Vector<CompositionUnderline> underlines; | 377 Vector<CompositionUnderline> underlines; |
368 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 378 underlines.push_back( |
| 379 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
369 controller().setComposition("foo", underlines, 0, 3); | 380 controller().setComposition("foo", underlines, 0, 3); |
370 controller().finishComposingText(InputMethodController::KeepSelection); | 381 controller().finishComposingText(InputMethodController::KeepSelection); |
371 | 382 |
372 EXPECT_STREQ("foo", input->value().utf8().data()); | 383 EXPECT_STREQ("foo", input->value().utf8().data()); |
373 } | 384 } |
374 | 385 |
375 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithEmptyText) { | 386 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithEmptyText) { |
376 HTMLInputElement* input = | 387 HTMLInputElement* input = |
377 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); | 388 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); |
378 | 389 |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); | 703 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); |
693 | 704 |
694 input->setValue("hello"); | 705 input->setValue("hello"); |
695 document().updateStyleAndLayout(); | 706 document().updateStyleAndLayout(); |
696 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | 707 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); |
697 EXPECT_STREQ("hello", input->value().utf8().data()); | 708 EXPECT_STREQ("hello", input->value().utf8().data()); |
698 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); | 709 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); |
699 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); | 710 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); |
700 | 711 |
701 Vector<CompositionUnderline> underlines; | 712 Vector<CompositionUnderline> underlines; |
702 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 713 underlines.push_back( |
| 714 CompositionUnderline(0, 2, Color(255, 0, 0), false, 0, false)); |
703 | 715 |
704 // The caret exceeds left boundary. | 716 // The caret exceeds left boundary. |
705 // "*heABllo", where * stands for caret. | 717 // "*heABllo", where * stands for caret. |
706 controller().setComposition("AB", underlines, -100, -100); | 718 controller().setComposition("AB", underlines, -100, -100); |
707 EXPECT_STREQ("heABllo", input->value().utf8().data()); | 719 EXPECT_STREQ("heABllo", input->value().utf8().data()); |
708 EXPECT_EQ(0u, controller().getSelectionOffsets().start()); | 720 EXPECT_EQ(0u, controller().getSelectionOffsets().start()); |
709 EXPECT_EQ(0u, controller().getSelectionOffsets().end()); | 721 EXPECT_EQ(0u, controller().getSelectionOffsets().end()); |
710 | 722 |
711 // The caret is on left boundary. | 723 // The caret is on left boundary. |
712 // "*heABllo". | 724 // "*heABllo". |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 "</div>" | 768 "</div>" |
757 "</div>", | 769 "</div>", |
758 "sample"); | 770 "sample"); |
759 | 771 |
760 controller().setEditableSelectionOffsets(PlainTextRange(17, 17)); | 772 controller().setEditableSelectionOffsets(PlainTextRange(17, 17)); |
761 EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data()); | 773 EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data()); |
762 EXPECT_EQ(17u, controller().getSelectionOffsets().start()); | 774 EXPECT_EQ(17u, controller().getSelectionOffsets().start()); |
763 EXPECT_EQ(17u, controller().getSelectionOffsets().end()); | 775 EXPECT_EQ(17u, controller().getSelectionOffsets().end()); |
764 | 776 |
765 Vector<CompositionUnderline> underlines; | 777 Vector<CompositionUnderline> underlines; |
766 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 778 underlines.push_back( |
| 779 CompositionUnderline(0, 2, Color(255, 0, 0), false, 0, false)); |
767 | 780 |
768 // The caret exceeds left boundary. | 781 // The caret exceeds left boundary. |
769 // "*hello\nworld\n01234AB56789", where * stands for caret. | 782 // "*hello\nworld\n01234AB56789", where * stands for caret. |
770 controller().setComposition("AB", underlines, -100, -100); | 783 controller().setComposition("AB", underlines, -100, -100); |
771 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data()); | 784 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data()); |
772 EXPECT_EQ(0u, controller().getSelectionOffsets().start()); | 785 EXPECT_EQ(0u, controller().getSelectionOffsets().start()); |
773 EXPECT_EQ(0u, controller().getSelectionOffsets().end()); | 786 EXPECT_EQ(0u, controller().getSelectionOffsets().end()); |
774 | 787 |
775 // The caret is on left boundary. | 788 // The caret is on left boundary. |
776 // "*hello\nworld\n01234AB56789". | 789 // "*hello\nworld\n01234AB56789". |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 TEST_F(InputMethodControllerTest, SetCompositionWithEmptyText) { | 859 TEST_F(InputMethodControllerTest, SetCompositionWithEmptyText) { |
847 Element* div = insertHTMLElement( | 860 Element* div = insertHTMLElement( |
848 "<div id='sample' contenteditable>hello</div>", "sample"); | 861 "<div id='sample' contenteditable>hello</div>", "sample"); |
849 | 862 |
850 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | 863 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); |
851 EXPECT_STREQ("hello", div->innerText().utf8().data()); | 864 EXPECT_STREQ("hello", div->innerText().utf8().data()); |
852 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); | 865 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); |
853 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); | 866 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); |
854 | 867 |
855 Vector<CompositionUnderline> underlines0; | 868 Vector<CompositionUnderline> underlines0; |
856 underlines0.push_back(CompositionUnderline(0, 0, Color(255, 0, 0), false, 0)); | 869 underlines0.push_back( |
| 870 CompositionUnderline(0, 0, Color(255, 0, 0), false, 0, false)); |
857 Vector<CompositionUnderline> underlines2; | 871 Vector<CompositionUnderline> underlines2; |
858 underlines2.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 872 underlines2.push_back( |
| 873 CompositionUnderline(0, 2, Color(255, 0, 0), false, 0, false)); |
859 | 874 |
860 controller().setComposition("AB", underlines2, 2, 2); | 875 controller().setComposition("AB", underlines2, 2, 2); |
861 // With previous composition. | 876 // With previous composition. |
862 controller().setComposition("", underlines0, 2, 2); | 877 controller().setComposition("", underlines0, 2, 2); |
863 EXPECT_STREQ("hello", div->innerText().utf8().data()); | 878 EXPECT_STREQ("hello", div->innerText().utf8().data()); |
864 EXPECT_EQ(4u, controller().getSelectionOffsets().start()); | 879 EXPECT_EQ(4u, controller().getSelectionOffsets().start()); |
865 EXPECT_EQ(4u, controller().getSelectionOffsets().end()); | 880 EXPECT_EQ(4u, controller().getSelectionOffsets().end()); |
866 | 881 |
867 // Without previous composition. | 882 // Without previous composition. |
868 controller().setComposition("", underlines0, -1, -1); | 883 controller().setComposition("", underlines0, -1, -1); |
869 EXPECT_STREQ("hello", div->innerText().utf8().data()); | 884 EXPECT_STREQ("hello", div->innerText().utf8().data()); |
870 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 885 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
871 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); | 886 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
872 } | 887 } |
873 | 888 |
874 TEST_F(InputMethodControllerTest, InsertLineBreakWhileComposingText) { | 889 TEST_F(InputMethodControllerTest, InsertLineBreakWhileComposingText) { |
875 Element* div = | 890 Element* div = |
876 insertHTMLElement("<div id='sample' contenteditable></div>", "sample"); | 891 insertHTMLElement("<div id='sample' contenteditable></div>", "sample"); |
877 | 892 |
878 Vector<CompositionUnderline> underlines; | 893 Vector<CompositionUnderline> underlines; |
879 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 894 underlines.push_back( |
| 895 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
880 controller().setComposition("hello", underlines, 5, 5); | 896 controller().setComposition("hello", underlines, 5, 5); |
881 EXPECT_STREQ("hello", div->innerText().utf8().data()); | 897 EXPECT_STREQ("hello", div->innerText().utf8().data()); |
882 EXPECT_EQ(5u, controller().getSelectionOffsets().start()); | 898 EXPECT_EQ(5u, controller().getSelectionOffsets().start()); |
883 EXPECT_EQ(5u, controller().getSelectionOffsets().end()); | 899 EXPECT_EQ(5u, controller().getSelectionOffsets().end()); |
884 | 900 |
885 frame().editor().insertLineBreak(); | 901 frame().editor().insertLineBreak(); |
886 EXPECT_STREQ("\n\n", div->innerText().utf8().data()); | 902 EXPECT_STREQ("\n\n", div->innerText().utf8().data()); |
887 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); | 903 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); |
888 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); | 904 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); |
889 } | 905 } |
890 | 906 |
891 TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText) { | 907 TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText) { |
892 Element* div = | 908 Element* div = |
893 insertHTMLElement("<div id='sample' contenteditable></div>", "sample"); | 909 insertHTMLElement("<div id='sample' contenteditable></div>", "sample"); |
894 | 910 |
895 Vector<CompositionUnderline> underlines; | 911 Vector<CompositionUnderline> underlines; |
896 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 912 underlines.append( |
| 913 CompositionUnderline(0, 2, Color(255, 0, 0), false, 0, false)); |
897 controller().commitText("hello", underlines, 0); | 914 controller().commitText("hello", underlines, 0); |
898 EXPECT_STREQ("hello", div->innerText().utf8().data()); | 915 EXPECT_STREQ("hello", div->innerText().utf8().data()); |
899 | 916 |
900 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | 917 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); |
901 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); | 918 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); |
902 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); | 919 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); |
903 | 920 |
904 frame().editor().insertLineBreak(); | 921 frame().editor().insertLineBreak(); |
905 EXPECT_STREQ("he\nllo", div->innerText().utf8().data()); | 922 EXPECT_STREQ("he\nllo", div->innerText().utf8().data()); |
906 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 923 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
(...skipping 10 matching lines...) Expand all Loading... |
917 " event => document.title = " | 934 " event => document.title = " |
918 " `beforeinput.isComposing:${event.isComposing};`);" | 935 " `beforeinput.isComposing:${event.isComposing};`);" |
919 "document.getElementById('sample').addEventListener('input', " | 936 "document.getElementById('sample').addEventListener('input', " |
920 " event => document.title += " | 937 " event => document.title += " |
921 " `input.isComposing:${event.isComposing};`);"); | 938 " `input.isComposing:${event.isComposing};`);"); |
922 document().body()->appendChild(script); | 939 document().body()->appendChild(script); |
923 document().view()->updateAllLifecyclePhases(); | 940 document().view()->updateAllLifecyclePhases(); |
924 | 941 |
925 // Simulate composition in the |contentEditable|. | 942 // Simulate composition in the |contentEditable|. |
926 Vector<CompositionUnderline> underlines; | 943 Vector<CompositionUnderline> underlines; |
927 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 944 underlines.push_back( |
| 945 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
928 editable->focus(); | 946 editable->focus(); |
929 | 947 |
930 document().setTitle(emptyString()); | 948 document().setTitle(emptyString()); |
931 controller().setComposition("foo", underlines, 0, 3); | 949 controller().setComposition("foo", underlines, 0, 3); |
932 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", | 950 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", |
933 document().title().utf8().data()); | 951 document().title().utf8().data()); |
934 | 952 |
935 document().setTitle(emptyString()); | 953 document().setTitle(emptyString()); |
936 controller().finishComposingText(InputMethodController::KeepSelection); | 954 controller().finishComposingText(InputMethodController::KeepSelection); |
937 // Last pair of InputEvent should also be inside composition scope. | 955 // Last pair of InputEvent should also be inside composition scope. |
938 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", | 956 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", |
939 document().title().utf8().data()); | 957 document().title().utf8().data()); |
940 } | 958 } |
941 | 959 |
942 TEST_F(InputMethodControllerTest, CompositionInputEventForReplace) { | 960 TEST_F(InputMethodControllerTest, CompositionInputEventForReplace) { |
943 createHTMLWithCompositionInputEventListeners(); | 961 createHTMLWithCompositionInputEventListeners(); |
944 | 962 |
945 // Simulate composition in the |contentEditable|. | 963 // Simulate composition in the |contentEditable|. |
946 Vector<CompositionUnderline> underlines; | 964 Vector<CompositionUnderline> underlines; |
947 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 965 underlines.push_back( |
| 966 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
948 | 967 |
949 document().setTitle(emptyString()); | 968 document().setTitle(emptyString()); |
950 controller().setComposition("hell", underlines, 4, 4); | 969 controller().setComposition("hell", underlines, 4, 4); |
951 EXPECT_STREQ("beforeinput.data:hell;input.data:hell;", | 970 EXPECT_STREQ("beforeinput.data:hell;input.data:hell;", |
952 document().title().utf8().data()); | 971 document().title().utf8().data()); |
953 | 972 |
954 // Replace the existing composition. | 973 // Replace the existing composition. |
955 document().setTitle(emptyString()); | 974 document().setTitle(emptyString()); |
956 controller().setComposition("hello", underlines, 0, 0); | 975 controller().setComposition("hello", underlines, 0, 0); |
957 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", | 976 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", |
958 document().title().utf8().data()); | 977 document().title().utf8().data()); |
959 } | 978 } |
960 | 979 |
961 TEST_F(InputMethodControllerTest, CompositionInputEventForConfirm) { | 980 TEST_F(InputMethodControllerTest, CompositionInputEventForConfirm) { |
962 createHTMLWithCompositionInputEventListeners(); | 981 createHTMLWithCompositionInputEventListeners(); |
963 | 982 |
964 // Simulate composition in the |contentEditable|. | 983 // Simulate composition in the |contentEditable|. |
965 Vector<CompositionUnderline> underlines; | 984 Vector<CompositionUnderline> underlines; |
966 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 985 underlines.push_back( |
| 986 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
967 | 987 |
968 document().setTitle(emptyString()); | 988 document().setTitle(emptyString()); |
969 controller().setComposition("hello", underlines, 5, 5); | 989 controller().setComposition("hello", underlines, 5, 5); |
970 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", | 990 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", |
971 document().title().utf8().data()); | 991 document().title().utf8().data()); |
972 | 992 |
973 // Confirm the ongoing composition. | 993 // Confirm the ongoing composition. |
974 document().setTitle(emptyString()); | 994 document().setTitle(emptyString()); |
975 controller().finishComposingText(InputMethodController::KeepSelection); | 995 controller().finishComposingText(InputMethodController::KeepSelection); |
976 EXPECT_STREQ( | 996 EXPECT_STREQ( |
977 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", | 997 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", |
978 document().title().utf8().data()); | 998 document().title().utf8().data()); |
979 } | 999 } |
980 | 1000 |
981 TEST_F(InputMethodControllerTest, CompositionInputEventForDelete) { | 1001 TEST_F(InputMethodControllerTest, CompositionInputEventForDelete) { |
982 createHTMLWithCompositionInputEventListeners(); | 1002 createHTMLWithCompositionInputEventListeners(); |
983 | 1003 |
984 // Simulate composition in the |contentEditable|. | 1004 // Simulate composition in the |contentEditable|. |
985 Vector<CompositionUnderline> underlines; | 1005 Vector<CompositionUnderline> underlines; |
986 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1006 underlines.push_back( |
| 1007 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
987 | 1008 |
988 document().setTitle(emptyString()); | 1009 document().setTitle(emptyString()); |
989 controller().setComposition("hello", underlines, 5, 5); | 1010 controller().setComposition("hello", underlines, 5, 5); |
990 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", | 1011 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", |
991 document().title().utf8().data()); | 1012 document().title().utf8().data()); |
992 | 1013 |
993 // Delete the existing composition. | 1014 // Delete the existing composition. |
994 document().setTitle(emptyString()); | 1015 document().setTitle(emptyString()); |
995 controller().setComposition("", underlines, 0, 0); | 1016 controller().setComposition("", underlines, 0, 0); |
996 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", | 1017 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", |
997 document().title().utf8().data()); | 1018 document().title().utf8().data()); |
998 } | 1019 } |
999 | 1020 |
1000 TEST_F(InputMethodControllerTest, CompositionInputEventForInsert) { | 1021 TEST_F(InputMethodControllerTest, CompositionInputEventForInsert) { |
1001 createHTMLWithCompositionInputEventListeners(); | 1022 createHTMLWithCompositionInputEventListeners(); |
1002 | 1023 |
1003 // Simulate composition in the |contentEditable|. | 1024 // Simulate composition in the |contentEditable|. |
1004 Vector<CompositionUnderline> underlines; | 1025 Vector<CompositionUnderline> underlines; |
1005 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1026 underlines.push_back( |
| 1027 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
1006 | 1028 |
1007 // Insert new text without previous composition. | 1029 // Insert new text without previous composition. |
1008 document().setTitle(emptyString()); | 1030 document().setTitle(emptyString()); |
1009 document().updateStyleAndLayout(); | 1031 document().updateStyleAndLayout(); |
1010 controller().commitText("hello", underlines, 0); | 1032 controller().commitText("hello", underlines, 0); |
1011 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", | 1033 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", |
1012 document().title().utf8().data()); | 1034 document().title().utf8().data()); |
1013 | 1035 |
1014 document().setTitle(emptyString()); | 1036 document().setTitle(emptyString()); |
1015 controller().setComposition("n", underlines, 1, 1); | 1037 controller().setComposition("n", underlines, 1, 1); |
1016 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | 1038 EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
1017 document().title().utf8().data()); | 1039 document().title().utf8().data()); |
1018 | 1040 |
1019 // Insert new text with previous composition. | 1041 // Insert new text with previous composition. |
1020 document().setTitle(emptyString()); | 1042 document().setTitle(emptyString()); |
1021 document().updateStyleAndLayout(); | 1043 document().updateStyleAndLayout(); |
1022 controller().commitText("hello", underlines, 1); | 1044 controller().commitText("hello", underlines, 1); |
1023 EXPECT_STREQ( | 1045 EXPECT_STREQ( |
1024 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", | 1046 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", |
1025 document().title().utf8().data()); | 1047 document().title().utf8().data()); |
1026 } | 1048 } |
1027 | 1049 |
1028 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) { | 1050 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) { |
1029 createHTMLWithCompositionInputEventListeners(); | 1051 createHTMLWithCompositionInputEventListeners(); |
1030 | 1052 |
1031 // Simulate composition in the |contentEditable|. | 1053 // Simulate composition in the |contentEditable|. |
1032 Vector<CompositionUnderline> underlines; | 1054 Vector<CompositionUnderline> underlines; |
1033 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1055 underlines.push_back( |
| 1056 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
1034 | 1057 |
1035 // Insert empty text without previous composition. | 1058 // Insert empty text without previous composition. |
1036 document().setTitle(emptyString()); | 1059 document().setTitle(emptyString()); |
1037 document().updateStyleAndLayout(); | 1060 document().updateStyleAndLayout(); |
1038 controller().commitText("", underlines, 0); | 1061 controller().commitText("", underlines, 0); |
1039 EXPECT_STREQ("", document().title().utf8().data()); | 1062 EXPECT_STREQ("", document().title().utf8().data()); |
1040 | 1063 |
1041 document().setTitle(emptyString()); | 1064 document().setTitle(emptyString()); |
1042 controller().setComposition("n", underlines, 1, 1); | 1065 controller().setComposition("n", underlines, 1, 1); |
1043 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | 1066 EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
1044 document().title().utf8().data()); | 1067 document().title().utf8().data()); |
1045 | 1068 |
1046 // Insert empty text with previous composition. | 1069 // Insert empty text with previous composition. |
1047 document().setTitle(emptyString()); | 1070 document().setTitle(emptyString()); |
1048 document().updateStyleAndLayout(); | 1071 document().updateStyleAndLayout(); |
1049 controller().commitText("", underlines, 1); | 1072 controller().commitText("", underlines, 1); |
1050 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", | 1073 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", |
1051 document().title().utf8().data()); | 1074 document().title().utf8().data()); |
1052 } | 1075 } |
1053 | 1076 |
1054 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) { | 1077 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) { |
1055 createHTMLWithCompositionEndEventListener(CaretSelection); | 1078 createHTMLWithCompositionEndEventListener(CaretSelection); |
1056 | 1079 |
1057 // Simulate composition in the |contentEditable|. | 1080 // Simulate composition in the |contentEditable|. |
1058 Vector<CompositionUnderline> underlines; | 1081 Vector<CompositionUnderline> underlines; |
1059 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1082 underlines.push_back( |
| 1083 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
1060 | 1084 |
1061 controller().setComposition("hello", underlines, 1, 1); | 1085 controller().setComposition("hello", underlines, 1, 1); |
1062 document().updateStyleAndLayout(); | 1086 document().updateStyleAndLayout(); |
1063 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); | 1087 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); |
1064 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); | 1088 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); |
1065 | 1089 |
1066 // Confirm the ongoing composition. Note that it moves the caret to the end of | 1090 // Confirm the ongoing composition. Note that it moves the caret to the end of |
1067 // text [5,5] before firing 'compositonend' event. | 1091 // text [5,5] before firing 'compositonend' event. |
1068 controller().finishComposingText(InputMethodController::DoNotKeepSelection); | 1092 controller().finishComposingText(InputMethodController::DoNotKeepSelection); |
1069 document().updateStyleAndLayout(); | 1093 document().updateStyleAndLayout(); |
1070 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 1094 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
1071 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); | 1095 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
1072 } | 1096 } |
1073 | 1097 |
1074 TEST_F(InputMethodControllerTest, CompositionEndEventForInsert) { | 1098 TEST_F(InputMethodControllerTest, CompositionEndEventForInsert) { |
1075 createHTMLWithCompositionEndEventListener(CaretSelection); | 1099 createHTMLWithCompositionEndEventListener(CaretSelection); |
1076 | 1100 |
1077 // Simulate composition in the |contentEditable|. | 1101 // Simulate composition in the |contentEditable|. |
1078 Vector<CompositionUnderline> underlines; | 1102 Vector<CompositionUnderline> underlines; |
1079 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1103 underlines.push_back( |
| 1104 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
1080 | 1105 |
1081 controller().setComposition("n", underlines, 1, 1); | 1106 controller().setComposition("n", underlines, 1, 1); |
1082 | 1107 |
1083 // Insert new text with previous composition. Note that it moves the caret to | 1108 // Insert new text with previous composition. Note that it moves the caret to |
1084 // [4,4] before firing 'compositonend' event. | 1109 // [4,4] before firing 'compositonend' event. |
1085 document().updateStyleAndLayout(); | 1110 document().updateStyleAndLayout(); |
1086 controller().commitText("hello", underlines, -1); | 1111 controller().commitText("hello", underlines, -1); |
1087 document().updateStyleAndLayout(); | 1112 document().updateStyleAndLayout(); |
1088 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 1113 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
1089 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); | 1114 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
1090 } | 1115 } |
1091 | 1116 |
1092 TEST_F(InputMethodControllerTest, CompositionEndEventWithRangeSelection) { | 1117 TEST_F(InputMethodControllerTest, CompositionEndEventWithRangeSelection) { |
1093 createHTMLWithCompositionEndEventListener(RangeSelection); | 1118 createHTMLWithCompositionEndEventListener(RangeSelection); |
1094 | 1119 |
1095 // Simulate composition in the |contentEditable|. | 1120 // Simulate composition in the |contentEditable|. |
1096 Vector<CompositionUnderline> underlines; | 1121 Vector<CompositionUnderline> underlines; |
1097 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1122 underlines.push_back( |
| 1123 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
1098 | 1124 |
1099 controller().setComposition("hello", underlines, 1, 1); | 1125 controller().setComposition("hello", underlines, 1, 1); |
1100 document().updateStyleAndLayout(); | 1126 document().updateStyleAndLayout(); |
1101 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); | 1127 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); |
1102 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); | 1128 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); |
1103 | 1129 |
1104 // Confirm the ongoing composition. Note that it moves the caret to the end of | 1130 // Confirm the ongoing composition. Note that it moves the caret to the end of |
1105 // text [5,5] before firing 'compositonend' event. | 1131 // text [5,5] before firing 'compositonend' event. |
1106 controller().finishComposingText(InputMethodController::DoNotKeepSelection); | 1132 controller().finishComposingText(InputMethodController::DoNotKeepSelection); |
1107 document().updateStyleAndLayout(); | 1133 document().updateStyleAndLayout(); |
1108 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); | 1134 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); |
1109 EXPECT_EQ(4u, controller().getSelectionOffsets().end()); | 1135 EXPECT_EQ(4u, controller().getSelectionOffsets().end()); |
1110 } | 1136 } |
1111 | 1137 |
1112 TEST_F(InputMethodControllerTest, CompositionEndEventWithNoSelection) { | 1138 TEST_F(InputMethodControllerTest, CompositionEndEventWithNoSelection) { |
1113 createHTMLWithCompositionEndEventListener(NoSelection); | 1139 createHTMLWithCompositionEndEventListener(NoSelection); |
1114 | 1140 |
1115 // Simulate composition in the |contentEditable|. | 1141 // Simulate composition in the |contentEditable|. |
1116 Vector<CompositionUnderline> underlines; | 1142 Vector<CompositionUnderline> underlines; |
1117 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1143 underlines.push_back( |
| 1144 CompositionUnderline(0, 5, Color(255, 0, 0), false, 0, false)); |
1118 | 1145 |
1119 controller().setComposition("hello", underlines, 1, 1); | 1146 controller().setComposition("hello", underlines, 1, 1); |
1120 document().updateStyleAndLayout(); | 1147 document().updateStyleAndLayout(); |
1121 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); | 1148 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); |
1122 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); | 1149 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); |
1123 | 1150 |
1124 // Confirm the ongoing composition. Note that it moves the caret to the end of | 1151 // Confirm the ongoing composition. Note that it moves the caret to the end of |
1125 // text [5,5] before firing 'compositonend' event. | 1152 // text [5,5] before firing 'compositonend' event. |
1126 controller().finishComposingText(InputMethodController::DoNotKeepSelection); | 1153 controller().finishComposingText(InputMethodController::DoNotKeepSelection); |
1127 document().updateStyleAndLayout(); | 1154 document().updateStyleAndLayout(); |
(...skipping 18 matching lines...) Expand all Loading... |
1146 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); | 1173 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); |
1147 | 1174 |
1148 controller().finishComposingText(InputMethodController::KeepSelection); | 1175 controller().finishComposingText(InputMethodController::KeepSelection); |
1149 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); | 1176 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); |
1150 } | 1177 } |
1151 | 1178 |
1152 TEST_F(InputMethodControllerTest, SetCompositionPlainTextWithUnderline) { | 1179 TEST_F(InputMethodControllerTest, SetCompositionPlainTextWithUnderline) { |
1153 insertHTMLElement("<div id='sample' contenteditable></div>", "sample"); | 1180 insertHTMLElement("<div id='sample' contenteditable></div>", "sample"); |
1154 | 1181 |
1155 Vector<CompositionUnderline> underlines; | 1182 Vector<CompositionUnderline> underlines; |
1156 underlines.push_back(CompositionUnderline(0, 1, Color(255, 0, 0), false, 0)); | 1183 underlines.push_back( |
| 1184 CompositionUnderline(0, 1, Color(255, 0, 0), false, 0, false)); |
1157 | 1185 |
1158 controller().setComposition(" ", underlines, 1, 1); | 1186 controller().setComposition(" ", underlines, 1, 1); |
1159 | 1187 |
1160 ASSERT_EQ(1u, document().markers().markers().size()); | 1188 ASSERT_EQ(1u, document().markers().markers().size()); |
1161 | 1189 |
1162 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset()); | 1190 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset()); |
1163 EXPECT_EQ(1u, document().markers().markers()[0]->endOffset()); | 1191 EXPECT_EQ(1u, document().markers().markers()[0]->endOffset()); |
1164 } | 1192 } |
1165 | 1193 |
1166 TEST_F(InputMethodControllerTest, CommitPlainTextWithUnderlineInsert) { | 1194 TEST_F(InputMethodControllerTest, CommitPlainTextWithUnderlineInsert) { |
1167 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>", | 1195 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>", |
1168 "sample"); | 1196 "sample"); |
1169 | 1197 |
1170 Vector<CompositionUnderline> underlines; | 1198 Vector<CompositionUnderline> underlines; |
1171 | 1199 |
1172 controller().setEditableSelectionOffsets(PlainTextRange(8, 8)); | 1200 controller().setEditableSelectionOffsets(PlainTextRange(8, 8)); |
1173 | 1201 |
1174 underlines.push_back(CompositionUnderline(1, 11, Color(255, 0, 0), false, 0)); | 1202 underlines.push_back( |
| 1203 CompositionUnderline(1, 11, Color(255, 0, 0), false, 0, false)); |
1175 | 1204 |
1176 controller().commitText(String("underlined"), underlines, 0); | 1205 controller().commitText(String("underlined"), underlines, 0); |
1177 | 1206 |
1178 ASSERT_EQ(1u, document().markers().markers().size()); | 1207 ASSERT_EQ(1u, document().markers().markers().size()); |
1179 | 1208 |
1180 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); | 1209 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); |
1181 EXPECT_EQ(19u, document().markers().markers()[0]->endOffset()); | 1210 EXPECT_EQ(19u, document().markers().markers()[0]->endOffset()); |
1182 } | 1211 } |
1183 | 1212 |
1184 TEST_F(InputMethodControllerTest, CommitPlainTextWithUnderlineReplace) { | 1213 TEST_F(InputMethodControllerTest, CommitPlainTextWithUnderlineReplace) { |
1185 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>", | 1214 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>", |
1186 "sample"); | 1215 "sample"); |
1187 | 1216 |
1188 Vector<CompositionUnderline> underlines; | 1217 Vector<CompositionUnderline> underlines; |
1189 | 1218 |
1190 controller().setCompositionFromExistingText(underlines, 8, 12); | 1219 controller().setCompositionFromExistingText(underlines, 8, 12); |
1191 | 1220 |
1192 underlines.push_back(CompositionUnderline(1, 11, Color(255, 0, 0), false, 0)); | 1221 underlines.push_back( |
| 1222 CompositionUnderline(1, 11, Color(255, 0, 0), false, 0, false)); |
1193 | 1223 |
1194 controller().commitText(String("string"), underlines, 0); | 1224 controller().commitText(String("string"), underlines, 0); |
1195 | 1225 |
1196 ASSERT_EQ(1u, document().markers().markers().size()); | 1226 ASSERT_EQ(1u, document().markers().markers().size()); |
1197 | 1227 |
1198 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); | 1228 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); |
1199 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); | 1229 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); |
1200 } | 1230 } |
1201 | 1231 |
| 1232 TEST_F(InputMethodControllerTest, UnderlinePersistence) { |
| 1233 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>", |
| 1234 "sample"); |
| 1235 Vector<CompositionUnderline> emptyUnderlines; |
| 1236 controller().setCompositionFromExistingText(emptyUnderlines, 8, 12); |
| 1237 |
| 1238 // Add non-persisting underline |
| 1239 Vector<CompositionUnderline> nonPersistingUnderlines; |
| 1240 nonPersistingUnderlines.push_back( |
| 1241 CompositionUnderline(1, 11, Color(255, 0, 0), false, 0, false)); |
| 1242 controller().commitText(String("string"), nonPersistingUnderlines, 0); |
| 1243 |
| 1244 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1245 |
| 1246 // setCompositionFromExistingText() should clear the non-persisting underline |
| 1247 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
| 1248 EXPECT_EQ(0u, document().markers().markers().size()); |
| 1249 |
| 1250 // Add persisting underline. |
| 1251 Vector<CompositionUnderline> persistingUnderlines; |
| 1252 persistingUnderlines.push_back( |
| 1253 CompositionUnderline(1, 11, Color(255, 0, 0), false, 0, true)); |
| 1254 controller().commitText(String("Replacement"), persistingUnderlines, 0); |
| 1255 |
| 1256 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1257 |
| 1258 // commitText() operation that should not affect the number of underlines |
| 1259 controller().setCompositionFromExistingText(emptyUnderlines, 11, 12); |
| 1260 controller().commitText(String(" "), emptyUnderlines, 0); |
| 1261 |
| 1262 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1263 |
| 1264 // finishComposingText() should not remove the persisting underline |
| 1265 controller().finishComposingText(InputMethodController::DoNotKeepSelection); |
| 1266 |
| 1267 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1268 } |
| 1269 |
| 1270 TEST_F(InputMethodControllerTest, DeleteStartOfMarker) { |
| 1271 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>", |
| 1272 "sample"); |
| 1273 |
| 1274 Vector<CompositionUnderline> underlines; |
| 1275 underlines.push_back( |
| 1276 CompositionUnderline(0, 7, Color(255, 0, 0), false, 0, true)); |
| 1277 // Underline "Initial" with a persisting underline |
| 1278 controller().setCompositionFromExistingText(underlines, 0, 7); |
| 1279 |
| 1280 Vector<CompositionUnderline> emptyUnderlines; |
| 1281 // Set composition to "Ini" |
| 1282 controller().setCompositionFromExistingText(emptyUnderlines, 0, 3); |
| 1283 // Delete "Ini" |
| 1284 controller().commitText(String(""), emptyUnderlines, 0); |
| 1285 |
| 1286 // Check that the underline is still attached to "tial" |
| 1287 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1288 EXPECT_EQ(0u, document().markers().markers()[0]->startOffset()); |
| 1289 EXPECT_EQ(4u, document().markers().markers()[0]->endOffset()); |
| 1290 } |
| 1291 |
| 1292 TEST_F(InputMethodControllerTest, DeleteBeforeStartOfMarker) { |
| 1293 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>", |
| 1294 "sample"); |
| 1295 |
| 1296 Vector<CompositionUnderline> underlines; |
| 1297 underlines.push_back( |
| 1298 CompositionUnderline(0, 4, Color(255, 0, 0), false, 0, true)); |
| 1299 // Underline "text" with a persisting underline |
| 1300 controller().setCompositionFromExistingText(underlines, 8, 12); |
| 1301 |
| 1302 Vector<CompositionUnderline> emptyUnderlines; |
| 1303 // Set composition to "Initial" |
| 1304 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
| 1305 |
| 1306 // Delete "Initial" |
| 1307 controller().commitText(String(""), emptyUnderlines, 0); |
| 1308 |
| 1309 // Check that the underline is still attached to "text" |
| 1310 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1311 EXPECT_EQ(1u, document().markers().markers()[0]->startOffset()); |
| 1312 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset()); |
| 1313 } |
| 1314 |
| 1315 TEST_F(InputMethodControllerTest, DeleteEndOfMarker) { |
| 1316 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>", |
| 1317 "sample"); |
| 1318 |
| 1319 Vector<CompositionUnderline> underlines; |
| 1320 underlines.push_back( |
| 1321 CompositionUnderline(0, 4, Color(255, 0, 0), false, 0, true)); |
| 1322 // Underline "text" with a persisting underline |
| 1323 controller().setCompositionFromExistingText(underlines, 8, 12); |
| 1324 |
| 1325 Vector<CompositionUnderline> emptyUnderlines; |
| 1326 // Set composition to "xt." |
| 1327 controller().setCompositionFromExistingText(emptyUnderlines, 10, 13); |
| 1328 |
| 1329 // Delete "xt." |
| 1330 controller().commitText(String(""), emptyUnderlines, 0); |
| 1331 |
| 1332 // Check that the underline is still attached to "te" |
| 1333 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1334 EXPECT_EQ(8u, document().markers().markers()[0]->startOffset()); |
| 1335 EXPECT_EQ(10u, document().markers().markers()[0]->endOffset()); |
| 1336 } |
| 1337 |
| 1338 TEST_F(InputMethodControllerTest, DeleteBeforeEndOfMarker) { |
| 1339 insertHTMLElement("<div id='sample' contenteditable>Initial text.</div>", |
| 1340 "sample"); |
| 1341 |
| 1342 Vector<CompositionUnderline> underlines; |
| 1343 underlines.push_back( |
| 1344 CompositionUnderline(0, 4, Color(255, 0, 0), false, 0, true)); |
| 1345 // Underline "text" with a persisting underline |
| 1346 controller().setCompositionFromExistingText(underlines, 8, 12); |
| 1347 |
| 1348 Vector<CompositionUnderline> emptyUnderlines; |
| 1349 // Set composition to "Initial" |
| 1350 controller().setCompositionFromExistingText(emptyUnderlines, 0, 7); |
| 1351 |
| 1352 // Delete "Initial" |
| 1353 controller().commitText(String(""), emptyUnderlines, 0); |
| 1354 |
| 1355 // Check that the underline is still attached to "text" |
| 1356 EXPECT_EQ(1u, document().markers().markers().size()); |
| 1357 EXPECT_EQ(1u, document().markers().markers()[0]->startOffset()); |
| 1358 EXPECT_EQ(5u, document().markers().markers()[0]->endOffset()); |
| 1359 } |
| 1360 |
1202 } // namespace blink | 1361 } // namespace blink |
OLD | NEW |