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

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: Reland. Add a parameter. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/editing/InputMethodController.h" 5 #include "core/editing/InputMethodController.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/dom/Element.h" 8 #include "core/dom/Element.h"
9 #include "core/dom/Range.h" 9 #include "core/dom/Range.h"
10 #include "core/editing/Editor.h"
10 #include "core/editing/FrameSelection.h" 11 #include "core/editing/FrameSelection.h"
11 #include "core/events/MouseEvent.h" 12 #include "core/events/MouseEvent.h"
12 #include "core/frame/FrameView.h" 13 #include "core/frame/FrameView.h"
13 #include "core/frame/LocalFrame.h" 14 #include "core/frame/LocalFrame.h"
14 #include "core/frame/Settings.h" 15 #include "core/frame/Settings.h"
15 #include "core/html/HTMLInputElement.h" 16 #include "core/html/HTMLInputElement.h"
16 #include "core/testing/DummyPageHolder.h" 17 #include "core/testing/DummyPageHolder.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 #include <memory> 19 #include <memory>
19 20
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 EXPECT_EQ(24u, controller().getSelectionOffsets().end()); 343 EXPECT_EQ(24u, controller().getSelectionOffsets().end());
343 344
344 // The cursor exceeds right boundary. 345 // The cursor exceeds right boundary.
345 // "hello\nworld\n01234AB56789*". 346 // "hello\nworld\n01234AB56789*".
346 controller().setComposition("AB", underlines, 100, 100); 347 controller().setComposition("AB", underlines, 100, 100);
347 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data()); 348 EXPECT_STREQ("hello\nworld\n01234AB56789", div->innerText().utf8().data());
348 EXPECT_EQ(24u, controller().getSelectionOffsets().start()); 349 EXPECT_EQ(24u, controller().getSelectionOffsets().start());
349 EXPECT_EQ(24u, controller().getSelectionOffsets().end()); 350 EXPECT_EQ(24u, controller().getSelectionOffsets().end());
350 } 351 }
351 352
353 TEST_F(InputMethodControllerTest, SetCompositionWithEmptyText)
354 {
355 Element* div = insertHTMLElement(
356 "<div id='sample' contenteditable='true'>hello</div>",
357 "sample");
358
359 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
360 EXPECT_STREQ("hello", div->innerText().utf8().data());
361 EXPECT_EQ(2u, controller().getSelectionOffsets().start());
362 EXPECT_EQ(2u, controller().getSelectionOffsets().end());
363
364 Vector<CompositionUnderline> underlines0;
365 underlines0.append(CompositionUnderline(0, 0, Color(255, 0, 0), false, 0));
366 Vector<CompositionUnderline> underlines2;
367 underlines2.append(CompositionUnderline(0, 2, Color(255, 0, 0), false, 0));
368
369 controller().setComposition("AB", underlines2, 2, 2);
370 // With previous composition.
371 controller().setComposition("", underlines0, 2, 2);
372 EXPECT_STREQ("hello", div->innerText().utf8().data());
373 EXPECT_EQ(4u, controller().getSelectionOffsets().start());
374 EXPECT_EQ(4u, controller().getSelectionOffsets().end());
375
376 // Without previous composition.
377 controller().setComposition("", underlines0, -1, -1);
378 EXPECT_STREQ("hello", div->innerText().utf8().data());
379 EXPECT_EQ(3u, controller().getSelectionOffsets().start());
380 EXPECT_EQ(3u, controller().getSelectionOffsets().end());
381 }
382
383 TEST_F(InputMethodControllerTest, InsertLineBreakWhileComposingText)
384 {
385 Element* div = insertHTMLElement(
386 "<div id='sample' contenteditable='true'></div>",
387 "sample");
388
389 Vector<CompositionUnderline> underlines;
390 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
391 controller().setComposition("hello", underlines, 5, 5);
392 EXPECT_STREQ("hello", div->innerText().utf8().data());
393 EXPECT_EQ(5u, controller().getSelectionOffsets().start());
394 EXPECT_EQ(5u, controller().getSelectionOffsets().end());
395
396 frame().editor().insertLineBreak();
397 EXPECT_STREQ("\n\n", div->innerText().utf8().data());
398 EXPECT_EQ(1u, controller().getSelectionOffsets().start());
399 EXPECT_EQ(1u, controller().getSelectionOffsets().end());
400 }
401
402 TEST_F(InputMethodControllerTest, InsertLineBreakAfterConfirmingText)
403 {
404 Element* div = insertHTMLElement(
405 "<div id='sample' contenteditable='true'></div>",
406 "sample");
407
408 controller().confirmCompositionOrInsertText("hello", InputMethodController:: ConfirmCompositionBehavior::KeepSelection);
409 EXPECT_STREQ("hello", div->innerText().utf8().data());
410
411 controller().setEditableSelectionOffsets(PlainTextRange(2, 2));
412 EXPECT_EQ(2u, controller().getSelectionOffsets().start());
413 EXPECT_EQ(2u, controller().getSelectionOffsets().end());
414
415 frame().editor().insertLineBreak();
416 EXPECT_STREQ("he\nllo", div->innerText().utf8().data());
417 EXPECT_EQ(3u, controller().getSelectionOffsets().start());
418 EXPECT_EQ(3u, controller().getSelectionOffsets().end());
419 }
420
352 TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing) 421 TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing)
353 { 422 {
354 document().settings()->setScriptEnabled(true); 423 document().settings()->setScriptEnabled(true);
355 Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru e'></div>", "sample"); 424 Element* editable = insertHTMLElement("<div id='sample' contentEditable='tru e'></div>", "sample");
356 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); 425 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION);
357 script->setInnerHTML( 426 script->setInnerHTML(
358 "document.getElementById('sample').addEventListener('beforeinput', funct ion(event) {" 427 "document.getElementById('sample').addEventListener('beforeinput', funct ion(event) {"
359 " document.title = `beforeinput.isComposing:${event.isComposing};`;" 428 " document.title = `beforeinput.isComposing:${event.isComposing};`;"
360 "});" 429 "});"
361 "document.getElementById('sample').addEventListener('input', function(ev ent) {" 430 "document.getElementById('sample').addEventListener('input', function(ev ent) {"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 document().setTitle(emptyString()); 477 document().setTitle(emptyString());
409 controller().setComposition("ni", underlines, 0, 1); 478 controller().setComposition("ni", underlines, 0, 1);
410 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data()); 479 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data());
411 480
412 document().setTitle(emptyString()); 481 document().setTitle(emptyString());
413 controller().confirmComposition(); 482 controller().confirmComposition();
414 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data()); 483 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data());
415 } 484 }
416 485
417 } // namespace blink 486 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698