OLD | NEW |
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" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 bool composition_text_confirmed_or_cleared_; | 67 bool composition_text_confirmed_or_cleared_; |
68 | 68 |
69 private: | 69 private: |
70 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModelTest); | 70 DISALLOW_COPY_AND_ASSIGN(TextfieldViewsModelTest); |
71 }; | 71 }; |
72 | 72 |
73 TEST_F(TextfieldViewsModelTest, EditString) { | 73 TEST_F(TextfieldViewsModelTest, EditString) { |
74 TextfieldViewsModel model(NULL); | 74 TextfieldViewsModel model(NULL); |
75 // append two strings | 75 // append two strings |
76 model.Append(ASCIIToUTF16("HILL")); | 76 model.Append(ASCIIToUTF16("HILL")); |
77 EXPECT_STR_EQ("HILL", model.text()); | 77 EXPECT_STR_EQ("HILL", model.GetText()); |
78 model.Append(ASCIIToUTF16("WORLD")); | 78 model.Append(ASCIIToUTF16("WORLD")); |
79 EXPECT_STR_EQ("HILLWORLD", model.text()); | 79 EXPECT_STR_EQ("HILLWORLD", model.GetText()); |
80 | 80 |
81 // Insert "E" to make hello | 81 // Insert "E" to make hello |
82 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); | 82 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); |
83 model.InsertChar('E'); | 83 model.InsertChar('E'); |
84 EXPECT_STR_EQ("HEILLWORLD", model.text()); | 84 EXPECT_STR_EQ("HEILLWORLD", model.GetText()); |
85 // Replace "I" with "L" | 85 // Replace "I" with "L" |
86 model.ReplaceChar('L'); | 86 model.ReplaceChar('L'); |
87 EXPECT_STR_EQ("HELLLWORLD", model.text()); | 87 EXPECT_STR_EQ("HELLLWORLD", model.GetText()); |
88 model.ReplaceChar('L'); | 88 model.ReplaceChar('L'); |
89 model.ReplaceChar('O'); | 89 model.ReplaceChar('O'); |
90 EXPECT_STR_EQ("HELLOWORLD", model.text()); | 90 EXPECT_STR_EQ("HELLOWORLD", model.GetText()); |
91 | 91 |
92 // Delete 6th char "W", then delete 5th char O" | 92 // Delete 6th char "W", then delete 5th char O" |
93 EXPECT_EQ(5U, model.GetCursorPosition()); | 93 EXPECT_EQ(5U, model.GetCursorPosition()); |
94 EXPECT_TRUE(model.Delete()); | 94 EXPECT_TRUE(model.Delete()); |
95 EXPECT_STR_EQ("HELLOORLD", model.text()); | 95 EXPECT_STR_EQ("HELLOORLD", model.GetText()); |
96 EXPECT_TRUE(model.Backspace()); | 96 EXPECT_TRUE(model.Backspace()); |
97 EXPECT_EQ(4U, model.GetCursorPosition()); | 97 EXPECT_EQ(4U, model.GetCursorPosition()); |
98 EXPECT_STR_EQ("HELLORLD", model.text()); | 98 EXPECT_STR_EQ("HELLORLD", model.GetText()); |
99 | 99 |
100 // Move the cursor to start. backspace should fail. | 100 // Move the cursor to start. backspace should fail. |
101 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); | 101 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); |
102 EXPECT_FALSE(model.Backspace()); | 102 EXPECT_FALSE(model.Backspace()); |
103 EXPECT_STR_EQ("HELLORLD", model.text()); | 103 EXPECT_STR_EQ("HELLORLD", model.GetText()); |
104 // Move the cursor to the end. delete should fail. | 104 // Move the cursor to the end. delete should fail. |
105 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 105 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
106 EXPECT_FALSE(model.Delete()); | 106 EXPECT_FALSE(model.Delete()); |
107 EXPECT_STR_EQ("HELLORLD", model.text()); | 107 EXPECT_STR_EQ("HELLORLD", model.GetText()); |
108 // but backspace should work. | 108 // but backspace should work. |
109 EXPECT_TRUE(model.Backspace()); | 109 EXPECT_TRUE(model.Backspace()); |
110 EXPECT_STR_EQ("HELLORL", model.text()); | 110 EXPECT_STR_EQ("HELLORL", model.GetText()); |
111 | 111 |
112 MoveCursorTo(model, 5); | 112 MoveCursorTo(model, 5); |
113 model.ReplaceText(ASCIIToUTF16(" WOR")); | 113 model.ReplaceText(ASCIIToUTF16(" WOR")); |
114 EXPECT_STR_EQ("HELLO WORL", model.text()); | 114 EXPECT_STR_EQ("HELLO WORL", model.GetText()); |
115 } | 115 } |
116 | 116 |
117 TEST_F(TextfieldViewsModelTest, EditString_SimpleRTL) { | 117 TEST_F(TextfieldViewsModelTest, EditString_SimpleRTL) { |
118 TextfieldViewsModel model(NULL); | 118 TextfieldViewsModel model(NULL); |
119 // Append two strings. | 119 // Append two strings. |
120 model.Append(WideToUTF16(L"\x05d0\x05d1\x05d2")); | 120 model.Append(WideToUTF16(L"\x05d0\x05d1\x05d2")); |
121 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2"), model.text()); | 121 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2"), model.GetText()); |
122 model.Append(WideToUTF16(L"\x05e0\x05e1\x05e2")); | 122 model.Append(WideToUTF16(L"\x05e0\x05e1\x05e2")); |
123 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2\x05e0\x05e1\x05e2"), model.text()); | 123 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2\x05e0\x05e1\x05e2"), |
| 124 model.GetText()); |
124 | 125 |
125 // Insert 0x05f0. | 126 // Insert 0x05f0. |
126 MoveCursorTo(model, 1); | 127 MoveCursorTo(model, 1); |
127 model.InsertChar(0x05f0); | 128 model.InsertChar(0x05f0); |
128 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05d1\x05d2\x05e0\x05e1\x05e2"), | 129 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05d1\x05d2\x05e0\x05e1\x05e2"), |
129 model.text()); | 130 model.GetText()); |
130 | 131 |
131 // Replace "\x05d1" with "\x05f1". | 132 // Replace "\x05d1" with "\x05f1". |
132 model.ReplaceChar(0x05f1); | 133 model.ReplaceChar(0x05f1); |
133 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05d2\x05e0\x05e1\x05e2"), | 134 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05d2\x05e0\x05e1\x05e2"), |
134 model.text()); | 135 model.GetText()); |
135 | 136 |
136 // Delete and backspace. | 137 // Delete and backspace. |
137 EXPECT_EQ(3U, model.GetCursorPosition()); | 138 EXPECT_EQ(3U, model.GetCursorPosition()); |
138 EXPECT_TRUE(model.Delete()); | 139 EXPECT_TRUE(model.Delete()); |
139 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05e0\x05e1\x05e2"), model.text()); | 140 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05e0\x05e1\x05e2"), |
| 141 model.GetText()); |
140 EXPECT_TRUE(model.Backspace()); | 142 EXPECT_TRUE(model.Backspace()); |
141 EXPECT_EQ(2U, model.GetCursorPosition()); | 143 EXPECT_EQ(2U, model.GetCursorPosition()); |
142 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05e0\x05e1\x05e2"), model.text()); | 144 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05e0\x05e1\x05e2"), model.GetText()); |
143 } | 145 } |
144 | 146 |
145 TEST_F(TextfieldViewsModelTest, EditString_ComplexScript) { | 147 TEST_F(TextfieldViewsModelTest, EditString_ComplexScript) { |
146 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete | 148 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete |
147 // font support for some scripts - http://crbug.com/106450 | 149 // font support for some scripts - http://crbug.com/106450 |
148 bool on_windows_xp = false; | 150 bool on_windows_xp = false; |
149 #if defined(OS_WIN) | 151 #if defined(OS_WIN) |
150 on_windows_xp = base::win::GetVersion() < base::win::VERSION_VISTA; | 152 on_windows_xp = base::win::GetVersion() < base::win::VERSION_VISTA; |
151 #endif | 153 #endif |
152 | 154 |
153 TextfieldViewsModel model(NULL); | 155 TextfieldViewsModel model(NULL); |
154 | 156 |
155 // Append two Hindi strings. | 157 // Append two Hindi strings. |
156 model.Append(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); | 158 model.Append(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); |
157 EXPECT_EQ(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"), model.text()); | 159 EXPECT_EQ(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"), |
| 160 model.GetText()); |
158 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d")); | 161 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d")); |
159 EXPECT_EQ(WideToUTF16( | 162 EXPECT_EQ(WideToUTF16( |
160 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), model.text()); | 163 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), |
| 164 model.GetText()); |
161 | 165 |
162 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete | 166 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete |
163 // font support for some scripts - http://crbug.com/106450 | 167 // font support for some scripts - http://crbug.com/106450 |
164 if (!on_windows_xp) { | 168 if (!on_windows_xp) { |
165 // Check it is not able to place cursor in middle of a grapheme. | 169 // Check it is not able to place cursor in middle of a grapheme. |
166 MoveCursorTo(model, 1); | 170 MoveCursorTo(model, 1); |
167 EXPECT_EQ(0U, model.GetCursorPosition()); | 171 EXPECT_EQ(0U, model.GetCursorPosition()); |
168 | 172 |
169 MoveCursorTo(model, 2); | 173 MoveCursorTo(model, 2); |
170 EXPECT_EQ(2U, model.GetCursorPosition()); | 174 EXPECT_EQ(2U, model.GetCursorPosition()); |
171 model.InsertChar('a'); | 175 model.InsertChar('a'); |
172 EXPECT_EQ(WideToUTF16( | 176 EXPECT_EQ(WideToUTF16( |
173 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), | 177 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), |
174 model.text()); | 178 model.GetText()); |
175 | 179 |
176 // ReplaceChar will replace the whole grapheme. | 180 // ReplaceChar will replace the whole grapheme. |
177 model.ReplaceChar('b'); | 181 model.ReplaceChar('b'); |
178 // TODO(xji): temporarily disable in platform Win since the complex script | 182 // TODO(xji): temporarily disable in platform Win since the complex script |
179 // characters turned into empty square due to font regression. So, not able | 183 // characters turned into empty square due to font regression. So, not able |
180 // to test 2 characters belong to the same grapheme. | 184 // to test 2 characters belong to the same grapheme. |
181 #if defined(OS_LINUX) | 185 #if defined(OS_LINUX) |
182 EXPECT_EQ(WideToUTF16( | 186 EXPECT_EQ(WideToUTF16( |
183 L"\x0915\x093f\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), | 187 L"\x0915\x093f\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), |
184 model.text()); | 188 model.GetText()); |
185 #endif | 189 #endif |
186 EXPECT_EQ(4U, model.GetCursorPosition()); | 190 EXPECT_EQ(4U, model.GetCursorPosition()); |
187 } | 191 } |
188 | 192 |
189 // Delete should delete the whole grapheme. | 193 // Delete should delete the whole grapheme. |
190 MoveCursorTo(model, 0); | 194 MoveCursorTo(model, 0); |
191 // TODO(xji): temporarily disable in platform Win since the complex script | 195 // TODO(xji): temporarily disable in platform Win since the complex script |
192 // characters turned into empty square due to font regression. So, not able | 196 // characters turned into empty square due to font regression. So, not able |
193 // to test 2 characters belong to the same grapheme. | 197 // to test 2 characters belong to the same grapheme. |
194 #if defined(OS_LINUX) | 198 #if defined(OS_LINUX) |
195 EXPECT_TRUE(model.Delete()); | 199 EXPECT_TRUE(model.Delete()); |
196 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), | 200 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), |
197 model.text()); | 201 model.GetText()); |
198 MoveCursorTo(model, model.text().length()); | 202 MoveCursorTo(model, model.GetText().length()); |
199 EXPECT_EQ(model.text().length(), model.GetCursorPosition()); | 203 EXPECT_EQ(model.GetText().length(), model.GetCursorPosition()); |
200 EXPECT_TRUE(model.Backspace()); | 204 EXPECT_TRUE(model.Backspace()); |
201 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"), model.text()); | 205 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"), |
| 206 model.GetText()); |
202 #endif | 207 #endif |
203 | 208 |
204 // Test cursor position and deletion for Hindi Virama. | 209 // Test cursor position and deletion for Hindi Virama. |
205 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E")); | 210 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E")); |
206 MoveCursorTo(model, 0); | 211 MoveCursorTo(model, 0); |
207 EXPECT_EQ(0U, model.GetCursorPosition()); | 212 EXPECT_EQ(0U, model.GetCursorPosition()); |
208 | 213 |
209 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete | 214 // TODO(asvitkine): Disable tests that fail on XP bots due to lack of complete |
210 // font support for some scripts - http://crbug.com/106450 | 215 // font support for some scripts - http://crbug.com/106450 |
211 if (!on_windows_xp) { | 216 if (!on_windows_xp) { |
212 MoveCursorTo(model, 1); | 217 MoveCursorTo(model, 1); |
213 EXPECT_EQ(0U, model.GetCursorPosition()); | 218 EXPECT_EQ(0U, model.GetCursorPosition()); |
214 MoveCursorTo(model, 3); | 219 MoveCursorTo(model, 3); |
215 EXPECT_EQ(3U, model.GetCursorPosition()); | 220 EXPECT_EQ(3U, model.GetCursorPosition()); |
216 } | 221 } |
217 | 222 |
218 // TODO(asvitkine): Temporarily disable the following check on Windows. It | 223 // TODO(asvitkine): Temporarily disable the following check on Windows. It |
219 // seems Windows treats "\x0D38\x0D4D\x0D15" as a single grapheme. | 224 // seems Windows treats "\x0D38\x0D4D\x0D15" as a single grapheme. |
220 #if !defined(OS_WIN) | 225 #if !defined(OS_WIN) |
221 MoveCursorTo(model, 2); | 226 MoveCursorTo(model, 2); |
222 EXPECT_EQ(2U, model.GetCursorPosition()); | 227 EXPECT_EQ(2U, model.GetCursorPosition()); |
223 EXPECT_TRUE(model.Backspace()); | 228 EXPECT_TRUE(model.Backspace()); |
224 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.text()); | 229 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText()); |
225 #endif | 230 #endif |
226 | 231 |
227 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9")); | 232 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9")); |
228 MoveCursorTo(model, 0); | 233 MoveCursorTo(model, 0); |
229 EXPECT_TRUE(model.Delete()); | 234 EXPECT_TRUE(model.Delete()); |
230 EXPECT_TRUE(model.Delete()); | 235 EXPECT_TRUE(model.Delete()); |
231 EXPECT_TRUE(model.Delete()); | 236 EXPECT_TRUE(model.Delete()); |
232 EXPECT_TRUE(model.Delete()); | 237 EXPECT_TRUE(model.Delete()); |
233 EXPECT_EQ(WideToUTF16(L""), model.text()); | 238 EXPECT_EQ(WideToUTF16(L""), model.GetText()); |
234 | 239 |
235 // The first 2 characters are not strong directionality characters. | 240 // The first 2 characters are not strong directionality characters. |
236 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); | 241 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); |
237 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); | 242 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); |
238 EXPECT_TRUE(model.Backspace()); | 243 EXPECT_TRUE(model.Backspace()); |
239 EXPECT_EQ(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"), model.text()); | 244 EXPECT_EQ(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"), |
| 245 model.GetText()); |
240 } | 246 } |
241 | 247 |
242 TEST_F(TextfieldViewsModelTest, EmptyString) { | 248 TEST_F(TextfieldViewsModelTest, EmptyString) { |
243 TextfieldViewsModel model(NULL); | 249 TextfieldViewsModel model(NULL); |
244 EXPECT_EQ(base::string16(), model.text()); | 250 EXPECT_EQ(base::string16(), model.GetText()); |
245 EXPECT_EQ(base::string16(), model.GetSelectedText()); | 251 EXPECT_EQ(base::string16(), model.GetSelectedText()); |
246 | 252 |
247 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); | 253 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); |
248 EXPECT_EQ(0U, model.GetCursorPosition()); | 254 EXPECT_EQ(0U, model.GetCursorPosition()); |
249 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 255 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
250 EXPECT_EQ(0U, model.GetCursorPosition()); | 256 EXPECT_EQ(0U, model.GetCursorPosition()); |
251 | 257 |
252 EXPECT_EQ(base::string16(), model.GetSelectedText()); | 258 EXPECT_EQ(base::string16(), model.GetSelectedText()); |
253 | 259 |
254 EXPECT_FALSE(model.Delete()); | 260 EXPECT_FALSE(model.Delete()); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 EXPECT_EQ(WideToUTF16(L"a\x05E9" L"b"), model.GetSelectedText()); | 388 EXPECT_EQ(WideToUTF16(L"a\x05E9" L"b"), model.GetSelectedText()); |
383 } | 389 } |
384 | 390 |
385 TEST_F(TextfieldViewsModelTest, SelectionAndEdit) { | 391 TEST_F(TextfieldViewsModelTest, SelectionAndEdit) { |
386 TextfieldViewsModel model(NULL); | 392 TextfieldViewsModel model(NULL); |
387 model.Append(ASCIIToUTF16("HELLO")); | 393 model.Append(ASCIIToUTF16("HELLO")); |
388 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); | 394 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); |
389 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 395 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
390 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "EL" | 396 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "EL" |
391 EXPECT_TRUE(model.Backspace()); | 397 EXPECT_TRUE(model.Backspace()); |
392 EXPECT_STR_EQ("HLO", model.text()); | 398 EXPECT_STR_EQ("HLO", model.GetText()); |
393 | 399 |
394 model.Append(ASCIIToUTF16("ILL")); | 400 model.Append(ASCIIToUTF16("ILL")); |
395 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 401 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
396 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "LO" | 402 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "LO" |
397 EXPECT_TRUE(model.Delete()); | 403 EXPECT_TRUE(model.Delete()); |
398 EXPECT_STR_EQ("HILL", model.text()); | 404 EXPECT_STR_EQ("HILL", model.GetText()); |
399 EXPECT_EQ(1U, model.GetCursorPosition()); | 405 EXPECT_EQ(1U, model.GetCursorPosition()); |
400 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "I" | 406 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "I" |
401 model.InsertChar('E'); | 407 model.InsertChar('E'); |
402 EXPECT_STR_EQ("HELL", model.text()); | 408 EXPECT_STR_EQ("HELL", model.GetText()); |
403 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); | 409 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); |
404 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "H" | 410 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); // "H" |
405 model.ReplaceChar('B'); | 411 model.ReplaceChar('B'); |
406 EXPECT_STR_EQ("BELL", model.text()); | 412 EXPECT_STR_EQ("BELL", model.GetText()); |
407 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 413 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
408 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); | 414 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); |
409 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); // "ELL" | 415 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); // "ELL" |
410 model.ReplaceChar('E'); | 416 model.ReplaceChar('E'); |
411 EXPECT_STR_EQ("BEE", model.text()); | 417 EXPECT_STR_EQ("BEE", model.GetText()); |
412 } | 418 } |
413 | 419 |
414 TEST_F(TextfieldViewsModelTest, Word) { | 420 TEST_F(TextfieldViewsModelTest, Word) { |
415 TextfieldViewsModel model(NULL); | 421 TextfieldViewsModel model(NULL); |
416 model.Append( | 422 model.Append( |
417 ASCIIToUTF16("The answer to Life, the Universe, and Everything")); | 423 ASCIIToUTF16("The answer to Life, the Universe, and Everything")); |
418 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); | 424 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); |
419 EXPECT_EQ(3U, model.GetCursorPosition()); | 425 EXPECT_EQ(3U, model.GetCursorPosition()); |
420 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); | 426 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); |
421 EXPECT_EQ(10U, model.GetCursorPosition()); | 427 EXPECT_EQ(10U, model.GetCursorPosition()); |
(...skipping 26 matching lines...) Expand all Loading... |
448 EXPECT_STR_EQ("to Life", model.GetSelectedText()); | 454 EXPECT_STR_EQ("to Life", model.GetSelectedText()); |
449 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 455 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
450 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 456 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
451 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); // Now at start. | 457 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); // Now at start. |
452 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); | 458 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); |
453 // Should be safe to go to the previous word at the beginning. | 459 // Should be safe to go to the previous word at the beginning. |
454 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 460 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
455 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); | 461 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); |
456 model.ReplaceChar('4'); | 462 model.ReplaceChar('4'); |
457 EXPECT_EQ(base::string16(), model.GetSelectedText()); | 463 EXPECT_EQ(base::string16(), model.GetSelectedText()); |
458 EXPECT_STR_EQ("42", model.text()); | 464 EXPECT_STR_EQ("42", model.GetText()); |
459 } | 465 } |
460 | 466 |
461 TEST_F(TextfieldViewsModelTest, SetText) { | 467 TEST_F(TextfieldViewsModelTest, SetText) { |
462 TextfieldViewsModel model(NULL); | 468 TextfieldViewsModel model(NULL); |
463 model.Append(ASCIIToUTF16("HELLO")); | 469 model.Append(ASCIIToUTF16("HELLO")); |
464 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 470 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
465 model.SetText(ASCIIToUTF16("GOODBYE")); | 471 model.SetText(ASCIIToUTF16("GOODBYE")); |
466 EXPECT_STR_EQ("GOODBYE", model.text()); | 472 EXPECT_STR_EQ("GOODBYE", model.GetText()); |
467 // SetText move the cursor to the end of the new text. | 473 // SetText move the cursor to the end of the new text. |
468 EXPECT_EQ(7U, model.GetCursorPosition()); | 474 EXPECT_EQ(7U, model.GetCursorPosition()); |
469 model.SelectAll(false); | 475 model.SelectAll(false); |
470 EXPECT_STR_EQ("GOODBYE", model.GetSelectedText()); | 476 EXPECT_STR_EQ("GOODBYE", model.GetSelectedText()); |
471 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 477 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
472 EXPECT_EQ(7U, model.GetCursorPosition()); | 478 EXPECT_EQ(7U, model.GetCursorPosition()); |
473 | 479 |
474 model.SetText(ASCIIToUTF16("BYE")); | 480 model.SetText(ASCIIToUTF16("BYE")); |
475 // Setting shorter string moves the cursor to the end of the new string. | 481 // Setting shorter string moves the cursor to the end of the new string. |
476 EXPECT_EQ(3U, model.GetCursorPosition()); | 482 EXPECT_EQ(3U, model.GetCursorPosition()); |
(...skipping 10 matching lines...) Expand all Loading... |
487 | 493 |
488 base::string16 clipboard_text; | 494 base::string16 clipboard_text; |
489 TextfieldViewsModel model(NULL); | 495 TextfieldViewsModel model(NULL); |
490 model.Append(ASCIIToUTF16("HELLO WORLD")); | 496 model.Append(ASCIIToUTF16("HELLO WORLD")); |
491 | 497 |
492 // Cut with an empty selection should do nothing. | 498 // Cut with an empty selection should do nothing. |
493 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 499 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
494 EXPECT_FALSE(model.Cut()); | 500 EXPECT_FALSE(model.Cut()); |
495 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); | 501 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); |
496 EXPECT_EQ(initial_clipboard_text, clipboard_text); | 502 EXPECT_EQ(initial_clipboard_text, clipboard_text); |
497 EXPECT_STR_EQ("HELLO WORLD", model.text()); | 503 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); |
498 EXPECT_EQ(11U, model.GetCursorPosition()); | 504 EXPECT_EQ(11U, model.GetCursorPosition()); |
499 | 505 |
500 // Copy with an empty selection should do nothing. | 506 // Copy with an empty selection should do nothing. |
501 model.Copy(); | 507 model.Copy(); |
502 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); | 508 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); |
503 EXPECT_EQ(initial_clipboard_text, clipboard_text); | 509 EXPECT_EQ(initial_clipboard_text, clipboard_text); |
504 EXPECT_STR_EQ("HELLO WORLD", model.text()); | 510 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); |
505 EXPECT_EQ(11U, model.GetCursorPosition()); | 511 EXPECT_EQ(11U, model.GetCursorPosition()); |
506 | 512 |
507 // Cut on obscured (password) text should do nothing. | 513 // Cut on obscured (password) text should do nothing. |
508 model.render_text()->SetObscured(true); | 514 model.render_text()->SetObscured(true); |
509 model.SelectAll(false); | 515 model.SelectAll(false); |
510 EXPECT_FALSE(model.Cut()); | 516 EXPECT_FALSE(model.Cut()); |
511 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); | 517 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); |
512 EXPECT_EQ(initial_clipboard_text, clipboard_text); | 518 EXPECT_EQ(initial_clipboard_text, clipboard_text); |
513 EXPECT_STR_EQ("HELLO WORLD", model.text()); | 519 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); |
514 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText()); | 520 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText()); |
515 | 521 |
516 // Copy on obscured text should do nothing. | 522 // Copy on obscured text should do nothing. |
517 model.SelectAll(false); | 523 model.SelectAll(false); |
518 EXPECT_FALSE(model.Copy()); | 524 EXPECT_FALSE(model.Copy()); |
519 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); | 525 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); |
520 EXPECT_EQ(initial_clipboard_text, clipboard_text); | 526 EXPECT_EQ(initial_clipboard_text, clipboard_text); |
521 EXPECT_STR_EQ("HELLO WORLD", model.text()); | 527 EXPECT_STR_EQ("HELLO WORLD", model.GetText()); |
522 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText()); | 528 EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText()); |
523 | 529 |
524 // Cut with non-empty selection. | 530 // Cut with non-empty selection. |
525 model.render_text()->SetObscured(false); | 531 model.render_text()->SetObscured(false); |
526 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 532 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
527 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 533 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
528 EXPECT_TRUE(model.Cut()); | 534 EXPECT_TRUE(model.Cut()); |
529 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); | 535 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); |
530 EXPECT_STR_EQ("WORLD", clipboard_text); | 536 EXPECT_STR_EQ("WORLD", clipboard_text); |
531 EXPECT_STR_EQ("HELLO ", model.text()); | 537 EXPECT_STR_EQ("HELLO ", model.GetText()); |
532 EXPECT_EQ(6U, model.GetCursorPosition()); | 538 EXPECT_EQ(6U, model.GetCursorPosition()); |
533 | 539 |
534 // Copy with non-empty selection. | 540 // Copy with non-empty selection. |
535 model.SelectAll(false); | 541 model.SelectAll(false); |
536 EXPECT_TRUE(model.Copy()); | 542 EXPECT_TRUE(model.Copy()); |
537 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); | 543 clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &clipboard_text); |
538 EXPECT_STR_EQ("HELLO ", clipboard_text); | 544 EXPECT_STR_EQ("HELLO ", clipboard_text); |
539 EXPECT_STR_EQ("HELLO ", model.text()); | 545 EXPECT_STR_EQ("HELLO ", model.GetText()); |
540 EXPECT_EQ(6U, model.GetCursorPosition()); | 546 EXPECT_EQ(6U, model.GetCursorPosition()); |
541 | 547 |
542 // Test that paste works regardless of the obscured bit. | 548 // Test that paste works regardless of the obscured bit. |
543 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 549 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
544 EXPECT_TRUE(model.Paste()); | 550 EXPECT_TRUE(model.Paste()); |
545 EXPECT_STR_EQ("HELLO HELLO ", model.text()); | 551 EXPECT_STR_EQ("HELLO HELLO ", model.GetText()); |
546 EXPECT_EQ(12U, model.GetCursorPosition()); | 552 EXPECT_EQ(12U, model.GetCursorPosition()); |
547 model.render_text()->SetObscured(true); | 553 model.render_text()->SetObscured(true); |
548 EXPECT_TRUE(model.Paste()); | 554 EXPECT_TRUE(model.Paste()); |
549 EXPECT_STR_EQ("HELLO HELLO HELLO ", model.text()); | 555 EXPECT_STR_EQ("HELLO HELLO HELLO ", model.GetText()); |
550 EXPECT_EQ(18U, model.GetCursorPosition()); | 556 EXPECT_EQ(18U, model.GetCursorPosition()); |
551 } | 557 } |
552 | 558 |
553 static void SelectWordTestVerifier( | 559 static void SelectWordTestVerifier( |
554 const TextfieldViewsModel& model, | 560 const TextfieldViewsModel& model, |
555 const base::string16 &expected_selected_string, | 561 const base::string16 &expected_selected_string, |
556 size_t expected_cursor_pos) { | 562 size_t expected_cursor_pos) { |
557 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); | 563 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); |
558 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); | 564 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); |
559 } | 565 } |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 composition.underlines.clear(); | 849 composition.underlines.clear(); |
844 composition.underlines.push_back(ui::CompositionUnderline(0, 2, 0, true)); | 850 composition.underlines.push_back(ui::CompositionUnderline(0, 2, 0, true)); |
845 composition.underlines.push_back(ui::CompositionUnderline(2, 3, 0, false)); | 851 composition.underlines.push_back(ui::CompositionUnderline(2, 3, 0, false)); |
846 model.SetCompositionText(composition); | 852 model.SetCompositionText(composition); |
847 EXPECT_TRUE(model.HasCompositionText()); | 853 EXPECT_TRUE(model.HasCompositionText()); |
848 EXPECT_TRUE(model.HasSelection()); | 854 EXPECT_TRUE(model.HasSelection()); |
849 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection()); | 855 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection()); |
850 | 856 |
851 model.GetTextRange(&range); | 857 model.GetTextRange(&range); |
852 EXPECT_EQ(10U, range.end()); | 858 EXPECT_EQ(10U, range.end()); |
853 EXPECT_STR_EQ("1234567890", model.text()); | 859 EXPECT_STR_EQ("1234567890", model.GetText()); |
854 | 860 |
855 model.GetCompositionTextRange(&range); | 861 model.GetCompositionTextRange(&range); |
856 EXPECT_EQ(gfx::Range(5, 8), range); | 862 EXPECT_EQ(gfx::Range(5, 8), range); |
857 // composition text | 863 // composition text |
858 EXPECT_STR_EQ("456", model.GetTextFromRange(gfx::Range(3, 6))); | 864 EXPECT_STR_EQ("456", model.GetTextFromRange(gfx::Range(3, 6))); |
859 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection()); | 865 EXPECT_EQ(gfx::Range(5, 7), model.render_text()->selection()); |
860 | 866 |
861 EXPECT_FALSE(composition_text_confirmed_or_cleared_); | 867 EXPECT_FALSE(composition_text_confirmed_or_cleared_); |
862 model.CancelCompositionText(); | 868 model.CancelCompositionText(); |
863 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 869 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
864 composition_text_confirmed_or_cleared_ = false; | 870 composition_text_confirmed_or_cleared_ = false; |
865 EXPECT_FALSE(model.HasCompositionText()); | 871 EXPECT_FALSE(model.HasCompositionText()); |
866 EXPECT_FALSE(model.HasSelection()); | 872 EXPECT_FALSE(model.HasSelection()); |
867 EXPECT_EQ(5U, model.GetCursorPosition()); | 873 EXPECT_EQ(5U, model.GetCursorPosition()); |
868 | 874 |
869 model.SetCompositionText(composition); | 875 model.SetCompositionText(composition); |
870 EXPECT_STR_EQ("1234567890", model.text()); | 876 EXPECT_STR_EQ("1234567890", model.GetText()); |
871 EXPECT_TRUE(model.SetText(ASCIIToUTF16("1234567890"))); | 877 EXPECT_TRUE(model.SetText(ASCIIToUTF16("1234567890"))); |
872 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 878 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
873 composition_text_confirmed_or_cleared_ = false; | 879 composition_text_confirmed_or_cleared_ = false; |
874 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 880 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
875 | 881 |
876 model.SetCompositionText(composition); | 882 model.SetCompositionText(composition); |
877 EXPECT_STR_EQ("1234567890678", model.text()); | 883 EXPECT_STR_EQ("1234567890678", model.GetText()); |
878 | 884 |
879 model.InsertText(UTF8ToUTF16("-")); | 885 model.InsertText(UTF8ToUTF16("-")); |
880 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 886 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
881 composition_text_confirmed_or_cleared_ = false; | 887 composition_text_confirmed_or_cleared_ = false; |
882 EXPECT_STR_EQ("1234567890-", model.text()); | 888 EXPECT_STR_EQ("1234567890-", model.GetText()); |
883 EXPECT_FALSE(model.HasCompositionText()); | 889 EXPECT_FALSE(model.HasCompositionText()); |
884 EXPECT_FALSE(model.HasSelection()); | 890 EXPECT_FALSE(model.HasSelection()); |
885 | 891 |
886 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); | 892 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); |
887 EXPECT_STR_EQ("-", model.GetSelectedText()); | 893 EXPECT_STR_EQ("-", model.GetSelectedText()); |
888 model.SetCompositionText(composition); | 894 model.SetCompositionText(composition); |
889 EXPECT_STR_EQ("1234567890678", model.text()); | 895 EXPECT_STR_EQ("1234567890678", model.GetText()); |
890 | 896 |
891 model.ReplaceText(UTF8ToUTF16("-")); | 897 model.ReplaceText(UTF8ToUTF16("-")); |
892 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 898 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
893 composition_text_confirmed_or_cleared_ = false; | 899 composition_text_confirmed_or_cleared_ = false; |
894 EXPECT_STR_EQ("1234567890-", model.text()); | 900 EXPECT_STR_EQ("1234567890-", model.GetText()); |
895 EXPECT_FALSE(model.HasCompositionText()); | 901 EXPECT_FALSE(model.HasCompositionText()); |
896 EXPECT_FALSE(model.HasSelection()); | 902 EXPECT_FALSE(model.HasSelection()); |
897 | 903 |
898 model.SetCompositionText(composition); | 904 model.SetCompositionText(composition); |
899 model.Append(UTF8ToUTF16("-")); | 905 model.Append(UTF8ToUTF16("-")); |
900 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 906 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
901 composition_text_confirmed_or_cleared_ = false; | 907 composition_text_confirmed_or_cleared_ = false; |
902 EXPECT_STR_EQ("1234567890-678-", model.text()); | 908 EXPECT_STR_EQ("1234567890-678-", model.GetText()); |
903 | 909 |
904 model.SetCompositionText(composition); | 910 model.SetCompositionText(composition); |
905 model.Delete(); | 911 model.Delete(); |
906 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 912 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
907 composition_text_confirmed_or_cleared_ = false; | 913 composition_text_confirmed_or_cleared_ = false; |
908 EXPECT_STR_EQ("1234567890-678-", model.text()); | 914 EXPECT_STR_EQ("1234567890-678-", model.GetText()); |
909 | 915 |
910 model.SetCompositionText(composition); | 916 model.SetCompositionText(composition); |
911 model.Backspace(); | 917 model.Backspace(); |
912 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 918 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
913 composition_text_confirmed_or_cleared_ = false; | 919 composition_text_confirmed_or_cleared_ = false; |
914 EXPECT_STR_EQ("1234567890-678-", model.text()); | 920 EXPECT_STR_EQ("1234567890-678-", model.GetText()); |
915 | 921 |
916 model.SetText(base::string16()); | 922 model.SetText(base::string16()); |
917 model.SetCompositionText(composition); | 923 model.SetCompositionText(composition); |
918 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); | 924 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); |
919 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 925 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
920 composition_text_confirmed_or_cleared_ = false; | 926 composition_text_confirmed_or_cleared_ = false; |
921 EXPECT_STR_EQ("678", model.text()); | 927 EXPECT_STR_EQ("678", model.GetText()); |
922 EXPECT_EQ(2U, model.GetCursorPosition()); | 928 EXPECT_EQ(2U, model.GetCursorPosition()); |
923 | 929 |
924 model.SetCompositionText(composition); | 930 model.SetCompositionText(composition); |
925 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); | 931 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); |
926 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 932 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
927 composition_text_confirmed_or_cleared_ = false; | 933 composition_text_confirmed_or_cleared_ = false; |
928 EXPECT_STR_EQ("676788", model.text()); | 934 EXPECT_STR_EQ("676788", model.GetText()); |
929 EXPECT_EQ(6U, model.GetCursorPosition()); | 935 EXPECT_EQ(6U, model.GetCursorPosition()); |
930 | 936 |
931 model.SetCompositionText(composition); | 937 model.SetCompositionText(composition); |
932 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false); | 938 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, false); |
933 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 939 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
934 composition_text_confirmed_or_cleared_ = false; | 940 composition_text_confirmed_or_cleared_ = false; |
935 EXPECT_STR_EQ("676788678", model.text()); | 941 EXPECT_STR_EQ("676788678", model.GetText()); |
936 | 942 |
937 model.SetText(base::string16()); | 943 model.SetText(base::string16()); |
938 model.SetCompositionText(composition); | 944 model.SetCompositionText(composition); |
939 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); | 945 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, false); |
940 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 946 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
941 composition_text_confirmed_or_cleared_ = false; | 947 composition_text_confirmed_or_cleared_ = false; |
942 | 948 |
943 model.SetCompositionText(composition); | 949 model.SetCompositionText(composition); |
944 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); | 950 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); |
945 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 951 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
946 composition_text_confirmed_or_cleared_ = false; | 952 composition_text_confirmed_or_cleared_ = false; |
947 EXPECT_STR_EQ("678678", model.text()); | 953 EXPECT_STR_EQ("678678", model.GetText()); |
948 | 954 |
949 model.SetCompositionText(composition); | 955 model.SetCompositionText(composition); |
950 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 956 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
951 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 957 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
952 composition_text_confirmed_or_cleared_ = false; | 958 composition_text_confirmed_or_cleared_ = false; |
953 EXPECT_STR_EQ("678", model.text()); | 959 EXPECT_STR_EQ("678", model.GetText()); |
954 | 960 |
955 model.SetCompositionText(composition); | 961 model.SetCompositionText(composition); |
956 gfx::SelectionModel sel( | 962 gfx::SelectionModel sel( |
957 gfx::Range(model.render_text()->selection().start(), 0), | 963 gfx::Range(model.render_text()->selection().start(), 0), |
958 gfx::CURSOR_FORWARD); | 964 gfx::CURSOR_FORWARD); |
959 model.MoveCursorTo(sel); | 965 model.MoveCursorTo(sel); |
960 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 966 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
961 composition_text_confirmed_or_cleared_ = false; | 967 composition_text_confirmed_or_cleared_ = false; |
962 EXPECT_STR_EQ("678678", model.text()); | 968 EXPECT_STR_EQ("678678", model.GetText()); |
963 | 969 |
964 model.SetCompositionText(composition); | 970 model.SetCompositionText(composition); |
965 model.SelectRange(gfx::Range(0, 3)); | 971 model.SelectRange(gfx::Range(0, 3)); |
966 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 972 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
967 composition_text_confirmed_or_cleared_ = false; | 973 composition_text_confirmed_or_cleared_ = false; |
968 EXPECT_STR_EQ("678", model.text()); | 974 EXPECT_STR_EQ("678", model.GetText()); |
969 | 975 |
970 model.SetCompositionText(composition); | 976 model.SetCompositionText(composition); |
971 model.SelectAll(false); | 977 model.SelectAll(false); |
972 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 978 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
973 composition_text_confirmed_or_cleared_ = false; | 979 composition_text_confirmed_or_cleared_ = false; |
974 EXPECT_STR_EQ("678", model.text()); | 980 EXPECT_STR_EQ("678", model.GetText()); |
975 | 981 |
976 model.SetCompositionText(composition); | 982 model.SetCompositionText(composition); |
977 model.SelectWord(); | 983 model.SelectWord(); |
978 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 984 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
979 composition_text_confirmed_or_cleared_ = false; | 985 composition_text_confirmed_or_cleared_ = false; |
980 EXPECT_STR_EQ("678", model.text()); | 986 EXPECT_STR_EQ("678", model.GetText()); |
981 | 987 |
982 model.SetCompositionText(composition); | 988 model.SetCompositionText(composition); |
983 model.ClearSelection(); | 989 model.ClearSelection(); |
984 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 990 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
985 composition_text_confirmed_or_cleared_ = false; | 991 composition_text_confirmed_or_cleared_ = false; |
986 | 992 |
987 model.SetCompositionText(composition); | 993 model.SetCompositionText(composition); |
988 EXPECT_FALSE(model.Cut()); | 994 EXPECT_FALSE(model.Cut()); |
989 EXPECT_FALSE(composition_text_confirmed_or_cleared_); | 995 EXPECT_FALSE(composition_text_confirmed_or_cleared_); |
990 } | 996 } |
991 | 997 |
992 TEST_F(TextfieldViewsModelTest, UndoRedo_BasicTest) { | 998 TEST_F(TextfieldViewsModelTest, UndoRedo_BasicTest) { |
993 TextfieldViewsModel model(NULL); | 999 TextfieldViewsModel model(NULL); |
994 model.InsertChar('a'); | 1000 model.InsertChar('a'); |
995 EXPECT_FALSE(model.Redo()); // nothing to redo | 1001 EXPECT_FALSE(model.Redo()); // nothing to redo |
996 EXPECT_TRUE(model.Undo()); | 1002 EXPECT_TRUE(model.Undo()); |
997 EXPECT_STR_EQ("", model.text()); | 1003 EXPECT_STR_EQ("", model.GetText()); |
998 EXPECT_TRUE(model.Redo()); | 1004 EXPECT_TRUE(model.Redo()); |
999 EXPECT_STR_EQ("a", model.text()); | 1005 EXPECT_STR_EQ("a", model.GetText()); |
1000 | 1006 |
1001 // Continuous inserts are treated as one edit. | 1007 // Continuous inserts are treated as one edit. |
1002 model.InsertChar('b'); | 1008 model.InsertChar('b'); |
1003 model.InsertChar('c'); | 1009 model.InsertChar('c'); |
1004 EXPECT_STR_EQ("abc", model.text()); | 1010 EXPECT_STR_EQ("abc", model.GetText()); |
1005 EXPECT_TRUE(model.Undo()); | 1011 EXPECT_TRUE(model.Undo()); |
1006 EXPECT_STR_EQ("a", model.text()); | 1012 EXPECT_STR_EQ("a", model.GetText()); |
1007 EXPECT_EQ(1U, model.GetCursorPosition()); | 1013 EXPECT_EQ(1U, model.GetCursorPosition()); |
1008 EXPECT_TRUE(model.Undo()); | 1014 EXPECT_TRUE(model.Undo()); |
1009 EXPECT_STR_EQ("", model.text()); | 1015 EXPECT_STR_EQ("", model.GetText()); |
1010 EXPECT_EQ(0U, model.GetCursorPosition()); | 1016 EXPECT_EQ(0U, model.GetCursorPosition()); |
1011 | 1017 |
1012 // Undoing further shouldn't change the text. | 1018 // Undoing further shouldn't change the text. |
1013 EXPECT_FALSE(model.Undo()); | 1019 EXPECT_FALSE(model.Undo()); |
1014 EXPECT_STR_EQ("", model.text()); | 1020 EXPECT_STR_EQ("", model.GetText()); |
1015 EXPECT_FALSE(model.Undo()); | 1021 EXPECT_FALSE(model.Undo()); |
1016 EXPECT_STR_EQ("", model.text()); | 1022 EXPECT_STR_EQ("", model.GetText()); |
1017 EXPECT_EQ(0U, model.GetCursorPosition()); | 1023 EXPECT_EQ(0U, model.GetCursorPosition()); |
1018 | 1024 |
1019 // Redoing to the latest text. | 1025 // Redoing to the latest text. |
1020 EXPECT_TRUE(model.Redo()); | 1026 EXPECT_TRUE(model.Redo()); |
1021 EXPECT_STR_EQ("a", model.text()); | 1027 EXPECT_STR_EQ("a", model.GetText()); |
1022 EXPECT_EQ(1U, model.GetCursorPosition()); | 1028 EXPECT_EQ(1U, model.GetCursorPosition()); |
1023 EXPECT_TRUE(model.Redo()); | 1029 EXPECT_TRUE(model.Redo()); |
1024 EXPECT_STR_EQ("abc", model.text()); | 1030 EXPECT_STR_EQ("abc", model.GetText()); |
1025 EXPECT_EQ(3U, model.GetCursorPosition()); | 1031 EXPECT_EQ(3U, model.GetCursorPosition()); |
1026 | 1032 |
1027 // Backspace =============================== | 1033 // Backspace =============================== |
1028 EXPECT_TRUE(model.Backspace()); | 1034 EXPECT_TRUE(model.Backspace()); |
1029 EXPECT_STR_EQ("ab", model.text()); | 1035 EXPECT_STR_EQ("ab", model.GetText()); |
1030 EXPECT_TRUE(model.Undo()); | 1036 EXPECT_TRUE(model.Undo()); |
1031 EXPECT_STR_EQ("abc", model.text()); | 1037 EXPECT_STR_EQ("abc", model.GetText()); |
1032 EXPECT_EQ(3U, model.GetCursorPosition()); | 1038 EXPECT_EQ(3U, model.GetCursorPosition()); |
1033 EXPECT_TRUE(model.Redo()); | 1039 EXPECT_TRUE(model.Redo()); |
1034 EXPECT_STR_EQ("ab", model.text()); | 1040 EXPECT_STR_EQ("ab", model.GetText()); |
1035 EXPECT_EQ(2U, model.GetCursorPosition()); | 1041 EXPECT_EQ(2U, model.GetCursorPosition()); |
1036 // Continous backspaces are treated as one edit. | 1042 // Continous backspaces are treated as one edit. |
1037 EXPECT_TRUE(model.Backspace()); | 1043 EXPECT_TRUE(model.Backspace()); |
1038 EXPECT_TRUE(model.Backspace()); | 1044 EXPECT_TRUE(model.Backspace()); |
1039 EXPECT_STR_EQ("", model.text()); | 1045 EXPECT_STR_EQ("", model.GetText()); |
1040 // Extra backspace shouldn't affect the history. | 1046 // Extra backspace shouldn't affect the history. |
1041 EXPECT_FALSE(model.Backspace()); | 1047 EXPECT_FALSE(model.Backspace()); |
1042 EXPECT_TRUE(model.Undo()); | 1048 EXPECT_TRUE(model.Undo()); |
1043 EXPECT_STR_EQ("ab", model.text()); | 1049 EXPECT_STR_EQ("ab", model.GetText()); |
1044 EXPECT_EQ(2U, model.GetCursorPosition()); | 1050 EXPECT_EQ(2U, model.GetCursorPosition()); |
1045 EXPECT_TRUE(model.Undo()); | 1051 EXPECT_TRUE(model.Undo()); |
1046 EXPECT_STR_EQ("abc", model.text()); | 1052 EXPECT_STR_EQ("abc", model.GetText()); |
1047 EXPECT_EQ(3U, model.GetCursorPosition()); | 1053 EXPECT_EQ(3U, model.GetCursorPosition()); |
1048 EXPECT_TRUE(model.Undo()); | 1054 EXPECT_TRUE(model.Undo()); |
1049 EXPECT_STR_EQ("a", model.text()); | 1055 EXPECT_STR_EQ("a", model.GetText()); |
1050 EXPECT_EQ(1U, model.GetCursorPosition()); | 1056 EXPECT_EQ(1U, model.GetCursorPosition()); |
1051 | 1057 |
1052 // Clear history | 1058 // Clear history |
1053 model.ClearEditHistory(); | 1059 model.ClearEditHistory(); |
1054 EXPECT_FALSE(model.Undo()); | 1060 EXPECT_FALSE(model.Undo()); |
1055 EXPECT_FALSE(model.Redo()); | 1061 EXPECT_FALSE(model.Redo()); |
1056 EXPECT_STR_EQ("a", model.text()); | 1062 EXPECT_STR_EQ("a", model.GetText()); |
1057 EXPECT_EQ(1U, model.GetCursorPosition()); | 1063 EXPECT_EQ(1U, model.GetCursorPosition()); |
1058 | 1064 |
1059 // Delete =============================== | 1065 // Delete =============================== |
1060 model.SetText(ASCIIToUTF16("ABCDE")); | 1066 model.SetText(ASCIIToUTF16("ABCDE")); |
1061 model.ClearEditHistory(); | 1067 model.ClearEditHistory(); |
1062 MoveCursorTo(model, 2); | 1068 MoveCursorTo(model, 2); |
1063 EXPECT_TRUE(model.Delete()); | 1069 EXPECT_TRUE(model.Delete()); |
1064 EXPECT_STR_EQ("ABDE", model.text()); | 1070 EXPECT_STR_EQ("ABDE", model.GetText()); |
1065 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); | 1071 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); |
1066 EXPECT_TRUE(model.Delete()); | 1072 EXPECT_TRUE(model.Delete()); |
1067 EXPECT_STR_EQ("BDE", model.text()); | 1073 EXPECT_STR_EQ("BDE", model.GetText()); |
1068 EXPECT_TRUE(model.Undo()); | 1074 EXPECT_TRUE(model.Undo()); |
1069 EXPECT_STR_EQ("ABDE", model.text()); | 1075 EXPECT_STR_EQ("ABDE", model.GetText()); |
1070 EXPECT_EQ(0U, model.GetCursorPosition()); | 1076 EXPECT_EQ(0U, model.GetCursorPosition()); |
1071 EXPECT_TRUE(model.Undo()); | 1077 EXPECT_TRUE(model.Undo()); |
1072 EXPECT_STR_EQ("ABCDE", model.text()); | 1078 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1073 EXPECT_EQ(2U, model.GetCursorPosition()); | 1079 EXPECT_EQ(2U, model.GetCursorPosition()); |
1074 EXPECT_TRUE(model.Redo()); | 1080 EXPECT_TRUE(model.Redo()); |
1075 EXPECT_STR_EQ("ABDE", model.text()); | 1081 EXPECT_STR_EQ("ABDE", model.GetText()); |
1076 EXPECT_EQ(2U, model.GetCursorPosition()); | 1082 EXPECT_EQ(2U, model.GetCursorPosition()); |
1077 // Continous deletes are treated as one edit. | 1083 // Continous deletes are treated as one edit. |
1078 EXPECT_TRUE(model.Delete()); | 1084 EXPECT_TRUE(model.Delete()); |
1079 EXPECT_TRUE(model.Delete()); | 1085 EXPECT_TRUE(model.Delete()); |
1080 EXPECT_STR_EQ("AB", model.text()); | 1086 EXPECT_STR_EQ("AB", model.GetText()); |
1081 EXPECT_TRUE(model.Undo()); | 1087 EXPECT_TRUE(model.Undo()); |
1082 EXPECT_STR_EQ("ABDE", model.text()); | 1088 EXPECT_STR_EQ("ABDE", model.GetText()); |
1083 EXPECT_EQ(2U, model.GetCursorPosition()); | 1089 EXPECT_EQ(2U, model.GetCursorPosition()); |
1084 EXPECT_TRUE(model.Redo()); | 1090 EXPECT_TRUE(model.Redo()); |
1085 EXPECT_STR_EQ("AB", model.text()); | 1091 EXPECT_STR_EQ("AB", model.GetText()); |
1086 EXPECT_EQ(2U, model.GetCursorPosition()); | 1092 EXPECT_EQ(2U, model.GetCursorPosition()); |
1087 } | 1093 } |
1088 | 1094 |
1089 TEST_F(TextfieldViewsModelTest, UndoRedo_SetText) { | 1095 TEST_F(TextfieldViewsModelTest, UndoRedo_SetText) { |
1090 // This is to test the undo/redo behavior of omnibox. | 1096 // This is to test the undo/redo behavior of omnibox. |
1091 TextfieldViewsModel model(NULL); | 1097 TextfieldViewsModel model(NULL); |
1092 model.InsertChar('w'); | 1098 model.InsertChar('w'); |
1093 EXPECT_STR_EQ("w", model.text()); | 1099 EXPECT_STR_EQ("w", model.GetText()); |
1094 EXPECT_EQ(1U, model.GetCursorPosition()); | 1100 EXPECT_EQ(1U, model.GetCursorPosition()); |
1095 model.SetText(ASCIIToUTF16("www.google.com")); | 1101 model.SetText(ASCIIToUTF16("www.google.com")); |
1096 EXPECT_EQ(14U, model.GetCursorPosition()); | 1102 EXPECT_EQ(14U, model.GetCursorPosition()); |
1097 EXPECT_STR_EQ("www.google.com", model.text()); | 1103 EXPECT_STR_EQ("www.google.com", model.GetText()); |
1098 model.SelectRange(gfx::Range(14, 1)); | 1104 model.SelectRange(gfx::Range(14, 1)); |
1099 model.InsertChar('w'); | 1105 model.InsertChar('w'); |
1100 EXPECT_STR_EQ("ww", model.text()); | 1106 EXPECT_STR_EQ("ww", model.GetText()); |
1101 model.SetText(ASCIIToUTF16("www.google.com")); | 1107 model.SetText(ASCIIToUTF16("www.google.com")); |
1102 model.SelectRange(gfx::Range(14, 2)); | 1108 model.SelectRange(gfx::Range(14, 2)); |
1103 model.InsertChar('w'); | 1109 model.InsertChar('w'); |
1104 EXPECT_STR_EQ("www", model.text()); | 1110 EXPECT_STR_EQ("www", model.GetText()); |
1105 model.SetText(ASCIIToUTF16("www.google.com")); | 1111 model.SetText(ASCIIToUTF16("www.google.com")); |
1106 model.SelectRange(gfx::Range(14, 3)); | 1112 model.SelectRange(gfx::Range(14, 3)); |
1107 model.InsertChar('.'); | 1113 model.InsertChar('.'); |
1108 EXPECT_STR_EQ("www.", model.text()); | 1114 EXPECT_STR_EQ("www.", model.GetText()); |
1109 model.SetText(ASCIIToUTF16("www.google.com")); | 1115 model.SetText(ASCIIToUTF16("www.google.com")); |
1110 model.SelectRange(gfx::Range(14, 4)); | 1116 model.SelectRange(gfx::Range(14, 4)); |
1111 model.InsertChar('y'); | 1117 model.InsertChar('y'); |
1112 EXPECT_STR_EQ("www.y", model.text()); | 1118 EXPECT_STR_EQ("www.y", model.GetText()); |
1113 model.SetText(ASCIIToUTF16("www.youtube.com")); | 1119 model.SetText(ASCIIToUTF16("www.youtube.com")); |
1114 EXPECT_STR_EQ("www.youtube.com", model.text()); | 1120 EXPECT_STR_EQ("www.youtube.com", model.GetText()); |
1115 EXPECT_EQ(15U, model.GetCursorPosition()); | 1121 EXPECT_EQ(15U, model.GetCursorPosition()); |
1116 | 1122 |
1117 EXPECT_TRUE(model.Undo()); | 1123 EXPECT_TRUE(model.Undo()); |
1118 EXPECT_STR_EQ("www.google.com", model.text()); | 1124 EXPECT_STR_EQ("www.google.com", model.GetText()); |
1119 EXPECT_EQ(4U, model.GetCursorPosition()); | 1125 EXPECT_EQ(4U, model.GetCursorPosition()); |
1120 EXPECT_TRUE(model.Undo()); | 1126 EXPECT_TRUE(model.Undo()); |
1121 EXPECT_STR_EQ("www.google.com", model.text()); | 1127 EXPECT_STR_EQ("www.google.com", model.GetText()); |
1122 EXPECT_EQ(3U, model.GetCursorPosition()); | 1128 EXPECT_EQ(3U, model.GetCursorPosition()); |
1123 EXPECT_TRUE(model.Undo()); | 1129 EXPECT_TRUE(model.Undo()); |
1124 EXPECT_STR_EQ("www.google.com", model.text()); | 1130 EXPECT_STR_EQ("www.google.com", model.GetText()); |
1125 EXPECT_EQ(2U, model.GetCursorPosition()); | 1131 EXPECT_EQ(2U, model.GetCursorPosition()); |
1126 EXPECT_TRUE(model.Undo()); | 1132 EXPECT_TRUE(model.Undo()); |
1127 EXPECT_STR_EQ("www.google.com", model.text()); | 1133 EXPECT_STR_EQ("www.google.com", model.GetText()); |
1128 EXPECT_EQ(1U, model.GetCursorPosition()); | 1134 EXPECT_EQ(1U, model.GetCursorPosition()); |
1129 EXPECT_TRUE(model.Undo()); | 1135 EXPECT_TRUE(model.Undo()); |
1130 EXPECT_STR_EQ("", model.text()); | 1136 EXPECT_STR_EQ("", model.GetText()); |
1131 EXPECT_EQ(0U, model.GetCursorPosition()); | 1137 EXPECT_EQ(0U, model.GetCursorPosition()); |
1132 EXPECT_FALSE(model.Undo()); | 1138 EXPECT_FALSE(model.Undo()); |
1133 EXPECT_TRUE(model.Redo()); | 1139 EXPECT_TRUE(model.Redo()); |
1134 EXPECT_STR_EQ("www.google.com", model.text()); | 1140 EXPECT_STR_EQ("www.google.com", model.GetText()); |
1135 EXPECT_EQ(1U, model.GetCursorPosition()); | 1141 EXPECT_EQ(1U, model.GetCursorPosition()); |
1136 EXPECT_TRUE(model.Redo()); | 1142 EXPECT_TRUE(model.Redo()); |
1137 EXPECT_STR_EQ("www.google.com", model.text()); | 1143 EXPECT_STR_EQ("www.google.com", model.GetText()); |
1138 EXPECT_EQ(2U, model.GetCursorPosition()); | 1144 EXPECT_EQ(2U, model.GetCursorPosition()); |
1139 EXPECT_TRUE(model.Redo()); | 1145 EXPECT_TRUE(model.Redo()); |
1140 EXPECT_STR_EQ("www.google.com", model.text()); | 1146 EXPECT_STR_EQ("www.google.com", model.GetText()); |
1141 EXPECT_EQ(3U, model.GetCursorPosition()); | 1147 EXPECT_EQ(3U, model.GetCursorPosition()); |
1142 EXPECT_TRUE(model.Redo()); | 1148 EXPECT_TRUE(model.Redo()); |
1143 EXPECT_STR_EQ("www.google.com", model.text()); | 1149 EXPECT_STR_EQ("www.google.com", model.GetText()); |
1144 EXPECT_EQ(4U, model.GetCursorPosition()); | 1150 EXPECT_EQ(4U, model.GetCursorPosition()); |
1145 EXPECT_TRUE(model.Redo()); | 1151 EXPECT_TRUE(model.Redo()); |
1146 EXPECT_STR_EQ("www.youtube.com", model.text()); | 1152 EXPECT_STR_EQ("www.youtube.com", model.GetText()); |
1147 EXPECT_EQ(5U, model.GetCursorPosition()); | 1153 EXPECT_EQ(5U, model.GetCursorPosition()); |
1148 EXPECT_FALSE(model.Redo()); | 1154 EXPECT_FALSE(model.Redo()); |
1149 } | 1155 } |
1150 | 1156 |
1151 TEST_F(TextfieldViewsModelTest, UndoRedo_BackspaceThenSetText) { | 1157 TEST_F(TextfieldViewsModelTest, UndoRedo_BackspaceThenSetText) { |
1152 // This is to test the undo/redo behavior of omnibox. | 1158 // This is to test the undo/redo behavior of omnibox. |
1153 TextfieldViewsModel model(NULL); | 1159 TextfieldViewsModel model(NULL); |
1154 model.InsertChar('w'); | 1160 model.InsertChar('w'); |
1155 EXPECT_STR_EQ("w", model.text()); | 1161 EXPECT_STR_EQ("w", model.GetText()); |
1156 EXPECT_EQ(1U, model.GetCursorPosition()); | 1162 EXPECT_EQ(1U, model.GetCursorPosition()); |
1157 model.SetText(ASCIIToUTF16("www.google.com")); | 1163 model.SetText(ASCIIToUTF16("www.google.com")); |
1158 EXPECT_EQ(14U, model.GetCursorPosition()); | 1164 EXPECT_EQ(14U, model.GetCursorPosition()); |
1159 EXPECT_STR_EQ("www.google.com", model.text()); | 1165 EXPECT_STR_EQ("www.google.com", model.GetText()); |
1160 model.SetText(ASCIIToUTF16("www.google.com")); // Confirm the text. | 1166 model.SetText(ASCIIToUTF16("www.google.com")); // Confirm the text. |
1161 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 1167 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
1162 EXPECT_EQ(14U, model.GetCursorPosition()); | 1168 EXPECT_EQ(14U, model.GetCursorPosition()); |
1163 EXPECT_TRUE(model.Backspace()); | 1169 EXPECT_TRUE(model.Backspace()); |
1164 EXPECT_TRUE(model.Backspace()); | 1170 EXPECT_TRUE(model.Backspace()); |
1165 EXPECT_STR_EQ("www.google.c", model.text()); | 1171 EXPECT_STR_EQ("www.google.c", model.GetText()); |
1166 // Autocomplete sets the text | 1172 // Autocomplete sets the text |
1167 model.SetText(ASCIIToUTF16("www.google.com/search=www.google.c")); | 1173 model.SetText(ASCIIToUTF16("www.google.com/search=www.google.c")); |
1168 EXPECT_STR_EQ("www.google.com/search=www.google.c", model.text()); | 1174 EXPECT_STR_EQ("www.google.com/search=www.google.c", model.GetText()); |
1169 EXPECT_TRUE(model.Undo()); | 1175 EXPECT_TRUE(model.Undo()); |
1170 EXPECT_STR_EQ("www.google.c", model.text()); | 1176 EXPECT_STR_EQ("www.google.c", model.GetText()); |
1171 EXPECT_TRUE(model.Undo()); | 1177 EXPECT_TRUE(model.Undo()); |
1172 EXPECT_STR_EQ("www.google.com", model.text()); | 1178 EXPECT_STR_EQ("www.google.com", model.GetText()); |
1173 } | 1179 } |
1174 | 1180 |
1175 TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) { | 1181 TEST_F(TextfieldViewsModelTest, UndoRedo_CutCopyPasteTest) { |
1176 TextfieldViewsModel model(NULL); | 1182 TextfieldViewsModel model(NULL); |
1177 model.SetText(ASCIIToUTF16("ABCDE")); | 1183 model.SetText(ASCIIToUTF16("ABCDE")); |
1178 EXPECT_FALSE(model.Redo()); // nothing to redo | 1184 EXPECT_FALSE(model.Redo()); // nothing to redo |
1179 // Cut | 1185 // Cut |
1180 model.SelectRange(gfx::Range(1, 3)); | 1186 model.SelectRange(gfx::Range(1, 3)); |
1181 model.Cut(); | 1187 model.Cut(); |
1182 EXPECT_STR_EQ("ADE", model.text()); | 1188 EXPECT_STR_EQ("ADE", model.GetText()); |
1183 EXPECT_EQ(1U, model.GetCursorPosition()); | 1189 EXPECT_EQ(1U, model.GetCursorPosition()); |
1184 EXPECT_TRUE(model.Undo()); | 1190 EXPECT_TRUE(model.Undo()); |
1185 EXPECT_STR_EQ("ABCDE", model.text()); | 1191 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1186 EXPECT_EQ(3U, model.GetCursorPosition()); | 1192 EXPECT_EQ(3U, model.GetCursorPosition()); |
1187 EXPECT_TRUE(model.Undo()); | 1193 EXPECT_TRUE(model.Undo()); |
1188 EXPECT_STR_EQ("", model.text()); | 1194 EXPECT_STR_EQ("", model.GetText()); |
1189 EXPECT_EQ(0U, model.GetCursorPosition()); | 1195 EXPECT_EQ(0U, model.GetCursorPosition()); |
1190 EXPECT_FALSE(model.Undo()); // no more undo | 1196 EXPECT_FALSE(model.Undo()); // no more undo |
1191 EXPECT_STR_EQ("", model.text()); | 1197 EXPECT_STR_EQ("", model.GetText()); |
1192 EXPECT_TRUE(model.Redo()); | 1198 EXPECT_TRUE(model.Redo()); |
1193 EXPECT_STR_EQ("ABCDE", model.text()); | 1199 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1194 EXPECT_EQ(5U, model.GetCursorPosition()); | 1200 EXPECT_EQ(5U, model.GetCursorPosition()); |
1195 EXPECT_TRUE(model.Redo()); | 1201 EXPECT_TRUE(model.Redo()); |
1196 EXPECT_STR_EQ("ADE", model.text()); | 1202 EXPECT_STR_EQ("ADE", model.GetText()); |
1197 EXPECT_EQ(1U, model.GetCursorPosition()); | 1203 EXPECT_EQ(1U, model.GetCursorPosition()); |
1198 EXPECT_FALSE(model.Redo()); // no more redo | 1204 EXPECT_FALSE(model.Redo()); // no more redo |
1199 EXPECT_STR_EQ("ADE", model.text()); | 1205 EXPECT_STR_EQ("ADE", model.GetText()); |
1200 | 1206 |
1201 model.Paste(); | 1207 model.Paste(); |
1202 model.Paste(); | 1208 model.Paste(); |
1203 model.Paste(); | 1209 model.Paste(); |
1204 EXPECT_STR_EQ("ABCBCBCDE", model.text()); | 1210 EXPECT_STR_EQ("ABCBCBCDE", model.GetText()); |
1205 EXPECT_EQ(7U, model.GetCursorPosition()); | 1211 EXPECT_EQ(7U, model.GetCursorPosition()); |
1206 EXPECT_TRUE(model.Undo()); | 1212 EXPECT_TRUE(model.Undo()); |
1207 EXPECT_STR_EQ("ABCBCDE", model.text()); | 1213 EXPECT_STR_EQ("ABCBCDE", model.GetText()); |
1208 EXPECT_EQ(5U, model.GetCursorPosition()); | 1214 EXPECT_EQ(5U, model.GetCursorPosition()); |
1209 EXPECT_TRUE(model.Undo()); | 1215 EXPECT_TRUE(model.Undo()); |
1210 EXPECT_STR_EQ("ABCDE", model.text()); | 1216 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1211 EXPECT_EQ(3U, model.GetCursorPosition()); | 1217 EXPECT_EQ(3U, model.GetCursorPosition()); |
1212 EXPECT_TRUE(model.Undo()); | 1218 EXPECT_TRUE(model.Undo()); |
1213 EXPECT_STR_EQ("ADE", model.text()); | 1219 EXPECT_STR_EQ("ADE", model.GetText()); |
1214 EXPECT_EQ(1U, model.GetCursorPosition()); | 1220 EXPECT_EQ(1U, model.GetCursorPosition()); |
1215 EXPECT_TRUE(model.Undo()); | 1221 EXPECT_TRUE(model.Undo()); |
1216 EXPECT_STR_EQ("ABCDE", model.text()); | 1222 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1217 EXPECT_EQ(3U, model.GetCursorPosition()); | 1223 EXPECT_EQ(3U, model.GetCursorPosition()); |
1218 EXPECT_TRUE(model.Undo()); | 1224 EXPECT_TRUE(model.Undo()); |
1219 EXPECT_STR_EQ("", model.text()); | 1225 EXPECT_STR_EQ("", model.GetText()); |
1220 EXPECT_EQ(0U, model.GetCursorPosition()); | 1226 EXPECT_EQ(0U, model.GetCursorPosition()); |
1221 EXPECT_FALSE(model.Undo()); | 1227 EXPECT_FALSE(model.Undo()); |
1222 EXPECT_STR_EQ("", model.text()); | 1228 EXPECT_STR_EQ("", model.GetText()); |
1223 EXPECT_TRUE(model.Redo()); | 1229 EXPECT_TRUE(model.Redo()); |
1224 EXPECT_STR_EQ("ABCDE", model.text()); // Redoing SetText | 1230 EXPECT_STR_EQ("ABCDE", model.GetText()); // Redoing SetText |
1225 EXPECT_EQ(5U, model.GetCursorPosition()); | 1231 EXPECT_EQ(5U, model.GetCursorPosition()); |
1226 | 1232 |
1227 // Redo | 1233 // Redo |
1228 EXPECT_TRUE(model.Redo()); | 1234 EXPECT_TRUE(model.Redo()); |
1229 EXPECT_STR_EQ("ADE", model.text()); | 1235 EXPECT_STR_EQ("ADE", model.GetText()); |
1230 EXPECT_EQ(1U, model.GetCursorPosition()); | 1236 EXPECT_EQ(1U, model.GetCursorPosition()); |
1231 EXPECT_TRUE(model.Redo()); | 1237 EXPECT_TRUE(model.Redo()); |
1232 EXPECT_STR_EQ("ABCDE", model.text()); | 1238 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1233 EXPECT_EQ(3U, model.GetCursorPosition()); | 1239 EXPECT_EQ(3U, model.GetCursorPosition()); |
1234 EXPECT_TRUE(model.Redo()); | 1240 EXPECT_TRUE(model.Redo()); |
1235 EXPECT_STR_EQ("ABCBCDE", model.text()); | 1241 EXPECT_STR_EQ("ABCBCDE", model.GetText()); |
1236 EXPECT_EQ(5U, model.GetCursorPosition()); | 1242 EXPECT_EQ(5U, model.GetCursorPosition()); |
1237 EXPECT_TRUE(model.Redo()); | 1243 EXPECT_TRUE(model.Redo()); |
1238 EXPECT_STR_EQ("ABCBCBCDE", model.text()); | 1244 EXPECT_STR_EQ("ABCBCBCDE", model.GetText()); |
1239 EXPECT_EQ(7U, model.GetCursorPosition()); | 1245 EXPECT_EQ(7U, model.GetCursorPosition()); |
1240 EXPECT_FALSE(model.Redo()); | 1246 EXPECT_FALSE(model.Redo()); |
1241 | 1247 |
1242 // with SelectRange | 1248 // with SelectRange |
1243 model.SelectRange(gfx::Range(1, 3)); | 1249 model.SelectRange(gfx::Range(1, 3)); |
1244 EXPECT_TRUE(model.Cut()); | 1250 EXPECT_TRUE(model.Cut()); |
1245 EXPECT_STR_EQ("ABCBCDE", model.text()); | 1251 EXPECT_STR_EQ("ABCBCDE", model.GetText()); |
1246 EXPECT_EQ(1U, model.GetCursorPosition()); | 1252 EXPECT_EQ(1U, model.GetCursorPosition()); |
1247 model.SelectRange(gfx::Range(1, 1)); | 1253 model.SelectRange(gfx::Range(1, 1)); |
1248 EXPECT_FALSE(model.Cut()); | 1254 EXPECT_FALSE(model.Cut()); |
1249 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 1255 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
1250 EXPECT_TRUE(model.Paste()); | 1256 EXPECT_TRUE(model.Paste()); |
1251 EXPECT_STR_EQ("ABCBCDEBC", model.text()); | 1257 EXPECT_STR_EQ("ABCBCDEBC", model.GetText()); |
1252 EXPECT_EQ(9U, model.GetCursorPosition()); | 1258 EXPECT_EQ(9U, model.GetCursorPosition()); |
1253 EXPECT_TRUE(model.Undo()); | 1259 EXPECT_TRUE(model.Undo()); |
1254 EXPECT_STR_EQ("ABCBCDE", model.text()); | 1260 EXPECT_STR_EQ("ABCBCDE", model.GetText()); |
1255 EXPECT_EQ(7U, model.GetCursorPosition()); | 1261 EXPECT_EQ(7U, model.GetCursorPosition()); |
1256 // empty cut shouldn't create an edit. | 1262 // empty cut shouldn't create an edit. |
1257 EXPECT_TRUE(model.Undo()); | 1263 EXPECT_TRUE(model.Undo()); |
1258 EXPECT_STR_EQ("ABCBCBCDE", model.text()); | 1264 EXPECT_STR_EQ("ABCBCBCDE", model.GetText()); |
1259 EXPECT_EQ(3U, model.GetCursorPosition()); | 1265 EXPECT_EQ(3U, model.GetCursorPosition()); |
1260 | 1266 |
1261 // Copy | 1267 // Copy |
1262 ResetModel(&model); | 1268 ResetModel(&model); |
1263 model.SetText(ASCIIToUTF16("12345")); | 1269 model.SetText(ASCIIToUTF16("12345")); |
1264 EXPECT_STR_EQ("12345", model.text()); | 1270 EXPECT_STR_EQ("12345", model.GetText()); |
1265 EXPECT_EQ(5U, model.GetCursorPosition()); | 1271 EXPECT_EQ(5U, model.GetCursorPosition()); |
1266 model.SelectRange(gfx::Range(1, 3)); | 1272 model.SelectRange(gfx::Range(1, 3)); |
1267 model.Copy(); // Copy "23" | 1273 model.Copy(); // Copy "23" |
1268 EXPECT_STR_EQ("12345", model.text()); | 1274 EXPECT_STR_EQ("12345", model.GetText()); |
1269 EXPECT_EQ(3U, model.GetCursorPosition()); | 1275 EXPECT_EQ(3U, model.GetCursorPosition()); |
1270 model.Paste(); // Paste "23" into "23". | 1276 model.Paste(); // Paste "23" into "23". |
1271 EXPECT_STR_EQ("12345", model.text()); | 1277 EXPECT_STR_EQ("12345", model.GetText()); |
1272 EXPECT_EQ(3U, model.GetCursorPosition()); | 1278 EXPECT_EQ(3U, model.GetCursorPosition()); |
1273 model.Paste(); | 1279 model.Paste(); |
1274 EXPECT_STR_EQ("1232345", model.text()); | 1280 EXPECT_STR_EQ("1232345", model.GetText()); |
1275 EXPECT_EQ(5U, model.GetCursorPosition()); | 1281 EXPECT_EQ(5U, model.GetCursorPosition()); |
1276 EXPECT_TRUE(model.Undo()); | 1282 EXPECT_TRUE(model.Undo()); |
1277 EXPECT_STR_EQ("12345", model.text()); | 1283 EXPECT_STR_EQ("12345", model.GetText()); |
1278 EXPECT_EQ(3U, model.GetCursorPosition()); | 1284 EXPECT_EQ(3U, model.GetCursorPosition()); |
1279 // TODO(oshima): We need to change the return type from bool to enum. | 1285 // TODO(oshima): We need to change the return type from bool to enum. |
1280 EXPECT_FALSE(model.Undo()); // No text change. | 1286 EXPECT_FALSE(model.Undo()); // No text change. |
1281 EXPECT_STR_EQ("12345", model.text()); | 1287 EXPECT_STR_EQ("12345", model.GetText()); |
1282 EXPECT_EQ(3U, model.GetCursorPosition()); | 1288 EXPECT_EQ(3U, model.GetCursorPosition()); |
1283 EXPECT_TRUE(model.Undo()); | 1289 EXPECT_TRUE(model.Undo()); |
1284 EXPECT_STR_EQ("", model.text()); | 1290 EXPECT_STR_EQ("", model.GetText()); |
1285 EXPECT_FALSE(model.Undo()); | 1291 EXPECT_FALSE(model.Undo()); |
1286 // Redo | 1292 // Redo |
1287 EXPECT_TRUE(model.Redo()); | 1293 EXPECT_TRUE(model.Redo()); |
1288 EXPECT_STR_EQ("12345", model.text()); | 1294 EXPECT_STR_EQ("12345", model.GetText()); |
1289 EXPECT_EQ(5U, model.GetCursorPosition()); | 1295 EXPECT_EQ(5U, model.GetCursorPosition()); |
1290 EXPECT_TRUE(model.Redo()); | 1296 EXPECT_TRUE(model.Redo()); |
1291 EXPECT_STR_EQ("12345", model.text()); // For 1st paste | 1297 EXPECT_STR_EQ("12345", model.GetText()); // For 1st paste |
1292 EXPECT_EQ(3U, model.GetCursorPosition()); | 1298 EXPECT_EQ(3U, model.GetCursorPosition()); |
1293 EXPECT_TRUE(model.Redo()); | 1299 EXPECT_TRUE(model.Redo()); |
1294 EXPECT_STR_EQ("1232345", model.text()); | 1300 EXPECT_STR_EQ("1232345", model.GetText()); |
1295 EXPECT_EQ(5U, model.GetCursorPosition()); | 1301 EXPECT_EQ(5U, model.GetCursorPosition()); |
1296 EXPECT_FALSE(model.Redo()); | 1302 EXPECT_FALSE(model.Redo()); |
1297 EXPECT_STR_EQ("1232345", model.text()); | 1303 EXPECT_STR_EQ("1232345", model.GetText()); |
1298 | 1304 |
1299 // Test using SelectRange | 1305 // Test using SelectRange |
1300 model.SelectRange(gfx::Range(1, 3)); | 1306 model.SelectRange(gfx::Range(1, 3)); |
1301 model.Copy(); | 1307 model.Copy(); |
1302 EXPECT_STR_EQ("1232345", model.text()); | 1308 EXPECT_STR_EQ("1232345", model.GetText()); |
1303 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 1309 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
1304 EXPECT_TRUE(model.Paste()); | 1310 EXPECT_TRUE(model.Paste()); |
1305 EXPECT_STR_EQ("123234523", model.text()); | 1311 EXPECT_STR_EQ("123234523", model.GetText()); |
1306 EXPECT_EQ(9U, model.GetCursorPosition()); | 1312 EXPECT_EQ(9U, model.GetCursorPosition()); |
1307 EXPECT_TRUE(model.Undo()); | 1313 EXPECT_TRUE(model.Undo()); |
1308 EXPECT_STR_EQ("1232345", model.text()); | 1314 EXPECT_STR_EQ("1232345", model.GetText()); |
1309 EXPECT_EQ(7U, model.GetCursorPosition()); | 1315 EXPECT_EQ(7U, model.GetCursorPosition()); |
1310 } | 1316 } |
1311 | 1317 |
1312 TEST_F(TextfieldViewsModelTest, UndoRedo_CursorTest) { | 1318 TEST_F(TextfieldViewsModelTest, UndoRedo_CursorTest) { |
1313 TextfieldViewsModel model(NULL); | 1319 TextfieldViewsModel model(NULL); |
1314 model.InsertChar('a'); | 1320 model.InsertChar('a'); |
1315 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); | 1321 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); |
1316 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); | 1322 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); |
1317 model.InsertChar('b'); | 1323 model.InsertChar('b'); |
1318 // Moving the cursor shouldn't create a new edit. | 1324 // Moving the cursor shouldn't create a new edit. |
1319 EXPECT_STR_EQ("ab", model.text()); | 1325 EXPECT_STR_EQ("ab", model.GetText()); |
1320 EXPECT_FALSE(model.Redo()); | 1326 EXPECT_FALSE(model.Redo()); |
1321 EXPECT_TRUE(model.Undo()); | 1327 EXPECT_TRUE(model.Undo()); |
1322 EXPECT_STR_EQ("", model.text()); | 1328 EXPECT_STR_EQ("", model.GetText()); |
1323 EXPECT_FALSE(model.Undo()); | 1329 EXPECT_FALSE(model.Undo()); |
1324 EXPECT_STR_EQ("", model.text()); | 1330 EXPECT_STR_EQ("", model.GetText()); |
1325 EXPECT_TRUE(model.Redo()); | 1331 EXPECT_TRUE(model.Redo()); |
1326 EXPECT_STR_EQ("ab", model.text()); | 1332 EXPECT_STR_EQ("ab", model.GetText()); |
1327 EXPECT_EQ(2U, model.GetCursorPosition()); | 1333 EXPECT_EQ(2U, model.GetCursorPosition()); |
1328 EXPECT_FALSE(model.Redo()); | 1334 EXPECT_FALSE(model.Redo()); |
1329 } | 1335 } |
1330 | 1336 |
1331 void RunInsertReplaceTest(TextfieldViewsModel& model) { | 1337 void RunInsertReplaceTest(TextfieldViewsModel& model) { |
1332 const bool reverse = model.render_text()->selection().is_reversed(); | 1338 const bool reverse = model.render_text()->selection().is_reversed(); |
1333 model.InsertChar('1'); | 1339 model.InsertChar('1'); |
1334 model.InsertChar('2'); | 1340 model.InsertChar('2'); |
1335 model.InsertChar('3'); | 1341 model.InsertChar('3'); |
1336 EXPECT_STR_EQ("a123d", model.text()); | 1342 EXPECT_STR_EQ("a123d", model.GetText()); |
1337 EXPECT_EQ(4U, model.GetCursorPosition()); | 1343 EXPECT_EQ(4U, model.GetCursorPosition()); |
1338 EXPECT_TRUE(model.Undo()); | 1344 EXPECT_TRUE(model.Undo()); |
1339 EXPECT_STR_EQ("abcd", model.text()); | 1345 EXPECT_STR_EQ("abcd", model.GetText()); |
1340 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); | 1346 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); |
1341 EXPECT_TRUE(model.Undo()); | 1347 EXPECT_TRUE(model.Undo()); |
1342 EXPECT_STR_EQ("", model.text()); | 1348 EXPECT_STR_EQ("", model.GetText()); |
1343 EXPECT_EQ(0U, model.GetCursorPosition()); | 1349 EXPECT_EQ(0U, model.GetCursorPosition()); |
1344 EXPECT_FALSE(model.Undo()); | 1350 EXPECT_FALSE(model.Undo()); |
1345 EXPECT_TRUE(model.Redo()); | 1351 EXPECT_TRUE(model.Redo()); |
1346 EXPECT_STR_EQ("abcd", model.text()); | 1352 EXPECT_STR_EQ("abcd", model.GetText()); |
1347 EXPECT_EQ(4U, model.GetCursorPosition()); // By SetText | 1353 EXPECT_EQ(4U, model.GetCursorPosition()); // By SetText |
1348 EXPECT_TRUE(model.Redo()); | 1354 EXPECT_TRUE(model.Redo()); |
1349 EXPECT_STR_EQ("a123d", model.text()); | 1355 EXPECT_STR_EQ("a123d", model.GetText()); |
1350 EXPECT_EQ(4U, model.GetCursorPosition()); | 1356 EXPECT_EQ(4U, model.GetCursorPosition()); |
1351 EXPECT_FALSE(model.Redo()); | 1357 EXPECT_FALSE(model.Redo()); |
1352 } | 1358 } |
1353 | 1359 |
1354 void RunOverwriteReplaceTest(TextfieldViewsModel& model) { | 1360 void RunOverwriteReplaceTest(TextfieldViewsModel& model) { |
1355 const bool reverse = model.render_text()->selection().is_reversed(); | 1361 const bool reverse = model.render_text()->selection().is_reversed(); |
1356 model.ReplaceChar('1'); | 1362 model.ReplaceChar('1'); |
1357 model.ReplaceChar('2'); | 1363 model.ReplaceChar('2'); |
1358 model.ReplaceChar('3'); | 1364 model.ReplaceChar('3'); |
1359 model.ReplaceChar('4'); | 1365 model.ReplaceChar('4'); |
1360 EXPECT_STR_EQ("a1234", model.text()); | 1366 EXPECT_STR_EQ("a1234", model.GetText()); |
1361 EXPECT_EQ(5U, model.GetCursorPosition()); | 1367 EXPECT_EQ(5U, model.GetCursorPosition()); |
1362 EXPECT_TRUE(model.Undo()); | 1368 EXPECT_TRUE(model.Undo()); |
1363 EXPECT_STR_EQ("abcd", model.text()); | 1369 EXPECT_STR_EQ("abcd", model.GetText()); |
1364 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); | 1370 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); |
1365 EXPECT_TRUE(model.Undo()); | 1371 EXPECT_TRUE(model.Undo()); |
1366 EXPECT_STR_EQ("", model.text()); | 1372 EXPECT_STR_EQ("", model.GetText()); |
1367 EXPECT_EQ(0U, model.GetCursorPosition()); | 1373 EXPECT_EQ(0U, model.GetCursorPosition()); |
1368 EXPECT_FALSE(model.Undo()); | 1374 EXPECT_FALSE(model.Undo()); |
1369 EXPECT_TRUE(model.Redo()); | 1375 EXPECT_TRUE(model.Redo()); |
1370 EXPECT_STR_EQ("abcd", model.text()); | 1376 EXPECT_STR_EQ("abcd", model.GetText()); |
1371 EXPECT_EQ(4U, model.GetCursorPosition()); | 1377 EXPECT_EQ(4U, model.GetCursorPosition()); |
1372 EXPECT_TRUE(model.Redo()); | 1378 EXPECT_TRUE(model.Redo()); |
1373 EXPECT_STR_EQ("a1234", model.text()); | 1379 EXPECT_STR_EQ("a1234", model.GetText()); |
1374 EXPECT_EQ(5U, model.GetCursorPosition()); | 1380 EXPECT_EQ(5U, model.GetCursorPosition()); |
1375 EXPECT_FALSE(model.Redo()); | 1381 EXPECT_FALSE(model.Redo()); |
1376 } | 1382 } |
1377 | 1383 |
1378 TEST_F(TextfieldViewsModelTest, UndoRedo_ReplaceTest) { | 1384 TEST_F(TextfieldViewsModelTest, UndoRedo_ReplaceTest) { |
1379 // By Cursor | 1385 // By Cursor |
1380 { | 1386 { |
1381 SCOPED_TRACE("forward & insert by cursor"); | 1387 SCOPED_TRACE("forward & insert by cursor"); |
1382 TextfieldViewsModel model(NULL); | 1388 TextfieldViewsModel model(NULL); |
1383 model.SetText(ASCIIToUTF16("abcd")); | 1389 model.SetText(ASCIIToUTF16("abcd")); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1440 TextfieldViewsModel model(NULL); | 1446 TextfieldViewsModel model(NULL); |
1441 | 1447 |
1442 ui::CompositionText composition; | 1448 ui::CompositionText composition; |
1443 composition.text = ASCIIToUTF16("abc"); | 1449 composition.text = ASCIIToUTF16("abc"); |
1444 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false)); | 1450 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false)); |
1445 composition.selection = gfx::Range(2, 3); | 1451 composition.selection = gfx::Range(2, 3); |
1446 | 1452 |
1447 model.SetText(ASCIIToUTF16("ABCDE")); | 1453 model.SetText(ASCIIToUTF16("ABCDE")); |
1448 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 1454 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
1449 model.InsertChar('x'); | 1455 model.InsertChar('x'); |
1450 EXPECT_STR_EQ("ABCDEx", model.text()); | 1456 EXPECT_STR_EQ("ABCDEx", model.GetText()); |
1451 EXPECT_TRUE(model.Undo()); // set composition should forget undone edit. | 1457 EXPECT_TRUE(model.Undo()); // set composition should forget undone edit. |
1452 model.SetCompositionText(composition); | 1458 model.SetCompositionText(composition); |
1453 EXPECT_TRUE(model.HasCompositionText()); | 1459 EXPECT_TRUE(model.HasCompositionText()); |
1454 EXPECT_TRUE(model.HasSelection()); | 1460 EXPECT_TRUE(model.HasSelection()); |
1455 EXPECT_STR_EQ("ABCDEabc", model.text()); | 1461 EXPECT_STR_EQ("ABCDEabc", model.GetText()); |
1456 | 1462 |
1457 // Accepting composition | 1463 // Accepting composition |
1458 model.ConfirmCompositionText(); | 1464 model.ConfirmCompositionText(); |
1459 EXPECT_STR_EQ("ABCDEabc", model.text()); | 1465 EXPECT_STR_EQ("ABCDEabc", model.GetText()); |
1460 EXPECT_TRUE(model.Undo()); | 1466 EXPECT_TRUE(model.Undo()); |
1461 EXPECT_STR_EQ("ABCDE", model.text()); | 1467 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1462 EXPECT_TRUE(model.Undo()); | 1468 EXPECT_TRUE(model.Undo()); |
1463 EXPECT_STR_EQ("", model.text()); | 1469 EXPECT_STR_EQ("", model.GetText()); |
1464 EXPECT_TRUE(model.Redo()); | 1470 EXPECT_TRUE(model.Redo()); |
1465 EXPECT_STR_EQ("ABCDE", model.text()); | 1471 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1466 EXPECT_TRUE(model.Redo()); | 1472 EXPECT_TRUE(model.Redo()); |
1467 EXPECT_STR_EQ("ABCDEabc", model.text()); | 1473 EXPECT_STR_EQ("ABCDEabc", model.GetText()); |
1468 EXPECT_FALSE(model.Redo()); | 1474 EXPECT_FALSE(model.Redo()); |
1469 | 1475 |
1470 // Canceling composition | 1476 // Canceling composition |
1471 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); | 1477 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); |
1472 model.SetCompositionText(composition); | 1478 model.SetCompositionText(composition); |
1473 EXPECT_STR_EQ("abcABCDEabc", model.text()); | 1479 EXPECT_STR_EQ("abcABCDEabc", model.GetText()); |
1474 model.CancelCompositionText(); | 1480 model.CancelCompositionText(); |
1475 EXPECT_STR_EQ("ABCDEabc", model.text()); | 1481 EXPECT_STR_EQ("ABCDEabc", model.GetText()); |
1476 EXPECT_FALSE(model.Redo()); | 1482 EXPECT_FALSE(model.Redo()); |
1477 EXPECT_STR_EQ("ABCDEabc", model.text()); | 1483 EXPECT_STR_EQ("ABCDEabc", model.GetText()); |
1478 EXPECT_TRUE(model.Undo()); | 1484 EXPECT_TRUE(model.Undo()); |
1479 EXPECT_STR_EQ("ABCDE", model.text()); | 1485 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1480 EXPECT_TRUE(model.Redo()); | 1486 EXPECT_TRUE(model.Redo()); |
1481 EXPECT_STR_EQ("ABCDEabc", model.text()); | 1487 EXPECT_STR_EQ("ABCDEabc", model.GetText()); |
1482 EXPECT_FALSE(model.Redo()); | 1488 EXPECT_FALSE(model.Redo()); |
1483 | 1489 |
1484 // SetText with the same text as the result. | 1490 // SetText with the same text as the result. |
1485 ResetModel(&model); | 1491 ResetModel(&model); |
1486 model.SetText(ASCIIToUTF16("ABCDE")); | 1492 model.SetText(ASCIIToUTF16("ABCDE")); |
1487 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 1493 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
1488 model.SetCompositionText(composition); | 1494 model.SetCompositionText(composition); |
1489 EXPECT_STR_EQ("ABCDEabc", model.text()); | 1495 EXPECT_STR_EQ("ABCDEabc", model.GetText()); |
1490 model.SetText(ASCIIToUTF16("ABCDEabc")); | 1496 model.SetText(ASCIIToUTF16("ABCDEabc")); |
1491 EXPECT_STR_EQ("ABCDEabc", model.text()); | 1497 EXPECT_STR_EQ("ABCDEabc", model.GetText()); |
1492 EXPECT_TRUE(model.Undo()); | 1498 EXPECT_TRUE(model.Undo()); |
1493 EXPECT_STR_EQ("ABCDE", model.text()); | 1499 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1494 EXPECT_TRUE(model.Redo()); | 1500 EXPECT_TRUE(model.Redo()); |
1495 EXPECT_STR_EQ("ABCDEabc", model.text()); | 1501 EXPECT_STR_EQ("ABCDEabc", model.GetText()); |
1496 EXPECT_FALSE(model.Redo()); | 1502 EXPECT_FALSE(model.Redo()); |
1497 | 1503 |
1498 // SetText with the different text than the result should not | 1504 // SetText with the different text than the result should not |
1499 // remember composition text. | 1505 // remember composition text. |
1500 ResetModel(&model); | 1506 ResetModel(&model); |
1501 model.SetText(ASCIIToUTF16("ABCDE")); | 1507 model.SetText(ASCIIToUTF16("ABCDE")); |
1502 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 1508 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
1503 model.SetCompositionText(composition); | 1509 model.SetCompositionText(composition); |
1504 EXPECT_STR_EQ("ABCDEabc", model.text()); | 1510 EXPECT_STR_EQ("ABCDEabc", model.GetText()); |
1505 model.SetText(ASCIIToUTF16("1234")); | 1511 model.SetText(ASCIIToUTF16("1234")); |
1506 EXPECT_STR_EQ("1234", model.text()); | 1512 EXPECT_STR_EQ("1234", model.GetText()); |
1507 EXPECT_TRUE(model.Undo()); | 1513 EXPECT_TRUE(model.Undo()); |
1508 EXPECT_STR_EQ("ABCDE", model.text()); | 1514 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1509 EXPECT_TRUE(model.Redo()); | 1515 EXPECT_TRUE(model.Redo()); |
1510 EXPECT_STR_EQ("1234", model.text()); | 1516 EXPECT_STR_EQ("1234", model.GetText()); |
1511 EXPECT_FALSE(model.Redo()); | 1517 EXPECT_FALSE(model.Redo()); |
1512 | 1518 |
1513 // TODO(oshima): We need MockInputMethod to test the behavior with IME. | 1519 // TODO(oshima): We need MockInputMethod to test the behavior with IME. |
1514 } | 1520 } |
1515 | 1521 |
1516 } // namespace views | 1522 } // namespace views |
OLD | NEW |