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

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

Issue 2020973002: Reland: Fix setComposingText with empty text when newCursorPosition != 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a different method to get the right boundary Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/editing/InputMethodController.h" 5 #include "core/editing/InputMethodController.h"
6 6
7 #include "core/dom/Element.h" 7 #include "core/dom/Element.h"
8 #include "core/dom/Range.h" 8 #include "core/dom/Range.h"
9 #include "core/editing/FrameSelection.h" 9 #include "core/editing/FrameSelection.h"
10 #include "core/events/MouseEvent.h" 10 #include "core/events/MouseEvent.h"
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 EXPECT_EQ(24u, controller().getSelectionOffsets().end()); 341 EXPECT_EQ(24u, controller().getSelectionOffsets().end());
342 342
343 // The cursor exceeds right boundary. 343 // The cursor exceeds right boundary.
344 // "hello\nworld\n01234AB56789*". 344 // "hello\nworld\n01234AB56789*".
345 controller().setComposition("AB", underlines, 100, 100); 345 controller().setComposition("AB", underlines, 100, 100);
346 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data()); 346 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
347 EXPECT_EQ(24u, controller().getSelectionOffsets().start()); 347 EXPECT_EQ(24u, controller().getSelectionOffsets().start());
348 EXPECT_EQ(24u, controller().getSelectionOffsets().end()); 348 EXPECT_EQ(24u, controller().getSelectionOffsets().end());
349 } 349 }
350 350
351 TEST_F(InputMethodControllerTest, SetCompositionWithEmptyText)
352 {
353 Element* div = insertHTMLElement(
354 "<div id='sample' contenteditable='true'>hello</div>",
355 "sample");
356
357 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
358 EXPECT_STREQ("hello", div->innerText().utf8().data());
359 EXPECT_EQ(2u, controller().getSelectionOffsets().start());
360 EXPECT_EQ(2u, controller().getSelectionOffsets().end());
361
362 Vector<CompositionUnderline> underlines0;
363 underlines0.append(CompositionUnderline(0, 0, Color(255, 0, 0), false, 0));
364 Vector<CompositionUnderline> underlines2;
365 underlines2.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
366
367 controller().setComposition("AB", underlines2, 2, 2);
368 // With previous composition.
369 controller().setComposition("", underlines0, 2, 2);
370 EXPECT_STREQ("hello", div->innerText().utf8().data());
371 EXPECT_EQ(4u, controller().getSelectionOffsets().start());
372 EXPECT_EQ(4u, controller().getSelectionOffsets().end());
373
374 // Without previous composition.
375 controller().setComposition("", underlines0, -1, -1);
376 EXPECT_STREQ("hello", div->innerText().utf8().data());
377 EXPECT_EQ(3u, controller().getSelectionOffsets().start());
378 EXPECT_EQ(3u, controller().getSelectionOffsets().end());
379 }
380
351 TEST_F(InputMethodControllerTest, CompositionFireBeforeInput) 381 TEST_F(InputMethodControllerTest, CompositionFireBeforeInput)
352 { 382 {
353 document().settings()->setScriptEnabled(true); 383 document().settings()->setScriptEnabled(true);
354 Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru e'></div>", "sample"); 384 Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru e'></div>", "sample");
355 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); 385 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION);
356 script->setInnerHTML( 386 script->setInnerHTML(
357 "document.getElementById('sample').addEventListener('beforeinput', funct ion(event) {" 387 "document.getElementById('sample').addEventListener('beforeinput', funct ion(event) {"
358 " document.title = `beforeinput.isComposing:${event.isComposing}`;" 388 " document.title = `beforeinput.isComposing:${event.isComposing}`;"
359 "});", 389 "});",
360 ASSERT_NO_EXCEPTION); 390 ASSERT_NO_EXCEPTION);
361 document().body()->appendChild(script, ASSERT_NO_EXCEPTION); 391 document().body()->appendChild(script, ASSERT_NO_EXCEPTION);
362 document().view()->updateAllLifecyclePhases(); 392 document().view()->updateAllLifecyclePhases();
363 393
364 // Simulate composition in the |contentEditable|. 394 // Simulate composition in the |contentEditable|.
365 Vector<CompositionUnderline> underlines; 395 Vector<CompositionUnderline> underlines;
366 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 396 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
367 editable->focus(); 397 editable->focus();
368 398
369 document().setTitle(emptyString()); 399 document().setTitle(emptyString());
370 controller().setComposition("foo", underlines, 0, 3); 400 controller().setComposition("foo", underlines, 0, 3);
371 EXPECT_STREQ("beforeinput.isComposing:true", document().title().utf8().data( )); 401 EXPECT_STREQ("beforeinput.isComposing:true", document().title().utf8().data( ));
372 402
373 document().setTitle(emptyString()); 403 document().setTitle(emptyString());
374 controller().confirmComposition(); 404 controller().confirmComposition();
375 // Last 'beforeinput' should also be inside composition scope. 405 // Last 'beforeinput' should also be inside composition scope.
376 EXPECT_STREQ("beforeinput.isComposing:true", document().title().utf8().data( )); 406 EXPECT_STREQ("beforeinput.isComposing:true", document().title().utf8().data( ));
377 } 407 }
378 408
379 } // namespace blink 409 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698