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

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

Issue 135863002: Reland Merge NativeTextfieldViews into views::Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle Ctrl-Shift-Delete and Backspace on Linux, like on ChromeOS. Created 6 years, 11 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 5 #include <vector>
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 bool composition_text_confirmed_or_cleared_; 67 bool composition_text_confirmed_or_cleared_;
68 68
69 private: 69 private:
70 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModelTest); 70 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModelTest);
71 }; 71 };
72 72
73 TEST_F(TextfieldViewsModelTest, EditString) { 73 TEST_F(TextfieldViewsModelTest, EditString) {
74 TextfieldViewsModel model(NULL); 74 TextfieldViewsModel model(NULL);
75 // append two strings 75 // append two strings
76 model.Append(ASCIIToUTF16("HILL")); 76 model.Append(ASCIIToUTF16("HILL"));
77 EXPECT_STR_EQ("HILL", model.GetText()); 77 EXPECT_STR_EQ("HILL", model.text());
78 model.Append(ASCIIToUTF16("WORLD")); 78 model.Append(ASCIIToUTF16("WORLD"));
79 EXPECT_STR_EQ("HILLWORLD", model.GetText()); 79 EXPECT_STR_EQ("HILLWORLD", model.text());
80 80
81 // Insert "E" to make hello 81 // Insert "E" to make hello
82 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 82 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
83 model.InsertChar('E'); 83 model.InsertChar('E');
84 EXPECT_STR_EQ("HEILLWORLD", model.GetText()); 84 EXPECT_STR_EQ("HEILLWORLD", model.text());
85 // Replace "I" with "L" 85 // Replace "I" with "L"
86 model.ReplaceChar('L'); 86 model.ReplaceChar('L');
87 EXPECT_STR_EQ("HELLLWORLD", model.GetText()); 87 EXPECT_STR_EQ("HELLLWORLD", model.text());
88 model.ReplaceChar('L'); 88 model.ReplaceChar('L');
89 model.ReplaceChar('O'); 89 model.ReplaceChar('O');
90 EXPECT_STR_EQ("HELLOWORLD", model.GetText()); 90 EXPECT_STR_EQ("HELLOWORLD", model.text());
91 91
92 // Delete 6th char "W", then delete 5th char O" 92 // Delete 6th char "W", then delete 5th char O"
93 EXPECT_EQ(5U, model.GetCursorPosition()); 93 EXPECT_EQ(5U, model.GetCursorPosition());
94 EXPECT_TRUE(model.Delete()); 94 EXPECT_TRUE(model.Delete());
95 EXPECT_STR_EQ("HELLOORLD", model.GetText()); 95 EXPECT_STR_EQ("HELLOORLD", model.text());
96 EXPECT_TRUE(model.Backspace()); 96 EXPECT_TRUE(model.Backspace());
97 EXPECT_EQ(4U, model.GetCursorPosition()); 97 EXPECT_EQ(4U, model.GetCursorPosition());
98 EXPECT_STR_EQ("HELLORLD", model.GetText()); 98 EXPECT_STR_EQ("HELLORLD", model.text());
99 99
100 // Move the cursor to start. backspace should fail. 100 // Move the cursor to start. backspace should fail.
101 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 101 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
102 EXPECT_FALSE(model.Backspace()); 102 EXPECT_FALSE(model.Backspace());
103 EXPECT_STR_EQ("HELLORLD", model.GetText()); 103 EXPECT_STR_EQ("HELLORLD", model.text());
104 // Move the cursor to the end. delete should fail. 104 // Move the cursor to the end. delete should fail.
105 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 105 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
106 EXPECT_FALSE(model.Delete()); 106 EXPECT_FALSE(model.Delete());
107 EXPECT_STR_EQ("HELLORLD", model.GetText()); 107 EXPECT_STR_EQ("HELLORLD", model.text());
108 // but backspace should work. 108 // but backspace should work.
109 EXPECT_TRUE(model.Backspace()); 109 EXPECT_TRUE(model.Backspace());
110 EXPECT_STR_EQ("HELLORL", model.GetText()); 110 EXPECT_STR_EQ("HELLORL", model.text());
111 111
112 MoveCursorTo(model, 5); 112 MoveCursorTo(model, 5);
113 model.ReplaceText(ASCIIToUTF16(" WOR")); 113 model.ReplaceText(ASCIIToUTF16(" WOR"));
114 EXPECT_STR_EQ("HELLO WORL", model.GetText()); 114 EXPECT_STR_EQ("HELLO WORL", model.text());
115 } 115 }
116 116
117 TEST_F(TextfieldViewsModelTest, EditString_SimpleRTL) { 117 TEST_F(TextfieldViewsModelTest, EditString_SimpleRTL) {
118 TextfieldViewsModel model(NULL); 118 TextfieldViewsModel model(NULL);
119 // Append two strings. 119 // Append two strings.
120 model.Append(WideToUTF16(L"\x05d0\x05d1\x05d2")); 120 model.Append(WideToUTF16(L"\x05d0\x05d1\x05d2"));
121 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2"), model.GetText()); 121 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2"), model.text());
122 model.Append(WideToUTF16(L"\x05e0\x05e1\x05e2")); 122 model.Append(WideToUTF16(L"\x05e0\x05e1\x05e2"));
123 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2\x05e0\x05e1\x05e2"), 123 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2\x05e0\x05e1\x05e2"), model.text());
124 model.GetText());
125 124
126 // Insert 0x05f0. 125 // Insert 0x05f0.
127 MoveCursorTo(model, 1); 126 MoveCursorTo(model, 1);
128 model.InsertChar(0x05f0); 127 model.InsertChar(0x05f0);
129 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05d1\x05d2\x05e0\x05e1\x05e2"), 128 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05d1\x05d2\x05e0\x05e1\x05e2"),
130 model.GetText()); 129 model.text());
131 130
132 // Replace "\x05d1" with "\x05f1". 131 // Replace "\x05d1" with "\x05f1".
133 model.ReplaceChar(0x05f1); 132 model.ReplaceChar(0x05f1);
134 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05d2\x05e0\x05e1\x05e2"), 133 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05d2\x05e0\x05e1\x05e2"),
135 model.GetText()); 134 model.text());
136 135
137 // Delete and backspace. 136 // Delete and backspace.
138 EXPECT_EQ(3U, model.GetCursorPosition()); 137 EXPECT_EQ(3U, model.GetCursorPosition());
139 EXPECT_TRUE(model.Delete()); 138 EXPECT_TRUE(model.Delete());
140 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05e0\x05e1\x05e2"), 139 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05e0\x05e1\x05e2"), model.text());
141 model.GetText());
142 EXPECT_TRUE(model.Backspace()); 140 EXPECT_TRUE(model.Backspace());
143 EXPECT_EQ(2U, model.GetCursorPosition()); 141 EXPECT_EQ(2U, model.GetCursorPosition());
144 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05e0\x05e1\x05e2"), model.GetText()); 142 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05e0\x05e1\x05e2"), model.text());
145 } 143 }
146 144
147 TEST_F(TextfieldViewsModelTest, EditString_ComplexScript) { 145 TEST_F(TextfieldViewsModelTest, EditString_ComplexScript) {
148 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete 146 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete
149 // font support for some scripts - http://crbug.com/106450 147 // font support for some scripts - http://crbug.com/106450
150 bool on_windows_xp = false; 148 bool on_windows_xp = false;
151 #if defined(OS_WIN) 149 #if defined(OS_WIN)
152 on_windows_xp = base::win::GetVersion() < base::win::VERSION_VISTA; 150 on_windows_xp = base::win::GetVersion() < base::win::VERSION_VISTA;
153 #endif 151 #endif
154 152
155 TextfieldViewsModel model(NULL); 153 TextfieldViewsModel model(NULL);
156 154
157 // Append two Hindi strings. 155 // Append two Hindi strings.
158 model.Append(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); 156 model.Append(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"));
159 EXPECT_EQ(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"), 157 EXPECT_EQ(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"), model.text());
160 model.GetText());
161 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d")); 158 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d"));
162 EXPECT_EQ(WideToUTF16( 159 EXPECT_EQ(WideToUTF16(
163 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), 160 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), model.text());
164 model.GetText());
165 161
166 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete 162 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete
167 // font support for some scripts - http://crbug.com/106450 163 // font support for some scripts - http://crbug.com/106450
168 if (!on_windows_xp) { 164 if (!on_windows_xp) {
169 // Check it is not able to place cursor in middle of a grapheme. 165 // Check it is not able to place cursor in middle of a grapheme.
170 MoveCursorTo(model, 1); 166 MoveCursorTo(model, 1);
171 EXPECT_EQ(0U, model.GetCursorPosition()); 167 EXPECT_EQ(0U, model.GetCursorPosition());
172 168
173 MoveCursorTo(model, 2); 169 MoveCursorTo(model, 2);
174 EXPECT_EQ(2U, model.GetCursorPosition()); 170 EXPECT_EQ(2U, model.GetCursorPosition());
175 model.InsertChar('a'); 171 model.InsertChar('a');
176 EXPECT_EQ(WideToUTF16( 172 EXPECT_EQ(WideToUTF16(
177 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), 173 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"),
178 model.GetText()); 174 model.text());
179 175
180 // ReplaceChar will replace the whole grapheme. 176 // ReplaceChar will replace the whole grapheme.
181 model.ReplaceChar('b'); 177 model.ReplaceChar('b');
182 // TODO(xji): temporarily disable in platform Win since the complex script 178 // TODO(xji): temporarily disable in platform Win since the complex script
183 // characters turned into empty square due to font regression. So, not able 179 // characters turned into empty square due to font regression. So, not able
184 // to test 2 characters belong to the same grapheme. 180 // to test 2 characters belong to the same grapheme.
185 #if defined(OS_LINUX) 181 #if defined(OS_LINUX)
186 EXPECT_EQ(WideToUTF16( 182 EXPECT_EQ(WideToUTF16(
187 L"\x0915\x093f\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), 183 L"\x0915\x093f\x0061\x0062\x0915\x0915\x094d\x092e\x094d"),
188 model.GetText()); 184 model.text());
189 #endif 185 #endif
190 EXPECT_EQ(4U, model.GetCursorPosition()); 186 EXPECT_EQ(4U, model.GetCursorPosition());
191 } 187 }
192 188
193 // Delete should delete the whole grapheme. 189 // Delete should delete the whole grapheme.
194 MoveCursorTo(model, 0); 190 MoveCursorTo(model, 0);
195 // TODO(xji): temporarily disable in platform Win since the complex script 191 // TODO(xji): temporarily disable in platform Win since the complex script
196 // characters turned into empty square due to font regression. So, not able 192 // characters turned into empty square due to font regression. So, not able
197 // to test 2 characters belong to the same grapheme. 193 // to test 2 characters belong to the same grapheme.
198 #if defined(OS_LINUX) 194 #if defined(OS_LINUX)
199 EXPECT_TRUE(model.Delete()); 195 EXPECT_TRUE(model.Delete());
200 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), 196 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"),
201 model.GetText()); 197 model.text());
202 MoveCursorTo(model, model.GetText().length()); 198 MoveCursorTo(model, model.text().length());
203 EXPECT_EQ(model.GetText().length(), model.GetCursorPosition()); 199 EXPECT_EQ(model.text().length(), model.GetCursorPosition());
204 EXPECT_TRUE(model.Backspace()); 200 EXPECT_TRUE(model.Backspace());
205 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"), 201 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"), model.text());
206 model.GetText());
207 #endif 202 #endif
208 203
209 // Test cursor position and deletion for Hindi Virama. 204 // Test cursor position and deletion for Hindi Virama.
210 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E")); 205 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E"));
211 MoveCursorTo(model, 0); 206 MoveCursorTo(model, 0);
212 EXPECT_EQ(0U, model.GetCursorPosition()); 207 EXPECT_EQ(0U, model.GetCursorPosition());
213 208
214 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete 209 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete
215 // font support for some scripts - http://crbug.com/106450 210 // font support for some scripts - http://crbug.com/106450
216 if (!on_windows_xp) { 211 if (!on_windows_xp) {
217 MoveCursorTo(model, 1); 212 MoveCursorTo(model, 1);
218 EXPECT_EQ(0U, model.GetCursorPosition()); 213 EXPECT_EQ(0U, model.GetCursorPosition());
219 MoveCursorTo(model, 3); 214 MoveCursorTo(model, 3);
220 EXPECT_EQ(3U, model.GetCursorPosition()); 215 EXPECT_EQ(3U, model.GetCursorPosition());
221 } 216 }
222 217
223 // TODO(asvitkine): Temporarily disable the following check on Windows. It 218 // TODO(asvitkine): Temporarily disable the following check on Windows. It
224 // seems Windows treats "\x0D38\x0D4D\x0D15" as a single grapheme. 219 // seems Windows treats "\x0D38\x0D4D\x0D15" as a single grapheme.
225 #if !defined(OS_WIN) 220 #if !defined(OS_WIN)
226 MoveCursorTo(model, 2); 221 MoveCursorTo(model, 2);
227 EXPECT_EQ(2U, model.GetCursorPosition()); 222 EXPECT_EQ(2U, model.GetCursorPosition());
228 EXPECT_TRUE(model.Backspace()); 223 EXPECT_TRUE(model.Backspace());
229 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText()); 224 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.text());
230 #endif 225 #endif
231 226
232 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9")); 227 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9"));
233 MoveCursorTo(model, 0); 228 MoveCursorTo(model, 0);
234 EXPECT_TRUE(model.Delete()); 229 EXPECT_TRUE(model.Delete());
235 EXPECT_TRUE(model.Delete()); 230 EXPECT_TRUE(model.Delete());
236 EXPECT_TRUE(model.Delete()); 231 EXPECT_TRUE(model.Delete());
237 EXPECT_TRUE(model.Delete()); 232 EXPECT_TRUE(model.Delete());
238 EXPECT_EQ(WideToUTF16(L""), model.GetText()); 233 EXPECT_EQ(WideToUTF16(L""), model.text());
239 234
240 // The first 2 characters are not strong directionality characters. 235 // The first 2 characters are not strong directionality characters.
241 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); 236 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC"));
242 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 237 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
243 EXPECT_TRUE(model.Backspace()); 238 EXPECT_TRUE(model.Backspace());
244 EXPECT_EQ(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"), 239 EXPECT_EQ(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"), model.text());
245 model.GetText());
246 } 240 }
247 241
248 TEST_F(TextfieldViewsModelTest, EmptyString) { 242 TEST_F(TextfieldViewsModelTest, EmptyString) {
249 TextfieldViewsModel model(NULL); 243 TextfieldViewsModel model(NULL);
250 EXPECT_EQ(base::string16(), model.GetText()); 244 EXPECT_EQ(base::string16(), model.text());
251 EXPECT_EQ(base::string16(), model.GetSelectedText()); 245 EXPECT_EQ(base::string16(), model.GetSelectedText());
252 246
253 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 247 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true);
254 EXPECT_EQ(0U, model.GetCursorPosition()); 248 EXPECT_EQ(0U, model.GetCursorPosition());
255 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 249 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
256 EXPECT_EQ(0U, model.GetCursorPosition()); 250 EXPECT_EQ(0U, model.GetCursorPosition());
257 251
258 EXPECT_EQ(base::string16(), model.GetSelectedText()); 252 EXPECT_EQ(base::string16(), model.GetSelectedText());
259 253
260 EXPECT_FALSE(model.Delete()); 254 EXPECT_FALSE(model.Delete());
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 EXPECT_EQ(WideToUTF16(L"a\x05E9" L"b"), model.GetSelectedText()); 382 EXPECT_EQ(WideToUTF16(L"a\x05E9" L"b"), model.GetSelectedText());
389 } 383 }
390 384
391 TEST_F(TextfieldViewsModelTest, SelectionAndEdit) { 385 TEST_F(TextfieldViewsModelTest, SelectionAndEdit) {
392 TextfieldViewsModel model(NULL); 386 TextfieldViewsModel model(NULL);
393 model.Append(ASCIIToUTF16("HELLO")); 387 model.Append(ASCIIToUTF16("HELLO"));
394 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 388 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
395 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 389 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
396 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "EL" 390 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "EL"
397 EXPECT_TRUE(model.Backspace()); 391 EXPECT_TRUE(model.Backspace());
398 EXPECT_STR_EQ("HLO", model.GetText()); 392 EXPECT_STR_EQ("HLO", model.text());
399 393
400 model.Append(ASCIIToUTF16("ILL")); 394 model.Append(ASCIIToUTF16("ILL"));
401 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 395 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
402 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "LO" 396 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "LO"
403 EXPECT_TRUE(model.Delete()); 397 EXPECT_TRUE(model.Delete());
404 EXPECT_STR_EQ("HILL", model.GetText()); 398 EXPECT_STR_EQ("HILL", model.text());
405 EXPECT_EQ(1U, model.GetCursorPosition()); 399 EXPECT_EQ(1U, model.GetCursorPosition());
406 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "I" 400 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "I"
407 model.InsertChar('E'); 401 model.InsertChar('E');
408 EXPECT_STR_EQ("HELL", model.GetText()); 402 EXPECT_STR_EQ("HELL", model.text());
409 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 403 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
410 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "H" 404 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "H"
411 model.ReplaceChar('B'); 405 model.ReplaceChar('B');
412 EXPECT_STR_EQ("BELL", model.GetText()); 406 EXPECT_STR_EQ("BELL", model.text());
413 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 407 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
414 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 408 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true);
415 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); // "ELL" 409 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); // "ELL"
416 model.ReplaceChar('E'); 410 model.ReplaceChar('E');
417 EXPECT_STR_EQ("BEE", model.GetText()); 411 EXPECT_STR_EQ("BEE", model.text());
418 } 412 }
419 413
420 TEST_F(TextfieldViewsModelTest, Word) { 414 TEST_F(TextfieldViewsModelTest, Word) {
421 TextfieldViewsModel model(NULL); 415 TextfieldViewsModel model(NULL);
422 model.Append( 416 model.Append(
423 ASCIIToUTF16("The answer to Life, the Universe, and Everything")); 417 ASCIIToUTF16("The answer to Life, the Universe, and Everything"));
424 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); 418 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false);
425 EXPECT_EQ(3U, model.GetCursorPosition()); 419 EXPECT_EQ(3U, model.GetCursorPosition());
426 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); 420 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false);
427 EXPECT_EQ(10U, model.GetCursorPosition()); 421 EXPECT_EQ(10U, model.GetCursorPosition());
(...skipping 26 matching lines...) Expand all
454 EXPECT_STR_EQ("to Life", model.GetSelectedText()); 448 EXPECT_STR_EQ("to Life", model.GetSelectedText());
455 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 449 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
456 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 450 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
457 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); // Now at start. 451 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); // Now at start.
458 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); 452 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText());
459 // Should be safe to go to the previous word at the beginning. 453 // Should be safe to go to the previous word at the beginning.
460 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 454 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
461 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); 455 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText());
462 model.ReplaceChar('4'); 456 model.ReplaceChar('4');
463 EXPECT_EQ(base::string16(), model.GetSelectedText()); 457 EXPECT_EQ(base::string16(), model.GetSelectedText());
464 EXPECT_STR_EQ("42", model.GetText()); 458 EXPECT_STR_EQ("42", model.text());
465 } 459 }
466 460
467 TEST_F(TextfieldViewsModelTest, SetText) { 461 TEST_F(TextfieldViewsModelTest, SetText) {
468 TextfieldViewsModel model(NULL); 462 TextfieldViewsModel model(NULL);
469 model.Append(ASCIIToUTF16("HELLO")); 463 model.Append(ASCIIToUTF16("HELLO"));
470 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 464 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
471 model.SetText(ASCIIToUTF16("GOODBYE")); 465 model.SetText(ASCIIToUTF16("GOODBYE"));
472 EXPECT_STR_EQ("GOODBYE", model.GetText()); 466 EXPECT_STR_EQ("GOODBYE", model.text());
473 // SetText move the cursor to the end of the new text. 467 // SetText move the cursor to the end of the new text.
474 EXPECT_EQ(7U, model.GetCursorPosition()); 468 EXPECT_EQ(7U, model.GetCursorPosition());
475 model.SelectAll(false); 469 model.SelectAll(false);
476 EXPECT_STR_EQ("GOODBYE", model.GetSelectedText()); 470 EXPECT_STR_EQ("GOODBYE", model.GetSelectedText());
477 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 471 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
478 EXPECT_EQ(7U, model.GetCursorPosition()); 472 EXPECT_EQ(7U, model.GetCursorPosition());
479 473
480 model.SetText(ASCIIToUTF16("BYE")); 474 model.SetText(ASCIIToUTF16("BYE"));
481 // Setting shorter string moves the cursor to the end of the new string. 475 // Setting shorter string moves the cursor to the end of the new string.
482 EXPECT_EQ(3U, model.GetCursorPosition()); 476 EXPECT_EQ(3U, model.GetCursorPosition());
(...skipping 10 matching lines...) Expand all
493 487
494 base::string16 clipboard_text; 488 base::string16 clipboard_text;
495 TextfieldViewsModel model(NULL); 489 TextfieldViewsModel model(NULL);
496 model.Append(ASCIIToUTF16("HELLO WORLD")); 490 model.Append(ASCIIToUTF16("HELLO WORLD"));
497 491
498 // Cut with an empty selection should do nothing. 492 // Cut with an empty selection should do nothing.
499 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 493 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
500 EXPECT_FALSE(model.Cut()); 494 EXPECT_FALSE(model.Cut());
501 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); 495 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text);
502 EXPECT_EQ(initial_clipboard_text, clipboard_text); 496 EXPECT_EQ(initial_clipboard_text, clipboard_text);
503 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); 497 EXPECT_STR_EQ("HELLO WORLD", model.text());
504 EXPECT_EQ(11U, model.GetCursorPosition()); 498 EXPECT_EQ(11U, model.GetCursorPosition());
505 499
506 // Copy with an empty selection should do nothing. 500 // Copy with an empty selection should do nothing.
507 model.Copy(); 501 model.Copy();
508 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); 502 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text);
509 EXPECT_EQ(initial_clipboard_text, clipboard_text); 503 EXPECT_EQ(initial_clipboard_text, clipboard_text);
510 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); 504 EXPECT_STR_EQ("HELLO WORLD", model.text());
511 EXPECT_EQ(11U, model.GetCursorPosition()); 505 EXPECT_EQ(11U, model.GetCursorPosition());
512 506
513 // Cut on obscured (password) text should do nothing. 507 // Cut on obscured (password) text should do nothing.
514 model.render_text()->SetObscured(true); 508 model.render_text()->SetObscured(true);
515 model.SelectAll(false); 509 model.SelectAll(false);
516 EXPECT_FALSE(model.Cut()); 510 EXPECT_FALSE(model.Cut());
517 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); 511 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text);
518 EXPECT_EQ(initial_clipboard_text, clipboard_text); 512 EXPECT_EQ(initial_clipboard_text, clipboard_text);
519 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); 513 EXPECT_STR_EQ("HELLO WORLD", model.text());
520 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText()); 514 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText());
521 515
522 // Copy on obscured text should do nothing. 516 // Copy on obscured text should do nothing.
523 model.SelectAll(false); 517 model.SelectAll(false);
524 EXPECT_FALSE(model.Copy()); 518 EXPECT_FALSE(model.Copy());
525 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); 519 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text);
526 EXPECT_EQ(initial_clipboard_text, clipboard_text); 520 EXPECT_EQ(initial_clipboard_text, clipboard_text);
527 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); 521 EXPECT_STR_EQ("HELLO WORLD", model.text());
528 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText()); 522 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText());
529 523
530 // Cut with non-empty selection. 524 // Cut with non-empty selection.
531 model.render_text()->SetObscured(false); 525 model.render_text()->SetObscured(false);
532 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 526 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
533 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 527 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
534 EXPECT_TRUE(model.Cut()); 528 EXPECT_TRUE(model.Cut());
535 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); 529 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text);
536 EXPECT_STR_EQ("WORLD", clipboard_text); 530 EXPECT_STR_EQ("WORLD", clipboard_text);
537 EXPECT_STR_EQ("HELLO ", model.GetText()); 531 EXPECT_STR_EQ("HELLO ", model.text());
538 EXPECT_EQ(6U, model.GetCursorPosition()); 532 EXPECT_EQ(6U, model.GetCursorPosition());
539 533
540 // Copy with non-empty selection. 534 // Copy with non-empty selection.
541 model.SelectAll(false); 535 model.SelectAll(false);
542 EXPECT_TRUE(model.Copy()); 536 EXPECT_TRUE(model.Copy());
543 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); 537 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text);
544 EXPECT_STR_EQ("HELLO ", clipboard_text); 538 EXPECT_STR_EQ("HELLO ", clipboard_text);
545 EXPECT_STR_EQ("HELLO ", model.GetText()); 539 EXPECT_STR_EQ("HELLO ", model.text());
546 EXPECT_EQ(6U, model.GetCursorPosition()); 540 EXPECT_EQ(6U, model.GetCursorPosition());
547 541
548 // Test that paste works regardless of the obscured bit. 542 // Test that paste works regardless of the obscured bit.
549 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 543 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
550 EXPECT_TRUE(model.Paste()); 544 EXPECT_TRUE(model.Paste());
551 EXPECT_STR_EQ("HELLO HELLO ", model.GetText()); 545 EXPECT_STR_EQ("HELLO HELLO ", model.text());
552 EXPECT_EQ(12U, model.GetCursorPosition()); 546 EXPECT_EQ(12U, model.GetCursorPosition());
553 model.render_text()->SetObscured(true); 547 model.render_text()->SetObscured(true);
554 EXPECT_TRUE(model.Paste()); 548 EXPECT_TRUE(model.Paste());
555 EXPECT_STR_EQ("HELLO HELLO HELLO ", model.GetText()); 549 EXPECT_STR_EQ("HELLO HELLO HELLO ", model.text());
556 EXPECT_EQ(18U, model.GetCursorPosition()); 550 EXPECT_EQ(18U, model.GetCursorPosition());
557 } 551 }
558 552
559 static void SelectWordTestVerifier( 553 static void SelectWordTestVerifier(
560 const TextfieldViewsModel& model, 554 const TextfieldViewsModel& model,
561 const base::string16 &expected_selected_string, 555 const base::string16 &expected_selected_string,
562 size_t expected_cursor_pos) { 556 size_t expected_cursor_pos) {
563 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); 557 EXPECT_EQ(expected_selected_string, model.GetSelectedText());
564 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); 558 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition());
565 } 559 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 composition.underlines.clear(); 843 composition.underlines.clear();
850 composition.underlines.push_back(ui::CompositionUnderline(0, 2, 0, true)); 844 composition.underlines.push_back(ui::CompositionUnderline(0, 2, 0, true));
851 composition.underlines.push_back(ui::CompositionUnderline(2, 3, 0, false)); 845 composition.underlines.push_back(ui::CompositionUnderline(2, 3, 0, false));
852 model.SetCompositionText(composition); 846 model.SetCompositionText(composition);
853 EXPECT_TRUE(model.HasCompositionText()); 847 EXPECT_TRUE(model.HasCompositionText());
854 EXPECT_TRUE(model.HasSelection()); 848 EXPECT_TRUE(model.HasSelection());
855 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection()); 849 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection());
856 850
857 model.GetTextRange(&range); 851 model.GetTextRange(&range);
858 EXPECT_EQ(10U, range.end()); 852 EXPECT_EQ(10U, range.end());
859 EXPECT_STR_EQ("1234567890", model.GetText()); 853 EXPECT_STR_EQ("1234567890", model.text());
860 854
861 model.GetCompositionTextRange(&range); 855 model.GetCompositionTextRange(&range);
862 EXPECT_EQ(gfx::Range(5, 8), range); 856 EXPECT_EQ(gfx::Range(5, 8), range);
863 // composition text 857 // composition text
864 EXPECT_STR_EQ("456", model.GetTextFromRange(gfx::Range(3, 6))); 858 EXPECT_STR_EQ("456", model.GetTextFromRange(gfx::Range(3, 6)));
865 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection()); 859 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection());
866 860
867 EXPECT_FALSE(composition_text_confirmed_or_cleared_); 861 EXPECT_FALSE(composition_text_confirmed_or_cleared_);
868 model.CancelCompositionText(); 862 model.CancelCompositionText();
869 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 863 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
870 composition_text_confirmed_or_cleared_ = false; 864 composition_text_confirmed_or_cleared_ = false;
871 EXPECT_FALSE(model.HasCompositionText()); 865 EXPECT_FALSE(model.HasCompositionText());
872 EXPECT_FALSE(model.HasSelection()); 866 EXPECT_FALSE(model.HasSelection());
873 EXPECT_EQ(5U, model.GetCursorPosition()); 867 EXPECT_EQ(5U, model.GetCursorPosition());
874 868
875 model.SetCompositionText(composition); 869 model.SetCompositionText(composition);
876 EXPECT_STR_EQ("1234567890", model.GetText()); 870 EXPECT_STR_EQ("1234567890", model.text());
877 EXPECT_TRUE(model.SetText(ASCIIToUTF16("1234567890"))); 871 EXPECT_TRUE(model.SetText(ASCIIToUTF16("1234567890")));
878 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 872 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
879 composition_text_confirmed_or_cleared_ = false; 873 composition_text_confirmed_or_cleared_ = false;
880 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 874 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
881 875
882 model.SetCompositionText(composition); 876 model.SetCompositionText(composition);
883 EXPECT_STR_EQ("1234567890678", model.GetText()); 877 EXPECT_STR_EQ("1234567890678", model.text());
884 878
885 model.InsertText(UTF8ToUTF16("-")); 879 model.InsertText(UTF8ToUTF16("-"));
886 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 880 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
887 composition_text_confirmed_or_cleared_ = false; 881 composition_text_confirmed_or_cleared_ = false;
888 EXPECT_STR_EQ("1234567890-", model.GetText()); 882 EXPECT_STR_EQ("1234567890-", model.text());
889 EXPECT_FALSE(model.HasCompositionText()); 883 EXPECT_FALSE(model.HasCompositionText());
890 EXPECT_FALSE(model.HasSelection()); 884 EXPECT_FALSE(model.HasSelection());
891 885
892 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 886 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true);
893 EXPECT_STR_EQ("-", model.GetSelectedText()); 887 EXPECT_STR_EQ("-", model.GetSelectedText());
894 model.SetCompositionText(composition); 888 model.SetCompositionText(composition);
895 EXPECT_STR_EQ("1234567890678", model.GetText()); 889 EXPECT_STR_EQ("1234567890678", model.text());
896 890
897 model.ReplaceText(UTF8ToUTF16("-")); 891 model.ReplaceText(UTF8ToUTF16("-"));
898 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 892 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
899 composition_text_confirmed_or_cleared_ = false; 893 composition_text_confirmed_or_cleared_ = false;
900 EXPECT_STR_EQ("1234567890-", model.GetText()); 894 EXPECT_STR_EQ("1234567890-", model.text());
901 EXPECT_FALSE(model.HasCompositionText()); 895 EXPECT_FALSE(model.HasCompositionText());
902 EXPECT_FALSE(model.HasSelection()); 896 EXPECT_FALSE(model.HasSelection());
903 897
904 model.SetCompositionText(composition); 898 model.SetCompositionText(composition);
905 model.Append(UTF8ToUTF16("-")); 899 model.Append(UTF8ToUTF16("-"));
906 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 900 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
907 composition_text_confirmed_or_cleared_ = false; 901 composition_text_confirmed_or_cleared_ = false;
908 EXPECT_STR_EQ("1234567890-678-", model.GetText()); 902 EXPECT_STR_EQ("1234567890-678-", model.text());
909 903
910 model.SetCompositionText(composition); 904 model.SetCompositionText(composition);
911 model.Delete(); 905 model.Delete();
912 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 906 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
913 composition_text_confirmed_or_cleared_ = false; 907 composition_text_confirmed_or_cleared_ = false;
914 EXPECT_STR_EQ("1234567890-678-", model.GetText()); 908 EXPECT_STR_EQ("1234567890-678-", model.text());
915 909
916 model.SetCompositionText(composition); 910 model.SetCompositionText(composition);
917 model.Backspace(); 911 model.Backspace();
918 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 912 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
919 composition_text_confirmed_or_cleared_ = false; 913 composition_text_confirmed_or_cleared_ = false;
920 EXPECT_STR_EQ("1234567890-678-", model.GetText()); 914 EXPECT_STR_EQ("1234567890-678-", model.text());
921 915
922 model.SetText(base::string16()); 916 model.SetText(base::string16());
923 model.SetCompositionText(composition); 917 model.SetCompositionText(composition);
924 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); 918 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false);
925 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 919 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
926 composition_text_confirmed_or_cleared_ = false; 920 composition_text_confirmed_or_cleared_ = false;
927 EXPECT_STR_EQ("678", model.GetText()); 921 EXPECT_STR_EQ("678", model.text());
928 EXPECT_EQ(2U, model.GetCursorPosition()); 922 EXPECT_EQ(2U, model.GetCursorPosition());
929 923
930 model.SetCompositionText(composition); 924 model.SetCompositionText(composition);
931 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 925 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
932 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 926 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
933 composition_text_confirmed_or_cleared_ = false; 927 composition_text_confirmed_or_cleared_ = false;
934 EXPECT_STR_EQ("676788", model.GetText()); 928 EXPECT_STR_EQ("676788", model.text());
935 EXPECT_EQ(6U, model.GetCursorPosition()); 929 EXPECT_EQ(6U, model.GetCursorPosition());
936 930
937 model.SetCompositionText(composition); 931 model.SetCompositionText(composition);
938 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false); 932 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false);
939 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 933 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
940 composition_text_confirmed_or_cleared_ = false; 934 composition_text_confirmed_or_cleared_ = false;
941 EXPECT_STR_EQ("676788678", model.GetText()); 935 EXPECT_STR_EQ("676788678", model.text());
942 936
943 model.SetText(base::string16()); 937 model.SetText(base::string16());
944 model.SetCompositionText(composition); 938 model.SetCompositionText(composition);
945 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); 939 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false);
946 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 940 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
947 composition_text_confirmed_or_cleared_ = false; 941 composition_text_confirmed_or_cleared_ = false;
948 942
949 model.SetCompositionText(composition); 943 model.SetCompositionText(composition);
950 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); 944 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true);
951 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 945 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
952 composition_text_confirmed_or_cleared_ = false; 946 composition_text_confirmed_or_cleared_ = false;
953 EXPECT_STR_EQ("678678", model.GetText()); 947 EXPECT_STR_EQ("678678", model.text());
954 948
955 model.SetCompositionText(composition); 949 model.SetCompositionText(composition);
956 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 950 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
957 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 951 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
958 composition_text_confirmed_or_cleared_ = false; 952 composition_text_confirmed_or_cleared_ = false;
959 EXPECT_STR_EQ("678", model.GetText()); 953 EXPECT_STR_EQ("678", model.text());
960 954
961 model.SetCompositionText(composition); 955 model.SetCompositionText(composition);
962 gfx::SelectionModel sel( 956 gfx::SelectionModel sel(
963 gfx::Range(model.render_text()->selection().start(), 0), 957 gfx::Range(model.render_text()->selection().start(), 0),
964 gfx::CURSOR_FORWARD); 958 gfx::CURSOR_FORWARD);
965 model.MoveCursorTo(sel); 959 model.MoveCursorTo(sel);
966 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 960 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
967 composition_text_confirmed_or_cleared_ = false; 961 composition_text_confirmed_or_cleared_ = false;
968 EXPECT_STR_EQ("678678", model.GetText()); 962 EXPECT_STR_EQ("678678", model.text());
969 963
970 model.SetCompositionText(composition); 964 model.SetCompositionText(composition);
971 model.SelectRange(gfx::Range(0, 3)); 965 model.SelectRange(gfx::Range(0, 3));
972 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 966 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
973 composition_text_confirmed_or_cleared_ = false; 967 composition_text_confirmed_or_cleared_ = false;
974 EXPECT_STR_EQ("678", model.GetText()); 968 EXPECT_STR_EQ("678", model.text());
975 969
976 model.SetCompositionText(composition); 970 model.SetCompositionText(composition);
977 model.SelectAll(false); 971 model.SelectAll(false);
978 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 972 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
979 composition_text_confirmed_or_cleared_ = false; 973 composition_text_confirmed_or_cleared_ = false;
980 EXPECT_STR_EQ("678", model.GetText()); 974 EXPECT_STR_EQ("678", model.text());
981 975
982 model.SetCompositionText(composition); 976 model.SetCompositionText(composition);
983 model.SelectWord(); 977 model.SelectWord();
984 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 978 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
985 composition_text_confirmed_or_cleared_ = false; 979 composition_text_confirmed_or_cleared_ = false;
986 EXPECT_STR_EQ("678", model.GetText()); 980 EXPECT_STR_EQ("678", model.text());
987 981
988 model.SetCompositionText(composition); 982 model.SetCompositionText(composition);
989 model.ClearSelection(); 983 model.ClearSelection();
990 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 984 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
991 composition_text_confirmed_or_cleared_ = false; 985 composition_text_confirmed_or_cleared_ = false;
992 986
993 model.SetCompositionText(composition); 987 model.SetCompositionText(composition);
994 EXPECT_FALSE(model.Cut()); 988 EXPECT_FALSE(model.Cut());
995 EXPECT_FALSE(composition_text_confirmed_or_cleared_); 989 EXPECT_FALSE(composition_text_confirmed_or_cleared_);
996 } 990 }
997 991
998 TEST_F(TextfieldViewsModelTest, UndoRedo_BasicTest) { 992 TEST_F(TextfieldViewsModelTest, UndoRedo_BasicTest) {
999 TextfieldViewsModel model(NULL); 993 TextfieldViewsModel model(NULL);
1000 model.InsertChar('a'); 994 model.InsertChar('a');
1001 EXPECT_FALSE(model.Redo()); // nothing to redo 995 EXPECT_FALSE(model.Redo()); // nothing to redo
1002 EXPECT_TRUE(model.Undo()); 996 EXPECT_TRUE(model.Undo());
1003 EXPECT_STR_EQ("", model.GetText()); 997 EXPECT_STR_EQ("", model.text());
1004 EXPECT_TRUE(model.Redo()); 998 EXPECT_TRUE(model.Redo());
1005 EXPECT_STR_EQ("a", model.GetText()); 999 EXPECT_STR_EQ("a", model.text());
1006 1000
1007 // Continuous inserts are treated as one edit. 1001 // Continuous inserts are treated as one edit.
1008 model.InsertChar('b'); 1002 model.InsertChar('b');
1009 model.InsertChar('c'); 1003 model.InsertChar('c');
1010 EXPECT_STR_EQ("abc", model.GetText()); 1004 EXPECT_STR_EQ("abc", model.text());
1011 EXPECT_TRUE(model.Undo()); 1005 EXPECT_TRUE(model.Undo());
1012 EXPECT_STR_EQ("a", model.GetText()); 1006 EXPECT_STR_EQ("a", model.text());
1013 EXPECT_EQ(1U, model.GetCursorPosition()); 1007 EXPECT_EQ(1U, model.GetCursorPosition());
1014 EXPECT_TRUE(model.Undo()); 1008 EXPECT_TRUE(model.Undo());
1015 EXPECT_STR_EQ("", model.GetText()); 1009 EXPECT_STR_EQ("", model.text());
1016 EXPECT_EQ(0U, model.GetCursorPosition()); 1010 EXPECT_EQ(0U, model.GetCursorPosition());
1017 1011
1018 // Undoing further shouldn't change the text. 1012 // Undoing further shouldn't change the text.
1019 EXPECT_FALSE(model.Undo()); 1013 EXPECT_FALSE(model.Undo());
1020 EXPECT_STR_EQ("", model.GetText()); 1014 EXPECT_STR_EQ("", model.text());
1021 EXPECT_FALSE(model.Undo()); 1015 EXPECT_FALSE(model.Undo());
1022 EXPECT_STR_EQ("", model.GetText()); 1016 EXPECT_STR_EQ("", model.text());
1023 EXPECT_EQ(0U, model.GetCursorPosition()); 1017 EXPECT_EQ(0U, model.GetCursorPosition());
1024 1018
1025 // Redoing to the latest text. 1019 // Redoing to the latest text.
1026 EXPECT_TRUE(model.Redo()); 1020 EXPECT_TRUE(model.Redo());
1027 EXPECT_STR_EQ("a", model.GetText()); 1021 EXPECT_STR_EQ("a", model.text());
1028 EXPECT_EQ(1U, model.GetCursorPosition()); 1022 EXPECT_EQ(1U, model.GetCursorPosition());
1029 EXPECT_TRUE(model.Redo()); 1023 EXPECT_TRUE(model.Redo());
1030 EXPECT_STR_EQ("abc", model.GetText()); 1024 EXPECT_STR_EQ("abc", model.text());
1031 EXPECT_EQ(3U, model.GetCursorPosition()); 1025 EXPECT_EQ(3U, model.GetCursorPosition());
1032 1026
1033 // Backspace =============================== 1027 // Backspace ===============================
1034 EXPECT_TRUE(model.Backspace()); 1028 EXPECT_TRUE(model.Backspace());
1035 EXPECT_STR_EQ("ab", model.GetText()); 1029 EXPECT_STR_EQ("ab", model.text());
1036 EXPECT_TRUE(model.Undo()); 1030 EXPECT_TRUE(model.Undo());
1037 EXPECT_STR_EQ("abc", model.GetText()); 1031 EXPECT_STR_EQ("abc", model.text());
1038 EXPECT_EQ(3U, model.GetCursorPosition()); 1032 EXPECT_EQ(3U, model.GetCursorPosition());
1039 EXPECT_TRUE(model.Redo()); 1033 EXPECT_TRUE(model.Redo());
1040 EXPECT_STR_EQ("ab", model.GetText()); 1034 EXPECT_STR_EQ("ab", model.text());
1041 EXPECT_EQ(2U, model.GetCursorPosition()); 1035 EXPECT_EQ(2U, model.GetCursorPosition());
1042 // Continous backspaces are treated as one edit. 1036 // Continous backspaces are treated as one edit.
1043 EXPECT_TRUE(model.Backspace()); 1037 EXPECT_TRUE(model.Backspace());
1044 EXPECT_TRUE(model.Backspace()); 1038 EXPECT_TRUE(model.Backspace());
1045 EXPECT_STR_EQ("", model.GetText()); 1039 EXPECT_STR_EQ("", model.text());
1046 // Extra backspace shouldn't affect the history. 1040 // Extra backspace shouldn't affect the history.
1047 EXPECT_FALSE(model.Backspace()); 1041 EXPECT_FALSE(model.Backspace());
1048 EXPECT_TRUE(model.Undo()); 1042 EXPECT_TRUE(model.Undo());
1049 EXPECT_STR_EQ("ab", model.GetText()); 1043 EXPECT_STR_EQ("ab", model.text());
1050 EXPECT_EQ(2U, model.GetCursorPosition()); 1044 EXPECT_EQ(2U, model.GetCursorPosition());
1051 EXPECT_TRUE(model.Undo()); 1045 EXPECT_TRUE(model.Undo());
1052 EXPECT_STR_EQ("abc", model.GetText()); 1046 EXPECT_STR_EQ("abc", model.text());
1053 EXPECT_EQ(3U, model.GetCursorPosition()); 1047 EXPECT_EQ(3U, model.GetCursorPosition());
1054 EXPECT_TRUE(model.Undo()); 1048 EXPECT_TRUE(model.Undo());
1055 EXPECT_STR_EQ("a", model.GetText()); 1049 EXPECT_STR_EQ("a", model.text());
1056 EXPECT_EQ(1U, model.GetCursorPosition()); 1050 EXPECT_EQ(1U, model.GetCursorPosition());
1057 1051
1058 // Clear history 1052 // Clear history
1059 model.ClearEditHistory(); 1053 model.ClearEditHistory();
1060 EXPECT_FALSE(model.Undo()); 1054 EXPECT_FALSE(model.Undo());
1061 EXPECT_FALSE(model.Redo()); 1055 EXPECT_FALSE(model.Redo());
1062 EXPECT_STR_EQ("a", model.GetText()); 1056 EXPECT_STR_EQ("a", model.text());
1063 EXPECT_EQ(1U, model.GetCursorPosition()); 1057 EXPECT_EQ(1U, model.GetCursorPosition());
1064 1058
1065 // Delete =============================== 1059 // Delete ===============================
1066 model.SetText(ASCIIToUTF16("ABCDE")); 1060 model.SetText(ASCIIToUTF16("ABCDE"));
1067 model.ClearEditHistory(); 1061 model.ClearEditHistory();
1068 MoveCursorTo(model, 2); 1062 MoveCursorTo(model, 2);
1069 EXPECT_TRUE(model.Delete()); 1063 EXPECT_TRUE(model.Delete());
1070 EXPECT_STR_EQ("ABDE", model.GetText()); 1064 EXPECT_STR_EQ("ABDE", model.text());
1071 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 1065 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
1072 EXPECT_TRUE(model.Delete()); 1066 EXPECT_TRUE(model.Delete());
1073 EXPECT_STR_EQ("BDE", model.GetText()); 1067 EXPECT_STR_EQ("BDE", model.text());
1074 EXPECT_TRUE(model.Undo()); 1068 EXPECT_TRUE(model.Undo());
1075 EXPECT_STR_EQ("ABDE", model.GetText()); 1069 EXPECT_STR_EQ("ABDE", model.text());
1076 EXPECT_EQ(0U, model.GetCursorPosition()); 1070 EXPECT_EQ(0U, model.GetCursorPosition());
1077 EXPECT_TRUE(model.Undo()); 1071 EXPECT_TRUE(model.Undo());
1078 EXPECT_STR_EQ("ABCDE", model.GetText()); 1072 EXPECT_STR_EQ("ABCDE", model.text());
1079 EXPECT_EQ(2U, model.GetCursorPosition()); 1073 EXPECT_EQ(2U, model.GetCursorPosition());
1080 EXPECT_TRUE(model.Redo()); 1074 EXPECT_TRUE(model.Redo());
1081 EXPECT_STR_EQ("ABDE", model.GetText()); 1075 EXPECT_STR_EQ("ABDE", model.text());
1082 EXPECT_EQ(2U, model.GetCursorPosition()); 1076 EXPECT_EQ(2U, model.GetCursorPosition());
1083 // Continous deletes are treated as one edit. 1077 // Continous deletes are treated as one edit.
1084 EXPECT_TRUE(model.Delete()); 1078 EXPECT_TRUE(model.Delete());
1085 EXPECT_TRUE(model.Delete()); 1079 EXPECT_TRUE(model.Delete());
1086 EXPECT_STR_EQ("AB", model.GetText()); 1080 EXPECT_STR_EQ("AB", model.text());
1087 EXPECT_TRUE(model.Undo()); 1081 EXPECT_TRUE(model.Undo());
1088 EXPECT_STR_EQ("ABDE", model.GetText()); 1082 EXPECT_STR_EQ("ABDE", model.text());
1089 EXPECT_EQ(2U, model.GetCursorPosition()); 1083 EXPECT_EQ(2U, model.GetCursorPosition());
1090 EXPECT_TRUE(model.Redo()); 1084 EXPECT_TRUE(model.Redo());
1091 EXPECT_STR_EQ("AB", model.GetText()); 1085 EXPECT_STR_EQ("AB", model.text());
1092 EXPECT_EQ(2U, model.GetCursorPosition()); 1086 EXPECT_EQ(2U, model.GetCursorPosition());
1093 } 1087 }
1094 1088
1095 TEST_F(TextfieldViewsModelTest, UndoRedo_SetText) { 1089 TEST_F(TextfieldViewsModelTest, UndoRedo_SetText) {
1096 // This is to test the undo/redo behavior of omnibox. 1090 // This is to test the undo/redo behavior of omnibox.
1097 TextfieldViewsModel model(NULL); 1091 TextfieldViewsModel model(NULL);
1098 model.InsertChar('w'); 1092 model.InsertChar('w');
1099 EXPECT_STR_EQ("w", model.GetText()); 1093 EXPECT_STR_EQ("w", model.text());
1100 EXPECT_EQ(1U, model.GetCursorPosition()); 1094 EXPECT_EQ(1U, model.GetCursorPosition());
1101 model.SetText(ASCIIToUTF16("www.google.com")); 1095 model.SetText(ASCIIToUTF16("www.google.com"));
1102 EXPECT_EQ(14U, model.GetCursorPosition()); 1096 EXPECT_EQ(14U, model.GetCursorPosition());
1103 EXPECT_STR_EQ("www.google.com", model.GetText()); 1097 EXPECT_STR_EQ("www.google.com", model.text());
1104 model.SelectRange(gfx::Range(14, 1)); 1098 model.SelectRange(gfx::Range(14, 1));
1105 model.InsertChar('w'); 1099 model.InsertChar('w');
1106 EXPECT_STR_EQ("ww", model.GetText()); 1100 EXPECT_STR_EQ("ww", model.text());
1107 model.SetText(ASCIIToUTF16("www.google.com")); 1101 model.SetText(ASCIIToUTF16("www.google.com"));
1108 model.SelectRange(gfx::Range(14, 2)); 1102 model.SelectRange(gfx::Range(14, 2));
1109 model.InsertChar('w'); 1103 model.InsertChar('w');
1110 EXPECT_STR_EQ("www", model.GetText()); 1104 EXPECT_STR_EQ("www", model.text());
1111 model.SetText(ASCIIToUTF16("www.google.com")); 1105 model.SetText(ASCIIToUTF16("www.google.com"));
1112 model.SelectRange(gfx::Range(14, 3)); 1106 model.SelectRange(gfx::Range(14, 3));
1113 model.InsertChar('.'); 1107 model.InsertChar('.');
1114 EXPECT_STR_EQ("www.", model.GetText()); 1108 EXPECT_STR_EQ("www.", model.text());
1115 model.SetText(ASCIIToUTF16("www.google.com")); 1109 model.SetText(ASCIIToUTF16("www.google.com"));
1116 model.SelectRange(gfx::Range(14, 4)); 1110 model.SelectRange(gfx::Range(14, 4));
1117 model.InsertChar('y'); 1111 model.InsertChar('y');
1118 EXPECT_STR_EQ("www.y", model.GetText()); 1112 EXPECT_STR_EQ("www.y", model.text());
1119 model.SetText(ASCIIToUTF16("www.youtube.com")); 1113 model.SetText(ASCIIToUTF16("www.youtube.com"));
1120 EXPECT_STR_EQ("www.youtube.com", model.GetText()); 1114 EXPECT_STR_EQ("www.youtube.com", model.text());
1121 EXPECT_EQ(15U, model.GetCursorPosition()); 1115 EXPECT_EQ(15U, model.GetCursorPosition());
1122 1116
1123 EXPECT_TRUE(model.Undo()); 1117 EXPECT_TRUE(model.Undo());
1124 EXPECT_STR_EQ("www.google.com", model.GetText()); 1118 EXPECT_STR_EQ("www.google.com", model.text());
1125 EXPECT_EQ(4U, model.GetCursorPosition()); 1119 EXPECT_EQ(4U, model.GetCursorPosition());
1126 EXPECT_TRUE(model.Undo()); 1120 EXPECT_TRUE(model.Undo());
1127 EXPECT_STR_EQ("www.google.com", model.GetText()); 1121 EXPECT_STR_EQ("www.google.com", model.text());
1128 EXPECT_EQ(3U, model.GetCursorPosition()); 1122 EXPECT_EQ(3U, model.GetCursorPosition());
1129 EXPECT_TRUE(model.Undo()); 1123 EXPECT_TRUE(model.Undo());
1130 EXPECT_STR_EQ("www.google.com", model.GetText()); 1124 EXPECT_STR_EQ("www.google.com", model.text());
1131 EXPECT_EQ(2U, model.GetCursorPosition()); 1125 EXPECT_EQ(2U, model.GetCursorPosition());
1132 EXPECT_TRUE(model.Undo()); 1126 EXPECT_TRUE(model.Undo());
1133 EXPECT_STR_EQ("www.google.com", model.GetText()); 1127 EXPECT_STR_EQ("www.google.com", model.text());
1134 EXPECT_EQ(1U, model.GetCursorPosition()); 1128 EXPECT_EQ(1U, model.GetCursorPosition());
1135 EXPECT_TRUE(model.Undo()); 1129 EXPECT_TRUE(model.Undo());
1136 EXPECT_STR_EQ("", model.GetText()); 1130 EXPECT_STR_EQ("", model.text());
1137 EXPECT_EQ(0U, model.GetCursorPosition()); 1131 EXPECT_EQ(0U, model.GetCursorPosition());
1138 EXPECT_FALSE(model.Undo()); 1132 EXPECT_FALSE(model.Undo());
1139 EXPECT_TRUE(model.Redo()); 1133 EXPECT_TRUE(model.Redo());
1140 EXPECT_STR_EQ("www.google.com", model.GetText()); 1134 EXPECT_STR_EQ("www.google.com", model.text());
1141 EXPECT_EQ(1U, model.GetCursorPosition()); 1135 EXPECT_EQ(1U, model.GetCursorPosition());
1142 EXPECT_TRUE(model.Redo()); 1136 EXPECT_TRUE(model.Redo());
1143 EXPECT_STR_EQ("www.google.com", model.GetText()); 1137 EXPECT_STR_EQ("www.google.com", model.text());
1144 EXPECT_EQ(2U, model.GetCursorPosition()); 1138 EXPECT_EQ(2U, model.GetCursorPosition());
1145 EXPECT_TRUE(model.Redo()); 1139 EXPECT_TRUE(model.Redo());
1146 EXPECT_STR_EQ("www.google.com", model.GetText()); 1140 EXPECT_STR_EQ("www.google.com", model.text());
1147 EXPECT_EQ(3U, model.GetCursorPosition()); 1141 EXPECT_EQ(3U, model.GetCursorPosition());
1148 EXPECT_TRUE(model.Redo()); 1142 EXPECT_TRUE(model.Redo());
1149 EXPECT_STR_EQ("www.google.com", model.GetText()); 1143 EXPECT_STR_EQ("www.google.com", model.text());
1150 EXPECT_EQ(4U, model.GetCursorPosition()); 1144 EXPECT_EQ(4U, model.GetCursorPosition());
1151 EXPECT_TRUE(model.Redo()); 1145 EXPECT_TRUE(model.Redo());
1152 EXPECT_STR_EQ("www.youtube.com", model.GetText()); 1146 EXPECT_STR_EQ("www.youtube.com", model.text());
1153 EXPECT_EQ(5U, model.GetCursorPosition()); 1147 EXPECT_EQ(5U, model.GetCursorPosition());
1154 EXPECT_FALSE(model.Redo()); 1148 EXPECT_FALSE(model.Redo());
1155 } 1149 }
1156 1150
1157 TEST_F(TextfieldViewsModelTest, UndoRedo_BackspaceThenSetText) { 1151 TEST_F(TextfieldViewsModelTest, UndoRedo_BackspaceThenSetText) {
1158 // This is to test the undo/redo behavior of omnibox. 1152 // This is to test the undo/redo behavior of omnibox.
1159 TextfieldViewsModel model(NULL); 1153 TextfieldViewsModel model(NULL);
1160 model.InsertChar('w'); 1154 model.InsertChar('w');
1161 EXPECT_STR_EQ("w", model.GetText()); 1155 EXPECT_STR_EQ("w", model.text());
1162 EXPECT_EQ(1U, model.GetCursorPosition()); 1156 EXPECT_EQ(1U, model.GetCursorPosition());
1163 model.SetText(ASCIIToUTF16("www.google.com")); 1157 model.SetText(ASCIIToUTF16("www.google.com"));
1164 EXPECT_EQ(14U, model.GetCursorPosition()); 1158 EXPECT_EQ(14U, model.GetCursorPosition());
1165 EXPECT_STR_EQ("www.google.com", model.GetText()); 1159 EXPECT_STR_EQ("www.google.com", model.text());
1166 model.SetText(ASCIIToUTF16("www.google.com")); // Confirm the text. 1160 model.SetText(ASCIIToUTF16("www.google.com")); // Confirm the text.
1167 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1161 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
1168 EXPECT_EQ(14U, model.GetCursorPosition()); 1162 EXPECT_EQ(14U, model.GetCursorPosition());
1169 EXPECT_TRUE(model.Backspace()); 1163 EXPECT_TRUE(model.Backspace());
1170 EXPECT_TRUE(model.Backspace()); 1164 EXPECT_TRUE(model.Backspace());
1171 EXPECT_STR_EQ("www.google.c", model.GetText()); 1165 EXPECT_STR_EQ("www.google.c", model.text());
1172 // Autocomplete sets the text 1166 // Autocomplete sets the text
1173 model.SetText(ASCIIToUTF16("www.google.com/search=www.google.c")); 1167 model.SetText(ASCIIToUTF16("www.google.com/search=www.google.c"));
1174 EXPECT_STR_EQ("www.google.com/search=www.google.c", model.GetText()); 1168 EXPECT_STR_EQ("www.google.com/search=www.google.c", model.text());
1175 EXPECT_TRUE(model.Undo()); 1169 EXPECT_TRUE(model.Undo());
1176 EXPECT_STR_EQ("www.google.c", model.GetText()); 1170 EXPECT_STR_EQ("www.google.c", model.text());
1177 EXPECT_TRUE(model.Undo()); 1171 EXPECT_TRUE(model.Undo());
1178 EXPECT_STR_EQ("www.google.com", model.GetText()); 1172 EXPECT_STR_EQ("www.google.com", model.text());
1179 } 1173 }
1180 1174
1181 TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) { 1175 TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) {
1182 TextfieldViewsModel model(NULL); 1176 TextfieldViewsModel model(NULL);
1183 model.SetText(ASCIIToUTF16("ABCDE")); 1177 model.SetText(ASCIIToUTF16("ABCDE"));
1184 EXPECT_FALSE(model.Redo()); // nothing to redo 1178 EXPECT_FALSE(model.Redo()); // nothing to redo
1185 // Cut 1179 // Cut
1186 model.SelectRange(gfx::Range(1, 3)); 1180 model.SelectRange(gfx::Range(1, 3));
1187 model.Cut(); 1181 model.Cut();
1188 EXPECT_STR_EQ("ADE", model.GetText()); 1182 EXPECT_STR_EQ("ADE", model.text());
1189 EXPECT_EQ(1U, model.GetCursorPosition()); 1183 EXPECT_EQ(1U, model.GetCursorPosition());
1190 EXPECT_TRUE(model.Undo()); 1184 EXPECT_TRUE(model.Undo());
1191 EXPECT_STR_EQ("ABCDE", model.GetText()); 1185 EXPECT_STR_EQ("ABCDE", model.text());
1192 EXPECT_EQ(3U, model.GetCursorPosition()); 1186 EXPECT_EQ(3U, model.GetCursorPosition());
1193 EXPECT_TRUE(model.Undo()); 1187 EXPECT_TRUE(model.Undo());
1194 EXPECT_STR_EQ("", model.GetText()); 1188 EXPECT_STR_EQ("", model.text());
1195 EXPECT_EQ(0U, model.GetCursorPosition()); 1189 EXPECT_EQ(0U, model.GetCursorPosition());
1196 EXPECT_FALSE(model.Undo()); // no more undo 1190 EXPECT_FALSE(model.Undo()); // no more undo
1197 EXPECT_STR_EQ("", model.GetText()); 1191 EXPECT_STR_EQ("", model.text());
1198 EXPECT_TRUE(model.Redo()); 1192 EXPECT_TRUE(model.Redo());
1199 EXPECT_STR_EQ("ABCDE", model.GetText()); 1193 EXPECT_STR_EQ("ABCDE", model.text());
1200 EXPECT_EQ(5U, model.GetCursorPosition()); 1194 EXPECT_EQ(5U, model.GetCursorPosition());
1201 EXPECT_TRUE(model.Redo()); 1195 EXPECT_TRUE(model.Redo());
1202 EXPECT_STR_EQ("ADE", model.GetText()); 1196 EXPECT_STR_EQ("ADE", model.text());
1203 EXPECT_EQ(1U, model.GetCursorPosition()); 1197 EXPECT_EQ(1U, model.GetCursorPosition());
1204 EXPECT_FALSE(model.Redo()); // no more redo 1198 EXPECT_FALSE(model.Redo()); // no more redo
1205 EXPECT_STR_EQ("ADE", model.GetText()); 1199 EXPECT_STR_EQ("ADE", model.text());
1206 1200
1207 model.Paste(); 1201 model.Paste();
1208 model.Paste(); 1202 model.Paste();
1209 model.Paste(); 1203 model.Paste();
1210 EXPECT_STR_EQ("ABCBCBCDE", model.GetText()); 1204 EXPECT_STR_EQ("ABCBCBCDE", model.text());
1211 EXPECT_EQ(7U, model.GetCursorPosition()); 1205 EXPECT_EQ(7U, model.GetCursorPosition());
1212 EXPECT_TRUE(model.Undo()); 1206 EXPECT_TRUE(model.Undo());
1213 EXPECT_STR_EQ("ABCBCDE", model.GetText()); 1207 EXPECT_STR_EQ("ABCBCDE", model.text());
1214 EXPECT_EQ(5U, model.GetCursorPosition()); 1208 EXPECT_EQ(5U, model.GetCursorPosition());
1215 EXPECT_TRUE(model.Undo()); 1209 EXPECT_TRUE(model.Undo());
1216 EXPECT_STR_EQ("ABCDE", model.GetText()); 1210 EXPECT_STR_EQ("ABCDE", model.text());
1217 EXPECT_EQ(3U, model.GetCursorPosition()); 1211 EXPECT_EQ(3U, model.GetCursorPosition());
1218 EXPECT_TRUE(model.Undo()); 1212 EXPECT_TRUE(model.Undo());
1219 EXPECT_STR_EQ("ADE", model.GetText()); 1213 EXPECT_STR_EQ("ADE", model.text());
1220 EXPECT_EQ(1U, model.GetCursorPosition()); 1214 EXPECT_EQ(1U, model.GetCursorPosition());
1221 EXPECT_TRUE(model.Undo()); 1215 EXPECT_TRUE(model.Undo());
1222 EXPECT_STR_EQ("ABCDE", model.GetText()); 1216 EXPECT_STR_EQ("ABCDE", model.text());
1223 EXPECT_EQ(3U, model.GetCursorPosition()); 1217 EXPECT_EQ(3U, model.GetCursorPosition());
1224 EXPECT_TRUE(model.Undo()); 1218 EXPECT_TRUE(model.Undo());
1225 EXPECT_STR_EQ("", model.GetText()); 1219 EXPECT_STR_EQ("", model.text());
1226 EXPECT_EQ(0U, model.GetCursorPosition()); 1220 EXPECT_EQ(0U, model.GetCursorPosition());
1227 EXPECT_FALSE(model.Undo()); 1221 EXPECT_FALSE(model.Undo());
1228 EXPECT_STR_EQ("", model.GetText()); 1222 EXPECT_STR_EQ("", model.text());
1229 EXPECT_TRUE(model.Redo()); 1223 EXPECT_TRUE(model.Redo());
1230 EXPECT_STR_EQ("ABCDE", model.GetText()); // Redoing SetText 1224 EXPECT_STR_EQ("ABCDE", model.text()); // Redoing SetText
1231 EXPECT_EQ(5U, model.GetCursorPosition()); 1225 EXPECT_EQ(5U, model.GetCursorPosition());
1232 1226
1233 // Redo 1227 // Redo
1234 EXPECT_TRUE(model.Redo()); 1228 EXPECT_TRUE(model.Redo());
1235 EXPECT_STR_EQ("ADE", model.GetText()); 1229 EXPECT_STR_EQ("ADE", model.text());
1236 EXPECT_EQ(1U, model.GetCursorPosition()); 1230 EXPECT_EQ(1U, model.GetCursorPosition());
1237 EXPECT_TRUE(model.Redo()); 1231 EXPECT_TRUE(model.Redo());
1238 EXPECT_STR_EQ("ABCDE", model.GetText()); 1232 EXPECT_STR_EQ("ABCDE", model.text());
1239 EXPECT_EQ(3U, model.GetCursorPosition()); 1233 EXPECT_EQ(3U, model.GetCursorPosition());
1240 EXPECT_TRUE(model.Redo()); 1234 EXPECT_TRUE(model.Redo());
1241 EXPECT_STR_EQ("ABCBCDE", model.GetText()); 1235 EXPECT_STR_EQ("ABCBCDE", model.text());
1242 EXPECT_EQ(5U, model.GetCursorPosition()); 1236 EXPECT_EQ(5U, model.GetCursorPosition());
1243 EXPECT_TRUE(model.Redo()); 1237 EXPECT_TRUE(model.Redo());
1244 EXPECT_STR_EQ("ABCBCBCDE", model.GetText()); 1238 EXPECT_STR_EQ("ABCBCBCDE", model.text());
1245 EXPECT_EQ(7U, model.GetCursorPosition()); 1239 EXPECT_EQ(7U, model.GetCursorPosition());
1246 EXPECT_FALSE(model.Redo()); 1240 EXPECT_FALSE(model.Redo());
1247 1241
1248 // with SelectRange 1242 // with SelectRange
1249 model.SelectRange(gfx::Range(1, 3)); 1243 model.SelectRange(gfx::Range(1, 3));
1250 EXPECT_TRUE(model.Cut()); 1244 EXPECT_TRUE(model.Cut());
1251 EXPECT_STR_EQ("ABCBCDE", model.GetText()); 1245 EXPECT_STR_EQ("ABCBCDE", model.text());
1252 EXPECT_EQ(1U, model.GetCursorPosition()); 1246 EXPECT_EQ(1U, model.GetCursorPosition());
1253 model.SelectRange(gfx::Range(1, 1)); 1247 model.SelectRange(gfx::Range(1, 1));
1254 EXPECT_FALSE(model.Cut()); 1248 EXPECT_FALSE(model.Cut());
1255 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1249 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
1256 EXPECT_TRUE(model.Paste()); 1250 EXPECT_TRUE(model.Paste());
1257 EXPECT_STR_EQ("ABCBCDEBC", model.GetText()); 1251 EXPECT_STR_EQ("ABCBCDEBC", model.text());
1258 EXPECT_EQ(9U, model.GetCursorPosition()); 1252 EXPECT_EQ(9U, model.GetCursorPosition());
1259 EXPECT_TRUE(model.Undo()); 1253 EXPECT_TRUE(model.Undo());
1260 EXPECT_STR_EQ("ABCBCDE", model.GetText()); 1254 EXPECT_STR_EQ("ABCBCDE", model.text());
1261 EXPECT_EQ(7U, model.GetCursorPosition()); 1255 EXPECT_EQ(7U, model.GetCursorPosition());
1262 // empty cut shouldn't create an edit. 1256 // empty cut shouldn't create an edit.
1263 EXPECT_TRUE(model.Undo()); 1257 EXPECT_TRUE(model.Undo());
1264 EXPECT_STR_EQ("ABCBCBCDE", model.GetText()); 1258 EXPECT_STR_EQ("ABCBCBCDE", model.text());
1265 EXPECT_EQ(3U, model.GetCursorPosition()); 1259 EXPECT_EQ(3U, model.GetCursorPosition());
1266 1260
1267 // Copy 1261 // Copy
1268 ResetModel(&model); 1262 ResetModel(&model);
1269 model.SetText(ASCIIToUTF16("12345")); 1263 model.SetText(ASCIIToUTF16("12345"));
1270 EXPECT_STR_EQ("12345", model.GetText()); 1264 EXPECT_STR_EQ("12345", model.text());
1271 EXPECT_EQ(5U, model.GetCursorPosition()); 1265 EXPECT_EQ(5U, model.GetCursorPosition());
1272 model.SelectRange(gfx::Range(1, 3)); 1266 model.SelectRange(gfx::Range(1, 3));
1273 model.Copy(); // Copy "23" 1267 model.Copy(); // Copy "23"
1274 EXPECT_STR_EQ("12345", model.GetText()); 1268 EXPECT_STR_EQ("12345", model.text());
1275 EXPECT_EQ(3U, model.GetCursorPosition()); 1269 EXPECT_EQ(3U, model.GetCursorPosition());
1276 model.Paste(); // Paste "23" into "23". 1270 model.Paste(); // Paste "23" into "23".
1277 EXPECT_STR_EQ("12345", model.GetText()); 1271 EXPECT_STR_EQ("12345", model.text());
1278 EXPECT_EQ(3U, model.GetCursorPosition()); 1272 EXPECT_EQ(3U, model.GetCursorPosition());
1279 model.Paste(); 1273 model.Paste();
1280 EXPECT_STR_EQ("1232345", model.GetText()); 1274 EXPECT_STR_EQ("1232345", model.text());
1281 EXPECT_EQ(5U, model.GetCursorPosition()); 1275 EXPECT_EQ(5U, model.GetCursorPosition());
1282 EXPECT_TRUE(model.Undo()); 1276 EXPECT_TRUE(model.Undo());
1283 EXPECT_STR_EQ("12345", model.GetText()); 1277 EXPECT_STR_EQ("12345", model.text());
1284 EXPECT_EQ(3U, model.GetCursorPosition()); 1278 EXPECT_EQ(3U, model.GetCursorPosition());
1285 // TODO(oshima): We need to change the return type from bool to enum. 1279 // TODO(oshima): We need to change the return type from bool to enum.
1286 EXPECT_FALSE(model.Undo()); // No text change. 1280 EXPECT_FALSE(model.Undo()); // No text change.
1287 EXPECT_STR_EQ("12345", model.GetText()); 1281 EXPECT_STR_EQ("12345", model.text());
1288 EXPECT_EQ(3U, model.GetCursorPosition()); 1282 EXPECT_EQ(3U, model.GetCursorPosition());
1289 EXPECT_TRUE(model.Undo()); 1283 EXPECT_TRUE(model.Undo());
1290 EXPECT_STR_EQ("", model.GetText()); 1284 EXPECT_STR_EQ("", model.text());
1291 EXPECT_FALSE(model.Undo()); 1285 EXPECT_FALSE(model.Undo());
1292 // Redo 1286 // Redo
1293 EXPECT_TRUE(model.Redo()); 1287 EXPECT_TRUE(model.Redo());
1294 EXPECT_STR_EQ("12345", model.GetText()); 1288 EXPECT_STR_EQ("12345", model.text());
1295 EXPECT_EQ(5U, model.GetCursorPosition()); 1289 EXPECT_EQ(5U, model.GetCursorPosition());
1296 EXPECT_TRUE(model.Redo()); 1290 EXPECT_TRUE(model.Redo());
1297 EXPECT_STR_EQ("12345", model.GetText()); // For 1st paste 1291 EXPECT_STR_EQ("12345", model.text()); // For 1st paste
1298 EXPECT_EQ(3U, model.GetCursorPosition()); 1292 EXPECT_EQ(3U, model.GetCursorPosition());
1299 EXPECT_TRUE(model.Redo()); 1293 EXPECT_TRUE(model.Redo());
1300 EXPECT_STR_EQ("1232345", model.GetText()); 1294 EXPECT_STR_EQ("1232345", model.text());
1301 EXPECT_EQ(5U, model.GetCursorPosition()); 1295 EXPECT_EQ(5U, model.GetCursorPosition());
1302 EXPECT_FALSE(model.Redo()); 1296 EXPECT_FALSE(model.Redo());
1303 EXPECT_STR_EQ("1232345", model.GetText()); 1297 EXPECT_STR_EQ("1232345", model.text());
1304 1298
1305 // Test using SelectRange 1299 // Test using SelectRange
1306 model.SelectRange(gfx::Range(1, 3)); 1300 model.SelectRange(gfx::Range(1, 3));
1307 model.Copy(); 1301 model.Copy();
1308 EXPECT_STR_EQ("1232345", model.GetText()); 1302 EXPECT_STR_EQ("1232345", model.text());
1309 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1303 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
1310 EXPECT_TRUE(model.Paste()); 1304 EXPECT_TRUE(model.Paste());
1311 EXPECT_STR_EQ("123234523", model.GetText()); 1305 EXPECT_STR_EQ("123234523", model.text());
1312 EXPECT_EQ(9U, model.GetCursorPosition()); 1306 EXPECT_EQ(9U, model.GetCursorPosition());
1313 EXPECT_TRUE(model.Undo()); 1307 EXPECT_TRUE(model.Undo());
1314 EXPECT_STR_EQ("1232345", model.GetText()); 1308 EXPECT_STR_EQ("1232345", model.text());
1315 EXPECT_EQ(7U, model.GetCursorPosition()); 1309 EXPECT_EQ(7U, model.GetCursorPosition());
1316 } 1310 }
1317 1311
1318 TEST_F(TextfieldViewsModelTest, UndoRedo_CursorTest) { 1312 TEST_F(TextfieldViewsModelTest, UndoRedo_CursorTest) {
1319 TextfieldViewsModel model(NULL); 1313 TextfieldViewsModel model(NULL);
1320 model.InsertChar('a'); 1314 model.InsertChar('a');
1321 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); 1315 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false);
1322 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 1316 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
1323 model.InsertChar('b'); 1317 model.InsertChar('b');
1324 // Moving the cursor shouldn't create a new edit. 1318 // Moving the cursor shouldn't create a new edit.
1325 EXPECT_STR_EQ("ab", model.GetText()); 1319 EXPECT_STR_EQ("ab", model.text());
1326 EXPECT_FALSE(model.Redo()); 1320 EXPECT_FALSE(model.Redo());
1327 EXPECT_TRUE(model.Undo()); 1321 EXPECT_TRUE(model.Undo());
1328 EXPECT_STR_EQ("", model.GetText()); 1322 EXPECT_STR_EQ("", model.text());
1329 EXPECT_FALSE(model.Undo()); 1323 EXPECT_FALSE(model.Undo());
1330 EXPECT_STR_EQ("", model.GetText()); 1324 EXPECT_STR_EQ("", model.text());
1331 EXPECT_TRUE(model.Redo()); 1325 EXPECT_TRUE(model.Redo());
1332 EXPECT_STR_EQ("ab", model.GetText()); 1326 EXPECT_STR_EQ("ab", model.text());
1333 EXPECT_EQ(2U, model.GetCursorPosition()); 1327 EXPECT_EQ(2U, model.GetCursorPosition());
1334 EXPECT_FALSE(model.Redo()); 1328 EXPECT_FALSE(model.Redo());
1335 } 1329 }
1336 1330
1337 void RunInsertReplaceTest(TextfieldViewsModel& model) { 1331 void RunInsertReplaceTest(TextfieldViewsModel& model) {
1338 const bool reverse = model.render_text()->selection().is_reversed(); 1332 const bool reverse = model.render_text()->selection().is_reversed();
1339 model.InsertChar('1'); 1333 model.InsertChar('1');
1340 model.InsertChar('2'); 1334 model.InsertChar('2');
1341 model.InsertChar('3'); 1335 model.InsertChar('3');
1342 EXPECT_STR_EQ("a123d", model.GetText()); 1336 EXPECT_STR_EQ("a123d", model.text());
1343 EXPECT_EQ(4U, model.GetCursorPosition()); 1337 EXPECT_EQ(4U, model.GetCursorPosition());
1344 EXPECT_TRUE(model.Undo()); 1338 EXPECT_TRUE(model.Undo());
1345 EXPECT_STR_EQ("abcd", model.GetText()); 1339 EXPECT_STR_EQ("abcd", model.text());
1346 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); 1340 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition());
1347 EXPECT_TRUE(model.Undo()); 1341 EXPECT_TRUE(model.Undo());
1348 EXPECT_STR_EQ("", model.GetText()); 1342 EXPECT_STR_EQ("", model.text());
1349 EXPECT_EQ(0U, model.GetCursorPosition()); 1343 EXPECT_EQ(0U, model.GetCursorPosition());
1350 EXPECT_FALSE(model.Undo()); 1344 EXPECT_FALSE(model.Undo());
1351 EXPECT_TRUE(model.Redo()); 1345 EXPECT_TRUE(model.Redo());
1352 EXPECT_STR_EQ("abcd", model.GetText()); 1346 EXPECT_STR_EQ("abcd", model.text());
1353 EXPECT_EQ(4U, model.GetCursorPosition()); // By SetText 1347 EXPECT_EQ(4U, model.GetCursorPosition()); // By SetText
1354 EXPECT_TRUE(model.Redo()); 1348 EXPECT_TRUE(model.Redo());
1355 EXPECT_STR_EQ("a123d", model.GetText()); 1349 EXPECT_STR_EQ("a123d", model.text());
1356 EXPECT_EQ(4U, model.GetCursorPosition()); 1350 EXPECT_EQ(4U, model.GetCursorPosition());
1357 EXPECT_FALSE(model.Redo()); 1351 EXPECT_FALSE(model.Redo());
1358 } 1352 }
1359 1353
1360 void RunOverwriteReplaceTest(TextfieldViewsModel& model) { 1354 void RunOverwriteReplaceTest(TextfieldViewsModel& model) {
1361 const bool reverse = model.render_text()->selection().is_reversed(); 1355 const bool reverse = model.render_text()->selection().is_reversed();
1362 model.ReplaceChar('1'); 1356 model.ReplaceChar('1');
1363 model.ReplaceChar('2'); 1357 model.ReplaceChar('2');
1364 model.ReplaceChar('3'); 1358 model.ReplaceChar('3');
1365 model.ReplaceChar('4'); 1359 model.ReplaceChar('4');
1366 EXPECT_STR_EQ("a1234", model.GetText()); 1360 EXPECT_STR_EQ("a1234", model.text());
1367 EXPECT_EQ(5U, model.GetCursorPosition()); 1361 EXPECT_EQ(5U, model.GetCursorPosition());
1368 EXPECT_TRUE(model.Undo()); 1362 EXPECT_TRUE(model.Undo());
1369 EXPECT_STR_EQ("abcd", model.GetText()); 1363 EXPECT_STR_EQ("abcd", model.text());
1370 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); 1364 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition());
1371 EXPECT_TRUE(model.Undo()); 1365 EXPECT_TRUE(model.Undo());
1372 EXPECT_STR_EQ("", model.GetText()); 1366 EXPECT_STR_EQ("", model.text());
1373 EXPECT_EQ(0U, model.GetCursorPosition()); 1367 EXPECT_EQ(0U, model.GetCursorPosition());
1374 EXPECT_FALSE(model.Undo()); 1368 EXPECT_FALSE(model.Undo());
1375 EXPECT_TRUE(model.Redo()); 1369 EXPECT_TRUE(model.Redo());
1376 EXPECT_STR_EQ("abcd", model.GetText()); 1370 EXPECT_STR_EQ("abcd", model.text());
1377 EXPECT_EQ(4U, model.GetCursorPosition()); 1371 EXPECT_EQ(4U, model.GetCursorPosition());
1378 EXPECT_TRUE(model.Redo()); 1372 EXPECT_TRUE(model.Redo());
1379 EXPECT_STR_EQ("a1234", model.GetText()); 1373 EXPECT_STR_EQ("a1234", model.text());
1380 EXPECT_EQ(5U, model.GetCursorPosition()); 1374 EXPECT_EQ(5U, model.GetCursorPosition());
1381 EXPECT_FALSE(model.Redo()); 1375 EXPECT_FALSE(model.Redo());
1382 } 1376 }
1383 1377
1384 TEST_F(TextfieldViewsModelTest, UndoRedo_ReplaceTest) { 1378 TEST_F(TextfieldViewsModelTest, UndoRedo_ReplaceTest) {
1385 // By Cursor 1379 // By Cursor
1386 { 1380 {
1387 SCOPED_TRACE("forward & insert by cursor"); 1381 SCOPED_TRACE("forward & insert by cursor");
1388 TextfieldViewsModel model(NULL); 1382 TextfieldViewsModel model(NULL);
1389 model.SetText(ASCIIToUTF16("abcd")); 1383 model.SetText(ASCIIToUTF16("abcd"));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 TextfieldViewsModel model(NULL); 1440 TextfieldViewsModel model(NULL);
1447 1441
1448 ui::CompositionText composition; 1442 ui::CompositionText composition;
1449 composition.text = ASCIIToUTF16("abc"); 1443 composition.text = ASCIIToUTF16("abc");
1450 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false)); 1444 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false));
1451 composition.selection = gfx::Range(2, 3); 1445 composition.selection = gfx::Range(2, 3);
1452 1446
1453 model.SetText(ASCIIToUTF16("ABCDE")); 1447 model.SetText(ASCIIToUTF16("ABCDE"));
1454 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1448 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
1455 model.InsertChar('x'); 1449 model.InsertChar('x');
1456 EXPECT_STR_EQ("ABCDEx", model.GetText()); 1450 EXPECT_STR_EQ("ABCDEx", model.text());
1457 EXPECT_TRUE(model.Undo()); // set composition should forget undone edit. 1451 EXPECT_TRUE(model.Undo()); // set composition should forget undone edit.
1458 model.SetCompositionText(composition); 1452 model.SetCompositionText(composition);
1459 EXPECT_TRUE(model.HasCompositionText()); 1453 EXPECT_TRUE(model.HasCompositionText());
1460 EXPECT_TRUE(model.HasSelection()); 1454 EXPECT_TRUE(model.HasSelection());
1461 EXPECT_STR_EQ("ABCDEabc", model.GetText()); 1455 EXPECT_STR_EQ("ABCDEabc", model.text());
1462 1456
1463 // Accepting composition 1457 // Accepting composition
1464 model.ConfirmCompositionText(); 1458 model.ConfirmCompositionText();
1465 EXPECT_STR_EQ("ABCDEabc", model.GetText()); 1459 EXPECT_STR_EQ("ABCDEabc", model.text());
1466 EXPECT_TRUE(model.Undo()); 1460 EXPECT_TRUE(model.Undo());
1467 EXPECT_STR_EQ("ABCDE", model.GetText()); 1461 EXPECT_STR_EQ("ABCDE", model.text());
1468 EXPECT_TRUE(model.Undo()); 1462 EXPECT_TRUE(model.Undo());
1469 EXPECT_STR_EQ("", model.GetText()); 1463 EXPECT_STR_EQ("", model.text());
1470 EXPECT_TRUE(model.Redo()); 1464 EXPECT_TRUE(model.Redo());
1471 EXPECT_STR_EQ("ABCDE", model.GetText()); 1465 EXPECT_STR_EQ("ABCDE", model.text());
1472 EXPECT_TRUE(model.Redo()); 1466 EXPECT_TRUE(model.Redo());
1473 EXPECT_STR_EQ("ABCDEabc", model.GetText()); 1467 EXPECT_STR_EQ("ABCDEabc", model.text());
1474 EXPECT_FALSE(model.Redo()); 1468 EXPECT_FALSE(model.Redo());
1475 1469
1476 // Canceling composition 1470 // Canceling composition
1477 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 1471 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
1478 model.SetCompositionText(composition); 1472 model.SetCompositionText(composition);
1479 EXPECT_STR_EQ("abcABCDEabc", model.GetText()); 1473 EXPECT_STR_EQ("abcABCDEabc", model.text());
1480 model.CancelCompositionText(); 1474 model.CancelCompositionText();
1481 EXPECT_STR_EQ("ABCDEabc", model.GetText()); 1475 EXPECT_STR_EQ("ABCDEabc", model.text());
1482 EXPECT_FALSE(model.Redo()); 1476 EXPECT_FALSE(model.Redo());
1483 EXPECT_STR_EQ("ABCDEabc", model.GetText()); 1477 EXPECT_STR_EQ("ABCDEabc", model.text());
1484 EXPECT_TRUE(model.Undo()); 1478 EXPECT_TRUE(model.Undo());
1485 EXPECT_STR_EQ("ABCDE", model.GetText()); 1479 EXPECT_STR_EQ("ABCDE", model.text());
1486 EXPECT_TRUE(model.Redo()); 1480 EXPECT_TRUE(model.Redo());
1487 EXPECT_STR_EQ("ABCDEabc", model.GetText()); 1481 EXPECT_STR_EQ("ABCDEabc", model.text());
1488 EXPECT_FALSE(model.Redo()); 1482 EXPECT_FALSE(model.Redo());
1489 1483
1490 // SetText with the same text as the result. 1484 // SetText with the same text as the result.
1491 ResetModel(&model); 1485 ResetModel(&model);
1492 model.SetText(ASCIIToUTF16("ABCDE")); 1486 model.SetText(ASCIIToUTF16("ABCDE"));
1493 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1487 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
1494 model.SetCompositionText(composition); 1488 model.SetCompositionText(composition);
1495 EXPECT_STR_EQ("ABCDEabc", model.GetText()); 1489 EXPECT_STR_EQ("ABCDEabc", model.text());
1496 model.SetText(ASCIIToUTF16("ABCDEabc")); 1490 model.SetText(ASCIIToUTF16("ABCDEabc"));
1497 EXPECT_STR_EQ("ABCDEabc", model.GetText()); 1491 EXPECT_STR_EQ("ABCDEabc", model.text());
1498 EXPECT_TRUE(model.Undo()); 1492 EXPECT_TRUE(model.Undo());
1499 EXPECT_STR_EQ("ABCDE", model.GetText()); 1493 EXPECT_STR_EQ("ABCDE", model.text());
1500 EXPECT_TRUE(model.Redo()); 1494 EXPECT_TRUE(model.Redo());
1501 EXPECT_STR_EQ("ABCDEabc", model.GetText()); 1495 EXPECT_STR_EQ("ABCDEabc", model.text());
1502 EXPECT_FALSE(model.Redo()); 1496 EXPECT_FALSE(model.Redo());
1503 1497
1504 // SetText with the different text than the result should not 1498 // SetText with the different text than the result should not
1505 // remember composition text. 1499 // remember composition text.
1506 ResetModel(&model); 1500 ResetModel(&model);
1507 model.SetText(ASCIIToUTF16("ABCDE")); 1501 model.SetText(ASCIIToUTF16("ABCDE"));
1508 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1502 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
1509 model.SetCompositionText(composition); 1503 model.SetCompositionText(composition);
1510 EXPECT_STR_EQ("ABCDEabc", model.GetText()); 1504 EXPECT_STR_EQ("ABCDEabc", model.text());
1511 model.SetText(ASCIIToUTF16("1234")); 1505 model.SetText(ASCIIToUTF16("1234"));
1512 EXPECT_STR_EQ("1234", model.GetText()); 1506 EXPECT_STR_EQ("1234", model.text());
1513 EXPECT_TRUE(model.Undo()); 1507 EXPECT_TRUE(model.Undo());
1514 EXPECT_STR_EQ("ABCDE", model.GetText()); 1508 EXPECT_STR_EQ("ABCDE", model.text());
1515 EXPECT_TRUE(model.Redo()); 1509 EXPECT_TRUE(model.Redo());
1516 EXPECT_STR_EQ("1234", model.GetText()); 1510 EXPECT_STR_EQ("1234", model.text());
1517 EXPECT_FALSE(model.Redo()); 1511 EXPECT_FALSE(model.Redo());
1518 1512
1519 // TODO(oshima): We need MockInputMethod to test the behavior with IME. 1513 // TODO(oshima): We need MockInputMethod to test the behavior with IME.
1520 } 1514 }
1521 1515
1522 } // namespace views 1516 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield_views_model.cc ('k') | ui/views/ime/input_method_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698