Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp |
| index 1d1eaf64d0da2b65835dd646f456a9ec1104c2e7..93659b3b009c2b94428a57ef61cfb6bb241f7203 100644 |
| --- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp |
| +++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp |
| @@ -852,6 +852,14 @@ TEST_F(InputMethodControllerTest, CompositionInputEventData) { |
| "document.getElementById('sample').addEventListener('input', " |
| "function(event) {" |
| " document.title += `input.data:${event.data};`;" |
| + "});" |
| + "document.getElementById('sample').addEventListener('compositionend', " |
| + "function(event) {" |
| + " if (getSelection().anchorOffset != event.data.length)" |
|
yosin_UTC9
2016/11/11 04:17:46
nit: We should have {} for then-clause.
|
| + " document.title += 'Wrong selection! Expected ' " |
|
yosin_UTC9
2016/11/11 04:17:46
Can we have a test case for this?
BTW, I don't th
yabinh
2016/11/11 05:23:52
How about this:
document.title += `selectionOffse
|
| + " + event.data.length + ', but got '" |
| + " + getSelection().anchorOffset + '!';" |
| + " document.title += `compositionend.data:${event.data};`;" |
| "});", |
| ASSERT_NO_EXCEPTION); |
| document().body()->appendChild(script, ASSERT_NO_EXCEPTION); |
| @@ -862,19 +870,53 @@ TEST_F(InputMethodControllerTest, CompositionInputEventData) { |
| underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); |
| editable->focus(); |
| + // Create new composition. |
| document().setTitle(emptyString()); |
| - controller().setComposition("n", underlines, 0, 1); |
| + controller().setComposition("n", underlines, 1, 1); |
| EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
| document().title().utf8().data()); |
| + // Update the existing composition. |
| + // TODO(yabinh): should be "beforeinput.data:ni;input.data:ni;". |
| document().setTitle(emptyString()); |
| - controller().setComposition("ni", underlines, 0, 1); |
| + controller().setComposition("ni", underlines, 2, 2); |
| EXPECT_STREQ("beforeinput.data:i;input.data:i;", |
| document().title().utf8().data()); |
| + // Confirm the ongoing composition. |
| document().setTitle(emptyString()); |
| controller().finishComposingText(InputMethodController::KeepSelection); |
| - EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", |
| + EXPECT_STREQ("beforeinput.data:ni;input.data:ni;compositionend.data:ni;", |
| + document().title().utf8().data()); |
| + |
| + // Delete the existing composition. |
| + document().setTitle(emptyString()); |
| + document().updateStyleAndLayout(); |
| + controller().setEditableSelectionOffsets(PlainTextRange(0, 0)); |
| + controller().setComposition("n", underlines, 1, 1); |
| + EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
| + document().title().utf8().data()); |
| + document().setTitle(emptyString()); |
| + controller().setComposition("", underlines, 0, 0); |
| + EXPECT_STREQ("beforeinput.data:;compositionend.data:;", |
| + document().title().utf8().data()); |
| + |
| + // Insert new text without previous composition. |
| + document().setTitle(emptyString()); |
| + controller().commitText("hello", 0); |
| + EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", |
| + document().title().utf8().data()); |
| + |
| + // Insert new text with previous composition. |
| + document().setTitle(emptyString()); |
| + document().updateStyleAndLayout(); |
| + controller().setEditableSelectionOffsets(PlainTextRange(0, 0)); |
| + controller().setComposition("n", underlines, 0, 1); |
| + EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
| + document().title().utf8().data()); |
| + document().setTitle(emptyString()); |
| + controller().commitText("abc", 0); |
| + EXPECT_STREQ("beforeinput.data:abc;input.data:abc;compositionend.data:abc;", |
| document().title().utf8().data()); |
| } |