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..5668554682736f72aee27c2c888fec7c0927ef11 100644 |
| --- a/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp |
| +++ b/third_party/WebKit/Source/core/editing/InputMethodControllerTest.cpp |
| @@ -811,11 +811,11 @@ TEST_F(InputMethodControllerTest, CompositionInputEventIsComposing) { |
| Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); |
| script->setInnerHTML( |
| "document.getElementById('sample').addEventListener('beforeinput', " |
| - "function(event) {" |
| + "event => {" |
| " document.title = `beforeinput.isComposing:${event.isComposing};`;" |
| "});" |
| "document.getElementById('sample').addEventListener('input', " |
| - "function(event) {" |
| + "event => {" |
| " document.title += `input.isComposing:${event.isComposing};`;" |
| "});", |
| ASSERT_NO_EXCEPTION); |
| @@ -846,12 +846,19 @@ TEST_F(InputMethodControllerTest, CompositionInputEventData) { |
| Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); |
| script->setInnerHTML( |
| "document.getElementById('sample').addEventListener('beforeinput', " |
| - "function(event) {" |
| + "event => {" |
| " document.title = `beforeinput.data:${event.data};`;" |
| "});" |
| "document.getElementById('sample').addEventListener('input', " |
| - "function(event) {" |
| + "event => {" |
| " document.title += `input.data:${event.data};`;" |
| + "});" |
| + "document.getElementById('sample').addEventListener('compositionend', " |
| + "event => {" |
| + " document.title += `compositionend.data:${event.data};`;" |
| + // Reset the selection to [3,3] on receiving 'compositonend' event. |
| + " const node = document.getElementById('sample').firstChild;" |
| + " getSelection().collapse(node, 3);" |
|
yosin_UTC9
2016/11/16 02:02:10
Could you add two more tests which set selection
yabinh
2016/11/16 19:52:15
Done.
|
| "});", |
| ASSERT_NO_EXCEPTION); |
| document().body()->appendChild(script, ASSERT_NO_EXCEPTION); |
| @@ -862,20 +869,65 @@ 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); |
| - EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
| + controller().setComposition("hell", underlines, 4, 4); |
| + EXPECT_STREQ("beforeinput.data:hell;input.data:hell;", |
| document().title().utf8().data()); |
| + // Update the existing composition. |
| + // TODO(yabinh): should be "beforeinput.data:hello;input.data:hello;". |
| document().setTitle(emptyString()); |
| - controller().setComposition("ni", underlines, 0, 1); |
| - EXPECT_STREQ("beforeinput.data:i;input.data:i;", |
| + controller().setComposition("hello", underlines, 0, 0); |
| + EXPECT_STREQ("beforeinput.data:o;input.data:o;", |
| document().title().utf8().data()); |
| + // Confirm the ongoing composition. |
| document().setTitle(emptyString()); |
| - controller().finishComposingText(InputMethodController::KeepSelection); |
| - EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", |
| + // Move the caret to the end of text. |
| + controller().finishComposingText(InputMethodController::DoNotKeepSelection); |
| + EXPECT_STREQ( |
| + "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", |
| + document().title().utf8().data()); |
| + document().updateStyleAndLayout(); |
| + // Caret has been reseted to [3,3] in 'compositionend' event listener. |
| + EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
| + EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
| + |
| + // Delete the existing composition. |
| + document().setTitle(emptyString()); |
| + controller().setComposition("hello", underlines, 5, 5); |
| + EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", |
| + document().title().utf8().data()); |
| + document().setTitle(emptyString()); |
| + controller().setComposition("", underlines, 0, 0); |
| + EXPECT_STREQ("beforeinput.data:;compositionend.data:;", |
| + document().title().utf8().data()); |
| + document().updateStyleAndLayout(); |
| + EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
| + EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
| + |
| + // 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()); |
| + controller().setComposition("n", underlines, 1, 1); |
| + EXPECT_STREQ("beforeinput.data:n;input.data:n;", |
| + document().title().utf8().data()); |
| + document().setTitle(emptyString()); |
| + // Move the caret before "o". |
| + controller().commitText("hello", -1); |
| + EXPECT_STREQ( |
| + "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", |
| + document().title().utf8().data()); |
| + document().updateStyleAndLayout(); |
| + // Caret has been reseted to [3,3] in 'compositionend' event listener. |
| + EXPECT_EQ(3u, controller().getSelectionOffsets().start()); |
| + EXPECT_EQ(3u, controller().getSelectionOffsets().end()); |
| } |
| } // namespace blink |