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); |
Yusuke Sato
2017/05/18 17:14:31
Changed to (1, 3) to make sure L898 has the preced
| |
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()); | |
Yusuke Sato
2017/05/18 17:14:31
Removed as this line looked just redundant.
| |
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 composition.selection = gfx::Range(0, 1); | |
Yusuke Sato
2017/05/18 17:14:31
Added a case where composition.selection exists bu
Shu Chen
2017/05/21 03:54:30
nit: pls put this as a code comment.
Yusuke Sato
2017/05/22 05:49:00
Done.
| |
939 composition.underlines.clear(); | |
930 model.SetCompositionText(composition); | 940 model.SetCompositionText(composition); |
931 EXPECT_STR_EQ("1234567890678", model.text()); | 941 EXPECT_STR_EQ("1234567890678", model.text()); |
942 EXPECT_TRUE(model.HasSelection()); | |
943 #if !defined(OS_CHROMEOS) | |
944 EXPECT_EQ(gfx::Range(10, 11), model.render_text()->selection()); | |
945 EXPECT_EQ(11U, model.render_text()->cursor_position()); | |
946 #else | |
947 // See SelectRangeInCompositionText(). | |
948 EXPECT_EQ(gfx::Range(11, 10), model.render_text()->selection()); | |
949 EXPECT_EQ(10U, model.render_text()->cursor_position()); | |
950 #endif | |
932 | 951 |
933 model.InsertText(base::UTF8ToUTF16("-")); | 952 model.InsertText(base::UTF8ToUTF16("-")); |
934 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 953 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
935 composition_text_confirmed_or_cleared_ = false; | 954 composition_text_confirmed_or_cleared_ = false; |
936 EXPECT_STR_EQ("1234567890-", model.text()); | 955 EXPECT_STR_EQ("1234567890-", model.text()); |
937 EXPECT_FALSE(model.HasCompositionText()); | 956 EXPECT_FALSE(model.HasCompositionText()); |
938 EXPECT_FALSE(model.HasSelection()); | 957 EXPECT_FALSE(model.HasSelection()); |
939 | 958 |
940 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, | 959 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, |
941 gfx::SELECTION_RETAIN); | 960 gfx::SELECTION_RETAIN); |
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1749 model.Backspace(true); | 1768 model.Backspace(true); |
1750 model.Backspace(true); | 1769 model.Backspace(true); |
1751 EXPECT_STR_EQ("aa", model.text()); | 1770 EXPECT_STR_EQ("aa", model.text()); |
1752 | 1771 |
1753 // Ensure yanking inserts the modified kill buffer text. | 1772 // Ensure yanking inserts the modified kill buffer text. |
1754 model.Yank(); | 1773 model.Yank(); |
1755 EXPECT_STR_EQ("aad", model.text()); | 1774 EXPECT_STR_EQ("aad", model.text()); |
1756 } | 1775 } |
1757 | 1776 |
1758 } // namespace views | 1777 } // namespace views |
OLD | NEW |