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

Side by Side Diff: views/controls/textfield/textfield_views_model_unittest.cc

Issue 7607018: Remove PREVIOUS_GRAPHEME_TRAILING. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « views/controls/textfield/textfield_views_model.cc ('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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/base/clipboard/clipboard.h" 10 #include "ui/base/clipboard/clipboard.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 EXPECT_EQ(string16(), model.GetSelectedText()); 119 EXPECT_EQ(string16(), model.GetSelectedText());
120 model.SelectAll(); 120 model.SelectAll();
121 EXPECT_STR_EQ("HELLO", model.GetSelectedText()); 121 EXPECT_STR_EQ("HELLO", model.GetSelectedText());
122 // SelectAll should select towards the end. 122 // SelectAll should select towards the end.
123 ui::Range range; 123 ui::Range range;
124 model.GetSelectedRange(&range); 124 model.GetSelectedRange(&range);
125 EXPECT_EQ(0U, range.start()); 125 EXPECT_EQ(0U, range.start());
126 EXPECT_EQ(5U, range.end()); 126 EXPECT_EQ(5U, range.end());
127 127
128 // Select and move cursor 128 // Select and move cursor
129 gfx::SelectionModel selection(1U); 129 model.MoveCursorTo(gfx::SelectionModel(1U, 3U));
130 model.MoveCursorTo(selection);
131 selection.set_selection_end(3U);
132 model.MoveCursorTo(selection);
133 EXPECT_STR_EQ("EL", model.GetSelectedText()); 130 EXPECT_STR_EQ("EL", model.GetSelectedText());
134 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false); 131 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false);
135 EXPECT_EQ(1U, model.GetCursorPosition()); 132 EXPECT_EQ(1U, model.GetCursorPosition());
136 selection.set_selection_end(1U); 133 model.MoveCursorTo(gfx::SelectionModel(1U, 3U));
137 selection.set_selection_start(selection.selection_end());
138 model.MoveCursorTo(selection);
139 selection.set_selection_end(3U);
140 model.MoveCursorTo(selection);
141 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); 134 model.MoveCursorRight(gfx::CHARACTER_BREAK, false);
142 EXPECT_EQ(3U, model.GetCursorPosition()); 135 EXPECT_EQ(3U, model.GetCursorPosition());
143 136
144 // Select all and move cursor 137 // Select all and move cursor
145 model.SelectAll(); 138 model.SelectAll();
146 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false); 139 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false);
147 EXPECT_EQ(0U, model.GetCursorPosition()); 140 EXPECT_EQ(0U, model.GetCursorPosition());
148 model.SelectAll(); 141 model.SelectAll();
149 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); 142 model.MoveCursorRight(gfx::CHARACTER_BREAK, false);
150 EXPECT_EQ(5U, model.GetCursorPosition()); 143 EXPECT_EQ(5U, model.GetCursorPosition());
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 model.SelectWord(); 328 model.SelectWord();
336 SelectWordTestVerifier(model, " ", 2U); 329 SelectWordTestVerifier(model, " ", 2U);
337 330
338 // Test when cursor is at the beginning of a word. 331 // Test when cursor is at the beginning of a word.
339 gfx::SelectionModel selection(2U); 332 gfx::SelectionModel selection(2U);
340 model.MoveCursorTo(selection); 333 model.MoveCursorTo(selection);
341 model.SelectWord(); 334 model.SelectWord();
342 SelectWordTestVerifier(model, "HELLO", 7U); 335 SelectWordTestVerifier(model, "HELLO", 7U);
343 336
344 // Test when cursor is at the end of a word. 337 // Test when cursor is at the end of a word.
345 selection.set_selection_end(15U); 338 selection = gfx::SelectionModel(15U);
346 selection.set_selection_start(selection.selection_end());
347 model.MoveCursorTo(selection); 339 model.MoveCursorTo(selection);
348 model.SelectWord(); 340 model.SelectWord();
349 SelectWordTestVerifier(model, "WO", 15U); 341 SelectWordTestVerifier(model, "WO", 15U);
350 342
351 // Test when cursor is somewhere in a non-alph-numeric fragment. 343 // Test when cursor is somewhere in a non-alph-numeric fragment.
352 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { 344 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) {
353 selection.set_selection_end(cursor_pos); 345 selection = gfx::SelectionModel(cursor_pos);
354 selection.set_selection_start(selection.selection_end());
355 model.MoveCursorTo(selection); 346 model.MoveCursorTo(selection);
356 model.SelectWord(); 347 model.SelectWord();
357 SelectWordTestVerifier(model, " !! ", 13U); 348 SelectWordTestVerifier(model, " !! ", 13U);
358 } 349 }
359 350
360 // Test when cursor is somewhere in a whitespace fragment. 351 // Test when cursor is somewhere in a whitespace fragment.
361 selection.set_selection_end(17U); 352 selection = gfx::SelectionModel(17U);
362 selection.set_selection_start(selection.selection_end());
363 model.MoveCursorTo(selection); 353 model.MoveCursorTo(selection);
364 model.SelectWord(); 354 model.SelectWord();
365 SelectWordTestVerifier(model, " ", 20U); 355 SelectWordTestVerifier(model, " ", 20U);
366 356
367 // Test when cursor is at the end. 357 // Test when cursor is at the end.
368 model.MoveCursorRight(gfx::LINE_BREAK, false); 358 model.MoveCursorRight(gfx::LINE_BREAK, false);
369 model.SelectWord(); 359 model.SelectWord();
370 SelectWordTestVerifier(model, " ", 24U); 360 SelectWordTestVerifier(model, " ", 24U);
371 } 361 }
372 362
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 EXPECT_STR_EQ("www.youtube.com", model.GetText()); 792 EXPECT_STR_EQ("www.youtube.com", model.GetText());
803 EXPECT_EQ(5U, model.GetCursorPosition()); 793 EXPECT_EQ(5U, model.GetCursorPosition());
804 EXPECT_FALSE(model.Redo()); 794 EXPECT_FALSE(model.Redo());
805 } 795 }
806 796
807 TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) { 797 TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) {
808 TextfieldViewsModel model(NULL); 798 TextfieldViewsModel model(NULL);
809 model.SetText(ASCIIToUTF16("ABCDE")); 799 model.SetText(ASCIIToUTF16("ABCDE"));
810 EXPECT_FALSE(model.Redo()); // nothing to redo 800 EXPECT_FALSE(model.Redo()); // nothing to redo
811 // Cut 801 // Cut
812 gfx::SelectionModel sel(1); 802 model.MoveCursorTo(gfx::SelectionModel(1, 3));
813 model.MoveCursorTo(sel);
814 sel.set_selection_end(3);
815 model.MoveCursorTo(sel);
816 model.Cut(); 803 model.Cut();
817 EXPECT_STR_EQ("ADE", model.GetText()); 804 EXPECT_STR_EQ("ADE", model.GetText());
818 EXPECT_EQ(1U, model.GetCursorPosition()); 805 EXPECT_EQ(1U, model.GetCursorPosition());
819 EXPECT_TRUE(model.Undo()); 806 EXPECT_TRUE(model.Undo());
820 EXPECT_STR_EQ("ABCDE", model.GetText()); 807 EXPECT_STR_EQ("ABCDE", model.GetText());
821 EXPECT_EQ(3U, model.GetCursorPosition()); 808 EXPECT_EQ(3U, model.GetCursorPosition());
822 EXPECT_TRUE(model.Undo()); 809 EXPECT_TRUE(model.Undo());
823 EXPECT_STR_EQ("", model.GetText()); 810 EXPECT_STR_EQ("", model.GetText());
824 EXPECT_EQ(0U, model.GetCursorPosition()); 811 EXPECT_EQ(0U, model.GetCursorPosition());
825 EXPECT_FALSE(model.Undo()); // no more undo 812 EXPECT_FALSE(model.Undo()); // no more undo
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 // empty cut shouldn't create an edit. 878 // empty cut shouldn't create an edit.
892 EXPECT_TRUE(model.Undo()); 879 EXPECT_TRUE(model.Undo());
893 EXPECT_STR_EQ("ABCBCBCDE", model.GetText()); 880 EXPECT_STR_EQ("ABCBCBCDE", model.GetText());
894 EXPECT_EQ(3U, model.GetCursorPosition()); 881 EXPECT_EQ(3U, model.GetCursorPosition());
895 882
896 // Copy 883 // Copy
897 ResetModel(&model); 884 ResetModel(&model);
898 model.SetText(ASCIIToUTF16("12345")); 885 model.SetText(ASCIIToUTF16("12345"));
899 EXPECT_STR_EQ("12345", model.GetText()); 886 EXPECT_STR_EQ("12345", model.GetText());
900 EXPECT_EQ(0U, model.GetCursorPosition()); 887 EXPECT_EQ(0U, model.GetCursorPosition());
901 sel.set_selection_end(1); 888 model.MoveCursorTo(gfx::SelectionModel(1, 3));
902 sel.set_selection_start(sel.selection_end());
903 model.MoveCursorTo(sel);
904 sel.set_selection_end(3);
905 model.MoveCursorTo(sel);
906 model.Copy(); // Copy "23" 889 model.Copy(); // Copy "23"
907 EXPECT_STR_EQ("12345", model.GetText()); 890 EXPECT_STR_EQ("12345", model.GetText());
908 EXPECT_EQ(3U, model.GetCursorPosition()); 891 EXPECT_EQ(3U, model.GetCursorPosition());
909 model.Paste(); // Paste "23" into "23". 892 model.Paste(); // Paste "23" into "23".
910 EXPECT_STR_EQ("12345", model.GetText()); 893 EXPECT_STR_EQ("12345", model.GetText());
911 EXPECT_EQ(3U, model.GetCursorPosition()); 894 EXPECT_EQ(3U, model.GetCursorPosition());
912 model.Paste(); 895 model.Paste();
913 EXPECT_STR_EQ("1232345", model.GetText()); 896 EXPECT_STR_EQ("1232345", model.GetText());
914 EXPECT_EQ(5U, model.GetCursorPosition()); 897 EXPECT_EQ(5U, model.GetCursorPosition());
915 EXPECT_TRUE(model.Undo()); 898 EXPECT_TRUE(model.Undo());
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 EXPECT_EQ(5U, model.GetCursorPosition()); 1002 EXPECT_EQ(5U, model.GetCursorPosition());
1020 EXPECT_FALSE(model.Redo()); 1003 EXPECT_FALSE(model.Redo());
1021 } 1004 }
1022 1005
1023 TEST_F(TextfieldViewsModelTest, UndoRedo_ReplaceTest) { 1006 TEST_F(TextfieldViewsModelTest, UndoRedo_ReplaceTest) {
1024 // By Cursor 1007 // By Cursor
1025 { 1008 {
1026 SCOPED_TRACE("forward & insert by cursor"); 1009 SCOPED_TRACE("forward & insert by cursor");
1027 TextfieldViewsModel model(NULL); 1010 TextfieldViewsModel model(NULL);
1028 model.SetText(ASCIIToUTF16("abcd")); 1011 model.SetText(ASCIIToUTF16("abcd"));
1029 gfx::SelectionModel sel(1); 1012 model.MoveCursorTo(gfx::SelectionModel(1, 3));
1030 model.MoveCursorTo(sel);
1031 sel.set_selection_end(3);
1032 model.MoveCursorTo(sel);
1033 RunInsertReplaceTest(model); 1013 RunInsertReplaceTest(model);
1034 } 1014 }
1035 { 1015 {
1036 SCOPED_TRACE("backward & insert by cursor"); 1016 SCOPED_TRACE("backward & insert by cursor");
1037 TextfieldViewsModel model(NULL); 1017 TextfieldViewsModel model(NULL);
1038 model.SetText(ASCIIToUTF16("abcd")); 1018 model.SetText(ASCIIToUTF16("abcd"));
1039 gfx::SelectionModel sel(3); 1019 model.MoveCursorTo(gfx::SelectionModel(3, 1));
1040 model.MoveCursorTo(sel);
1041 sel.set_selection_end(1);
1042 model.MoveCursorTo(sel);
1043 RunInsertReplaceTest(model); 1020 RunInsertReplaceTest(model);
1044 } 1021 }
1045 { 1022 {
1046 SCOPED_TRACE("forward & overwrite by cursor"); 1023 SCOPED_TRACE("forward & overwrite by cursor");
1047 TextfieldViewsModel model(NULL); 1024 TextfieldViewsModel model(NULL);
1048 model.SetText(ASCIIToUTF16("abcd")); 1025 model.SetText(ASCIIToUTF16("abcd"));
1049 gfx::SelectionModel sel(1); 1026 model.MoveCursorTo(gfx::SelectionModel(1, 3));
1050 model.MoveCursorTo(sel);
1051 sel.set_selection_end(3);
1052 model.MoveCursorTo(sel);
1053 RunOverwriteReplaceTest(model); 1027 RunOverwriteReplaceTest(model);
1054 } 1028 }
1055 { 1029 {
1056 SCOPED_TRACE("backward & overwrite by cursor"); 1030 SCOPED_TRACE("backward & overwrite by cursor");
1057 TextfieldViewsModel model(NULL); 1031 TextfieldViewsModel model(NULL);
1058 model.SetText(ASCIIToUTF16("abcd")); 1032 model.SetText(ASCIIToUTF16("abcd"));
1059 gfx::SelectionModel sel(3); 1033 model.MoveCursorTo(gfx::SelectionModel(3, 1));
1060 model.MoveCursorTo(sel);
1061 sel.set_selection_end(1);
1062 model.MoveCursorTo(sel);
1063 RunOverwriteReplaceTest(model); 1034 RunOverwriteReplaceTest(model);
1064 } 1035 }
1065 // By SelectRange API 1036 // By SelectRange API
1066 { 1037 {
1067 SCOPED_TRACE("forward & insert by SelectRange"); 1038 SCOPED_TRACE("forward & insert by SelectRange");
1068 TextfieldViewsModel model(NULL); 1039 TextfieldViewsModel model(NULL);
1069 model.SetText(ASCIIToUTF16("abcd")); 1040 model.SetText(ASCIIToUTF16("abcd"));
1070 model.SelectRange(ui::Range(1, 3)); 1041 model.SelectRange(ui::Range(1, 3));
1071 RunInsertReplaceTest(model); 1042 RunInsertReplaceTest(model);
1072 } 1043 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 EXPECT_TRUE(model.Undo()); 1135 EXPECT_TRUE(model.Undo());
1165 EXPECT_STR_EQ("ABCDE", model.GetText()); 1136 EXPECT_STR_EQ("ABCDE", model.GetText());
1166 EXPECT_TRUE(model.Redo()); 1137 EXPECT_TRUE(model.Redo());
1167 EXPECT_STR_EQ("1234", model.GetText()); 1138 EXPECT_STR_EQ("1234", model.GetText());
1168 EXPECT_FALSE(model.Redo()); 1139 EXPECT_FALSE(model.Redo());
1169 1140
1170 // TODO(oshima): We need MockInputMethod to test the behavior with IME. 1141 // TODO(oshima): We need MockInputMethod to test the behavior with IME.
1171 } 1142 }
1172 1143
1173 } // namespace views 1144 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/textfield/textfield_views_model.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698