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

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

Issue 2493703002: Make "compositionend" event fired after setting caret position (Closed)
Patch Set: Not able to listen to selectionchange event Created 4 years, 1 month 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 | « third_party/WebKit/Source/core/editing/InputMethodController.cpp ('k') | no next file » | 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 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 controller().finishComposingText(InputMethodController::KeepSelection); 836 controller().finishComposingText(InputMethodController::KeepSelection);
837 // Last pair of InputEvent should also be inside composition scope. 837 // Last pair of InputEvent should also be inside composition scope.
838 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", 838 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;",
839 document().title().utf8().data()); 839 document().title().utf8().data());
840 } 840 }
841 841
842 TEST_F(InputMethodControllerTest, CompositionInputEventData) { 842 TEST_F(InputMethodControllerTest, CompositionInputEventData) {
843 document().settings()->setScriptEnabled(true); 843 document().settings()->setScriptEnabled(true);
844 Element* editable = insertHTMLElement( 844 Element* editable = insertHTMLElement(
845 "<div id='sample' contentEditable='true'></div>", "sample"); 845 "<div id='sample' contentEditable='true'></div>", "sample");
846
846 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION); 847 Element* script = document().createElement("script", ASSERT_NO_EXCEPTION);
847 script->setInnerHTML( 848 script->setInnerHTML(
848 "document.getElementById('sample').addEventListener('beforeinput', " 849 "document.getElementById('sample').addEventListener('beforeinput', "
849 "function(event) {" 850 "function(event) {"
850 " document.title = `beforeinput.data:${event.data};`;" 851 " document.title = `beforeinput.data:${event.data};`;"
851 "});" 852 "});"
852 "document.getElementById('sample').addEventListener('input', " 853 "document.getElementById('sample').addEventListener('input', "
853 "function(event) {" 854 "function(event) {"
854 " document.title += `input.data:${event.data};`;" 855 " document.title += `input.data:${event.data};`;"
856 "});"
857 "document.getElementById('sample').addEventListener('compositionend', "
858 "function(event) {"
859 " document.title += `compositionend.data:${event.data};`;"
860 "});"
yabinh 2016/11/10 07:57:41 It seems that selectionchange doesn't work here. (
861 "document.addEventListener('selectionchange', "
862 "function() {"
863 " document.title += 'selectionchange;';"
855 "});", 864 "});",
856 ASSERT_NO_EXCEPTION); 865 ASSERT_NO_EXCEPTION);
857 document().body()->appendChild(script, ASSERT_NO_EXCEPTION); 866 document().body()->appendChild(script, ASSERT_NO_EXCEPTION);
858 document().view()->updateAllLifecyclePhases(); 867 document().view()->updateAllLifecyclePhases();
859 868
860 // Simulate composition in the |contentEditable|. 869 // Simulate composition in the |contentEditable|.
861 Vector<CompositionUnderline> underlines; 870 Vector<CompositionUnderline> underlines;
862 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 871 underlines.append(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
863 editable->focus(); 872 editable->focus();
864 873
874 // Create new composition.
865 document().setTitle(emptyString()); 875 document().setTitle(emptyString());
866 controller().setComposition("n", underlines, 0, 1); 876 controller().setComposition("n", underlines, 0, 1);
867 EXPECT_STREQ("beforeinput.data:n;input.data:n;", 877 EXPECT_STREQ("beforeinput.data:n;input.data:n;",
868 document().title().utf8().data()); 878 document().title().utf8().data());
869 879
880 // Update the existing composition.
881 // TODO(yabinh): should be "beforeinput.data:ni;input.data:ni;".
870 document().setTitle(emptyString()); 882 document().setTitle(emptyString());
871 controller().setComposition("ni", underlines, 0, 1); 883 controller().setComposition("ni", underlines, 0, 2);
872 EXPECT_STREQ("beforeinput.data:i;input.data:i;", 884 EXPECT_STREQ("beforeinput.data:i;input.data:i;",
873 document().title().utf8().data()); 885 document().title().utf8().data());
874 886
887 // Confirm the ongoing composition.
875 document().setTitle(emptyString()); 888 document().setTitle(emptyString());
876 controller().finishComposingText(InputMethodController::KeepSelection); 889 controller().finishComposingText(InputMethodController::KeepSelection);
877 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;", 890 EXPECT_STREQ("beforeinput.data:ni;input.data:ni;compositionend.data:ni;",
891 document().title().utf8().data());
892
893 // Delete the existing composition.
894 document().setTitle(emptyString());
895 controller().setComposition("n", underlines, 0, 1);
896 EXPECT_STREQ("beforeinput.data:n;input.data:n;",
897 document().title().utf8().data());
898 document().setTitle(emptyString());
899 controller().setComposition("", underlines, 0, 0);
900 EXPECT_STREQ("beforeinput.data:;compositionend.data:;",
901 document().title().utf8().data());
902
903 // Insert new text without previous composition.
904 document().setTitle(emptyString());
905 controller().commitText("hello", 0);
906 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;",
907 document().title().utf8().data());
908
909 // Insert new text with previous composition.
910 document().setTitle(emptyString());
911 controller().setComposition("n", underlines, 0, 1);
912 EXPECT_STREQ("beforeinput.data:n;input.data:n;",
913 document().title().utf8().data());
914 document().setTitle(emptyString());
915 controller().commitText("abc", 0);
916 EXPECT_STREQ("beforeinput.data:abc;input.data:abc;compositionend.data:abc;",
878 document().title().utf8().data()); 917 document().title().utf8().data());
879 } 918 }
880 919
881 } // namespace blink 920 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodController.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698