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

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

Issue 9390022: Simplify handling of BiDi cursor movement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 9 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.h" 9 #include "base/message_loop.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 18 matching lines...) Expand all
29 struct WordAndCursor { 29 struct WordAndCursor {
30 WordAndCursor(const wchar_t* w, size_t c) 30 WordAndCursor(const wchar_t* w, size_t c)
31 : word(w), 31 : word(w),
32 cursor(c) { 32 cursor(c) {
33 } 33 }
34 34
35 const wchar_t* word; 35 const wchar_t* word;
36 size_t cursor; 36 size_t cursor;
37 }; 37 };
38 38
39 void MoveCursorTo(views::TextfieldViewsModel& model, size_t pos) {
40 model.MoveCursorTo(gfx::SelectionModel(pos, gfx::CURSOR_FORWARD));
41 }
42
39 } // namespace 43 } // namespace
40 44
41 namespace views { 45 namespace views {
42 46
43 class TextfieldViewsModelTest : public ViewsTestBase, 47 class TextfieldViewsModelTest : public ViewsTestBase,
44 public TextfieldViewsModel::Delegate { 48 public TextfieldViewsModel::Delegate {
45 public: 49 public:
46 TextfieldViewsModelTest() 50 TextfieldViewsModelTest()
47 : ViewsTestBase(), 51 : ViewsTestBase(),
48 composition_text_confirmed_or_cleared_(false) { 52 composition_text_confirmed_or_cleared_(false) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 EXPECT_FALSE(model.Backspace()); 102 EXPECT_FALSE(model.Backspace());
99 EXPECT_STR_EQ("HELLORLD", model.GetText()); 103 EXPECT_STR_EQ("HELLORLD", model.GetText());
100 // Move the cursor to the end. delete should fail. 104 // Move the cursor to the end. delete should fail.
101 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 105 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
102 EXPECT_FALSE(model.Delete()); 106 EXPECT_FALSE(model.Delete());
103 EXPECT_STR_EQ("HELLORLD", model.GetText()); 107 EXPECT_STR_EQ("HELLORLD", model.GetText());
104 // but backspace should work. 108 // but backspace should work.
105 EXPECT_TRUE(model.Backspace()); 109 EXPECT_TRUE(model.Backspace());
106 EXPECT_STR_EQ("HELLORL", model.GetText()); 110 EXPECT_STR_EQ("HELLORL", model.GetText());
107 111
108 model.MoveCursorTo(gfx::SelectionModel(5)); 112 MoveCursorTo(model, 5);
109 model.ReplaceText(ASCIIToUTF16(" WOR")); 113 model.ReplaceText(ASCIIToUTF16(" WOR"));
110 EXPECT_STR_EQ("HELLO WORL", model.GetText()); 114 EXPECT_STR_EQ("HELLO WORL", model.GetText());
111 } 115 }
112 116
113 TEST_F(TextfieldViewsModelTest, EditString_SimpleRTL) { 117 TEST_F(TextfieldViewsModelTest, EditString_SimpleRTL) {
114 TextfieldViewsModel model(NULL); 118 TextfieldViewsModel model(NULL);
115 // Append two strings. 119 // Append two strings.
116 model.Append(WideToUTF16(L"\x05d0\x05d1\x05d2")); 120 model.Append(WideToUTF16(L"\x05d0\x05d1\x05d2"));
117 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2"), model.GetText()); 121 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2"), model.GetText());
118 model.Append(WideToUTF16(L"\x05e0\x05e1\x05e2")); 122 model.Append(WideToUTF16(L"\x05e0\x05e1\x05e2"));
119 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2\x05e0\x05e1\x05e2"), 123 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2\x05e0\x05e1\x05e2"),
120 model.GetText()); 124 model.GetText());
121 125
122 // Insert 0x05f0. 126 // Insert 0x05f0.
123 model.MoveCursorTo(gfx::SelectionModel(1U)); 127 MoveCursorTo(model, 1);
124 model.InsertChar(0x05f0); 128 model.InsertChar(0x05f0);
125 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05d1\x05d2\x05e0\x05e1\x05e2"), 129 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05d1\x05d2\x05e0\x05e1\x05e2"),
126 model.GetText()); 130 model.GetText());
127 131
128 // Replace "\x05d1" with "\x05f1". 132 // Replace "\x05d1" with "\x05f1".
129 model.ReplaceChar(0x05f1); 133 model.ReplaceChar(0x05f1);
130 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05d2\x05e0\x05e1\x05e2"), 134 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05d2\x05e0\x05e1\x05e2"),
131 model.GetText()); 135 model.GetText());
132 136
133 // Delete and backspace. 137 // Delete and backspace.
(...skipping 22 matching lines...) Expand all
156 model.GetText()); 160 model.GetText());
157 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d")); 161 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d"));
158 EXPECT_EQ(WideToUTF16( 162 EXPECT_EQ(WideToUTF16(
159 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), 163 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"),
160 model.GetText()); 164 model.GetText());
161 165
162 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete 166 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete
163 // font support for some scripts - http://crbug.com/106450 167 // font support for some scripts - http://crbug.com/106450
164 if (!on_windows_xp) { 168 if (!on_windows_xp) {
165 // Check it is not able to place cursor in middle of a grapheme. 169 // Check it is not able to place cursor in middle of a grapheme.
166 model.MoveCursorTo(gfx::SelectionModel(1U)); 170 MoveCursorTo(model, 1);
167 EXPECT_EQ(0U, model.GetCursorPosition()); 171 EXPECT_EQ(0U, model.GetCursorPosition());
168 172
169 model.MoveCursorTo(gfx::SelectionModel(2U)); 173 MoveCursorTo(model, 2);
170 EXPECT_EQ(2U, model.GetCursorPosition()); 174 EXPECT_EQ(2U, model.GetCursorPosition());
171 model.InsertChar('a'); 175 model.InsertChar('a');
172 EXPECT_EQ(WideToUTF16( 176 EXPECT_EQ(WideToUTF16(
173 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), 177 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"),
174 model.GetText()); 178 model.GetText());
175 179
176 // ReplaceChar will replace the whole grapheme. 180 // ReplaceChar will replace the whole grapheme.
177 model.ReplaceChar('b'); 181 model.ReplaceChar('b');
178 // TODO(xji): temporarily disable in platform Win since the complex script 182 // TODO(xji): temporarily disable in platform Win since the complex script
179 // characters turned into empty square due to font regression. So, not able 183 // characters turned into empty square due to font regression. So, not able
180 // to test 2 characters belong to the same grapheme. 184 // to test 2 characters belong to the same grapheme.
181 #if defined(OS_LINUX) 185 #if defined(OS_LINUX)
182 EXPECT_EQ(WideToUTF16( 186 EXPECT_EQ(WideToUTF16(
183 L"\x0915\x093f\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), 187 L"\x0915\x093f\x0061\x0062\x0915\x0915\x094d\x092e\x094d"),
184 model.GetText()); 188 model.GetText());
185 #endif 189 #endif
186 EXPECT_EQ(4U, model.GetCursorPosition()); 190 EXPECT_EQ(4U, model.GetCursorPosition());
187 } 191 }
188 192
189 // Delete should delete the whole grapheme. 193 // Delete should delete the whole grapheme.
190 model.MoveCursorTo(gfx::SelectionModel(0U)); 194 MoveCursorTo(model, 0);
191 // TODO(xji): temporarily disable in platform Win since the complex script 195 // TODO(xji): temporarily disable in platform Win since the complex script
192 // characters turned into empty square due to font regression. So, not able 196 // characters turned into empty square due to font regression. So, not able
193 // to test 2 characters belong to the same grapheme. 197 // to test 2 characters belong to the same grapheme.
194 #if defined(OS_LINUX) 198 #if defined(OS_LINUX)
195 EXPECT_TRUE(model.Delete()); 199 EXPECT_TRUE(model.Delete());
196 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), 200 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"),
197 model.GetText()); 201 model.GetText());
198 model.MoveCursorTo(gfx::SelectionModel(model.GetText().length())); 202 MoveCursorTo(model, model.GetText().length());
199 EXPECT_EQ(model.GetText().length(), model.GetCursorPosition()); 203 EXPECT_EQ(model.GetText().length(), model.GetCursorPosition());
200 EXPECT_TRUE(model.Backspace()); 204 EXPECT_TRUE(model.Backspace());
201 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"), 205 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"),
202 model.GetText()); 206 model.GetText());
203 #endif 207 #endif
204 208
205 // Test cursor position and deletion for Hindi Virama. 209 // Test cursor position and deletion for Hindi Virama.
206 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E")); 210 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E"));
207 model.MoveCursorTo(gfx::SelectionModel(0)); 211 MoveCursorTo(model, 0);
208 EXPECT_EQ(0U, model.GetCursorPosition()); 212 EXPECT_EQ(0U, model.GetCursorPosition());
209 213
210 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete 214 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete
211 // font support for some scripts - http://crbug.com/106450 215 // font support for some scripts - http://crbug.com/106450
212 if (!on_windows_xp) { 216 if (!on_windows_xp) {
213 model.MoveCursorTo(gfx::SelectionModel(1)); 217 MoveCursorTo(model, 1);
214 EXPECT_EQ(0U, model.GetCursorPosition()); 218 EXPECT_EQ(0U, model.GetCursorPosition());
215 model.MoveCursorTo(gfx::SelectionModel(3)); 219 MoveCursorTo(model, 3);
216 EXPECT_EQ(3U, model.GetCursorPosition()); 220 EXPECT_EQ(3U, model.GetCursorPosition());
217 } 221 }
218 222
219 // TODO(asvitkine): Temporarily disable the following check on Windows. It 223 // TODO(asvitkine): Temporarily disable the following check on Windows. It
220 // seems Windows treats "\x0D38\x0D4D\x0D15" as a single grapheme. 224 // seems Windows treats "\x0D38\x0D4D\x0D15" as a single grapheme.
221 #if !defined(OS_WIN) 225 #if !defined(OS_WIN)
222 model.MoveCursorTo(gfx::SelectionModel(2)); 226 MoveCursorTo(model, 2);
223 EXPECT_EQ(2U, model.GetCursorPosition()); 227 EXPECT_EQ(2U, model.GetCursorPosition());
224 EXPECT_TRUE(model.Backspace()); 228 EXPECT_TRUE(model.Backspace());
225 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText()); 229 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText());
226 #endif 230 #endif
227 231
228 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9")); 232 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9"));
229 model.MoveCursorTo(gfx::SelectionModel(0)); 233 MoveCursorTo(model, 0);
230 EXPECT_TRUE(model.Delete()); 234 EXPECT_TRUE(model.Delete());
231 EXPECT_TRUE(model.Delete()); 235 EXPECT_TRUE(model.Delete());
232 EXPECT_TRUE(model.Delete()); 236 EXPECT_TRUE(model.Delete());
233 EXPECT_TRUE(model.Delete()); 237 EXPECT_TRUE(model.Delete());
234 EXPECT_EQ(WideToUTF16(L""), model.GetText()); 238 EXPECT_EQ(WideToUTF16(L""), model.GetText());
235 239
236 // The first 2 characters are not strong directionality characters. 240 // The first 2 characters are not strong directionality characters.
237 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); 241 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC"));
238 #if defined(OS_WIN) 242 #if defined(OS_WIN)
239 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 243 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 EXPECT_STR_EQ("H", model.GetSelectedText()); 278 EXPECT_STR_EQ("H", model.GetSelectedText());
275 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, true); 279 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, true);
276 EXPECT_STR_EQ("ELLO", model.GetSelectedText()); 280 EXPECT_STR_EQ("ELLO", model.GetSelectedText());
277 model.ClearSelection(); 281 model.ClearSelection();
278 EXPECT_EQ(string16(), model.GetSelectedText()); 282 EXPECT_EQ(string16(), model.GetSelectedText());
279 model.SelectAll(); 283 model.SelectAll();
280 EXPECT_STR_EQ("HELLO", model.GetSelectedText()); 284 EXPECT_STR_EQ("HELLO", model.GetSelectedText());
281 // SelectAll should select towards the end. 285 // SelectAll should select towards the end.
282 gfx::SelectionModel sel; 286 gfx::SelectionModel sel;
283 model.GetSelectionModel(&sel); 287 model.GetSelectionModel(&sel);
284 EXPECT_EQ(0U, sel.selection_start()); 288 EXPECT_EQ(ui::Range(0, 5), sel.selection());
285 EXPECT_EQ(5U, sel.selection_end());
286 289
287 // Select and move cursor 290 // Select and move cursor
288 model.SelectRange(ui::Range(1U, 3U)); 291 model.SelectRange(ui::Range(1U, 3U));
289 EXPECT_STR_EQ("EL", model.GetSelectedText()); 292 EXPECT_STR_EQ("EL", model.GetSelectedText());
290 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); 293 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false);
291 EXPECT_EQ(1U, model.GetCursorPosition()); 294 EXPECT_EQ(1U, model.GetCursorPosition());
292 model.SelectRange(ui::Range(1U, 3U)); 295 model.SelectRange(ui::Range(1U, 3U));
293 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 296 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
294 EXPECT_EQ(3U, model.GetCursorPosition()); 297 EXPECT_EQ(3U, model.GetCursorPosition());
295 298
(...skipping 16 matching lines...) Expand all
312 // TODO(xji): temporarily disable in platform Win since the complex script 315 // TODO(xji): temporarily disable in platform Win since the complex script
313 // characters turned into empty square due to font regression. So, not able 316 // characters turned into empty square due to font regression. So, not able
314 // to test 2 characters belong to the same grapheme. 317 // to test 2 characters belong to the same grapheme.
315 #if defined(OS_LINUX) 318 #if defined(OS_LINUX)
316 model.Append(WideToUTF16( 319 model.Append(WideToUTF16(
317 L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def")); 320 L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def"));
318 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 321 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
319 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 322 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
320 323
321 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 324 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
322 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); 325 EXPECT_EQ(ui::Range(2, 3), model.render_text()->selection());
323 EXPECT_EQ(3U, model.GetCursorPosition());
324 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); 326 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText());
325 327
326 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 328 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
327 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); 329 EXPECT_EQ(ui::Range(2, 7), model.render_text()->selection());
328 EXPECT_EQ(7U, model.GetCursorPosition());
329 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8"), 330 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8"),
330 model.GetSelectedText()); 331 model.GetSelectedText());
331 332
332 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 333 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
333 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); 334 EXPECT_EQ(ui::Range(2, 3), model.render_text()->selection());
334 EXPECT_EQ(3U, model.GetCursorPosition());
335 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); 335 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText());
336 336
337 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 337 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
338 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); 338 EXPECT_EQ(ui::Range(2, 10), model.render_text()->selection());
339 EXPECT_EQ(10U, model.GetCursorPosition());
340 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"d"), 339 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"d"),
341 model.GetSelectedText()); 340 model.GetSelectedText());
342 341
343 model.ClearSelection(); 342 model.ClearSelection();
344 EXPECT_EQ(string16(), model.GetSelectedText()); 343 EXPECT_EQ(string16(), model.GetSelectedText());
345 model.SelectAll(); 344 model.SelectAll();
346 EXPECT_EQ(WideToUTF16(L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def"), 345 EXPECT_EQ(WideToUTF16(L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def"),
347 model.GetSelectedText()); 346 model.GetSelectedText());
348 #endif 347 #endif
349 348
350 // In case of "aBc", this test shows how to select "aB" or "Bc", assume 'B' is 349 // In case of "aBc", this test shows how to select "aB" or "Bc", assume 'B' is
351 // an RTL character. 350 // an RTL character.
352 model.SetText(WideToUTF16(L"a\x05E9"L"b")); 351 model.SetText(WideToUTF16(L"a\x05E9"L"b"));
353 model.MoveCursorTo(gfx::SelectionModel(0)); 352 MoveCursorTo(model, 0);
354 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 353 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
355 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText()); 354 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText());
356 355
357 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 356 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
358 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText()); 357 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText());
359 358
360 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 359 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
361 EXPECT_EQ(WideToUTF16(L"a\x05E9"L"b"), model.GetSelectedText()); 360 EXPECT_EQ(WideToUTF16(L"a\x05E9"L"b"), model.GetSelectedText());
362 361
363 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 362 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); // leave 2. 449 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); // leave 2.
451 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 450 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
452 EXPECT_EQ(14U, model.GetCursorPosition()); 451 EXPECT_EQ(14U, model.GetCursorPosition());
453 EXPECT_STR_EQ("Life", model.GetSelectedText()); 452 EXPECT_STR_EQ("Life", model.GetSelectedText());
454 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 453 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
455 EXPECT_STR_EQ("to Life", model.GetSelectedText()); 454 EXPECT_STR_EQ("to Life", model.GetSelectedText());
456 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 455 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
457 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 456 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
458 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); // Now at start. 457 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); // Now at start.
459 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); 458 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText());
460 // Should be safe to go pervious word at the begining. 459 // Should be safe to go to the previous word at the beginning.
461 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 460 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
462 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); 461 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText());
463 model.ReplaceChar('4'); 462 model.ReplaceChar('4');
464 EXPECT_EQ(string16(), model.GetSelectedText()); 463 EXPECT_EQ(string16(), model.GetSelectedText());
465 EXPECT_STR_EQ("42", model.GetText()); 464 EXPECT_STR_EQ("42", model.GetText());
466 } 465 }
467 466
468 TEST_F(TextfieldViewsModelTest, SetText) { 467 TEST_F(TextfieldViewsModelTest, SetText) {
469 TextfieldViewsModel model(NULL); 468 TextfieldViewsModel model(NULL);
470 model.Append(ASCIIToUTF16("HELLO")); 469 model.Append(ASCIIToUTF16("HELLO"));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 TEST_F(TextfieldViewsModelTest, SelectWordTest) { 583 TEST_F(TextfieldViewsModelTest, SelectWordTest) {
585 TextfieldViewsModel model(NULL); 584 TextfieldViewsModel model(NULL);
586 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); 585 model.Append(ASCIIToUTF16(" HELLO !! WO RLD "));
587 586
588 // Test when cursor is at the beginning. 587 // Test when cursor is at the beginning.
589 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 588 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
590 model.SelectWord(); 589 model.SelectWord();
591 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 2U); 590 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 2U);
592 591
593 // Test when cursor is at the beginning of a word. 592 // Test when cursor is at the beginning of a word.
594 gfx::SelectionModel selection(2U); 593 MoveCursorTo(model, 2);
595 model.MoveCursorTo(selection);
596 model.SelectWord(); 594 model.SelectWord();
597 SelectWordTestVerifier(model, ASCIIToUTF16("HELLO"), 7U); 595 SelectWordTestVerifier(model, ASCIIToUTF16("HELLO"), 7U);
598 596
599 // Test when cursor is at the end of a word. 597 // Test when cursor is at the end of a word.
600 selection = gfx::SelectionModel(15U); 598 MoveCursorTo(model, 15);
601 model.MoveCursorTo(selection);
602 model.SelectWord(); 599 model.SelectWord();
603 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); 600 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U);
604 601
605 // Test when cursor is somewhere in a non-alpha-numeric fragment. 602 // Test when cursor is somewhere in a non-alpha-numeric fragment.
606 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { 603 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) {
607 selection = gfx::SelectionModel(cursor_pos); 604 MoveCursorTo(model, cursor_pos);
608 model.MoveCursorTo(selection);
609 model.SelectWord(); 605 model.SelectWord();
610 SelectWordTestVerifier(model, ASCIIToUTF16(" !! "), 13U); 606 SelectWordTestVerifier(model, ASCIIToUTF16(" !! "), 13U);
611 } 607 }
612 608
613 // Test when cursor is somewhere in a whitespace fragment. 609 // Test when cursor is somewhere in a whitespace fragment.
614 selection = gfx::SelectionModel(17U); 610 MoveCursorTo(model, 17);
615 model.MoveCursorTo(selection);
616 model.SelectWord(); 611 model.SelectWord();
617 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); 612 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U);
618 613
619 // Test when cursor is at the end. 614 // Test when cursor is at the end.
620 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 615 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
621 model.SelectWord(); 616 model.SelectWord();
622 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 24U); 617 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 24U);
623 } 618 }
624 619
625 // TODO(xji): temporarily disable in platform Win since the complex script 620 // TODO(xji): temporarily disable in platform Win since the complex script
(...skipping 28 matching lines...) Expand all
654 SelectWordTestVerifier(model, WideToUTF16(word_and_cursor[i].word), 649 SelectWordTestVerifier(model, WideToUTF16(word_and_cursor[i].word),
655 word_and_cursor[i].cursor); 650 word_and_cursor[i].cursor);
656 } 651 }
657 } 652 }
658 #endif 653 #endif
659 654
660 TEST_F(TextfieldViewsModelTest, RangeTest) { 655 TEST_F(TextfieldViewsModelTest, RangeTest) {
661 TextfieldViewsModel model(NULL); 656 TextfieldViewsModel model(NULL);
662 model.Append(ASCIIToUTF16("HELLO WORLD")); 657 model.Append(ASCIIToUTF16("HELLO WORLD"));
663 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 658 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
664 ui::Range range; 659 ui::Range range = model.render_text()->selection();
665 model.GetSelectedRange(&range);
666 EXPECT_TRUE(range.is_empty()); 660 EXPECT_TRUE(range.is_empty());
667 EXPECT_EQ(0U, range.start()); 661 EXPECT_EQ(0U, range.start());
668 EXPECT_EQ(0U, range.end()); 662 EXPECT_EQ(0U, range.end());
669 663
670 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 664 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
671 model.GetSelectedRange(&range); 665 range = model.render_text()->selection();
672 EXPECT_FALSE(range.is_empty()); 666 EXPECT_FALSE(range.is_empty());
673 EXPECT_FALSE(range.is_reversed()); 667 EXPECT_FALSE(range.is_reversed());
674 EXPECT_EQ(0U, range.start()); 668 EXPECT_EQ(0U, range.start());
675 EXPECT_EQ(5U, range.end()); 669 EXPECT_EQ(5U, range.end());
676 670
677 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 671 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true);
678 model.GetSelectedRange(&range); 672 range = model.render_text()->selection();
679 EXPECT_FALSE(range.is_empty()); 673 EXPECT_FALSE(range.is_empty());
680 EXPECT_EQ(0U, range.start()); 674 EXPECT_EQ(0U, range.start());
681 EXPECT_EQ(4U, range.end()); 675 EXPECT_EQ(4U, range.end());
682 676
683 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 677 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
684 model.GetSelectedRange(&range); 678 range = model.render_text()->selection();
685 EXPECT_TRUE(range.is_empty()); 679 EXPECT_TRUE(range.is_empty());
686 EXPECT_EQ(0U, range.start()); 680 EXPECT_EQ(0U, range.start());
687 EXPECT_EQ(0U, range.end()); 681 EXPECT_EQ(0U, range.end());
688 682
689 // now from the end. 683 // now from the end.
690 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 684 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
691 model.GetSelectedRange(&range); 685 range = model.render_text()->selection();
692 EXPECT_TRUE(range.is_empty()); 686 EXPECT_TRUE(range.is_empty());
693 EXPECT_EQ(11U, range.start()); 687 EXPECT_EQ(11U, range.start());
694 EXPECT_EQ(11U, range.end()); 688 EXPECT_EQ(11U, range.end());
695 689
696 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 690 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
697 model.GetSelectedRange(&range); 691 range = model.render_text()->selection();
698 EXPECT_FALSE(range.is_empty()); 692 EXPECT_FALSE(range.is_empty());
699 EXPECT_TRUE(range.is_reversed()); 693 EXPECT_TRUE(range.is_reversed());
700 EXPECT_EQ(11U, range.start()); 694 EXPECT_EQ(11U, range.start());
701 EXPECT_EQ(6U, range.end()); 695 EXPECT_EQ(6U, range.end());
702 696
703 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 697 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
704 model.GetSelectedRange(&range); 698 range = model.render_text()->selection();
705 EXPECT_FALSE(range.is_empty()); 699 EXPECT_FALSE(range.is_empty());
706 EXPECT_TRUE(range.is_reversed()); 700 EXPECT_TRUE(range.is_reversed());
707 EXPECT_EQ(11U, range.start()); 701 EXPECT_EQ(11U, range.start());
708 EXPECT_EQ(7U, range.end()); 702 EXPECT_EQ(7U, range.end());
709 703
710 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 704 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
711 model.GetSelectedRange(&range); 705 range = model.render_text()->selection();
712 EXPECT_TRUE(range.is_empty()); 706 EXPECT_TRUE(range.is_empty());
713 EXPECT_EQ(11U, range.start()); 707 EXPECT_EQ(11U, range.start());
714 EXPECT_EQ(11U, range.end()); 708 EXPECT_EQ(11U, range.end());
715 709
716 // Select All 710 // Select All
717 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); 711 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true);
718 model.GetSelectedRange(&range); 712 range = model.render_text()->selection();
719 EXPECT_FALSE(range.is_empty()); 713 EXPECT_FALSE(range.is_empty());
720 EXPECT_TRUE(range.is_reversed()); 714 EXPECT_TRUE(range.is_reversed());
721 EXPECT_EQ(11U, range.start()); 715 EXPECT_EQ(11U, range.start());
722 EXPECT_EQ(0U, range.end()); 716 EXPECT_EQ(0U, range.end());
723 } 717 }
724 718
725 TEST_F(TextfieldViewsModelTest, SelectRangeTest) { 719 TEST_F(TextfieldViewsModelTest, SelectRangeTest) {
726 TextfieldViewsModel model(NULL); 720 TextfieldViewsModel model(NULL);
727 model.Append(ASCIIToUTF16("HELLO WORLD")); 721 model.Append(ASCIIToUTF16("HELLO WORLD"));
728 ui::Range range(0, 6); 722 ui::Range range(0, 6);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 model.SelectRange(range); 759 model.SelectRange(range);
766 EXPECT_TRUE(model.GetSelectedText().empty()); 760 EXPECT_TRUE(model.GetSelectedText().empty());
767 } 761 }
768 762
769 TEST_F(TextfieldViewsModelTest, SelectionModelTest) { 763 TEST_F(TextfieldViewsModelTest, SelectionModelTest) {
770 TextfieldViewsModel model(NULL); 764 TextfieldViewsModel model(NULL);
771 model.Append(ASCIIToUTF16("HELLO WORLD")); 765 model.Append(ASCIIToUTF16("HELLO WORLD"));
772 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 766 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
773 gfx::SelectionModel sel; 767 gfx::SelectionModel sel;
774 model.GetSelectionModel(&sel); 768 model.GetSelectionModel(&sel);
775 EXPECT_EQ(sel.selection_start(), sel.selection_end()); 769 EXPECT_EQ(ui::Range(0), sel.selection());
776 EXPECT_EQ(0U, sel.selection_start());
777 EXPECT_EQ(0U, sel.selection_end());
778 770
779 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 771 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
780 model.GetSelectionModel(&sel); 772 model.GetSelectionModel(&sel);
781 EXPECT_NE(sel.selection_start(), sel.selection_end()); 773 EXPECT_EQ(ui::Range(0, 5), sel.selection());
782 EXPECT_LE(sel.selection_start(), sel.selection_end());
783 EXPECT_EQ(0U, sel.selection_start());
784 EXPECT_EQ(5U, sel.selection_end());
785 774
786 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 775 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true);
787 model.GetSelectionModel(&sel); 776 model.GetSelectionModel(&sel);
788 EXPECT_NE(sel.selection_start(), sel.selection_end()); 777 EXPECT_EQ(ui::Range(0, 4), sel.selection());
789 EXPECT_EQ(0U, sel.selection_start());
790 EXPECT_EQ(4U, sel.selection_end());
791 778
792 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 779 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
793 model.GetSelectionModel(&sel); 780 model.GetSelectionModel(&sel);
794 EXPECT_EQ(sel.selection_start(), sel.selection_end()); 781 EXPECT_EQ(ui::Range(0), sel.selection());
795 EXPECT_EQ(0U, sel.selection_start());
796 EXPECT_EQ(0U, sel.selection_end());
797 782
798 // now from the end. 783 // now from the end.
799 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 784 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
800 model.GetSelectionModel(&sel); 785 model.GetSelectionModel(&sel);
801 EXPECT_EQ(sel.selection_start(), sel.selection_end()); 786 EXPECT_EQ(ui::Range(11), sel.selection());
802 EXPECT_EQ(11U, sel.selection_start());
803 EXPECT_EQ(11U, sel.selection_end());
804 787
805 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 788 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
806 model.GetSelectionModel(&sel); 789 model.GetSelectionModel(&sel);
807 EXPECT_NE(sel.selection_start(), sel.selection_end()); 790 EXPECT_EQ(ui::Range(11, 6), sel.selection());
808 EXPECT_GT(sel.selection_start(), sel.selection_end());
809 EXPECT_EQ(11U, sel.selection_start());
810 EXPECT_EQ(6U, sel.selection_end());
811 791
812 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 792 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
813 model.GetSelectionModel(&sel); 793 model.GetSelectionModel(&sel);
814 EXPECT_NE(sel.selection_start(), sel.selection_end()); 794 EXPECT_EQ(ui::Range(11, 7), sel.selection());
815 EXPECT_GT(sel.selection_start(), sel.selection_end());
816 EXPECT_EQ(11U, sel.selection_start());
817 EXPECT_EQ(7U, sel.selection_end());
818 795
819 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 796 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
820 model.GetSelectionModel(&sel); 797 model.GetSelectionModel(&sel);
821 EXPECT_EQ(sel.selection_start(), sel.selection_end()); 798 EXPECT_EQ(ui::Range(11), sel.selection());
822 EXPECT_EQ(11U, sel.selection_start());
823 EXPECT_EQ(11U, sel.selection_end());
824 799
825 // Select All 800 // Select All
826 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); 801 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true);
827 model.GetSelectionModel(&sel); 802 model.GetSelectionModel(&sel);
828 EXPECT_NE(sel.selection_start(), sel.selection_end()); 803 EXPECT_EQ(ui::Range(11, 0), sel.selection());
829 EXPECT_GT(sel.selection_start(), sel.selection_end());
830 EXPECT_EQ(11U, sel.selection_start());
831 EXPECT_EQ(0U, sel.selection_end());
832 } 804 }
833 805
834 TEST_F(TextfieldViewsModelTest, SelectSelectionModelTest) { 806 TEST_F(TextfieldViewsModelTest, SelectSelectionModelTest) {
835 TextfieldViewsModel model(NULL); 807 TextfieldViewsModel model(NULL);
836 model.Append(ASCIIToUTF16("HELLO WORLD")); 808 model.Append(ASCIIToUTF16("HELLO WORLD"));
837 model.SelectSelectionModel(gfx::SelectionModel(0, 6, 5, 809 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(0, 6),
838 gfx::SelectionModel::TRAILING)); 810 gfx::CURSOR_BACKWARD));
839 EXPECT_STR_EQ("HELLO ", model.GetSelectedText()); 811 EXPECT_STR_EQ("HELLO ", model.GetSelectedText());
840 812
841 model.SelectSelectionModel(gfx::SelectionModel(6, 1, 1, 813 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(6, 1),
842 gfx::SelectionModel::LEADING)); 814 gfx::CURSOR_FORWARD));
843 EXPECT_STR_EQ("ELLO ", model.GetSelectedText()); 815 EXPECT_STR_EQ("ELLO ", model.GetSelectedText());
844 816
845 model.SelectSelectionModel(gfx::SelectionModel(2, 1000, 999, 817 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(2, 1000),
846 gfx::SelectionModel::TRAILING)); 818 gfx::CURSOR_BACKWARD));
847 EXPECT_STR_EQ("LLO WORLD", model.GetSelectedText()); 819 EXPECT_STR_EQ("LLO WORLD", model.GetSelectedText());
848 820
849 model.SelectSelectionModel(gfx::SelectionModel(1000, 3, 3, 821 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(1000, 3),
850 gfx::SelectionModel::LEADING)); 822 gfx::CURSOR_FORWARD));
851 EXPECT_STR_EQ("LO WORLD", model.GetSelectedText()); 823 EXPECT_STR_EQ("LO WORLD", model.GetSelectedText());
852 824
853 model.SelectSelectionModel(gfx::SelectionModel(0, 0, 0, 825 model.SelectSelectionModel(gfx::SelectionModel(0, gfx::CURSOR_FORWARD));
854 gfx::SelectionModel::LEADING));
855 EXPECT_TRUE(model.GetSelectedText().empty()); 826 EXPECT_TRUE(model.GetSelectedText().empty());
856 827
857 model.SelectSelectionModel(gfx::SelectionModel(3, 3, 3, 828 model.SelectSelectionModel(gfx::SelectionModel(3, gfx::CURSOR_FORWARD));
858 gfx::SelectionModel::LEADING));
859 EXPECT_TRUE(model.GetSelectedText().empty()); 829 EXPECT_TRUE(model.GetSelectedText().empty());
860 830
861 model.SelectSelectionModel(gfx::SelectionModel(1000, 100, 100, 831 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(1000, 100),
862 gfx::SelectionModel::LEADING)); 832 gfx::CURSOR_FORWARD));
863 EXPECT_TRUE(model.GetSelectedText().empty()); 833 EXPECT_TRUE(model.GetSelectedText().empty());
864 834
865 model.SelectSelectionModel(gfx::SelectionModel(1000, 1000, 1000, 835 model.SelectSelectionModel(gfx::SelectionModel(1000, gfx::CURSOR_BACKWARD));
866 gfx::SelectionModel::TRAILING));
867 EXPECT_TRUE(model.GetSelectedText().empty()); 836 EXPECT_TRUE(model.GetSelectedText().empty());
868 } 837 }
869 838
870 TEST_F(TextfieldViewsModelTest, CompositionTextTest) { 839 TEST_F(TextfieldViewsModelTest, CompositionTextTest) {
871 TextfieldViewsModel model(this); 840 TextfieldViewsModel model(this);
872 model.Append(ASCIIToUTF16("1234590")); 841 model.Append(ASCIIToUTF16("1234590"));
873 model.SelectRange(ui::Range(5, 5)); 842 model.SelectRange(ui::Range(5, 5));
874 EXPECT_FALSE(model.HasSelection()); 843 EXPECT_FALSE(model.HasSelection());
875 EXPECT_EQ(5U, model.GetCursorPosition()); 844 EXPECT_EQ(5U, model.GetCursorPosition());
876 845
877 ui::Range range; 846 ui::Range range;
878 model.GetTextRange(&range); 847 model.GetTextRange(&range);
879 EXPECT_EQ(0U, range.start()); 848 EXPECT_EQ(ui::Range(0, 7), range);
880 EXPECT_EQ(7U, range.end());
881 849
882 ui::CompositionText composition; 850 ui::CompositionText composition;
883 composition.text = ASCIIToUTF16("678"); 851 composition.text = ASCIIToUTF16("678");
884 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false)); 852 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false));
885 composition.selection = ui::Range(2, 3); 853 composition.selection = ui::Range(2, 3);
886 model.SetCompositionText(composition); 854 model.SetCompositionText(composition);
887 EXPECT_TRUE(model.HasCompositionText()); 855 EXPECT_TRUE(model.HasCompositionText());
888 EXPECT_TRUE(model.HasSelection()); 856 EXPECT_TRUE(model.HasSelection());
889 857
890 model.GetTextRange(&range); 858 model.GetTextRange(&range);
891 EXPECT_EQ(10U, range.end()); 859 EXPECT_EQ(10U, range.end());
892 EXPECT_STR_EQ("1234567890", model.GetText()); 860 EXPECT_STR_EQ("1234567890", model.GetText());
893 861
894 model.GetCompositionTextRange(&range); 862 model.GetCompositionTextRange(&range);
895 EXPECT_EQ(5U, range.start()); 863 EXPECT_EQ(ui::Range(5, 8), range);
896 EXPECT_EQ(8U, range.end());
897 // composition text 864 // composition text
898 EXPECT_STR_EQ("456", model.GetTextFromRange(ui::Range(3, 6))); 865 EXPECT_STR_EQ("456", model.GetTextFromRange(ui::Range(3, 6)));
899 866
900 gfx::SelectionModel selection; 867 gfx::SelectionModel selection;
901 model.GetSelectionModel(&selection); 868 model.GetSelectionModel(&selection);
902 EXPECT_EQ(7U, selection.selection_start()); 869 EXPECT_EQ(ui::Range(7, 8), selection.selection());
903 EXPECT_EQ(8U, selection.selection_end());
904 EXPECT_STR_EQ("8", model.GetSelectedText()); 870 EXPECT_STR_EQ("8", model.GetSelectedText());
905 871
906 EXPECT_FALSE(composition_text_confirmed_or_cleared_); 872 EXPECT_FALSE(composition_text_confirmed_or_cleared_);
907 model.CancelCompositionText(); 873 model.CancelCompositionText();
908 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 874 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
909 composition_text_confirmed_or_cleared_ = false; 875 composition_text_confirmed_or_cleared_ = false;
910 EXPECT_FALSE(model.HasCompositionText()); 876 EXPECT_FALSE(model.HasCompositionText());
911 EXPECT_FALSE(model.HasSelection()); 877 EXPECT_FALSE(model.HasSelection());
912 EXPECT_EQ(5U, model.GetCursorPosition()); 878 EXPECT_EQ(5U, model.GetCursorPosition());
913 879
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 composition_text_confirmed_or_cleared_ = false; 957 composition_text_confirmed_or_cleared_ = false;
992 EXPECT_STR_EQ("678678", model.GetText()); 958 EXPECT_STR_EQ("678678", model.GetText());
993 959
994 model.SetCompositionText(composition); 960 model.SetCompositionText(composition);
995 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 961 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
996 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 962 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
997 composition_text_confirmed_or_cleared_ = false; 963 composition_text_confirmed_or_cleared_ = false;
998 EXPECT_STR_EQ("678", model.GetText()); 964 EXPECT_STR_EQ("678", model.GetText());
999 965
1000 model.SetCompositionText(composition); 966 model.SetCompositionText(composition);
1001 gfx::SelectionModel sel(model.render_text()->GetSelectionStart(), 967 gfx::SelectionModel sel(
1002 0, 0, gfx::SelectionModel::LEADING); 968 ui::Range(model.render_text()->selection().start(), 0),
969 gfx::CURSOR_FORWARD);
1003 model.MoveCursorTo(sel); 970 model.MoveCursorTo(sel);
1004 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 971 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
1005 composition_text_confirmed_or_cleared_ = false; 972 composition_text_confirmed_or_cleared_ = false;
1006 EXPECT_STR_EQ("678678", model.GetText()); 973 EXPECT_STR_EQ("678678", model.GetText());
1007 974
1008 model.SetCompositionText(composition); 975 model.SetCompositionText(composition);
1009 model.SelectRange(ui::Range(0, 3)); 976 model.SelectRange(ui::Range(0, 3));
1010 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 977 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
1011 composition_text_confirmed_or_cleared_ = false; 978 composition_text_confirmed_or_cleared_ = false;
1012 EXPECT_STR_EQ("678", model.GetText()); 979 EXPECT_STR_EQ("678", model.GetText());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 // Clear history 1063 // Clear history
1097 model.ClearEditHistory(); 1064 model.ClearEditHistory();
1098 EXPECT_FALSE(model.Undo()); 1065 EXPECT_FALSE(model.Undo());
1099 EXPECT_FALSE(model.Redo()); 1066 EXPECT_FALSE(model.Redo());
1100 EXPECT_STR_EQ("a", model.GetText()); 1067 EXPECT_STR_EQ("a", model.GetText());
1101 EXPECT_EQ(1U, model.GetCursorPosition()); 1068 EXPECT_EQ(1U, model.GetCursorPosition());
1102 1069
1103 // Delete =============================== 1070 // Delete ===============================
1104 model.SetText(ASCIIToUTF16("ABCDE")); 1071 model.SetText(ASCIIToUTF16("ABCDE"));
1105 model.ClearEditHistory(); 1072 model.ClearEditHistory();
1106 gfx::SelectionModel sel(2); 1073 MoveCursorTo(model, 2);
1107 model.MoveCursorTo(sel);
1108 EXPECT_TRUE(model.Delete()); 1074 EXPECT_TRUE(model.Delete());
1109 EXPECT_STR_EQ("ABDE", model.GetText()); 1075 EXPECT_STR_EQ("ABDE", model.GetText());
1110 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 1076 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
1111 EXPECT_TRUE(model.Delete()); 1077 EXPECT_TRUE(model.Delete());
1112 EXPECT_STR_EQ("BDE", model.GetText()); 1078 EXPECT_STR_EQ("BDE", model.GetText());
1113 EXPECT_TRUE(model.Undo()); 1079 EXPECT_TRUE(model.Undo());
1114 EXPECT_STR_EQ("ABDE", model.GetText()); 1080 EXPECT_STR_EQ("ABDE", model.GetText());
1115 EXPECT_EQ(0U, model.GetCursorPosition()); 1081 EXPECT_EQ(0U, model.GetCursorPosition());
1116 EXPECT_TRUE(model.Undo()); 1082 EXPECT_TRUE(model.Undo());
1117 EXPECT_STR_EQ("ABCDE", model.GetText()); 1083 EXPECT_STR_EQ("ABCDE", model.GetText());
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 EXPECT_STR_EQ("", model.GetText()); 1335 EXPECT_STR_EQ("", model.GetText());
1370 EXPECT_TRUE(model.Redo()); 1336 EXPECT_TRUE(model.Redo());
1371 EXPECT_STR_EQ("ab", model.GetText()); 1337 EXPECT_STR_EQ("ab", model.GetText());
1372 EXPECT_EQ(2U, model.GetCursorPosition()); 1338 EXPECT_EQ(2U, model.GetCursorPosition());
1373 EXPECT_FALSE(model.Redo()); 1339 EXPECT_FALSE(model.Redo());
1374 } 1340 }
1375 1341
1376 void RunInsertReplaceTest(TextfieldViewsModel& model) { 1342 void RunInsertReplaceTest(TextfieldViewsModel& model) {
1377 gfx::SelectionModel sel; 1343 gfx::SelectionModel sel;
1378 model.GetSelectionModel(&sel); 1344 model.GetSelectionModel(&sel);
1379 bool reverse = (sel.selection_start() > sel.selection_end()); 1345 bool reverse = sel.selection().is_reversed();
1380 1346
1381 model.InsertChar('1'); 1347 model.InsertChar('1');
1382 model.InsertChar('2'); 1348 model.InsertChar('2');
1383 model.InsertChar('3'); 1349 model.InsertChar('3');
1384 EXPECT_STR_EQ("a123d", model.GetText()); 1350 EXPECT_STR_EQ("a123d", model.GetText());
1385 EXPECT_EQ(4U, model.GetCursorPosition()); 1351 EXPECT_EQ(4U, model.GetCursorPosition());
1386 EXPECT_TRUE(model.Undo()); 1352 EXPECT_TRUE(model.Undo());
1387 EXPECT_STR_EQ("abcd", model.GetText()); 1353 EXPECT_STR_EQ("abcd", model.GetText());
1388 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); 1354 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition());
1389 EXPECT_TRUE(model.Undo()); 1355 EXPECT_TRUE(model.Undo());
1390 EXPECT_STR_EQ("", model.GetText()); 1356 EXPECT_STR_EQ("", model.GetText());
1391 EXPECT_EQ(0U, model.GetCursorPosition()); 1357 EXPECT_EQ(0U, model.GetCursorPosition());
1392 EXPECT_FALSE(model.Undo()); 1358 EXPECT_FALSE(model.Undo());
1393 EXPECT_TRUE(model.Redo()); 1359 EXPECT_TRUE(model.Redo());
1394 EXPECT_STR_EQ("abcd", model.GetText()); 1360 EXPECT_STR_EQ("abcd", model.GetText());
1395 EXPECT_EQ(0U, model.GetCursorPosition()); // By SetText 1361 EXPECT_EQ(0U, model.GetCursorPosition()); // By SetText
1396 EXPECT_TRUE(model.Redo()); 1362 EXPECT_TRUE(model.Redo());
1397 EXPECT_STR_EQ("a123d", model.GetText()); 1363 EXPECT_STR_EQ("a123d", model.GetText());
1398 EXPECT_EQ(4U, model.GetCursorPosition()); 1364 EXPECT_EQ(4U, model.GetCursorPosition());
1399 EXPECT_FALSE(model.Redo()); 1365 EXPECT_FALSE(model.Redo());
1400 } 1366 }
1401 1367
1402 void RunOverwriteReplaceTest(TextfieldViewsModel& model) { 1368 void RunOverwriteReplaceTest(TextfieldViewsModel& model) {
1403 gfx::SelectionModel sel; 1369 gfx::SelectionModel sel;
1404 model.GetSelectionModel(&sel); 1370 model.GetSelectionModel(&sel);
1405 bool reverse = (sel.selection_start() > sel.selection_end()); 1371 bool reverse = sel.selection().is_reversed();
1406 1372
1407 model.ReplaceChar('1'); 1373 model.ReplaceChar('1');
1408 model.ReplaceChar('2'); 1374 model.ReplaceChar('2');
1409 model.ReplaceChar('3'); 1375 model.ReplaceChar('3');
1410 model.ReplaceChar('4'); 1376 model.ReplaceChar('4');
1411 EXPECT_STR_EQ("a1234", model.GetText()); 1377 EXPECT_STR_EQ("a1234", model.GetText());
1412 EXPECT_EQ(5U, model.GetCursorPosition()); 1378 EXPECT_EQ(5U, model.GetCursorPosition());
1413 EXPECT_TRUE(model.Undo()); 1379 EXPECT_TRUE(model.Undo());
1414 EXPECT_STR_EQ("abcd", model.GetText()); 1380 EXPECT_STR_EQ("abcd", model.GetText());
1415 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); 1381 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 EXPECT_TRUE(model.Undo()); 1524 EXPECT_TRUE(model.Undo());
1559 EXPECT_STR_EQ("ABCDE", model.GetText()); 1525 EXPECT_STR_EQ("ABCDE", model.GetText());
1560 EXPECT_TRUE(model.Redo()); 1526 EXPECT_TRUE(model.Redo());
1561 EXPECT_STR_EQ("1234", model.GetText()); 1527 EXPECT_STR_EQ("1234", model.GetText());
1562 EXPECT_FALSE(model.Redo()); 1528 EXPECT_FALSE(model.Redo());
1563 1529
1564 // TODO(oshima): We need MockInputMethod to test the behavior with IME. 1530 // TODO(oshima): We need MockInputMethod to test the behavior with IME.
1565 } 1531 }
1566 1532
1567 } // namespace views 1533 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698