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

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 gfx::SelectionModel selection(1U);
msw 2011/08/13 19:37:38 These two lines are no longer necessary.
130 model.MoveCursorTo(selection); 130 model.MoveCursorTo(selection);
131 selection.set_selection_end(3U); 131 selection = gfx::SelectionModel(1U, 3U);
msw 2011/08/13 19:37:38 You can optionally get rid of |selection| and just
132 model.MoveCursorTo(selection); 132 model.MoveCursorTo(selection);
133 EXPECT_STR_EQ("EL", model.GetSelectedText()); 133 EXPECT_STR_EQ("EL", model.GetSelectedText());
134 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false); 134 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false);
135 EXPECT_EQ(1U, model.GetCursorPosition()); 135 EXPECT_EQ(1U, model.GetCursorPosition());
136 selection.set_selection_end(1U); 136 selection = gfx::SelectionModel(1U);
137 selection.set_selection_start(selection.selection_end());
138 model.MoveCursorTo(selection); 137 model.MoveCursorTo(selection);
139 selection.set_selection_end(3U); 138 selection = gfx::SelectionModel(1U, 3U);
140 model.MoveCursorTo(selection); 139 model.MoveCursorTo(selection);
141 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); 140 model.MoveCursorRight(gfx::CHARACTER_BREAK, false);
142 EXPECT_EQ(3U, model.GetCursorPosition()); 141 EXPECT_EQ(3U, model.GetCursorPosition());
143 142
144 // Select all and move cursor 143 // Select all and move cursor
145 model.SelectAll(); 144 model.SelectAll();
146 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false); 145 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false);
147 EXPECT_EQ(0U, model.GetCursorPosition()); 146 EXPECT_EQ(0U, model.GetCursorPosition());
148 model.SelectAll(); 147 model.SelectAll();
149 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); 148 model.MoveCursorRight(gfx::CHARACTER_BREAK, false);
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 model.SelectWord(); 334 model.SelectWord();
336 SelectWordTestVerifier(model, " ", 2U); 335 SelectWordTestVerifier(model, " ", 2U);
337 336
338 // Test when cursor is at the beginning of a word. 337 // Test when cursor is at the beginning of a word.
339 gfx::SelectionModel selection(2U); 338 gfx::SelectionModel selection(2U);
340 model.MoveCursorTo(selection); 339 model.MoveCursorTo(selection);
341 model.SelectWord(); 340 model.SelectWord();
342 SelectWordTestVerifier(model, "HELLO", 7U); 341 SelectWordTestVerifier(model, "HELLO", 7U);
343 342
344 // Test when cursor is at the end of a word. 343 // Test when cursor is at the end of a word.
345 selection.set_selection_end(15U); 344 selection = gfx::SelectionModel(15U);
346 selection.set_selection_start(selection.selection_end());
347 model.MoveCursorTo(selection); 345 model.MoveCursorTo(selection);
348 model.SelectWord(); 346 model.SelectWord();
349 SelectWordTestVerifier(model, "WO", 15U); 347 SelectWordTestVerifier(model, "WO", 15U);
350 348
351 // Test when cursor is somewhere in a non-alph-numeric fragment. 349 // Test when cursor is somewhere in a non-alph-numeric fragment.
352 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { 350 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) {
353 selection.set_selection_end(cursor_pos); 351 selection = gfx::SelectionModel(cursor_pos);
354 selection.set_selection_start(selection.selection_end());
355 model.MoveCursorTo(selection); 352 model.MoveCursorTo(selection);
356 model.SelectWord(); 353 model.SelectWord();
357 SelectWordTestVerifier(model, " !! ", 13U); 354 SelectWordTestVerifier(model, " !! ", 13U);
358 } 355 }
359 356
360 // Test when cursor is somewhere in a whitespace fragment. 357 // Test when cursor is somewhere in a whitespace fragment.
361 selection.set_selection_end(17U); 358 selection = gfx::SelectionModel(17U);
362 selection.set_selection_start(selection.selection_end());
363 model.MoveCursorTo(selection); 359 model.MoveCursorTo(selection);
364 model.SelectWord(); 360 model.SelectWord();
365 SelectWordTestVerifier(model, " ", 20U); 361 SelectWordTestVerifier(model, " ", 20U);
366 362
367 // Test when cursor is at the end. 363 // Test when cursor is at the end.
368 model.MoveCursorRight(gfx::LINE_BREAK, false); 364 model.MoveCursorRight(gfx::LINE_BREAK, false);
369 model.SelectWord(); 365 model.SelectWord();
370 SelectWordTestVerifier(model, " ", 24U); 366 SelectWordTestVerifier(model, " ", 24U);
371 } 367 }
372 368
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 EXPECT_STR_EQ("www.youtube.com", model.GetText()); 798 EXPECT_STR_EQ("www.youtube.com", model.GetText());
803 EXPECT_EQ(5U, model.GetCursorPosition()); 799 EXPECT_EQ(5U, model.GetCursorPosition());
804 EXPECT_FALSE(model.Redo()); 800 EXPECT_FALSE(model.Redo());
805 } 801 }
806 802
807 TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) { 803 TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) {
808 TextfieldViewsModel model(NULL); 804 TextfieldViewsModel model(NULL);
809 model.SetText(ASCIIToUTF16("ABCDE")); 805 model.SetText(ASCIIToUTF16("ABCDE"));
810 EXPECT_FALSE(model.Redo()); // nothing to redo 806 EXPECT_FALSE(model.Redo()); // nothing to redo
811 // Cut 807 // Cut
812 gfx::SelectionModel sel(1); 808 gfx::SelectionModel sel(1);
msw 2011/08/13 19:37:38 You can remove these two lines.
813 model.MoveCursorTo(sel); 809 model.MoveCursorTo(sel);
814 sel.set_selection_end(3); 810 sel = gfx::SelectionModel(1, 3);
815 model.MoveCursorTo(sel); 811 model.MoveCursorTo(sel);
816 model.Cut(); 812 model.Cut();
817 EXPECT_STR_EQ("ADE", model.GetText()); 813 EXPECT_STR_EQ("ADE", model.GetText());
818 EXPECT_EQ(1U, model.GetCursorPosition()); 814 EXPECT_EQ(1U, model.GetCursorPosition());
819 EXPECT_TRUE(model.Undo()); 815 EXPECT_TRUE(model.Undo());
820 EXPECT_STR_EQ("ABCDE", model.GetText()); 816 EXPECT_STR_EQ("ABCDE", model.GetText());
821 EXPECT_EQ(3U, model.GetCursorPosition()); 817 EXPECT_EQ(3U, model.GetCursorPosition());
822 EXPECT_TRUE(model.Undo()); 818 EXPECT_TRUE(model.Undo());
823 EXPECT_STR_EQ("", model.GetText()); 819 EXPECT_STR_EQ("", model.GetText());
824 EXPECT_EQ(0U, model.GetCursorPosition()); 820 EXPECT_EQ(0U, model.GetCursorPosition());
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 // empty cut shouldn't create an edit. 887 // empty cut shouldn't create an edit.
892 EXPECT_TRUE(model.Undo()); 888 EXPECT_TRUE(model.Undo());
893 EXPECT_STR_EQ("ABCBCBCDE", model.GetText()); 889 EXPECT_STR_EQ("ABCBCBCDE", model.GetText());
894 EXPECT_EQ(3U, model.GetCursorPosition()); 890 EXPECT_EQ(3U, model.GetCursorPosition());
895 891
896 // Copy 892 // Copy
897 ResetModel(&model); 893 ResetModel(&model);
898 model.SetText(ASCIIToUTF16("12345")); 894 model.SetText(ASCIIToUTF16("12345"));
899 EXPECT_STR_EQ("12345", model.GetText()); 895 EXPECT_STR_EQ("12345", model.GetText());
900 EXPECT_EQ(0U, model.GetCursorPosition()); 896 EXPECT_EQ(0U, model.GetCursorPosition());
901 sel.set_selection_end(1); 897 sel.set_selection_end(1);
msw 2011/08/13 19:37:38 You can remove these three lines.
902 sel.set_selection_start(sel.selection_end()); 898 sel.set_selection_start(sel.selection_end());
903 model.MoveCursorTo(sel); 899 model.MoveCursorTo(sel);
904 sel.set_selection_end(3); 900 sel = gfx::SelectionModel(1, 3);
905 model.MoveCursorTo(sel); 901 model.MoveCursorTo(sel);
906 model.Copy(); // Copy "23" 902 model.Copy(); // Copy "23"
907 EXPECT_STR_EQ("12345", model.GetText()); 903 EXPECT_STR_EQ("12345", model.GetText());
908 EXPECT_EQ(3U, model.GetCursorPosition()); 904 EXPECT_EQ(3U, model.GetCursorPosition());
909 model.Paste(); // Paste "23" into "23". 905 model.Paste(); // Paste "23" into "23".
910 EXPECT_STR_EQ("12345", model.GetText()); 906 EXPECT_STR_EQ("12345", model.GetText());
911 EXPECT_EQ(3U, model.GetCursorPosition()); 907 EXPECT_EQ(3U, model.GetCursorPosition());
912 model.Paste(); 908 model.Paste();
913 EXPECT_STR_EQ("1232345", model.GetText()); 909 EXPECT_STR_EQ("1232345", model.GetText());
914 EXPECT_EQ(5U, model.GetCursorPosition()); 910 EXPECT_EQ(5U, model.GetCursorPosition());
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 EXPECT_EQ(5U, model.GetCursorPosition()); 1015 EXPECT_EQ(5U, model.GetCursorPosition());
1020 EXPECT_FALSE(model.Redo()); 1016 EXPECT_FALSE(model.Redo());
1021 } 1017 }
1022 1018
1023 TEST_F(TextfieldViewsModelTest, UndoRedo_ReplaceTest) { 1019 TEST_F(TextfieldViewsModelTest, UndoRedo_ReplaceTest) {
1024 // By Cursor 1020 // By Cursor
1025 { 1021 {
1026 SCOPED_TRACE("forward & insert by cursor"); 1022 SCOPED_TRACE("forward & insert by cursor");
1027 TextfieldViewsModel model(NULL); 1023 TextfieldViewsModel model(NULL);
1028 model.SetText(ASCIIToUTF16("abcd")); 1024 model.SetText(ASCIIToUTF16("abcd"));
1029 gfx::SelectionModel sel(1); 1025 gfx::SelectionModel sel(1);
msw 2011/08/13 19:37:38 You can remove these two lines.
1030 model.MoveCursorTo(sel); 1026 model.MoveCursorTo(sel);
1031 sel.set_selection_end(3); 1027 sel = gfx::SelectionModel(1, 3);
1032 model.MoveCursorTo(sel); 1028 model.MoveCursorTo(sel);
1033 RunInsertReplaceTest(model); 1029 RunInsertReplaceTest(model);
1034 } 1030 }
1035 { 1031 {
1036 SCOPED_TRACE("backward & insert by cursor"); 1032 SCOPED_TRACE("backward & insert by cursor");
1037 TextfieldViewsModel model(NULL); 1033 TextfieldViewsModel model(NULL);
1038 model.SetText(ASCIIToUTF16("abcd")); 1034 model.SetText(ASCIIToUTF16("abcd"));
1039 gfx::SelectionModel sel(3); 1035 gfx::SelectionModel sel(3);
msw 2011/08/13 19:37:38 You can remove these two lines.
1040 model.MoveCursorTo(sel); 1036 model.MoveCursorTo(sel);
1041 sel.set_selection_end(1); 1037 sel = gfx::SelectionModel(3, 1);
1042 model.MoveCursorTo(sel); 1038 model.MoveCursorTo(sel);
1043 RunInsertReplaceTest(model); 1039 RunInsertReplaceTest(model);
1044 } 1040 }
1045 { 1041 {
1046 SCOPED_TRACE("forward & overwrite by cursor"); 1042 SCOPED_TRACE("forward & overwrite by cursor");
1047 TextfieldViewsModel model(NULL); 1043 TextfieldViewsModel model(NULL);
1048 model.SetText(ASCIIToUTF16("abcd")); 1044 model.SetText(ASCIIToUTF16("abcd"));
1049 gfx::SelectionModel sel(1); 1045 gfx::SelectionModel sel(1);
msw 2011/08/13 19:37:38 You can remove these two lines.
1050 model.MoveCursorTo(sel); 1046 model.MoveCursorTo(sel);
1051 sel.set_selection_end(3); 1047 sel = gfx::SelectionModel(1, 3);
1052 model.MoveCursorTo(sel); 1048 model.MoveCursorTo(sel);
1053 RunOverwriteReplaceTest(model); 1049 RunOverwriteReplaceTest(model);
1054 } 1050 }
1055 { 1051 {
1056 SCOPED_TRACE("backward & overwrite by cursor"); 1052 SCOPED_TRACE("backward & overwrite by cursor");
1057 TextfieldViewsModel model(NULL); 1053 TextfieldViewsModel model(NULL);
1058 model.SetText(ASCIIToUTF16("abcd")); 1054 model.SetText(ASCIIToUTF16("abcd"));
1059 gfx::SelectionModel sel(3); 1055 gfx::SelectionModel sel(3);
msw 2011/08/13 19:37:38 You can remove these two lines.
1060 model.MoveCursorTo(sel); 1056 model.MoveCursorTo(sel);
1061 sel.set_selection_end(1); 1057 sel = gfx::SelectionModel(3, 1);
1062 model.MoveCursorTo(sel); 1058 model.MoveCursorTo(sel);
1063 RunOverwriteReplaceTest(model); 1059 RunOverwriteReplaceTest(model);
1064 } 1060 }
1065 // By SelectRange API 1061 // By SelectRange API
1066 { 1062 {
1067 SCOPED_TRACE("forward & insert by SelectRange"); 1063 SCOPED_TRACE("forward & insert by SelectRange");
1068 TextfieldViewsModel model(NULL); 1064 TextfieldViewsModel model(NULL);
1069 model.SetText(ASCIIToUTF16("abcd")); 1065 model.SetText(ASCIIToUTF16("abcd"));
1070 model.SelectRange(ui::Range(1, 3)); 1066 model.SelectRange(ui::Range(1, 3));
1071 RunInsertReplaceTest(model); 1067 RunInsertReplaceTest(model);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 EXPECT_TRUE(model.Undo()); 1160 EXPECT_TRUE(model.Undo());
1165 EXPECT_STR_EQ("ABCDE", model.GetText()); 1161 EXPECT_STR_EQ("ABCDE", model.GetText());
1166 EXPECT_TRUE(model.Redo()); 1162 EXPECT_TRUE(model.Redo());
1167 EXPECT_STR_EQ("1234", model.GetText()); 1163 EXPECT_STR_EQ("1234", model.GetText());
1168 EXPECT_FALSE(model.Redo()); 1164 EXPECT_FALSE(model.Redo());
1169 1165
1170 // TODO(oshima): We need MockInputMethod to test the behavior with IME. 1166 // TODO(oshima): We need MockInputMethod to test the behavior with IME.
1171 } 1167 }
1172 1168
1173 } // namespace views 1169 } // 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