| 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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 168 |
| 169 TEST_F(InputMethodControllerTest, SetCompositionFromExistingText) { | 169 TEST_F(InputMethodControllerTest, SetCompositionFromExistingText) { |
| 170 Element* div = insertHTMLElement( | 170 Element* div = insertHTMLElement( |
| 171 "<div id='sample' contenteditable>hello world</div>", "sample"); | 171 "<div id='sample' contenteditable>hello world</div>", "sample"); |
| 172 | 172 |
| 173 Vector<CompositionUnderline> underlines; | 173 Vector<CompositionUnderline> underlines; |
| 174 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 174 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 175 controller().setCompositionFromExistingText(underlines, 0, 5); | 175 controller().setCompositionFromExistingText(underlines, 0, 5); |
| 176 | 176 |
| 177 Range* range = controller().compositionRange(); | 177 Range* range = controller().compositionRange(); |
| 178 EXPECT_EQ(0, range->startOffset()); | 178 EXPECT_EQ(0u, range->startOffset()); |
| 179 EXPECT_EQ(5, range->endOffset()); | 179 EXPECT_EQ(5u, range->endOffset()); |
| 180 | 180 |
| 181 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); | 181 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); |
| 182 EXPECT_EQ(0u, plainTextRange.start()); | 182 EXPECT_EQ(0u, plainTextRange.start()); |
| 183 EXPECT_EQ(5u, plainTextRange.end()); | 183 EXPECT_EQ(5u, plainTextRange.end()); |
| 184 } | 184 } |
| 185 | 185 |
| 186 TEST_F(InputMethodControllerTest, SetCompositionAfterEmoji) { | 186 TEST_F(InputMethodControllerTest, SetCompositionAfterEmoji) { |
| 187 // "trophy" = U+1F3C6 = 0xF0 0x9F 0x8F 0x86 (UTF8). | 187 // "trophy" = U+1F3C6 = 0xF0 0x9F 0x8F 0x86 (UTF8). |
| 188 Element* div = insertHTMLElement( | 188 Element* div = insertHTMLElement( |
| 189 "<div id='sample' contenteditable>🏆</div>", "sample"); | 189 "<div id='sample' contenteditable>🏆</div>", "sample"); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 // Creates a div with one leading new line char. The new line char is hidden | 377 // Creates a div with one leading new line char. The new line char is hidden |
| 378 // from the user and IME, but is visible to InputMethodController. | 378 // from the user and IME, but is visible to InputMethodController. |
| 379 Element* div = insertHTMLElement( | 379 Element* div = insertHTMLElement( |
| 380 "<div id='sample' contenteditable>\nhello world</div>", "sample"); | 380 "<div id='sample' contenteditable>\nhello world</div>", "sample"); |
| 381 | 381 |
| 382 Vector<CompositionUnderline> underlines; | 382 Vector<CompositionUnderline> underlines; |
| 383 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); | 383 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| 384 controller().setCompositionFromExistingText(underlines, 0, 5); | 384 controller().setCompositionFromExistingText(underlines, 0, 5); |
| 385 | 385 |
| 386 Range* range = controller().compositionRange(); | 386 Range* range = controller().compositionRange(); |
| 387 EXPECT_EQ(1, range->startOffset()); | 387 EXPECT_EQ(1u, range->startOffset()); |
| 388 EXPECT_EQ(6, range->endOffset()); | 388 EXPECT_EQ(6u, range->endOffset()); |
| 389 | 389 |
| 390 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); | 390 PlainTextRange plainTextRange(PlainTextRange::create(*div, *range)); |
| 391 EXPECT_EQ(0u, plainTextRange.start()); | 391 EXPECT_EQ(0u, plainTextRange.start()); |
| 392 EXPECT_EQ(5u, plainTextRange.end()); | 392 EXPECT_EQ(5u, plainTextRange.end()); |
| 393 } | 393 } |
| 394 | 394 |
| 395 TEST_F(InputMethodControllerTest, | 395 TEST_F(InputMethodControllerTest, |
| 396 SetCompositionFromExistingTextWithInvalidOffsets) { | 396 SetCompositionFromExistingTextWithInvalidOffsets) { |
| 397 insertHTMLElement("<div id='sample' contenteditable>test</div>", "sample"); | 397 insertHTMLElement("<div id='sample' contenteditable>test</div>", "sample"); |
| 398 | 398 |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 | 1190 |
| 1191 controller().commitText(String("string"), underlines, 0); | 1191 controller().commitText(String("string"), underlines, 0); |
| 1192 | 1192 |
| 1193 ASSERT_EQ(1u, document().markers().markers().size()); | 1193 ASSERT_EQ(1u, document().markers().markers().size()); |
| 1194 | 1194 |
| 1195 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); | 1195 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); |
| 1196 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); | 1196 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); |
| 1197 } | 1197 } |
| 1198 | 1198 |
| 1199 } // namespace blink | 1199 } // namespace blink |
| OLD | NEW |