OLD | NEW |
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 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 composition.selection = gfx::Range(3, 3); | 886 composition.selection = gfx::Range(3, 3); |
887 model.SetCompositionText(composition); | 887 model.SetCompositionText(composition); |
888 EXPECT_TRUE(model.HasCompositionText()); | 888 EXPECT_TRUE(model.HasCompositionText()); |
889 EXPECT_FALSE(model.HasSelection()); | 889 EXPECT_FALSE(model.HasSelection()); |
890 | 890 |
891 // Cancel the composition. | 891 // Cancel the composition. |
892 model.CancelCompositionText(); | 892 model.CancelCompositionText(); |
893 composition_text_confirmed_or_cleared_ = false; | 893 composition_text_confirmed_or_cleared_ = false; |
894 | 894 |
895 // Restart composition with targeting "67" in "678". | 895 // Restart composition with targeting "67" in "678". |
896 composition.selection = gfx::Range(0, 2); | 896 composition.selection = gfx::Range(1, 3); |
897 composition.underlines.clear(); | 897 composition.underlines.clear(); |
898 composition.underlines.push_back(ui::CompositionUnderline(0, 2, 0, true)); | 898 composition.underlines.push_back(ui::CompositionUnderline(0, 2, 0, true)); |
899 composition.underlines.push_back(ui::CompositionUnderline(2, 3, 0, false)); | 899 composition.underlines.push_back(ui::CompositionUnderline(2, 3, 0, false)); |
900 model.SetCompositionText(composition); | 900 model.SetCompositionText(composition); |
901 EXPECT_TRUE(model.HasCompositionText()); | 901 EXPECT_TRUE(model.HasCompositionText()); |
902 EXPECT_TRUE(model.HasSelection()); | 902 EXPECT_TRUE(model.HasSelection()); |
| 903 #if !defined(OS_CHROMEOS) |
| 904 // |composition.selection| is ignored because SetCompositionText checks |
| 905 // if a bold underline exists first. |
903 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection()); | 906 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection()); |
| 907 EXPECT_EQ(7U, model.render_text()->cursor_position()); |
| 908 #else |
| 909 // See SelectRangeInCompositionText(). |
| 910 EXPECT_EQ(gfx::Range(7, 5), model.render_text()->selection()); |
| 911 EXPECT_EQ(5U, model.render_text()->cursor_position()); |
| 912 #endif |
904 | 913 |
905 model.GetTextRange(&range); | 914 model.GetTextRange(&range); |
906 EXPECT_EQ(10U, range.end()); | 915 EXPECT_EQ(10U, range.end()); |
907 EXPECT_STR_EQ("1234567890", model.text()); | 916 EXPECT_STR_EQ("1234567890", model.text()); |
908 | 917 |
909 model.GetCompositionTextRange(&range); | 918 model.GetCompositionTextRange(&range); |
910 EXPECT_EQ(gfx::Range(5, 8), range); | 919 EXPECT_EQ(gfx::Range(5, 8), range); |
911 // Check the composition text. | 920 // Check the composition text. |
912 EXPECT_STR_EQ("456", model.GetTextFromRange(gfx::Range(3, 6))); | 921 EXPECT_STR_EQ("456", model.GetTextFromRange(gfx::Range(3, 6))); |
913 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection()); | |
914 | 922 |
915 EXPECT_FALSE(composition_text_confirmed_or_cleared_); | 923 EXPECT_FALSE(composition_text_confirmed_or_cleared_); |
916 model.CancelCompositionText(); | 924 model.CancelCompositionText(); |
917 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 925 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
918 composition_text_confirmed_or_cleared_ = false; | 926 composition_text_confirmed_or_cleared_ = false; |
919 EXPECT_FALSE(model.HasCompositionText()); | 927 EXPECT_FALSE(model.HasCompositionText()); |
920 EXPECT_FALSE(model.HasSelection()); | 928 EXPECT_FALSE(model.HasSelection()); |
921 EXPECT_EQ(5U, model.GetCursorPosition()); | 929 EXPECT_EQ(5U, model.GetCursorPosition()); |
922 | 930 |
923 model.SetCompositionText(composition); | 931 model.SetCompositionText(composition); |
924 EXPECT_STR_EQ("1234567890", model.text()); | 932 EXPECT_STR_EQ("1234567890", model.text()); |
925 EXPECT_TRUE(model.SetText(base::ASCIIToUTF16("1234567890"))); | 933 EXPECT_TRUE(model.SetText(base::ASCIIToUTF16("1234567890"))); |
926 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 934 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
927 composition_text_confirmed_or_cleared_ = false; | 935 composition_text_confirmed_or_cleared_ = false; |
928 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE); | 936 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, gfx::SELECTION_NONE); |
929 | 937 |
| 938 // Also test the case where a selection exists but a bold underline doesn't. |
| 939 composition.selection = gfx::Range(0, 1); |
| 940 composition.underlines.clear(); |
930 model.SetCompositionText(composition); | 941 model.SetCompositionText(composition); |
931 EXPECT_STR_EQ("1234567890678", model.text()); | 942 EXPECT_STR_EQ("1234567890678", model.text()); |
| 943 EXPECT_TRUE(model.HasSelection()); |
| 944 #if !defined(OS_CHROMEOS) |
| 945 EXPECT_EQ(gfx::Range(10, 11), model.render_text()->selection()); |
| 946 EXPECT_EQ(11U, model.render_text()->cursor_position()); |
| 947 #else |
| 948 // See SelectRangeInCompositionText(). |
| 949 EXPECT_EQ(gfx::Range(11, 10), model.render_text()->selection()); |
| 950 EXPECT_EQ(10U, model.render_text()->cursor_position()); |
| 951 #endif |
932 | 952 |
933 model.InsertText(base::UTF8ToUTF16("-")); | 953 model.InsertText(base::UTF8ToUTF16("-")); |
934 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 954 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
935 composition_text_confirmed_or_cleared_ = false; | 955 composition_text_confirmed_or_cleared_ = false; |
936 EXPECT_STR_EQ("1234567890-", model.text()); | 956 EXPECT_STR_EQ("1234567890-", model.text()); |
937 EXPECT_FALSE(model.HasCompositionText()); | 957 EXPECT_FALSE(model.HasCompositionText()); |
938 EXPECT_FALSE(model.HasSelection()); | 958 EXPECT_FALSE(model.HasSelection()); |
939 | 959 |
940 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, | 960 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, |
941 gfx::SELECTION_RETAIN); | 961 gfx::SELECTION_RETAIN); |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 model.Backspace(true); | 1769 model.Backspace(true); |
1750 model.Backspace(true); | 1770 model.Backspace(true); |
1751 EXPECT_STR_EQ("aa", model.text()); | 1771 EXPECT_STR_EQ("aa", model.text()); |
1752 | 1772 |
1753 // Ensure yanking inserts the modified kill buffer text. | 1773 // Ensure yanking inserts the modified kill buffer text. |
1754 model.Yank(); | 1774 model.Yank(); |
1755 EXPECT_STR_EQ("aad", model.text()); | 1775 EXPECT_STR_EQ("aad", model.text()); |
1756 } | 1776 } |
1757 | 1777 |
1758 } // namespace views | 1778 } // namespace views |
OLD | NEW |