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

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

Issue 2668903003: Replace WTF::emptyString{16Bit}() with a static global (Closed)
Patch Set: Replace WTF::emptyString{16Bit}() with a static global Created 3 years, 10 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 929 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 " event => document.title += " 940 " event => document.title += "
941 " `input.isComposing:${event.isComposing};`);"); 941 " `input.isComposing:${event.isComposing};`);");
942 document().body()->appendChild(script); 942 document().body()->appendChild(script);
943 document().view()->updateAllLifecyclePhases(); 943 document().view()->updateAllLifecyclePhases();
944 944
945 // Simulate composition in the |contentEditable|. 945 // Simulate composition in the |contentEditable|.
946 Vector<CompositionUnderline> underlines; 946 Vector<CompositionUnderline> underlines;
947 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 947 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
948 editable->focus(); 948 editable->focus();
949 949
950 document().setTitle(emptyString()); 950 document().setTitle(emptyString);
951 controller().setComposition("foo", underlines, 0, 3); 951 controller().setComposition("foo", underlines, 0, 3);
952 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", 952 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;",
953 document().title().utf8().data()); 953 document().title().utf8().data());
954 954
955 document().setTitle(emptyString()); 955 document().setTitle(emptyString);
956 controller().finishComposingText(InputMethodController::KeepSelection); 956 controller().finishComposingText(InputMethodController::KeepSelection);
957 // Last pair of InputEvent should also be inside composition scope. 957 // Last pair of InputEvent should also be inside composition scope.
958 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;", 958 EXPECT_STREQ("beforeinput.isComposing:true;input.isComposing:true;",
959 document().title().utf8().data()); 959 document().title().utf8().data());
960 } 960 }
961 961
962 TEST_F(InputMethodControllerTest, CompositionInputEventForReplace) { 962 TEST_F(InputMethodControllerTest, CompositionInputEventForReplace) {
963 createHTMLWithCompositionInputEventListeners(); 963 createHTMLWithCompositionInputEventListeners();
964 964
965 // Simulate composition in the |contentEditable|. 965 // Simulate composition in the |contentEditable|.
966 Vector<CompositionUnderline> underlines; 966 Vector<CompositionUnderline> underlines;
967 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 967 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
968 968
969 document().setTitle(emptyString()); 969 document().setTitle(emptyString);
970 controller().setComposition("hell", underlines, 4, 4); 970 controller().setComposition("hell", underlines, 4, 4);
971 EXPECT_STREQ("beforeinput.data:hell;input.data:hell;", 971 EXPECT_STREQ("beforeinput.data:hell;input.data:hell;",
972 document().title().utf8().data()); 972 document().title().utf8().data());
973 973
974 // Replace the existing composition. 974 // Replace the existing composition.
975 document().setTitle(emptyString()); 975 document().setTitle(emptyString);
976 controller().setComposition("hello", underlines, 0, 0); 976 controller().setComposition("hello", underlines, 0, 0);
977 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", 977 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;",
978 document().title().utf8().data()); 978 document().title().utf8().data());
979 } 979 }
980 980
981 TEST_F(InputMethodControllerTest, CompositionInputEventForConfirm) { 981 TEST_F(InputMethodControllerTest, CompositionInputEventForConfirm) {
982 createHTMLWithCompositionInputEventListeners(); 982 createHTMLWithCompositionInputEventListeners();
983 983
984 // Simulate composition in the |contentEditable|. 984 // Simulate composition in the |contentEditable|.
985 Vector<CompositionUnderline> underlines; 985 Vector<CompositionUnderline> underlines;
986 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 986 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
987 987
988 document().setTitle(emptyString()); 988 document().setTitle(emptyString);
989 controller().setComposition("hello", underlines, 5, 5); 989 controller().setComposition("hello", underlines, 5, 5);
990 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", 990 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;",
991 document().title().utf8().data()); 991 document().title().utf8().data());
992 992
993 // Confirm the ongoing composition. 993 // Confirm the ongoing composition.
994 document().setTitle(emptyString()); 994 document().setTitle(emptyString);
995 controller().finishComposingText(InputMethodController::KeepSelection); 995 controller().finishComposingText(InputMethodController::KeepSelection);
996 EXPECT_STREQ( 996 EXPECT_STREQ(
997 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", 997 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;",
998 document().title().utf8().data()); 998 document().title().utf8().data());
999 } 999 }
1000 1000
1001 TEST_F(InputMethodControllerTest, CompositionInputEventForDelete) { 1001 TEST_F(InputMethodControllerTest, CompositionInputEventForDelete) {
1002 createHTMLWithCompositionInputEventListeners(); 1002 createHTMLWithCompositionInputEventListeners();
1003 1003
1004 // Simulate composition in the |contentEditable|. 1004 // Simulate composition in the |contentEditable|.
1005 Vector<CompositionUnderline> underlines; 1005 Vector<CompositionUnderline> underlines;
1006 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1006 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
1007 1007
1008 document().setTitle(emptyString()); 1008 document().setTitle(emptyString);
1009 controller().setComposition("hello", underlines, 5, 5); 1009 controller().setComposition("hello", underlines, 5, 5);
1010 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", 1010 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;",
1011 document().title().utf8().data()); 1011 document().title().utf8().data());
1012 1012
1013 // Delete the existing composition. 1013 // Delete the existing composition.
1014 document().setTitle(emptyString()); 1014 document().setTitle(emptyString);
1015 controller().setComposition("", underlines, 0, 0); 1015 controller().setComposition("", underlines, 0, 0);
1016 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", 1016 EXPECT_STREQ("beforeinput.data:;compositionend.data:;",
1017 document().title().utf8().data()); 1017 document().title().utf8().data());
1018 } 1018 }
1019 1019
1020 TEST_F(InputMethodControllerTest, CompositionInputEventForInsert) { 1020 TEST_F(InputMethodControllerTest, CompositionInputEventForInsert) {
1021 createHTMLWithCompositionInputEventListeners(); 1021 createHTMLWithCompositionInputEventListeners();
1022 1022
1023 // Simulate composition in the |contentEditable|. 1023 // Simulate composition in the |contentEditable|.
1024 Vector<CompositionUnderline> underlines; 1024 Vector<CompositionUnderline> underlines;
1025 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1025 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
1026 1026
1027 // Insert new text without previous composition. 1027 // Insert new text without previous composition.
1028 document().setTitle(emptyString()); 1028 document().setTitle(emptyString);
1029 document().updateStyleAndLayout(); 1029 document().updateStyleAndLayout();
1030 controller().commitText("hello", underlines, 0); 1030 controller().commitText("hello", underlines, 0);
1031 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;", 1031 EXPECT_STREQ("beforeinput.data:hello;input.data:hello;",
1032 document().title().utf8().data()); 1032 document().title().utf8().data());
1033 1033
1034 document().setTitle(emptyString()); 1034 document().setTitle(emptyString);
1035 controller().setComposition("n", underlines, 1, 1); 1035 controller().setComposition("n", underlines, 1, 1);
1036 EXPECT_STREQ("beforeinput.data:n;input.data:n;", 1036 EXPECT_STREQ("beforeinput.data:n;input.data:n;",
1037 document().title().utf8().data()); 1037 document().title().utf8().data());
1038 1038
1039 // Insert new text with previous composition. 1039 // Insert new text with previous composition.
1040 document().setTitle(emptyString()); 1040 document().setTitle(emptyString);
1041 document().updateStyleAndLayout(); 1041 document().updateStyleAndLayout();
1042 controller().commitText("hello", underlines, 1); 1042 controller().commitText("hello", underlines, 1);
1043 EXPECT_STREQ( 1043 EXPECT_STREQ(
1044 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;", 1044 "beforeinput.data:hello;input.data:hello;compositionend.data:hello;",
1045 document().title().utf8().data()); 1045 document().title().utf8().data());
1046 } 1046 }
1047 1047
1048 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) { 1048 TEST_F(InputMethodControllerTest, CompositionInputEventForInsertEmptyText) {
1049 createHTMLWithCompositionInputEventListeners(); 1049 createHTMLWithCompositionInputEventListeners();
1050 1050
1051 // Simulate composition in the |contentEditable|. 1051 // Simulate composition in the |contentEditable|.
1052 Vector<CompositionUnderline> underlines; 1052 Vector<CompositionUnderline> underlines;
1053 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0)); 1053 underlines.push_back(CompositionUnderline(0, 5, Color(255, 0, 0), false, 0));
1054 1054
1055 // Insert empty text without previous composition. 1055 // Insert empty text without previous composition.
1056 document().setTitle(emptyString()); 1056 document().setTitle(emptyString);
1057 document().updateStyleAndLayout(); 1057 document().updateStyleAndLayout();
1058 controller().commitText("", underlines, 0); 1058 controller().commitText("", underlines, 0);
1059 EXPECT_STREQ("", document().title().utf8().data()); 1059 EXPECT_STREQ("", document().title().utf8().data());
1060 1060
1061 document().setTitle(emptyString()); 1061 document().setTitle(emptyString);
1062 controller().setComposition("n", underlines, 1, 1); 1062 controller().setComposition("n", underlines, 1, 1);
1063 EXPECT_STREQ("beforeinput.data:n;input.data:n;", 1063 EXPECT_STREQ("beforeinput.data:n;input.data:n;",
1064 document().title().utf8().data()); 1064 document().title().utf8().data());
1065 1065
1066 // Insert empty text with previous composition. 1066 // Insert empty text with previous composition.
1067 document().setTitle(emptyString()); 1067 document().setTitle(emptyString);
1068 document().updateStyleAndLayout(); 1068 document().updateStyleAndLayout();
1069 controller().commitText("", underlines, 1); 1069 controller().commitText("", underlines, 1);
1070 EXPECT_STREQ("beforeinput.data:;compositionend.data:;", 1070 EXPECT_STREQ("beforeinput.data:;compositionend.data:;",
1071 document().title().utf8().data()); 1071 document().title().utf8().data());
1072 } 1072 }
1073 1073
1074 TEST_F(InputMethodControllerTest, CompositionEndEventWithNoSelection) { 1074 TEST_F(InputMethodControllerTest, CompositionEndEventWithNoSelection) {
1075 createHTMLWithCompositionEndEventListener(NoSelection); 1075 createHTMLWithCompositionEndEventListener(NoSelection);
1076 1076
1077 // Simulate composition in the |contentEditable|. 1077 // Simulate composition in the |contentEditable|.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 1169
1170 controller().commitText(String("string"), underlines, 0); 1170 controller().commitText(String("string"), underlines, 0);
1171 1171
1172 ASSERT_EQ(1u, document().markers().markers().size()); 1172 ASSERT_EQ(1u, document().markers().markers().size());
1173 1173
1174 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset()); 1174 EXPECT_EQ(9u, document().markers().markers()[0]->startOffset());
1175 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset()); 1175 EXPECT_EQ(15u, document().markers().markers()[0]->endOffset());
1176 } 1176 }
1177 1177
1178 } // namespace blink 1178 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/InputMethodController.cpp ('k') | third_party/WebKit/Source/core/editing/Position.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698