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

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

Issue 2228833002: MacViews: Fix behavior of move and select commands when selection direction changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@use_text_commands
Patch Set: Add apple rdar in comment. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/views/controls/textfield/textfield_model.h" 5 #include "ui/views/controls/textfield/textfield_model.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 TEST_F(TextfieldModelTest, EditString) { 82 TEST_F(TextfieldModelTest, EditString) {
83 TextfieldModel model(NULL); 83 TextfieldModel model(NULL);
84 // Append two strings. 84 // Append two strings.
85 model.Append(base::ASCIIToUTF16("HILL")); 85 model.Append(base::ASCIIToUTF16("HILL"));
86 EXPECT_STR_EQ("HILL", model.text()); 86 EXPECT_STR_EQ("HILL", model.text());
87 model.Append(base::ASCIIToUTF16("WORLD")); 87 model.Append(base::ASCIIToUTF16("WORLD"));
88 EXPECT_STR_EQ("HILLWORLD", model.text()); 88 EXPECT_STR_EQ("HILLWORLD", model.text());
89 89
90 // Insert "E" and replace "I" with "L" to make "HELLO". 90 // Insert "E" and replace "I" with "L" to make "HELLO".
91 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 91 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
92 gfx::SELECTION_NONE);
92 model.InsertChar('E'); 93 model.InsertChar('E');
93 EXPECT_STR_EQ("HEILLWORLD", model.text()); 94 EXPECT_STR_EQ("HEILLWORLD", model.text());
94 model.ReplaceChar('L'); 95 model.ReplaceChar('L');
95 EXPECT_STR_EQ("HELLLWORLD", model.text()); 96 EXPECT_STR_EQ("HELLLWORLD", model.text());
96 model.ReplaceChar('L'); 97 model.ReplaceChar('L');
97 model.ReplaceChar('O'); 98 model.ReplaceChar('O');
98 EXPECT_STR_EQ("HELLOWORLD", model.text()); 99 EXPECT_STR_EQ("HELLOWORLD", model.text());
99 100
100 // Delete 6th char "W", then delete 5th char "O". 101 // Delete 6th char "W", then delete 5th char "O".
101 EXPECT_EQ(5U, model.GetCursorPosition()); 102 EXPECT_EQ(5U, model.GetCursorPosition());
102 EXPECT_TRUE(model.Delete()); 103 EXPECT_TRUE(model.Delete());
103 EXPECT_STR_EQ("HELLOORLD", model.text()); 104 EXPECT_STR_EQ("HELLOORLD", model.text());
104 EXPECT_TRUE(model.Backspace()); 105 EXPECT_TRUE(model.Backspace());
105 EXPECT_EQ(4U, model.GetCursorPosition()); 106 EXPECT_EQ(4U, model.GetCursorPosition());
106 EXPECT_STR_EQ("HELLORLD", model.text()); 107 EXPECT_STR_EQ("HELLORLD", model.text());
107 108
108 // Move the cursor to start; backspace should fail. 109 // Move the cursor to start; backspace should fail.
109 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 110 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
110 EXPECT_FALSE(model.Backspace()); 111 EXPECT_FALSE(model.Backspace());
111 EXPECT_STR_EQ("HELLORLD", model.text()); 112 EXPECT_STR_EQ("HELLORLD", model.text());
112 // Move the cursor to the end; delete should fail, but backspace should work. 113 // Move the cursor to the end; delete should fail, but backspace should work.
113 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 114 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
114 EXPECT_FALSE(model.Delete()); 115 EXPECT_FALSE(model.Delete());
115 EXPECT_STR_EQ("HELLORLD", model.text()); 116 EXPECT_STR_EQ("HELLORLD", model.text());
116 EXPECT_TRUE(model.Backspace()); 117 EXPECT_TRUE(model.Backspace());
117 EXPECT_STR_EQ("HELLORL", model.text()); 118 EXPECT_STR_EQ("HELLORL", model.text());
118 119
119 MoveCursorTo(model, 5); 120 MoveCursorTo(model, 5);
120 model.ReplaceText(base::ASCIIToUTF16(" WOR")); 121 model.ReplaceText(base::ASCIIToUTF16(" WOR"));
121 EXPECT_STR_EQ("HELLO WORL", model.text()); 122 EXPECT_STR_EQ("HELLO WORL", model.text());
122 } 123 }
123 124
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 MoveCursorTo(model, 0); 235 MoveCursorTo(model, 0);
235 EXPECT_TRUE(model.Delete()); 236 EXPECT_TRUE(model.Delete());
236 EXPECT_TRUE(model.Delete()); 237 EXPECT_TRUE(model.Delete());
237 EXPECT_TRUE(model.Delete()); 238 EXPECT_TRUE(model.Delete());
238 EXPECT_TRUE(model.Delete()); 239 EXPECT_TRUE(model.Delete());
239 EXPECT_EQ(base::WideToUTF16(L""), model.text()); 240 EXPECT_EQ(base::WideToUTF16(L""), model.text());
240 241
241 // The first 2 characters are not strong directionality characters. 242 // The first 2 characters are not strong directionality characters.
242 model.SetText( 243 model.SetText(
243 base::WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); 244 base::WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC"));
244 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 245 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
245 EXPECT_TRUE(model.Backspace()); 246 EXPECT_TRUE(model.Backspace());
246 EXPECT_EQ(base::WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"), 247 EXPECT_EQ(base::WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"),
247 model.text()); 248 model.text());
248 } 249 }
249 250
250 TEST_F(TextfieldModelTest, EmptyString) { 251 TEST_F(TextfieldModelTest, EmptyString) {
251 TextfieldModel model(NULL); 252 TextfieldModel model(NULL);
252 EXPECT_EQ(base::string16(), model.text()); 253 EXPECT_EQ(base::string16(), model.text());
253 EXPECT_EQ(base::string16(), model.GetSelectedText()); 254 EXPECT_EQ(base::string16(), model.GetSelectedText());
254 255
255 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 256 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
257 gfx::SELECTION_RETAIN);
256 EXPECT_EQ(0U, model.GetCursorPosition()); 258 EXPECT_EQ(0U, model.GetCursorPosition());
257 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 259 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
260 gfx::SELECTION_RETAIN);
258 EXPECT_EQ(0U, model.GetCursorPosition()); 261 EXPECT_EQ(0U, model.GetCursorPosition());
259 262
260 EXPECT_EQ(base::string16(), model.GetSelectedText()); 263 EXPECT_EQ(base::string16(), model.GetSelectedText());
261 264
262 EXPECT_FALSE(model.Delete()); 265 EXPECT_FALSE(model.Delete());
263 EXPECT_FALSE(model.Backspace()); 266 EXPECT_FALSE(model.Backspace());
264 } 267 }
265 268
266 TEST_F(TextfieldModelTest, Selection) { 269 TEST_F(TextfieldModelTest, Selection) {
267 TextfieldModel model(NULL); 270 TextfieldModel model(NULL);
268 model.Append(base::ASCIIToUTF16("HELLO")); 271 model.Append(base::ASCIIToUTF16("HELLO"));
269 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 272 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
270 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 273 gfx::SELECTION_NONE);
274 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
275 gfx::SELECTION_RETAIN);
271 EXPECT_STR_EQ("E", model.GetSelectedText()); 276 EXPECT_STR_EQ("E", model.GetSelectedText());
272 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 277 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
278 gfx::SELECTION_RETAIN);
273 EXPECT_STR_EQ("EL", model.GetSelectedText()); 279 EXPECT_STR_EQ("EL", model.GetSelectedText());
274 280
275 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); 281 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
276 EXPECT_STR_EQ("H", model.GetSelectedText()); 282 EXPECT_STR_EQ("H", model.GetSelectedText());
277 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, true); 283 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_RETAIN);
278 EXPECT_STR_EQ("ELLO", model.GetSelectedText()); 284 EXPECT_STR_EQ("ELLO", model.GetSelectedText());
279 model.ClearSelection(); 285 model.ClearSelection();
280 EXPECT_EQ(base::string16(), model.GetSelectedText()); 286 EXPECT_EQ(base::string16(), model.GetSelectedText());
281 287
282 // SelectAll(false) selects towards the end. 288 // SelectAll(false) selects towards the end.
283 model.SelectAll(false); 289 model.SelectAll(false);
284 EXPECT_STR_EQ("HELLO", model.GetSelectedText()); 290 EXPECT_STR_EQ("HELLO", model.GetSelectedText());
285 EXPECT_EQ(gfx::Range(0, 5), model.render_text()->selection()); 291 EXPECT_EQ(gfx::Range(0, 5), model.render_text()->selection());
286 292
287 // SelectAll(true) selects towards the beginning. 293 // SelectAll(true) selects towards the beginning.
288 model.SelectAll(true); 294 model.SelectAll(true);
289 EXPECT_STR_EQ("HELLO", model.GetSelectedText()); 295 EXPECT_STR_EQ("HELLO", model.GetSelectedText());
290 EXPECT_EQ(gfx::Range(5, 0), model.render_text()->selection()); 296 EXPECT_EQ(gfx::Range(5, 0), model.render_text()->selection());
291 297
292 // Select and move cursor. 298 // Select and move cursor.
293 model.SelectRange(gfx::Range(1U, 3U)); 299 model.SelectRange(gfx::Range(1U, 3U));
294 EXPECT_STR_EQ("EL", model.GetSelectedText()); 300 EXPECT_STR_EQ("EL", model.GetSelectedText());
295 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); 301 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
296 EXPECT_EQ(1U, model.GetCursorPosition()); 302 EXPECT_EQ(1U, model.GetCursorPosition());
297 model.SelectRange(gfx::Range(1U, 3U)); 303 model.SelectRange(gfx::Range(1U, 3U));
298 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 304 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
305 gfx::SELECTION_NONE);
299 EXPECT_EQ(3U, model.GetCursorPosition()); 306 EXPECT_EQ(3U, model.GetCursorPosition());
300 307
301 // Select all and move cursor. 308 // Select all and move cursor.
302 model.SelectAll(false); 309 model.SelectAll(false);
303 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); 310 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
304 EXPECT_EQ(0U, model.GetCursorPosition()); 311 EXPECT_EQ(0U, model.GetCursorPosition());
305 model.SelectAll(false); 312 model.SelectAll(false);
306 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 313 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
314 gfx::SELECTION_NONE);
307 EXPECT_EQ(5U, model.GetCursorPosition()); 315 EXPECT_EQ(5U, model.GetCursorPosition());
308 } 316 }
309 317
310 TEST_F(TextfieldModelTest, Selection_BidiWithNonSpacingMarks) { 318 TEST_F(TextfieldModelTest, Selection_BidiWithNonSpacingMarks) {
311 // Selection is a logical operation. And it should work with the arrow 319 // Selection is a logical operation. And it should work with the arrow
312 // keys doing visual movements, while the selection is logical between 320 // keys doing visual movements, while the selection is logical between
313 // the (logical) start and end points. Selection is simply defined as 321 // the (logical) start and end points. Selection is simply defined as
314 // the portion of text between the logical positions of the start and end 322 // the portion of text between the logical positions of the start and end
315 // caret positions. 323 // caret positions.
316 TextfieldModel model(NULL); 324 TextfieldModel model(NULL);
317 // TODO(xji): temporarily disable in platform Win since the complex script 325 // TODO(xji): temporarily disable in platform Win since the complex script
318 // characters turned into empty square due to font regression. So, not able 326 // characters turned into empty square due to font regression. So, not able
319 // to test 2 characters belong to the same grapheme. 327 // to test 2 characters belong to the same grapheme.
320 #if defined(OS_LINUX) 328 #if defined(OS_LINUX)
321 model.Append(base::WideToUTF16( 329 model.Append(base::WideToUTF16(
322 L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"def")); 330 L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"def"));
323 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 331 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
324 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 332 gfx::SELECTION_NONE);
333 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
334 gfx::SELECTION_NONE);
325 335
326 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 336 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
337 gfx::SELECTION_RETAIN);
327 EXPECT_EQ(gfx::Range(2, 3), model.render_text()->selection()); 338 EXPECT_EQ(gfx::Range(2, 3), model.render_text()->selection());
328 EXPECT_EQ(base::WideToUTF16(L"c"), model.GetSelectedText()); 339 EXPECT_EQ(base::WideToUTF16(L"c"), model.GetSelectedText());
329 340
330 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 341 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
342 gfx::SELECTION_RETAIN);
331 EXPECT_EQ(gfx::Range(2, 7), model.render_text()->selection()); 343 EXPECT_EQ(gfx::Range(2, 7), model.render_text()->selection());
332 EXPECT_EQ(base::WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8"), 344 EXPECT_EQ(base::WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8"),
333 model.GetSelectedText()); 345 model.GetSelectedText());
334 346
335 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 347 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
348 gfx::SELECTION_RETAIN);
336 EXPECT_EQ(gfx::Range(2, 3), model.render_text()->selection()); 349 EXPECT_EQ(gfx::Range(2, 3), model.render_text()->selection());
337 EXPECT_EQ(base::WideToUTF16(L"c"), model.GetSelectedText()); 350 EXPECT_EQ(base::WideToUTF16(L"c"), model.GetSelectedText());
338 351
339 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 352 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
353 gfx::SELECTION_RETAIN);
340 EXPECT_EQ(gfx::Range(2, 10), model.render_text()->selection()); 354 EXPECT_EQ(gfx::Range(2, 10), model.render_text()->selection());
341 EXPECT_EQ(base::WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"d"), 355 EXPECT_EQ(base::WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"d"),
342 model.GetSelectedText()); 356 model.GetSelectedText());
343 357
344 model.ClearSelection(); 358 model.ClearSelection();
345 EXPECT_EQ(base::string16(), model.GetSelectedText()); 359 EXPECT_EQ(base::string16(), model.GetSelectedText());
346 model.SelectAll(false); 360 model.SelectAll(false);
347 EXPECT_EQ( 361 EXPECT_EQ(
348 base::WideToUTF16(L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"def"), 362 base::WideToUTF16(L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"def"),
349 model.GetSelectedText()); 363 model.GetSelectedText());
350 #endif 364 #endif
351 365
352 // In case of "aBc", this test shows how to select "aB" or "Bc", assume 'B' is 366 // In case of "aBc", this test shows how to select "aB" or "Bc", assume 'B' is
353 // an RTL character. 367 // an RTL character.
354 model.SetText(base::WideToUTF16(L"a\x05E9" L"b")); 368 model.SetText(base::WideToUTF16(L"a\x05E9" L"b"));
355 MoveCursorTo(model, 0); 369 MoveCursorTo(model, 0);
356 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 370 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
371 gfx::SELECTION_RETAIN);
357 EXPECT_EQ(base::WideToUTF16(L"a"), model.GetSelectedText()); 372 EXPECT_EQ(base::WideToUTF16(L"a"), model.GetSelectedText());
358 373
359 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 374 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
375 gfx::SELECTION_RETAIN);
360 EXPECT_EQ(base::WideToUTF16(L"a"), model.GetSelectedText()); 376 EXPECT_EQ(base::WideToUTF16(L"a"), model.GetSelectedText());
361 377
362 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 378 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
379 gfx::SELECTION_RETAIN);
363 EXPECT_EQ(base::WideToUTF16(L"a\x05E9" L"b"), model.GetSelectedText()); 380 EXPECT_EQ(base::WideToUTF16(L"a\x05E9" L"b"), model.GetSelectedText());
364 381
365 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 382 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
383 gfx::SELECTION_NONE);
366 EXPECT_EQ(3U, model.GetCursorPosition()); 384 EXPECT_EQ(3U, model.GetCursorPosition());
367 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 385 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
386 gfx::SELECTION_RETAIN);
368 EXPECT_EQ(base::WideToUTF16(L"b"), model.GetSelectedText()); 387 EXPECT_EQ(base::WideToUTF16(L"b"), model.GetSelectedText());
369 388
370 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 389 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
390 gfx::SELECTION_RETAIN);
371 EXPECT_EQ(base::WideToUTF16(L"b"), model.GetSelectedText()); 391 EXPECT_EQ(base::WideToUTF16(L"b"), model.GetSelectedText());
372 392
373 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 393 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
394 gfx::SELECTION_RETAIN);
374 EXPECT_EQ(base::WideToUTF16(L"a\x05E9" L"b"), model.GetSelectedText()); 395 EXPECT_EQ(base::WideToUTF16(L"a\x05E9" L"b"), model.GetSelectedText());
375 396
376 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 397 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
377 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 398 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
378 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 399 gfx::SELECTION_RETAIN);
379 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 400 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
401 gfx::SELECTION_RETAIN);
402 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
403 gfx::SELECTION_RETAIN);
380 EXPECT_EQ(base::WideToUTF16(L"a\x05E9"), model.GetSelectedText()); 404 EXPECT_EQ(base::WideToUTF16(L"a\x05E9"), model.GetSelectedText());
381 405
382 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 406 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
383 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 407 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
384 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 408 gfx::SELECTION_RETAIN);
385 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 409 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
410 gfx::SELECTION_RETAIN);
411 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
412 gfx::SELECTION_RETAIN);
386 EXPECT_EQ(base::WideToUTF16(L"\x05E9" L"b"), model.GetSelectedText()); 413 EXPECT_EQ(base::WideToUTF16(L"\x05E9" L"b"), model.GetSelectedText());
387 414
388 model.ClearSelection(); 415 model.ClearSelection();
389 EXPECT_EQ(base::string16(), model.GetSelectedText()); 416 EXPECT_EQ(base::string16(), model.GetSelectedText());
390 model.SelectAll(false); 417 model.SelectAll(false);
391 EXPECT_EQ(base::WideToUTF16(L"a\x05E9" L"b"), model.GetSelectedText()); 418 EXPECT_EQ(base::WideToUTF16(L"a\x05E9" L"b"), model.GetSelectedText());
392 } 419 }
393 420
394 TEST_F(TextfieldModelTest, SelectionAndEdit) { 421 TEST_F(TextfieldModelTest, SelectionAndEdit) {
395 TextfieldModel model(NULL); 422 TextfieldModel model(NULL);
396 model.Append(base::ASCIIToUTF16("HELLO")); 423 model.Append(base::ASCIIToUTF16("HELLO"));
397 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 424 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
398 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 425 gfx::SELECTION_NONE);
399 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "EL" 426 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
427 gfx::SELECTION_RETAIN);
428 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
429 gfx::SELECTION_RETAIN); // "EL"
400 EXPECT_TRUE(model.Backspace()); 430 EXPECT_TRUE(model.Backspace());
401 EXPECT_STR_EQ("HLO", model.text()); 431 EXPECT_STR_EQ("HLO", model.text());
402 432
403 model.Append(base::ASCIIToUTF16("ILL")); 433 model.Append(base::ASCIIToUTF16("ILL"));
404 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 434 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
405 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "LO" 435 gfx::SELECTION_RETAIN);
436 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
437 gfx::SELECTION_RETAIN); // "LO"
406 EXPECT_TRUE(model.Delete()); 438 EXPECT_TRUE(model.Delete());
407 EXPECT_STR_EQ("HILL", model.text()); 439 EXPECT_STR_EQ("HILL", model.text());
408 EXPECT_EQ(1U, model.GetCursorPosition()); 440 EXPECT_EQ(1U, model.GetCursorPosition());
409 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "I" 441 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
442 gfx::SELECTION_RETAIN); // "I"
410 model.InsertChar('E'); 443 model.InsertChar('E');
411 EXPECT_STR_EQ("HELL", model.text()); 444 EXPECT_STR_EQ("HELL", model.text());
412 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 445 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
413 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "H" 446 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
447 gfx::SELECTION_RETAIN); // "H"
414 model.ReplaceChar('B'); 448 model.ReplaceChar('B');
415 EXPECT_STR_EQ("BELL", model.text()); 449 EXPECT_STR_EQ("BELL", model.text());
416 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 450 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
417 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 451 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
418 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); // "ELL" 452 gfx::SELECTION_RETAIN);
453 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
454 gfx::SELECTION_RETAIN); // "ELL"
419 model.ReplaceChar('E'); 455 model.ReplaceChar('E');
420 EXPECT_STR_EQ("BEE", model.text()); 456 EXPECT_STR_EQ("BEE", model.text());
421 } 457 }
422 458
423 TEST_F(TextfieldModelTest, Word) { 459 TEST_F(TextfieldModelTest, Word) {
424 TextfieldModel model(NULL); 460 TextfieldModel model(NULL);
425 model.Append( 461 model.Append(
426 base::ASCIIToUTF16("The answer to Life, the Universe, and Everything")); 462 base::ASCIIToUTF16("The answer to Life, the Universe, and Everything"));
427 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); 463 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
428 EXPECT_EQ(3U, model.GetCursorPosition()); 464 EXPECT_EQ(3U, model.GetCursorPosition());
429 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); 465 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
430 EXPECT_EQ(10U, model.GetCursorPosition()); 466 EXPECT_EQ(10U, model.GetCursorPosition());
431 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); 467 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
432 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); 468 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
433 EXPECT_EQ(18U, model.GetCursorPosition()); 469 EXPECT_EQ(18U, model.GetCursorPosition());
434 470
435 // Should passes the non word char ',' 471 // Should passes the non word char ','
436 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 472 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_RETAIN);
437 EXPECT_EQ(23U, model.GetCursorPosition()); 473 EXPECT_EQ(23U, model.GetCursorPosition());
438 EXPECT_STR_EQ(", the", model.GetSelectedText()); 474 EXPECT_STR_EQ(", the", model.GetSelectedText());
439 475
440 // Move to the end. 476 // Move to the end.
441 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 477 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_RETAIN);
442 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 478 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_RETAIN);
443 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 479 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_RETAIN);
444 EXPECT_STR_EQ(", the Universe, and Everything", model.GetSelectedText()); 480 EXPECT_STR_EQ(", the Universe, and Everything", model.GetSelectedText());
445 // Should be safe to go next word at the end. 481 // Should be safe to go next word at the end.
446 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 482 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_RETAIN);
447 EXPECT_STR_EQ(", the Universe, and Everything", model.GetSelectedText()); 483 EXPECT_STR_EQ(", the Universe, and Everything", model.GetSelectedText());
448 model.InsertChar('2'); 484 model.InsertChar('2');
449 EXPECT_EQ(19U, model.GetCursorPosition()); 485 EXPECT_EQ(19U, model.GetCursorPosition());
450 486
451 // Now backwards. 487 // Now backwards.
452 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); // leave 2. 488 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
453 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 489 gfx::SELECTION_NONE); // leave 2.
490 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
454 EXPECT_EQ(14U, model.GetCursorPosition()); 491 EXPECT_EQ(14U, model.GetCursorPosition());
455 EXPECT_STR_EQ("Life", model.GetSelectedText()); 492 EXPECT_STR_EQ("Life", model.GetSelectedText());
456 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 493 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
457 EXPECT_STR_EQ("to Life", model.GetSelectedText()); 494 EXPECT_STR_EQ("to Life", model.GetSelectedText());
458 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 495 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
459 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 496 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
460 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); // Now at start. 497 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT,
498 gfx::SELECTION_RETAIN); // Now at start.
461 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); 499 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText());
462 // Should be safe to go to the previous word at the beginning. 500 // Should be safe to go to the previous word at the beginning.
463 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 501 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
464 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); 502 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText());
465 model.ReplaceChar('4'); 503 model.ReplaceChar('4');
466 EXPECT_EQ(base::string16(), model.GetSelectedText()); 504 EXPECT_EQ(base::string16(), model.GetSelectedText());
467 EXPECT_STR_EQ("42", model.text()); 505 EXPECT_STR_EQ("42", model.text());
468 } 506 }
469 507
470 TEST_F(TextfieldModelTest, SetText) { 508 TEST_F(TextfieldModelTest, SetText) {
471 TextfieldModel model(NULL); 509 TextfieldModel model(NULL);
472 model.Append(base::ASCIIToUTF16("HELLO")); 510 model.Append(base::ASCIIToUTF16("HELLO"));
473 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 511 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
474 model.SetText(base::ASCIIToUTF16("GOODBYE")); 512 model.SetText(base::ASCIIToUTF16("GOODBYE"));
475 EXPECT_STR_EQ("GOODBYE", model.text()); 513 EXPECT_STR_EQ("GOODBYE", model.text());
476 // SetText move the cursor to the end of the new text. 514 // SetText move the cursor to the end of the new text.
477 EXPECT_EQ(7U, model.GetCursorPosition()); 515 EXPECT_EQ(7U, model.GetCursorPosition());
478 model.SelectAll(false); 516 model.SelectAll(false);
479 EXPECT_STR_EQ("GOODBYE", model.GetSelectedText()); 517 EXPECT_STR_EQ("GOODBYE", model.GetSelectedText());
480 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 518 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
481 EXPECT_EQ(7U, model.GetCursorPosition()); 519 EXPECT_EQ(7U, model.GetCursorPosition());
482 520
483 model.SetText(base::ASCIIToUTF16("BYE")); 521 model.SetText(base::ASCIIToUTF16("BYE"));
484 // Setting shorter string moves the cursor to the end of the new string. 522 // Setting shorter string moves the cursor to the end of the new string.
485 EXPECT_EQ(3U, model.GetCursorPosition()); 523 EXPECT_EQ(3U, model.GetCursorPosition());
486 EXPECT_EQ(base::string16(), model.GetSelectedText()); 524 EXPECT_EQ(base::string16(), model.GetSelectedText());
487 model.SetText(base::string16()); 525 model.SetText(base::string16());
488 EXPECT_EQ(0U, model.GetCursorPosition()); 526 EXPECT_EQ(0U, model.GetCursorPosition());
489 } 527 }
490 528
491 TEST_F(TextfieldModelTest, Clipboard) { 529 TEST_F(TextfieldModelTest, Clipboard) {
492 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); 530 ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread();
493 const base::string16 initial_clipboard_text = 531 const base::string16 initial_clipboard_text =
494 base::ASCIIToUTF16("initial text"); 532 base::ASCIIToUTF16("initial text");
495 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_COPY_PASTE) 533 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_COPY_PASTE)
496 .WriteText(initial_clipboard_text); 534 .WriteText(initial_clipboard_text);
497 535
498 base::string16 clipboard_text; 536 base::string16 clipboard_text;
499 TextfieldModel model(NULL); 537 TextfieldModel model(NULL);
500 model.Append(base::ASCIIToUTF16("HELLO WORLD")); 538 model.Append(base::ASCIIToUTF16("HELLO WORLD"));
501 539
502 // Cut with an empty selection should do nothing. 540 // Cut with an empty selection should do nothing.
503 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 541 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
504 EXPECT_FALSE(model.Cut()); 542 EXPECT_FALSE(model.Cut());
505 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); 543 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text);
506 EXPECT_EQ(initial_clipboard_text, clipboard_text); 544 EXPECT_EQ(initial_clipboard_text, clipboard_text);
507 EXPECT_STR_EQ("HELLO WORLD", model.text()); 545 EXPECT_STR_EQ("HELLO WORLD", model.text());
508 EXPECT_EQ(11U, model.GetCursorPosition()); 546 EXPECT_EQ(11U, model.GetCursorPosition());
509 547
510 // Copy with an empty selection should do nothing. 548 // Copy with an empty selection should do nothing.
511 model.Copy(); 549 model.Copy();
512 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); 550 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text);
513 EXPECT_EQ(initial_clipboard_text, clipboard_text); 551 EXPECT_EQ(initial_clipboard_text, clipboard_text);
(...skipping 12 matching lines...) Expand all
526 // Copy on obscured (password) text should do nothing. 564 // Copy on obscured (password) text should do nothing.
527 model.SelectAll(false); 565 model.SelectAll(false);
528 EXPECT_FALSE(model.Copy()); 566 EXPECT_FALSE(model.Copy());
529 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); 567 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text);
530 EXPECT_EQ(initial_clipboard_text, clipboard_text); 568 EXPECT_EQ(initial_clipboard_text, clipboard_text);
531 EXPECT_STR_EQ("HELLO WORLD", model.text()); 569 EXPECT_STR_EQ("HELLO WORLD", model.text());
532 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText()); 570 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText());
533 571
534 // Cut with non-empty selection. 572 // Cut with non-empty selection.
535 model.render_text()->SetObscured(false); 573 model.render_text()->SetObscured(false);
536 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 574 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
537 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 575 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
538 EXPECT_TRUE(model.Cut()); 576 EXPECT_TRUE(model.Cut());
539 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); 577 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text);
540 EXPECT_STR_EQ("WORLD", clipboard_text); 578 EXPECT_STR_EQ("WORLD", clipboard_text);
541 EXPECT_STR_EQ("HELLO ", model.text()); 579 EXPECT_STR_EQ("HELLO ", model.text());
542 EXPECT_EQ(6U, model.GetCursorPosition()); 580 EXPECT_EQ(6U, model.GetCursorPosition());
543 581
544 // Copy with non-empty selection. 582 // Copy with non-empty selection.
545 model.SelectAll(false); 583 model.SelectAll(false);
546 EXPECT_TRUE(model.Copy()); 584 EXPECT_TRUE(model.Copy());
547 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); 585 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text);
548 EXPECT_STR_EQ("HELLO ", clipboard_text); 586 EXPECT_STR_EQ("HELLO ", clipboard_text);
549 EXPECT_STR_EQ("HELLO ", model.text()); 587 EXPECT_STR_EQ("HELLO ", model.text());
550 EXPECT_EQ(6U, model.GetCursorPosition()); 588 EXPECT_EQ(6U, model.GetCursorPosition());
551 589
552 // Test that paste works regardless of the obscured bit. Please note that 590 // Test that paste works regardless of the obscured bit. Please note that
553 // trailing spaces and tabs in clipboard strings will be stripped. 591 // trailing spaces and tabs in clipboard strings will be stripped.
554 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 592 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
555 EXPECT_TRUE(model.Paste()); 593 EXPECT_TRUE(model.Paste());
556 EXPECT_STR_EQ("HELLO HELLO", model.text()); 594 EXPECT_STR_EQ("HELLO HELLO", model.text());
557 EXPECT_EQ(11U, model.GetCursorPosition()); 595 EXPECT_EQ(11U, model.GetCursorPosition());
558 model.render_text()->SetObscured(true); 596 model.render_text()->SetObscured(true);
559 EXPECT_TRUE(model.Paste()); 597 EXPECT_TRUE(model.Paste());
560 EXPECT_STR_EQ("HELLO HELLOHELLO", model.text()); 598 EXPECT_STR_EQ("HELLO HELLOHELLO", model.text());
561 EXPECT_EQ(16U, model.GetCursorPosition()); 599 EXPECT_EQ(16U, model.GetCursorPosition());
562 } 600 }
563 601
564 static void SelectWordTestVerifier( 602 static void SelectWordTestVerifier(
565 const TextfieldModel& model, 603 const TextfieldModel& model,
566 const base::string16 &expected_selected_string, 604 const base::string16 &expected_selected_string,
567 size_t expected_cursor_pos) { 605 size_t expected_cursor_pos) {
568 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); 606 EXPECT_EQ(expected_selected_string, model.GetSelectedText());
569 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); 607 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition());
570 } 608 }
571 609
572 TEST_F(TextfieldModelTest, SelectWordTest) { 610 TEST_F(TextfieldModelTest, SelectWordTest) {
573 TextfieldModel model(NULL); 611 TextfieldModel model(NULL);
574 model.Append(base::ASCIIToUTF16(" HELLO !! WO RLD ")); 612 model.Append(base::ASCIIToUTF16(" HELLO !! WO RLD "));
575 613
576 // Test when cursor is at the beginning. 614 // Test when cursor is at the beginning.
577 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 615 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
578 model.SelectWord(); 616 model.SelectWord();
579 SelectWordTestVerifier(model, base::ASCIIToUTF16(" "), 2U); 617 SelectWordTestVerifier(model, base::ASCIIToUTF16(" "), 2U);
580 618
581 // Test when cursor is at the beginning of a word. 619 // Test when cursor is at the beginning of a word.
582 MoveCursorTo(model, 2); 620 MoveCursorTo(model, 2);
583 model.SelectWord(); 621 model.SelectWord();
584 SelectWordTestVerifier(model, base::ASCIIToUTF16("HELLO"), 7U); 622 SelectWordTestVerifier(model, base::ASCIIToUTF16("HELLO"), 7U);
585 623
586 // Test when cursor is at the end of a word. 624 // Test when cursor is at the end of a word.
587 MoveCursorTo(model, 15); 625 MoveCursorTo(model, 15);
588 model.SelectWord(); 626 model.SelectWord();
589 SelectWordTestVerifier(model, base::ASCIIToUTF16(" "), 20U); 627 SelectWordTestVerifier(model, base::ASCIIToUTF16(" "), 20U);
590 628
591 // Test when cursor is somewhere in a non-alpha-numeric fragment. 629 // Test when cursor is somewhere in a non-alpha-numeric fragment.
592 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { 630 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) {
593 MoveCursorTo(model, cursor_pos); 631 MoveCursorTo(model, cursor_pos);
594 model.SelectWord(); 632 model.SelectWord();
595 SelectWordTestVerifier(model, base::ASCIIToUTF16(" !! "), 13U); 633 SelectWordTestVerifier(model, base::ASCIIToUTF16(" !! "), 13U);
596 } 634 }
597 635
598 // Test when cursor is somewhere in a whitespace fragment. 636 // Test when cursor is somewhere in a whitespace fragment.
599 MoveCursorTo(model, 17); 637 MoveCursorTo(model, 17);
600 model.SelectWord(); 638 model.SelectWord();
601 SelectWordTestVerifier(model, base::ASCIIToUTF16(" "), 20U); 639 SelectWordTestVerifier(model, base::ASCIIToUTF16(" "), 20U);
602 640
603 // Test when cursor is at the end. 641 // Test when cursor is at the end.
604 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 642 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
605 model.SelectWord(); 643 model.SelectWord();
606 SelectWordTestVerifier(model, base::ASCIIToUTF16(" "), 24U); 644 SelectWordTestVerifier(model, base::ASCIIToUTF16(" "), 24U);
607 } 645 }
608 646
609 // TODO(xji): temporarily disable in platform Win since the complex script 647 // TODO(xji): temporarily disable in platform Win since the complex script
610 // characters and Chinese characters are turned into empty square due to font 648 // characters and Chinese characters are turned into empty square due to font
611 // regression. 649 // regression.
612 #if defined(OS_LINUX) 650 #if defined(OS_LINUX)
613 TEST_F(TextfieldModelTest, SelectWordTest_MixScripts) { 651 TEST_F(TextfieldModelTest, SelectWordTest_MixScripts) {
614 TextfieldModel model(NULL); 652 TextfieldModel model(NULL);
615 std::vector<WordAndCursor> word_and_cursor; 653 std::vector<WordAndCursor> word_and_cursor;
616 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2)); 654 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2));
617 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2)); 655 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2));
618 word_and_cursor.push_back(WordAndCursor(L"\x05d1\x05d2", 5)); 656 word_and_cursor.push_back(WordAndCursor(L"\x05d1\x05d2", 5));
619 word_and_cursor.push_back(WordAndCursor(L"\x05d1\x05d2", 5)); 657 word_and_cursor.push_back(WordAndCursor(L"\x05d1\x05d2", 5));
620 word_and_cursor.push_back(WordAndCursor(L" ", 3)); 658 word_and_cursor.push_back(WordAndCursor(L" ", 3));
621 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2)); 659 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2));
622 word_and_cursor.push_back(WordAndCursor(L"\x0915\x094d\x0915", 9)); 660 word_and_cursor.push_back(WordAndCursor(L"\x0915\x094d\x0915", 9));
623 word_and_cursor.push_back(WordAndCursor(L"\x0915\x094d\x0915", 9)); 661 word_and_cursor.push_back(WordAndCursor(L"\x0915\x094d\x0915", 9));
624 word_and_cursor.push_back(WordAndCursor(L" ", 10)); 662 word_and_cursor.push_back(WordAndCursor(L" ", 10));
625 word_and_cursor.push_back(WordAndCursor(L"\x4E2D\x56FD", 12)); 663 word_and_cursor.push_back(WordAndCursor(L"\x4E2D\x56FD", 12));
626 word_and_cursor.push_back(WordAndCursor(L"\x4E2D\x56FD", 12)); 664 word_and_cursor.push_back(WordAndCursor(L"\x4E2D\x56FD", 12));
627 word_and_cursor.push_back(WordAndCursor(L"\x82B1", 13)); 665 word_and_cursor.push_back(WordAndCursor(L"\x82B1", 13));
628 word_and_cursor.push_back(WordAndCursor(L"\x5929", 14)); 666 word_and_cursor.push_back(WordAndCursor(L"\x5929", 14));
629 667
630 // The text consists of Ascii, Hebrew, Hindi with Virama sign, and Chinese. 668 // The text consists of Ascii, Hebrew, Hindi with Virama sign, and Chinese.
631 model.SetText(base::WideToUTF16(L"a\x05d0 \x05d1\x05d2 \x0915\x094d\x0915 " 669 model.SetText(base::WideToUTF16(L"a\x05d0 \x05d1\x05d2 \x0915\x094d\x0915 "
632 L"\x4E2D\x56FD\x82B1\x5929")); 670 L"\x4E2D\x56FD\x82B1\x5929"));
633 for (size_t i = 0; i < word_and_cursor.size(); ++i) { 671 for (size_t i = 0; i < word_and_cursor.size(); ++i) {
634 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 672 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
635 for (size_t j = 0; j < i; ++j) 673 for (size_t j = 0; j < i; ++j)
636 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 674 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
675 gfx::SELECTION_NONE);
637 model.SelectWord(); 676 model.SelectWord();
638 SelectWordTestVerifier(model, base::WideToUTF16(word_and_cursor[i].word), 677 SelectWordTestVerifier(model, base::WideToUTF16(word_and_cursor[i].word),
639 word_and_cursor[i].cursor); 678 word_and_cursor[i].cursor);
640 } 679 }
641 } 680 }
642 #endif 681 #endif
643 682
644 TEST_F(TextfieldModelTest, RangeTest) { 683 TEST_F(TextfieldModelTest, RangeTest) {
645 TextfieldModel model(NULL); 684 TextfieldModel model(NULL);
646 model.Append(base::ASCIIToUTF16("HELLO WORLD")); 685 model.Append(base::ASCIIToUTF16("HELLO WORLD"));
647 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 686 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
648 gfx::Range range = model.render_text()->selection(); 687 gfx::Range range = model.render_text()->selection();
649 EXPECT_TRUE(range.is_empty()); 688 EXPECT_TRUE(range.is_empty());
650 EXPECT_EQ(0U, range.start()); 689 EXPECT_EQ(0U, range.start());
651 EXPECT_EQ(0U, range.end()); 690 EXPECT_EQ(0U, range.end());
652 691
653 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 692 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_RETAIN);
654 range = model.render_text()->selection(); 693 range = model.render_text()->selection();
655 EXPECT_FALSE(range.is_empty()); 694 EXPECT_FALSE(range.is_empty());
656 EXPECT_FALSE(range.is_reversed()); 695 EXPECT_FALSE(range.is_reversed());
657 EXPECT_EQ(0U, range.start()); 696 EXPECT_EQ(0U, range.start());
658 EXPECT_EQ(5U, range.end()); 697 EXPECT_EQ(5U, range.end());
659 698
660 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 699 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
700 gfx::SELECTION_RETAIN);
661 range = model.render_text()->selection(); 701 range = model.render_text()->selection();
662 EXPECT_FALSE(range.is_empty()); 702 EXPECT_FALSE(range.is_empty());
663 EXPECT_EQ(0U, range.start()); 703 EXPECT_EQ(0U, range.start());
664 EXPECT_EQ(4U, range.end()); 704 EXPECT_EQ(4U, range.end());
665 705
666 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 706 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
667 range = model.render_text()->selection(); 707 range = model.render_text()->selection();
668 EXPECT_TRUE(range.is_empty()); 708 EXPECT_TRUE(range.is_empty());
669 EXPECT_EQ(0U, range.start()); 709 EXPECT_EQ(0U, range.start());
670 EXPECT_EQ(0U, range.end()); 710 EXPECT_EQ(0U, range.end());
671 711
672 // now from the end. 712 // now from the end.
673 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 713 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
674 range = model.render_text()->selection(); 714 range = model.render_text()->selection();
675 EXPECT_TRUE(range.is_empty()); 715 EXPECT_TRUE(range.is_empty());
676 EXPECT_EQ(11U, range.start()); 716 EXPECT_EQ(11U, range.start());
677 EXPECT_EQ(11U, range.end()); 717 EXPECT_EQ(11U, range.end());
678 718
679 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 719 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
680 range = model.render_text()->selection(); 720 range = model.render_text()->selection();
681 EXPECT_FALSE(range.is_empty()); 721 EXPECT_FALSE(range.is_empty());
682 EXPECT_TRUE(range.is_reversed()); 722 EXPECT_TRUE(range.is_reversed());
683 EXPECT_EQ(11U, range.start()); 723 EXPECT_EQ(11U, range.start());
684 EXPECT_EQ(6U, range.end()); 724 EXPECT_EQ(6U, range.end());
685 725
686 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 726 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
727 gfx::SELECTION_RETAIN);
687 range = model.render_text()->selection(); 728 range = model.render_text()->selection();
688 EXPECT_FALSE(range.is_empty()); 729 EXPECT_FALSE(range.is_empty());
689 EXPECT_TRUE(range.is_reversed()); 730 EXPECT_TRUE(range.is_reversed());
690 EXPECT_EQ(11U, range.start()); 731 EXPECT_EQ(11U, range.start());
691 EXPECT_EQ(7U, range.end()); 732 EXPECT_EQ(7U, range.end());
692 733
693 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 734 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_RETAIN);
694 range = model.render_text()->selection(); 735 range = model.render_text()->selection();
695 EXPECT_TRUE(range.is_empty()); 736 EXPECT_TRUE(range.is_empty());
696 EXPECT_EQ(11U, range.start()); 737 EXPECT_EQ(11U, range.start());
697 EXPECT_EQ(11U, range.end()); 738 EXPECT_EQ(11U, range.end());
698 739
699 // Select All 740 // Select All
700 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); 741 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
701 range = model.render_text()->selection(); 742 range = model.render_text()->selection();
702 EXPECT_FALSE(range.is_empty()); 743 EXPECT_FALSE(range.is_empty());
703 EXPECT_TRUE(range.is_reversed()); 744 EXPECT_TRUE(range.is_reversed());
704 EXPECT_EQ(11U, range.start()); 745 EXPECT_EQ(11U, range.start());
705 EXPECT_EQ(0U, range.end()); 746 EXPECT_EQ(0U, range.end());
706 } 747 }
707 748
708 TEST_F(TextfieldModelTest, SelectRangeTest) { 749 TEST_F(TextfieldModelTest, SelectRangeTest) {
709 TextfieldModel model(NULL); 750 TextfieldModel model(NULL);
710 model.Append(base::ASCIIToUTF16("HELLO WORLD")); 751 model.Append(base::ASCIIToUTF16("HELLO WORLD"));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 786
746 range = gfx::Range(1000, 1000); 787 range = gfx::Range(1000, 1000);
747 EXPECT_TRUE(range.is_empty()); 788 EXPECT_TRUE(range.is_empty());
748 model.SelectRange(range); 789 model.SelectRange(range);
749 EXPECT_TRUE(model.GetSelectedText().empty()); 790 EXPECT_TRUE(model.GetSelectedText().empty());
750 } 791 }
751 792
752 TEST_F(TextfieldModelTest, SelectionTest) { 793 TEST_F(TextfieldModelTest, SelectionTest) {
753 TextfieldModel model(NULL); 794 TextfieldModel model(NULL);
754 model.Append(base::ASCIIToUTF16("HELLO WORLD")); 795 model.Append(base::ASCIIToUTF16("HELLO WORLD"));
755 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 796 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
756 gfx::Range selection = model.render_text()->selection(); 797 gfx::Range selection = model.render_text()->selection();
757 EXPECT_EQ(gfx::Range(0), selection); 798 EXPECT_EQ(gfx::Range(0), selection);
758 799
759 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 800 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_RETAIN);
760 selection = model.render_text()->selection(); 801 selection = model.render_text()->selection();
761 EXPECT_EQ(gfx::Range(0, 5), selection); 802 EXPECT_EQ(gfx::Range(0, 5), selection);
762 803
763 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 804 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
805 gfx::SELECTION_RETAIN);
764 selection = model.render_text()->selection(); 806 selection = model.render_text()->selection();
765 EXPECT_EQ(gfx::Range(0, 4), selection); 807 EXPECT_EQ(gfx::Range(0, 4), selection);
766 808
767 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 809 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
768 selection = model.render_text()->selection(); 810 selection = model.render_text()->selection();
769 EXPECT_EQ(gfx::Range(0), selection); 811 EXPECT_EQ(gfx::Range(0), selection);
770 812
771 // now from the end. 813 // now from the end.
772 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 814 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
773 selection = model.render_text()->selection(); 815 selection = model.render_text()->selection();
774 EXPECT_EQ(gfx::Range(11), selection); 816 EXPECT_EQ(gfx::Range(11), selection);
775 817
776 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 818 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
777 selection = model.render_text()->selection(); 819 selection = model.render_text()->selection();
778 EXPECT_EQ(gfx::Range(11, 6), selection); 820 EXPECT_EQ(gfx::Range(11, 6), selection);
779 821
780 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 822 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
823 gfx::SELECTION_RETAIN);
781 selection = model.render_text()->selection(); 824 selection = model.render_text()->selection();
782 EXPECT_EQ(gfx::Range(11, 7), selection); 825 EXPECT_EQ(gfx::Range(11, 7), selection);
783 826
784 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 827 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_RETAIN);
785 selection = model.render_text()->selection(); 828 selection = model.render_text()->selection();
786 EXPECT_EQ(gfx::Range(11), selection); 829 EXPECT_EQ(gfx::Range(11), selection);
787 830
788 // Select All 831 // Select All
789 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); 832 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
790 selection = model.render_text()->selection(); 833 selection = model.render_text()->selection();
791 EXPECT_EQ(gfx::Range(11, 0), selection); 834 EXPECT_EQ(gfx::Range(11, 0), selection);
792 } 835 }
793 836
794 TEST_F(TextfieldModelTest, SelectSelectionModelTest) { 837 TEST_F(TextfieldModelTest, SelectSelectionModelTest) {
795 TextfieldModel model(NULL); 838 TextfieldModel model(NULL);
796 model.Append(base::ASCIIToUTF16("HELLO WORLD")); 839 model.Append(base::ASCIIToUTF16("HELLO WORLD"));
797 model.SelectSelectionModel(gfx::SelectionModel(gfx::Range(0, 6), 840 model.SelectSelectionModel(gfx::SelectionModel(gfx::Range(0, 6),
798 gfx::CURSOR_BACKWARD)); 841 gfx::CURSOR_BACKWARD));
799 EXPECT_STR_EQ("HELLO ", model.GetSelectedText()); 842 EXPECT_STR_EQ("HELLO ", model.GetSelectedText());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 composition_text_confirmed_or_cleared_ = false; 918 composition_text_confirmed_or_cleared_ = false;
876 EXPECT_FALSE(model.HasCompositionText()); 919 EXPECT_FALSE(model.HasCompositionText());
877 EXPECT_FALSE(model.HasSelection()); 920 EXPECT_FALSE(model.HasSelection());
878 EXPECT_EQ(5U, model.GetCursorPosition()); 921 EXPECT_EQ(5U, model.GetCursorPosition());
879 922
880 model.SetCompositionText(composition); 923 model.SetCompositionText(composition);
881 EXPECT_STR_EQ("1234567890", model.text()); 924 EXPECT_STR_EQ("1234567890", model.text());
882 EXPECT_TRUE(model.SetText(base::ASCIIToUTF16("1234567890"))); 925 EXPECT_TRUE(model.SetText(base::ASCIIToUTF16("1234567890")));
883 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 926 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
884 composition_text_confirmed_or_cleared_ = false; 927 composition_text_confirmed_or_cleared_ = false;
885 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 928 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
886 929
887 model.SetCompositionText(composition); 930 model.SetCompositionText(composition);
888 EXPECT_STR_EQ("1234567890678", model.text()); 931 EXPECT_STR_EQ("1234567890678", model.text());
889 932
890 model.InsertText(base::UTF8ToUTF16("-")); 933 model.InsertText(base::UTF8ToUTF16("-"));
891 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 934 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
892 composition_text_confirmed_or_cleared_ = false; 935 composition_text_confirmed_or_cleared_ = false;
893 EXPECT_STR_EQ("1234567890-", model.text()); 936 EXPECT_STR_EQ("1234567890-", model.text());
894 EXPECT_FALSE(model.HasCompositionText()); 937 EXPECT_FALSE(model.HasCompositionText());
895 EXPECT_FALSE(model.HasSelection()); 938 EXPECT_FALSE(model.HasSelection());
896 939
897 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 940 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT,
941 gfx::SELECTION_RETAIN);
898 EXPECT_STR_EQ("-", model.GetSelectedText()); 942 EXPECT_STR_EQ("-", model.GetSelectedText());
899 model.SetCompositionText(composition); 943 model.SetCompositionText(composition);
900 EXPECT_STR_EQ("1234567890678", model.text()); 944 EXPECT_STR_EQ("1234567890678", model.text());
901 945
902 model.ReplaceText(base::UTF8ToUTF16("-")); 946 model.ReplaceText(base::UTF8ToUTF16("-"));
903 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 947 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
904 composition_text_confirmed_or_cleared_ = false; 948 composition_text_confirmed_or_cleared_ = false;
905 EXPECT_STR_EQ("1234567890-", model.text()); 949 EXPECT_STR_EQ("1234567890-", model.text());
906 EXPECT_FALSE(model.HasCompositionText()); 950 EXPECT_FALSE(model.HasCompositionText());
907 EXPECT_FALSE(model.HasSelection()); 951 EXPECT_FALSE(model.HasSelection());
(...skipping 11 matching lines...) Expand all
919 EXPECT_STR_EQ("1234567890-678-", model.text()); 963 EXPECT_STR_EQ("1234567890-678-", model.text());
920 964
921 model.SetCompositionText(composition); 965 model.SetCompositionText(composition);
922 model.Backspace(); 966 model.Backspace();
923 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 967 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
924 composition_text_confirmed_or_cleared_ = false; 968 composition_text_confirmed_or_cleared_ = false;
925 EXPECT_STR_EQ("1234567890-678-", model.text()); 969 EXPECT_STR_EQ("1234567890-678-", model.text());
926 970
927 model.SetText(base::string16()); 971 model.SetText(base::string16());
928 model.SetCompositionText(composition); 972 model.SetCompositionText(composition);
929 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); 973 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
930 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 974 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
931 composition_text_confirmed_or_cleared_ = false; 975 composition_text_confirmed_or_cleared_ = false;
932 EXPECT_STR_EQ("678", model.text()); 976 EXPECT_STR_EQ("678", model.text());
933 EXPECT_EQ(2U, model.GetCursorPosition()); 977 EXPECT_EQ(2U, model.GetCursorPosition());
934 978
935 model.SetCompositionText(composition); 979 model.SetCompositionText(composition);
936 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 980 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
981 gfx::SELECTION_NONE);
937 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 982 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
938 composition_text_confirmed_or_cleared_ = false; 983 composition_text_confirmed_or_cleared_ = false;
939 EXPECT_STR_EQ("676788", model.text()); 984 EXPECT_STR_EQ("676788", model.text());
940 EXPECT_EQ(6U, model.GetCursorPosition()); 985 EXPECT_EQ(6U, model.GetCursorPosition());
941 986
942 model.SetCompositionText(composition); 987 model.SetCompositionText(composition);
943 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false); 988 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
944 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 989 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
945 composition_text_confirmed_or_cleared_ = false; 990 composition_text_confirmed_or_cleared_ = false;
946 EXPECT_STR_EQ("676788678", model.text()); 991 EXPECT_STR_EQ("676788678", model.text());
947 992
948 model.SetText(base::string16()); 993 model.SetText(base::string16());
949 model.SetCompositionText(composition); 994 model.SetCompositionText(composition);
950 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); 995 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
951 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 996 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
952 composition_text_confirmed_or_cleared_ = false; 997 composition_text_confirmed_or_cleared_ = false;
953 998
954 model.SetCompositionText(composition); 999 model.SetCompositionText(composition);
955 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); 1000 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_RETAIN);
956 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 1001 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
957 composition_text_confirmed_or_cleared_ = false; 1002 composition_text_confirmed_or_cleared_ = false;
958 EXPECT_STR_EQ("678678", model.text()); 1003 EXPECT_STR_EQ("678678", model.text());
959 1004
960 model.SetCompositionText(composition); 1005 model.SetCompositionText(composition);
961 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1006 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
962 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 1007 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
963 composition_text_confirmed_or_cleared_ = false; 1008 composition_text_confirmed_or_cleared_ = false;
964 EXPECT_STR_EQ("678", model.text()); 1009 EXPECT_STR_EQ("678", model.text());
965 1010
966 model.SetCompositionText(composition); 1011 model.SetCompositionText(composition);
967 gfx::SelectionModel sel( 1012 gfx::SelectionModel sel(
968 gfx::Range(model.render_text()->selection().start(), 0), 1013 gfx::Range(model.render_text()->selection().start(), 0),
969 gfx::CURSOR_FORWARD); 1014 gfx::CURSOR_FORWARD);
970 model.MoveCursorTo(sel); 1015 model.MoveCursorTo(sel);
971 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 1016 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 EXPECT_FALSE(model.Redo()); 1111 EXPECT_FALSE(model.Redo());
1067 EXPECT_STR_EQ("a", model.text()); 1112 EXPECT_STR_EQ("a", model.text());
1068 EXPECT_EQ(1U, model.GetCursorPosition()); 1113 EXPECT_EQ(1U, model.GetCursorPosition());
1069 1114
1070 // Delete =============================== 1115 // Delete ===============================
1071 model.SetText(base::ASCIIToUTF16("ABCDE")); 1116 model.SetText(base::ASCIIToUTF16("ABCDE"));
1072 model.ClearEditHistory(); 1117 model.ClearEditHistory();
1073 MoveCursorTo(model, 2); 1118 MoveCursorTo(model, 2);
1074 EXPECT_TRUE(model.Delete()); 1119 EXPECT_TRUE(model.Delete());
1075 EXPECT_STR_EQ("ABDE", model.text()); 1120 EXPECT_STR_EQ("ABDE", model.text());
1076 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 1121 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
1077 EXPECT_TRUE(model.Delete()); 1122 EXPECT_TRUE(model.Delete());
1078 EXPECT_STR_EQ("BDE", model.text()); 1123 EXPECT_STR_EQ("BDE", model.text());
1079 EXPECT_TRUE(model.Undo()); 1124 EXPECT_TRUE(model.Undo());
1080 EXPECT_STR_EQ("ABDE", model.text()); 1125 EXPECT_STR_EQ("ABDE", model.text());
1081 EXPECT_EQ(0U, model.GetCursorPosition()); 1126 EXPECT_EQ(0U, model.GetCursorPosition());
1082 EXPECT_TRUE(model.Undo()); 1127 EXPECT_TRUE(model.Undo());
1083 EXPECT_STR_EQ("ABCDE", model.text()); 1128 EXPECT_STR_EQ("ABCDE", model.text());
1084 EXPECT_EQ(2U, model.GetCursorPosition()); 1129 EXPECT_EQ(2U, model.GetCursorPosition());
1085 EXPECT_TRUE(model.Redo()); 1130 EXPECT_TRUE(model.Redo());
1086 EXPECT_STR_EQ("ABDE", model.text()); 1131 EXPECT_STR_EQ("ABDE", model.text());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1162 TEST_F(TextfieldModelTest, UndoRedo_BackspaceThenSetText) { 1207 TEST_F(TextfieldModelTest, UndoRedo_BackspaceThenSetText) {
1163 // This is to test the undo/redo behavior of omnibox. 1208 // This is to test the undo/redo behavior of omnibox.
1164 TextfieldModel model(NULL); 1209 TextfieldModel model(NULL);
1165 model.InsertChar('w'); 1210 model.InsertChar('w');
1166 EXPECT_STR_EQ("w", model.text()); 1211 EXPECT_STR_EQ("w", model.text());
1167 EXPECT_EQ(1U, model.GetCursorPosition()); 1212 EXPECT_EQ(1U, model.GetCursorPosition());
1168 model.SetText(base::ASCIIToUTF16("www.google.com")); 1213 model.SetText(base::ASCIIToUTF16("www.google.com"));
1169 EXPECT_EQ(14U, model.GetCursorPosition()); 1214 EXPECT_EQ(14U, model.GetCursorPosition());
1170 EXPECT_STR_EQ("www.google.com", model.text()); 1215 EXPECT_STR_EQ("www.google.com", model.text());
1171 model.SetText(base::ASCIIToUTF16("www.google.com")); // Confirm the text. 1216 model.SetText(base::ASCIIToUTF16("www.google.com")); // Confirm the text.
1172 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1217 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
1173 EXPECT_EQ(14U, model.GetCursorPosition()); 1218 EXPECT_EQ(14U, model.GetCursorPosition());
1174 EXPECT_TRUE(model.Backspace()); 1219 EXPECT_TRUE(model.Backspace());
1175 EXPECT_TRUE(model.Backspace()); 1220 EXPECT_TRUE(model.Backspace());
1176 EXPECT_STR_EQ("www.google.c", model.text()); 1221 EXPECT_STR_EQ("www.google.c", model.text());
1177 // Autocomplete sets the text. 1222 // Autocomplete sets the text.
1178 model.SetText(base::ASCIIToUTF16("www.google.com/search=www.google.c")); 1223 model.SetText(base::ASCIIToUTF16("www.google.com/search=www.google.c"));
1179 EXPECT_STR_EQ("www.google.com/search=www.google.c", model.text()); 1224 EXPECT_STR_EQ("www.google.com/search=www.google.c", model.text());
1180 EXPECT_TRUE(model.Undo()); 1225 EXPECT_TRUE(model.Undo());
1181 EXPECT_STR_EQ("www.google.c", model.text()); 1226 EXPECT_STR_EQ("www.google.c", model.text());
1182 EXPECT_TRUE(model.Undo()); 1227 EXPECT_TRUE(model.Undo());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 EXPECT_EQ(7U, model.GetCursorPosition()); 1295 EXPECT_EQ(7U, model.GetCursorPosition());
1251 EXPECT_FALSE(model.Redo()); 1296 EXPECT_FALSE(model.Redo());
1252 1297
1253 // Test using SelectRange. 1298 // Test using SelectRange.
1254 model.SelectRange(gfx::Range(1, 3)); 1299 model.SelectRange(gfx::Range(1, 3));
1255 EXPECT_TRUE(model.Cut()); 1300 EXPECT_TRUE(model.Cut());
1256 EXPECT_STR_EQ("ABCBCDE", model.text()); 1301 EXPECT_STR_EQ("ABCBCDE", model.text());
1257 EXPECT_EQ(1U, model.GetCursorPosition()); 1302 EXPECT_EQ(1U, model.GetCursorPosition());
1258 model.SelectRange(gfx::Range(1, 1)); 1303 model.SelectRange(gfx::Range(1, 1));
1259 EXPECT_FALSE(model.Cut()); 1304 EXPECT_FALSE(model.Cut());
1260 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1305 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
1261 EXPECT_TRUE(model.Paste()); 1306 EXPECT_TRUE(model.Paste());
1262 EXPECT_STR_EQ("ABCBCDEBC", model.text()); 1307 EXPECT_STR_EQ("ABCBCDEBC", model.text());
1263 EXPECT_EQ(9U, model.GetCursorPosition()); 1308 EXPECT_EQ(9U, model.GetCursorPosition());
1264 EXPECT_TRUE(model.Undo()); 1309 EXPECT_TRUE(model.Undo());
1265 EXPECT_STR_EQ("ABCBCDE", model.text()); 1310 EXPECT_STR_EQ("ABCBCDE", model.text());
1266 EXPECT_EQ(7U, model.GetCursorPosition()); 1311 EXPECT_EQ(7U, model.GetCursorPosition());
1267 // An empty cut shouldn't create an edit. 1312 // An empty cut shouldn't create an edit.
1268 EXPECT_TRUE(model.Undo()); 1313 EXPECT_TRUE(model.Undo());
1269 EXPECT_STR_EQ("ABCBCBCDE", model.text()); 1314 EXPECT_STR_EQ("ABCBCBCDE", model.text());
1270 EXPECT_EQ(3U, model.GetCursorPosition()); 1315 EXPECT_EQ(3U, model.GetCursorPosition());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 EXPECT_TRUE(model.Redo()); 1349 EXPECT_TRUE(model.Redo());
1305 EXPECT_STR_EQ("1232345", model.text()); 1350 EXPECT_STR_EQ("1232345", model.text());
1306 EXPECT_EQ(5U, model.GetCursorPosition()); 1351 EXPECT_EQ(5U, model.GetCursorPosition());
1307 EXPECT_FALSE(model.Redo()); 1352 EXPECT_FALSE(model.Redo());
1308 EXPECT_STR_EQ("1232345", model.text()); 1353 EXPECT_STR_EQ("1232345", model.text());
1309 1354
1310 // Test using SelectRange. 1355 // Test using SelectRange.
1311 model.SelectRange(gfx::Range(1, 3)); 1356 model.SelectRange(gfx::Range(1, 3));
1312 model.Copy(); 1357 model.Copy();
1313 EXPECT_STR_EQ("1232345", model.text()); 1358 EXPECT_STR_EQ("1232345", model.text());
1314 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1359 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
1315 EXPECT_TRUE(model.Paste()); 1360 EXPECT_TRUE(model.Paste());
1316 EXPECT_STR_EQ("123234523", model.text()); 1361 EXPECT_STR_EQ("123234523", model.text());
1317 EXPECT_EQ(9U, model.GetCursorPosition()); 1362 EXPECT_EQ(9U, model.GetCursorPosition());
1318 EXPECT_TRUE(model.Undo()); 1363 EXPECT_TRUE(model.Undo());
1319 EXPECT_STR_EQ("1232345", model.text()); 1364 EXPECT_STR_EQ("1232345", model.text());
1320 EXPECT_EQ(7U, model.GetCursorPosition()); 1365 EXPECT_EQ(7U, model.GetCursorPosition());
1321 } 1366 }
1322 1367
1323 TEST_F(TextfieldModelTest, UndoRedo_CursorTest) { 1368 TEST_F(TextfieldModelTest, UndoRedo_CursorTest) {
1324 TextfieldModel model(NULL); 1369 TextfieldModel model(NULL);
1325 model.InsertChar('a'); 1370 model.InsertChar('a');
1326 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); 1371 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
1327 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 1372 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT,
1373 gfx::SELECTION_NONE);
1328 model.InsertChar('b'); 1374 model.InsertChar('b');
1329 // Moving the cursor shouldn't create a new edit. 1375 // Moving the cursor shouldn't create a new edit.
1330 EXPECT_STR_EQ("ab", model.text()); 1376 EXPECT_STR_EQ("ab", model.text());
1331 EXPECT_FALSE(model.Redo()); 1377 EXPECT_FALSE(model.Redo());
1332 EXPECT_TRUE(model.Undo()); 1378 EXPECT_TRUE(model.Undo());
1333 EXPECT_STR_EQ("", model.text()); 1379 EXPECT_STR_EQ("", model.text());
1334 EXPECT_FALSE(model.Undo()); 1380 EXPECT_FALSE(model.Undo());
1335 EXPECT_STR_EQ("", model.text()); 1381 EXPECT_STR_EQ("", model.text());
1336 EXPECT_TRUE(model.Redo()); 1382 EXPECT_TRUE(model.Redo());
1337 EXPECT_STR_EQ("ab", model.text()); 1383 EXPECT_STR_EQ("ab", model.text());
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 1465
1420 TEST_F(TextfieldModelTest, UndoRedo_CompositionText) { 1466 TEST_F(TextfieldModelTest, UndoRedo_CompositionText) {
1421 TextfieldModel model(NULL); 1467 TextfieldModel model(NULL);
1422 1468
1423 ui::CompositionText composition; 1469 ui::CompositionText composition;
1424 composition.text = base::ASCIIToUTF16("abc"); 1470 composition.text = base::ASCIIToUTF16("abc");
1425 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false)); 1471 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false));
1426 composition.selection = gfx::Range(2, 3); 1472 composition.selection = gfx::Range(2, 3);
1427 1473
1428 model.SetText(base::ASCIIToUTF16("ABCDE")); 1474 model.SetText(base::ASCIIToUTF16("ABCDE"));
1429 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1475 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
1430 model.InsertChar('x'); 1476 model.InsertChar('x');
1431 EXPECT_STR_EQ("ABCDEx", model.text()); 1477 EXPECT_STR_EQ("ABCDEx", model.text());
1432 EXPECT_TRUE(model.Undo()); // set composition should forget undone edit. 1478 EXPECT_TRUE(model.Undo()); // set composition should forget undone edit.
1433 model.SetCompositionText(composition); 1479 model.SetCompositionText(composition);
1434 EXPECT_TRUE(model.HasCompositionText()); 1480 EXPECT_TRUE(model.HasCompositionText());
1435 EXPECT_TRUE(model.HasSelection()); 1481 EXPECT_TRUE(model.HasSelection());
1436 EXPECT_STR_EQ("ABCDEabc", model.text()); 1482 EXPECT_STR_EQ("ABCDEabc", model.text());
1437 1483
1438 // Confirm the composition. 1484 // Confirm the composition.
1439 model.ConfirmCompositionText(); 1485 model.ConfirmCompositionText();
1440 EXPECT_STR_EQ("ABCDEabc", model.text()); 1486 EXPECT_STR_EQ("ABCDEabc", model.text());
1441 EXPECT_TRUE(model.Undo()); 1487 EXPECT_TRUE(model.Undo());
1442 EXPECT_STR_EQ("ABCDE", model.text()); 1488 EXPECT_STR_EQ("ABCDE", model.text());
1443 EXPECT_TRUE(model.Undo()); 1489 EXPECT_TRUE(model.Undo());
1444 EXPECT_STR_EQ("", model.text()); 1490 EXPECT_STR_EQ("", model.text());
1445 EXPECT_TRUE(model.Redo()); 1491 EXPECT_TRUE(model.Redo());
1446 EXPECT_STR_EQ("ABCDE", model.text()); 1492 EXPECT_STR_EQ("ABCDE", model.text());
1447 EXPECT_TRUE(model.Redo()); 1493 EXPECT_TRUE(model.Redo());
1448 EXPECT_STR_EQ("ABCDEabc", model.text()); 1494 EXPECT_STR_EQ("ABCDEabc", model.text());
1449 EXPECT_FALSE(model.Redo()); 1495 EXPECT_FALSE(model.Redo());
1450 1496
1451 // Cancel the composition. 1497 // Cancel the composition.
1452 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 1498 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, gfx::SELECTION_NONE);
1453 model.SetCompositionText(composition); 1499 model.SetCompositionText(composition);
1454 EXPECT_STR_EQ("abcABCDEabc", model.text()); 1500 EXPECT_STR_EQ("abcABCDEabc", model.text());
1455 model.CancelCompositionText(); 1501 model.CancelCompositionText();
1456 EXPECT_STR_EQ("ABCDEabc", model.text()); 1502 EXPECT_STR_EQ("ABCDEabc", model.text());
1457 EXPECT_FALSE(model.Redo()); 1503 EXPECT_FALSE(model.Redo());
1458 EXPECT_STR_EQ("ABCDEabc", model.text()); 1504 EXPECT_STR_EQ("ABCDEabc", model.text());
1459 EXPECT_TRUE(model.Undo()); 1505 EXPECT_TRUE(model.Undo());
1460 EXPECT_STR_EQ("ABCDE", model.text()); 1506 EXPECT_STR_EQ("ABCDE", model.text());
1461 EXPECT_TRUE(model.Redo()); 1507 EXPECT_TRUE(model.Redo());
1462 EXPECT_STR_EQ("ABCDEabc", model.text()); 1508 EXPECT_STR_EQ("ABCDEabc", model.text());
1463 EXPECT_FALSE(model.Redo()); 1509 EXPECT_FALSE(model.Redo());
1464 1510
1465 // Call SetText with the same text as the result. 1511 // Call SetText with the same text as the result.
1466 ResetModel(&model); 1512 ResetModel(&model);
1467 model.SetText(base::ASCIIToUTF16("ABCDE")); 1513 model.SetText(base::ASCIIToUTF16("ABCDE"));
1468 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1514 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
1469 model.SetCompositionText(composition); 1515 model.SetCompositionText(composition);
1470 EXPECT_STR_EQ("ABCDEabc", model.text()); 1516 EXPECT_STR_EQ("ABCDEabc", model.text());
1471 model.SetText(base::ASCIIToUTF16("ABCDEabc")); 1517 model.SetText(base::ASCIIToUTF16("ABCDEabc"));
1472 EXPECT_STR_EQ("ABCDEabc", model.text()); 1518 EXPECT_STR_EQ("ABCDEabc", model.text());
1473 EXPECT_TRUE(model.Undo()); 1519 EXPECT_TRUE(model.Undo());
1474 EXPECT_STR_EQ("ABCDE", model.text()); 1520 EXPECT_STR_EQ("ABCDE", model.text());
1475 EXPECT_TRUE(model.Redo()); 1521 EXPECT_TRUE(model.Redo());
1476 EXPECT_STR_EQ("ABCDEabc", model.text()); 1522 EXPECT_STR_EQ("ABCDEabc", model.text());
1477 EXPECT_FALSE(model.Redo()); 1523 EXPECT_FALSE(model.Redo());
1478 1524
1479 // Call SetText with a different result; the composition should be forgotten. 1525 // Call SetText with a different result; the composition should be forgotten.
1480 ResetModel(&model); 1526 ResetModel(&model);
1481 model.SetText(base::ASCIIToUTF16("ABCDE")); 1527 model.SetText(base::ASCIIToUTF16("ABCDE"));
1482 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1528 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
1483 model.SetCompositionText(composition); 1529 model.SetCompositionText(composition);
1484 EXPECT_STR_EQ("ABCDEabc", model.text()); 1530 EXPECT_STR_EQ("ABCDEabc", model.text());
1485 model.SetText(base::ASCIIToUTF16("1234")); 1531 model.SetText(base::ASCIIToUTF16("1234"));
1486 EXPECT_STR_EQ("1234", model.text()); 1532 EXPECT_STR_EQ("1234", model.text());
1487 EXPECT_TRUE(model.Undo()); 1533 EXPECT_TRUE(model.Undo());
1488 EXPECT_STR_EQ("ABCDE", model.text()); 1534 EXPECT_STR_EQ("ABCDE", model.text());
1489 EXPECT_TRUE(model.Redo()); 1535 EXPECT_TRUE(model.Redo());
1490 EXPECT_STR_EQ("1234", model.text()); 1536 EXPECT_STR_EQ("1234", model.text());
1491 EXPECT_FALSE(model.Redo()); 1537 EXPECT_FALSE(model.Redo());
1492 1538
1493 // TODO(oshima): Test the behavior with an IME. 1539 // TODO(oshima): Test the behavior with an IME.
1494 } 1540 }
1495 1541
1496 // Tests that clipboard text with leading, trailing and interspersed tabs 1542 // Tests that clipboard text with leading, trailing and interspersed tabs
1497 // spaces etc is pasted correctly. Leading and trailing tabs should be 1543 // spaces etc is pasted correctly. Leading and trailing tabs should be
1498 // stripped. Text separated by multiple tabs/spaces should be collapsed into 1544 // stripped. Text separated by multiple tabs/spaces should be collapsed into
1499 // one space. Text with just tabs and spaces should be pasted as one space. 1545 // one space. Text with just tabs and spaces should be pasted as one space.
1500 TEST_F(TextfieldModelTest, Clipboard_WhiteSpaceStringTest) { 1546 TEST_F(TextfieldModelTest, Clipboard_WhiteSpaceStringTest) {
1501 // Test 1 1547 // Test 1
1502 // Clipboard text with a leading tab should be pasted with the tab stripped. 1548 // Clipboard text with a leading tab should be pasted with the tab stripped.
1503 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_COPY_PASTE) 1549 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_COPY_PASTE)
1504 .WriteText(base::ASCIIToUTF16("\tB")); 1550 .WriteText(base::ASCIIToUTF16("\tB"));
1505 1551
1506 TextfieldModel model(NULL); 1552 TextfieldModel model(NULL);
1507 model.Append(base::ASCIIToUTF16("HELLO WORLD")); 1553 model.Append(base::ASCIIToUTF16("HELLO WORLD"));
1508 EXPECT_STR_EQ("HELLO WORLD", model.text()); 1554 EXPECT_STR_EQ("HELLO WORLD", model.text());
1509 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1555 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
1510 EXPECT_EQ(11U, model.GetCursorPosition()); 1556 EXPECT_EQ(11U, model.GetCursorPosition());
1511 1557
1512 EXPECT_TRUE(model.Paste()); 1558 EXPECT_TRUE(model.Paste());
1513 EXPECT_STR_EQ("HELLO WORLDB", model.text()); 1559 EXPECT_STR_EQ("HELLO WORLDB", model.text());
1514 1560
1515 model.SelectAll(false); 1561 model.SelectAll(false);
1516 model.DeleteSelection(); 1562 model.DeleteSelection();
1517 EXPECT_STR_EQ("", model.text()); 1563 EXPECT_STR_EQ("", model.text());
1518 1564
1519 // Test 2 1565 // Test 2
1520 // Clipboard text with multiple leading tabs and spaces should be pasted with 1566 // Clipboard text with multiple leading tabs and spaces should be pasted with
1521 // all tabs and spaces stripped. 1567 // all tabs and spaces stripped.
1522 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_COPY_PASTE) 1568 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_COPY_PASTE)
1523 .WriteText(base::ASCIIToUTF16("\t\t\t B")); 1569 .WriteText(base::ASCIIToUTF16("\t\t\t B"));
1524 1570
1525 model.Append(base::ASCIIToUTF16("HELLO WORLD")); 1571 model.Append(base::ASCIIToUTF16("HELLO WORLD"));
1526 EXPECT_STR_EQ("HELLO WORLD", model.text()); 1572 EXPECT_STR_EQ("HELLO WORLD", model.text());
1527 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1573 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
1528 EXPECT_EQ(11U, model.GetCursorPosition()); 1574 EXPECT_EQ(11U, model.GetCursorPosition());
1529 EXPECT_TRUE(model.Paste()); 1575 EXPECT_TRUE(model.Paste());
1530 EXPECT_STR_EQ("HELLO WORLDB", model.text()); 1576 EXPECT_STR_EQ("HELLO WORLDB", model.text());
1531 1577
1532 model.SelectAll(false); 1578 model.SelectAll(false);
1533 model.DeleteSelection(); 1579 model.DeleteSelection();
1534 EXPECT_STR_EQ("", model.text()); 1580 EXPECT_STR_EQ("", model.text());
1535 1581
1536 // Test 3 1582 // Test 3
1537 // Clipboard text with multiple tabs separating the words should be pasted 1583 // Clipboard text with multiple tabs separating the words should be pasted
1538 // with one space replacing all tabs. 1584 // with one space replacing all tabs.
1539 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_COPY_PASTE) 1585 ui::ScopedClipboardWriter(ui::CLIPBOARD_TYPE_COPY_PASTE)
1540 .WriteText(base::ASCIIToUTF16("FOO \t\t BAR")); 1586 .WriteText(base::ASCIIToUTF16("FOO \t\t BAR"));
1541 1587
1542 model.Append(base::ASCIIToUTF16("HELLO WORLD")); 1588 model.Append(base::ASCIIToUTF16("HELLO WORLD"));
1543 EXPECT_STR_EQ("HELLO WORLD", model.text()); 1589 EXPECT_STR_EQ("HELLO WORLD", model.text());
1544 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1590 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE);
1545 EXPECT_EQ(11U, model.GetCursorPosition()); 1591 EXPECT_EQ(11U, model.GetCursorPosition());
1546 EXPECT_TRUE(model.Paste()); 1592 EXPECT_TRUE(model.Paste());
1547 EXPECT_STR_EQ("HELLO WORLDFOO BAR", model.text()); 1593 EXPECT_STR_EQ("HELLO WORLDFOO BAR", model.text());
1548 1594
1549 model.SelectAll(false); 1595 model.SelectAll(false);
1550 model.DeleteSelection(); 1596 model.DeleteSelection();
1551 EXPECT_STR_EQ("", model.text()); 1597 EXPECT_STR_EQ("", model.text());
1552 1598
1553 // Test 4 1599 // Test 4
1554 // Clipboard text with multiple leading tabs and multiple tabs separating 1600 // Clipboard text with multiple leading tabs and multiple tabs separating
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 model.Backspace(true); 1749 model.Backspace(true);
1704 model.Backspace(true); 1750 model.Backspace(true);
1705 EXPECT_STR_EQ("aa", model.text()); 1751 EXPECT_STR_EQ("aa", model.text());
1706 1752
1707 // Ensure yanking inserts the modified kill buffer text. 1753 // Ensure yanking inserts the modified kill buffer text.
1708 model.Yank(); 1754 model.Yank();
1709 EXPECT_STR_EQ("aad", model.text()); 1755 EXPECT_STR_EQ("aad", model.text());
1710 } 1756 }
1711 1757
1712 } // namespace views 1758 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698