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.h" | 9 #include "base/message_loop.h" |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 struct WordAndCursor { | 29 struct WordAndCursor { |
30 WordAndCursor(const wchar_t* w, size_t c) | 30 WordAndCursor(const wchar_t* w, size_t c) |
31 : word(w), | 31 : word(w), |
32 cursor(c) { | 32 cursor(c) { |
33 } | 33 } |
34 | 34 |
35 const wchar_t* word; | 35 const wchar_t* word; |
36 size_t cursor; | 36 size_t cursor; |
37 }; | 37 }; |
38 | 38 |
| 39 void MoveCursorTo(views::TextfieldViewsModel& model, size_t pos) { |
| 40 model.MoveCursorTo(gfx::SelectionModel(pos, gfx::CURSOR_FORWARD)); |
| 41 } |
| 42 |
39 } // namespace | 43 } // namespace |
40 | 44 |
41 namespace views { | 45 namespace views { |
42 | 46 |
43 class TextfieldViewsModelTest : public ViewsTestBase, | 47 class TextfieldViewsModelTest : public ViewsTestBase, |
44 public TextfieldViewsModel::Delegate { | 48 public TextfieldViewsModel::Delegate { |
45 public: | 49 public: |
46 TextfieldViewsModelTest() | 50 TextfieldViewsModelTest() |
47 : ViewsTestBase(), | 51 : ViewsTestBase(), |
48 composition_text_confirmed_or_cleared_(false) { | 52 composition_text_confirmed_or_cleared_(false) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 EXPECT_FALSE(model.Backspace()); | 102 EXPECT_FALSE(model.Backspace()); |
99 EXPECT_STR_EQ("HELLORLD", model.GetText()); | 103 EXPECT_STR_EQ("HELLORLD", model.GetText()); |
100 // Move the cursor to the end. delete should fail. | 104 // Move the cursor to the end. delete should fail. |
101 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 105 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
102 EXPECT_FALSE(model.Delete()); | 106 EXPECT_FALSE(model.Delete()); |
103 EXPECT_STR_EQ("HELLORLD", model.GetText()); | 107 EXPECT_STR_EQ("HELLORLD", model.GetText()); |
104 // but backspace should work. | 108 // but backspace should work. |
105 EXPECT_TRUE(model.Backspace()); | 109 EXPECT_TRUE(model.Backspace()); |
106 EXPECT_STR_EQ("HELLORL", model.GetText()); | 110 EXPECT_STR_EQ("HELLORL", model.GetText()); |
107 | 111 |
108 model.MoveCursorTo(gfx::SelectionModel(5)); | 112 MoveCursorTo(model, 5); |
109 model.ReplaceText(ASCIIToUTF16(" WOR")); | 113 model.ReplaceText(ASCIIToUTF16(" WOR")); |
110 EXPECT_STR_EQ("HELLO WORL", model.GetText()); | 114 EXPECT_STR_EQ("HELLO WORL", model.GetText()); |
111 } | 115 } |
112 | 116 |
113 TEST_F(TextfieldViewsModelTest, EditString_SimpleRTL) { | 117 TEST_F(TextfieldViewsModelTest, EditString_SimpleRTL) { |
114 TextfieldViewsModel model(NULL); | 118 TextfieldViewsModel model(NULL); |
115 // Append two strings. | 119 // Append two strings. |
116 model.Append(WideToUTF16(L"\x05d0\x05d1\x05d2")); | 120 model.Append(WideToUTF16(L"\x05d0\x05d1\x05d2")); |
117 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2"), model.GetText()); | 121 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2"), model.GetText()); |
118 model.Append(WideToUTF16(L"\x05e0\x05e1\x05e2")); | 122 model.Append(WideToUTF16(L"\x05e0\x05e1\x05e2")); |
119 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2\x05e0\x05e1\x05e2"), | 123 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2\x05e0\x05e1\x05e2"), |
120 model.GetText()); | 124 model.GetText()); |
121 | 125 |
122 // Insert 0x05f0. | 126 // Insert 0x05f0. |
123 model.MoveCursorTo(gfx::SelectionModel(1U)); | 127 MoveCursorTo(model, 1); |
124 model.InsertChar(0x05f0); | 128 model.InsertChar(0x05f0); |
125 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05d1\x05d2\x05e0\x05e1\x05e2"), | 129 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05d1\x05d2\x05e0\x05e1\x05e2"), |
126 model.GetText()); | 130 model.GetText()); |
127 | 131 |
128 // Replace "\x05d1" with "\x05f1". | 132 // Replace "\x05d1" with "\x05f1". |
129 model.ReplaceChar(0x05f1); | 133 model.ReplaceChar(0x05f1); |
130 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05d2\x05e0\x05e1\x05e2"), | 134 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05d2\x05e0\x05e1\x05e2"), |
131 model.GetText()); | 135 model.GetText()); |
132 | 136 |
133 // Delete and backspace. | 137 // Delete and backspace. |
(...skipping 22 matching lines...) Expand all Loading... |
156 model.GetText()); | 160 model.GetText()); |
157 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d")); | 161 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d")); |
158 EXPECT_EQ(WideToUTF16( | 162 EXPECT_EQ(WideToUTF16( |
159 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), | 163 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), |
160 model.GetText()); | 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 model.MoveCursorTo(gfx::SelectionModel(1U)); | 170 MoveCursorTo(model, 1); |
167 EXPECT_EQ(0U, model.GetCursorPosition()); | 171 EXPECT_EQ(0U, model.GetCursorPosition()); |
168 | 172 |
169 model.MoveCursorTo(gfx::SelectionModel(2U)); | 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.GetText()); | 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.GetText()); | 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 model.MoveCursorTo(gfx::SelectionModel(0U)); | 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.GetText()); | 201 model.GetText()); |
198 model.MoveCursorTo(gfx::SelectionModel(model.GetText().length())); | 202 MoveCursorTo(model, model.GetText().length()); |
199 EXPECT_EQ(model.GetText().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"), | 205 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"), |
202 model.GetText()); | 206 model.GetText()); |
203 #endif | 207 #endif |
204 | 208 |
205 // Test cursor position and deletion for Hindi Virama. | 209 // Test cursor position and deletion for Hindi Virama. |
206 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E")); | 210 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E")); |
207 model.MoveCursorTo(gfx::SelectionModel(0)); | 211 MoveCursorTo(model, 0); |
208 EXPECT_EQ(0U, model.GetCursorPosition()); | 212 EXPECT_EQ(0U, model.GetCursorPosition()); |
209 | 213 |
210 // 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 |
211 // font support for some scripts - http://crbug.com/106450 | 215 // font support for some scripts - http://crbug.com/106450 |
212 if (!on_windows_xp) { | 216 if (!on_windows_xp) { |
213 model.MoveCursorTo(gfx::SelectionModel(1)); | 217 MoveCursorTo(model, 1); |
214 EXPECT_EQ(0U, model.GetCursorPosition()); | 218 EXPECT_EQ(0U, model.GetCursorPosition()); |
215 model.MoveCursorTo(gfx::SelectionModel(3)); | 219 MoveCursorTo(model, 3); |
216 EXPECT_EQ(3U, model.GetCursorPosition()); | 220 EXPECT_EQ(3U, model.GetCursorPosition()); |
217 } | 221 } |
218 | 222 |
219 // TODO(asvitkine): Temporarily disable the following check on Windows. It | 223 // TODO(asvitkine): Temporarily disable the following check on Windows. It |
220 // seems Windows treats "\x0D38\x0D4D\x0D15" as a single grapheme. | 224 // seems Windows treats "\x0D38\x0D4D\x0D15" as a single grapheme. |
221 #if !defined(OS_WIN) | 225 #if !defined(OS_WIN) |
222 model.MoveCursorTo(gfx::SelectionModel(2)); | 226 MoveCursorTo(model, 2); |
223 EXPECT_EQ(2U, model.GetCursorPosition()); | 227 EXPECT_EQ(2U, model.GetCursorPosition()); |
224 EXPECT_TRUE(model.Backspace()); | 228 EXPECT_TRUE(model.Backspace()); |
225 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText()); | 229 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText()); |
226 #endif | 230 #endif |
227 | 231 |
228 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9")); | 232 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9")); |
229 model.MoveCursorTo(gfx::SelectionModel(0)); | 233 MoveCursorTo(model, 0); |
230 EXPECT_TRUE(model.Delete()); | 234 EXPECT_TRUE(model.Delete()); |
231 EXPECT_TRUE(model.Delete()); | 235 EXPECT_TRUE(model.Delete()); |
232 EXPECT_TRUE(model.Delete()); | 236 EXPECT_TRUE(model.Delete()); |
233 EXPECT_TRUE(model.Delete()); | 237 EXPECT_TRUE(model.Delete()); |
234 EXPECT_EQ(WideToUTF16(L""), model.GetText()); | 238 EXPECT_EQ(WideToUTF16(L""), model.GetText()); |
235 | 239 |
236 // The first 2 characters are not strong directionality characters. | 240 // The first 2 characters are not strong directionality characters. |
237 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); | 241 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); |
238 #if defined(OS_WIN) | 242 #if defined(OS_WIN) |
239 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 243 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 EXPECT_STR_EQ("H", model.GetSelectedText()); | 278 EXPECT_STR_EQ("H", model.GetSelectedText()); |
275 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, true); | 279 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, true); |
276 EXPECT_STR_EQ("ELLO", model.GetSelectedText()); | 280 EXPECT_STR_EQ("ELLO", model.GetSelectedText()); |
277 model.ClearSelection(); | 281 model.ClearSelection(); |
278 EXPECT_EQ(string16(), model.GetSelectedText()); | 282 EXPECT_EQ(string16(), model.GetSelectedText()); |
279 model.SelectAll(); | 283 model.SelectAll(); |
280 EXPECT_STR_EQ("HELLO", model.GetSelectedText()); | 284 EXPECT_STR_EQ("HELLO", model.GetSelectedText()); |
281 // SelectAll should select towards the end. | 285 // SelectAll should select towards the end. |
282 gfx::SelectionModel sel; | 286 gfx::SelectionModel sel; |
283 model.GetSelectionModel(&sel); | 287 model.GetSelectionModel(&sel); |
284 EXPECT_EQ(0U, sel.selection_start()); | 288 EXPECT_EQ(ui::Range(0, 5), sel.selection()); |
285 EXPECT_EQ(5U, sel.selection_end()); | |
286 | 289 |
287 // Select and move cursor | 290 // Select and move cursor |
288 model.SelectRange(ui::Range(1U, 3U)); | 291 model.SelectRange(ui::Range(1U, 3U)); |
289 EXPECT_STR_EQ("EL", model.GetSelectedText()); | 292 EXPECT_STR_EQ("EL", model.GetSelectedText()); |
290 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); | 293 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); |
291 EXPECT_EQ(1U, model.GetCursorPosition()); | 294 EXPECT_EQ(1U, model.GetCursorPosition()); |
292 model.SelectRange(ui::Range(1U, 3U)); | 295 model.SelectRange(ui::Range(1U, 3U)); |
293 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); | 296 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); |
294 EXPECT_EQ(3U, model.GetCursorPosition()); | 297 EXPECT_EQ(3U, model.GetCursorPosition()); |
295 | 298 |
(...skipping 16 matching lines...) Expand all Loading... |
312 // TODO(xji): temporarily disable in platform Win since the complex script | 315 // TODO(xji): temporarily disable in platform Win since the complex script |
313 // characters turned into empty square due to font regression. So, not able | 316 // characters turned into empty square due to font regression. So, not able |
314 // to test 2 characters belong to the same grapheme. | 317 // to test 2 characters belong to the same grapheme. |
315 #if defined(OS_LINUX) | 318 #if defined(OS_LINUX) |
316 model.Append(WideToUTF16( | 319 model.Append(WideToUTF16( |
317 L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def")); | 320 L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def")); |
318 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); | 321 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); |
319 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); | 322 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); |
320 | 323 |
321 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 324 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
322 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); | 325 EXPECT_EQ(ui::Range(2, 3), model.render_text()->selection()); |
323 EXPECT_EQ(3U, model.GetCursorPosition()); | 326 EXPECT_EQ(3U, model.GetCursorPosition()); |
324 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); | 327 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); |
325 | 328 |
326 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 329 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
327 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); | 330 EXPECT_EQ(ui::Range(2, 7), model.render_text()->selection()); |
328 EXPECT_EQ(7U, model.GetCursorPosition()); | 331 EXPECT_EQ(7U, model.GetCursorPosition()); |
329 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8"), | 332 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8"), |
330 model.GetSelectedText()); | 333 model.GetSelectedText()); |
331 | 334 |
332 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 335 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
333 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); | 336 EXPECT_EQ(ui::Range(2, 3), model.render_text()->selection()); |
334 EXPECT_EQ(3U, model.GetCursorPosition()); | 337 EXPECT_EQ(3U, model.GetCursorPosition()); |
335 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); | 338 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); |
336 | 339 |
337 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 340 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
338 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); | 341 EXPECT_EQ(ui::Range(2, 10), model.render_text()->selection()); |
339 EXPECT_EQ(10U, model.GetCursorPosition()); | 342 EXPECT_EQ(10U, model.GetCursorPosition()); |
340 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"d"), | 343 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"d"), |
341 model.GetSelectedText()); | 344 model.GetSelectedText()); |
342 | 345 |
343 model.ClearSelection(); | 346 model.ClearSelection(); |
344 EXPECT_EQ(string16(), model.GetSelectedText()); | 347 EXPECT_EQ(string16(), model.GetSelectedText()); |
345 model.SelectAll(); | 348 model.SelectAll(); |
346 EXPECT_EQ(WideToUTF16(L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def"), | 349 EXPECT_EQ(WideToUTF16(L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def"), |
347 model.GetSelectedText()); | 350 model.GetSelectedText()); |
348 #endif | 351 #endif |
349 | 352 |
350 // In case of "aBc", this test shows how to select "aB" or "Bc", assume 'B' is | 353 // In case of "aBc", this test shows how to select "aB" or "Bc", assume 'B' is |
351 // an RTL character. | 354 // an RTL character. |
352 model.SetText(WideToUTF16(L"a\x05E9"L"b")); | 355 model.SetText(WideToUTF16(L"a\x05E9"L"b")); |
353 model.MoveCursorTo(gfx::SelectionModel(0)); | 356 MoveCursorTo(model, 0); |
354 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 357 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
355 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText()); | 358 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText()); |
356 | 359 |
357 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 360 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
358 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText()); | 361 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText()); |
359 | 362 |
360 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 363 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
361 EXPECT_EQ(WideToUTF16(L"a\x05E9"L"b"), model.GetSelectedText()); | 364 EXPECT_EQ(WideToUTF16(L"a\x05E9"L"b"), model.GetSelectedText()); |
362 | 365 |
363 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); | 366 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); // leave 2. | 453 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false); // leave 2. |
451 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 454 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
452 EXPECT_EQ(14U, model.GetCursorPosition()); | 455 EXPECT_EQ(14U, model.GetCursorPosition()); |
453 EXPECT_STR_EQ("Life", model.GetSelectedText()); | 456 EXPECT_STR_EQ("Life", model.GetSelectedText()); |
454 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 457 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
455 EXPECT_STR_EQ("to Life", model.GetSelectedText()); | 458 EXPECT_STR_EQ("to Life", model.GetSelectedText()); |
456 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 459 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
457 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 460 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
458 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); // Now at start. | 461 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); // Now at start. |
459 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); | 462 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); |
460 // Should be safe to go pervious word at the begining. | 463 // Should be safe to go to the previous word at the beginning. |
461 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 464 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
462 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); | 465 EXPECT_STR_EQ("The answer to Life", model.GetSelectedText()); |
463 model.ReplaceChar('4'); | 466 model.ReplaceChar('4'); |
464 EXPECT_EQ(string16(), model.GetSelectedText()); | 467 EXPECT_EQ(string16(), model.GetSelectedText()); |
465 EXPECT_STR_EQ("42", model.GetText()); | 468 EXPECT_STR_EQ("42", model.GetText()); |
466 } | 469 } |
467 | 470 |
468 TEST_F(TextfieldViewsModelTest, SetText) { | 471 TEST_F(TextfieldViewsModelTest, SetText) { |
469 TextfieldViewsModel model(NULL); | 472 TextfieldViewsModel model(NULL); |
470 model.Append(ASCIIToUTF16("HELLO")); | 473 model.Append(ASCIIToUTF16("HELLO")); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 TEST_F(TextfieldViewsModelTest, SelectWordTest) { | 556 TEST_F(TextfieldViewsModelTest, SelectWordTest) { |
554 TextfieldViewsModel model(NULL); | 557 TextfieldViewsModel model(NULL); |
555 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); | 558 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); |
556 | 559 |
557 // Test when cursor is at the beginning. | 560 // Test when cursor is at the beginning. |
558 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); | 561 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); |
559 model.SelectWord(); | 562 model.SelectWord(); |
560 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 2U); | 563 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 2U); |
561 | 564 |
562 // Test when cursor is at the beginning of a word. | 565 // Test when cursor is at the beginning of a word. |
563 gfx::SelectionModel selection(2U); | 566 MoveCursorTo(model, 2); |
564 model.MoveCursorTo(selection); | |
565 model.SelectWord(); | 567 model.SelectWord(); |
566 SelectWordTestVerifier(model, ASCIIToUTF16("HELLO"), 7U); | 568 SelectWordTestVerifier(model, ASCIIToUTF16("HELLO"), 7U); |
567 | 569 |
568 // Test when cursor is at the end of a word. | 570 // Test when cursor is at the end of a word. |
569 selection = gfx::SelectionModel(15U); | 571 MoveCursorTo(model, 15); |
570 model.MoveCursorTo(selection); | |
571 model.SelectWord(); | 572 model.SelectWord(); |
572 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); | 573 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); |
573 | 574 |
574 // Test when cursor is somewhere in a non-alpha-numeric fragment. | 575 // Test when cursor is somewhere in a non-alpha-numeric fragment. |
575 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { | 576 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { |
576 selection = gfx::SelectionModel(cursor_pos); | 577 MoveCursorTo(model, cursor_pos); |
577 model.MoveCursorTo(selection); | |
578 model.SelectWord(); | 578 model.SelectWord(); |
579 SelectWordTestVerifier(model, ASCIIToUTF16(" !! "), 13U); | 579 SelectWordTestVerifier(model, ASCIIToUTF16(" !! "), 13U); |
580 } | 580 } |
581 | 581 |
582 // Test when cursor is somewhere in a whitespace fragment. | 582 // Test when cursor is somewhere in a whitespace fragment. |
583 selection = gfx::SelectionModel(17U); | 583 MoveCursorTo(model, 17); |
584 model.MoveCursorTo(selection); | |
585 model.SelectWord(); | 584 model.SelectWord(); |
586 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); | 585 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); |
587 | 586 |
588 // Test when cursor is at the end. | 587 // Test when cursor is at the end. |
589 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 588 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
590 model.SelectWord(); | 589 model.SelectWord(); |
591 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 24U); | 590 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 24U); |
592 } | 591 } |
593 | 592 |
594 // TODO(xji): temporarily disable in platform Win since the complex script | 593 // TODO(xji): temporarily disable in platform Win since the complex script |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 model.SelectRange(range); | 733 model.SelectRange(range); |
735 EXPECT_TRUE(model.GetSelectedText().empty()); | 734 EXPECT_TRUE(model.GetSelectedText().empty()); |
736 } | 735 } |
737 | 736 |
738 TEST_F(TextfieldViewsModelTest, SelectionModelTest) { | 737 TEST_F(TextfieldViewsModelTest, SelectionModelTest) { |
739 TextfieldViewsModel model(NULL); | 738 TextfieldViewsModel model(NULL); |
740 model.Append(ASCIIToUTF16("HELLO WORLD")); | 739 model.Append(ASCIIToUTF16("HELLO WORLD")); |
741 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); | 740 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); |
742 gfx::SelectionModel sel; | 741 gfx::SelectionModel sel; |
743 model.GetSelectionModel(&sel); | 742 model.GetSelectionModel(&sel); |
744 EXPECT_EQ(sel.selection_start(), sel.selection_end()); | 743 EXPECT_EQ(ui::Range(0), sel.selection()); |
745 EXPECT_EQ(0U, sel.selection_start()); | |
746 EXPECT_EQ(0U, sel.selection_end()); | |
747 | 744 |
748 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); | 745 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); |
749 model.GetSelectionModel(&sel); | 746 model.GetSelectionModel(&sel); |
750 EXPECT_NE(sel.selection_start(), sel.selection_end()); | 747 EXPECT_EQ(ui::Range(0, 5), sel.selection()); |
751 EXPECT_LE(sel.selection_start(), sel.selection_end()); | |
752 EXPECT_EQ(0U, sel.selection_start()); | |
753 EXPECT_EQ(5U, sel.selection_end()); | |
754 | 748 |
755 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); | 749 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, true); |
756 model.GetSelectionModel(&sel); | 750 model.GetSelectionModel(&sel); |
757 EXPECT_NE(sel.selection_start(), sel.selection_end()); | 751 EXPECT_EQ(ui::Range(0, 4), sel.selection()); |
758 EXPECT_EQ(0U, sel.selection_start()); | |
759 EXPECT_EQ(4U, sel.selection_end()); | |
760 | 752 |
761 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 753 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
762 model.GetSelectionModel(&sel); | 754 model.GetSelectionModel(&sel); |
763 EXPECT_EQ(sel.selection_start(), sel.selection_end()); | 755 EXPECT_EQ(ui::Range(0), sel.selection()); |
764 EXPECT_EQ(0U, sel.selection_start()); | |
765 EXPECT_EQ(0U, sel.selection_end()); | |
766 | 756 |
767 // now from the end. | 757 // now from the end. |
768 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 758 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
769 model.GetSelectionModel(&sel); | 759 model.GetSelectionModel(&sel); |
770 EXPECT_EQ(sel.selection_start(), sel.selection_end()); | 760 EXPECT_EQ(ui::Range(11), sel.selection()); |
771 EXPECT_EQ(11U, sel.selection_start()); | |
772 EXPECT_EQ(11U, sel.selection_end()); | |
773 | 761 |
774 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); | 762 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_LEFT, true); |
775 model.GetSelectionModel(&sel); | 763 model.GetSelectionModel(&sel); |
776 EXPECT_NE(sel.selection_start(), sel.selection_end()); | 764 EXPECT_EQ(ui::Range(11, 6), sel.selection()); |
777 EXPECT_GT(sel.selection_start(), sel.selection_end()); | |
778 EXPECT_EQ(11U, sel.selection_start()); | |
779 EXPECT_EQ(6U, sel.selection_end()); | |
780 | 765 |
781 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); | 766 model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, true); |
782 model.GetSelectionModel(&sel); | 767 model.GetSelectionModel(&sel); |
783 EXPECT_NE(sel.selection_start(), sel.selection_end()); | 768 EXPECT_EQ(ui::Range(11, 7), sel.selection()); |
784 EXPECT_GT(sel.selection_start(), sel.selection_end()); | |
785 EXPECT_EQ(11U, sel.selection_start()); | |
786 EXPECT_EQ(7U, sel.selection_end()); | |
787 | 769 |
788 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); | 770 model.MoveCursor(gfx::WORD_BREAK, gfx::CURSOR_RIGHT, true); |
789 model.GetSelectionModel(&sel); | 771 model.GetSelectionModel(&sel); |
790 EXPECT_EQ(sel.selection_start(), sel.selection_end()); | 772 EXPECT_EQ(ui::Range(11), sel.selection()); |
791 EXPECT_EQ(11U, sel.selection_start()); | |
792 EXPECT_EQ(11U, sel.selection_end()); | |
793 | 773 |
794 // Select All | 774 // Select All |
795 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); | 775 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, true); |
796 model.GetSelectionModel(&sel); | 776 model.GetSelectionModel(&sel); |
797 EXPECT_NE(sel.selection_start(), sel.selection_end()); | 777 EXPECT_EQ(ui::Range(11, 0), sel.selection()); |
798 EXPECT_GT(sel.selection_start(), sel.selection_end()); | |
799 EXPECT_EQ(11U, sel.selection_start()); | |
800 EXPECT_EQ(0U, sel.selection_end()); | |
801 } | 778 } |
802 | 779 |
803 TEST_F(TextfieldViewsModelTest, SelectSelectionModelTest) { | 780 TEST_F(TextfieldViewsModelTest, SelectSelectionModelTest) { |
804 TextfieldViewsModel model(NULL); | 781 TextfieldViewsModel model(NULL); |
805 model.Append(ASCIIToUTF16("HELLO WORLD")); | 782 model.Append(ASCIIToUTF16("HELLO WORLD")); |
806 model.SelectSelectionModel(gfx::SelectionModel(0, 6, 5, | 783 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(0, 6), |
807 gfx::SelectionModel::TRAILING)); | 784 gfx::CURSOR_BACKWARD)); |
808 EXPECT_STR_EQ("HELLO ", model.GetSelectedText()); | 785 EXPECT_STR_EQ("HELLO ", model.GetSelectedText()); |
809 | 786 |
810 model.SelectSelectionModel(gfx::SelectionModel(6, 1, 1, | 787 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(6, 1), |
811 gfx::SelectionModel::LEADING)); | 788 gfx::CURSOR_FORWARD)); |
812 EXPECT_STR_EQ("ELLO ", model.GetSelectedText()); | 789 EXPECT_STR_EQ("ELLO ", model.GetSelectedText()); |
813 | 790 |
814 model.SelectSelectionModel(gfx::SelectionModel(2, 1000, 999, | 791 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(2, 1000), |
815 gfx::SelectionModel::TRAILING)); | 792 gfx::CURSOR_BACKWARD)); |
816 EXPECT_STR_EQ("LLO WORLD", model.GetSelectedText()); | 793 EXPECT_STR_EQ("LLO WORLD", model.GetSelectedText()); |
817 | 794 |
818 model.SelectSelectionModel(gfx::SelectionModel(1000, 3, 3, | 795 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(1000, 3), |
819 gfx::SelectionModel::LEADING)); | 796 gfx::CURSOR_FORWARD)); |
820 EXPECT_STR_EQ("LO WORLD", model.GetSelectedText()); | 797 EXPECT_STR_EQ("LO WORLD", model.GetSelectedText()); |
821 | 798 |
822 model.SelectSelectionModel(gfx::SelectionModel(0, 0, 0, | 799 model.SelectSelectionModel(gfx::SelectionModel(0, gfx::CURSOR_FORWARD)); |
823 gfx::SelectionModel::LEADING)); | |
824 EXPECT_TRUE(model.GetSelectedText().empty()); | 800 EXPECT_TRUE(model.GetSelectedText().empty()); |
825 | 801 |
826 model.SelectSelectionModel(gfx::SelectionModel(3, 3, 3, | 802 model.SelectSelectionModel(gfx::SelectionModel(3, gfx::CURSOR_FORWARD)); |
827 gfx::SelectionModel::LEADING)); | |
828 EXPECT_TRUE(model.GetSelectedText().empty()); | 803 EXPECT_TRUE(model.GetSelectedText().empty()); |
829 | 804 |
830 model.SelectSelectionModel(gfx::SelectionModel(1000, 100, 100, | 805 model.SelectSelectionModel(gfx::SelectionModel(ui::Range(1000, 100), |
831 gfx::SelectionModel::LEADING)); | 806 gfx::CURSOR_FORWARD)); |
832 EXPECT_TRUE(model.GetSelectedText().empty()); | 807 EXPECT_TRUE(model.GetSelectedText().empty()); |
833 | 808 |
834 model.SelectSelectionModel(gfx::SelectionModel(1000, 1000, 1000, | 809 model.SelectSelectionModel(gfx::SelectionModel(1000, gfx::CURSOR_BACKWARD)); |
835 gfx::SelectionModel::TRAILING)); | |
836 EXPECT_TRUE(model.GetSelectedText().empty()); | 810 EXPECT_TRUE(model.GetSelectedText().empty()); |
837 } | 811 } |
838 | 812 |
839 TEST_F(TextfieldViewsModelTest, CompositionTextTest) { | 813 TEST_F(TextfieldViewsModelTest, CompositionTextTest) { |
840 TextfieldViewsModel model(this); | 814 TextfieldViewsModel model(this); |
841 model.Append(ASCIIToUTF16("1234590")); | 815 model.Append(ASCIIToUTF16("1234590")); |
842 model.SelectRange(ui::Range(5, 5)); | 816 model.SelectRange(ui::Range(5, 5)); |
843 EXPECT_FALSE(model.HasSelection()); | 817 EXPECT_FALSE(model.HasSelection()); |
844 EXPECT_EQ(5U, model.GetCursorPosition()); | 818 EXPECT_EQ(5U, model.GetCursorPosition()); |
845 | 819 |
846 ui::Range range; | 820 ui::Range range; |
847 model.GetTextRange(&range); | 821 model.GetTextRange(&range); |
848 EXPECT_EQ(0U, range.start()); | 822 EXPECT_EQ(ui::Range(0, 7), range); |
849 EXPECT_EQ(7U, range.end()); | |
850 | 823 |
851 ui::CompositionText composition; | 824 ui::CompositionText composition; |
852 composition.text = ASCIIToUTF16("678"); | 825 composition.text = ASCIIToUTF16("678"); |
853 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false)); | 826 composition.underlines.push_back(ui::CompositionUnderline(0, 3, 0, false)); |
854 composition.selection = ui::Range(2, 3); | 827 composition.selection = ui::Range(2, 3); |
855 model.SetCompositionText(composition); | 828 model.SetCompositionText(composition); |
856 EXPECT_TRUE(model.HasCompositionText()); | 829 EXPECT_TRUE(model.HasCompositionText()); |
857 EXPECT_TRUE(model.HasSelection()); | 830 EXPECT_TRUE(model.HasSelection()); |
858 | 831 |
859 model.GetTextRange(&range); | 832 model.GetTextRange(&range); |
860 EXPECT_EQ(10U, range.end()); | 833 EXPECT_EQ(10U, range.end()); |
861 EXPECT_STR_EQ("1234567890", model.GetText()); | 834 EXPECT_STR_EQ("1234567890", model.GetText()); |
862 | 835 |
863 model.GetCompositionTextRange(&range); | 836 model.GetCompositionTextRange(&range); |
864 EXPECT_EQ(5U, range.start()); | 837 EXPECT_EQ(ui::Range(5, 8), range); |
865 EXPECT_EQ(8U, range.end()); | |
866 // composition text | 838 // composition text |
867 EXPECT_STR_EQ("456", model.GetTextFromRange(ui::Range(3, 6))); | 839 EXPECT_STR_EQ("456", model.GetTextFromRange(ui::Range(3, 6))); |
868 | 840 |
869 gfx::SelectionModel selection; | 841 gfx::SelectionModel selection; |
870 model.GetSelectionModel(&selection); | 842 model.GetSelectionModel(&selection); |
871 EXPECT_EQ(7U, selection.selection_start()); | 843 EXPECT_EQ(ui::Range(7, 8), selection.selection()); |
872 EXPECT_EQ(8U, selection.selection_end()); | |
873 EXPECT_STR_EQ("8", model.GetSelectedText()); | 844 EXPECT_STR_EQ("8", model.GetSelectedText()); |
874 | 845 |
875 EXPECT_FALSE(composition_text_confirmed_or_cleared_); | 846 EXPECT_FALSE(composition_text_confirmed_or_cleared_); |
876 model.CancelCompositionText(); | 847 model.CancelCompositionText(); |
877 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 848 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
878 composition_text_confirmed_or_cleared_ = false; | 849 composition_text_confirmed_or_cleared_ = false; |
879 EXPECT_FALSE(model.HasCompositionText()); | 850 EXPECT_FALSE(model.HasCompositionText()); |
880 EXPECT_FALSE(model.HasSelection()); | 851 EXPECT_FALSE(model.HasSelection()); |
881 EXPECT_EQ(5U, model.GetCursorPosition()); | 852 EXPECT_EQ(5U, model.GetCursorPosition()); |
882 | 853 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
960 composition_text_confirmed_or_cleared_ = false; | 931 composition_text_confirmed_or_cleared_ = false; |
961 EXPECT_STR_EQ("678678", model.GetText()); | 932 EXPECT_STR_EQ("678678", model.GetText()); |
962 | 933 |
963 model.SetCompositionText(composition); | 934 model.SetCompositionText(composition); |
964 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); | 935 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false); |
965 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 936 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
966 composition_text_confirmed_or_cleared_ = false; | 937 composition_text_confirmed_or_cleared_ = false; |
967 EXPECT_STR_EQ("678", model.GetText()); | 938 EXPECT_STR_EQ("678", model.GetText()); |
968 | 939 |
969 model.SetCompositionText(composition); | 940 model.SetCompositionText(composition); |
970 gfx::SelectionModel sel(model.render_text()->GetSelectionStart(), | 941 gfx::SelectionModel sel( |
971 0, 0, gfx::SelectionModel::LEADING); | 942 ui::Range(model.render_text()->selection().start(), 0), |
| 943 gfx::CURSOR_FORWARD); |
972 model.MoveCursorTo(sel); | 944 model.MoveCursorTo(sel); |
973 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 945 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
974 composition_text_confirmed_or_cleared_ = false; | 946 composition_text_confirmed_or_cleared_ = false; |
975 EXPECT_STR_EQ("678678", model.GetText()); | 947 EXPECT_STR_EQ("678678", model.GetText()); |
976 | 948 |
977 model.SetCompositionText(composition); | 949 model.SetCompositionText(composition); |
978 model.SelectRange(ui::Range(0, 3)); | 950 model.SelectRange(ui::Range(0, 3)); |
979 EXPECT_TRUE(composition_text_confirmed_or_cleared_); | 951 EXPECT_TRUE(composition_text_confirmed_or_cleared_); |
980 composition_text_confirmed_or_cleared_ = false; | 952 composition_text_confirmed_or_cleared_ = false; |
981 EXPECT_STR_EQ("678", model.GetText()); | 953 EXPECT_STR_EQ("678", model.GetText()); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 // Clear history | 1037 // Clear history |
1066 model.ClearEditHistory(); | 1038 model.ClearEditHistory(); |
1067 EXPECT_FALSE(model.Undo()); | 1039 EXPECT_FALSE(model.Undo()); |
1068 EXPECT_FALSE(model.Redo()); | 1040 EXPECT_FALSE(model.Redo()); |
1069 EXPECT_STR_EQ("a", model.GetText()); | 1041 EXPECT_STR_EQ("a", model.GetText()); |
1070 EXPECT_EQ(1U, model.GetCursorPosition()); | 1042 EXPECT_EQ(1U, model.GetCursorPosition()); |
1071 | 1043 |
1072 // Delete =============================== | 1044 // Delete =============================== |
1073 model.SetText(ASCIIToUTF16("ABCDE")); | 1045 model.SetText(ASCIIToUTF16("ABCDE")); |
1074 model.ClearEditHistory(); | 1046 model.ClearEditHistory(); |
1075 gfx::SelectionModel sel(2); | 1047 MoveCursorTo(model, 2); |
1076 model.MoveCursorTo(sel); | |
1077 EXPECT_TRUE(model.Delete()); | 1048 EXPECT_TRUE(model.Delete()); |
1078 EXPECT_STR_EQ("ABDE", model.GetText()); | 1049 EXPECT_STR_EQ("ABDE", model.GetText()); |
1079 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); | 1050 model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, false); |
1080 EXPECT_TRUE(model.Delete()); | 1051 EXPECT_TRUE(model.Delete()); |
1081 EXPECT_STR_EQ("BDE", model.GetText()); | 1052 EXPECT_STR_EQ("BDE", model.GetText()); |
1082 EXPECT_TRUE(model.Undo()); | 1053 EXPECT_TRUE(model.Undo()); |
1083 EXPECT_STR_EQ("ABDE", model.GetText()); | 1054 EXPECT_STR_EQ("ABDE", model.GetText()); |
1084 EXPECT_EQ(0U, model.GetCursorPosition()); | 1055 EXPECT_EQ(0U, model.GetCursorPosition()); |
1085 EXPECT_TRUE(model.Undo()); | 1056 EXPECT_TRUE(model.Undo()); |
1086 EXPECT_STR_EQ("ABCDE", model.GetText()); | 1057 EXPECT_STR_EQ("ABCDE", model.GetText()); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 EXPECT_STR_EQ("", model.GetText()); | 1309 EXPECT_STR_EQ("", model.GetText()); |
1339 EXPECT_TRUE(model.Redo()); | 1310 EXPECT_TRUE(model.Redo()); |
1340 EXPECT_STR_EQ("ab", model.GetText()); | 1311 EXPECT_STR_EQ("ab", model.GetText()); |
1341 EXPECT_EQ(2U, model.GetCursorPosition()); | 1312 EXPECT_EQ(2U, model.GetCursorPosition()); |
1342 EXPECT_FALSE(model.Redo()); | 1313 EXPECT_FALSE(model.Redo()); |
1343 } | 1314 } |
1344 | 1315 |
1345 void RunInsertReplaceTest(TextfieldViewsModel& model) { | 1316 void RunInsertReplaceTest(TextfieldViewsModel& model) { |
1346 gfx::SelectionModel sel; | 1317 gfx::SelectionModel sel; |
1347 model.GetSelectionModel(&sel); | 1318 model.GetSelectionModel(&sel); |
1348 bool reverse = (sel.selection_start() > sel.selection_end()); | 1319 bool reverse = sel.selection().is_reversed(); |
1349 | 1320 |
1350 model.InsertChar('1'); | 1321 model.InsertChar('1'); |
1351 model.InsertChar('2'); | 1322 model.InsertChar('2'); |
1352 model.InsertChar('3'); | 1323 model.InsertChar('3'); |
1353 EXPECT_STR_EQ("a123d", model.GetText()); | 1324 EXPECT_STR_EQ("a123d", model.GetText()); |
1354 EXPECT_EQ(4U, model.GetCursorPosition()); | 1325 EXPECT_EQ(4U, model.GetCursorPosition()); |
1355 EXPECT_TRUE(model.Undo()); | 1326 EXPECT_TRUE(model.Undo()); |
1356 EXPECT_STR_EQ("abcd", model.GetText()); | 1327 EXPECT_STR_EQ("abcd", model.GetText()); |
1357 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); | 1328 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); |
1358 EXPECT_TRUE(model.Undo()); | 1329 EXPECT_TRUE(model.Undo()); |
1359 EXPECT_STR_EQ("", model.GetText()); | 1330 EXPECT_STR_EQ("", model.GetText()); |
1360 EXPECT_EQ(0U, model.GetCursorPosition()); | 1331 EXPECT_EQ(0U, model.GetCursorPosition()); |
1361 EXPECT_FALSE(model.Undo()); | 1332 EXPECT_FALSE(model.Undo()); |
1362 EXPECT_TRUE(model.Redo()); | 1333 EXPECT_TRUE(model.Redo()); |
1363 EXPECT_STR_EQ("abcd", model.GetText()); | 1334 EXPECT_STR_EQ("abcd", model.GetText()); |
1364 EXPECT_EQ(0U, model.GetCursorPosition()); // By SetText | 1335 EXPECT_EQ(0U, model.GetCursorPosition()); // By SetText |
1365 EXPECT_TRUE(model.Redo()); | 1336 EXPECT_TRUE(model.Redo()); |
1366 EXPECT_STR_EQ("a123d", model.GetText()); | 1337 EXPECT_STR_EQ("a123d", model.GetText()); |
1367 EXPECT_EQ(4U, model.GetCursorPosition()); | 1338 EXPECT_EQ(4U, model.GetCursorPosition()); |
1368 EXPECT_FALSE(model.Redo()); | 1339 EXPECT_FALSE(model.Redo()); |
1369 } | 1340 } |
1370 | 1341 |
1371 void RunOverwriteReplaceTest(TextfieldViewsModel& model) { | 1342 void RunOverwriteReplaceTest(TextfieldViewsModel& model) { |
1372 gfx::SelectionModel sel; | 1343 gfx::SelectionModel sel; |
1373 model.GetSelectionModel(&sel); | 1344 model.GetSelectionModel(&sel); |
1374 bool reverse = (sel.selection_start() > sel.selection_end()); | 1345 bool reverse = sel.selection().is_reversed(); |
1375 | 1346 |
1376 model.ReplaceChar('1'); | 1347 model.ReplaceChar('1'); |
1377 model.ReplaceChar('2'); | 1348 model.ReplaceChar('2'); |
1378 model.ReplaceChar('3'); | 1349 model.ReplaceChar('3'); |
1379 model.ReplaceChar('4'); | 1350 model.ReplaceChar('4'); |
1380 EXPECT_STR_EQ("a1234", model.GetText()); | 1351 EXPECT_STR_EQ("a1234", model.GetText()); |
1381 EXPECT_EQ(5U, model.GetCursorPosition()); | 1352 EXPECT_EQ(5U, model.GetCursorPosition()); |
1382 EXPECT_TRUE(model.Undo()); | 1353 EXPECT_TRUE(model.Undo()); |
1383 EXPECT_STR_EQ("abcd", model.GetText()); | 1354 EXPECT_STR_EQ("abcd", model.GetText()); |
1384 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); | 1355 EXPECT_EQ(reverse ? 1U : 3U, model.GetCursorPosition()); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1527 EXPECT_TRUE(model.Undo()); | 1498 EXPECT_TRUE(model.Undo()); |
1528 EXPECT_STR_EQ("ABCDE", model.GetText()); | 1499 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1529 EXPECT_TRUE(model.Redo()); | 1500 EXPECT_TRUE(model.Redo()); |
1530 EXPECT_STR_EQ("1234", model.GetText()); | 1501 EXPECT_STR_EQ("1234", model.GetText()); |
1531 EXPECT_FALSE(model.Redo()); | 1502 EXPECT_FALSE(model.Redo()); |
1532 | 1503 |
1533 // TODO(oshima): We need MockInputMethod to test the behavior with IME. | 1504 // TODO(oshima): We need MockInputMethod to test the behavior with IME. |
1534 } | 1505 } |
1535 | 1506 |
1536 } // namespace views | 1507 } // namespace views |
OLD | NEW |