| 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 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 EXPECT_STREQ("fooX", input->value().utf8().data()); | 163 EXPECT_STREQ("fooX", input->value().utf8().data()); |
| 164 controller().extendSelectionAndDelete(0, 1); | 164 controller().extendSelectionAndDelete(0, 1); |
| 165 EXPECT_STREQ("fooX", input->value().utf8().data()); | 165 EXPECT_STREQ("fooX", input->value().utf8().data()); |
| 166 } | 166 } |
| 167 | 167 |
| 168 TEST_F(InputMethodControllerTest, SetCompositionFromExistingText) { | 168 TEST_F(InputMethodControllerTest, SetCompositionFromExistingText) { |
| 169 Element* div = insertHTMLElement( | 169 Element* div = insertHTMLElement( |
| 170 "<div id='sample' contenteditable>hello world</div>", "sample"); | 170 "<div id='sample' contenteditable>hello world</div>", "sample"); |
| 171 | 171 |
| 172 Vector<CompositionUnderline> underlines; | 172 Vector<CompositionUnderline> underlines; |
| 173 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 173 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 174 controller().setCompositionFromExistingText(underlines, 0, 5); | 174 controller().setCompositionFromExistingText(underlines, 0, 5); |
| 175 | 175 |
| 176 Range* range = controller().compositionRange(); | 176 Range* range = controller().compositionRange(); |
| 177 EXPECT_EQ(0, range->startOffset()); | 177 EXPECT_EQ(0, range->startOffset()); |
| 178 EXPECT_EQ(5, range->endOffset()); | 178 EXPECT_EQ(5, range->endOffset()); |
| 179 | 179 |
| 180 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); | 180 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); |
| 181 EXPECT_EQ(0u, plainTextRange.start()); | 181 EXPECT_EQ(0u, plainTextRange.start()); |
| 182 EXPECT_EQ(5u, plainTextRange.end()); | 182 EXPECT_EQ(5u, plainTextRange.end()); |
| 183 } | 183 } |
| 184 | 184 |
| 185 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) { | 185 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle) { |
| 186 Element* div = insertHTMLElement( | 186 Element* div = insertHTMLElement( |
| 187 "<div id='sample' " | 187 "<div id='sample' " |
| 188 "contenteditable>abc1<b>2</b>34567<b>8</b>9d<b>e</b>f</div>", | 188 "contenteditable>abc1<b>2</b>34567<b>8</b>9d<b>e</b>f</div>", |
| 189 "sample"); | 189 "sample"); |
| 190 | 190 |
| 191 Vector<CompositionUnderline> underlines; | 191 Vector<CompositionUnderline> underlines; |
| 192 underlines.append(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); | 192 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); |
| 193 controller().setCompositionFromExistingText(underlines, 3, 12); | 193 controller().setCompositionFromExistingText(underlines, 3, 12); |
| 194 | 194 |
| 195 // Subtract a character. | 195 // Subtract a character. |
| 196 controller().setComposition(String("12345789"), underlines, 8, 8); | 196 controller().setComposition(String("12345789"), underlines, 8, 8); |
| 197 EXPECT_STREQ("abc1<b>2</b>3457<b>8</b>9d<b>e</b>f", | 197 EXPECT_STREQ("abc1<b>2</b>3457<b>8</b>9d<b>e</b>f", |
| 198 div->innerHTML().utf8().data()); | 198 div->innerHTML().utf8().data()); |
| 199 EXPECT_EQ(11u, controller().getSelectionOffsets().start()); | 199 EXPECT_EQ(11u, controller().getSelectionOffsets().start()); |
| 200 EXPECT_EQ(11u, controller().getSelectionOffsets().end()); | 200 EXPECT_EQ(11u, controller().getSelectionOffsets().end()); |
| 201 | 201 |
| 202 // Append a character. | 202 // Append a character. |
| 203 controller().setComposition(String("123456789"), underlines, 9, 9); | 203 controller().setComposition(String("123456789"), underlines, 9, 9); |
| 204 EXPECT_STREQ("abc1<b>2</b>34567<b>8</b>9d<b>e</b>f", | 204 EXPECT_STREQ("abc1<b>2</b>34567<b>8</b>9d<b>e</b>f", |
| 205 div->innerHTML().utf8().data()); | 205 div->innerHTML().utf8().data()); |
| 206 EXPECT_EQ(12u, controller().getSelectionOffsets().start()); | 206 EXPECT_EQ(12u, controller().getSelectionOffsets().start()); |
| 207 EXPECT_EQ(12u, controller().getSelectionOffsets().end()); | 207 EXPECT_EQ(12u, controller().getSelectionOffsets().end()); |
| 208 | 208 |
| 209 // Subtract and append characters. | 209 // Subtract and append characters. |
| 210 controller().setComposition(String("123hello789"), underlines, 11, 11); | 210 controller().setComposition(String("123hello789"), underlines, 11, 11); |
| 211 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9d<b>e</b>f", | 211 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9d<b>e</b>f", |
| 212 div->innerHTML().utf8().data()); | 212 div->innerHTML().utf8().data()); |
| 213 } | 213 } |
| 214 | 214 |
| 215 TEST_F(InputMethodControllerTest, SetCompositionWithEmojiKeepingStyle) { | 215 TEST_F(InputMethodControllerTest, SetCompositionWithEmojiKeepingStyle) { |
| 216 // U+1F3E0 = 0xF0 0x9F 0x8F 0xA0 (UTF8). It's an emoji character. | 216 // U+1F3E0 = 0xF0 0x9F 0x8F 0xA0 (UTF8). It's an emoji character. |
| 217 Element* div = insertHTMLElement( | 217 Element* div = insertHTMLElement( |
| 218 "<div id='sample' contenteditable><b>🏠</b></div>", "sample"); | 218 "<div id='sample' contenteditable><b>🏠</b></div>", "sample"); |
| 219 | 219 |
| 220 Vector<CompositionUnderline> underlines; | 220 Vector<CompositionUnderline> underlines; |
| 221 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 221 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); |
| 222 | 222 |
| 223 controller().setCompositionFromExistingText(underlines, 0, 2); | 223 controller().setCompositionFromExistingText(underlines, 0, 2); |
| 224 | 224 |
| 225 // 0xF0 0x9F 0x8F 0xAB is also an emoji character, with the same leading | 225 // 0xF0 0x9F 0x8F 0xAB is also an emoji character, with the same leading |
| 226 // surrogate pair to the previous one. | 226 // surrogate pair to the previous one. |
| 227 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xAB"), underlines, | 227 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xAB"), underlines, |
| 228 2, 2); | 228 2, 2); |
| 229 EXPECT_STREQ("<b>\xF0\x9F\x8F\xAB</b>", div->innerHTML().utf8().data()); | 229 EXPECT_STREQ("<b>\xF0\x9F\x8F\xAB</b>", div->innerHTML().utf8().data()); |
| 230 | 230 |
| 231 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xA0"), underlines, | 231 controller().setComposition(String::fromUTF8("\xF0\x9F\x8F\xA0"), underlines, |
| 232 2, 2); | 232 2, 2); |
| 233 EXPECT_STREQ("<b>\xF0\x9F\x8F\xA0</b>", div->innerHTML().utf8().data()); | 233 EXPECT_STREQ("<b>\xF0\x9F\x8F\xA0</b>", div->innerHTML().utf8().data()); |
| 234 } | 234 } |
| 235 | 235 |
| 236 TEST_F(InputMethodControllerTest, | 236 TEST_F(InputMethodControllerTest, |
| 237 SetCompositionWithTeluguSignVisargaKeepingStyle) { | 237 SetCompositionWithTeluguSignVisargaKeepingStyle) { |
| 238 // U+0C03 = 0xE0 0xB0 0x83 (UTF8), a telugu sign visarga with one code point. | 238 // U+0C03 = 0xE0 0xB0 0x83 (UTF8), a telugu sign visarga with one code point. |
| 239 // It's one grapheme cluster if separated. It can also form one grapheme | 239 // It's one grapheme cluster if separated. It can also form one grapheme |
| 240 // cluster with another code point(e.g, itself). | 240 // cluster with another code point(e.g, itself). |
| 241 Element* div = insertHTMLElement( | 241 Element* div = insertHTMLElement( |
| 242 "<div id='sample' contenteditable><b>ః</b></div>", "sample"); | 242 "<div id='sample' contenteditable><b>ః</b></div>", "sample"); |
| 243 | 243 |
| 244 Vector<CompositionUnderline> underlines; | 244 Vector<CompositionUnderline> underlines; |
| 245 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 245 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); |
| 246 controller().setCompositionFromExistingText(underlines, 0, 1); | 246 controller().setCompositionFromExistingText(underlines, 0, 1); |
| 247 | 247 |
| 248 // 0xE0 0xB0 0x83 0xE0 0xB0 0x83, a telugu character with 2 code points in | 248 // 0xE0 0xB0 0x83 0xE0 0xB0 0x83, a telugu character with 2 code points in |
| 249 // 1 grapheme cluster. | 249 // 1 grapheme cluster. |
| 250 controller().setComposition(String::fromUTF8("\xE0\xB0\x83\xE0\xB0\x83"), | 250 controller().setComposition(String::fromUTF8("\xE0\xB0\x83\xE0\xB0\x83"), |
| 251 underlines, 2, 2); | 251 underlines, 2, 2); |
| 252 EXPECT_STREQ("<b>\xE0\xB0\x83\xE0\xB0\x83</b>", | 252 EXPECT_STREQ("<b>\xE0\xB0\x83\xE0\xB0\x83</b>", |
| 253 div->innerHTML().utf8().data()); | 253 div->innerHTML().utf8().data()); |
| 254 | 254 |
| 255 controller().setComposition(String::fromUTF8("\xE0\xB0\x83"), underlines, 1, | 255 controller().setComposition(String::fromUTF8("\xE0\xB0\x83"), underlines, 1, |
| 256 1); | 256 1); |
| 257 EXPECT_STREQ("<b>\xE0\xB0\x83</b>", div->innerHTML().utf8().data()); | 257 EXPECT_STREQ("<b>\xE0\xB0\x83</b>", div->innerHTML().utf8().data()); |
| 258 } | 258 } |
| 259 | 259 |
| 260 TEST_F(InputMethodControllerTest, FinishComposingTextKeepingStyle) { | 260 TEST_F(InputMethodControllerTest, FinishComposingTextKeepingStyle) { |
| 261 Element* div = insertHTMLElement( | 261 Element* div = insertHTMLElement( |
| 262 "<div id='sample' " | 262 "<div id='sample' " |
| 263 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>", | 263 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>", |
| 264 "sample"); | 264 "sample"); |
| 265 | 265 |
| 266 Vector<CompositionUnderline> underlines; | 266 Vector<CompositionUnderline> underlines; |
| 267 underlines.append(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); | 267 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); |
| 268 controller().setCompositionFromExistingText(underlines, 3, 12); | 268 controller().setCompositionFromExistingText(underlines, 3, 12); |
| 269 | 269 |
| 270 controller().setComposition(String("123hello789"), underlines, 11, 11); | 270 controller().setComposition(String("123hello789"), underlines, 11, 11); |
| 271 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9", div->innerHTML().utf8().data()); | 271 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9", div->innerHTML().utf8().data()); |
| 272 | 272 |
| 273 controller().finishComposingText(InputMethodController::KeepSelection); | 273 controller().finishComposingText(InputMethodController::KeepSelection); |
| 274 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9", div->innerHTML().utf8().data()); | 274 EXPECT_STREQ("abc1<b>2</b>3hello7<b>8</b>9", div->innerHTML().utf8().data()); |
| 275 } | 275 } |
| 276 | 276 |
| 277 TEST_F(InputMethodControllerTest, CommitTextKeepingStyle) { | 277 TEST_F(InputMethodControllerTest, CommitTextKeepingStyle) { |
| 278 Element* div = insertHTMLElement( | 278 Element* div = insertHTMLElement( |
| 279 "<div id='sample' " | 279 "<div id='sample' " |
| 280 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>", | 280 "contenteditable>abc1<b>2</b>34567<b>8</b>9</div>", |
| 281 "sample"); | 281 "sample"); |
| 282 | 282 |
| 283 Vector<CompositionUnderline> underlines; | 283 Vector<CompositionUnderline> underlines; |
| 284 underlines.append(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); | 284 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); |
| 285 controller().setCompositionFromExistingText(underlines, 3, 12); | 285 controller().setCompositionFromExistingText(underlines, 3, 12); |
| 286 | 286 |
| 287 controller().commitText(String("123789"), 0); | 287 controller().commitText(String("123789"), 0); |
| 288 EXPECT_STREQ("abc1<b>2</b>37<b>8</b>9", div->innerHTML().utf8().data()); | 288 EXPECT_STREQ("abc1<b>2</b>37<b>8</b>9", div->innerHTML().utf8().data()); |
| 289 } | 289 } |
| 290 | 290 |
| 291 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { | 291 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { |
| 292 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", | 292 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", |
| 293 "sample"); | 293 "sample"); |
| 294 | 294 |
| 295 Vector<CompositionUnderline> underlines; | 295 Vector<CompositionUnderline> underlines; |
| 296 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 296 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 297 controller().setCompositionFromExistingText(underlines, 0, 5); | 297 controller().setCompositionFromExistingText(underlines, 0, 5); |
| 298 | 298 |
| 299 controller().finishComposingText(InputMethodController::KeepSelection); | 299 controller().finishComposingText(InputMethodController::KeepSelection); |
| 300 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); | 300 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); |
| 301 EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode()); | 301 EXPECT_EQ(0, frame().selection().end().computeOffsetInContainerNode()); |
| 302 } | 302 } |
| 303 | 303 |
| 304 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition) { | 304 TEST_F(InputMethodControllerTest, DeleteBySettingEmptyComposition) { |
| 305 HTMLInputElement* input = | 305 HTMLInputElement* input = |
| 306 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); | 306 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); |
| 307 | 307 |
| 308 input->setValue("foo "); | 308 input->setValue("foo "); |
| 309 document().updateStyleAndLayout(); | 309 document().updateStyleAndLayout(); |
| 310 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 310 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
| 311 EXPECT_STREQ("foo ", input->value().utf8().data()); | 311 EXPECT_STREQ("foo ", input->value().utf8().data()); |
| 312 controller().extendSelectionAndDelete(0, 0); | 312 controller().extendSelectionAndDelete(0, 0); |
| 313 EXPECT_STREQ("foo ", input->value().utf8().data()); | 313 EXPECT_STREQ("foo ", input->value().utf8().data()); |
| 314 | 314 |
| 315 input->setValue("foo "); | 315 input->setValue("foo "); |
| 316 document().updateStyleAndLayout(); | 316 document().updateStyleAndLayout(); |
| 317 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); | 317 controller().setEditableSelectionOffsets(PlainTextRange(4, 4)); |
| 318 EXPECT_STREQ("foo ", input->value().utf8().data()); | 318 EXPECT_STREQ("foo ", input->value().utf8().data()); |
| 319 controller().extendSelectionAndDelete(1, 0); | 319 controller().extendSelectionAndDelete(1, 0); |
| 320 EXPECT_STREQ("foo", input->value().utf8().data()); | 320 EXPECT_STREQ("foo", input->value().utf8().data()); |
| 321 | 321 |
| 322 Vector<CompositionUnderline> underlines; | 322 Vector<CompositionUnderline> underlines; |
| 323 underlines.append(CompositionUnderline(0, 3, Color(255, 0, 0), false, 0)); | 323 underlines.push_back(CompositionUnderline(0, 3, Color(255, 0, 0), false, 0)); |
| 324 controller().setCompositionFromExistingText(underlines, 0, 3); | 324 controller().setCompositionFromExistingText(underlines, 0, 3); |
| 325 | 325 |
| 326 controller().setComposition(String(""), underlines, 0, 3); | 326 controller().setComposition(String(""), underlines, 0, 3); |
| 327 | 327 |
| 328 EXPECT_STREQ("", input->value().utf8().data()); | 328 EXPECT_STREQ("", input->value().utf8().data()); |
| 329 } | 329 } |
| 330 | 330 |
| 331 TEST_F(InputMethodControllerTest, | 331 TEST_F(InputMethodControllerTest, |
| 332 SetCompositionFromExistingTextWithCollapsedWhiteSpace) { | 332 SetCompositionFromExistingTextWithCollapsedWhiteSpace) { |
| 333 // Creates a div with one leading new line char. The new line char is hidden | 333 // Creates a div with one leading new line char. The new line char is hidden |
| 334 // from the user and IME, but is visible to InputMethodController. | 334 // from the user and IME, but is visible to InputMethodController. |
| 335 Element* div = insertHTMLElement( | 335 Element* div = insertHTMLElement( |
| 336 "<div id='sample' contenteditable>\nhello world</div>", "sample"); | 336 "<div id='sample' contenteditable>\nhello world</div>", "sample"); |
| 337 | 337 |
| 338 Vector<CompositionUnderline> underlines; | 338 Vector<CompositionUnderline> underlines; |
| 339 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 339 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 340 controller().setCompositionFromExistingText(underlines, 0, 5); | 340 controller().setCompositionFromExistingText(underlines, 0, 5); |
| 341 | 341 |
| 342 Range* range = controller().compositionRange(); | 342 Range* range = controller().compositionRange(); |
| 343 EXPECT_EQ(1, range->startOffset()); | 343 EXPECT_EQ(1, range->startOffset()); |
| 344 EXPECT_EQ(6, range->endOffset()); | 344 EXPECT_EQ(6, range->endOffset()); |
| 345 | 345 |
| 346 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); | 346 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); |
| 347 EXPECT_EQ(0u, plainTextRange.start()); | 347 EXPECT_EQ(0u, plainTextRange.start()); |
| 348 EXPECT_EQ(5u, plainTextRange.end()); | 348 EXPECT_EQ(5u, plainTextRange.end()); |
| 349 } | 349 } |
| 350 | 350 |
| 351 TEST_F(InputMethodControllerTest, | 351 TEST_F(InputMethodControllerTest, |
| 352 SetCompositionFromExistingTextWithInvalidOffsets) { | 352 SetCompositionFromExistingTextWithInvalidOffsets) { |
| 353 insertHTMLElement("<div id='sample' contenteditable>test</div>", "sample"); | 353 insertHTMLElement("<div id='sample' contenteditable>test</div>", "sample"); |
| 354 | 354 |
| 355 Vector<CompositionUnderline> underlines; | 355 Vector<CompositionUnderline> underlines; |
| 356 underlines.append(CompositionUnderline(7, 8, Color(255, 0, 0), false, 0)); | 356 underlines.push_back(CompositionUnderline(7, 8, Color(255, 0, 0), false, 0)); |
| 357 controller().setCompositionFromExistingText(underlines, 7, 8); | 357 controller().setCompositionFromExistingText(underlines, 7, 8); |
| 358 | 358 |
| 359 EXPECT_FALSE(controller().compositionRange()); | 359 EXPECT_FALSE(controller().compositionRange()); |
| 360 } | 360 } |
| 361 | 361 |
| 362 TEST_F(InputMethodControllerTest, ConfirmPasswordComposition) { | 362 TEST_F(InputMethodControllerTest, ConfirmPasswordComposition) { |
| 363 HTMLInputElement* input = toHTMLInputElement(insertHTMLElement( | 363 HTMLInputElement* input = toHTMLInputElement(insertHTMLElement( |
| 364 "<input id='sample' type='password' size='24'>", "sample")); | 364 "<input id='sample' type='password' size='24'>", "sample")); |
| 365 | 365 |
| 366 Vector<CompositionUnderline> underlines; | 366 Vector<CompositionUnderline> underlines; |
| 367 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 367 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 368 controller().setComposition("foo", underlines, 0, 3); | 368 controller().setComposition("foo", underlines, 0, 3); |
| 369 controller().finishComposingText(InputMethodController::KeepSelection); | 369 controller().finishComposingText(InputMethodController::KeepSelection); |
| 370 | 370 |
| 371 EXPECT_STREQ("foo", input->value().utf8().data()); | 371 EXPECT_STREQ("foo", input->value().utf8().data()); |
| 372 } | 372 } |
| 373 | 373 |
| 374 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithEmptyText) { | 374 TEST_F(InputMethodControllerTest, DeleteSurroundingTextWithEmptyText) { |
| 375 HTMLInputElement* input = | 375 HTMLInputElement* input = |
| 376 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); | 376 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); |
| 377 | 377 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); | 691 toHTMLInputElement(insertHTMLElement("<input id='sample'>", "sample")); |
| 692 | 692 |
| 693 input->setValue("hello"); | 693 input->setValue("hello"); |
| 694 document().updateStyleAndLayout(); | 694 document().updateStyleAndLayout(); |
| 695 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | 695 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); |
| 696 EXPECT_STREQ("hello", input->value().utf8().data()); | 696 EXPECT_STREQ("hello", input->value().utf8().data()); |
| 697 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); | 697 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); |
| 698 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); | 698 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); |
| 699 | 699 |
| 700 Vector<CompositionUnderline> underlines; | 700 Vector<CompositionUnderline> underlines; |
| 701 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 701 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); |
| 702 | 702 |
| 703 // The caret exceeds left boundary. | 703 // The caret exceeds left boundary. |
| 704 // "*heABllo", where * stands for caret. | 704 // "*heABllo", where * stands for caret. |
| 705 controller().setComposition("AB", underlines, -100, -100); | 705 controller().setComposition("AB", underlines, -100, -100); |
| 706 EXPECT_STREQ("heABllo", input->value().utf8().data()); | 706 EXPECT_STREQ("heABllo", input->value().utf8().data()); |
| 707 EXPECT_EQ(0u, controller().getSelectionOffsets().start()); | 707 EXPECT_EQ(0u, controller().getSelectionOffsets().start()); |
| 708 EXPECT_EQ(0u, controller().getSelectionOffsets().end()); | 708 EXPECT_EQ(0u, controller().getSelectionOffsets().end()); |
| 709 | 709 |
| 710 // The caret is on left boundary. | 710 // The caret is on left boundary. |
| 711 // "*heABllo". | 711 // "*heABllo". |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 "</div>" | 755 "</div>" |
| 756 "</div>", | 756 "</div>", |
| 757 "sample"); | 757 "sample"); |
| 758 | 758 |
| 759 controller().setEditableSelectionOffsets(PlainTextRange(17, 17)); | 759 controller().setEditableSelectionOffsets(PlainTextRange(17, 17)); |
| 760 EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data()); | 760 EXPECT_STREQ("hello\nworld\n0123456789", div->innerText().utf8().data()); |
| 761 EXPECT_EQ(17u, controller().getSelectionOffsets().start()); | 761 EXPECT_EQ(17u, controller().getSelectionOffsets().start()); |
| 762 EXPECT_EQ(17u, controller().getSelectionOffsets().end()); | 762 EXPECT_EQ(17u, controller().getSelectionOffsets().end()); |
| 763 | 763 |
| 764 Vector<CompositionUnderline> underlines; | 764 Vector<CompositionUnderline> underlines; |
| 765 underlines.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 765 underlines.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); |
| 766 | 766 |
| 767 // The caret exceeds left boundary. | 767 // The caret exceeds left boundary. |
| 768 // "*hello\nworld\n01234AB56789", where * stands for caret. | 768 // "*hello\nworld\n01234AB56789", where * stands for caret. |
| 769 controller().setComposition("AB", underlines, -100, -100); | 769 controller().setComposition("AB", underlines, -100, -100); |
| 770 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data()); | 770 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data()); |
| 771 EXPECT_EQ(0u, controller().getSelectionOffsets().start()); | 771 EXPECT_EQ(0u, controller().getSelectionOffsets().start()); |
| 772 EXPECT_EQ(0u, controller().getSelectionOffsets().end()); | 772 EXPECT_EQ(0u, controller().getSelectionOffsets().end()); |
| 773 | 773 |
| 774 // The caret is on left boundary. | 774 // The caret is on left boundary. |
| 775 // "*hello\nworld\n01234AB56789". | 775 // "*hello\nworld\n01234AB56789". |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 TEST_F(InputMethodControllerTest, SetCompositionWithEmptyText) { | 845 TEST_F(InputMethodControllerTest, SetCompositionWithEmptyText) { |
| 846 Element* div = insertHTMLElement( | 846 Element* div = insertHTMLElement( |
| 847 "<div id='sample' contenteditable>hello</div>", "sample"); | 847 "<div id='sample' contenteditable>hello</div>", "sample"); |
| 848 | 848 |
| 849 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); | 849 controller().setEditableSelectionOffsets(PlainTextRange(2, 2)); |
| 850 EXPECT_STREQ("hello", div->innerText().utf8().data()); | 850 EXPECT_STREQ("hello", div->innerText().utf8().data()); |
| 851 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); | 851 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); |
| 852 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); | 852 EXPECT_EQ(2u, controller().getSelectionOffsets().end()); |
| 853 | 853 |
| 854 Vector<CompositionUnderline> underlines0; | 854 Vector<CompositionUnderline> underlines0; |
| 855 underlines0.append(CompositionUnderline(0, 0, Color(255, 0, 0), false, 0)); | 855 underlines0.push_back(CompositionUnderline(0, 0, Color(255, 0, 0), false, 0)); |
| 856 Vector<CompositionUnderline> underlines2; | 856 Vector<CompositionUnderline> underlines2; |
| 857 underlines2.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); | 857 underlines2.push_back(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0)); |
| 858 | 858 |
| 859 controller().setComposition("AB", underlines2, 2, 2); | 859 controller().setComposition("AB", underlines2, 2, 2); |
| 860 // With previous composition. | 860 // With previous composition. |
| 861 controller().setComposition("", underlines0, 2, 2); | 861 controller().setComposition("", underlines0, 2, 2); |
| 862 EXPECT_STREQ("hello", div->innerText().utf8().data()); | 862 EXPECT_STREQ("hello", div->innerText().utf8().data()); |
| 863 EXPECT_EQ(4u, controller().getSelectionOffsets().start()); | 863 EXPECT_EQ(4u, controller().getSelectionOffsets().start()); |
| 864 EXPECT_EQ(4u, controller().getSelectionOffsets().end()); | 864 EXPECT_EQ(4u, controller().getSelectionOffsets().end()); |
| 865 | 865 |
| 866 // Without previous composition. | 866 // Without previous composition. |
| 867 controller().setComposition("", underlines0, -1, -1); | 867 controller().setComposition("", underlines0, -1, -1); |
| 868 EXPECT_STREQ("hello", div->innerText().utf8().data()); | 868 EXPECT_STREQ("hello", div->innerText().utf8().data()); |
| 869 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 869 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
| 870 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); | 870 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
| 871 } | 871 } |
| 872 | 872 |
| 873 TEST_F(InputMethodControllerTest, InsertLineBreakWhileComposingText) { | 873 TEST_F(InputMethodControllerTest, InsertLineBreakWhileComposingText) { |
| 874 Element* div = | 874 Element* div = |
| 875 insertHTMLElement("<div id='sample' contenteditable></div>", "sample"); | 875 insertHTMLElement("<div id='sample' contenteditable></div>", "sample"); |
| 876 | 876 |
| 877 Vector<CompositionUnderline> underlines; | 877 Vector<CompositionUnderline> underlines; |
| 878 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 878 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 879 controller().setComposition("hello", underlines, 5, 5); | 879 controller().setComposition("hello", underlines, 5, 5); |
| 880 EXPECT_STREQ("hello", div->innerText().utf8().data()); | 880 EXPECT_STREQ("hello", div->innerText().utf8().data()); |
| 881 EXPECT_EQ(5u, controller().getSelectionOffsets().start()); | 881 EXPECT_EQ(5u, controller().getSelectionOffsets().start()); |
| 882 EXPECT_EQ(5u, controller().getSelectionOffsets().end()); | 882 EXPECT_EQ(5u, controller().getSelectionOffsets().end()); |
| 883 | 883 |
| 884 frame().editor().insertLineBreak(); | 884 frame().editor().insertLineBreak(); |
| 885 EXPECT_STREQ("\n\n", div->innerText().utf8().data()); | 885 EXPECT_STREQ("\n\n", div->innerText().utf8().data()); |
| 886 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); | 886 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); |
| 887 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); | 887 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); |
| 888 } | 888 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 914 " event => document.title = " | 914 " event => document.title = " |
| 915 " `beforeinput.isComposing:${event.isComposing};`);" | 915 " `beforeinput.isComposing:${event.isComposing};`);" |
| 916 "document.getElementById('sample').addEventListener('input', " | 916 "document.getElementById('sample').addEventListener('input', " |
| 917 " event => document.title += " | 917 " event => document.title += " |
| 918 " `input.isComposing:${event.isComposing};`);"); | 918 " `input.isComposing:${event.isComposing};`);"); |
| 919 document().body()->appendChild(script); | 919 document().body()->appendChild(script); |
| 920 document().view()->updateAllLifecyclePhases(); | 920 document().view()->updateAllLifecyclePhases(); |
| 921 | 921 |
| 922 // Simulate composition in the |contentEditable|. | 922 // Simulate composition in the |contentEditable|. |
| 923 Vector<CompositionUnderline> underlines; | 923 Vector<CompositionUnderline> underlines; |
| 924 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 924 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 925 editable->focus(); | 925 editable->focus(); |
| 926 | 926 |
| 927 document().setTitle(emptyString()); | 927 document().setTitle(emptyString()); |
| 928 controller().setComposition("foo", underlines, 0, 3); | 928 controller().setComposition("foo", underlines, 0, 3); |
| 929 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", | 929 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", |
| 930 document().title().utf8().data()); | 930 document().title().utf8().data()); |
| 931 | 931 |
| 932 document().setTitle(emptyString()); | 932 document().setTitle(emptyString()); |
| 933 controller().finishComposingText(InputMethodController::KeepSelection); | 933 controller().finishComposingText(InputMethodController::KeepSelection); |
| 934 // Last pair of InputEvent should also be inside composition scope. | 934 // Last pair of InputEvent should also be inside composition scope. |
| 935 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", | 935 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", |
| 936 document().title().utf8().data()); | 936 document().title().utf8().data()); |
| 937 } | 937 } |
| 938 | 938 |
| 939 TEST_F(InputMethodControllerTest, CompositionInputEventForReplace) { | 939 TEST_F(InputMethodControllerTest, CompositionInputEventForReplace) { |
| 940 createHTMLWithCompositionInputEventListeners(); | 940 createHTMLWithCompositionInputEventListeners(); |
| 941 | 941 |
| 942 // Simulate composition in the |contentEditable|. | 942 // Simulate composition in the |contentEditable|. |
| 943 Vector<CompositionUnderline> underlines; | 943 Vector<CompositionUnderline> underlines; |
| 944 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 944 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 945 | 945 |
| 946 document().setTitle(emptyString()); | 946 document().setTitle(emptyString()); |
| 947 controller().setComposition("hell", underlines, 4, 4); | 947 controller().setComposition("hell", underlines, 4, 4); |
| 948 EXPECT_STREQ("beforeinput.data:hell;input.data:hell;", | 948 EXPECT_STREQ("beforeinput.data:hell;input.data:hell;", |
| 949 document().title().utf8().data()); | 949 document().title().utf8().data()); |
| 950 | 950 |
| 951 // Replace the existing composition. | 951 // Replace the existing composition. |
| 952 document().setTitle(emptyString()); | 952 document().setTitle(emptyString()); |
| 953 controller().setComposition("hello", underlines, 0, 0); | 953 controller().setComposition("hello", underlines, 0, 0); |
| 954 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", | 954 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", |
| 955 document().title().utf8().data()); | 955 document().title().utf8().data()); |
| 956 } | 956 } |
| 957 | 957 |
| 958 TEST_F(InputMethodControllerTest, CompositionInputEventForConfirm) { | 958 TEST_F(InputMethodControllerTest, CompositionInputEventForConfirm) { |
| 959 createHTMLWithCompositionInputEventListeners(); | 959 createHTMLWithCompositionInputEventListeners(); |
| 960 | 960 |
| 961 // Simulate composition in the |contentEditable|. | 961 // Simulate composition in the |contentEditable|. |
| 962 Vector<CompositionUnderline> underlines; | 962 Vector<CompositionUnderline> underlines; |
| 963 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 963 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 964 | 964 |
| 965 document().setTitle(emptyString()); | 965 document().setTitle(emptyString()); |
| 966 controller().setComposition("hello", underlines, 5, 5); | 966 controller().setComposition("hello", underlines, 5, 5); |
| 967 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", | 967 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", |
| 968 document().title().utf8().data()); | 968 document().title().utf8().data()); |
| 969 | 969 |
| 970 // Confirm the ongoing composition. | 970 // Confirm the ongoing composition. |
| 971 document().setTitle(emptyString()); | 971 document().setTitle(emptyString()); |
| 972 controller().finishComposingText(InputMethodController::KeepSelection); | 972 controller().finishComposingText(InputMethodController::KeepSelection); |
| 973 EXPECT_STREQ( | 973 EXPECT_STREQ( |
| 974 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", | 974 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", |
| 975 document().title().utf8().data()); | 975 document().title().utf8().data()); |
| 976 } | 976 } |
| 977 | 977 |
| 978 TEST_F(InputMethodControllerTest, CompositionInputEventForDelete) { | 978 TEST_F(InputMethodControllerTest, CompositionInputEventForDelete) { |
| 979 createHTMLWithCompositionInputEventListeners(); | 979 createHTMLWithCompositionInputEventListeners(); |
| 980 | 980 |
| 981 // Simulate composition in the |contentEditable|. | 981 // Simulate composition in the |contentEditable|. |
| 982 Vector<CompositionUnderline> underlines; | 982 Vector<CompositionUnderline> underlines; |
| 983 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 983 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 984 | 984 |
| 985 document().setTitle(emptyString()); | 985 document().setTitle(emptyString()); |
| 986 controller().setComposition("hello", underlines, 5, 5); | 986 controller().setComposition("hello", underlines, 5, 5); |
| 987 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", | 987 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", |
| 988 document().title().utf8().data()); | 988 document().title().utf8().data()); |
| 989 | 989 |
| 990 // Delete the existing composition. | 990 // Delete the existing composition. |
| 991 document().setTitle(emptyString()); | 991 document().setTitle(emptyString()); |
| 992 controller().setComposition("", underlines, 0, 0); | 992 controller().setComposition("", underlines, 0, 0); |
| 993 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", | 993 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", |
| 994 document().title().utf8().data()); | 994 document().title().utf8().data()); |
| 995 } | 995 } |
| 996 | 996 |
| 997 TEST_F(InputMethodControllerTest, CompositionInputEventForInsert) { | 997 TEST_F(InputMethodControllerTest, CompositionInputEventForInsert) { |
| 998 createHTMLWithCompositionInputEventListeners(); | 998 createHTMLWithCompositionInputEventListeners(); |
| 999 | 999 |
| 1000 // Simulate composition in the |contentEditable|. | 1000 // Simulate composition in the |contentEditable|. |
| 1001 Vector<CompositionUnderline> underlines; | 1001 Vector<CompositionUnderline> underlines; |
| 1002 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1002 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 1003 | 1003 |
| 1004 // Insert new text without previous composition. | 1004 // Insert new text without previous composition. |
| 1005 document().setTitle(emptyString()); | 1005 document().setTitle(emptyString()); |
| 1006 document().updateStyleAndLayout(); | 1006 document().updateStyleAndLayout(); |
| 1007 controller().commitText("hello", 0); | 1007 controller().commitText("hello", 0); |
| 1008 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", | 1008 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", |
| 1009 document().title().utf8().data()); | 1009 document().title().utf8().data()); |
| 1010 | 1010 |
| 1011 document().setTitle(emptyString()); | 1011 document().setTitle(emptyString()); |
| 1012 controller().setComposition("n", underlines, 1, 1); | 1012 controller().setComposition("n", underlines, 1, 1); |
| 1013 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | 1013 EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
| 1014 document().title().utf8().data()); | 1014 document().title().utf8().data()); |
| 1015 | 1015 |
| 1016 // Insert new text with previous composition. | 1016 // Insert new text with previous composition. |
| 1017 document().setTitle(emptyString()); | 1017 document().setTitle(emptyString()); |
| 1018 document().updateStyleAndLayout(); | 1018 document().updateStyleAndLayout(); |
| 1019 controller().commitText("hello", 1); | 1019 controller().commitText("hello", 1); |
| 1020 EXPECT_STREQ( | 1020 EXPECT_STREQ( |
| 1021 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", | 1021 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", |
| 1022 document().title().utf8().data()); | 1022 document().title().utf8().data()); |
| 1023 } | 1023 } |
| 1024 | 1024 |
| 1025 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) { | 1025 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) { |
| 1026 createHTMLWithCompositionInputEventListeners(); | 1026 createHTMLWithCompositionInputEventListeners(); |
| 1027 | 1027 |
| 1028 // Simulate composition in the |contentEditable|. | 1028 // Simulate composition in the |contentEditable|. |
| 1029 Vector<CompositionUnderline> underlines; | 1029 Vector<CompositionUnderline> underlines; |
| 1030 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1030 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 1031 | 1031 |
| 1032 // Insert empty text without previous composition. | 1032 // Insert empty text without previous composition. |
| 1033 document().setTitle(emptyString()); | 1033 document().setTitle(emptyString()); |
| 1034 document().updateStyleAndLayout(); | 1034 document().updateStyleAndLayout(); |
| 1035 controller().commitText("", 0); | 1035 controller().commitText("", 0); |
| 1036 EXPECT_STREQ("", document().title().utf8().data()); | 1036 EXPECT_STREQ("", document().title().utf8().data()); |
| 1037 | 1037 |
| 1038 document().setTitle(emptyString()); | 1038 document().setTitle(emptyString()); |
| 1039 controller().setComposition("n", underlines, 1, 1); | 1039 controller().setComposition("n", underlines, 1, 1); |
| 1040 EXPECT_STREQ("beforeinput.data:n;input.data:n;", | 1040 EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
| 1041 document().title().utf8().data()); | 1041 document().title().utf8().data()); |
| 1042 | 1042 |
| 1043 // Insert empty text with previous composition. | 1043 // Insert empty text with previous composition. |
| 1044 document().setTitle(emptyString()); | 1044 document().setTitle(emptyString()); |
| 1045 document().updateStyleAndLayout(); | 1045 document().updateStyleAndLayout(); |
| 1046 controller().commitText("", 1); | 1046 controller().commitText("", 1); |
| 1047 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", | 1047 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", |
| 1048 document().title().utf8().data()); | 1048 document().title().utf8().data()); |
| 1049 } | 1049 } |
| 1050 | 1050 |
| 1051 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) { | 1051 TEST_F(InputMethodControllerTest, CompositionEndEventForConfirm) { |
| 1052 createHTMLWithCompositionEndEventListener(CaretSelection); | 1052 createHTMLWithCompositionEndEventListener(CaretSelection); |
| 1053 | 1053 |
| 1054 // Simulate composition in the |contentEditable|. | 1054 // Simulate composition in the |contentEditable|. |
| 1055 Vector<CompositionUnderline> underlines; | 1055 Vector<CompositionUnderline> underlines; |
| 1056 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1056 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 1057 | 1057 |
| 1058 controller().setComposition("hello", underlines, 1, 1); | 1058 controller().setComposition("hello", underlines, 1, 1); |
| 1059 document().updateStyleAndLayout(); | 1059 document().updateStyleAndLayout(); |
| 1060 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); | 1060 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); |
| 1061 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); | 1061 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); |
| 1062 | 1062 |
| 1063 // Confirm the ongoing composition. Note that it moves the caret to the end of | 1063 // Confirm the ongoing composition. Note that it moves the caret to the end of |
| 1064 // text [5,5] before firing 'compositonend' event. | 1064 // text [5,5] before firing 'compositonend' event. |
| 1065 controller().finishComposingText(InputMethodController::DoNotKeepSelection); | 1065 controller().finishComposingText(InputMethodController::DoNotKeepSelection); |
| 1066 document().updateStyleAndLayout(); | 1066 document().updateStyleAndLayout(); |
| 1067 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 1067 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
| 1068 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); | 1068 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 TEST_F(InputMethodControllerTest, CompositionEndEventForInsert) { | 1071 TEST_F(InputMethodControllerTest, CompositionEndEventForInsert) { |
| 1072 createHTMLWithCompositionEndEventListener(CaretSelection); | 1072 createHTMLWithCompositionEndEventListener(CaretSelection); |
| 1073 | 1073 |
| 1074 // Simulate composition in the |contentEditable|. | 1074 // Simulate composition in the |contentEditable|. |
| 1075 Vector<CompositionUnderline> underlines; | 1075 Vector<CompositionUnderline> underlines; |
| 1076 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1076 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 1077 | 1077 |
| 1078 controller().setComposition("n", underlines, 1, 1); | 1078 controller().setComposition("n", underlines, 1, 1); |
| 1079 | 1079 |
| 1080 // Insert new text with previous composition. Note that it moves the caret to | 1080 // Insert new text with previous composition. Note that it moves the caret to |
| 1081 // [4,4] before firing 'compositonend' event. | 1081 // [4,4] before firing 'compositonend' event. |
| 1082 document().updateStyleAndLayout(); | 1082 document().updateStyleAndLayout(); |
| 1083 controller().commitText("hello", -1); | 1083 controller().commitText("hello", -1); |
| 1084 document().updateStyleAndLayout(); | 1084 document().updateStyleAndLayout(); |
| 1085 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); | 1085 EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
| 1086 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); | 1086 EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 TEST_F(InputMethodControllerTest, CompositionEndEventWithRangeSelection) { | 1089 TEST_F(InputMethodControllerTest, CompositionEndEventWithRangeSelection) { |
| 1090 createHTMLWithCompositionEndEventListener(RangeSelection); | 1090 createHTMLWithCompositionEndEventListener(RangeSelection); |
| 1091 | 1091 |
| 1092 // Simulate composition in the |contentEditable|. | 1092 // Simulate composition in the |contentEditable|. |
| 1093 Vector<CompositionUnderline> underlines; | 1093 Vector<CompositionUnderline> underlines; |
| 1094 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1094 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 1095 | 1095 |
| 1096 controller().setComposition("hello", underlines, 1, 1); | 1096 controller().setComposition("hello", underlines, 1, 1); |
| 1097 document().updateStyleAndLayout(); | 1097 document().updateStyleAndLayout(); |
| 1098 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); | 1098 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); |
| 1099 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); | 1099 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); |
| 1100 | 1100 |
| 1101 // Confirm the ongoing composition. Note that it moves the caret to the end of | 1101 // Confirm the ongoing composition. Note that it moves the caret to the end of |
| 1102 // text [5,5] before firing 'compositonend' event. | 1102 // text [5,5] before firing 'compositonend' event. |
| 1103 controller().finishComposingText(InputMethodController::DoNotKeepSelection); | 1103 controller().finishComposingText(InputMethodController::DoNotKeepSelection); |
| 1104 document().updateStyleAndLayout(); | 1104 document().updateStyleAndLayout(); |
| 1105 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); | 1105 EXPECT_EQ(2u, controller().getSelectionOffsets().start()); |
| 1106 EXPECT_EQ(4u, controller().getSelectionOffsets().end()); | 1106 EXPECT_EQ(4u, controller().getSelectionOffsets().end()); |
| 1107 } | 1107 } |
| 1108 | 1108 |
| 1109 TEST_F(InputMethodControllerTest, CompositionEndEventWithNoSelection) { | 1109 TEST_F(InputMethodControllerTest, CompositionEndEventWithNoSelection) { |
| 1110 createHTMLWithCompositionEndEventListener(NoSelection); | 1110 createHTMLWithCompositionEndEventListener(NoSelection); |
| 1111 | 1111 |
| 1112 // Simulate composition in the |contentEditable|. | 1112 // Simulate composition in the |contentEditable|. |
| 1113 Vector<CompositionUnderline> underlines; | 1113 Vector<CompositionUnderline> underlines; |
| 1114 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 1114 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 1115 | 1115 |
| 1116 controller().setComposition("hello", underlines, 1, 1); | 1116 controller().setComposition("hello", underlines, 1, 1); |
| 1117 document().updateStyleAndLayout(); | 1117 document().updateStyleAndLayout(); |
| 1118 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); | 1118 EXPECT_EQ(1u, controller().getSelectionOffsets().start()); |
| 1119 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); | 1119 EXPECT_EQ(1u, controller().getSelectionOffsets().end()); |
| 1120 | 1120 |
| 1121 // Confirm the ongoing composition. Note that it moves the caret to the end of | 1121 // Confirm the ongoing composition. Note that it moves the caret to the end of |
| 1122 // text [5,5] before firing 'compositonend' event. | 1122 // text [5,5] before firing 'compositonend' event. |
| 1123 controller().finishComposingText(InputMethodController::DoNotKeepSelection); | 1123 controller().finishComposingText(InputMethodController::DoNotKeepSelection); |
| 1124 document().updateStyleAndLayout(); | 1124 document().updateStyleAndLayout(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1140 EXPECT_EQ(WebTextInputTypeNone, controller().textInputType()); | 1140 EXPECT_EQ(WebTextInputTypeNone, controller().textInputType()); |
| 1141 | 1141 |
| 1142 document().getElementById("b")->focus(); | 1142 document().getElementById("b")->focus(); |
| 1143 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); | 1143 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); |
| 1144 | 1144 |
| 1145 controller().finishComposingText(InputMethodController::KeepSelection); | 1145 controller().finishComposingText(InputMethodController::KeepSelection); |
| 1146 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); | 1146 EXPECT_EQ(WebTextInputTypeTelephone, controller().textInputType()); |
| 1147 } | 1147 } |
| 1148 | 1148 |
| 1149 } // namespace blink | 1149 } // namespace blink |
| OLD | NEW |