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

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

Issue 2372493002: Workaround for setComposition styling clobber (Closed)
Patch Set: Change a test for multi-node text Created 4 years, 2 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/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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 108 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
109 controller().setCompositionFromExistingText(underlines, 0, 5); 109 controller().setCompositionFromExistingText(underlines, 0, 5);
110 110
111 Range* range = controller().compositionRange(); 111 Range* range = controller().compositionRange();
112 EXPECT_EQ(0, range->startOffset()); 112 EXPECT_EQ(0, range->startOffset());
113 EXPECT_EQ(5, range->endOffset()); 113 EXPECT_EQ(5, range->endOffset());
114 114
115 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); 115 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range));
116 EXPECT_EQ(0u, plainTextRange.start()); 116 EXPECT_EQ(0u, plainTextRange.start());
117 EXPECT_EQ(5u, plainTextRange.end()); 117 EXPECT_EQ(5u, plainTextRange.end());
118
119 controller().setComposition(String("hellobar"), underlines, 8, 8);
120 range = controller().compositionRange();
121 EXPECT_EQ(0, range->startOffset());
122 EXPECT_EQ(8, range->endOffset());
123 }
124
125 TEST_F(InputMethodControllerTest, SetCompositionKeepingStyle)
126 {
127 Element* div = insertHTMLElement(
128 "<div id='sample' contenteditable='true'><b>he</b>llo</div>", "sample");
129
130 Vector<CompositionUnderline> underlines;
131 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
132 controller().setCompositionFromExistingText(underlines, 0, 5);
133
134 controller().setComposition(String("hell"), underlines, 4, 4);
135 EXPECT_STREQ("<b>he</b>ll", div->innerHTML().utf8().data());
136
137 controller().setComposition(String("hello"), underlines, 5, 5);
138 EXPECT_STREQ("<b>he</b>llo", div->innerHTML().utf8().data());
139 }
140
141 TEST_F(InputMethodControllerTest, SetCompositionWithMultiCodeTextKeepingStyle)
142 {
143 Element* div = insertHTMLElement(
144 "<div id='sample' contenteditable='true'><i>hello</i>world<b>&#x1f3e0</b ></div>", "sample"); // U+1F3E0 = 0xF0 0x9F 0x8F 0xA0 (UTF8)
Changwan Ryu 2016/09/27 09:17:11 could you add some explanation to the UTF8 code yo
yabinh 2016/09/27 12:46:47 Done.
145
146 Vector<CompositionUnderline> underlines;
147 underlines.append(CompositionUnderline(0, 12, Color(255, 0, 0), false, 0));
148 controller().setCompositionFromExistingText(underlines, 0, 12);
149
150 controller().setComposition(String::fromUTF8("helloworld\xF0\x9F\x8F\xAB"), underlines, 12, 12);
151 EXPECT_STREQ("<i>hello</i>world<b>\xF0\x9F\x8F\xAB</b>", div->innerHTML().ut f8().data());
152
153 controller().setComposition(String::fromUTF8("helloworld\xF0\x9F\x8F\xA0"), underlines, 12, 12);
154 EXPECT_STREQ("<i>hello</i>world<b>\xF0\x9F\x8F\xA0</b>", div->innerHTML().ut f8().data());
118 } 155 }
119 156
120 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText) 157 TEST_F(InputMethodControllerTest, SelectionOnConfirmExistingText)
121 { 158 {
122 insertHTMLElement( 159 insertHTMLElement(
123 "<div id='sample' contenteditable='true'>hello world</div>", "sample"); 160 "<div id='sample' contenteditable='true'>hello world</div>", "sample");
124 161
125 Vector<CompositionUnderline> underlines; 162 Vector<CompositionUnderline> underlines;
126 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 163 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
127 controller().setCompositionFromExistingText(underlines, 0, 5); 164 controller().setCompositionFromExistingText(underlines, 0, 5);
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 Vector<CompositionUnderline> underlines; 515 Vector<CompositionUnderline> underlines;
479 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 516 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
480 editable->focus(); 517 editable->focus();
481 518
482 document().setTitle(emptyString()); 519 document().setTitle(emptyString());
483 controller().setComposition("n", underlines, 0, 1); 520 controller().setComposition("n", underlines, 0, 1);
484 EXPECT_STREQ("beforeinput.data:n;input.data:n;", document().title().utf8().d ata()); 521 EXPECT_STREQ("beforeinput.data:n;input.data:n;", document().title().utf8().d ata());
485 522
486 document().setTitle(emptyString()); 523 document().setTitle(emptyString());
487 controller().setComposition("ni", underlines, 0, 1); 524 controller().setComposition("ni", underlines, 0, 1);
488 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data()); 525 EXPECT_STREQ("beforeinput.data:i;input.data:i;", document().title().utf8().d ata());
489 526
490 document().setTitle(emptyString()); 527 document().setTitle(emptyString());
491 controller().finishComposingText(InputMethodController::KeepSelection); 528 controller().finishComposingText(InputMethodController::KeepSelection);
492 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data()); 529 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", document().title().utf8() .data());
493 } 530 }
494 531
495 } // namespace blink 532 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698