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

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

Issue 24012002: Move Range code to gfx. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: d Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/base/clipboard/clipboard.h" 13 #include "ui/base/clipboard/clipboard.h"
14 #include "ui/base/clipboard/scoped_clipboard_writer.h" 14 #include "ui/base/clipboard/scoped_clipboard_writer.h"
15 #include "ui/base/range/range.h" 15 #include "ui/gfx/range/range.h"
16 #include "ui/gfx/render_text.h" 16 #include "ui/gfx/render_text.h"
17 #include "ui/views/controls/textfield/textfield.h" 17 #include "ui/views/controls/textfield/textfield.h"
18 #include "ui/views/controls/textfield/textfield_views_model.h" 18 #include "ui/views/controls/textfield/textfield_views_model.h"
19 #include "ui/views/test/test_views_delegate.h" 19 #include "ui/views/test/test_views_delegate.h"
20 #include "ui/views/test/views_test_base.h" 20 #include "ui/views/test/views_test_base.h"
21 21
22 #if defined(OS_WIN) 22 #if defined(OS_WIN)
23 #include "base/win/windows_version.h" 23 #include "base/win/windows_version.h"
24 #endif 24 #endif
25 25
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); 269 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true);
270 EXPECT_STR_EQ("H", model.GetSelectedText()); 270 EXPECT_STR_EQ("H", model.GetSelectedText());
271 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, true); 271 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, true);
272 EXPECT_STR_EQ("ELLO", model.GetSelectedText()); 272 EXPECT_STR_EQ("ELLO", model.GetSelectedText());
273 model.ClearSelection(); 273 model.ClearSelection();
274 EXPECT_EQ(string16(), model.GetSelectedText()); 274 EXPECT_EQ(string16(), model.GetSelectedText());
275 275
276 // SelectAll(false) selects towards the end. 276 // SelectAll(false) selects towards the end.
277 model.SelectAll(false); 277 model.SelectAll(false);
278 EXPECT_STR_EQ("HELLO", model.GetSelectedText()); 278 EXPECT_STR_EQ("HELLO", model.GetSelectedText());
279 EXPECT_EQ(ui::Range(0, 5), model.render_text()->selection()); 279 EXPECT_EQ(gfx::Range(0, 5), model.render_text()->selection());
280 280
281 // SelectAll(true) selects towards the beginning. 281 // SelectAll(true) selects towards the beginning.
282 model.SelectAll(true); 282 model.SelectAll(true);
283 EXPECT_STR_EQ("HELLO", model.GetSelectedText()); 283 EXPECT_STR_EQ("HELLO", model.GetSelectedText());
284 EXPECT_EQ(ui::Range(5, 0), model.render_text()->selection()); 284 EXPECT_EQ(gfx::Range(5, 0), model.render_text()->selection());
285 285
286 // Select and move cursor. 286 // Select and move cursor.
287 model.SelectRange(ui::Range(1U, 3U)); 287 model.SelectRange(gfx::Range(1U, 3U));
288 EXPECT_STR_EQ("EL", model.GetSelectedText()); 288 EXPECT_STR_EQ("EL", model.GetSelectedText());
289 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); 289 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false);
290 EXPECT_EQ(1U, model.GetCursorPosition()); 290 EXPECT_EQ(1U, model.GetCursorPosition());
291 model.SelectRange(ui::Range(1U, 3U)); 291 model.SelectRange(gfx::Range(1U, 3U));
292 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 292 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
293 EXPECT_EQ(3U, model.GetCursorPosition()); 293 EXPECT_EQ(3U, model.GetCursorPosition());
294 294
295 // Select all and move cursor. 295 // Select all and move cursor.
296 model.SelectAll(false); 296 model.SelectAll(false);
297 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); 297 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false);
298 EXPECT_EQ(0U, model.GetCursorPosition()); 298 EXPECT_EQ(0U, model.GetCursorPosition());
299 model.SelectAll(false); 299 model.SelectAll(false);
300 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 300 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
301 EXPECT_EQ(5U, model.GetCursorPosition()); 301 EXPECT_EQ(5U, model.GetCursorPosition());
302 } 302 }
303 303
304 TEST_F(TextfieldViewsModelTest, Selection_BidiWithNonSpacingMarks) { 304 TEST_F(TextfieldViewsModelTest, Selection_BidiWithNonSpacingMarks) {
305 // Selection is a logical operation. And it should work with the arrow 305 // Selection is a logical operation. And it should work with the arrow
306 // keys doing visual movements, while the selection is logical between 306 // keys doing visual movements, while the selection is logical between
307 // the (logical) start and end points. Selection is simply defined as 307 // the (logical) start and end points. Selection is simply defined as
308 // the portion of text between the logical positions of the start and end 308 // the portion of text between the logical positions of the start and end
309 // caret positions. 309 // caret positions.
310 TextfieldViewsModel model(NULL); 310 TextfieldViewsModel model(NULL);
311 // TODO(xji): temporarily disable in platform Win since the complex script 311 // TODO(xji): temporarily disable in platform Win since the complex script
312 // characters turned into empty square due to font regression. So, not able 312 // characters turned into empty square due to font regression. So, not able
313 // to test 2 characters belong to the same grapheme. 313 // to test 2 characters belong to the same grapheme.
314 #if defined(OS_LINUX) 314 #if defined(OS_LINUX)
315 model.Append(WideToUTF16( 315 model.Append(WideToUTF16(
316 L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"def")); 316 L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"def"));
317 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 317 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
318 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); 318 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
319 319
320 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 320 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
321 EXPECT_EQ(ui::Range(2, 3), model.render_text()->selection()); 321 EXPECT_EQ(gfx::Range(2, 3), model.render_text()->selection());
322 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); 322 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText());
323 323
324 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 324 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
325 EXPECT_EQ(ui::Range(2, 7), model.render_text()->selection()); 325 EXPECT_EQ(gfx::Range(2, 7), model.render_text()->selection());
326 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8"), 326 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8"),
327 model.GetSelectedText()); 327 model.GetSelectedText());
328 328
329 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 329 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
330 EXPECT_EQ(ui::Range(2, 3), model.render_text()->selection()); 330 EXPECT_EQ(gfx::Range(2, 3), model.render_text()->selection());
331 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); 331 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText());
332 332
333 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 333 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
334 EXPECT_EQ(ui::Range(2, 10), model.render_text()->selection()); 334 EXPECT_EQ(gfx::Range(2, 10), model.render_text()->selection());
335 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"d"), 335 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"d"),
336 model.GetSelectedText()); 336 model.GetSelectedText());
337 337
338 model.ClearSelection(); 338 model.ClearSelection();
339 EXPECT_EQ(string16(), model.GetSelectedText()); 339 EXPECT_EQ(string16(), model.GetSelectedText());
340 model.SelectAll(false); 340 model.SelectAll(false);
341 EXPECT_EQ(WideToUTF16(L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"def"), 341 EXPECT_EQ(WideToUTF16(L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8" L"def"),
342 model.GetSelectedText()); 342 model.GetSelectedText());
343 #endif 343 #endif
344 344
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 SelectWordTestVerifier(model, WideToUTF16(word_and_cursor[i].word), 627 SelectWordTestVerifier(model, WideToUTF16(word_and_cursor[i].word),
628 word_and_cursor[i].cursor); 628 word_and_cursor[i].cursor);
629 } 629 }
630 } 630 }
631 #endif 631 #endif
632 632
633 TEST_F(TextfieldViewsModelTest, RangeTest) { 633 TEST_F(TextfieldViewsModelTest, RangeTest) {
634 TextfieldViewsModel model(NULL); 634 TextfieldViewsModel model(NULL);
635 model.Append(ASCIIToUTF16("HELLO WORLD")); 635 model.Append(ASCIIToUTF16("HELLO WORLD"));
636 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 636 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
637 ui::Range range = model.render_text()->selection(); 637 gfx::Range range = model.render_text()->selection();
638 EXPECT_TRUE(range.is_empty()); 638 EXPECT_TRUE(range.is_empty());
639 EXPECT_EQ(0U, range.start()); 639 EXPECT_EQ(0U, range.start());
640 EXPECT_EQ(0U, range.end()); 640 EXPECT_EQ(0U, range.end());
641 641
642 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 642 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
643 range = model.render_text()->selection(); 643 range = model.render_text()->selection();
644 EXPECT_FALSE(range.is_empty()); 644 EXPECT_FALSE(range.is_empty());
645 EXPECT_FALSE(range.is_reversed()); 645 EXPECT_FALSE(range.is_reversed());
646 EXPECT_EQ(0U, range.start()); 646 EXPECT_EQ(0U, range.start());
647 EXPECT_EQ(5U, range.end()); 647 EXPECT_EQ(5U, range.end());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 range = model.render_text()->selection(); 690 range = model.render_text()->selection();
691 EXPECT_FALSE(range.is_empty()); 691 EXPECT_FALSE(range.is_empty());
692 EXPECT_TRUE(range.is_reversed()); 692 EXPECT_TRUE(range.is_reversed());
693 EXPECT_EQ(11U, range.start()); 693 EXPECT_EQ(11U, range.start());
694 EXPECT_EQ(0U, range.end()); 694 EXPECT_EQ(0U, range.end());
695 } 695 }
696 696
697 TEST_F(TextfieldViewsModelTest, SelectRangeTest) { 697 TEST_F(TextfieldViewsModelTest, SelectRangeTest) {
698 TextfieldViewsModel model(NULL); 698 TextfieldViewsModel model(NULL);
699 model.Append(ASCIIToUTF16("HELLO WORLD")); 699 model.Append(ASCIIToUTF16("HELLO WORLD"));
700 ui::Range range(0, 6); 700 gfx::Range range(0, 6);
701 EXPECT_FALSE(range.is_reversed()); 701 EXPECT_FALSE(range.is_reversed());
702 model.SelectRange(range); 702 model.SelectRange(range);
703 EXPECT_STR_EQ("HELLO ", model.GetSelectedText()); 703 EXPECT_STR_EQ("HELLO ", model.GetSelectedText());
704 704
705 range = ui::Range(6, 1); 705 range = gfx::Range(6, 1);
706 EXPECT_TRUE(range.is_reversed()); 706 EXPECT_TRUE(range.is_reversed());
707 model.SelectRange(range); 707 model.SelectRange(range);
708 EXPECT_STR_EQ("ELLO ", model.GetSelectedText()); 708 EXPECT_STR_EQ("ELLO ", model.GetSelectedText());
709 709
710 range = ui::Range(2, 1000); 710 range = gfx::Range(2, 1000);
711 EXPECT_FALSE(range.is_reversed()); 711 EXPECT_FALSE(range.is_reversed());
712 model.SelectRange(range); 712 model.SelectRange(range);
713 EXPECT_STR_EQ("LLO WORLD", model.GetSelectedText()); 713 EXPECT_STR_EQ("LLO WORLD", model.GetSelectedText());
714 714
715 range = ui::Range(1000, 3); 715 range = gfx::Range(1000, 3);
716 EXPECT_TRUE(range.is_reversed()); 716 EXPECT_TRUE(range.is_reversed());
717 model.SelectRange(range); 717 model.SelectRange(range);
718 EXPECT_STR_EQ("LO WORLD", model.GetSelectedText()); 718 EXPECT_STR_EQ("LO WORLD", model.GetSelectedText());
719 719
720 range = ui::Range(0, 0); 720 range = gfx::Range(0, 0);
721 EXPECT_TRUE(range.is_empty()); 721 EXPECT_TRUE(range.is_empty());
722 model.SelectRange(range); 722 model.SelectRange(range);
723 EXPECT_TRUE(model.GetSelectedText().empty()); 723 EXPECT_TRUE(model.GetSelectedText().empty());
724 724
725 range = ui::Range(3, 3); 725 range = gfx::Range(3, 3);
726 EXPECT_TRUE(range.is_empty()); 726 EXPECT_TRUE(range.is_empty());
727 model.SelectRange(range); 727 model.SelectRange(range);
728 EXPECT_TRUE(model.GetSelectedText().empty()); 728 EXPECT_TRUE(model.GetSelectedText().empty());
729 729
730 range = ui::Range(1000, 100); 730 range = gfx::Range(1000, 100);
731 EXPECT_FALSE(range.is_empty()); 731 EXPECT_FALSE(range.is_empty());
732 model.SelectRange(range); 732 model.SelectRange(range);
733 EXPECT_TRUE(model.GetSelectedText().empty()); 733 EXPECT_TRUE(model.GetSelectedText().empty());
734 734
735 range = ui::Range(1000, 1000); 735 range = gfx::Range(1000, 1000);
736 EXPECT_TRUE(range.is_empty()); 736 EXPECT_TRUE(range.is_empty());
737 model.SelectRange(range); 737 model.SelectRange(range);
738 EXPECT_TRUE(model.GetSelectedText().empty()); 738 EXPECT_TRUE(model.GetSelectedText().empty());
739 } 739 }
740 740
741 TEST_F(TextfieldViewsModelTest, SelectionTest) { 741 TEST_F(TextfieldViewsModelTest, SelectionTest) {
742 TextfieldViewsModel model(NULL); 742 TextfieldViewsModel model(NULL);
743 model.Append(ASCIIToUTF16("HELLO WORLD")); 743 model.Append(ASCIIToUTF16("HELLO WORLD"));
744 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); 744 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false);
745 ui::Range selection = model.render_text()->selection(); 745 gfx::Range selection = model.render_text()->selection();
746 EXPECT_EQ(ui::Range(0), selection); 746 EXPECT_EQ(gfx::Range(0), selection);
747 747
748 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 748 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
749 selection = model.render_text()->selection(); 749 selection = model.render_text()->selection();
750 EXPECT_EQ(ui::Range(0, 5), selection); 750 EXPECT_EQ(gfx::Range(0, 5), selection);
751 751
752 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); 752 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true);
753 selection = model.render_text()->selection(); 753 selection = model.render_text()->selection();
754 EXPECT_EQ(ui::Range(0, 4), selection); 754 EXPECT_EQ(gfx::Range(0, 4), selection);
755 755
756 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 756 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
757 selection = model.render_text()->selection(); 757 selection = model.render_text()->selection();
758 EXPECT_EQ(ui::Range(0), selection); 758 EXPECT_EQ(gfx::Range(0), selection);
759 759
760 // now from the end. 760 // now from the end.
761 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 761 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
762 selection = model.render_text()->selection(); 762 selection = model.render_text()->selection();
763 EXPECT_EQ(ui::Range(11), selection); 763 EXPECT_EQ(gfx::Range(11), selection);
764 764
765 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); 765 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true);
766 selection = model.render_text()->selection(); 766 selection = model.render_text()->selection();
767 EXPECT_EQ(ui::Range(11, 6), selection); 767 EXPECT_EQ(gfx::Range(11, 6), selection);
768 768
769 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); 769 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true);
770 selection = model.render_text()->selection(); 770 selection = model.render_text()->selection();
771 EXPECT_EQ(ui::Range(11, 7), selection); 771 EXPECT_EQ(gfx::Range(11, 7), selection);
772 772
773 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); 773 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true);
774 selection = model.render_text()->selection(); 774 selection = model.render_text()->selection();
775 EXPECT_EQ(ui::Range(11), selection); 775 EXPECT_EQ(gfx::Range(11), selection);
776 776
777 // Select All 777 // Select All
778 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); 778 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true);
779 selection = model.render_text()->selection(); 779 selection = model.render_text()->selection();
780 EXPECT_EQ(ui::Range(11, 0), selection); 780 EXPECT_EQ(gfx::Range(11, 0), selection);
781 } 781 }
782 782
783 TEST_F(TextfieldViewsModelTest, SelectSelectionModelTest) { 783 TEST_F(TextfieldViewsModelTest, SelectSelectionModelTest) {
784 TextfieldViewsModel model(NULL); 784 TextfieldViewsModel model(NULL);
785 model.Append(ASCIIToUTF16("HELLO WORLD")); 785 model.Append(ASCIIToUTF16("HELLO WORLD"));
786 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(0, 6), 786 model.SelectSelectionModel(gfx::SelectionModel(gfx::Range(0, 6),
787 gfx::CURSOR_BACKWARD)); 787 gfx::CURSOR_BACKWARD));
788 EXPECT_STR_EQ("HELLO ", model.GetSelectedText()); 788 EXPECT_STR_EQ("HELLO ", model.GetSelectedText());
789 789
790 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(6, 1), 790 model.SelectSelectionModel(gfx::SelectionModel(gfx::Range(6, 1),
791 gfx::CURSOR_FORWARD)); 791 gfx::CURSOR_FORWARD));
792 EXPECT_STR_EQ("ELLO ", model.GetSelectedText()); 792 EXPECT_STR_EQ("ELLO ", model.GetSelectedText());
793 793
794 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(2, 1000), 794 model.SelectSelectionModel(gfx::SelectionModel(gfx::Range(2, 1000),
795 gfx::CURSOR_BACKWARD)); 795 gfx::CURSOR_BACKWARD));
796 EXPECT_STR_EQ("LLO WORLD", model.GetSelectedText()); 796 EXPECT_STR_EQ("LLO WORLD", model.GetSelectedText());
797 797
798 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(1000, 3), 798 model.SelectSelectionModel(gfx::SelectionModel(gfx::Range(1000, 3),
799 gfx::CURSOR_FORWARD)); 799 gfx::CURSOR_FORWARD));
800 EXPECT_STR_EQ("LO WORLD", model.GetSelectedText()); 800 EXPECT_STR_EQ("LO WORLD", model.GetSelectedText());
801 801
802 model.SelectSelectionModel(gfx::SelectionModel(0, gfx::CURSOR_FORWARD)); 802 model.SelectSelectionModel(gfx::SelectionModel(0, gfx::CURSOR_FORWARD));
803 EXPECT_TRUE(model.GetSelectedText().empty()); 803 EXPECT_TRUE(model.GetSelectedText().empty());
804 804
805 model.SelectSelectionModel(gfx::SelectionModel(3, gfx::CURSOR_FORWARD)); 805 model.SelectSelectionModel(gfx::SelectionModel(3, gfx::CURSOR_FORWARD));
806 EXPECT_TRUE(model.GetSelectedText().empty()); 806 EXPECT_TRUE(model.GetSelectedText().empty());
807 807
808 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(1000, 100), 808 model.SelectSelectionModel(gfx::SelectionModel(gfx::Range(1000, 100),
809 gfx::CURSOR_FORWARD)); 809 gfx::CURSOR_FORWARD));
810 EXPECT_TRUE(model.GetSelectedText().empty()); 810 EXPECT_TRUE(model.GetSelectedText().empty());
811 811
812 model.SelectSelectionModel(gfx::SelectionModel(1000, gfx::CURSOR_BACKWARD)); 812 model.SelectSelectionModel(gfx::SelectionModel(1000, gfx::CURSOR_BACKWARD));
813 EXPECT_TRUE(model.GetSelectedText().empty()); 813 EXPECT_TRUE(model.GetSelectedText().empty());
814 } 814 }
815 815
816 TEST_F(TextfieldViewsModelTest, CompositionTextTest) { 816 TEST_F(TextfieldViewsModelTest, CompositionTextTest) {
817 TextfieldViewsModel model(this); 817 TextfieldViewsModel model(this);
818 model.Append(ASCIIToUTF16("1234590")); 818 model.Append(ASCIIToUTF16("1234590"));
819 model.SelectRange(ui::Range(5, 5)); 819 model.SelectRange(gfx::Range(5, 5));
820 EXPECT_FALSE(model.HasSelection()); 820 EXPECT_FALSE(model.HasSelection());
821 EXPECT_EQ(5U, model.GetCursorPosition()); 821 EXPECT_EQ(5U, model.GetCursorPosition());
822 822
823 ui::Range range; 823 gfx::Range range;
824 model.GetTextRange(&range); 824 model.GetTextRange(&range);
825 EXPECT_EQ(ui::Range(0, 7), range); 825 EXPECT_EQ(gfx::Range(0, 7), range);
826 826
827 ui::CompositionText composition; 827 ui::CompositionText composition;
828 composition.text = ASCIIToUTF16("678"); 828 composition.text = ASCIIToUTF16("678");
829 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false)); 829 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false));
830 830
831 // Cursor should be at the end of composition when characters are just typed. 831 // Cursor should be at the end of composition when characters are just typed.
832 composition.selection = ui::Range(3, 3); 832 composition.selection = gfx::Range(3, 3);
833 model.SetCompositionText(composition); 833 model.SetCompositionText(composition);
834 EXPECT_TRUE(model.HasCompositionText()); 834 EXPECT_TRUE(model.HasCompositionText());
835 EXPECT_FALSE(model.HasSelection()); 835 EXPECT_FALSE(model.HasSelection());
836 836
837 // Cancel composition 837 // Cancel composition
838 model.CancelCompositionText(); 838 model.CancelCompositionText();
839 composition_text_confirmed_or_cleared_ = false; 839 composition_text_confirmed_or_cleared_ = false;
840 840
841 // Restart composition with targeting "67" in "678". 841 // Restart composition with targeting "67" in "678".
842 composition.selection = ui::Range(0, 2); 842 composition.selection = gfx::Range(0, 2);
843 composition.underlines.clear(); 843 composition.underlines.clear();
844 composition.underlines.push_back(ui::CompositionUnderline(0, 2, 0, true)); 844 composition.underlines.push_back(ui::CompositionUnderline(0, 2, 0, true));
845 composition.underlines.push_back(ui::CompositionUnderline(2, 3, 0, false)); 845 composition.underlines.push_back(ui::CompositionUnderline(2, 3, 0, false));
846 model.SetCompositionText(composition); 846 model.SetCompositionText(composition);
847 EXPECT_TRUE(model.HasCompositionText()); 847 EXPECT_TRUE(model.HasCompositionText());
848 EXPECT_TRUE(model.HasSelection()); 848 EXPECT_TRUE(model.HasSelection());
849 EXPECT_EQ(ui::Range(5, 7), model.render_text()->selection()); 849 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection());
850 850
851 model.GetTextRange(&range); 851 model.GetTextRange(&range);
852 EXPECT_EQ(10U, range.end()); 852 EXPECT_EQ(10U, range.end());
853 EXPECT_STR_EQ("1234567890", model.GetText()); 853 EXPECT_STR_EQ("1234567890", model.GetText());
854 854
855 model.GetCompositionTextRange(&range); 855 model.GetCompositionTextRange(&range);
856 EXPECT_EQ(ui::Range(5, 8), range); 856 EXPECT_EQ(gfx::Range(5, 8), range);
857 // composition text 857 // composition text
858 EXPECT_STR_EQ("456", model.GetTextFromRange(ui::Range(3, 6))); 858 EXPECT_STR_EQ("456", model.GetTextFromRange(gfx::Range(3, 6)));
859 EXPECT_EQ(ui::Range(5, 7), model.render_text()->selection()); 859 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection());
860 860
861 EXPECT_FALSE(composition_text_confirmed_or_cleared_); 861 EXPECT_FALSE(composition_text_confirmed_or_cleared_);
862 model.CancelCompositionText(); 862 model.CancelCompositionText();
863 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 863 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
864 composition_text_confirmed_or_cleared_ = false; 864 composition_text_confirmed_or_cleared_ = false;
865 EXPECT_FALSE(model.HasCompositionText()); 865 EXPECT_FALSE(model.HasCompositionText());
866 EXPECT_FALSE(model.HasSelection()); 866 EXPECT_FALSE(model.HasSelection());
867 EXPECT_EQ(5U, model.GetCursorPosition()); 867 EXPECT_EQ(5U, model.GetCursorPosition());
868 868
869 model.SetCompositionText(composition); 869 model.SetCompositionText(composition);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 EXPECT_STR_EQ("678678", model.GetText()); 947 EXPECT_STR_EQ("678678", model.GetText());
948 948
949 model.SetCompositionText(composition); 949 model.SetCompositionText(composition);
950 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 950 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
951 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 951 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
952 composition_text_confirmed_or_cleared_ = false; 952 composition_text_confirmed_or_cleared_ = false;
953 EXPECT_STR_EQ("678", model.GetText()); 953 EXPECT_STR_EQ("678", model.GetText());
954 954
955 model.SetCompositionText(composition); 955 model.SetCompositionText(composition);
956 gfx::SelectionModel sel( 956 gfx::SelectionModel sel(
957 ui::Range(model.render_text()->selection().start(), 0), 957 gfx::Range(model.render_text()->selection().start(), 0),
958 gfx::CURSOR_FORWARD); 958 gfx::CURSOR_FORWARD);
959 model.MoveCursorTo(sel); 959 model.MoveCursorTo(sel);
960 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 960 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
961 composition_text_confirmed_or_cleared_ = false; 961 composition_text_confirmed_or_cleared_ = false;
962 EXPECT_STR_EQ("678678", model.GetText()); 962 EXPECT_STR_EQ("678678", model.GetText());
963 963
964 model.SetCompositionText(composition); 964 model.SetCompositionText(composition);
965 model.SelectRange(ui::Range(0, 3)); 965 model.SelectRange(gfx::Range(0, 3));
966 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 966 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
967 composition_text_confirmed_or_cleared_ = false; 967 composition_text_confirmed_or_cleared_ = false;
968 EXPECT_STR_EQ("678", model.GetText()); 968 EXPECT_STR_EQ("678", model.GetText());
969 969
970 model.SetCompositionText(composition); 970 model.SetCompositionText(composition);
971 model.SelectAll(false); 971 model.SelectAll(false);
972 EXPECT_TRUE(composition_text_confirmed_or_cleared_); 972 EXPECT_TRUE(composition_text_confirmed_or_cleared_);
973 composition_text_confirmed_or_cleared_ = false; 973 composition_text_confirmed_or_cleared_ = false;
974 EXPECT_STR_EQ("678", model.GetText()); 974 EXPECT_STR_EQ("678", model.GetText());
975 975
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 1088
1089 TEST_F(TextfieldViewsModelTest, UndoRedo_SetText) { 1089 TEST_F(TextfieldViewsModelTest, UndoRedo_SetText) {
1090 // This is to test the undo/redo behavior of omnibox. 1090 // This is to test the undo/redo behavior of omnibox.
1091 TextfieldViewsModel model(NULL); 1091 TextfieldViewsModel model(NULL);
1092 model.InsertChar('w'); 1092 model.InsertChar('w');
1093 EXPECT_STR_EQ("w", model.GetText()); 1093 EXPECT_STR_EQ("w", model.GetText());
1094 EXPECT_EQ(1U, model.GetCursorPosition()); 1094 EXPECT_EQ(1U, model.GetCursorPosition());
1095 model.SetText(ASCIIToUTF16("www.google.com")); 1095 model.SetText(ASCIIToUTF16("www.google.com"));
1096 EXPECT_EQ(14U, model.GetCursorPosition()); 1096 EXPECT_EQ(14U, model.GetCursorPosition());
1097 EXPECT_STR_EQ("www.google.com", model.GetText()); 1097 EXPECT_STR_EQ("www.google.com", model.GetText());
1098 model.SelectRange(ui::Range(14, 1)); 1098 model.SelectRange(gfx::Range(14, 1));
1099 model.InsertChar('w'); 1099 model.InsertChar('w');
1100 EXPECT_STR_EQ("ww", model.GetText()); 1100 EXPECT_STR_EQ("ww", model.GetText());
1101 model.SetText(ASCIIToUTF16("www.google.com")); 1101 model.SetText(ASCIIToUTF16("www.google.com"));
1102 model.SelectRange(ui::Range(14, 2)); 1102 model.SelectRange(gfx::Range(14, 2));
1103 model.InsertChar('w'); 1103 model.InsertChar('w');
1104 EXPECT_STR_EQ("www", model.GetText()); 1104 EXPECT_STR_EQ("www", model.GetText());
1105 model.SetText(ASCIIToUTF16("www.google.com")); 1105 model.SetText(ASCIIToUTF16("www.google.com"));
1106 model.SelectRange(ui::Range(14, 3)); 1106 model.SelectRange(gfx::Range(14, 3));
1107 model.InsertChar('.'); 1107 model.InsertChar('.');
1108 EXPECT_STR_EQ("www.", model.GetText()); 1108 EXPECT_STR_EQ("www.", model.GetText());
1109 model.SetText(ASCIIToUTF16("www.google.com")); 1109 model.SetText(ASCIIToUTF16("www.google.com"));
1110 model.SelectRange(ui::Range(14, 4)); 1110 model.SelectRange(gfx::Range(14, 4));
1111 model.InsertChar('y'); 1111 model.InsertChar('y');
1112 EXPECT_STR_EQ("www.y", model.GetText()); 1112 EXPECT_STR_EQ("www.y", model.GetText());
1113 model.SetText(ASCIIToUTF16("www.youtube.com")); 1113 model.SetText(ASCIIToUTF16("www.youtube.com"));
1114 EXPECT_STR_EQ("www.youtube.com", model.GetText()); 1114 EXPECT_STR_EQ("www.youtube.com", model.GetText());
1115 EXPECT_EQ(15U, model.GetCursorPosition()); 1115 EXPECT_EQ(15U, model.GetCursorPosition());
1116 1116
1117 EXPECT_TRUE(model.Undo()); 1117 EXPECT_TRUE(model.Undo());
1118 EXPECT_STR_EQ("www.google.com", model.GetText()); 1118 EXPECT_STR_EQ("www.google.com", model.GetText());
1119 EXPECT_EQ(4U, model.GetCursorPosition()); 1119 EXPECT_EQ(4U, model.GetCursorPosition());
1120 EXPECT_TRUE(model.Undo()); 1120 EXPECT_TRUE(model.Undo());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 EXPECT_STR_EQ("www.google.c", model.GetText()); 1170 EXPECT_STR_EQ("www.google.c", model.GetText());
1171 EXPECT_TRUE(model.Undo()); 1171 EXPECT_TRUE(model.Undo());
1172 EXPECT_STR_EQ("www.google.com", model.GetText()); 1172 EXPECT_STR_EQ("www.google.com", model.GetText());
1173 } 1173 }
1174 1174
1175 TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) { 1175 TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) {
1176 TextfieldViewsModel model(NULL); 1176 TextfieldViewsModel model(NULL);
1177 model.SetText(ASCIIToUTF16("ABCDE")); 1177 model.SetText(ASCIIToUTF16("ABCDE"));
1178 EXPECT_FALSE(model.Redo()); // nothing to redo 1178 EXPECT_FALSE(model.Redo()); // nothing to redo
1179 // Cut 1179 // Cut
1180 model.SelectRange(ui::Range(1, 3)); 1180 model.SelectRange(gfx::Range(1, 3));
1181 model.Cut(); 1181 model.Cut();
1182 EXPECT_STR_EQ("ADE", model.GetText()); 1182 EXPECT_STR_EQ("ADE", model.GetText());
1183 EXPECT_EQ(1U, model.GetCursorPosition()); 1183 EXPECT_EQ(1U, model.GetCursorPosition());
1184 EXPECT_TRUE(model.Undo()); 1184 EXPECT_TRUE(model.Undo());
1185 EXPECT_STR_EQ("ABCDE", model.GetText()); 1185 EXPECT_STR_EQ("ABCDE", model.GetText());
1186 EXPECT_EQ(3U, model.GetCursorPosition()); 1186 EXPECT_EQ(3U, model.GetCursorPosition());
1187 EXPECT_TRUE(model.Undo()); 1187 EXPECT_TRUE(model.Undo());
1188 EXPECT_STR_EQ("", model.GetText()); 1188 EXPECT_STR_EQ("", model.GetText());
1189 EXPECT_EQ(0U, model.GetCursorPosition()); 1189 EXPECT_EQ(0U, model.GetCursorPosition());
1190 EXPECT_FALSE(model.Undo()); // no more undo 1190 EXPECT_FALSE(model.Undo()); // no more undo
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 EXPECT_EQ(3U, model.GetCursorPosition()); 1233 EXPECT_EQ(3U, model.GetCursorPosition());
1234 EXPECT_TRUE(model.Redo()); 1234 EXPECT_TRUE(model.Redo());
1235 EXPECT_STR_EQ("ABCBCDE", model.GetText()); 1235 EXPECT_STR_EQ("ABCBCDE", model.GetText());
1236 EXPECT_EQ(5U, model.GetCursorPosition()); 1236 EXPECT_EQ(5U, model.GetCursorPosition());
1237 EXPECT_TRUE(model.Redo()); 1237 EXPECT_TRUE(model.Redo());
1238 EXPECT_STR_EQ("ABCBCBCDE", model.GetText()); 1238 EXPECT_STR_EQ("ABCBCBCDE", model.GetText());
1239 EXPECT_EQ(7U, model.GetCursorPosition()); 1239 EXPECT_EQ(7U, model.GetCursorPosition());
1240 EXPECT_FALSE(model.Redo()); 1240 EXPECT_FALSE(model.Redo());
1241 1241
1242 // with SelectRange 1242 // with SelectRange
1243 model.SelectRange(ui::Range(1, 3)); 1243 model.SelectRange(gfx::Range(1, 3));
1244 EXPECT_TRUE(model.Cut()); 1244 EXPECT_TRUE(model.Cut());
1245 EXPECT_STR_EQ("ABCBCDE", model.GetText()); 1245 EXPECT_STR_EQ("ABCBCDE", model.GetText());
1246 EXPECT_EQ(1U, model.GetCursorPosition()); 1246 EXPECT_EQ(1U, model.GetCursorPosition());
1247 model.SelectRange(ui::Range(1, 1)); 1247 model.SelectRange(gfx::Range(1, 1));
1248 EXPECT_FALSE(model.Cut()); 1248 EXPECT_FALSE(model.Cut());
1249 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1249 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
1250 EXPECT_TRUE(model.Paste()); 1250 EXPECT_TRUE(model.Paste());
1251 EXPECT_STR_EQ("ABCBCDEBC", model.GetText()); 1251 EXPECT_STR_EQ("ABCBCDEBC", model.GetText());
1252 EXPECT_EQ(9U, model.GetCursorPosition()); 1252 EXPECT_EQ(9U, model.GetCursorPosition());
1253 EXPECT_TRUE(model.Undo()); 1253 EXPECT_TRUE(model.Undo());
1254 EXPECT_STR_EQ("ABCBCDE", model.GetText()); 1254 EXPECT_STR_EQ("ABCBCDE", model.GetText());
1255 EXPECT_EQ(7U, model.GetCursorPosition()); 1255 EXPECT_EQ(7U, model.GetCursorPosition());
1256 // empty cut shouldn't create an edit. 1256 // empty cut shouldn't create an edit.
1257 EXPECT_TRUE(model.Undo()); 1257 EXPECT_TRUE(model.Undo());
1258 EXPECT_STR_EQ("ABCBCBCDE", model.GetText()); 1258 EXPECT_STR_EQ("ABCBCBCDE", model.GetText());
1259 EXPECT_EQ(3U, model.GetCursorPosition()); 1259 EXPECT_EQ(3U, model.GetCursorPosition());
1260 1260
1261 // Copy 1261 // Copy
1262 ResetModel(&model); 1262 ResetModel(&model);
1263 model.SetText(ASCIIToUTF16("12345")); 1263 model.SetText(ASCIIToUTF16("12345"));
1264 EXPECT_STR_EQ("12345", model.GetText()); 1264 EXPECT_STR_EQ("12345", model.GetText());
1265 EXPECT_EQ(5U, model.GetCursorPosition()); 1265 EXPECT_EQ(5U, model.GetCursorPosition());
1266 model.SelectRange(ui::Range(1, 3)); 1266 model.SelectRange(gfx::Range(1, 3));
1267 model.Copy(); // Copy "23" 1267 model.Copy(); // Copy "23"
1268 EXPECT_STR_EQ("12345", model.GetText()); 1268 EXPECT_STR_EQ("12345", model.GetText());
1269 EXPECT_EQ(3U, model.GetCursorPosition()); 1269 EXPECT_EQ(3U, model.GetCursorPosition());
1270 model.Paste(); // Paste "23" into "23". 1270 model.Paste(); // Paste "23" into "23".
1271 EXPECT_STR_EQ("12345", model.GetText()); 1271 EXPECT_STR_EQ("12345", model.GetText());
1272 EXPECT_EQ(3U, model.GetCursorPosition()); 1272 EXPECT_EQ(3U, model.GetCursorPosition());
1273 model.Paste(); 1273 model.Paste();
1274 EXPECT_STR_EQ("1232345", model.GetText()); 1274 EXPECT_STR_EQ("1232345", model.GetText());
1275 EXPECT_EQ(5U, model.GetCursorPosition()); 1275 EXPECT_EQ(5U, model.GetCursorPosition());
1276 EXPECT_TRUE(model.Undo()); 1276 EXPECT_TRUE(model.Undo());
(...skipping 13 matching lines...) Expand all
1290 EXPECT_TRUE(model.Redo()); 1290 EXPECT_TRUE(model.Redo());
1291 EXPECT_STR_EQ("12345", model.GetText()); // For 1st paste 1291 EXPECT_STR_EQ("12345", model.GetText()); // For 1st paste
1292 EXPECT_EQ(3U, model.GetCursorPosition()); 1292 EXPECT_EQ(3U, model.GetCursorPosition());
1293 EXPECT_TRUE(model.Redo()); 1293 EXPECT_TRUE(model.Redo());
1294 EXPECT_STR_EQ("1232345", model.GetText()); 1294 EXPECT_STR_EQ("1232345", model.GetText());
1295 EXPECT_EQ(5U, model.GetCursorPosition()); 1295 EXPECT_EQ(5U, model.GetCursorPosition());
1296 EXPECT_FALSE(model.Redo()); 1296 EXPECT_FALSE(model.Redo());
1297 EXPECT_STR_EQ("1232345", model.GetText()); 1297 EXPECT_STR_EQ("1232345", model.GetText());
1298 1298
1299 // Test using SelectRange 1299 // Test using SelectRange
1300 model.SelectRange(ui::Range(1, 3)); 1300 model.SelectRange(gfx::Range(1, 3));
1301 model.Copy(); 1301 model.Copy();
1302 EXPECT_STR_EQ("1232345", model.GetText()); 1302 EXPECT_STR_EQ("1232345", model.GetText());
1303 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1303 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
1304 EXPECT_TRUE(model.Paste()); 1304 EXPECT_TRUE(model.Paste());
1305 EXPECT_STR_EQ("123234523", model.GetText()); 1305 EXPECT_STR_EQ("123234523", model.GetText());
1306 EXPECT_EQ(9U, model.GetCursorPosition()); 1306 EXPECT_EQ(9U, model.GetCursorPosition());
1307 EXPECT_TRUE(model.Undo()); 1307 EXPECT_TRUE(model.Undo());
1308 EXPECT_STR_EQ("1232345", model.GetText()); 1308 EXPECT_STR_EQ("1232345", model.GetText());
1309 EXPECT_EQ(7U, model.GetCursorPosition()); 1309 EXPECT_EQ(7U, model.GetCursorPosition());
1310 } 1310 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 EXPECT_EQ(5U, model.GetCursorPosition()); 1374 EXPECT_EQ(5U, model.GetCursorPosition());
1375 EXPECT_FALSE(model.Redo()); 1375 EXPECT_FALSE(model.Redo());
1376 } 1376 }
1377 1377
1378 TEST_F(TextfieldViewsModelTest, UndoRedo_ReplaceTest) { 1378 TEST_F(TextfieldViewsModelTest, UndoRedo_ReplaceTest) {
1379 // By Cursor 1379 // By Cursor
1380 { 1380 {
1381 SCOPED_TRACE("forward & insert by cursor"); 1381 SCOPED_TRACE("forward & insert by cursor");
1382 TextfieldViewsModel model(NULL); 1382 TextfieldViewsModel model(NULL);
1383 model.SetText(ASCIIToUTF16("abcd")); 1383 model.SetText(ASCIIToUTF16("abcd"));
1384 model.SelectRange(ui::Range(1, 3)); 1384 model.SelectRange(gfx::Range(1, 3));
1385 RunInsertReplaceTest(model); 1385 RunInsertReplaceTest(model);
1386 } 1386 }
1387 { 1387 {
1388 SCOPED_TRACE("backward & insert by cursor"); 1388 SCOPED_TRACE("backward & insert by cursor");
1389 TextfieldViewsModel model(NULL); 1389 TextfieldViewsModel model(NULL);
1390 model.SetText(ASCIIToUTF16("abcd")); 1390 model.SetText(ASCIIToUTF16("abcd"));
1391 model.SelectRange(ui::Range(3, 1)); 1391 model.SelectRange(gfx::Range(3, 1));
1392 RunInsertReplaceTest(model); 1392 RunInsertReplaceTest(model);
1393 } 1393 }
1394 { 1394 {
1395 SCOPED_TRACE("forward & overwrite by cursor"); 1395 SCOPED_TRACE("forward & overwrite by cursor");
1396 TextfieldViewsModel model(NULL); 1396 TextfieldViewsModel model(NULL);
1397 model.SetText(ASCIIToUTF16("abcd")); 1397 model.SetText(ASCIIToUTF16("abcd"));
1398 model.SelectRange(ui::Range(1, 3)); 1398 model.SelectRange(gfx::Range(1, 3));
1399 RunOverwriteReplaceTest(model); 1399 RunOverwriteReplaceTest(model);
1400 } 1400 }
1401 { 1401 {
1402 SCOPED_TRACE("backward & overwrite by cursor"); 1402 SCOPED_TRACE("backward & overwrite by cursor");
1403 TextfieldViewsModel model(NULL); 1403 TextfieldViewsModel model(NULL);
1404 model.SetText(ASCIIToUTF16("abcd")); 1404 model.SetText(ASCIIToUTF16("abcd"));
1405 model.SelectRange(ui::Range(3, 1)); 1405 model.SelectRange(gfx::Range(3, 1));
1406 RunOverwriteReplaceTest(model); 1406 RunOverwriteReplaceTest(model);
1407 } 1407 }
1408 // By SelectRange API 1408 // By SelectRange API
1409 { 1409 {
1410 SCOPED_TRACE("forward & insert by SelectRange"); 1410 SCOPED_TRACE("forward & insert by SelectRange");
1411 TextfieldViewsModel model(NULL); 1411 TextfieldViewsModel model(NULL);
1412 model.SetText(ASCIIToUTF16("abcd")); 1412 model.SetText(ASCIIToUTF16("abcd"));
1413 model.SelectRange(ui::Range(1, 3)); 1413 model.SelectRange(gfx::Range(1, 3));
1414 RunInsertReplaceTest(model); 1414 RunInsertReplaceTest(model);
1415 } 1415 }
1416 { 1416 {
1417 SCOPED_TRACE("backward & insert by SelectRange"); 1417 SCOPED_TRACE("backward & insert by SelectRange");
1418 TextfieldViewsModel model(NULL); 1418 TextfieldViewsModel model(NULL);
1419 model.SetText(ASCIIToUTF16("abcd")); 1419 model.SetText(ASCIIToUTF16("abcd"));
1420 model.SelectRange(ui::Range(3, 1)); 1420 model.SelectRange(gfx::Range(3, 1));
1421 RunInsertReplaceTest(model); 1421 RunInsertReplaceTest(model);
1422 } 1422 }
1423 { 1423 {
1424 SCOPED_TRACE("forward & overwrite by SelectRange"); 1424 SCOPED_TRACE("forward & overwrite by SelectRange");
1425 TextfieldViewsModel model(NULL); 1425 TextfieldViewsModel model(NULL);
1426 model.SetText(ASCIIToUTF16("abcd")); 1426 model.SetText(ASCIIToUTF16("abcd"));
1427 model.SelectRange(ui::Range(1, 3)); 1427 model.SelectRange(gfx::Range(1, 3));
1428 RunOverwriteReplaceTest(model); 1428 RunOverwriteReplaceTest(model);
1429 } 1429 }
1430 { 1430 {
1431 SCOPED_TRACE("backward & overwrite by SelectRange"); 1431 SCOPED_TRACE("backward & overwrite by SelectRange");
1432 TextfieldViewsModel model(NULL); 1432 TextfieldViewsModel model(NULL);
1433 model.SetText(ASCIIToUTF16("abcd")); 1433 model.SetText(ASCIIToUTF16("abcd"));
1434 model.SelectRange(ui::Range(3, 1)); 1434 model.SelectRange(gfx::Range(3, 1));
1435 RunOverwriteReplaceTest(model); 1435 RunOverwriteReplaceTest(model);
1436 } 1436 }
1437 } 1437 }
1438 1438
1439 TEST_F(TextfieldViewsModelTest, UndoRedo_CompositionText) { 1439 TEST_F(TextfieldViewsModelTest, UndoRedo_CompositionText) {
1440 TextfieldViewsModel model(NULL); 1440 TextfieldViewsModel model(NULL);
1441 1441
1442 ui::CompositionText composition; 1442 ui::CompositionText composition;
1443 composition.text = ASCIIToUTF16("abc"); 1443 composition.text = ASCIIToUTF16("abc");
1444 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false)); 1444 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false));
1445 composition.selection = ui::Range(2, 3); 1445 composition.selection = gfx::Range(2, 3);
1446 1446
1447 model.SetText(ASCIIToUTF16("ABCDE")); 1447 model.SetText(ASCIIToUTF16("ABCDE"));
1448 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); 1448 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
1449 model.InsertChar('x'); 1449 model.InsertChar('x');
1450 EXPECT_STR_EQ("ABCDEx", model.GetText()); 1450 EXPECT_STR_EQ("ABCDEx", model.GetText());
1451 EXPECT_TRUE(model.Undo()); // set composition should forget undone edit. 1451 EXPECT_TRUE(model.Undo()); // set composition should forget undone edit.
1452 model.SetCompositionText(composition); 1452 model.SetCompositionText(composition);
1453 EXPECT_TRUE(model.HasCompositionText()); 1453 EXPECT_TRUE(model.HasCompositionText());
1454 EXPECT_TRUE(model.HasSelection()); 1454 EXPECT_TRUE(model.HasSelection());
1455 EXPECT_STR_EQ("ABCDEabc", model.GetText()); 1455 EXPECT_STR_EQ("ABCDEabc", model.GetText());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 EXPECT_TRUE(model.Undo()); 1507 EXPECT_TRUE(model.Undo());
1508 EXPECT_STR_EQ("ABCDE", model.GetText()); 1508 EXPECT_STR_EQ("ABCDE", model.GetText());
1509 EXPECT_TRUE(model.Redo()); 1509 EXPECT_TRUE(model.Redo());
1510 EXPECT_STR_EQ("1234", model.GetText()); 1510 EXPECT_STR_EQ("1234", model.GetText());
1511 EXPECT_FALSE(model.Redo()); 1511 EXPECT_FALSE(model.Redo());
1512 1512
1513 // TODO(oshima): We need MockInputMethod to test the behavior with IME. 1513 // TODO(oshima): We need MockInputMethod to test the behavior with IME.
1514 } 1514 }
1515 1515
1516 } // namespace views 1516 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/textfield/textfield_views_model.cc ('k') | ui/views/examples/textfield_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698