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

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

Issue 2691433002: Make Blink support multiline text insertion (Closed)
Patch Set: Created 3 years, 10 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 | « no previous file | third_party/WebKit/Source/core/editing/commands/TypingCommand.h » ('j') | 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/Editor.h"
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 "sample"); 302 "sample");
303 303
304 Vector<CompositionUnderline> underlines; 304 Vector<CompositionUnderline> underlines;
305 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0)); 305 underlines.push_back(CompositionUnderline(3, 12, Color(255, 0, 0), false, 0));
306 controller().setCompositionFromExistingText(underlines, 3, 12); 306 controller().setCompositionFromExistingText(underlines, 3, 12);
307 307
308 controller().commitText(String("123789"), underlines, 0); 308 controller().commitText(String("123789"), underlines, 0);
309 EXPECT_STREQ("abc1<b>2</b>37<b>8</b>9", div->innerHTML().utf8().data()); 309 EXPECT_STREQ("abc1<b>2</b>37<b>8</b>9", div->innerHTML().utf8().data());
310 } 310 }
311 311
312 TEST_F(InputMethodControllerTest, InsertTextWithNewLine) {
313 Element* div =
314 insertHTMLElement("<div id='sample' contenteditable></div>", "sample");
315 Vector<CompositionUnderline> underlines;
316 underlines.push_back(CompositionUnderline(0, 11, Color(255, 0, 0), false, 0));
317
318 controller().commitText(String("hello\nworld"), underlines, 0);
319 EXPECT_STREQ("hello<div>world</div>", div->innerHTML().utf8().data());
320 }
321
322 TEST_F(InputMethodControllerTest, InsertTextWithNewLineIncrementally) {
323 Element* div =
324 insertHTMLElement("<div id='sample' contenteditable></div>", "sample");
325
326 Vector<CompositionUnderline> underlines;
327 underlines.push_back(CompositionUnderline(0, 11, Color(255, 0, 0), false, 0));
328 controller().setComposition("foo", underlines, 0, 2);
329 EXPECT_STREQ("foo", div->innerHTML().utf8().data());
330
331 controller().commitText(String("hello\nworld"), underlines, 0);
332 EXPECT_STREQ("hello<div>world</div>", div->innerHTML().utf8().data());
333 }
334
312 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) { 335 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) {
313 insertHTMLElement("<div id='sample' contenteditable>hello world</div>", 336 insertHTMLElement("<div id='sample' contenteditable>hello world</div>",
314 "sample"); 337 "sample");
315 338
316 Vector<CompositionUnderline> underlines; 339 Vector<CompositionUnderline> underlines;
317 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 340 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
318 controller().setCompositionFromExistingText(underlines, 0, 5); 341 controller().setCompositionFromExistingText(underlines, 0, 5);
319 342
320 controller().finishComposingText(InputMethodController::KeepSelection); 343 controller().finishComposingText(InputMethodController::KeepSelection);
321 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode()); 344 EXPECT_EQ(0, frame().selection().start().computeOffsetInContainerNode());
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1176
1154 controller().commitText(String("string"), underlines, 0); 1177 controller().commitText(String("string"), underlines, 0);
1155 1178
1156 ASSERT_EQ(1u, document().markers().markers().size()); 1179 ASSERT_EQ(1u, document().markers().markers().size());
1157 1180
1158 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); 1181 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset());
1159 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); 1182 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset());
1160 } 1183 }
1161 1184
1162 } // namespace blink 1185 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/commands/TypingCommand.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698