OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> | |
6 | |
5 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
6 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
8 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/base/clipboard/clipboard.h" | 12 #include "ui/base/clipboard/clipboard.h" |
11 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 13 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
12 #include "ui/base/range/range.h" | 14 #include "ui/base/range/range.h" |
13 #include "ui/gfx/render_text.h" | 15 #include "ui/gfx/render_text.h" |
14 #include "views/controls/textfield/textfield.h" | 16 #include "views/controls/textfield/textfield.h" |
15 #include "views/controls/textfield/textfield_views_model.h" | 17 #include "views/controls/textfield/textfield_views_model.h" |
16 #include "views/test/test_views_delegate.h" | 18 #include "views/test/test_views_delegate.h" |
17 #include "views/test/views_test_base.h" | 19 #include "views/test/views_test_base.h" |
18 #include "views/views_delegate.h" | 20 #include "views/views_delegate.h" |
19 | 21 |
22 namespace { | |
23 | |
24 struct WordAndCursor { | |
25 const wchar_t* word; | |
msw
2011/09/14 02:43:48
Data members belong below the ctor.
xji
2011/09/15 23:38:13
Done.
| |
26 size_t cursor; | |
27 WordAndCursor(const wchar_t* w, size_t c) | |
28 : word(w), | |
29 cursor(c) { | |
30 } | |
31 }; | |
32 | |
33 } // namespace | |
34 | |
20 namespace views { | 35 namespace views { |
21 | 36 |
22 class TextfieldViewsModelTest : public ViewsTestBase, | 37 class TextfieldViewsModelTest : public ViewsTestBase, |
23 public TextfieldViewsModel::Delegate { | 38 public TextfieldViewsModel::Delegate { |
24 public: | 39 public: |
25 TextfieldViewsModelTest() | 40 TextfieldViewsModelTest() |
26 : ViewsTestBase(), | 41 : ViewsTestBase(), |
27 composition_text_confirmed_or_cleared_(false) { | 42 composition_text_confirmed_or_cleared_(false) { |
28 } | 43 } |
29 | 44 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 model.MoveCursorLeft(gfx::LINE_BREAK, false); | 91 model.MoveCursorLeft(gfx::LINE_BREAK, false); |
77 EXPECT_FALSE(model.Backspace()); | 92 EXPECT_FALSE(model.Backspace()); |
78 EXPECT_STR_EQ("HELLORLD", model.GetText()); | 93 EXPECT_STR_EQ("HELLORLD", model.GetText()); |
79 // Move the cursor to the end. delete should fail. | 94 // Move the cursor to the end. delete should fail. |
80 model.MoveCursorRight(gfx::LINE_BREAK, false); | 95 model.MoveCursorRight(gfx::LINE_BREAK, false); |
81 EXPECT_FALSE(model.Delete()); | 96 EXPECT_FALSE(model.Delete()); |
82 EXPECT_STR_EQ("HELLORLD", model.GetText()); | 97 EXPECT_STR_EQ("HELLORLD", model.GetText()); |
83 // but backspace should work. | 98 // but backspace should work. |
84 EXPECT_TRUE(model.Backspace()); | 99 EXPECT_TRUE(model.Backspace()); |
85 EXPECT_STR_EQ("HELLORL", model.GetText()); | 100 EXPECT_STR_EQ("HELLORL", model.GetText()); |
101 | |
102 model.MoveCursorTo(gfx::SelectionModel(5)); | |
103 model.ReplaceText(ASCIIToUTF16(" WOR")); | |
104 EXPECT_STR_EQ("HELLO WORL", model.GetText()); | |
105 } | |
106 | |
107 TEST_F(TextfieldViewsModelTest, EditString_SimpleRTL) { | |
108 TextfieldViewsModel model(NULL); | |
109 // Append two strings. | |
110 model.Append(WideToUTF16(L"\x05d0\x05d1\x05d2")); | |
111 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2"), model.GetText()); | |
112 model.Append(WideToUTF16(L"\x05e0\x05e1\x05e2")); | |
113 EXPECT_EQ(WideToUTF16(L"\x05d0\x05d1\x05d2\x05e0\x05e1\x05e2"), | |
114 model.GetText()); | |
115 | |
116 // Insert 0x05f0. | |
117 model.MoveCursorTo(gfx::SelectionModel(1U)); | |
118 model.InsertChar(0x05f0); | |
119 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05d1\x05d2\x05e0\x05e1\x05e2"), | |
120 model.GetText()); | |
121 | |
122 // Replace "\x05d1" with "\x05f1". | |
123 model.ReplaceChar(0x05f1); | |
124 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05d2\x05e0\x05e1\x05e2"), | |
125 model.GetText()); | |
126 | |
127 // Delete and backspace. | |
128 EXPECT_EQ(3U, model.GetCursorPosition()); | |
129 EXPECT_TRUE(model.Delete()); | |
130 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x5f1\x05e0\x05e1\x05e2"), | |
131 model.GetText()); | |
132 EXPECT_TRUE(model.Backspace()); | |
133 EXPECT_EQ(2U, model.GetCursorPosition()); | |
134 EXPECT_EQ(WideToUTF16(L"\x05d0\x05f0\x05e0\x05e1\x05e2"), model.GetText()); | |
135 } | |
136 | |
137 TEST_F(TextfieldViewsModelTest, EditString_ComplexScript) { | |
138 TextfieldViewsModel model(NULL); | |
139 // Append two Hindi strings. | |
140 model.Append(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915")); | |
141 EXPECT_EQ(WideToUTF16(L"\x0915\x093f\x0915\x094d\x0915"), | |
142 model.GetText()); | |
143 model.Append(WideToUTF16(L"\x0915\x094d\x092e\x094d")); | |
144 EXPECT_EQ(WideToUTF16( | |
145 L"\x0915\x093f\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), | |
146 model.GetText()); | |
147 | |
148 // Check it is not able to place cursor in middle of a grapheme. | |
149 model.MoveCursorTo(gfx::SelectionModel(1U)); | |
150 EXPECT_EQ(0U, model.GetCursorPosition()); | |
151 | |
152 model.MoveCursorTo(gfx::SelectionModel(2U)); | |
153 EXPECT_EQ(2U, model.GetCursorPosition()); | |
154 model.InsertChar('a'); | |
155 EXPECT_EQ(WideToUTF16( | |
156 L"\x0915\x093f\x0061\x0915\x094d\x0915\x0915\x094d\x092e\x094d"), | |
157 model.GetText()); | |
158 | |
159 // ReplaceChar will replace the whole grapheme. | |
160 model.ReplaceChar('b'); | |
161 EXPECT_EQ(WideToUTF16( | |
162 L"\x0915\x093f\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), | |
163 model.GetText()); | |
164 EXPECT_EQ(4U, model.GetCursorPosition()); | |
165 | |
166 // Delete should delete the whole grapheme. | |
167 model.MoveCursorTo(gfx::SelectionModel(0U)); | |
168 EXPECT_TRUE(model.Delete()); | |
169 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e\x094d"), | |
170 model.GetText()); | |
171 model.MoveCursorTo(gfx::SelectionModel(model.GetText().length())); | |
172 EXPECT_TRUE(model.Backspace()); | |
173 EXPECT_EQ(WideToUTF16(L"\x0061\x0062\x0915\x0915\x094d\x092e"), | |
174 model.GetText()); | |
175 | |
176 // Test cursor position and deletion for Hindi Virama. | |
177 model.SetText(WideToUTF16(L"\x0D38\x0D4D\x0D15\x0D16\x0D2E")); | |
178 model.MoveCursorTo(gfx::SelectionModel(0)); | |
179 EXPECT_EQ(0U, model.GetCursorPosition()); | |
180 | |
181 model.MoveCursorTo(gfx::SelectionModel(1)); | |
182 EXPECT_EQ(0U, model.GetCursorPosition()); | |
183 | |
184 model.MoveCursorTo(gfx::SelectionModel(2)); | |
185 EXPECT_EQ(2U, model.GetCursorPosition()); | |
186 | |
187 model.MoveCursorTo(gfx::SelectionModel(3)); | |
188 EXPECT_EQ(3U, model.GetCursorPosition()); | |
189 | |
190 model.MoveCursorTo(gfx::SelectionModel(2)); | |
191 | |
192 EXPECT_TRUE(model.Backspace()); | |
193 EXPECT_EQ(WideToUTF16(L"\x0D38\x0D15\x0D16\x0D2E"), model.GetText()); | |
194 | |
195 // Test Delete/Backspace on Hebrew with non-spacing marks. | |
196 model.SetText(WideToUTF16(L"\x05d5\x05b7\x05D9\x05B0\x05D4\x05B4\x05D9")); | |
197 model.MoveCursorTo(gfx::SelectionModel(0)); | |
198 EXPECT_TRUE(model.Delete()); | |
199 EXPECT_TRUE(model.Delete()); | |
200 EXPECT_TRUE(model.Delete()); | |
201 EXPECT_TRUE(model.Delete()); | |
202 EXPECT_EQ(WideToUTF16(L""), model.GetText()); | |
203 | |
204 // The first 2 characters are not strong directionality characters. | |
205 model.SetText(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9\x05BC")); | |
206 #if defined(OS_WIN) | |
207 model.MoveCursorRight(gfx::LINE_BREAK, false); | |
208 #else | |
209 model.MoveCursorLeft(gfx::LINE_BREAK, false); | |
210 #endif | |
211 EXPECT_TRUE(model.Backspace()); | |
212 EXPECT_EQ(WideToUTF16(L"\x002C\x0020\x05D1\x05BC\x05B7\x05E9"), | |
213 model.GetText()); | |
86 } | 214 } |
87 | 215 |
88 TEST_F(TextfieldViewsModelTest, EmptyString) { | 216 TEST_F(TextfieldViewsModelTest, EmptyString) { |
89 TextfieldViewsModel model(NULL); | 217 TextfieldViewsModel model(NULL); |
90 EXPECT_EQ(string16(), model.GetText()); | 218 EXPECT_EQ(string16(), model.GetText()); |
91 EXPECT_EQ(string16(), model.GetSelectedText()); | 219 EXPECT_EQ(string16(), model.GetSelectedText()); |
92 EXPECT_EQ(string16(), model.GetVisibleText()); | 220 EXPECT_EQ(string16(), model.GetVisibleText()); |
93 | 221 |
94 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); | 222 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); |
95 EXPECT_EQ(0U, model.GetCursorPosition()); | 223 EXPECT_EQ(0U, model.GetCursorPosition()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 | 264 |
137 // Select all and move cursor | 265 // Select all and move cursor |
138 model.SelectAll(); | 266 model.SelectAll(); |
139 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false); | 267 model.MoveCursorLeft(gfx::CHARACTER_BREAK, false); |
140 EXPECT_EQ(0U, model.GetCursorPosition()); | 268 EXPECT_EQ(0U, model.GetCursorPosition()); |
141 model.SelectAll(); | 269 model.SelectAll(); |
142 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); | 270 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); |
143 EXPECT_EQ(5U, model.GetCursorPosition()); | 271 EXPECT_EQ(5U, model.GetCursorPosition()); |
144 } | 272 } |
145 | 273 |
274 TEST_F(TextfieldViewsModelTest, Selection_BidiWithNonSpacingMarks) { | |
275 // Selection is a logical operation. And it should work with the arrow | |
276 // keys doing visual movements, while the selection is logical between | |
277 // the (logical) start and end points. Selection is simply defined as | |
278 // the portion of text between the logical positions of the start and end | |
279 // caret positions. | |
280 TextfieldViewsModel model(NULL); | |
281 model.Append(WideToUTF16( | |
282 L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def")); | |
283 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); | |
284 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); | |
285 | |
286 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | |
287 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); | |
288 EXPECT_EQ(3U, model.GetCursorPosition()); | |
289 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); | |
290 | |
291 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | |
292 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); | |
293 EXPECT_EQ(7U, model.GetCursorPosition()); | |
294 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8"), | |
295 model.GetSelectedText()); | |
296 | |
297 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | |
298 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); | |
299 EXPECT_EQ(3U, model.GetCursorPosition()); | |
300 EXPECT_EQ(WideToUTF16(L"c"), model.GetSelectedText()); | |
301 | |
302 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | |
303 EXPECT_EQ(2U, model.render_text()->GetSelectionStart()); | |
304 EXPECT_EQ(10U, model.GetCursorPosition()); | |
305 EXPECT_EQ(WideToUTF16(L"c\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"d"), | |
306 model.GetSelectedText()); | |
307 | |
308 model.ClearSelection(); | |
309 EXPECT_EQ(string16(), model.GetSelectedText()); | |
310 model.SelectAll(); | |
311 EXPECT_EQ(WideToUTF16(L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def"), | |
312 model.GetSelectedText()); | |
313 | |
314 // In case of "aBc", this test shows how to select "aB" or "Bc", assume 'B' is | |
315 // an RTL character. | |
316 model.SetText(WideToUTF16(L"a\x05E9"L"b")); | |
317 model.MoveCursorTo(gfx::SelectionModel(0)); | |
318 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | |
319 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText()); | |
320 | |
321 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | |
322 EXPECT_EQ(WideToUTF16(L"a"), model.GetSelectedText()); | |
323 | |
324 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | |
325 EXPECT_EQ(WideToUTF16(L"a\x05E9"L"b"), model.GetSelectedText()); | |
326 | |
327 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); | |
328 EXPECT_EQ(3U, model.GetCursorPosition()); | |
329 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); | |
330 EXPECT_EQ(WideToUTF16(L"b"), model.GetSelectedText()); | |
331 | |
332 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); | |
333 EXPECT_EQ(WideToUTF16(L"b"), model.GetSelectedText()); | |
334 | |
335 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); | |
336 EXPECT_EQ(WideToUTF16(L"a\x05E9"L"b"), model.GetSelectedText()); | |
337 | |
338 model.MoveCursorLeft(gfx::LINE_BREAK, false); | |
339 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | |
340 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | |
341 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); | |
342 EXPECT_EQ(WideToUTF16(L"a\x05E9"), model.GetSelectedText()); | |
343 | |
344 model.MoveCursorRight(gfx::LINE_BREAK, false); | |
345 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); | |
346 model.MoveCursorLeft(gfx::CHARACTER_BREAK, true); | |
347 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | |
348 EXPECT_EQ(WideToUTF16(L"\x05E9"L"b"), model.GetSelectedText()); | |
349 | |
350 model.ClearSelection(); | |
351 EXPECT_EQ(string16(), model.GetSelectedText()); | |
352 model.SelectAll(); | |
353 EXPECT_EQ(WideToUTF16(L"a\x05E9"L"b"), model.GetSelectedText()); | |
354 } | |
355 | |
146 TEST_F(TextfieldViewsModelTest, SelectionAndEdit) { | 356 TEST_F(TextfieldViewsModelTest, SelectionAndEdit) { |
147 TextfieldViewsModel model(NULL); | 357 TextfieldViewsModel model(NULL); |
148 model.Append(ASCIIToUTF16("HELLO")); | 358 model.Append(ASCIIToUTF16("HELLO")); |
149 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); | 359 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); |
150 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); | 360 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); |
151 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); // select "EL" | 361 model.MoveCursorRight(gfx::CHARACTER_BREAK, true); // select "EL" |
152 EXPECT_TRUE(model.Backspace()); | 362 EXPECT_TRUE(model.Backspace()); |
153 EXPECT_STR_EQ("HLO", model.GetText()); | 363 EXPECT_STR_EQ("HLO", model.GetText()); |
154 | 364 |
155 model.Append(ASCIIToUTF16("ILL")); | 365 model.Append(ASCIIToUTF16("ILL")); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
307 model.MoveCursorRight(gfx::LINE_BREAK, false); | 517 model.MoveCursorRight(gfx::LINE_BREAK, false); |
308 model.MoveCursorLeft(gfx::WORD_BREAK, true); | 518 model.MoveCursorLeft(gfx::WORD_BREAK, true); |
309 EXPECT_TRUE(model.Paste()); | 519 EXPECT_TRUE(model.Paste()); |
310 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); | 520 clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text); |
311 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); | 521 EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text); |
312 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); | 522 EXPECT_STR_EQ("HELLO HELLO HELLO HELLO WORLD", model.GetText()); |
313 EXPECT_EQ(29U, model.GetCursorPosition()); | 523 EXPECT_EQ(29U, model.GetCursorPosition()); |
314 } | 524 } |
315 | 525 |
316 void SelectWordTestVerifier(TextfieldViewsModel &model, | 526 void SelectWordTestVerifier(TextfieldViewsModel &model, |
317 const std::string &expected_selected_string, size_t expected_cursor_pos) { | 527 const string16 &expected_selected_string, size_t expected_cursor_pos) { |
318 EXPECT_STR_EQ(expected_selected_string, model.GetSelectedText()); | 528 EXPECT_EQ(expected_selected_string, model.GetSelectedText()); |
319 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); | 529 EXPECT_EQ(expected_cursor_pos, model.GetCursorPosition()); |
320 } | 530 } |
321 | 531 |
322 TEST_F(TextfieldViewsModelTest, SelectWordTest) { | 532 TEST_F(TextfieldViewsModelTest, SelectWordTest) { |
323 TextfieldViewsModel model(NULL); | 533 TextfieldViewsModel model(NULL); |
324 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); | 534 model.Append(ASCIIToUTF16(" HELLO !! WO RLD ")); |
325 | 535 |
326 // Test when cursor is at the beginning. | 536 // Test when cursor is at the beginning. |
327 model.MoveCursorLeft(gfx::LINE_BREAK, false); | 537 model.MoveCursorLeft(gfx::LINE_BREAK, false); |
328 model.SelectWord(); | 538 model.SelectWord(); |
329 SelectWordTestVerifier(model, " ", 2U); | 539 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 2U); |
330 | 540 |
331 // Test when cursor is at the beginning of a word. | 541 // Test when cursor is at the beginning of a word. |
332 gfx::SelectionModel selection(2U); | 542 gfx::SelectionModel selection(2U); |
333 model.MoveCursorTo(selection); | 543 model.MoveCursorTo(selection); |
334 model.SelectWord(); | 544 model.SelectWord(); |
335 SelectWordTestVerifier(model, "HELLO", 7U); | 545 SelectWordTestVerifier(model, ASCIIToUTF16("HELLO"), 7U); |
336 | 546 |
337 // Test when cursor is at the end of a word. | 547 // Test when cursor is at the end of a word. |
338 selection = gfx::SelectionModel(15U); | 548 selection = gfx::SelectionModel(15U); |
339 model.MoveCursorTo(selection); | 549 model.MoveCursorTo(selection); |
340 model.SelectWord(); | 550 model.SelectWord(); |
341 SelectWordTestVerifier(model, "WO", 15U); | 551 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); |
342 | 552 |
343 // Test when cursor is somewhere in a non-alph-numeric fragment. | 553 // Test when cursor is somewhere in a non-alpha-numeric fragment. |
344 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { | 554 for (size_t cursor_pos = 8; cursor_pos < 13U; cursor_pos++) { |
345 selection = gfx::SelectionModel(cursor_pos); | 555 selection = gfx::SelectionModel(cursor_pos); |
346 model.MoveCursorTo(selection); | 556 model.MoveCursorTo(selection); |
347 model.SelectWord(); | 557 model.SelectWord(); |
348 SelectWordTestVerifier(model, " !! ", 13U); | 558 SelectWordTestVerifier(model, ASCIIToUTF16(" !! "), 13U); |
349 } | 559 } |
350 | 560 |
351 // Test when cursor is somewhere in a whitespace fragment. | 561 // Test when cursor is somewhere in a whitespace fragment. |
352 selection = gfx::SelectionModel(17U); | 562 selection = gfx::SelectionModel(17U); |
353 model.MoveCursorTo(selection); | 563 model.MoveCursorTo(selection); |
354 model.SelectWord(); | 564 model.SelectWord(); |
355 SelectWordTestVerifier(model, " ", 20U); | 565 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 20U); |
356 | 566 |
357 // Test when cursor is at the end. | 567 // Test when cursor is at the end. |
358 model.MoveCursorRight(gfx::LINE_BREAK, false); | 568 model.MoveCursorRight(gfx::LINE_BREAK, false); |
359 model.SelectWord(); | 569 model.SelectWord(); |
360 SelectWordTestVerifier(model, " ", 24U); | 570 SelectWordTestVerifier(model, ASCIIToUTF16(" "), 24U); |
571 } | |
572 | |
573 TEST_F(TextfieldViewsModelTest, SelectWordTest_MixScripts) { | |
574 TextfieldViewsModel model(NULL); | |
575 std::vector<WordAndCursor> word_and_cursor; | |
576 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2)); | |
577 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2)); | |
578 word_and_cursor.push_back(WordAndCursor(L"\x05d1\x05d2", 5)); | |
579 word_and_cursor.push_back(WordAndCursor(L"\x05d1\x05d2", 5)); | |
580 word_and_cursor.push_back(WordAndCursor(L" ", 3)); | |
581 word_and_cursor.push_back(WordAndCursor(L"a\x05d0", 2)); | |
582 word_and_cursor.push_back(WordAndCursor(L"\x0915\x094d\x0915", 9)); | |
583 word_and_cursor.push_back(WordAndCursor(L"\x0915\x094d\x0915", 9)); | |
584 word_and_cursor.push_back(WordAndCursor(L" ", 10)); | |
585 word_and_cursor.push_back(WordAndCursor(L"\x4E2D\x56FD", 12)); | |
586 word_and_cursor.push_back(WordAndCursor(L"\x4E2D\x56FD", 12)); | |
587 word_and_cursor.push_back(WordAndCursor(L"\x82B1", 13)); | |
588 word_and_cursor.push_back(WordAndCursor(L"\x5929", 14)); | |
589 | |
590 // The text consists of Ascii, Hebrew, Hindi with Virama sign, and Chinese. | |
591 model.SetText(WideToUTF16(L"a\x05d0 \x05d1\x05d2 \x0915\x094d\x0915 " | |
592 L"\x4E2D\x56FD\x82B1\x5929")); | |
593 for (size_t i = 0; i < word_and_cursor.size(); ++i) { | |
594 model.MoveCursorLeft(gfx::LINE_BREAK, false); | |
595 for (size_t j = 0; j < i; ++j) | |
596 model.MoveCursorRight(gfx::CHARACTER_BREAK, false); | |
597 model.SelectWord(); | |
598 SelectWordTestVerifier(model, WideToUTF16(word_and_cursor[i].word), | |
599 word_and_cursor[i].cursor); | |
600 } | |
361 } | 601 } |
362 | 602 |
363 TEST_F(TextfieldViewsModelTest, RangeTest) { | 603 TEST_F(TextfieldViewsModelTest, RangeTest) { |
364 TextfieldViewsModel model(NULL); | 604 TextfieldViewsModel model(NULL); |
365 model.Append(ASCIIToUTF16("HELLO WORLD")); | 605 model.Append(ASCIIToUTF16("HELLO WORLD")); |
366 model.MoveCursorLeft(gfx::LINE_BREAK, false); | 606 model.MoveCursorLeft(gfx::LINE_BREAK, false); |
367 ui::Range range; | 607 ui::Range range; |
368 model.GetSelectedRange(&range); | 608 model.GetSelectedRange(&range); |
369 EXPECT_TRUE(range.is_empty()); | 609 EXPECT_TRUE(range.is_empty()); |
370 EXPECT_EQ(0U, range.start()); | 610 EXPECT_EQ(0U, range.start()); |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1135 EXPECT_TRUE(model.Undo()); | 1375 EXPECT_TRUE(model.Undo()); |
1136 EXPECT_STR_EQ("ABCDE", model.GetText()); | 1376 EXPECT_STR_EQ("ABCDE", model.GetText()); |
1137 EXPECT_TRUE(model.Redo()); | 1377 EXPECT_TRUE(model.Redo()); |
1138 EXPECT_STR_EQ("1234", model.GetText()); | 1378 EXPECT_STR_EQ("1234", model.GetText()); |
1139 EXPECT_FALSE(model.Redo()); | 1379 EXPECT_FALSE(model.Redo()); |
1140 | 1380 |
1141 // TODO(oshima): We need MockInputMethod to test the behavior with IME. | 1381 // TODO(oshima): We need MockInputMethod to test the behavior with IME. |
1142 } | 1382 } |
1143 | 1383 |
1144 } // namespace views | 1384 } // namespace views |
OLD | NEW |