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

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: make set_selection_start private, fix accidental inclusion of local hacks Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 TEST_F(TextfieldViewsModelTest, SelectWordTest) { 552 TEST_F(TextfieldViewsModelTest, SelectWordTest) {
554 TextfieldViewsModel model(NULL); 553 TextfieldViewsModel model(NULL);
555 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); 554 model.Append(ASCIIToUTF16(" HELLO !! WO RLD "));
556 555
557 // Test when cursor is at the beginning. 556 // Test when cursor is at the beginning.
558 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 557 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
559 model.SelectWord(); 558 model.SelectWord();
560 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 2U); 559 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 2U);
561 560
562 // Test when cursor is at the beginning of a word. 561 // Test when cursor is at the beginning of a word.
563 gfx::SelectionModel selection(2U); 562 MoveCursorTo(model, 2);
564 model.MoveCursorTo(selection);
565 model.SelectWord(); 563 model.SelectWord();
566 SelectWordTestVerifier(model, ASCIIToUTF16("HELLO"), 7U); 564 SelectWordTestVerifier(model, ASCIIToUTF16("HELLO"), 7U);
567 565
568 // Test when cursor is at the end of a word. 566 // Test when cursor is at the end of a word.
569 selection = gfx::SelectionModel(15U); 567 MoveCursorTo(model, 15);
570 model.MoveCursorTo(selection);
571 model.SelectWord(); 568 model.SelectWord();
572 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); 569 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U);
573 570
574 // Test when cursor is somewhere in a non-alpha-numeric fragment. 571 // Test when cursor is somewhere in a non-alpha-numeric fragment.
575 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { 572 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) {
576 selection = gfx::SelectionModel(cursor_pos); 573 MoveCursorTo(model, cursor_pos);
577 model.MoveCursorTo(selection);
578 model.SelectWord(); 574 model.SelectWord();
579 SelectWordTestVerifier(model, ASCIIToUTF16(" !! "), 13U); 575 SelectWordTestVerifier(model, ASCIIToUTF16(" !! "), 13U);
580 } 576 }
581 577
582 // Test when cursor is somewhere in a whitespace fragment. 578 // Test when cursor is somewhere in a whitespace fragment.
583 selection = gfx::SelectionModel(17U); 579 MoveCursorTo(model, 17);
584 model.MoveCursorTo(selection);
585 model.SelectWord(); 580 model.SelectWord();
586 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); 581 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U);
587 582
588 // Test when cursor is at the end. 583 // Test when cursor is at the end.
589 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 584 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
590 model.SelectWord(); 585 model.SelectWord();
591 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 24U); 586 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 24U);
592 } 587 }
593 588
594 // TODO(xji): temporarily disable in platform Win since the complex script 589 // TODO(xji): temporarily disable in platform Win since the complex script
(...skipping 28 matching lines...) Expand all
623 SelectWordTestVerifier(model, WideToUTF16(word_and_cursor[i].word), 618 SelectWordTestVerifier(model, WideToUTF16(word_and_cursor[i].word),
624 word_and_cursor[i].cursor); 619 word_and_cursor[i].cursor);
625 } 620 }
626 } 621 }
627 #endif 622 #endif
628 623
629 TEST_F(TextfieldViewsModelTest, RangeTest) { 624 TEST_F(TextfieldViewsModelTest, RangeTest) {
630 TextfieldViewsModel model(NULL); 625 TextfieldViewsModel model(NULL);
631 model.Append(ASCIIToUTF16("HELLO WORLD")); 626 model.Append(ASCIIToUTF16("HELLO WORLD"));
632 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 627 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
633 ui::Range range; 628 ui::Range range = model.render_text()->selection();
634 model.GetSelectedRange(&range);
635 EXPECT_TRUE(range.is_empty()); 629 EXPECT_TRUE(range.is_empty());
636 EXPECT_EQ(0U, range.start()); 630 EXPECT_EQ(0U, range.start());
637 EXPECT_EQ(0U, range.end()); 631 EXPECT_EQ(0U, range.end());
638 632
639 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 633 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
640 model.GetSelectedRange(&range); 634 range = model.render_text()->selection();
641 EXPECT_FALSE(range.is_empty()); 635 EXPECT_FALSE(range.is_empty());
642 EXPECT_FALSE(range.is_reversed()); 636 EXPECT_FALSE(range.is_reversed());
643 EXPECT_EQ(0U, range.start()); 637 EXPECT_EQ(0U, range.start());
644 EXPECT_EQ(5U, range.end()); 638 EXPECT_EQ(5U, range.end());
645 639
646 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 640 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true);
647 model.GetSelectedRange(&range); 641 range = model.render_text()->selection();
648 EXPECT_FALSE(range.is_empty()); 642 EXPECT_FALSE(range.is_empty());
649 EXPECT_EQ(0U, range.start()); 643 EXPECT_EQ(0U, range.start());
650 EXPECT_EQ(4U, range.end()); 644 EXPECT_EQ(4U, range.end());
651 645
652 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 646 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
653 model.GetSelectedRange(&range); 647 range = model.render_text()->selection();
654 EXPECT_TRUE(range.is_empty()); 648 EXPECT_TRUE(range.is_empty());
655 EXPECT_EQ(0U, range.start()); 649 EXPECT_EQ(0U, range.start());
656 EXPECT_EQ(0U, range.end()); 650 EXPECT_EQ(0U, range.end());
657 651
658 // now from the end. 652 // now from the end.
659 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 653 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
660 model.GetSelectedRange(&range); 654 range = model.render_text()->selection();
661 EXPECT_TRUE(range.is_empty()); 655 EXPECT_TRUE(range.is_empty());
662 EXPECT_EQ(11U, range.start()); 656 EXPECT_EQ(11U, range.start());
663 EXPECT_EQ(11U, range.end()); 657 EXPECT_EQ(11U, range.end());
664 658
665 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 659 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
666 model.GetSelectedRange(&range); 660 range = model.render_text()->selection();
667 EXPECT_FALSE(range.is_empty()); 661 EXPECT_FALSE(range.is_empty());
668 EXPECT_TRUE(range.is_reversed()); 662 EXPECT_TRUE(range.is_reversed());
669 EXPECT_EQ(11U, range.start()); 663 EXPECT_EQ(11U, range.start());
670 EXPECT_EQ(6U, range.end()); 664 EXPECT_EQ(6U, range.end());
671 665
672 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 666 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
673 model.GetSelectedRange(&range); 667 range = model.render_text()->selection();
674 EXPECT_FALSE(range.is_empty()); 668 EXPECT_FALSE(range.is_empty());
675 EXPECT_TRUE(range.is_reversed()); 669 EXPECT_TRUE(range.is_reversed());
676 EXPECT_EQ(11U, range.start()); 670 EXPECT_EQ(11U, range.start());
677 EXPECT_EQ(7U, range.end()); 671 EXPECT_EQ(7U, range.end());
678 672
679 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 673 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
680 model.GetSelectedRange(&range); 674 range = model.render_text()->selection();
681 EXPECT_TRUE(range.is_empty()); 675 EXPECT_TRUE(range.is_empty());
682 EXPECT_EQ(11U, range.start()); 676 EXPECT_EQ(11U, range.start());
683 EXPECT_EQ(11U, range.end()); 677 EXPECT_EQ(11U, range.end());
684 678
685 // Select All 679 // Select All
686 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); 680 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true);
687 model.GetSelectedRange(&range); 681 range = model.render_text()->selection();
688 EXPECT_FALSE(range.is_empty()); 682 EXPECT_FALSE(range.is_empty());
689 EXPECT_TRUE(range.is_reversed()); 683 EXPECT_TRUE(range.is_reversed());
690 EXPECT_EQ(11U, range.start()); 684 EXPECT_EQ(11U, range.start());
691 EXPECT_EQ(0U, range.end()); 685 EXPECT_EQ(0U, range.end());
692 } 686 }
693 687
694 TEST_F(TextfieldViewsModelTest, SelectRangeTest) { 688 TEST_F(TextfieldViewsModelTest, SelectRangeTest) {
695 TextfieldViewsModel model(NULL); 689 TextfieldViewsModel model(NULL);
696 model.Append(ASCIIToUTF16("HELLO WORLD")); 690 model.Append(ASCIIToUTF16("HELLO WORLD"));
697 ui::Range range(0, 6); 691 ui::Range range(0, 6);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 model.SelectRange(range); 728 model.SelectRange(range);
735 EXPECT_TRUE(model.GetSelectedText().empty()); 729 EXPECT_TRUE(model.GetSelectedText().empty());
736 } 730 }
737 731
738 TEST_F(TextfieldViewsModelTest, SelectionModelTest) { 732 TEST_F(TextfieldViewsModelTest, SelectionModelTest) {
739 TextfieldViewsModel model(NULL); 733 TextfieldViewsModel model(NULL);
740 model.Append(ASCIIToUTF16("HELLO WORLD")); 734 model.Append(ASCIIToUTF16("HELLO WORLD"));
741 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 735 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
742 gfx::SelectionModel sel; 736 gfx::SelectionModel sel;
743 model.GetSelectionModel(&sel); 737 model.GetSelectionModel(&sel);
744 EXPECT_EQ(sel.selection_start(), sel.selection_end()); 738 EXPECT_EQ(ui::Range(0), sel.selection());
745 EXPECT_EQ(0U, sel.selection_start());
746 EXPECT_EQ(0U, sel.selection_end());
747 739
748 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 740 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
749 model.GetSelectionModel(&sel); 741 model.GetSelectionModel(&sel);
750 EXPECT_NE(sel.selection_start(), sel.selection_end()); 742 EXPECT_EQ(ui::Range(0, 5), sel.selection());
751 EXPECT_LE(sel.selection_start(), sel.selection_end());
752 EXPECT_EQ(0U, sel.selection_start());
753 EXPECT_EQ(5U, sel.selection_end());
754 743
755 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 744 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true);
756 model.GetSelectionModel(&sel); 745 model.GetSelectionModel(&sel);
757 EXPECT_NE(sel.selection_start(), sel.selection_end()); 746 EXPECT_EQ(ui::Range(0, 4), sel.selection());
758 EXPECT_EQ(0U, sel.selection_start());
759 EXPECT_EQ(4U, sel.selection_end());
760 747
761 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 748 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
762 model.GetSelectionModel(&sel); 749 model.GetSelectionModel(&sel);
763 EXPECT_EQ(sel.selection_start(), sel.selection_end()); 750 EXPECT_EQ(ui::Range(0), sel.selection());
764 EXPECT_EQ(0U, sel.selection_start());
765 EXPECT_EQ(0U, sel.selection_end());
766 751
767 // now from the end. 752 // now from the end.
768 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 753 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
769 model.GetSelectionModel(&sel); 754 model.GetSelectionModel(&sel);
770 EXPECT_EQ(sel.selection_start(), sel.selection_end()); 755 EXPECT_EQ(ui::Range(11), sel.selection());
771 EXPECT_EQ(11U, sel.selection_start());
772 EXPECT_EQ(11U, sel.selection_end());
773 756
774 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 757 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
775 model.GetSelectionModel(&sel); 758 model.GetSelectionModel(&sel);
776 EXPECT_NE(sel.selection_start(), sel.selection_end()); 759 EXPECT_EQ(ui::Range(11, 6), sel.selection());
777 EXPECT_GT(sel.selection_start(), sel.selection_end());
778 EXPECT_EQ(11U, sel.selection_start());
779 EXPECT_EQ(6U, sel.selection_end());
780 760
781 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 761 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
782 model.GetSelectionModel(&sel); 762 model.GetSelectionModel(&sel);
783 EXPECT_NE(sel.selection_start(), sel.selection_end()); 763 EXPECT_EQ(ui::Range(11, 7), sel.selection());
784 EXPECT_GT(sel.selection_start(), sel.selection_end());
785 EXPECT_EQ(11U, sel.selection_start());
786 EXPECT_EQ(7U, sel.selection_end());
787 764
788 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 765 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
789 model.GetSelectionModel(&sel); 766 model.GetSelectionModel(&sel);
790 EXPECT_EQ(sel.selection_start(), sel.selection_end()); 767 EXPECT_EQ(ui::Range(11), sel.selection());
791 EXPECT_EQ(11U, sel.selection_start());
792 EXPECT_EQ(11U, sel.selection_end());
793 768
794 // Select All 769 // Select All
795 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); 770 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true);
796 model.GetSelectionModel(&sel); 771 model.GetSelectionModel(&sel);
797 EXPECT_NE(sel.selection_start(), sel.selection_end()); 772 EXPECT_EQ(ui::Range(11, 0), sel.selection());
798 EXPECT_GT(sel.selection_start(), sel.selection_end());
799 EXPECT_EQ(11U, sel.selection_start());
800 EXPECT_EQ(0U, sel.selection_end());
801 } 773 }
802 774
803 TEST_F(TextfieldViewsModelTest, SelectSelectionModelTest) { 775 TEST_F(TextfieldViewsModelTest, SelectSelectionModelTest) {
804 TextfieldViewsModel model(NULL); 776 TextfieldViewsModel model(NULL);
805 model.Append(ASCIIToUTF16("HELLO WORLD")); 777 model.Append(ASCIIToUTF16("HELLO WORLD"));
806 model.SelectSelectionModel(gfx::SelectionModel(0, 6, 5, 778 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(0, 6),
807 gfx::SelectionModel::TRAILING)); 779 gfx::CURSOR_BACKWARD));
808 EXPECT_STR_EQ("HELLO ", model.GetSelectedText()); 780 EXPECT_STR_EQ("HELLO ", model.GetSelectedText());
809 781
810 model.SelectSelectionModel(gfx::SelectionModel(6, 1, 1, 782 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(6, 1),
811 gfx::SelectionModel::LEADING)); 783 gfx::CURSOR_FORWARD));
812 EXPECT_STR_EQ("ELLO ", model.GetSelectedText()); 784 EXPECT_STR_EQ("ELLO ", model.GetSelectedText());
813 785
814 model.SelectSelectionModel(gfx::SelectionModel(2, 1000, 999, 786 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(2, 1000),
815 gfx::SelectionModel::TRAILING)); 787 gfx::CURSOR_BACKWARD));
816 EXPECT_STR_EQ("LLO WORLD", model.GetSelectedText()); 788 EXPECT_STR_EQ("LLO WORLD", model.GetSelectedText());
817 789
818 model.SelectSelectionModel(gfx::SelectionModel(1000, 3, 3, 790 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(1000, 3),
819 gfx::SelectionModel::LEADING)); 791 gfx::CURSOR_FORWARD));
820 EXPECT_STR_EQ("LO WORLD", model.GetSelectedText()); 792 EXPECT_STR_EQ("LO WORLD", model.GetSelectedText());
821 793
822 model.SelectSelectionModel(gfx::SelectionModel(0, 0, 0, 794 model.SelectSelectionModel(gfx::SelectionModel(0, gfx::CURSOR_FORWARD));
823 gfx::SelectionModel::LEADING));
824 EXPECT_TRUE(model.GetSelectedText().empty()); 795 EXPECT_TRUE(model.GetSelectedText().empty());
825 796
826 model.SelectSelectionModel(gfx::SelectionModel(3, 3, 3, 797 model.SelectSelectionModel(gfx::SelectionModel(3, gfx::CURSOR_FORWARD));
827 gfx::SelectionModel::LEADING));
828 EXPECT_TRUE(model.GetSelectedText().empty()); 798 EXPECT_TRUE(model.GetSelectedText().empty());
829 799
830 model.SelectSelectionModel(gfx::SelectionModel(1000, 100, 100, 800 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(1000, 100),
831 gfx::SelectionModel::LEADING)); 801 gfx::CURSOR_FORWARD));
832 EXPECT_TRUE(model.GetSelectedText().empty()); 802 EXPECT_TRUE(model.GetSelectedText().empty());
833 803
834 model.SelectSelectionModel(gfx::SelectionModel(1000, 1000, 1000, 804 model.SelectSelectionModel(gfx::SelectionModel(1000, gfx::CURSOR_BACKWARD));
835 gfx::SelectionModel::TRAILING));
836 EXPECT_TRUE(model.GetSelectedText().empty()); 805 EXPECT_TRUE(model.GetSelectedText().empty());
837 } 806 }
838 807
839 TEST_F(TextfieldViewsModelTest, CompositionTextTest) { 808 TEST_F(TextfieldViewsModelTest, CompositionTextTest) {
840 TextfieldViewsModel model(this); 809 TextfieldViewsModel model(this);
841 model.Append(ASCIIToUTF16("1234590")); 810 model.Append(ASCIIToUTF16("1234590"));
842 model.SelectRange(ui::Range(5, 5)); 811 model.SelectRange(ui::Range(5, 5));
843 EXPECT_FALSE(model.HasSelection()); 812 EXPECT_FALSE(model.HasSelection());
844 EXPECT_EQ(5U, model.GetCursorPosition()); 813 EXPECT_EQ(5U, model.GetCursorPosition());
845 814
846 ui::Range range; 815 ui::Range range;
847 model.GetTextRange(&range); 816 model.GetTextRange(&range);
848 EXPECT_EQ(0U, range.start()); 817 EXPECT_EQ(ui::Range(0, 7), range);
849 EXPECT_EQ(7U, range.end());
850 818
851 ui::CompositionText composition; 819 ui::CompositionText composition;
852 composition.text = ASCIIToUTF16("678"); 820 composition.text = ASCIIToUTF16("678");
853 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false)); 821 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false));
854 composition.selection = ui::Range(2, 3); 822 composition.selection = ui::Range(2, 3);
855 model.SetCompositionText(composition); 823 model.SetCompositionText(composition);
856 EXPECT_TRUE(model.HasCompositionText()); 824 EXPECT_TRUE(model.HasCompositionText());
857 EXPECT_TRUE(model.HasSelection()); 825 EXPECT_TRUE(model.HasSelection());
858 826
859 model.GetTextRange(&range); 827 model.GetTextRange(&range);
860 EXPECT_EQ(10U, range.end()); 828 EXPECT_EQ(10U, range.end());
861 EXPECT_STR_EQ("1234567890", model.GetText()); 829 EXPECT_STR_EQ("1234567890", model.GetText());
862 830
863 model.GetCompositionTextRange(&range); 831 model.GetCompositionTextRange(&range);
864 EXPECT_EQ(5U, range.start()); 832 EXPECT_EQ(ui::Range(5, 8), range);
865 EXPECT_EQ(8U, range.end());
866 // composition text 833 // composition text
867 EXPECT_STR_EQ("456", model.GetTextFromRange(ui::Range(3, 6))); 834 EXPECT_STR_EQ("456", model.GetTextFromRange(ui::Range(3, 6)));
868 835
869 gfx::SelectionModel selection; 836 gfx::SelectionModel selection;
870 model.GetSelectionModel(&selection); 837 model.GetSelectionModel(&selection);
871 EXPECT_EQ(7U, selection.selection_start()); 838 EXPECT_EQ(ui::Range(7, 8), selection.selection());
872 EXPECT_EQ(8U, selection.selection_end());
873 EXPECT_STR_EQ("8", model.GetSelectedText()); 839 EXPECT_STR_EQ("8", model.GetSelectedText());
874 840
875 EXPECT_FALSE(composition_text_confirmed_or_cleared_); 841 EXPECT_FALSE(composition_text_confirmed_or_cleared_);
876 model.CancelCompositionText(); 842 model.CancelCompositionText();
877 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 843 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
878 composition_text_confirmed_or_cleared_ = false; 844 composition_text_confirmed_or_cleared_ = false;
879 EXPECT_FALSE(model.HasCompositionText()); 845 EXPECT_FALSE(model.HasCompositionText());
880 EXPECT_FALSE(model.HasSelection()); 846 EXPECT_FALSE(model.HasSelection());
881 EXPECT_EQ(5U, model.GetCursorPosition()); 847 EXPECT_EQ(5U, model.GetCursorPosition());
882 848
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 composition_text_confirmed_or_cleared_ = false; 926 composition_text_confirmed_or_cleared_ = false;
961 EXPECT_STR_EQ("678678", model.GetText()); 927 EXPECT_STR_EQ("678678", model.GetText());
962 928
963 model.SetCompositionText(composition); 929 model.SetCompositionText(composition);
964 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 930 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
965 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 931 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
966 composition_text_confirmed_or_cleared_ = false; 932 composition_text_confirmed_or_cleared_ = false;
967 EXPECT_STR_EQ("678", model.GetText()); 933 EXPECT_STR_EQ("678", model.GetText());
968 934
969 model.SetCompositionText(composition); 935 model.SetCompositionText(composition);
970 gfx::SelectionModel sel(model.render_text()->GetSelectionStart(), 936 gfx::SelectionModel sel(
971 0, 0, gfx::SelectionModel::LEADING); 937 ui::Range(model.render_text()->selection().start(), 0),
938 gfx::CURSOR_FORWARD);
972 model.MoveCursorTo(sel); 939 model.MoveCursorTo(sel);
973 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 940 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
974 composition_text_confirmed_or_cleared_ = false; 941 composition_text_confirmed_or_cleared_ = false;
975 EXPECT_STR_EQ("678678", model.GetText()); 942 EXPECT_STR_EQ("678678", model.GetText());
976 943
977 model.SetCompositionText(composition); 944 model.SetCompositionText(composition);
978 model.SelectRange(ui::Range(0, 3)); 945 model.SelectRange(ui::Range(0, 3));
979 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 946 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
980 composition_text_confirmed_or_cleared_ = false; 947 composition_text_confirmed_or_cleared_ = false;
981 EXPECT_STR_EQ("678", model.GetText()); 948 EXPECT_STR_EQ("678", model.GetText());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 // Clear history 1032 // Clear history
1066 model.ClearEditHistory(); 1033 model.ClearEditHistory();
1067 EXPECT_FALSE(model.Undo()); 1034 EXPECT_FALSE(model.Undo());
1068 EXPECT_FALSE(model.Redo()); 1035 EXPECT_FALSE(model.Redo());
1069 EXPECT_STR_EQ("a", model.GetText()); 1036 EXPECT_STR_EQ("a", model.GetText());
1070 EXPECT_EQ(1U, model.GetCursorPosition()); 1037 EXPECT_EQ(1U, model.GetCursorPosition());
1071 1038
1072 // Delete =============================== 1039 // Delete ===============================
1073 model.SetText(ASCIIToUTF16("ABCDE")); 1040 model.SetText(ASCIIToUTF16("ABCDE"));
1074 model.ClearEditHistory(); 1041 model.ClearEditHistory();
1075 gfx::SelectionModel sel(2); 1042 MoveCursorTo(model, 2);
1076 model.MoveCursorTo(sel);
1077 EXPECT_TRUE(model.Delete()); 1043 EXPECT_TRUE(model.Delete());
1078 EXPECT_STR_EQ("ABDE", model.GetText()); 1044 EXPECT_STR_EQ("ABDE", model.GetText());
1079 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 1045 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
1080 EXPECT_TRUE(model.Delete()); 1046 EXPECT_TRUE(model.Delete());
1081 EXPECT_STR_EQ("BDE", model.GetText()); 1047 EXPECT_STR_EQ("BDE", model.GetText());
1082 EXPECT_TRUE(model.Undo()); 1048 EXPECT_TRUE(model.Undo());
1083 EXPECT_STR_EQ("ABDE", model.GetText()); 1049 EXPECT_STR_EQ("ABDE", model.GetText());
1084 EXPECT_EQ(0U, model.GetCursorPosition()); 1050 EXPECT_EQ(0U, model.GetCursorPosition());
1085 EXPECT_TRUE(model.Undo()); 1051 EXPECT_TRUE(model.Undo());
1086 EXPECT_STR_EQ("ABCDE", model.GetText()); 1052 EXPECT_STR_EQ("ABCDE", model.GetText());
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 EXPECT_STR_EQ("", model.GetText()); 1304 EXPECT_STR_EQ("", model.GetText());
1339 EXPECT_TRUE(model.Redo()); 1305 EXPECT_TRUE(model.Redo());
1340 EXPECT_STR_EQ("ab", model.GetText()); 1306 EXPECT_STR_EQ("ab", model.GetText());
1341 EXPECT_EQ(2U, model.GetCursorPosition()); 1307 EXPECT_EQ(2U, model.GetCursorPosition());
1342 EXPECT_FALSE(model.Redo()); 1308 EXPECT_FALSE(model.Redo());
1343 } 1309 }
1344 1310
1345 void RunInsertReplaceTest(TextfieldViewsModel& model) { 1311 void RunInsertReplaceTest(TextfieldViewsModel& model) {
1346 gfx::SelectionModel sel; 1312 gfx::SelectionModel sel;
1347 model.GetSelectionModel(&sel); 1313 model.GetSelectionModel(&sel);
1348 bool reverse = (sel.selection_start() > sel.selection_end()); 1314 bool reverse = sel.selection().is_reversed();
1349 1315
1350 model.InsertChar('1'); 1316 model.InsertChar('1');
1351 model.InsertChar('2'); 1317 model.InsertChar('2');
1352 model.InsertChar('3'); 1318 model.InsertChar('3');
1353 EXPECT_STR_EQ("a123d", model.GetText()); 1319 EXPECT_STR_EQ("a123d", model.GetText());
1354 EXPECT_EQ(4U, model.GetCursorPosition()); 1320 EXPECT_EQ(4U, model.GetCursorPosition());
1355 EXPECT_TRUE(model.Undo()); 1321 EXPECT_TRUE(model.Undo());
1356 EXPECT_STR_EQ("abcd", model.GetText()); 1322 EXPECT_STR_EQ("abcd", model.GetText());
1357 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); 1323 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition());
1358 EXPECT_TRUE(model.Undo()); 1324 EXPECT_TRUE(model.Undo());
1359 EXPECT_STR_EQ("", model.GetText()); 1325 EXPECT_STR_EQ("", model.GetText());
1360 EXPECT_EQ(0U, model.GetCursorPosition()); 1326 EXPECT_EQ(0U, model.GetCursorPosition());
1361 EXPECT_FALSE(model.Undo()); 1327 EXPECT_FALSE(model.Undo());
1362 EXPECT_TRUE(model.Redo()); 1328 EXPECT_TRUE(model.Redo());
1363 EXPECT_STR_EQ("abcd", model.GetText()); 1329 EXPECT_STR_EQ("abcd", model.GetText());
1364 EXPECT_EQ(0U, model.GetCursorPosition()); // By SetText 1330 EXPECT_EQ(0U, model.GetCursorPosition()); // By SetText
1365 EXPECT_TRUE(model.Redo()); 1331 EXPECT_TRUE(model.Redo());
1366 EXPECT_STR_EQ("a123d", model.GetText()); 1332 EXPECT_STR_EQ("a123d", model.GetText());
1367 EXPECT_EQ(4U, model.GetCursorPosition()); 1333 EXPECT_EQ(4U, model.GetCursorPosition());
1368 EXPECT_FALSE(model.Redo()); 1334 EXPECT_FALSE(model.Redo());
1369 } 1335 }
1370 1336
1371 void RunOverwriteReplaceTest(TextfieldViewsModel& model) { 1337 void RunOverwriteReplaceTest(TextfieldViewsModel& model) {
1372 gfx::SelectionModel sel; 1338 gfx::SelectionModel sel;
1373 model.GetSelectionModel(&sel); 1339 model.GetSelectionModel(&sel);
1374 bool reverse = (sel.selection_start() > sel.selection_end()); 1340 bool reverse = sel.selection().is_reversed();
1375 1341
1376 model.ReplaceChar('1'); 1342 model.ReplaceChar('1');
1377 model.ReplaceChar('2'); 1343 model.ReplaceChar('2');
1378 model.ReplaceChar('3'); 1344 model.ReplaceChar('3');
1379 model.ReplaceChar('4'); 1345 model.ReplaceChar('4');
1380 EXPECT_STR_EQ("a1234", model.GetText()); 1346 EXPECT_STR_EQ("a1234", model.GetText());
1381 EXPECT_EQ(5U, model.GetCursorPosition()); 1347 EXPECT_EQ(5U, model.GetCursorPosition());
1382 EXPECT_TRUE(model.Undo()); 1348 EXPECT_TRUE(model.Undo());
1383 EXPECT_STR_EQ("abcd", model.GetText()); 1349 EXPECT_STR_EQ("abcd", model.GetText());
1384 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); 1350 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1527 EXPECT_TRUE(model.Undo()); 1493 EXPECT_TRUE(model.Undo());
1528 EXPECT_STR_EQ("ABCDE", model.GetText()); 1494 EXPECT_STR_EQ("ABCDE", model.GetText());
1529 EXPECT_TRUE(model.Redo()); 1495 EXPECT_TRUE(model.Redo());
1530 EXPECT_STR_EQ("1234", model.GetText()); 1496 EXPECT_STR_EQ("1234", model.GetText());
1531 EXPECT_FALSE(model.Redo()); 1497 EXPECT_FALSE(model.Redo());
1532 1498
1533 // TODO(oshima): We need MockInputMethod to test the behavior with IME. 1499 // TODO(oshima): We need MockInputMethod to test the behavior with IME.
1534 } 1500 }
1535 1501
1536 } // namespace views 1502 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698